Whamcloud - gitweb
LU-17343 utils: added --path option for lctl list_param
authorFrederick Dilger <fdilger@whamcloud.com>
Sat, 25 May 2024 23:23:20 +0000 (19:23 -0400)
committerAndreas Dilger <adilger@whamcloud.com>
Wed, 12 Jun 2024 08:52:17 +0000 (08:52 +0000)
Added 'lctl list_param [-p] PARAM' option that prints the
actual pathname(s) for PARAM instead of the parameter names(s).
This should allow users to "resolve" PARAM pathnames so that they
can be used directly, which avoids having to hard code them. Also
renamed "po_only_path" and "po_show_path" to be "po_only_name" and
"po_show_name" to avoid confusion with "po_only_pathname" for the new
option.

Lustre-change: https://review.whamcloud.com/55202
Lustre-commit: e1a9d08351721d280faed51a2061e3e16f25a6b2

Signed-off-by: Frederick Dilger <fdilger@whamcloud.com>
Change-Id: I2259b930f3ac5cc46ac7a9a36218a44fa110157c
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/55331
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/doc/lctl-list_param.8
lustre/tests/sanity.sh
lustre/utils/lctl.c
lustre/utils/lctl_thread.h
lustre/utils/lustre_cfg.c

index 6917a3f..bbc20b0 100644 (file)
@@ -2,7 +2,7 @@
 .SH NAME
 lctl list_param \- list configuration parameter names
 .SH SYNOPSIS
-.BR list_param " [" -F | -R ]
+.BR list_param " ["-D | -F | -p | -R ]
 .RI < param_search " ...>"
 .SH DESCRIPTION
 List the Lustre or LNet parameter name(s) matching
@@ -11,9 +11,15 @@ The parameter name(s) may contain wildcards using
 .BR glob (3)
 pathname patterns.
 .TP
+.B -D
+Only list directories.
+.TP
 .B -F
 Append '/', '@' or '=' for dirs, symlinks and writeable files, respectively.
 .TP
+.B -p
+Print the pathname instead of the parameter name.
+.TP
 .B -R
 Recursively list all parameters under the specified parameter search string. If
 .I param_search
@@ -36,6 +42,13 @@ is unspecified, all the parameters will be shown.
   debug=
 .br
 .B
+# lctl list_param -p ost.*
+.br
+  /sys/fs/lustre/ost/OSS
+.br
+  /sys/fs/lustre/ost/num_refs
+.br
+.B
 # lctl list_param -R mdt
 .br
   mdt
index 156e150..7f1bac2 100644 (file)
@@ -26643,6 +26643,13 @@ test_401a() { #LU-7437
 }
 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
 
+test_401aa() {
+       $LCTL list_param -p osc.* | while read path; do
+               [[ -r $path ]] && echo "$path" || error "'$path' does not exist"
+       done
+}
+run_test 401aa "Verify that 'lctl list_param -p' lists the correct path names"
+
 test_401b() {
        # jobid_var may not allow arbitrary values, so use jobid_name
        # if available
index eaac5e5..94681f7 100644 (file)
@@ -247,11 +247,11 @@ command_t cmdlist[] = {
        },
        {"list_param", jt_lcfg_listparam, 0,
         "list the Lustre or LNET parameter name\n"
-        "usage: list_param [-F|-R|-D] <param_path1 param_path2 ...>\n"
+        "usage: list_param [-D|-F|-p|-R] <param_path1 param_path2 ...>\n"
         "List the name of Lustre or LNET parameter from the specified path.\n"
-        "  -F  Add '/', '@' or '=' for dirs, symlinks and writeable files,\n"
-               "respectively.\n"
         "  -D  Only list directories.\n"
+        "  -F  Add '/', '@' or '=' for dirs, symlinks and writeable files, respectively.\n"
+        "  -p  Prints the pathname instead of the parameter name.\n"
         "  -R  Recursively list all parameters under the specified path.\n"},
        {"del_ost", jt_del_ost, 0, "permanently delete OST records\n"
         "usage: del_ost [--dryrun] --target <$fsname-OSTxxxx>\n"
index aca8903..8b946b5 100644 (file)
@@ -36,8 +36,9 @@
 #endif
 
 struct param_opts {
-       unsigned int po_only_path:1;
-       unsigned int po_show_path:1;
+       unsigned int po_only_name:1;
+       unsigned int po_show_name:1;
+       unsigned int po_only_pathname:1;
        unsigned int po_show_type:1;
        unsigned int po_recursive:1;
        unsigned int po_perm:1;
index 367505d..18fff12 100644 (file)
@@ -762,22 +762,25 @@ clean_path(struct param_opts *popt, char *path)
 
 /**
  * The application lctl can perform three operations for lustre
- * tunables. This enum defines those three operations which are
+ * tunables. This enum defines those four operations which are
  *
  * 1) LIST_PARAM       - list available tunables
  * 2) GET_PARAM                - report the current setting of a tunable
  * 3) SET_PARAM                - set the tunable to a new value
+ * 4) LIST_PATHNAME    - list paths of available tunables
  */
 enum parameter_operation {
        LIST_PARAM,
        GET_PARAM,
        SET_PARAM,
+       LIST_PATHNAME,
 };
 
 char *parameter_opname[] = {
        [LIST_PARAM] = "list_param",
        [GET_PARAM] = "get_param",
        [SET_PARAM] = "set_param",
+       [LIST_PATHNAME] = "list_pathname",
 };
 
 /**
@@ -828,7 +831,7 @@ read_param(const char *path, const char *param_name, struct param_opts *popt)
 
                } while (buflen > 0);
 
-       } else if (popt->po_show_path) {
+       } else if (popt->po_show_name) {
                bool multilines = memchr(buf, '\n', buflen - 1);
 
                printf("%s=%s%s", param_name, multilines ? "\n" : "", buf);
@@ -883,7 +886,7 @@ write_param(const char *path, const char *param_name, struct param_opts *popt,
                fprintf(stderr,
                        "error: set_param: setting %s=%s: wrote only %zd\n",
                        path, value, count);
-       } else if (popt->po_show_path) {
+       } else if (popt->po_show_name) {
                printf("%s=%s\n", param_name, value);
        }
        close(fd);
@@ -1022,9 +1025,23 @@ do_param_op(struct param_opts *popt, char *pattern, char *value,
                        }
                        dup_cache[dup_count++] = strdup(param_name);
 
-                       if (popt->po_show_path)
+                       if (popt->po_show_name)
                                printf("%s\n", param_name);
                        break;
+               case LIST_PATHNAME:
+                       for (j = 0; j < dup_count; j++) {
+                               if (!strcmp(dup_cache[j], param_name))
+                                       break;
+                       }
+                       if (j != dup_count) {
+                               free(param_name);
+                               param_name = NULL;
+                               continue;
+                       }
+                       dup_cache[dup_count++] = strdup(param_name);
+                       if (popt->po_show_name)
+                               printf("%s\n", paths.gl_pathv[i]);
+                       break;
                }
 
                /*
@@ -1103,20 +1120,23 @@ static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
 {
        int ch;
 
-       popt->po_show_path = 1;
-       popt->po_only_path = 1;
+       popt->po_show_name = 1;
+       popt->po_only_name = 1;
 
-       while ((ch = getopt(argc, argv, "FRD")) != -1) {
+       while ((ch = getopt(argc, argv, "DFpR")) != -1) {
                switch (ch) {
+               case 'D':
+                       popt->po_only_dir = 1;
+                       break;
                case 'F':
                        popt->po_show_type = 1;
                        break;
+               case 'p':
+                       popt->po_only_pathname = 1;
+                       break;
                case 'R':
                        popt->po_recursive = 1;
                        break;
-               case 'D':
-                       popt->po_only_dir = 1;
-                       break;
                default:
                        return -1;
                }
@@ -1150,7 +1170,8 @@ int jt_lcfg_listparam(int argc, char **argv)
                        continue;
                }
 
-               rc2 = do_param_op(&popt, path, NULL, LIST_PARAM, NULL);
+               rc2 = do_param_op(&popt, path, NULL, popt.po_only_pathname ?
+                                 LIST_PATHNAME : LIST_PARAM, NULL);
                if (rc2 < 0) {
                        fprintf(stderr, "error: %s: listing '%s': %s\n",
                                jt_cmdname(argv[0]), path, strerror(-rc2));
@@ -1167,7 +1188,7 @@ static int getparam_cmdline(int argc, char **argv, struct param_opts *popt)
 {
        int ch;
 
-       popt->po_show_path = 1;
+       popt->po_show_name = 1;
 
        while ((ch = getopt(argc, argv, "FHnNR")) != -1) {
                switch (ch) {
@@ -1178,10 +1199,10 @@ static int getparam_cmdline(int argc, char **argv, struct param_opts *popt)
                        popt->po_header = 1;
                        break;
                case 'n':
-                       popt->po_show_path = 0;
+                       popt->po_show_name = 0;
                        break;
                case 'N':
-                       popt->po_only_path = 1;
+                       popt->po_only_name = 1;
                        break;
                case 'R':
                        popt->po_recursive = 1;
@@ -1220,7 +1241,7 @@ int jt_lcfg_getparam(int argc, char **argv)
                }
 
                rc2 = do_param_op(&popt, path, NULL,
-                                 popt.po_only_path ? LIST_PARAM : GET_PARAM,
+                                 popt.po_only_name ? LIST_PARAM : GET_PARAM,
                                  NULL);
                if (rc2 < 0) {
                        if (rc == 0)
@@ -1251,7 +1272,7 @@ int jt_nodemap_info(int argc, char **argv)
        int rc = 0;
 
        memset(&popt, 0, sizeof(popt));
-       popt.po_show_path = 1;
+       popt.po_show_name = 1;
 
        if (argc > 2) {
                fprintf(stderr, usage_str);
@@ -1259,7 +1280,7 @@ int jt_nodemap_info(int argc, char **argv)
        }
 
        if (argc == 1 || strcmp("list", argv[1]) == 0) {
-               popt.po_only_path = 1;
+               popt.po_only_name = 1;
                popt.po_only_dir = 1;
                rc = do_param_op(&popt, "nodemap/*", NULL, LIST_PARAM, NULL);
        } else if (strcmp("all", argv[1]) == 0) {
@@ -1291,8 +1312,8 @@ static int setparam_cmdline(int argc, char **argv, struct param_opts *popt)
 {
        int ch;
 
-       popt->po_show_path = 1;
-       popt->po_only_path = 0;
+       popt->po_show_name = 1;
+       popt->po_only_name = 0;
        popt->po_show_type = 0;
        popt->po_recursive = 0;
        popt->po_perm = 0;
@@ -1304,7 +1325,7 @@ static int setparam_cmdline(int argc, char **argv, struct param_opts *popt)
        while ((ch = getopt(argc, argv, "dFnPt::")) != -1) {
                switch (ch) {
                case 'n':
-                       popt->po_show_path = 0;
+                       popt->po_show_name = 0;
                        break;
                case 't':
 #if HAVE_LIBPTHREAD