Whamcloud - gitweb
LU-17343 utils: added --path option for lctl list_param 02/55202/3
authorFrederick Dilger <fdilger@whamcloud.com>
Sat, 25 May 2024 23:23:20 +0000 (19:23 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 5 Jun 2024 04:52:45 +0000 (04: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.

Signed-off-by: Frederick Dilger <fdilger@whamcloud.com>
Change-Id: I2259b930f3ac5cc46ac7a9a36218a44fa110157c
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55202
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@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 10371ef..55d760b 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 3445620..f158339 100755 (executable)
@@ -28567,6 +28567,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 720fb33..8ac743c 100644 (file)
@@ -216,11 +216,11 @@ command_t cmdlist[] = {
         "usage: apply_yaml file\n"},
        {"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 ae64041..667f49f 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 928ea30..32e9b60 100644 (file)
@@ -772,22 +772,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",
 };
 
 /**
@@ -838,7 +841,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);
@@ -893,7 +896,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);
@@ -1231,9 +1234,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;
                }
 
                /*
@@ -1312,20 +1329,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;
                }
@@ -1359,7 +1379,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) {
                        if (rc == 0)
                                rc = rc2;
@@ -1383,7 +1404,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, "FHnNRy")) != -1) {
                switch (ch) {
@@ -1394,10 +1415,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;
@@ -1427,13 +1448,13 @@ int jt_lcfg_getparam(int argc, char **argv)
        if (index < 0 || index >= argc)
                return CMD_HELP;
 
-       mode = popt.po_only_path ? LIST_PARAM : GET_PARAM;
+       mode = popt.po_only_name ? LIST_PARAM : GET_PARAM;
        if (mode == LIST_PARAM)
                version = 0;
 
        if (popt.po_yaml)
                flags |= PARAM_FLAGS_YAML_FORMAT;
-       if (popt.po_show_path)
+       if (popt.po_show_name)
                flags |= PARAM_FLAGS_SHOW_SOURCE;
 
        for (i = index; i < argc; i++) {
@@ -1451,7 +1472,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)
@@ -1621,7 +1642,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);
@@ -1660,8 +1681,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;
@@ -1673,7 +1694,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