Whamcloud - gitweb
LU-13403 utils: mirror-count not required for mirror extend 77/55677/7
authorFrederick Dilger <fdilger@whamcloud.com>
Tue, 9 Jul 2024 19:11:20 +0000 (13:11 -0600)
committerOleg Drokin <green@whamcloud.com>
Wed, 31 Jul 2024 16:03:45 +0000 (16:03 +0000)
If [--mirror-count|-N] is not specified for 'lfs mirror extend', '-N'
will be added to the option arguments before lfs_setstripe_internal()
is called.

The lustre manual states for 'lfs mirror extend':
    "The mirror_count argument is optional and default to 1 if it is
     not specified."
Which can be interpretend as [--mirror-count|-N] does not need to be
specified rather than the MIRROR_COUNT being optional.

It also makes sense that someone who is using 'lfs mirror extend' in
fact intends to extend the mirror count, so it would make sense to
have a default for mirror-count without it having to be specified.

Signed-off-by: Frederick Dilger <fdilger@whamcloud.com>
Change-Id: I01bea6cec71fbf61c617cf27a52d7fb24fd4b06d
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55677
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/doc/lfs-mirror-extend.1
lustre/tests/sanity-flr.sh
lustre/utils/lfs.c

index aa08df7..4076be9 100644 (file)
@@ -6,7 +6,7 @@ lfs-mirror-extend \- add mirror(s) to an existing file
 .ad l
 .B lfs mirror extend
 [\fB\-\-no\-verify\fR]
-\fB\-\-mirror\-count\fR|\fB\-N\fR[\fIMIRROR_COUNT\fR]
+[\fB\-\-mirror\-count\fR|\fB\-N\fR[\fIMIRROR_COUNT\fR]]
 [\fB\-\-bandwidth\-limit\fR|\fB\-W\fR \fIBANDWIDTH\fR]
 [\fB\-\-stats\fR|\fB\-\-stats\-interval\fR=\fISTATS_INTERVAL\fR]
 [\fISETSTRIPE_OPTIONS\fR|\fB\-f\fR \fIVICTIM_FILE\fR]
@@ -19,11 +19,12 @@ The file \fIFILENAME\fR can already be a mirrored file, or just a regular
 non-mirrored file. If it's a non-mirrored file, then the command will convert it
 to a mirrored file.
 .br
-The \fB\-\-mirror\-count\fR|\fB\-N\fR option is required and indicates how many
+The \fB\-\-mirror\-count\fR|\fB\-N\fR option is optional and indicates how many
 mirrors that have the same layout will be added. It can be repeated multiple
 times to separate mirrors that have different layouts. The \fIMIRROR_COUNT\fR
 argument is optional and defaults to 1 if it's not specified; if specified, it
-must follow the option without a space.
+must follow the option without a space. If \fB\-\-mirror\-count\fR|\fB\-N\fR is
+not specified, the default value of 1 will be used.
 .br
 The \fISETSTRIPE_OPTIONS\fR specify the specific layout for the mirror. It can
 be a plain layout with specific striping pattern or a composite layout like
index 7c51533..04317ca 100644 (file)
@@ -518,15 +518,16 @@ test_0d() {
        # create parent directory
        mkdir $td || error "mkdir $td failed"
 
-       $mirror_cmd $tf &> /dev/null && error "miss -N option"
        $mirror_cmd -N $tf &> /dev/null && error "$tf does not exist"
 
        # create a non-mirrored file, convert it to a mirrored file and extend
        touch $tf || error "touch $tf failed"
        $mirror_cmd -N $tf || error "convert and extend $tf failed"
        verify_mirror_count $tf 2
+       $mirror_cmd $tf || error "extend $tf without --mirror-count|-N failed"
+       verify_mirror_count $tf 3
        ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' '))
-       for ((i = 0; i < 2; i++)); do
+       for ((i = 0; i < 3; i++)); do
                verify_comp_attrs $tf ${ids[$i]}
                verify_comp_extent $tf ${ids[$i]} 0 EOF
        done
index 45faa08..8c742f9 100755 (executable)
@@ -181,6 +181,24 @@ static inline int lfs_mirror_create(int argc, char **argv)
 
 static inline int lfs_mirror_extend(int argc, char **argv)
 {
+       int i;
+
+       for (i = 0; i < argc; i++)
+               if (strstr(argv[i], "-N") ||
+                   strstr(argv[i], "--mirror-count"))
+                       break;
+
+       /* add -N if not specified */
+       if (i == argc) {
+               char *tmp[argc + 1];
+
+               tmp[0] = argv[0]; /* extend */
+               tmp[1] = "-N";
+               memcpy(tmp + 2, argv + 1, (argc - 1) * sizeof(*argv));
+
+               return lfs_setstripe_internal(argc + 1, tmp, SO_MIRROR_EXTEND);
+       }
+
        return lfs_setstripe_internal(argc, argv, SO_MIRROR_EXTEND);
 }