Whamcloud - gitweb
LU-399 do not use mke2fs -E resize for large LUNs
[fs/lustre-release.git] / lustre / utils / lustre_cfg.c
index 3d88065..b2ed7e9 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
@@ -491,19 +491,48 @@ int jt_lcfg_param(int argc, char **argv)
 }
 
 /* Param set in config log on MGS */
-/* conf_param key1=value1 [key2=value2...] */
+/* conf_param key=value */
+/* Note we can actually send mgc conf_params from clients, but currently
+ * that's only done for default file striping (see ll_send_mgc_param),
+ * and not here. */
+/* After removal of a parameter (-d) Lustre will use the default
+ * AT NEXT REBOOT, not immediately. */
 int jt_lcfg_mgsparam(int argc, char **argv)
 {
-        int i, rc;
+        int rc;
+        int del = 0;
         struct lustre_cfg_bufs bufs;
         struct lustre_cfg *lcfg;
+        char *buf = NULL;
 
-        if ((argc >= LUSTRE_CFG_MAX_BUFCOUNT) || (argc <= 1))
+        /* mgs_setparam processes only lctl buf #1 */
+        if ((argc > 3) || (argc <= 1))
                 return CMD_HELP;
 
+        while ((rc = getopt(argc, argv, "d")) != -1) {
+                switch (rc) {
+                        case 'd':
+                                del = 1;
+                                break;
+                        default:
+                                return CMD_HELP;
+                }
+        }
+
         lustre_cfg_bufs_reset(&bufs, NULL);
-        for (i = 1; i < argc; i++) {
-                lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
+        if (del) {
+                char *ptr;
+
+                /* for delete, make it "<param>=\0" */
+                buf = malloc(strlen(argv[optind]) + 2);
+                /* put an '=' on the end in case it doesn't have one */
+                sprintf(buf, "%s=", argv[optind]);
+                /* then truncate after the first '=' */
+                ptr = strchr(buf, '=');
+                *(++ptr) = '\0';
+                lustre_cfg_bufs_set_string(&bufs, 1, buf);
+        } else {
+                lustre_cfg_bufs_set_string(&bufs, 1, argv[optind]);
         }
 
         /* We could put other opcodes here. */
@@ -511,6 +540,8 @@ int jt_lcfg_mgsparam(int argc, char **argv)
 
         rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
         lustre_cfg_free(lcfg);
+        if (buf)
+                free(buf);
         if (rc < 0) {
                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
                         strerror(rc = errno));
@@ -539,6 +570,8 @@ static char *display_name(char *filename, int show_type)
 
         if (strncmp(filename, "lustre/", strlen("lustre/")) == 0)
                 filename += strlen("lustre/");
+        else if (strncmp(filename, "lnet/", strlen("lnet/")) == 0)
+                filename += strlen("lnet/");
 
         /* replace '/' with '.' to match conf_param and sysctl */
         tmp = filename;
@@ -614,9 +647,10 @@ static void clean_path(char *path)
 }
 
 struct param_opts {
-        int only_path;
-        int show_path;
-        int show_type;
+        int only_path:1;
+        int show_path:1;
+        int show_type:1;
+        int recursive:1;
 };
 
 static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
@@ -626,12 +660,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->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;
+                case 'R':
+                        popt->recursive = 1;
+                        break;
                 default:
                         return -1;
                 }
@@ -647,7 +685,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 */
 
-        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));
@@ -656,11 +695,25 @@ static int listparam_display(struct param_opts *popt, char *pattern)
 
         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);
+                if (last) {
+                        strcpy(filename, glob_info.gl_pathv[i]);
+                        strcat(filename, "/*");
+                        listparam_display(popt, filename);
+                }
         }
 
         globfree(&glob_info);
@@ -676,8 +729,12 @@ int jt_lcfg_listparam(int argc, char **argv)
         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;
+        }
 
         for (i = rc; i < argc; i++) {
                 path = argv[i];
@@ -709,6 +766,7 @@ static int getparam_cmdline(int argc, char **argv, struct param_opts *popt)
         popt->show_path = 1;
         popt->only_path = 0;
         popt->show_type = 0;
+        popt->recursive = 0;
 
         while ((ch = getopt(argc, argv, "nNF")) != -1) {
                 switch (ch) {
@@ -848,6 +906,7 @@ static int setparam_cmdline(int argc, char **argv, struct param_opts *popt)
         popt->show_path = 1;
         popt->only_path = 0;
         popt->show_type = 0;
+        popt->recursive = 0;
 
         while ((ch = getopt(argc, argv, "n")) != -1) {
                 switch (ch) {