Whamcloud - gitweb
LU-6785 utils: compatibility fix for lfs migrate 38/16238/4
authorHenri Doreau <henri.doreau@cea.fr>
Fri, 4 Sep 2015 08:17:53 +0000 (10:17 +0200)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 10 Sep 2015 04:03:47 +0000 (04:03 +0000)
Make lfs migrate able to operate against servers that support
file lease but not atomic swap/close (as added in LU-4840).

Make blocking mode the default and add a --non-block switch to
lfs accordingly.

Signed-off-by: Henri Doreau <henri.doreau@cea.fr>
Change-Id: I7d3cdccfcc5bec78e69c69615ee29cac11f6f31f
Reviewed-on: http://review.whamcloud.com/16238
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/lfs.c

index 2ce7586..c58113d 100644 (file)
@@ -148,10 +148,12 @@ static int lfs_mv(int argc, char **argv);
 #define MIGRATE_USAGE                                                  \
        SSM_CMD_COMMON("migrate  ")                                     \
        "                 [--block|-b]\n"                               \
+       "                 [--non-block|-n]\n"                           \
        "                 <filename>\n"                                 \
        SSM_HELP_COMMON                                                 \
        "\n"                                                            \
-       "\tblock:        Block file access during data migration\n"     \
+       "\tblock:        Block file access during data migration (default)\n" \
+       "\tnon-block:    Abort migrations if concurrent access is detected\n" \
 
 static const char      *progname;
 static bool             file_lease_supported = true;
@@ -374,7 +376,7 @@ command_t cmdlist[] = {
 };
 
 
-#define MIGRATION_BLOCKS 1
+#define MIGRATION_NONBLOCK     1
 
 /**
  * Internal helper for migrate_copy_data(). Check lease and report error if
@@ -745,16 +747,19 @@ static int lfs_migrate(char *name, __u64 migration_flags,
                }
        }
 
-       if (migration_flags & MIGRATION_BLOCKS || !file_lease_supported) {
-               /* Blocking mode, forced if servers do not support file lease */
-               rc = migrate_block(fd, fdv, &st, buf_size, name);
-       } else {
+       if (migration_flags & MIGRATION_NONBLOCK && file_lease_supported) {
                rc = migrate_nonblock(fd, fdv, &st, buf_size, name);
                if (rc == 0) {
                        have_lease_rdlck = false;
                        fdv = -1; /* The volatile file is closed as we put the
                                   * lease in non-blocking mode. */
                }
+       } else {
+               /* Blocking mode (forced if servers do not support file lease).
+                * It is also the default mode, since we cannot distinguish
+                * between a broken lease and a server that does not support
+                * atomic swap/close (LU-6785) */
+               rc = migrate_block(fd, fdv, &st, buf_size, name);
        }
 
 error:
@@ -881,12 +886,13 @@ static int lfs_setstripe(int argc, char **argv)
        char                            *mdt_idx_arg = NULL;
        unsigned long long               size_units = 1;
        bool                             migrate_mode = false;
+       bool                             migration_block = false;
        __u64                            migration_flags = 0;
        __u32                            osts[LOV_MAX_STRIPE_COUNT] = { 0 };
        int                              nr_osts = 0;
 
        struct option            long_opts[] = {
-               /* valid only in migrate mode */
+               /* --block is only valid in migrate mode */
                {"block",        no_argument,       0, 'b'},
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 53, 0)
                /* This formerly implied "stripe-count", but was explicitly
@@ -907,6 +913,8 @@ static int lfs_setstripe(int argc, char **argv)
                {"stripe_index", required_argument, 0, 'i'},
                {"mdt-index",    required_argument, 0, 'm'},
                {"mdt_index",    required_argument, 0, 'm'},
+               /* --non-block is only valid in migrate mode */
+               {"non-block",    no_argument,       0, 'n'},
                {"ost-list",     required_argument, 0, 'o'},
                {"ost_list",     required_argument, 0, 'o'},
                {"pool",         required_argument, 0, 'p'},
@@ -928,7 +936,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:m:o:p:s:S:",
+       while ((c = getopt_long(argc, argv, "bc:di:m:no:p:s:S:",
                                long_opts, NULL)) >= 0) {
                switch (c) {
                case 0:
@@ -940,7 +948,7 @@ static int lfs_setstripe(int argc, char **argv)
                                                " migrate mode\n");
                                return CMD_HELP;
                        }
-                       migration_flags |= MIGRATION_BLOCKS;
+                       migration_block = true;
                        break;
                case 'c':
 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 6, 53, 0)
@@ -984,6 +992,14 @@ static int lfs_setstripe(int argc, char **argv)
                        }
                        mdt_idx_arg = optarg;
                        break;
+               case 'n':
+                       if (!migrate_mode) {
+                               fprintf(stderr, "--non-block is valid only for"
+                                               " migrate mode\n");
+                               return CMD_HELP;
+                       }
+                       migration_flags |= MIGRATION_NONBLOCK;
+                       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)
@@ -1025,6 +1041,13 @@ static int lfs_setstripe(int argc, char **argv)
                return CMD_HELP;
        }
 
+       if ((migration_flags & MIGRATION_NONBLOCK) && migration_block) {
+               fprintf(stderr,
+                       "error: %s: cannot specify --non-block and --block\n",
+                       argv[0]);
+               return CMD_HELP;
+       }
+
        if (pool_name_arg != NULL) {
                char    *ptr;
                int     rc;