Whamcloud - gitweb
LU-5868 nodemap: Add nodemap_info to lctl 44/13044/5
authorKit Westneat <kit.westneat@gmail.com>
Fri, 12 Dec 2014 06:17:52 +0000 (01:17 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 9 May 2015 02:38:00 +0000 (02:38 +0000)
This patch adds nodemap_info to lctl, which can list all defined
nodemaps and display information about them, such as idmaps, ranges,
and flags. It is implemented as a wrapper to get_param/list_param,
and adds a -D parameter to list_param to only show directories.

Signed-off-by: Kit Westneat <kit.westneat@gmail.com>
Change-Id: I5d5ac44ec30bad49878be76168954dd231656421
Reviewed-on: http://review.whamcloud.com/13044
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/lctl.c
lustre/utils/lustre_cfg.c
lustre/utils/obdctl.h

index 9b1d0a3..a908de0 100644 (file)
@@ -186,12 +186,13 @@ command_t cmdlist[] = {
         "  -P  Set the parameter permanently, filesystem-wide.\n"
         "  -d  Remove the permanent setting (only with -P option).\n"},
        {"list_param", jt_lcfg_listparam, 0,
         "  -P  Set the parameter permanently, filesystem-wide.\n"
         "  -d  Remove the permanent setting (only with -P option).\n"},
        {"list_param", jt_lcfg_listparam, 0,
-         "list the Lustre or LNET parameter name\n"
-         "usage: list_param [-F|-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"
-         "  -R  Recursively list all parameters under the specified path.\n"},
+        "list the Lustre or LNET parameter name\n"
+        "usage: list_param [-F|-R|-D] <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"
+        "  -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"},
@@ -283,6 +284,8 @@ command_t cmdlist[] = {
         "usage: nodemap_test_nid <nid>"},
        {"nodemap_test_id", jt_nodemap_test_id, 0,
         "Usage: nodemap_test_id --nid <nid> --idtype [uid|gid] --id <id>"},
         "usage: nodemap_test_nid <nid>"},
        {"nodemap_test_id", jt_nodemap_test_id, 0,
         "Usage: nodemap_test_id --nid <nid> --idtype [uid|gid] --id <id>"},
+       {"nodemap_info", jt_nodemap_info, 0,
+        "Usage: nodemap_info [list|nodemap_name|all]"},
 
         /* Changelog commands */
         {"===  Changelogs ==", jt_noop, 0, "changelog user management"},
 
         /* Changelog commands */
         {"===  Changelogs ==", jt_noop, 0, "changelog user management"},
index a7af694..cc9763d 100644 (file)
@@ -523,6 +523,7 @@ struct param_opts {
        unsigned int po_recursive:1;
        unsigned int po_params2:1;
        unsigned int po_delete:1;
        unsigned int po_recursive:1;
        unsigned int po_params2:1;
        unsigned int po_delete:1;
+       unsigned int po_only_dir:1;
 };
 
 /* Param set to single log file, used by all clients and servers.
 };
 
 /* Param set to single log file, used by all clients and servers.
@@ -664,22 +665,27 @@ int jt_lcfg_mgsparam(int argc, char **argv)
 /* Display the path in the same format as sysctl
  * For eg. obdfilter.lustre-OST0000.stats */
 static char *
 /* Display the path in the same format as sysctl
  * For eg. obdfilter.lustre-OST0000.stats */
 static char *
-display_name(char *filename, size_t filename_size, bool po_show_type)
+display_name(char *filename, size_t filename_size, struct param_opts *popt)
 {
        struct stat st;
        char *tmp;
        char *suffix = NULL;
 
 {
        struct stat st;
        char *tmp;
        char *suffix = NULL;
 
-       if (po_show_type) {
+       if (popt->po_show_type || popt->po_only_dir) {
                if (lstat(filename, &st) == -1)
                        return NULL;
 
                if (lstat(filename, &st) == -1)
                        return NULL;
 
-               if (S_ISDIR(st.st_mode))
-                       suffix = "/";
-               else if (S_ISLNK(st.st_mode))
-                       suffix = "@";
-               else if (st.st_mode & S_IWUSR)
-                       suffix = "=";
+               if (popt->po_show_type) {
+                       if (S_ISDIR(st.st_mode))
+                               suffix = "/";
+                       else if (S_ISLNK(st.st_mode))
+                               suffix = "@";
+                       else if (st.st_mode & S_IWUSR)
+                               suffix = "=";
+               } else if (popt->po_only_dir) {
+                       if (!S_ISDIR(st.st_mode))
+                               return NULL;
+               }
        }
 
        filename += strlen("/proc/");
        }
 
        filename += strlen("/proc/");
@@ -700,7 +706,7 @@ display_name(char *filename, size_t filename_size, bool po_show_type)
 
        /* Append the indicator to entries.  We know there is enough space
         * for the suffix, since the path prefix was deleted. */
 
        /* Append the indicator to entries.  We know there is enough space
         * for the suffix, since the path prefix was deleted. */
-       if (po_show_type && suffix != NULL)
+       if (popt->po_show_type && suffix != NULL)
                strncat(filename, suffix, filename_size);
 
        return filename;
                strncat(filename, suffix, filename_size);
 
        return filename;
@@ -780,27 +786,31 @@ static int lprocfs_param_pattern(const char *pattern, char *buf, size_t bufsize)
 
 static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
 {
 
 static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
 {
-        int ch;
+       int ch;
 
 
-        popt->po_show_path = 1;
-        popt->po_only_path = 1;
-        popt->po_show_type = 0;
-        popt->po_recursive = 0;
+       popt->po_show_path = 1;
+       popt->po_only_path = 1;
+       popt->po_show_type = 0;
+       popt->po_recursive = 0;
+       popt->po_only_dir = 0;
 
 
-        while ((ch = getopt(argc, argv, "FR")) != -1) {
-                switch (ch) {
-                case 'F':
-                        popt->po_show_type = 1;
-                        break;
-                case 'R':
-                        popt->po_recursive = 1;
-                        break;
-                default:
-                        return -1;
-                }
-        }
+       while ((ch = getopt(argc, argv, "FRD")) != -1) {
+               switch (ch) {
+               case 'F':
+                       popt->po_show_type = 1;
+                       break;
+               case 'R':
+                       popt->po_recursive = 1;
+                       break;
+               case 'D':
+                       popt->po_only_dir = 1;
+                       break;
+               default:
+                       return -1;
+               }
+       }
 
 
-        return optind;
+       return optind;
 }
 
 static int listparam_display(struct param_opts *popt, char *pattern)
 }
 
 static int listparam_display(struct param_opts *popt, char *pattern)
@@ -814,7 +824,11 @@ static int listparam_display(struct param_opts *popt, char *pattern)
        if (rc < 0)
                return rc;
 
        if (rc < 0)
                return rc;
 
-       rc = glob(filename, GLOB_BRACE | (popt->po_recursive ? GLOB_MARK : 0),
+       rc = glob(filename,
+                 GLOB_BRACE |
+                       (popt->po_recursive ? GLOB_MARK : 0) |
+                       /* GLOB_ONLYDIR doesn't guarantee, only a hint */
+                       (popt->po_only_dir ? GLOB_ONLYDIR : 0),
                  NULL, &glob_info);
        if (rc) {
                fprintf(stderr, "error: list_param: %s: %s\n",
                  NULL, &glob_info);
        if (rc) {
                fprintf(stderr, "error: list_param: %s: %s\n",
@@ -835,7 +849,7 @@ static int listparam_display(struct param_opts *popt, char *pattern)
                else
                        last = 0;
                strlcpy(filename, glob_info.gl_pathv[i], len);
                else
                        last = 0;
                strlcpy(filename, glob_info.gl_pathv[i], len);
-               valuename = display_name(filename, len, popt->po_show_type);
+               valuename = display_name(filename, len, popt);
                if (valuename)
                        printf("%s\n", valuename);
                if (last) {
                if (valuename)
                        printf("%s\n", valuename);
                if (last) {
@@ -944,7 +958,7 @@ static int getparam_display(struct param_opts *popt, char *pattern)
                        strncpy(filename, glob_info.gl_pathv[i],
                                sizeof(filename));
                        valuename = display_name(filename, sizeof(filename),
                        strncpy(filename, glob_info.gl_pathv[i],
                                sizeof(filename));
                        valuename = display_name(filename, sizeof(filename),
-                                                false);
+                                                popt);
                }
 
                 /* Write the contents of file to stdout */
                }
 
                 /* Write the contents of file to stdout */
@@ -1025,6 +1039,54 @@ int jt_lcfg_getparam(int argc, char **argv)
        return rc;
 }
 
        return rc;
 }
 
+/**
+ * Output information about nodemaps.
+ * \param      argc            number of args
+ * \param      argv[]          variable string arguments
+ *
+ * [list|nodemap_name|all]     \a list will list all nodemaps (default).
+ *                             Specifying a \a nodemap_name will
+ *                             display info about that specific nodemap.
+ *                             \a all will display info for all nodemaps.
+ * \retval                     0 on success
+ */
+int jt_nodemap_info(int argc, char **argv)
+{
+       const char              usage_str[] = "usage: nodemap_info "
+                                             "[list|nodemap_name|all]\n";
+       struct param_opts       popt = {
+               .po_only_path = 0,
+               .po_show_path = 1,
+               .po_show_type = 0,
+               .po_recursive = 0,
+               .po_only_dir = 0
+       };
+       int                     rc = 0;
+
+       if (argc > 2) {
+               fprintf(stderr, usage_str);
+               return -1;
+       }
+
+       if (argc == 1 || strcmp("list", argv[1]) == 0) {
+               popt.po_only_path = 1;
+               popt.po_only_dir = 1;
+               rc = listparam_display(&popt, "nodemap/*");
+       } else if (strcmp("all", argv[1]) == 0) {
+               rc = getparam_display(&popt, "nodemap/*/*");
+       } else {
+               char    pattern[PATH_MAX];
+
+               snprintf(pattern, sizeof(pattern), "nodemap/%s/*", argv[1]);
+               rc = getparam_display(&popt, pattern);
+               if (rc == -ESRCH)
+                       fprintf(stderr, "error: nodemap_info: cannot find"
+                                       "nodemap %s\n", argv[1]);
+       }
+       return rc;
+}
+
+
 static int setparam_cmdline(int argc, char **argv, struct param_opts *popt)
 {
         int ch;
 static int setparam_cmdline(int argc, char **argv, struct param_opts *popt)
 {
         int ch;
@@ -1081,7 +1143,7 @@ static int setparam_display(struct param_opts *popt, char *pattern, char *value)
                        strncpy(filename, glob_info.gl_pathv[i],
                                sizeof(filename));
                        valuename = display_name(filename, sizeof(filename),
                        strncpy(filename, glob_info.gl_pathv[i],
                                sizeof(filename));
                        valuename = display_name(filename, sizeof(filename),
-                                                false);
+                                                popt);
                        if (valuename)
                                printf("%s=%s\n", valuename, value);
                }
                        if (valuename)
                                printf("%s=%s\n", valuename, value);
                }
index d0ef67f..95c3c59 100644 (file)
@@ -133,6 +133,7 @@ int jt_nodemap_del_range(int argc, char **argv);
 int jt_nodemap_add_idmap(int argc, char **argv);
 int jt_nodemap_del_idmap(int argc, char **argv);
 int jt_nodemap_test_id(int argc, char **argv);
 int jt_nodemap_add_idmap(int argc, char **argv);
 int jt_nodemap_del_idmap(int argc, char **argv);
 int jt_nodemap_test_id(int argc, char **argv);
+int jt_nodemap_info(int argc, char **argv);
 int jt_changelog_register(int argc, char **argv);
 int jt_changelog_deregister(int argc, char **argv);
 
 int jt_changelog_register(int argc, char **argv);
 int jt_changelog_deregister(int argc, char **argv);