]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf trace: Add beautifier script for fsmount flags
authorNamhyung Kim <namhyung@kernel.org>
Sun, 10 May 2026 20:23:45 +0000 (13:23 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 14 May 2026 21:48:32 +0000 (14:48 -0700)
And move the existing one to fsmount_attr.sh to be more precise.
Now the fsmount_flags[] is generated from the mount.h like below.
The ilog2() + 1 is an existing pattern to handle bit flags.

  $ cat tools/perf/trace/beauty/generated/fsmount_arrays.c
  static const char *fsmount_flags[] = {
   [ilog2(0x00000001) + 1] = "CLOEXEC",
   [ilog2(0x00000002) + 1] = "NAMESPACE",
  };

It was found by Sashiko during the review.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/Makefile.perf
tools/perf/builtin-trace.c
tools/perf/trace/beauty/beauty.h
tools/perf/trace/beauty/fsmount.c
tools/perf/trace/beauty/fsmount.sh
tools/perf/trace/beauty/fsmount_attr.sh [new file with mode: 0644]

index 585637fc934fe6ec4a95fcd5a73e80f5a29bc9f9..76b35ac19acbfb2007733ce360a7bf5dbd4d1c11 100644 (file)
@@ -564,6 +564,12 @@ fsmount_tbls := $(srctree)/tools/perf/trace/beauty/fsmount.sh
 $(fsmount_arrays): $(beauty_uapi_linux_dir)/mount.h $(fsmount_tbls)
        $(Q)$(SHELL) '$(fsmount_tbls)' $(beauty_uapi_linux_dir) > $@
 
+fsmount_attr_arrays := $(beauty_outdir)/fsmount_attr_arrays.c
+fsmount_attr_tbls := $(srctree)/tools/perf/trace/beauty/fsmount_attr.sh
+
+$(fsmount_attr_arrays): $(beauty_uapi_linux_dir)/mount.h $(fsmount_attr_tbls)
+       $(Q)$(SHELL) '$(fsmount_attr_tbls)' $(beauty_uapi_linux_dir) > $@
+
 fspick_arrays := $(beauty_outdir)/fspick_arrays.c
 fspick_tbls := $(srctree)/tools/perf/trace/beauty/fspick.sh
 
@@ -854,6 +860,7 @@ prepare: $(OUTPUT)PERF-VERSION-FILE archheaders \
        $(fadvise_advice_array) \
        $(fsconfig_arrays) \
        $(fsmount_arrays) \
+       $(fsmount_attr_arrays) \
        $(fspick_arrays) \
        $(pkey_alloc_access_rights_array) \
        $(sndrv_pcm_ioctl_array) \
@@ -1301,6 +1308,7 @@ clean:: $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clean $(LIBSYMBOL)-clean $(
                $(OUTPUT)$(fadvise_advice_array) \
                $(OUTPUT)$(fsconfig_arrays) \
                $(OUTPUT)$(fsmount_arrays) \
+               $(OUTPUT)$(fsmount_attr_arrays) \
                $(OUTPUT)$(fspick_arrays) \
                $(OUTPUT)$(madvise_behavior_array) \
                $(OUTPUT)$(mmap_flags_array) \
index e58c49d047a294db3af61ca6f71173e0de5a25aa..48615ddccd93a1e8fa4338bdaefcb4d6d7b96f3d 100644 (file)
@@ -771,11 +771,6 @@ static const char *bpf_cmd[] = {
 };
 static DEFINE_STRARRAY(bpf_cmd, "BPF_");
 
-static const char *fsmount_flags[] = {
-       [1] = "CLOEXEC",
-};
-static DEFINE_STRARRAY(fsmount_flags, "FSMOUNT_");
-
 #include "trace/beauty/generated/fsconfig_arrays.c"
 
 static DEFINE_STRARRAY(fsconfig_cmds, "FSCONFIG_");
@@ -1202,7 +1197,9 @@ static const struct syscall_fmt syscall_fmts[] = {
        { .name     = "fsconfig",
          .arg = { [1] = STRARRAY(cmd, fsconfig_cmds), }, },
        { .name     = "fsmount",
-         .arg = { [1] = STRARRAY_FLAGS(flags, fsmount_flags),
+         .arg = { [1] = { .scnprintf = SCA_FSMOUNT_FLAGS, /* fsmount_flags */
+                          .strtoul   = STUL_STRARRAYS,
+                          .show_zero = true, },
                   [2] = { .scnprintf = SCA_FSMOUNT_ATTR_FLAGS, /* attr_flags */ }, }, },
        { .name     = "fspick",
          .arg = { [0] = { .scnprintf = SCA_FDAT,         /* dfd */ },
index 0a07ad158f87c73c0ee3886d0b5971bd581ab392..a90c35fa5c123f2be61c5208bd200c90cf82fc85 100644 (file)
@@ -179,6 +179,9 @@ size_t syscall_arg__scnprintf_fcntl_arg(char *bf, size_t size, struct syscall_ar
 size_t syscall_arg__scnprintf_flock(char *bf, size_t size, struct syscall_arg *arg);
 #define SCA_FLOCK syscall_arg__scnprintf_flock
 
+size_t syscall_arg__scnprintf_fsmount_flags(char *bf, size_t size, struct syscall_arg *arg);
+#define SCA_FSMOUNT_FLAGS syscall_arg__scnprintf_fsmount_flags
+
 size_t syscall_arg__scnprintf_fsmount_attr_flags(char *bf, size_t size, struct syscall_arg *arg);
 #define SCA_FSMOUNT_ATTR_FLAGS syscall_arg__scnprintf_fsmount_attr_flags
 
index 28c2c16fc1a80dfd23b0309f79be10bddc36b3e5..179e649fc72a4724d01dab2197f84c90d734e8c6 100644 (file)
 #define MOUNT_ATTR_RELATIME    0x00000000 /* - Update atime relative to mtime/ctime. */
 #endif
 
-static size_t fsmount__scnprintf_attr_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
+
+static size_t fsmount__scnprintf_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
 {
 #include "trace/beauty/generated/fsmount_arrays.c"
+       static DEFINE_STRARRAY(fsmount_flags, "FSMOUNT_");
+
+       return strarray__scnprintf_flags(&strarray__fsmount_flags, bf, size, show_prefix, flags);
+}
+
+size_t syscall_arg__scnprintf_fsmount_flags(char *bf, size_t size, struct syscall_arg *arg)
+{
+       unsigned long flags = arg->val;
+
+       return fsmount__scnprintf_flags(flags, bf, size, arg->show_string_prefix);
+}
+
+static size_t fsmount__scnprintf_attr_flags(unsigned long flags, char *bf, size_t size, bool show_prefix)
+{
+#include "trace/beauty/generated/fsmount_attr_arrays.c"
        static DEFINE_STRARRAY(fsmount_attr_flags, "MOUNT_ATTR_");
        size_t printed = 0;
 
index 6b67a54cdeee64b391e7f481c6254cf153df63f9..6d1e80bc15e4416b6a582e1e57083846311af13b 100755 (executable)
@@ -9,14 +9,9 @@ fi
 
 linux_mount=${beauty_uapi_linux_dir}/mount.h
 
-# Remove MOUNT_ATTR_RELATIME as it is zeros, handle it a special way in the beautifier
-# Only handle MOUNT_ATTR_ followed by a capital letter/num as __ is special case
-# for things like MOUNT_ATTR__ATIME that is a mask for the possible ATIME handling
-# bits. Special case it as well in the beautifier
-
-printf "static const char *fsmount_attr_flags[] = {\n"
-regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MOUNT_ATTR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*'
-grep -E $regex ${linux_mount} | grep -v MOUNT_ATTR_RELATIME | \
+printf "static const char *fsmount_flags[] = {\n"
+regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+FSMOUNT_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*'
+grep -E $regex ${linux_mount} | \
        sed -r "s/$regex/\2 \1/g"       | \
        xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n"
 printf "};\n"
diff --git a/tools/perf/trace/beauty/fsmount_attr.sh b/tools/perf/trace/beauty/fsmount_attr.sh
new file mode 100644 (file)
index 0000000..6b67a54
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: LGPL-2.1
+
+if [ $# -ne 1 ] ; then
+       beauty_uapi_linux_dir=tools/perf/trace/beauty/include/uapi/linux/
+else
+       beauty_uapi_linux_dir=$1
+fi
+
+linux_mount=${beauty_uapi_linux_dir}/mount.h
+
+# Remove MOUNT_ATTR_RELATIME as it is zeros, handle it a special way in the beautifier
+# Only handle MOUNT_ATTR_ followed by a capital letter/num as __ is special case
+# for things like MOUNT_ATTR__ATIME that is a mask for the possible ATIME handling
+# bits. Special case it as well in the beautifier
+
+printf "static const char *fsmount_attr_flags[] = {\n"
+regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MOUNT_ATTR_([[:alnum:]][[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*'
+grep -E $regex ${linux_mount} | grep -v MOUNT_ATTR_RELATIME | \
+       sed -r "s/$regex/\2 \1/g"       | \
+       xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n"
+printf "};\n"