From 37f6389f1405182186937fa54224cbc22151397b Mon Sep 17 00:00:00 2001 From: Frederick Dilger Date: Tue, 9 Jul 2024 13:11:20 -0600 Subject: [PATCH] LU-13403 utils: mirror-count not required for mirror extend 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 Change-Id: I01bea6cec71fbf61c617cf27a52d7fb24fd4b06d Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55677 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/doc/lfs-mirror-extend.1 | 7 ++++--- lustre/tests/sanity-flr.sh | 5 +++-- lustre/utils/lfs.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lustre/doc/lfs-mirror-extend.1 b/lustre/doc/lfs-mirror-extend.1 index aa08df7..4076be9 100644 --- a/lustre/doc/lfs-mirror-extend.1 +++ b/lustre/doc/lfs-mirror-extend.1 @@ -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 diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index 7c51533..04317ca 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -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 diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 45faa08..8c742f9 100755 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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); } -- 1.8.3.1