]> www.infradead.org Git - nvme.git/commitdiff
tools/rv: Allow rv list to filter for container
authorGabriele Monaco <gmonaco@redhat.com>
Wed, 5 Mar 2025 14:04:02 +0000 (15:04 +0100)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Mon, 24 Mar 2025 21:27:40 +0000 (17:27 -0400)
Add possibility to supply the container name to rv list:

  # rv list sched
  mon1
  mon2
  mon3

This lists only monitors in sched, without indentation.
Supplying -h, any option (string starting with -) or more than 1
argument will still print the usage.
Passing a non-existent container prints nothing and passing no container
continues to print all monitors, showing indentation for nested
monitors, reported after their container.

Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Link: https://lore.kernel.org/20250305140406.350227-10-gmonaco@redhat.com
Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
tools/verification/rv/include/in_kernel.h
tools/verification/rv/src/in_kernel.c
tools/verification/rv/src/rv.c

index 3090638c8d7105fc486c85087c1e83febdadd3f0..f3bfd3b9895fecd42e2157d8a6eed2ea5ca9d769 100644 (file)
@@ -1,3 +1,3 @@
 // SPDX-License-Identifier: GPL-2.0
-int ikm_list_monitors(void);
+int ikm_list_monitors(char *container);
 int ikm_run_monitor(char *monitor, int argc, char **argv);
index 032b851019290788145c9aaadb42470130d50801..c0dcee795c0de045c52f33ebd420ea698200afa5 100644 (file)
@@ -180,19 +180,25 @@ static char *ikm_read_desc(char *monitor_name)
 /*
  * ikm_fill_monitor_definition - fill monitor's definition
  *
- * Returns -1 on error, 0 otherwise.
+ * Returns -1 on error, 1 if the monitor does not belong in the container, 0 otherwise.
+ * container can be NULL
  */
-static int ikm_fill_monitor_definition(char *name, struct monitor *ikm)
+static int ikm_fill_monitor_definition(char *name, struct monitor *ikm, char *container)
 {
        int enabled;
        char *desc, *nested_name;
 
        nested_name = strstr(name, ":");
        if (nested_name) {
+               /* it belongs in container if it starts with "container:" */
+               if (container && strstr(name, container) != name)
+                       return 1;
                *nested_name = '/';
                ++nested_name;
                ikm->nested = 1;
        } else {
+               if (container)
+                       return 1;
                nested_name = name;
                ikm->nested = 0;
        }
@@ -328,12 +334,12 @@ static int ikm_has_id(char *monitor_name)
  *
  * Returns 0 on success, -1 otherwise.
  */
-int ikm_list_monitors(void)
+int ikm_list_monitors(char *container)
 {
        char *available_monitors;
        struct monitor ikm = {0};
        char *curr, *next;
-       int retval;
+       int retval, list_monitor = 0;
 
        available_monitors = tracefs_instance_file_read(NULL, "rv/available_monitors", NULL);
 
@@ -347,17 +353,29 @@ int ikm_list_monitors(void)
                next = strstr(curr, "\n");
                *next = '\0';
 
-               retval = ikm_fill_monitor_definition(curr, &ikm);
-               if (retval)
+               retval = ikm_fill_monitor_definition(curr, &ikm, container);
+               if (retval < 0)
                        err_msg("ikm: error reading %d in kernel monitor, skipping\n", curr);
 
-               printf("%s%-*s %s %s\n", ikm.nested ? " - " : "",
-                      ikm.nested ? MAX_DA_NAME_LEN - 3 : MAX_DA_NAME_LEN,
-                      ikm.name, ikm.desc, ikm.enabled ? "[ON]" : "[OFF]");
+               if (!retval) {
+                       int indent = ikm.nested && !container;
+
+                       list_monitor = 1;
+                       printf("%s%-*s %s %s\n", indent ? " - " : "",
+                              indent ? MAX_DA_NAME_LEN - 3 : MAX_DA_NAME_LEN,
+                              ikm.name, ikm.desc, ikm.enabled ? "[ON]" : "[OFF]");
+               }
                curr = ++next;
 
        } while (strlen(curr));
 
+       if (!list_monitor) {
+               if (container)
+                       printf("-- No monitor found in container %s --\n", container);
+               else
+                       printf("-- No monitor found --\n");
+       }
+
        free(available_monitors);
 
        return 0;
index 1ddb855328165f2ac11600da33bb96494eb202f7..239de054d1e069312bf00b5c4fcf7d0a015c9c05 100644 (file)
@@ -41,30 +41,42 @@ static void rv_list(int argc, char **argv)
 {
        static const char *const usage[] = {
                "",
-               "  usage: rv list [-h]",
+               "  usage: rv list [-h] [container]",
                "",
                "       list all available monitors",
                "",
                "       -h/--help: print this menu",
+               "",
+               "       [container]: list only monitors in this container",
                NULL,
        };
-       int i;
-
-       if (argc > 1) {
+       int i, print_help = 0, retval = 0;
+       char *container = NULL;
+
+       if (argc == 2) {
+               if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
+                       print_help = 1;
+                       retval = 0;
+               } else if (argv[1][0] == '-') {
+                       /* assume invalid option */
+                       print_help = 1;
+                       retval = 1;
+               } else
+                       container = argv[1];
+       } else if (argc > 2) {
+               /* more than 2 is always usage */
+               print_help = 1;
+               retval = 1;
+       }
+       if (print_help) {
                fprintf(stderr, "rv version %s\n", VERSION);
-
-               /* more than 1 is always usage */
                for (i = 0; usage[i]; i++)
                        fprintf(stderr, "%s\n", usage[i]);
-
-               /* but only -h is valid */
-               if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
-                       exit(0);
-               else
-                       exit(1);
+               exit(retval);
        }
 
-       ikm_list_monitors();
+       ikm_list_monitors(container);
+
        exit(0);
 }