Whamcloud - gitweb
LU-8314 lfs: improve getdirstripe interface
[fs/lustre-release.git] / lustre / utils / lfs.c
index 0f9cd3c..da0ccf7 100644 (file)
@@ -160,7 +160,7 @@ static int lfs_ladvise(int argc, char **argv);
        "               [--mdt-count|-c stripe_count>\n"        \
        "               [--mdt-index|-i mdt_index]\n"           \
        "               [--mdt-hash|-t mdt_hash]\n"             \
-       "               [--default_stripe|-D] [--mode|-m mode] <dir>\n" \
+       "               [--default|-D] [--mode|-m mode] <dir>\n"        \
        "\tstripe_count: stripe count of the striped directory\n"       \
        "\tmdt_index: MDT index of first stripe\n"                      \
        "\tmdt_hash:  hash type of the striped directory. mdt types:\n" \
@@ -198,9 +198,9 @@ command_t cmdlist[] = {
        {"getdirstripe", lfs_getdirstripe, 0,
         "To list the striping info for a given directory\n"
         "or recursively for all directories in a directory tree.\n"
-        "usage: getdirstripe [--obd|-O <uuid>] [--quiet|-q] [--verbose|-v]\n"
-        "               [--count|-c ] [--index|-i ] [--raw|-R]\n"
-        "               [--recursive | -r] [ --default_stripe | -D ] <dir> "},
+        "usage: getdirstripe [--obd|-O <uuid>] [--mdt-count|-c]\n"
+        "                    [--mdt-index|-i] [--mdt-hash|-t]\n"
+        "                    [--recursive|-r] [--default|-D] <dir> ..."},
        {"mkdir", lfs_setdirstripe, 0,
         "To create a striped directory on a specified MDT. This can only\n"
         "be done on MDT0 with the right of administrator.\n"
@@ -1966,9 +1966,68 @@ static int lfs_getstripe(int argc, char **argv)
 static int lfs_getdirstripe(int argc, char **argv)
 {
        struct find_param param = { 0 };
+       struct option long_opts[] = {
+               {"mdt-count",   no_argument,            0, 'c'},
+               {"mdt-index",   no_argument,            0, 'i'},
+               {"recursive",   no_argument,            0, 'r'},
+               {"mdt-hash",    no_argument,            0, 't'},
+               {"default",     no_argument,            0, 'D'},
+               {"obd",         required_argument,      0, 'O'},
+               {0, 0, 0, 0}
+       };
+       int c, rc;
 
        param.fp_get_lmv = 1;
-       return lfs_getstripe_internal(argc, argv, &param);
+
+       while ((c = getopt_long(argc, argv, "cirtDO:", long_opts, NULL)) != -1)
+       {
+               switch (c) {
+               case 'O':
+                       if (param.fp_obd_uuid) {
+                               fprintf(stderr,
+                                       "error: %s: only one obduuid allowed",
+                                       argv[0]);
+                               return CMD_HELP;
+                       }
+                       param.fp_obd_uuid = (struct obd_uuid *)optarg;
+                       break;
+               case 'c':
+                       param.fp_verbose |= VERBOSE_COUNT;
+                       break;
+               case 'i':
+                       param.fp_verbose |= VERBOSE_OFFSET;
+                       break;
+               case 't':
+                       param.fp_verbose |= VERBOSE_HASH_TYPE;
+                       break;
+               case 'D':
+                       param.fp_get_default_lmv = 1;
+                       break;
+               case 'r':
+                       param.fp_recursive = 1;
+                       break;
+               default:
+                       return CMD_HELP;
+               }
+       }
+
+       if (optind >= argc)
+               return CMD_HELP;
+
+       if (param.fp_recursive)
+               param.fp_max_depth = -1;
+
+       if (!param.fp_verbose)
+               param.fp_verbose = VERBOSE_DEFAULT;
+
+       do {
+               rc = llapi_getstripe(argv[optind], &param);
+       } while (++optind < argc && !rc);
+
+       if (rc)
+               fprintf(stderr, "error: %s failed for %s.\n",
+                       argv[0], argv[optind - 1]);
+       return rc;
 }
 
 /* functions */
@@ -2005,7 +2064,10 @@ static int lfs_setdirstripe(int argc, char **argv)
                {"hash-type",   required_argument, 0, 't'},
 #endif
                {"mdt-hash",    required_argument, 0, 't'},
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                {"default_stripe", no_argument, 0, 'D'},
+#endif
+               {"default",     no_argument, 0, 'D'},
                {0, 0, 0, 0}
        };
 
@@ -2101,15 +2163,23 @@ static int lfs_setdirstripe(int argc, char **argv)
                previous_mode = umask(0);
        }
 
-       if (stripe_hash_opt == NULL ||
-           strcmp(stripe_hash_opt, LMV_HASH_NAME_FNV_1A_64) == 0) {
+       if (stripe_hash_opt == NULL) {
                hash_type = LMV_HASH_TYPE_FNV_1A_64;
-       } else if (strcmp(stripe_hash_opt, LMV_HASH_NAME_ALL_CHARS) == 0) {
-               hash_type = LMV_HASH_TYPE_ALL_CHARS;
        } else {
-               fprintf(stderr, "error: %s: bad stripe hash type '%s'\n",
-                       argv[0], stripe_hash_opt);
-               return CMD_HELP;
+               int i;
+
+               for (i = LMV_HASH_TYPE_ALL_CHARS; i < LMV_HASH_TYPE_MAX; i++)
+                       if (strcmp(stripe_hash_opt, mdt_hash_name[i]) == 0)
+                               break;
+
+               if (i == LMV_HASH_TYPE_MAX) {
+                       fprintf(stderr,
+                               "error: %s: bad stripe hash type '%s'\n",
+                               argv[0], stripe_hash_opt);
+                       return CMD_HELP;
+               }
+
+               hash_type = i;
        }
 
        /* get the stripe count */