From: zhaolei@cn.fujitsu.com (Zhaolei)
Subject: [ltt-dev] [PATCH 1/2] Make lttctl mount debugfs automatically
Date: Wed, 07 Jan 2009 16:04:24 +0800 [thread overview]
Message-ID: <49646208.7070607@cn.fujitsu.com> (raw)
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;
next reply other threads:[~2009-01-07 8:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-07 8:04 Zhaolei [this message]
2009-01-07 8:09 ` [ltt-dev] [PATCH 2/2] Make lttctl load ltt-trace-control module automatically Zhaolei
2009-01-15 1:20 ` Mathieu Desnoyers
2009-01-07 14:20 ` [ltt-dev] [PATCH 1/2] Make lttctl mount debugfs automatically Pierre-Marc Fournier
2009-01-08 0:40 ` Zhaolei
2009-01-08 14:44 ` Mathieu Desnoyers
2009-01-09 1:57 ` Zhaolei
2009-01-09 3:30 ` Mathieu Desnoyers
2009-01-13 23:54 ` Greg KH
2009-01-14 2:02 ` Josh Boyer
2009-01-14 5:16 ` Mathieu Desnoyers
2009-01-14 5:54 ` Greg KH
2009-01-15 1:41 ` Mathieu Desnoyers
2009-01-15 1:20 ` Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49646208.7070607@cn.fujitsu.com \
--to=zhaolei@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox