From a6f497a18ae38cd29f3d57a5c220efc975659b15 Mon Sep 17 00:00:00 2001 From: LiuYing Date: Wed, 12 May 2010 15:22:09 +0800 Subject: [PATCH] b=22455 add list_param to b1_8 add list_param to b1_8 and add "-R" option to list params recursively o=adilger i=johann i=nathan i=emoly.liu --- lustre/utils/lctl.c | 7 +++ lustre/utils/lustre_cfg.c | 112 ++++++++++++++++++++++++++++++++++++++++++++-- lustre/utils/obdctl.h | 1 + 3 files changed, 117 insertions(+), 3 deletions(-) diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 3deb1a9..17efa93 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -149,6 +149,13 @@ command_t cmdlist[] = { "usage: set_param [-n] \n" "Set the value of the Lustre or LNET parameter at the specified path\n" " -n Disable printing of the key name when printing values."}, + {"list_param", jt_lcfg_listparam, 0, + "list the Lustre or LNET parameter name\n" + "usage: list_param [-FR] \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"}, /* Debug commands */ {"==== debugging control ===", jt_noop, 0, "debug"}, diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index 047c0de..0ff48bd 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -527,11 +527,11 @@ static char *display_name(char *filename, int show_type) /* append the indicator to entries*/ if (show_type) { if (S_ISDIR(st.st_mode)) - filename[strlen(filename)] = '/'; + strcat(filename, "/"); else if (S_ISLNK(st.st_mode)) - filename[strlen(filename)] = '@'; + strcat(filename, "@"); else if (st.st_mode & S_IWUSR) - filename[strlen(filename)] = '='; + strcat(filename, "="); } return filename; @@ -595,8 +595,114 @@ struct param_opts { int only_path; int show_path; int show_type; + int recursive; }; +static int listparam_cmdline(int argc, char **argv, struct param_opts *popt) +{ + int ch; + popt->show_path = 1; + popt->only_path = 1; + popt->show_type = 0; + popt->recursive = 0; + + while ((ch = getopt(argc, argv, "FR")) != -1) { + switch (ch) { + case 'F': + popt->show_type = 1; + break; + case 'R': + popt->recursive = 1; + break; + default: + return -1; + } + } + + return optind; +} + +static int listparam_display(struct param_opts *popt, char *pattern) +{ + int rc; + int i; + glob_t glob_info; + char filename[PATH_MAX + 1]; /* extra 1 byte for file type */ + + 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)); + return -ESRCH; + } + + for (i = 0; i < glob_info.gl_pathc; i++) { + char *valuename; + 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); + if (last) { + strcpy(filename, glob_info.gl_pathv[i]); + strcat(filename, "/*"); + listparam_display(popt, filename); + } + } + + globfree(&glob_info); + return rc; +} + +int jt_lcfg_listparam(int argc, char **argv) +{ + int fp; + int rc = 0, i; + struct param_opts popt; + char pattern[PATH_MAX]; + char *path; + + rc = listparam_cmdline(argc, argv, &popt); + 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; + } + + for (i = rc; i < argc; i++) { + path = argv[i]; + + clean_path(path); + + /* If the entire path is specified as input */ + fp = open(path, O_RDONLY); + if (fp < 0) { + snprintf(pattern, PATH_MAX, + "/proc/{fs,sys}/{lnet,lustre}/%s", path); + } else { + strcpy(pattern, path); + close(fp); + } + + rc = listparam_display(&popt, pattern); + if (rc < 0) + return rc; + } + + return 0; +} + static int getparam_cmdline(int argc, char **argv, struct param_opts *popt) { int ch; diff --git a/lustre/utils/obdctl.h b/lustre/utils/obdctl.h index 0a61a5e..2716ca7 100644 --- a/lustre/utils/obdctl.h +++ b/lustre/utils/obdctl.h @@ -113,6 +113,7 @@ int jt_lcfg_param(int argc, char **argv); int jt_lcfg_mgsparam(int argc, char **argv); int jt_lcfg_getparam(int argc, char **argv); int jt_lcfg_setparam(int argc, char **argv); +int jt_lcfg_listparam(int argc, char **argv); int obd_add_uuid(char *uuid, lnet_nid_t nid); -- 1.8.3.1