[PATCH 03/10] rt-utils: Rename get_debugfileprefix() and let it look for tracefs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



get_debugfileprefix() used to look for debugfs and added the tracing
suffix to it. In the early days it it was not always monted at the same
destination. Later, that function got a fastpath to look directly at
"/sys/kernel/debug/tracing". This avoids parsing the mounted filesystem
and looking for debugfs.

Since about v4.1 (released over 10 years ago) that tracing folder moved
out debugfs and got its own filesystem (tracefs) and is mounted at
/sys/kernel/tracing. Since then that /sys/kernel/debug/tracing folder is
just an automount/ alias to /sys/kernel/tracing.
Since v6.17 that automount can be disabled and is schedulued for
removal.
Strart using tracefs directly instead that alias:
- Replace that "debug" prefix with tracefs since debugfs is no longer
  the thing that is used
- Look directy for /sys/kernel/tracing
- If it is not there, look for tracefs filesystem in case it is mounted
  at an unusual spot.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
---
 src/backfire/sendme.c         |  2 +-
 src/include/rt-utils.h        |  2 +-
 src/lib/rt-utils.c            | 51 ++++++++++++-----------------------
 src/pmqtest/pmqtest.c         |  2 +-
 src/ptsematest/ptsematest.c   |  2 +-
 src/sigwaittest/sigwaittest.c |  2 +-
 src/svsematest/svsematest.c   |  2 +-
 7 files changed, 23 insertions(+), 40 deletions(-)

diff --git a/src/backfire/sendme.c b/src/backfire/sendme.c
index da10397846f79..1c3e8b0c4c1b9 100644
--- a/src/backfire/sendme.c
+++ b/src/backfire/sendme.c
@@ -45,7 +45,7 @@ static int interval = 1000;
 static int kernvar(int mode, const char *name, char *value, size_t sizeofvalue)
 {
 	char filename[128];
-	char *fileprefix = get_debugfileprefix();
+	char *fileprefix = get_tracefs_prefix();
 	int retval = 1;
 	int path;
 	size_t len_prefix = strlen(fileprefix), len_name = strlen(name);
diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h
index 95964f70a6310..569023c5d3051 100644
--- a/src/include/rt-utils.h
+++ b/src/include/rt-utils.h
@@ -11,7 +11,7 @@
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 int check_privs(void);
-char *get_debugfileprefix(void);
+char *get_tracefs_prefix(void);
 int get_tracers(char ***);
 int valid_tracer(char *);
 
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 7e96950ef9887..696bca2657d18 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -32,7 +32,7 @@
 #define  MAX_COMMAND_LINE 4096
 #define  MAX_TS_SIZE 64
 
-static char debugfileprefix[MAX_PATH];
+static char tracefs_prefix[MAX_PATH];
 static char *fileprefix;
 static int trace_fd = -1;
 static int tracemark_fd = -1;
@@ -41,28 +41,21 @@ static char test_cmdline[MAX_COMMAND_LINE];
 static char ts_start[MAX_TS_SIZE];
 
 /*
- * Finds the tracing directory in a mounted debugfs
+ * Finds the tracing directory
  */
-char *get_debugfileprefix(void)
+char *get_tracefs_prefix(void)
 {
 	char type[100];
 	FILE *fp;
-	int size;
 	int found = 0;
 	struct stat s;
 
-	if (debugfileprefix[0] != '\0')
+	if (tracefs_prefix[0] != '\0')
 		goto out;
 
 	/* look in the "standard" mount point first */
-	if ((stat("/sys/kernel/debug/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
-		strcpy(debugfileprefix, "/sys/kernel/debug/tracing/");
-		goto out;
-	}
-
-	/* now look in the "other standard" place */
-	if ((stat("/debug/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
-		strcpy(debugfileprefix, "/debug/tracing/");
+	if ((stat("/sys/kernel/tracing", &s) == 0) && S_ISDIR(s.st_mode)) {
+		strcpy(tracefs_prefix, "/sys/kernel/tracing/");
 		goto out;
 	}
 
@@ -73,14 +66,8 @@ char *get_debugfileprefix(void)
 	while (fscanf(fp, "%*s %"
 		      STR(MAX_PATH)
 		      "s %99s %*s %*d %*d\n",
-		      debugfileprefix, type) == 2) {
-		if (strcmp(type, "debugfs") == 0) {
-			found = 1;
-			break;
-		}
-		/* stupid check for systemd-style autofs mount */
-		if ((strcmp(debugfileprefix, "/sys/kernel/debug") == 0) &&
-		    (strcmp(type, "systemd") == 0)) {
+		      tracefs_prefix, type) == 2) {
+		if (strcmp(type, "tracefs") == 0) {
 			found = 1;
 			break;
 		}
@@ -88,15 +75,11 @@ char *get_debugfileprefix(void)
 	fclose(fp);
 
 	if (!found) {
-		debugfileprefix[0] = '\0';
+		tracefs_prefix[0] = '\0';
 		goto out;
 	}
-
-	size = sizeof(debugfileprefix) - strlen(debugfileprefix);
-	strncat(debugfileprefix, "/tracing/", size);
-
 out:
-	return debugfileprefix;
+	return tracefs_prefix;
 }
 
 static char **tracer_list;
@@ -113,7 +96,7 @@ int get_tracers(char ***list)
 	int ret;
 	FILE *fp;
 	char buffer[CHUNKSZ];
-	char *prefix = get_debugfileprefix();
+	char *prefix = get_tracefs_prefix();
 	char *tmpbuf = NULL;
 	char *ptr;
 	int tmpsz = 0;
@@ -193,7 +176,7 @@ int valid_tracer(char *tracername)
  */
 int setevent(char *event, char *val)
 {
-	char *prefix = get_debugfileprefix();
+	char *prefix = get_tracefs_prefix();
 	char buffer[MAX_PATH];
 	int fd;
 	int ret;
@@ -417,19 +400,19 @@ static void close_tracemark_fd(void)
 static int trace_file_exists(char *name)
 {
 	struct stat sbuf;
-	char *tracing_prefix = get_debugfileprefix();
+	char *tracing_prefix = get_tracefs_prefix();
 	char path[MAX_PATH];
 	strcat(strcpy(path, tracing_prefix), name);
 	return stat(path, &sbuf) ? 0 : 1;
 }
 
-static void debugfs_prepare(void)
+static void tracefs_prepare(void)
 {
-	fileprefix = get_debugfileprefix();
+	fileprefix = get_tracefs_prefix();
 	if (!trace_file_exists("tracing_enabled") &&
 	    !trace_file_exists("tracing_on"))
 		warn("tracing_enabled or tracing_on not found\n"
-		     "debug fs not mounted");
+		     "tracefs not found");
 }
 
 void tracemark(char *fmt, ...)
@@ -455,7 +438,7 @@ void tracemark(char *fmt, ...)
 
 void enable_trace_mark(void)
 {
-	debugfs_prepare();
+	tracefs_prepare();
 	open_tracemark_fd();
 }
 
diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
index 04e36a1ad9795..a25b5cd2c24a1 100644
--- a/src/pmqtest/pmqtest.c
+++ b/src/pmqtest/pmqtest.c
@@ -184,7 +184,7 @@ void *pmqthread(void *param)
 			if (par->tracelimit && par->maxdiff > par->tracelimit) {
 				char tracing_enabled_file[MAX_PATH];
 
-				strcpy(tracing_enabled_file, get_debugfileprefix());
+				strcpy(tracing_enabled_file, get_tracefs_prefix());
 				strcat(tracing_enabled_file, "tracing_on");
 				int tracing_enabled =
 				    open(tracing_enabled_file, O_WRONLY);
diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
index d21166946f6ac..00871d08df3a8 100644
--- a/src/ptsematest/ptsematest.c
+++ b/src/ptsematest/ptsematest.c
@@ -107,7 +107,7 @@ void *semathread(void *param)
 			if (par->tracelimit && par->maxdiff > par->tracelimit) {
 				char tracing_enabled_file[MAX_PATH];
 
-				strcpy(tracing_enabled_file, get_debugfileprefix());
+				strcpy(tracing_enabled_file, get_tracefs_prefix());
 				strcat(tracing_enabled_file, "tracing_on");
 				int tracing_enabled =
 				    open(tracing_enabled_file, O_WRONLY);
diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
index 026cc81510157..e55f7fd2411f6 100644
--- a/src/sigwaittest/sigwaittest.c
+++ b/src/sigwaittest/sigwaittest.c
@@ -163,7 +163,7 @@ void *semathread(void *param)
 			if (par->tracelimit && par->maxdiff > par->tracelimit) {
 				char tracing_enabled_file[MAX_PATH];
 
-				strcpy(tracing_enabled_file, get_debugfileprefix());
+				strcpy(tracing_enabled_file, get_tracefs_prefix());
 				strcat(tracing_enabled_file, "tracing_on");
 				int tracing_enabled =
 				    open(tracing_enabled_file, O_WRONLY);
diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
index f3cddf8545757..093f3c473f0a1 100644
--- a/src/svsematest/svsematest.c
+++ b/src/svsematest/svsematest.c
@@ -170,7 +170,7 @@ void *semathread(void *param)
 			if (par->tracelimit && par->maxdiff > par->tracelimit) {
 				char tracing_enabled_file[MAX_PATH];
 
-				strcpy(tracing_enabled_file, get_debugfileprefix());
+				strcpy(tracing_enabled_file, get_tracefs_prefix());
 				strcat(tracing_enabled_file, "tracing_on");
 				int tracing_enabled =
 				    open(tracing_enabled_file, O_WRONLY);
-- 
2.51.0





[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux