Skip to contentSkip to conversation

selftests: tracing: Fix to unmount tracefs for recovering environment

PATCH Superseded Masami Hiramatsu (Google) 2 participants 4 messages Sep 9, 2023 – Sep 12, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Masami Hiramatsu (Google)

author maintainer
#0 lore raw

PATCH 1/1 selftests: tracing: Fix to unmount tracefs for recovering environment

From: Masami Hiramatsu (Google) <[email protected]>

Fix to unmount the tracefs if the ftracetest mounted it for recovering system environment. If the tracefs is already mounted, this does nothing.

Fixes cbd965bde74c ("ftrace/selftests: Return the skip code when tracing directory not configured in kernel")
---
 tools/testing/selftests/ftrace/ftracetest |    8 ++++++++
 1 file changed, 8 insertions(+)
tools/testing/selftests/ftrace/ftracetest +8 -0
index cb5f18c06593..89c212d82256 100755
@@ -31,6 +31,9 @@ err_ret=1
 # kselftest skip code is 4
 err_skip=4
 
+# umount required
+UMOUNT_DIR=""
+
 # cgroup RT scheduling prevents chrt commands from succeeding, which
 # induces failures in test wakeup tests.  Disable for the duration of
 # the tests.
@@ -45,6 +48,9 @@ setup() {
 
 cleanup() {
   echo $sched_rt_runtime_orig > $sched_rt_runtime
+  if [ "${UMOUNT_DIR}" ]; then
+    umount ${UMOUNT_DIR} ||:
+  fi
 }
 
 errexit() { # message
@@ -160,11 +166,13 @@ if [ -z "$TRACING_DIR" ]; then
 	    mount -t tracefs nodev /sys/kernel/tracing ||
 	      errexit "Failed to mount /sys/kernel/tracing"
 	    TRACING_DIR="/sys/kernel/tracing"
+	    UMOUNT_DIR=${TRACING_DIR}
 	# If debugfs exists, then so does /sys/kernel/debug
 	elif [ -d "/sys/kernel/debug" ]; then
 	    mount -t debugfs nodev /sys/kernel/debug ||
 	      errexit "Failed to mount /sys/kernel/debug"
 	    TRACING_DIR="/sys/kernel/debug/tracing"
+	    UMOUNT_DIR=${TRACING_DIR}
 	else
 	    err_ret=$err_skip
 	    errexit "debugfs and tracefs are not configured in this kernel"
maintainer
#1 lore raw
Quoted 28 lines · On Sat, 9 Sep 2023 18:36:39 +0900 "Masami Hiramatsu (Google)"…

From: Masami Hiramatsu (Google) <[email protected]>

Fix to unmount the tracefs if the ftracetest mounted it for recovering system environment. If the tracefs is already mounted, this does nothing.

Fixes cbd965bde74c ("ftrace/selftests: Return the skip code when tracing directory not configured in kernel")
---
 tools/testing/selftests/ftrace/ftracetest |    8 ++++++++
 1 file changed, 8 insertions(+)
tools/testing/selftests/ftrace/ftracetest +3 -0
index cb5f18c06593..89c212d82256 100755
@@ -31,6 +31,9 @@ err_ret=1
 # kselftest skip code is 4
 err_skip=4
 
+# umount required
+UMOUNT_DIR=""
+
 # cgroup RT scheduling prevents chrt commands from succeeding, which
 # induces failures in test wakeup tests.  Disable for the duration of
 # the tests.

tools/testing/selftests/ftrace/ftracetest setup() { · line 51

Quoted 4 lines
tools/testing/selftests/ftrace/ftracetest +1 -0
@@ -45,6 +48,9 @@ setup() {
 
 cleanup() {
   echo $sched_rt_runtime_orig > $sched_rt_runtime
+  if [ "${UMOUNT_DIR}" ]; then

Shouldn't the above be:

     if [ ! -z "${UNMOUNT_DIR}" ]; then

?

-- Steve

Quoted 19 lines
tools/testing/selftests/ftrace/ftracetest +4 -0
+    umount ${UMOUNT_DIR} ||:
+  fi
 }
 
 errexit() { # message
@@ -160,11 +166,13 @@ if [ -z "$TRACING_DIR" ]; then
 	    mount -t tracefs nodev /sys/kernel/tracing ||
 	      errexit "Failed to mount /sys/kernel/tracing"
 	    TRACING_DIR="/sys/kernel/tracing"
+	    UMOUNT_DIR=${TRACING_DIR}
 	# If debugfs exists, then so does /sys/kernel/debug
 	elif [ -d "/sys/kernel/debug" ]; then
 	    mount -t debugfs nodev /sys/kernel/debug ||
 	      errexit "Failed to mount /sys/kernel/debug"
 	    TRACING_DIR="/sys/kernel/debug/tracing"
+	    UMOUNT_DIR=${TRACING_DIR}
 	else
 	    err_ret=$err_skip
 	    errexit "debugfs and tracefs are not configured in this kernel"
author maintainer
#2 lore raw
Quoted 38 lines · On Mon, 11 Sep 2023 13:09:09 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 28 lines · On Sat, 9 Sep 2023 18:36:39 +0900 "Masami Hiramatsu (Google)"…

From: Masami Hiramatsu (Google) <[email protected]>

Fix to unmount the tracefs if the ftracetest mounted it for recovering system environment. If the tracefs is already mounted, this does nothing.

Fixes cbd965bde74c ("ftrace/selftests: Return the skip code when tracing directory not configured in kernel")
---
 tools/testing/selftests/ftrace/ftracetest |    8 ++++++++
 1 file changed, 8 insertions(+)
tools/testing/selftests/ftrace/ftracetest +3 -0
index cb5f18c06593..89c212d82256 100755
@@ -31,6 +31,9 @@ err_ret=1
 # kselftest skip code is 4
 err_skip=4
 
+# umount required
+UMOUNT_DIR=""
+
 # cgroup RT scheduling prevents chrt commands from succeeding, which
 # induces failures in test wakeup tests.  Disable for the duration of
 # the tests.

tools/testing/selftests/ftrace/ftracetest setup() { · line 51

Quoted 4 lines
tools/testing/selftests/ftrace/ftracetest +1 -0
@@ -45,6 +48,9 @@ setup() {
 
 cleanup() {
   echo $sched_rt_runtime_orig > $sched_rt_runtime
+  if [ "${UMOUNT_DIR}" ]; then

Shouldn't the above be:

Quoted 3 lines
     if [ ! -z "${UNMOUNT_DIR}" ]; then

?

I think both are good.
What about using '-n' explictly?

[ -n "${UNMOUNT_DIR}" ]

Thanks,

Quoted 23 lines

-- Steve

Quoted 19 lines
tools/testing/selftests/ftrace/ftracetest +4 -0
+    umount ${UMOUNT_DIR} ||:
+  fi
 }
 
 errexit() { # message
@@ -160,11 +166,13 @@ if [ -z "$TRACING_DIR" ]; then
 	    mount -t tracefs nodev /sys/kernel/tracing ||
 	      errexit "Failed to mount /sys/kernel/tracing"
 	    TRACING_DIR="/sys/kernel/tracing"
+	    UMOUNT_DIR=${TRACING_DIR}
 	# If debugfs exists, then so does /sys/kernel/debug
 	elif [ -d "/sys/kernel/debug" ]; then
 	    mount -t debugfs nodev /sys/kernel/debug ||
 	      errexit "Failed to mount /sys/kernel/debug"
 	    TRACING_DIR="/sys/kernel/debug/tracing"
+	    UMOUNT_DIR=${TRACING_DIR}
 	else
 	    err_ret=$err_skip
 	    errexit "debugfs and tracefs are not configured in this kernel"
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
maintainer
#3 lore raw
Quoted 10 lines · On Tue, 12 Sep 2023 09:54:57 +0900 Masami Hiramatsu (Google)…
Quoted 5 lines

Shouldn't the above be:

     if [ ! -z "${UNMOUNT_DIR}" ]; then

?

I think both are good.
What about using '-n' explictly?

[ -n "${UNMOUNT_DIR}" ]

Even better. Heh, I never even knew about that switch :-p

-- Steve