Whamcloud - gitweb
b=22455 add "list_param -R"
authorLiuYing <Emoly.Liu@sun.com>
Fri, 14 May 2010 00:47:07 +0000 (08:47 +0800)
committerRobert Read <robert.read@oracle.com>
Mon, 17 May 2010 19:35:13 +0000 (12:35 -0700)
list parameters recursively with the "-R" option

o=adilger
i=emoly.liu
i=nathan

lustre/utils/lctl.c
lustre/utils/lustre_cfg.c

index e85190b..f1c7c31 100644 (file)
@@ -154,7 +154,8 @@ command_t cmdlist[] = {
          "usage: list_param [-F] <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"
          "usage: list_param [-F] <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."},
+                "respectively.\n"
+         "  -R  Recursively list all parameters under the specified path.\n"},
 
         /* Debug commands */
         {"==== debugging control ====", jt_noop, 0, "debug"},
 
         /* Debug commands */
         {"==== debugging control ====", jt_noop, 0, "debug"},
index 3d88065..c5d825b 100644 (file)
@@ -617,6 +617,7 @@ struct param_opts {
         int only_path;
         int show_path;
         int show_type;
         int only_path;
         int show_path;
         int show_type;
+        int recursive;
 };
 
 static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
 };
 
 static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
@@ -626,12 +627,16 @@ static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
         popt->show_path = 1;
         popt->only_path = 1;
         popt->show_type = 0;
         popt->show_path = 1;
         popt->only_path = 1;
         popt->show_type = 0;
+        popt->recursive = 0;
 
 
-        while ((ch = getopt(argc, argv, "F")) != -1) {
+        while ((ch = getopt(argc, argv, "FR")) != -1) {
                 switch (ch) {
                 case 'F':
                         popt->show_type = 1;
                         break;
                 switch (ch) {
                 case 'F':
                         popt->show_type = 1;
                         break;
+                case 'R':
+                        popt->recursive = 1;
+                        break;
                 default:
                         return -1;
                 }
                 default:
                         return -1;
                 }
@@ -647,7 +652,8 @@ static int listparam_display(struct param_opts *popt, char *pattern)
         glob_t glob_info;
         char filename[PATH_MAX + 1];    /* extra 1 byte for file type */
 
         glob_t glob_info;
         char filename[PATH_MAX + 1];    /* extra 1 byte for file type */
 
-        rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
+        rc = glob(pattern, GLOB_BRACE | (popt->recursive ? GLOB_MARK : 0),
+                  NULL, &glob_info);
         if (rc) {
                 fprintf(stderr, "error: list_param: %s: %s\n",
                         pattern, globerrstr(rc));
         if (rc) {
                 fprintf(stderr, "error: list_param: %s: %s\n",
                         pattern, globerrstr(rc));
@@ -656,11 +662,25 @@ static int listparam_display(struct param_opts *popt, char *pattern)
 
         for (i = 0; i  < glob_info.gl_pathc; i++) {
                 char *valuename = NULL;
 
         for (i = 0; i  < glob_info.gl_pathc; i++) {
                 char *valuename = NULL;
+                int last;
 
 
+                /* Trailing '/' will indicate recursion into directory */
+                last = strlen(glob_info.gl_pathv[i]) - 1;
+
+                /* Remove trailing '/' or it will be converted to '.' */
+                if (last > 0 && glob_info.gl_pathv[i][last] == '/')
+                        glob_info.gl_pathv[i][last] = '\0';
+                else
+                        last = 0;
                 strcpy(filename, glob_info.gl_pathv[i]);
                 valuename = display_name(filename, popt->show_type);
                 if (valuename)
                         printf("%s\n", valuename);
                 strcpy(filename, glob_info.gl_pathv[i]);
                 valuename = display_name(filename, popt->show_type);
                 if (valuename)
                         printf("%s\n", valuename);
+                if (last) {
+                        strcpy(filename, glob_info.gl_pathv[i]);
+                        strcat(filename, "/*");
+                        listparam_display(popt, filename);
+                }
         }
 
         globfree(&glob_info);
         }
 
         globfree(&glob_info);
@@ -676,8 +696,12 @@ int jt_lcfg_listparam(int argc, char **argv)
         char *path;
 
         rc = listparam_cmdline(argc, argv, &popt);
         char *path;
 
         rc = listparam_cmdline(argc, argv, &popt);
-        if (rc < 0 || rc >= argc)
+        if (rc == argc && popt.recursive) {
+                rc--;           /* we know at least "-R" is a parameter */
+                argv[rc] = "*";
+        } else if (rc < 0 || rc >= argc) {
                 return CMD_HELP;
                 return CMD_HELP;
+        }
 
         for (i = rc; i < argc; i++) {
                 path = argv[i];
 
         for (i = rc; i < argc; i++) {
                 path = argv[i];