Whamcloud - gitweb
LU-6052 utils: change "lfs mv" to "lfs migrate" 54/13754/14
authorLai Siyao <lai.siyao@intel.com>
Fri, 13 Feb 2015 08:54:15 +0000 (16:54 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 29 Jul 2015 15:42:14 +0000 (15:42 +0000)
"lfs mv" causes some confusion between mv and migration, change
"lfs mv" to "lfs migrate -m", and mark "lfs mv" deprecated.

Signed-off-by: Lai Siyao <lai.siyao@intel.com>
Change-Id: I72ead14854eb6038ba13fddec81b867bc0542b46
Reviewed-on: http://review.whamcloud.com/13754
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: frank zago <fzago@cray.com>
lustre/include/lustre/lustreapi.h
lustre/tests/recovery-small.sh
lustre/tests/sanity-lfsck.sh
lustre/tests/sanity.sh
lustre/tests/sanityn.sh
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 135a3c8..ce5f6ce 100644 (file)
@@ -267,6 +267,7 @@ extern int llapi_getname(const char *path, char *buf, size_t size);
 
 extern int llapi_search_rootpath(char *pathname, const char *fsname);
 extern int llapi_nodemap_exists(const char *name);
+extern int llapi_migrate_mdt(char *path, struct find_param *param);
 extern int llapi_mv(char *path, struct find_param *param);
 
 struct mntent;
index b58e276..fdc3b15 100755 (executable)
@@ -1899,7 +1899,7 @@ test_110g () {
 
        #define OBD_FAIL_MIGRATE_NET_REP        0x1702
        do_facet mds$MDTIDX lctl set_param fail_loc=0x1702
-       $LFS mv -M $MDTIDX $remote_dir || error "migrate failed"
+       $LFS migrate -m $MDTIDX $remote_dir || error "migrate failed"
        do_facet mds$MDTIDX lctl set_param fail_loc=0x0
 
        for file in $(find $remote_dir); do
index da57b5f..5ddd8d8 100644 (file)
@@ -1612,7 +1612,7 @@ test_15c() {
        #define OBD_FAIL_MIGRATE_DELAY                  0x1803
        do_facet mds2 $LCTL set_param fail_val=5 fail_loc=0x1803
        echo "Migrate $DIR/$tdir/a1 from MDT1 to MDT0 with delay"
-       $LFS mv -M 0 $DIR/$tdir/a1 &
+       $LFS migrate -m 0 $DIR/$tdir/a1 &
 
        sleep 1
        echo "Trigger layout LFSCK to race with the migration"
index 4828b19..1eabf32 100644 (file)
@@ -664,7 +664,7 @@ test_17n() {
                mkdir -p $DIR/$tdir/remote_dir_${i}
                createmany -o $DIR/$tdir/remote_dir_${i}/f 10 ||
                        error "create files under remote dir failed $i"
-               $LFS mv --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
+               $LFS migrate --mdt-index 1 $DIR/$tdir/remote_dir_${i} ||
                        error "migrate remote dir error $i"
        done
        check_fs_consistency_17n || error "e2fsck report error after migration"
@@ -12588,7 +12588,7 @@ test_230b() {
        ln -s $migrate_dir/$tfile $migrate_dir/${tfile}_ln
        ln -s $other_dir/$tfile $migrate_dir/${tfile}_ln_other
 
-       $LFS mv -v -M $MDTIDX $migrate_dir ||
+       $LFS migrate -m $MDTIDX $migrate_dir ||
                error "migrate remote dir error"
 
        echo "migratate to MDT1, then checking.."
@@ -12652,7 +12652,7 @@ test_230b() {
 
        #migrate back to MDT0
        MDTIDX=0
-       $LFS mv -v -M $MDTIDX $migrate_dir ||
+       $LFS migrate -m $MDTIDX $migrate_dir ||
                error "migrate remote dir error"
 
        echo "migrate back to MDT0, checking.."
@@ -12729,7 +12729,7 @@ test_230c() {
        do_facet mds1 lctl set_param fail_loc=0x20001801
        do_facet mds1 lctl  set_param fail_val=5
        local t=$(ls $migrate_dir | wc -l)
-       $LFS mv --mdt-index $MDTIDX $migrate_dir &&
+       $LFS migrate --mdt-index $MDTIDX $migrate_dir &&
                error "migrate should fail after 5 entries"
        local u=$(ls $migrate_dir | wc -l)
        [ "$u" == "$t" ] || error "$u != $t during migration"
@@ -12741,7 +12741,7 @@ test_230c() {
        do_facet mds1 lctl set_param fail_loc=0
        do_facet mds1 lctl set_param fail_val=0
 
-       $LFS mv -M $MDTIDX $migrate_dir ||
+       $LFS migrate -m $MDTIDX $migrate_dir ||
                error "migrate open files should failed with open files"
 
        echo "Finish migration, then checking.."
@@ -12773,7 +12773,8 @@ test_230d() {
                        error "create files under remote dir failed $i"
        done
 
-       $LFS mv -M $MDTIDX -v $migrate_dir || error "migrate remote dir error"
+       $LFS migrate -m $MDTIDX $migrate_dir ||
+               error "migrate remote dir error"
 
        echo "Finish migration, then checking.."
        for file in $(find $migrate_dir); do
index 5871961..1e65fda 100644 (file)
@@ -3095,12 +3095,12 @@ test_80() {
        # give multiop a chance to open
        sleep 1
 
-       $LFS mv -M $MDTIDX $DIR1/$tdir &&
+       $LFS migrate -m $MDTIDX $DIR1/$tdir &&
                error "migrate open files should failed with open files"
 
        kill -USR1 $pid
 
-       $LFS mv -M $MDTIDX $DIR1/$tdir ||
+       $LFS migrate -m $MDTIDX $DIR1/$tdir ||
                        error "migrate remote dir error"
 
        echo "Finish migration, then checking.."
index 378cc78..767c5d4 100644 (file)
@@ -352,10 +352,16 @@ command_t cmdlist[] = {
         "usage: hsm_cancel [--filelist FILELIST] [--data DATA] <file> ..."},
        {"swap_layouts", lfs_swap_layouts, 0, "Swap layouts between 2 files.\n"
         "usage: swap_layouts <path1> <path2>"},
-       {"migrate", lfs_setstripe, 0, "migrate file from one OST layout to "
-        "another.\n" MIGRATE_USAGE},
+       {"migrate", lfs_setstripe, 0,
+        "migrate file/directory between MDTs, or migrate file from one OST "
+        "layout\nto another (may be not safe with concurent writes).\n"
+        "usage: migrate   [--mdt-index|-m <mdt_idx>] <directory|filename>]\n"
+        "\tmdt_idx:      MDT index to migrate to\n"
+        " or\n"
+        MIGRATE_USAGE},
        {"mv", lfs_mv, 0,
-        "To move directories between MDTs.\n"
+        "To move directories between MDTs. This command is deprecated, "
+        "use \"migrate\" instead.\n"
         "usage: mv <directory|filename> [--mdt-index|-M] <mdt_index> "
         "[--verbose|-v]\n"},
        {"help", Parser_help, 0, "help"},
@@ -854,7 +860,11 @@ static int parse_targets(__u32 *osts, int size, int offset, char *arg)
 /* functions */
 static int lfs_setstripe(int argc, char **argv)
 {
-       struct llapi_stripe_param       *param;
+       struct llapi_stripe_param       *param = NULL;
+       struct find_param                migrate_mdt_param = {
+               .fp_max_depth = -1,
+               .fp_mdt_index = -1,
+       };
        char                            *fname;
        int                              result;
        int                              result2 = 0;
@@ -867,6 +877,7 @@ static int lfs_setstripe(int argc, char **argv)
        char                            *stripe_off_arg = NULL;
        char                            *stripe_count_arg = NULL;
        char                            *pool_name_arg = NULL;
+       char                            *mdt_idx_arg = NULL;
        unsigned long long               size_units = 1;
        bool                             migrate_mode = false;
        __u64                            migration_flags = 0;
@@ -893,6 +904,8 @@ static int lfs_setstripe(int argc, char **argv)
 #endif
                {"stripe-index", required_argument, 0, 'i'},
                {"stripe_index", required_argument, 0, 'i'},
+               {"mdt-index",    required_argument, 0, 'm'},
+               {"mdt_index",    required_argument, 0, 'm'},
                {"ost-list",     required_argument, 0, 'o'},
                {"ost_list",     required_argument, 0, 'o'},
                {"pool",         required_argument, 0, 'p'},
@@ -914,7 +927,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:di:o:p:s:S:",
+       while ((c = getopt_long(argc, argv, "bc:di:m:o:p:s:S:",
                                long_opts, NULL)) >= 0) {
                switch (c) {
                case 0:
@@ -962,6 +975,14 @@ static int lfs_setstripe(int argc, char **argv)
 #endif
                        stripe_off_arg = optarg;
                        break;
+               case 'm':
+                       if (!migrate_mode) {
+                               fprintf(stderr, "--mdt-index is valid only for"
+                                               " migrate mode\n");
+                               return CMD_HELP;
+                       }
+                       mdt_idx_arg = optarg;
+                       break;
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 53, 0)
                case 's':
 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 6, 53, 0)
@@ -997,6 +1018,12 @@ static int lfs_setstripe(int argc, char **argv)
                return CMD_HELP;
        }
 
+       if (mdt_idx_arg != NULL && optind > 3) {
+               fprintf(stderr, "error: %s: cannot specify -m with other "
+                       "options\n", argv[0]);
+               return CMD_HELP;
+       }
+
        if (pool_name_arg && strlen(pool_name_arg) > LOV_MAXPOOLNAME) {
                fprintf(stderr,
                        "error: %s: pool name '%s' is too long (max is %d characters)\n",
@@ -1033,37 +1060,47 @@ static int lfs_setstripe(int argc, char **argv)
                 }
         }
 
-       /* initialize stripe parameters */
-       param = calloc(1, offsetof(typeof(*param), lsp_osts[nr_osts]));
-       if (param == NULL) {
-               fprintf(stderr, "error: %s: run out of memory\n", argv[0]);
-               return CMD_HELP;
-       }
-
-       param->lsp_stripe_size = st_size;
-       param->lsp_stripe_offset = st_offset;
-       param->lsp_stripe_count = st_count;
-       param->lsp_stripe_pattern = 0;
-       param->lsp_pool = pool_name_arg;
-       param->lsp_is_specific = false;
-       if (nr_osts > 0) {
-               if (st_count > 0 && nr_osts != st_count) {
-                       fprintf(stderr, "error: %s: stripe count '%d' doesn't "
-                               "match the number of OSTs: %d\n",
-                               argv[0], st_count, nr_osts);
-                       free(param);
+       if (mdt_idx_arg != NULL) {
+               /* initialize migrate mdt parameters */
+               migrate_mdt_param.fp_mdt_index = strtoul(mdt_idx_arg, &end, 0);
+               if (*end != '\0') {
+                       fprintf(stderr, "error: %s: bad MDT index '%s'\n",
+                               argv[0], mdt_idx_arg);
                        return CMD_HELP;
                }
+               migrate_mdt_param.fp_migrate = 1;
+       } else {
+               /* initialize stripe parameters */
+               param = calloc(1, offsetof(typeof(*param), lsp_osts[nr_osts]));
+               if (param == NULL) {
+                       fprintf(stderr, "error: %s: run out of memory\n",
+                               argv[0]);
+                       return CMD_HELP;
+               }
+
+               param->lsp_stripe_size = st_size;
+               param->lsp_stripe_offset = st_offset;
+               param->lsp_stripe_count = st_count;
+               param->lsp_stripe_pattern = 0;
+               param->lsp_pool = pool_name_arg;
+               param->lsp_is_specific = false;
+               if (nr_osts > 0) {
+                       if (st_count > 0 && nr_osts != st_count) {
+                               fprintf(stderr, "error: %s: stripe count '%d' "
+                                       "doesn't match the number of OSTs: %d\n"
+                                       , argv[0], st_count, nr_osts);
+                               free(param);
+                               return CMD_HELP;
+                       }
 
-               param->lsp_is_specific = true;
-               param->lsp_stripe_count = nr_osts;
-               memcpy(param->lsp_osts, osts, sizeof(*osts) * nr_osts);
+                       param->lsp_is_specific = true;
+                       param->lsp_stripe_count = nr_osts;
+                       memcpy(param->lsp_osts, osts, sizeof(*osts) * nr_osts);
+               }
        }
 
        for (fname = argv[optind]; fname != NULL; fname = argv[++optind]) {
-               if (migrate_mode) {
-                       result = lfs_migrate(fname, migration_flags, param);
-               } else {
+               if (!migrate_mode) {
                        result = llapi_file_open_param(fname,
                                                       O_CREAT | O_WRONLY,
                                                       0644, param);
@@ -1071,13 +1108,17 @@ static int lfs_setstripe(int argc, char **argv)
                                close(result);
                                result = 0;
                        }
+               } else if (mdt_idx_arg != NULL) {
+                       result = llapi_migrate_mdt(fname, &migrate_mdt_param);
+               } else {
+                       result = lfs_migrate(fname, migration_flags, param);
                }
                if (result) {
                        /* Save the first error encountered. */
                        if (result2 == 0)
                                result2 = result;
                        fprintf(stderr,
-                               "error: %s: %s stripe file '%s' failed\n",
+                               "error: %s: %s file '%s' failed\n",
                                argv[0], migrate_mode ? "migrate" : "create",
                                fname);
                        continue;
@@ -2027,7 +2068,7 @@ static int lfs_mv(int argc, char **argv)
        }
 
        param.fp_migrate = 1;
-       rc = llapi_mv(argv[optind], &param);
+       rc = llapi_migrate_mdt(argv[optind], &param);
        if (rc != 0)
                fprintf(stderr, "%s: cannot migrate '%s' to MDT%04x: %s\n",
                        argv[0], argv[optind], param.fp_mdt_index,
index fbcfb2d..ea68c7e 100644 (file)
@@ -3302,7 +3302,7 @@ decided:
        return 0;
 }
 
-static int cb_mv_init(char *path, DIR *parent, DIR **dirp,
+static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
                      void *param_data, struct dirent64 *de)
 {
        struct find_param       *param = (struct find_param *)param_data;
@@ -3346,7 +3346,8 @@ static int cb_mv_init(char *path, DIR *parent, DIR **dirp,
        ret = ioctl(fd, LL_IOC_MIGRATE, rawbuf);
        if (ret != 0) {
                ret = -errno;
-               fprintf(stderr, "%s migrate failed %d\n", path, ret);
+               fprintf(stderr, "%s migrate failed: %s (%d)\n",
+                       path, strerror(-ret), ret);
                goto out;
        } else if (param->fp_verbose & VERBOSE_DETAIL) {
                fprintf(stdout, "migrate %s to MDT%d\n",
@@ -3375,9 +3376,23 @@ out:
        return ret;
 }
 
+int llapi_migrate_mdt(char *path, struct find_param *param)
+{
+       return param_callback(path, cb_migrate_mdt_init, cb_common_fini, param);
+}
+
 int llapi_mv(char *path, struct find_param *param)
 {
-       return param_callback(path, cb_mv_init, cb_common_fini, param);
+#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 9, 53, 0)
+       static bool printed;
+
+       if (!printed) {
+               llapi_error(LLAPI_MSG_ERROR, -ESTALE,
+                           "llapi_mv() is deprecated, use llapi_migrate_mdt()\n");
+               printed = true;
+       }
+#endif
+       return llapi_migrate_mdt(path, param);
 }
 
 int llapi_find(char *path, struct find_param *param)