This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CONFIG_RELAY and debugfs in SystemTap


Masami Hiramatsu writes:
 > Hi Tom,
 > 
 > Could you show me an actual patch of this change?
 > I'm interested in it.
 > 

Here's the patch.  It works for me, but I still need to do some
testing on it, which I probably won't get to by the end of the week.
If you could take it for a spin and report problems if you see any,
that would be great.

Tom

Index: README
===================================================================
RCS file: /cvs/systemtap/src/README,v
retrieving revision 1.16
diff -u -p -r1.16 README
--- README	14 Jun 2006 15:14:30 -0000	1.16
+++ README	14 Sep 2006 13:14:19 -0000
@@ -53,7 +53,8 @@ Tips:
 Building a kernel.org kernel:
 
 - Build the kernel using your normal procedures.  Enable
-  CONFIG_DEBUG_INFO, CONFIG_KPROBES, and optionally CONFIG_RELAY.
+  CONFIG_DEBUG_INFO, CONFIG_KPROBES, and optionally CONFIG_RELAY and
+  CONFIG_DEBUG_FS.
 - Boot into the kernel.
 - Make sure the large unstripped kernel image 'vmlinux' from your
   build can be found by systemtap (see above)  You can just symlink
Index: runtime/stpd/stpd.c
===================================================================
RCS file: /cvs/systemtap/src/runtime/stpd/stpd.c,v
retrieving revision 1.23
diff -u -p -r1.23 stpd.c
--- runtime/stpd/stpd.c	2 Aug 2006 14:06:35 -0000	1.23
+++ runtime/stpd/stpd.c	14 Sep 2006 13:14:20 -0000
@@ -54,6 +54,7 @@ gid_t cmd_gid;
  /* relayfs base file name */
 static char stpd_filebase[1024];
 #define RELAYFS_MAGIC			0xF0B4A981
+#define DEBUGFS_MAGIC			0x64626720
 
 /* stp_check script */
 #ifdef PKGLIBDIR
@@ -88,7 +89,7 @@ int main(int argc, char **argv)
 	int c, status;
 	pid_t pid;
 	struct statfs st;
-	
+
 	while ((c = getopt(argc, argv, "mpqrb:n:t:d:c:vo:u:")) != EOF)
 	{
 		switch (c) {
@@ -210,15 +211,12 @@ int main(int argc, char **argv)
 
 	if (statfs("/mnt/relay", &st) == 0
 	    && (int) st.f_type == (int) RELAYFS_MAGIC)
-		sprintf(stpd_filebase, "/mnt/relay/%d/cpu", getpid());
-	else {
-		char *ptr;
-		sprintf(stpd_filebase, "/proc/systemtap/%s", modname);
-		ptr = index(stpd_filebase,'.');
-		if (ptr)
-			*ptr = 0;
-		strcat(stpd_filebase, "/cpu");
-	}
+		sprintf(stpd_filebase, "/mnt/relay/systemtap/%d/cpu", getpid());
+	else if (statfs("/sys/kernel/debug", &st) == 0
+	    && (int) st.f_type == (int) DEBUGFS_MAGIC)
+		sprintf(stpd_filebase, "/sys/kernel/debug/systemtap/%d/cpu", getpid());
+	else
+		sprintf(stpd_filebase, "/debug/systemtap/%d/cpu", getpid());
 
 	if (init_stp(stpd_filebase, !quiet)) {
 		//fprintf(stderr, "Couldn't initialize stpd. Exiting.\n");
Index: runtime/transport/procfs.c
===================================================================
RCS file: /cvs/systemtap/src/runtime/transport/procfs.c,v
retrieving revision 1.17
diff -u -p -r1.17 procfs.c
--- runtime/transport/procfs.c	5 Jun 2006 23:53:48 -0000	1.17
+++ runtime/transport/procfs.c	14 Sep 2006 13:14:20 -0000
@@ -267,38 +267,6 @@ err:
 	return _stp_current_buffers;
 }
 
-#if defined (STP_RELAYFS) && defined(CONFIG_RELAY)
-struct dentry *module_dir_dentry;
-
-static inline struct dentry *_stp_get_proc_root(void)
-{
-	struct file_system_type *procfs_type;
-	struct super_block *procfs_sb;
-
-	procfs_type = get_fs_type("proc");
-	if (!procfs_type || list_empty(&procfs_type->fs_supers))
-		return NULL;
-	procfs_sb = list_entry(procfs_type->fs_supers.next,
-			       struct super_block, s_instances);
-	return procfs_sb->s_root;
-}
-
-static inline struct dentry *_stp_force_dir_creation(const char *dirname, struct dentry *parent)
-{
-	struct dentry *dir_dentry;
-
-	mutex_lock(&parent->d_inode->i_mutex);
-	dir_dentry = lookup_one_len(dirname, parent, strlen(dirname));
-	mutex_unlock(&parent->d_inode->i_mutex);
-	if (IS_ERR(dir_dentry)) {
-		dir_dentry = NULL;
-		remove_proc_entry(dirname, NULL);
-	}
-	
-	return dir_dentry;
-}
-#endif  /* STP_RELAYFS && CONFIG_RELAY */
-
 static int _stp_register_procfs (void)
 {
 	int i;
@@ -307,10 +275,6 @@ static int _stp_register_procfs (void)
 	int j;
 	char buf[8];
 #endif
-#if defined (CONFIG_RELAY)
-	struct dentry *proc_root_dentry;
-	struct dentry *systemtap_dir_dentry;
-#endif /* CONFIG_RELAY */
 	struct proc_dir_entry *de;
 	struct list_head *p, *tmp;
 
@@ -342,23 +306,11 @@ static int _stp_register_procfs (void)
 			goto err0;
 	}
 
-#if defined (STP_RELAYFS) && defined (CONFIG_RELAY)
-	proc_root_dentry = _stp_get_proc_root();
-	systemtap_dir_dentry = _stp_force_dir_creation(dirname, proc_root_dentry);
-	if (!systemtap_dir_dentry)
-		goto err0;
-#endif /* STP_RELAYFS && CONFIG_RELAY */
 	/* now create /proc/systemtap/module_name */
 	_stp_proc_mod = proc_mkdir (THIS_MODULE->name, _stp_proc_root);
 	if (_stp_proc_mod == NULL)
 		goto err0;
 
-#if defined (STP_RELAYFS) && defined (CONFIG_RELAY)
-	module_dir_dentry = _stp_force_dir_creation(THIS_MODULE->name, systemtap_dir_dentry);
-	if (!module_dir_dentry)
-		goto err0;
-#endif /* STP_RELAYFS && CONFIG_RELAY */
-
 #ifdef STP_RELAYFS	
 	/* now for each cpu "n", create /proc/systemtap/module_name/n  */
 	for_each_cpu(i) {
Index: runtime/transport/relayfs.c
===================================================================
RCS file: /cvs/systemtap/src/runtime/transport/relayfs.c,v
retrieving revision 1.4
diff -u -p -r1.4 relayfs.c
--- runtime/transport/relayfs.c	16 Mar 2006 15:14:39 -0000	1.4
+++ runtime/transport/relayfs.c	14 Sep 2006 13:14:21 -0000
@@ -78,35 +78,15 @@ static struct dentry *_stp_create_buf_fi
 					   struct rchan_buf *buf,
 					   int *is_global)
 {
-	struct proc_dir_entry *pde;
-	struct dentry *dentry;
-	struct proc_dir_entry *parent_pde = NULL;
-
-	if (parent)
-		parent_pde = PDE(parent->d_inode);
-	pde = create_proc_entry(filename, S_IFREG|S_IRUSR, parent_pde);
-	if (unlikely(!pde))
-		return NULL;    
-	pde->proc_fops = &relay_file_operations;
-
-	mutex_lock(&parent->d_inode->i_mutex);
-	dentry = lookup_one_len(filename, parent, strlen(filename));
-	mutex_unlock(&parent->d_inode->i_mutex);
-	if (IS_ERR(dentry))
-		remove_proc_entry(filename, parent_pde);
-
-	dentry->d_inode->u.generic_ip = buf;
-
-	return dentry;
+	return debugfs_create_file(filename, mode, parent, buf,
+                                   &relay_file_operations);
 }
 
 static int _stp_remove_buf_file(struct dentry *dentry)
 {
-	struct proc_dir_entry *pde = PDE(dentry->d_inode);
-	
-	remove_proc_entry(pde->name, pde->parent);
+        debugfs_remove(dentry);
 
-	return 0;
+        return 0;
 }
 #endif /* CONFIG_RELAY */
 
@@ -128,34 +108,85 @@ static struct rchan_callbacks stp_rchan_
 };
 #endif  /* CONFIG_RELAY */
 
-/**
- *	_stp_relayfs_close - destroys relayfs channel
- *	@chan: the relayfs channel
- *	@dir: the directory containing the relayfs files
- */
+static struct dentry *create_relay_dir(const char *dirname, struct dentry *parent)
+{
+	struct dentry *dir;
+	
 #if defined (CONFIG_RELAY)
-void _stp_relayfs_close(struct rchan *chan, struct dentry *dir)
+	dir = debugfs_create_dir(dirname, parent);
+	if (IS_ERR(dir)) {
+		printk("STP: Couldn't create directory %s - debugfs not configured in.\n", dirname);
+		dir = NULL;
+	}
+#else
+	dir = relayfs_create_dir(dirname, parent);
+#endif
+
+	return dir;
+}
+
+static void remove_relay_dir(struct dentry *dir)
 {
-	if (!chan)
+	if (dir == NULL)
 		return;
-
-	relay_close(chan);
-	if (dir) {
-		struct proc_dir_entry *pde = PDE(dir->d_inode);
-		remove_proc_entry(pde->name, pde->parent);
-	}
+	
+#if defined (CONFIG_RELAY)
+		debugfs_remove(dir);
+#else
+		relayfs_remove_dir(dir);
+#endif
 }
+
+static struct dentry *get_relay_root(void)
+{
+	struct file_system_type *fs;
+	struct super_block *sb;
+	struct dentry *root;
+	char *dirname = "systemtap";
+
+	root = create_relay_dir(dirname, NULL);
+	if (root)
+		return root;
+	
+#if defined (CONFIG_RELAY)
+	fs = get_fs_type("debugfs");
 #else
+	fs = get_fs_type("relayfs");
+#endif
+	if (!fs)
+		return NULL;
+
+	sb = list_entry(fs->fs_supers.next, struct super_block, s_instances);
+	mutex_lock(&sb->s_root->d_inode->i_mutex);
+	root = lookup_one_len(dirname, sb->s_root, strlen(dirname));
+	mutex_unlock(&sb->s_root->d_inode->i_mutex);
+	if (!IS_ERR(root))
+		dput(root);
+	
+	return root;
+}
+
+static void put_relay_root(struct dentry *root)
+{
+	if (root)
+		remove_relay_dir(root);
+}
+
+static struct dentry *_relay_root;
+
+/**
+ *	_stp_relayfs_close - destroys relayfs channel
+ *	@chan: the relayfs channel
+ *	@dir: the directory containing the relayfs files
+ */
 void _stp_relayfs_close(struct rchan *chan, struct dentry *dir)
 {
 	if (!chan)
 		return;
-
 	relay_close(chan);
-	if (dir)
-		relayfs_remove_dir(dir);
+	remove_relay_dir(dir);
+	put_relay_root(_relay_root);
 }
-#endif /* CONFIG_RELAY */
 
 /**
  *	_stp_relayfs_open - create relayfs channel
@@ -163,56 +194,35 @@ void _stp_relayfs_close(struct rchan *ch
  *	@subbuf_size: size of relayfs sub-buffers
  *	@pid: daemon pid
  *	@outdir: receives directory dentry
- *	@parentdir: parent directory dentry
  *
  *	Returns relay channel, NULL on failure
  *
  *	Creates relayfs files as /systemtap/pid/cpuX in relayfs root
  */
-#if defined (CONFIG_RELAY)
-extern struct dentry *module_dentry;
 struct rchan *_stp_relayfs_open(unsigned n_subbufs,
 				unsigned subbuf_size,
 				int pid,
-				struct dentry **outdir,
-				struct dentry *parent_dir)
+				struct dentry **outdir)
 {
 	char dirname[16];
 	struct rchan *chan;
-	struct dentry* dir = NULL;
+	struct dentry* root, *dir;
 
 	sprintf(dirname, "%d", pid);
 	
-	/* TODO: need to create systemtap dir */
-	chan = relay_open("cpu", parent_dir, subbuf_size,
-			  n_subbufs, &stp_rchan_callbacks);
-	if (!chan) {
-		printk("STP: couldn't create relayfs channel.\n");
-		if (dir)
-			remove_proc_entry(dirname, NULL);
+	root = get_relay_root();
+	if (!root) {
+		printk("STP: couldn't get relay root dir.\n");
+		return NULL;
 	}
-	*outdir = dir;
-	return chan;
-}
-#else
-struct rchan *_stp_relayfs_open(unsigned n_subbufs,
-				unsigned subbuf_size,
-				int pid,
-				struct dentry **outdir)
-{
-	char dirname[16];
-	struct rchan *chan;
-	struct dentry* dir = NULL;
 
-	sprintf(dirname, "%d", pid);
-	
-	/* TODO: need to create systemtap dir */
-	dir = relayfs_create_dir(dirname, NULL);
+	dir = create_relay_dir(dirname, root);
 	if (!dir) {
-		printk("STP: couldn't create relayfs dir %s.\n", dirname);
+		printk("STP: couldn't create relay dir %s.\n", dirname);
+		put_relay_root(root);
 		return NULL;
 	}
-
+	
 #if (RELAYFS_CHANNEL_VERSION >= 4)
 	chan = relay_open("cpu", dir, subbuf_size,
 			  n_subbufs, &stp_rchan_callbacks);
@@ -222,15 +232,15 @@ struct rchan *_stp_relayfs_open(unsigned
 #endif /* RELAYFS_CHANNEL_VERSION >= 4 */
 
 	if (!chan) {
-		printk("STP: couldn't create relayfs channel.\n");
-		if (dir)
-			relayfs_remove_dir(dir);
+		printk("STP: couldn't create relay channel.\n");
+		remove_relay_dir(dir);
+		put_relay_root(root);
 	}
 
+	_relay_root = root;
 	*outdir = dir;
 	return chan;
 }
-#endif /* CONFIG_RELAY */
 
 #endif /* _TRANSPORT_RELAYFS_C_ */
 
Index: runtime/transport/relayfs.h
===================================================================
RCS file: /cvs/systemtap/src/runtime/transport/relayfs.h,v
retrieving revision 1.4
diff -u -p -r1.4 relayfs.h
--- runtime/transport/relayfs.h	16 Mar 2006 15:14:39 -0000	1.4
+++ runtime/transport/relayfs.h	14 Sep 2006 13:14:21 -0000
@@ -9,23 +9,17 @@
 #  include <linux/relayfs_fs.h>
 #elif defined (CONFIG_RELAY)
 #  include <linux/relay.h>
-#  include <linux/namei.h>
+#  include <linux/debugfs.h>
 #else
 #  undef STP_RELAYFS
 #endif
 
-#if defined (CONFIG_RELAY)
-struct rchan *_stp_relayfs_open(unsigned n_subbufs,
-				unsigned subbuf_size,
-				int pid,
-				struct dentry **outdir,
-				struct dentry *parent_dir);
-#else
+#  include <linux/namei.h>
+
 struct rchan *_stp_relayfs_open(unsigned n_subbufs,
 				unsigned subbuf_size,
 				int pid,
 				struct dentry **outdir);
-#endif
 
 void _stp_relayfs_close(struct rchan *chan, struct dentry *dir);
 
Index: runtime/transport/transport.c
===================================================================
RCS file: /cvs/systemtap/src/runtime/transport/transport.c,v
retrieving revision 1.25
diff -u -p -r1.25 transport.c
--- runtime/transport/transport.c	22 Jun 2006 00:48:33 -0000	1.25
+++ runtime/transport/transport.c	14 Sep 2006 13:14:21 -0000
@@ -203,10 +203,6 @@ void _stp_transport_close()
 	kbug("---- CLOSED ----\n");
 }
 
-#if defined (STP_RELAYFS) && defined (CONFIG_RELAY)
-extern struct dentry *module_dir_dentry;
-#endif /* STP_RELAYFS && CONFIG_RELAY */
-
 /**
  *	_stp_transport_open - open proc and relayfs channels
  *      with proper parameters
@@ -240,11 +236,8 @@ int _stp_transport_open(struct transport
 		info->n_subbufs = n_subbufs;
 		info->subbuf_size = subbuf_size;
 
-#if defined (CONFIG_RELAY)
-		_stp_chan = _stp_relayfs_open(n_subbufs, subbuf_size, _stp_pid, &_stp_dir, module_dir_dentry);
-#else
 		_stp_chan = _stp_relayfs_open(n_subbufs, subbuf_size, _stp_pid, &_stp_dir);
-#endif /* CONFIG_RELAY */
+
 		if (!_stp_chan) {
 			_stp_unregister_procfs();
 			return -ENOMEM;



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]