[ltt-dev] [PATCH 1/2] Make lttctl mount debugfs automatically

Zhaolei zhaolei at cn.fujitsu.com
Wed Jan 7 03:04:24 EST 2009


lttctl need debugfs mounted,
This patch make lttctl mount debugfs automatically when it is not mounted.

Little cleanup also done(combile 2 getdebugfsmntdir() into one).

Applies on top of ltt-control-0.63-03012009.

Signed-off-by: Zhao lei <zhaolei at cn.fujitsu.com>
---
 liblttctl/liblttctl.c |   54 +++++++++++++++++++++++++++++---------------------
 liblttctl/lttctl.h    |    3 ++
 lttctl/lttctl.c       |   40 +++++++------------------------------
 3 files changed, 43 insertions(+), 54 deletions(-)
diff -Nur ltt-control-0.63-03012009.org/liblttctl/liblttctl.c ltt-control-0.63-03012009.new/liblttctl/liblttctl.c
--- ltt-control-0.63-03012009.org/liblttctl/liblttctl.c	2009-01-07 09:52:05.000000000 +0800
+++ ltt-control-0.63-03012009.new/liblttctl/liblttctl.c	2009-01-07 14:48:18.000000000 +0800
@@ -39,27 +39,7 @@
 
 static int initdebugfsmntdir(void)
 {
-	char mnt_dir[PATH_MAX];
-	char mnt_type[PATH_MAX];
-
-	FILE *fp = fopen("/proc/mounts", "r");
-	if (!fp) {
-		fprintf(stderr, "%s: Can't open /proc/mounts\n", __func__);
-		return 1;
-	}
-
-	while (1) {
-		if (fscanf(fp, "%*s %s %s %*s %*s %*s", mnt_dir, mnt_type)
-			<= 0) {
-			fprintf(stderr, "%s: debugfs mountpoint not found\n",
-				__func__);
-			return 1;
-		}
-		if (!strcmp(mnt_type, "debugfs")) {
-			strcpy(debugfsmntdir, mnt_dir);
-			return 0;
-		}
-	}
+	return getdebugfsmntdir(debugfsmntdir);
 }
 
 int lttctl_init(void)
@@ -70,7 +50,7 @@
 
 	ret = initdebugfsmntdir();
 	if (ret) {
-		fprintf(stderr, "Debugfs mount point not found\n");
+		fprintf(stderr, "Get debugfs mount point failed\n");
 		return 1;
 	}
 
@@ -664,3 +644,33 @@
 arg_error:
 	return ret;
 }
+
+int getdebugfsmntdir(char *mntdir)
+{
+	char mnt_dir[PATH_MAX];
+	char mnt_type[PATH_MAX];
+	int trymount_done = 0;
+
+	FILE *fp = fopen("/proc/mounts", "r");
+	if (!fp)
+		return -EINVAL;
+
+find_again:
+	while (1) {
+		if (fscanf(fp, "%*s %s %s %*s %*s %*s", mnt_dir, mnt_type) <= 0)
+			break;
+
+		if (!strcmp(mnt_type, "debugfs")) {
+			strcpy(mntdir, mnt_dir);
+			return 0;
+		}
+	}
+
+	if (!trymount_done) {
+		mount("debugfs", "/sys/kernel/debug/", "debugfs", 0, NULL);
+		trymount_done = 1;
+		goto find_again;
+	}
+
+	return -ENOENT;
+}
diff -Nur ltt-control-0.63-03012009.org/liblttctl/lttctl.h ltt-control-0.63-03012009.new/liblttctl/lttctl.h
--- ltt-control-0.63-03012009.org/liblttctl/lttctl.h	2009-01-07 09:52:05.000000000 +0800
+++ ltt-control-0.63-03012009.new/liblttctl/lttctl.h	2009-01-07 14:48:18.000000000 +0800
@@ -36,4 +36,7 @@
 int lttctl_set_channel_subbuf_size(const char *name, const char *channel,
 		unsigned subbuf_size);
 
+/* Helper functions */
+int getdebugfsmntdir(char *mntdir);
+
 #endif /*_LIBLTT_H */
diff -Nur ltt-control-0.63-03012009.org/lttctl/lttctl.c ltt-control-0.63-03012009.new/lttctl/lttctl.c
--- ltt-control-0.63-03012009.org/lttctl/lttctl.c	2009-01-07 09:52:05.000000000 +0800
+++ ltt-control-0.63-03012009.new/lttctl/lttctl.c	2009-01-07 14:48:18.000000000 +0800
@@ -142,26 +142,6 @@
 	printf("\n");
 }
 
-static int getdebugfsmntdir(char *mntdir)
-{
-	char mnt_dir[PATH_MAX];
-	char mnt_type[PATH_MAX];
-
-	FILE *fp = fopen("/proc/mounts", "r");
-	if (!fp)
-		return -EINVAL;
-
-	while (1) {
-		if (fscanf(fp, "%*s %s %s %*s %*s %*s", mnt_dir, mnt_type) <= 0)
-			return -ENOENT;
-
-		if (!strcmp(mnt_type, "debugfs")) {
-			strcpy(mntdir, mnt_dir);
-			return 0;
-		}
-	}
-}
-
 /*
  * Separate option name to 3 fields
  * Ex:
@@ -559,19 +539,15 @@
 			if (getdebugfsmntdir(channel_root_default) == 0) {
 				strcat(channel_root_default, "/ltt");
 				opt_channel_root = channel_root_default;
+			} else {
+				fprintf(stderr,
+					"Channel_root is necessary for -w"
+					" option, but neither --channel_root"
+					" option\n"
+					"specified, nor debugfs's mount dir"
+					" found, mount debugfs also failed\n");
+				return -EINVAL;
 			}
-		/* Todo:
-		 * if (!opt_channel_root)
-		 *	if (auto_mount_debugfs_dir(channel_root_default) == 0)
-		 *		opt_channel_root = debugfs_dir_mnt_point;
-		 */
-		if (!opt_channel_root) {
-			fprintf(stderr,
-				"Channel_root is necessary for -w option,"
-				" but neither --channel_root option\n"
-				"specified, nor debugfs's mount dir found.\n");
-			return -EINVAL;
-		}
 
 		if (opt_dump_threads == 0)
 			opt_dump_threads = 1;





More information about the lttng-dev mailing list