Whamcloud - gitweb
LU-3285 lfs: add parameter for Data-on-MDT file
[fs/lustre-release.git] / lustre / utils / lfs.c
index dc07fb9..00ac0b1 100644 (file)
@@ -116,6 +116,7 @@ static int lfs_list_commands(int argc, char **argv);
        "usage: "cmd" [--stripe-count|-c <stripe_count>]\n"             \
        "                 [--stripe-index|-i <start_ost_idx>]\n"        \
        "                 [--stripe-size|-S <stripe_size>]\n"           \
+       "                 [--layout|-L <pattern>]\n"            \
        "                 [--pool|-p <pool_name>]\n"                    \
        "                 [--ost|-o <ost_indices>]\n"                   \
        "                 [--component-end|-E <comp_end>]\n"
@@ -126,6 +127,7 @@ static int lfs_list_commands(int argc, char **argv);
        "\t              respectively)\n"                               \
        "\tstart_ost_idx: OST index of first stripe (-1 default)\n"     \
        "\tstripe_count: Number of OSTs to stripe over (0 default, -1 all)\n" \
+       "\tlayout:       stripe pattern type: raid0, mdt (default raid0)\n"\
        "\tpool_name:    Name of OST pool to use (default none)\n"      \
        "\tost_indices:  List of OST indices, can be repeated multiple times\n"\
        "\t              Indices be specified in a format of:\n"        \
@@ -249,7 +251,7 @@ command_t cmdlist[] = {
          "     [[!] --gid|-g|--group|-G <gid>|<gname>]\n"
          "     [[!] --uid|-u|--user|-U <uid>|<uname>] [[!] --pool <pool>]\n"
         "     [[!] --projid <projid>]\n"
-        "     [[!] --layout|-L released,raid0]\n"
+        "     [[!] --layout|-L released,raid0,mdt]\n"
         "     [[!] --component-count [+-]<comp_cnt>]\n"
         "     [[!] --component-start [+-]N[kMGTPE]]\n"
         "     [[!] --component-end|-E [+-]N[kMGTPE]]\n"
@@ -1017,6 +1019,7 @@ struct lfs_setstripe_args {
        int                      lsa_stripe_off;
        __u32                    lsa_comp_flags;
        int                      lsa_nr_osts;
+       int                      lsa_pattern;
        __u32                   *lsa_osts;
        char                    *lsa_pool_name;
 };
@@ -1031,7 +1034,7 @@ static inline bool setstripe_args_specified(struct lfs_setstripe_args *lsa)
 {
        return (lsa->lsa_stripe_size != 0 || lsa->lsa_stripe_count != 0 ||
                lsa->lsa_stripe_off != -1 || lsa->lsa_pool_name != NULL ||
-               lsa->lsa_comp_end != 0);
+               lsa->lsa_comp_end != 0 || lsa->lsa_pattern != 0);
 }
 
 static int comp_args_to_layout(struct llapi_layout **composite,
@@ -1076,6 +1079,51 @@ static int comp_args_to_layout(struct llapi_layout **composite,
                return rc;
        }
 
+       /* Data-on-MDT component setting */
+       if (lsa->lsa_pattern == LLAPI_LAYOUT_MDT) {
+               /* In case of Data-on-MDT patterns the only extra option
+                * applicable is stripe size option. */
+               if (lsa->lsa_stripe_count) {
+                       fprintf(stderr, "Option 'stripe-count' can't be "
+                               "specified with Data-on-MDT component: %i\n",
+                               lsa->lsa_stripe_count);
+                       return -EINVAL;
+               }
+               if (lsa->lsa_stripe_size) {
+                       fprintf(stderr, "Option 'stripe-size' can't be "
+                               "specified with Data-on-MDT component: %llu\n",
+                               lsa->lsa_stripe_size);
+                       return -EINVAL;
+               }
+               if (lsa->lsa_nr_osts != 0) {
+                       fprintf(stderr, "Option 'ost-list' can't be specified "
+                               "with Data-on-MDT component: '%i'\n",
+                               lsa->lsa_nr_osts);
+                       return -EINVAL;
+               }
+               if (lsa->lsa_stripe_off != -1) {
+                       fprintf(stderr, "Option 'stripe-offset' can't be "
+                               "specified with Data-on-MDT component: %i\n",
+                               lsa->lsa_stripe_off);
+                       return -EINVAL;
+               }
+               if (lsa->lsa_pool_name != 0) {
+                       fprintf(stderr, "Option 'pool' can't be specified "
+                               "with Data-on-MDT component: '%s'\n",
+                               lsa->lsa_pool_name);
+                       return -EINVAL;
+               }
+
+               rc = llapi_layout_pattern_set(layout, lsa->lsa_pattern);
+               if (rc) {
+                       fprintf(stderr, "Set stripe pattern %#x failed. %s\n",
+                               lsa->lsa_pattern, strerror(errno));
+                       return rc;
+               }
+               /* Data-on-MDT component has always single stripe up to end */
+               lsa->lsa_stripe_size = lsa->lsa_comp_end;
+       }
+
        if (lsa->lsa_stripe_size != 0) {
                rc = llapi_layout_stripe_size_set(layout,
                                                  lsa->lsa_stripe_size);
@@ -1386,6 +1434,7 @@ static int lfs_setstripe(int argc, char **argv)
         * the consistent "--stripe-size|-S" for all commands. */
        { .val = 's',   .name = "size",         .has_arg = required_argument },
 #endif
+       { .val = 'L',   .name = "layout",       .has_arg = required_argument },
        { .val = 'S',   .name = "stripe-size",  .has_arg = required_argument },
        { .val = 'S',   .name = "stripe_size",  .has_arg = required_argument },
        /* dirstripe {"mdt-count",    required_argument, 0, 'T'}, */
@@ -1410,7 +1459,7 @@ static int lfs_setstripe(int argc, char **argv)
        if (strcmp(argv[0], "migrate") == 0)
                migrate_mode = true;
 
-       while ((c = getopt_long(argc, argv, "bc:dE:i:I:m:no:p:s:S:v",
+       while ((c = getopt_long(argc, argv, "bc:dE:i:I:m:no:p:L:s:S:v",
                                long_opts, NULL)) >= 0) {
                switch (c) {
                case 0:
@@ -1481,6 +1530,27 @@ static int lfs_setstripe(int argc, char **argv)
                                }
                        }
                        break;
+               case 'L':
+                       if (strcmp(argv[optind - 1], "mdt") == 0) {
+                               /* Can be only the first component */
+                               if (layout != NULL) {
+                                       fprintf(stderr, "error: 'mdt' layout "
+                                               "can be only the first one\n");
+                                       goto error;
+                               }
+                               if (lsa.lsa_comp_end > (1ULL << 30)) { /* 1Gb */
+                                       fprintf(stderr, "error: 'mdt' layout "
+                                               "size is too big\n");
+                                       goto error;
+                               }
+                               lsa.lsa_pattern = LLAPI_LAYOUT_MDT;
+                       } else if (strcmp(argv[optind - 1], "raid0") != 0) {
+                               fprintf(stderr, "error: layout '%s' is "
+                                       "unknown, supported layouts are: "
+                                       "'mdt', 'raid0'\n", argv[optind]);
+                               goto error;
+                       }
+                       break;
                case 'i':
                        if (strcmp(argv[optind - 1], "--index") == 0)
                                fprintf(stderr, "warning: '--index' deprecated"
@@ -1684,7 +1754,6 @@ static int lfs_setstripe(int argc, char **argv)
                param->lsp_stripe_size = lsa.lsa_stripe_size;
                param->lsp_stripe_offset = lsa.lsa_stripe_off;
                param->lsp_stripe_count = lsa.lsa_stripe_count;
-               param->lsp_stripe_pattern = 0;
                param->lsp_pool = lsa.lsa_pool_name;
                param->lsp_is_specific = false;
                if (lsa.lsa_nr_osts > 0) {
@@ -1850,17 +1919,19 @@ static inline int gid2name(char **name, unsigned int id)
 
 static int name2layout(__u32 *layout, char *name)
 {
-       char *ptr, *lyt;
+       char *ptr, *layout_name;
 
        *layout = 0;
        for (ptr = name; ; ptr = NULL) {
-               lyt = strtok(ptr, ",");
-               if (lyt == NULL)
+               layout_name = strtok(ptr, ",");
+               if (layout_name == NULL)
                        break;
-               if (strcmp(lyt, "released") == 0)
+               if (strcmp(layout_name, "released") == 0)
                        *layout |= LOV_PATTERN_F_RELEASED;
-               else if (strcmp(lyt, "raid0") == 0)
+               else if (strcmp(layout_name, "raid0") == 0)
                        *layout |= LOV_PATTERN_RAID0;
+               else if (strcmp(layout_name, "mdt") == 0)
+                       *layout |= LOV_PATTERN_MDT;
                else
                        return -1;
        }