From ddae357087fee63da36483c8432e178c3cacf903 Mon Sep 17 00:00:00 2001 From: Kit Westneat Date: Fri, 12 Dec 2014 01:17:52 -0500 Subject: [PATCH] LU-5868 nodemap: Add nodemap_info to lctl 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 Change-Id: I5d5ac44ec30bad49878be76168954dd231656421 Reviewed-on: http://review.whamcloud.com/13044 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/utils/lctl.c | 15 +++--- lustre/utils/lustre_cfg.c | 124 ++++++++++++++++++++++++++++++++++------------ lustre/utils/obdctl.h | 1 + 3 files changed, 103 insertions(+), 37 deletions(-) diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 9b1d0a3..a908de0 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -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, - "list the Lustre or LNET parameter name\n" - "usage: list_param [-F|-R] \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] \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"}, @@ -283,6 +284,8 @@ command_t cmdlist[] = { "usage: nodemap_test_nid "}, {"nodemap_test_id", jt_nodemap_test_id, 0, "Usage: nodemap_test_id --nid --idtype [uid|gid] --id "}, + {"nodemap_info", jt_nodemap_info, 0, + "Usage: nodemap_info [list|nodemap_name|all]"}, /* Changelog commands */ {"=== Changelogs ==", jt_noop, 0, "changelog user management"}, diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index a7af694..cc9763d 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -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_only_dir:1; }; /* 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_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; - if (po_show_type) { + if (popt->po_show_type || popt->po_only_dir) { 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/"); @@ -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. */ - if (po_show_type && suffix != NULL) + if (popt->po_show_type && suffix != NULL) 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) { - 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) @@ -814,7 +824,11 @@ static int listparam_display(struct param_opts *popt, char *pattern) 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", @@ -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); - valuename = display_name(filename, len, popt->po_show_type); + valuename = display_name(filename, len, popt); 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), - false); + popt); } /* Write the contents of file to stdout */ @@ -1025,6 +1039,54 @@ int jt_lcfg_getparam(int argc, char **argv) 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; @@ -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), - false); + popt); if (valuename) printf("%s=%s\n", valuename, value); } diff --git a/lustre/utils/obdctl.h b/lustre/utils/obdctl.h index d0ef67f..95c3c59 100644 --- a/lustre/utils/obdctl.h +++ b/lustre/utils/obdctl.h @@ -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_info(int argc, char **argv); int jt_changelog_register(int argc, char **argv); int jt_changelog_deregister(int argc, char **argv); -- 1.8.3.1