From 6d0e247cfc956dae1148aad054bb3d100c8863c9 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 19 Sep 2019 00:45:11 -0700 Subject: [PATCH] LU-11467 utils: add lfs mirror delete command Add "lfs mirror delete" as an alias for "lfs mirror split -d", to balance "lfs mirror create" and simplify the interface for users. Add lfs-mirror-create.1 man page, and convert some tests in sanity-flr.sh to use the new interface. Signed-off-by: Andreas Dilger Signed-off-by: Jian Yu Change-Id: I4399878dc2fd435c517a2ff529b91480583ebbe5 Reviewed-on: https://review.whamcloud.com/36185 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Oleg Drokin --- lustre/doc/Makefile.am | 1 + lustre/doc/lfs-mirror-create.1 | 1 + lustre/doc/lfs-mirror-delete.1 | 50 ++++++++++++++++++++++++++++++++++++++++++ lustre/doc/lfs-mirror-extend.1 | 11 +++++----- lustre/doc/lfs-mirror-split.1 | 1 + lustre/tests/sanity-flr.sh | 6 ++--- lustre/utils/lfs.c | 33 +++++++++++++++++++--------- 7 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 lustre/doc/lfs-mirror-delete.1 diff --git a/lustre/doc/Makefile.am b/lustre/doc/Makefile.am index 8fa2f10..b8f88ad 100644 --- a/lustre/doc/Makefile.am +++ b/lustre/doc/Makefile.am @@ -52,6 +52,7 @@ MANFILES = \ lfs_migrate.1 \ lfs-migrate.1 \ lfs-mirror-create.1 \ + lfs-mirror-delete.1 \ lfs-mirror-extend.1 \ lfs-mirror-resync.1 \ lfs-mirror-split.1 \ diff --git a/lustre/doc/lfs-mirror-create.1 b/lustre/doc/lfs-mirror-create.1 index 28092fa..5d18c3b 100644 --- a/lustre/doc/lfs-mirror-create.1 +++ b/lustre/doc/lfs-mirror-create.1 @@ -107,6 +107,7 @@ The \fBlfs mirror create\fR command is part of the Lustre filesystem. .SH SEE ALSO .BR lfs (1), .BR lfs-setstripe (1), +.BR lfs-mirror-delete (1), .BR lfs-mirror-extend (1), .BR lfs-mirror-split (1), .BR lfs-mirror-resync (1), diff --git a/lustre/doc/lfs-mirror-delete.1 b/lustre/doc/lfs-mirror-delete.1 new file mode 100644 index 0000000..93a4f11 --- /dev/null +++ b/lustre/doc/lfs-mirror-delete.1 @@ -0,0 +1,50 @@ +.TH LFS-MIRROR-DELETE 1 2019-09-15 "Lustre" "Lustre Utilities" +.SH NAME +lfs mirror delete \- delete a specified mirror from an existing mirrored file +.SH SYNOPSIS +.B lfs mirror delete +{\fB\-\-mirror\-id\fR <\fImirror_id\fR> | \fB\-\-component\-id\fR|\fB\-I\fR +<\fIcomp_id\fR> |\fB\-\-pool\fR <\fIpool\fR>} +<\fImirrored_file\fR> +.SH DESCRIPTION +This command deletes a mirror with mirror ID <\fImirror_id\fR> or containing +a component with <\fIcomp_id\fR> or containing a component on <\fIpool\fR> +out of a mirrored file specified by the path name \fImirrored_file\fR. +.br +If \fImirrored_file\fR has only one mirror existing after split, it will be +converted to a regular non-mirrored file. +.br +If the original \fImirrored_file\fR is not a mirrored file, then the command +will return an error. +.br +If the specified mirror is the last non-stale mirror, then the command will +return an error. +.SH OPTIONS +.TP +.BR \-\-mirror\-id\fR\ <\fImirror_id\fR> +The numerical unique identifier for a mirror. The mirror ID is unique within a +mirrored file and is automatically assigned at file creation or extension time. +It can be fetched by \fBlfs getstripe\fR command (see \fBlfs(1)\fR). +.TP +.BR \-\-comp\-id\fR\ <\fIcomp_id\fR> +The numerical unique identifier for a component contained within a mirror. +.TP +.BR \-\-pool\fR\ <\fIpool\fR> +The pool storing a component contained within a mirror. +.SH EXAMPLES +.TP +.B lfs mirror delete --mirror-id 2 /mnt/lustre/file1 +Delete the mirror with ID 2 of /mnt/lustre/file1. +.TP +.B lfs mirror delete --pool ssd /mnt/lustre/file1 +Split a mirror on pool ssd out of /mnt/lustre/file1 and destroy it. +.SH AUTHOR +The \fBlfs mirror split\fR command is part of the Lustre filesystem. +.SH SEE ALSO +.BR lfs (1), +.BR lfs-setstripe (1), +.BR lfs-mirror-create (1), +.BR lfs-mirror-extend (1), +.BR lfs-mirror-resync (1), +.BR lfs-mirror-split (1), +.BR lfs-mirror-verify (1) diff --git a/lustre/doc/lfs-mirror-extend.1 b/lustre/doc/lfs-mirror-extend.1 index f97ca66..3063d00 100644 --- a/lustre/doc/lfs-mirror-extend.1 +++ b/lustre/doc/lfs-mirror-extend.1 @@ -27,9 +27,9 @@ Progressive File Layout (PFL) (see \fBlfs-setstripe\fR(1)). If \fIsetstripe_options\fR are not specified, then the stripe options inherited from the previous component will be used. If \fIvictim_file\fR exists, then the -command will split the layout from that file and use it as a mirror added to the -mirrored file. After the command is finished, the victim file will be removed. -The \fIsetstripe_options\fR cannot be specified with +command will merge the layout from that file as a mirror added to the +mirrored file. After the command is finished, the victim file will be +removed. The \fIsetstripe_options\fR cannot be specified with \fB\-f\fR <\fIvictim_file\fR> option in one command line. .br If \fIvictim_file\fR is specified, the utility will verify that the file contents @@ -56,7 +56,7 @@ from the previous component will be used. This option cannot be specified with \fB\-f\fR <\fIvictim_file\fR> option. .TP .BR \-f\fR\ <\fIvictim_file\fR> -The layout of \fIvictim_file\fR will be split and used as a mirror added to the +The layout of \fIvictim_file\fR will be merged as a mirror added to the mirrored file. This option cannot be specified with \fIsetstripe_options\fR option. .TP @@ -99,7 +99,7 @@ stripe size of 16MB and use OSTs in the archive pool. .B lfs mirror extend --no-verify -N -f /mnt/lustre/file2 -N -f /mnt/lustre/file3 .B /mnt/lustre/file1 .in -Split the layouts from /mnt/lustre/file2 and /mnt/lustre/file3, which contain +Merge the layouts from /mnt/lustre/file2 and /mnt/lustre/file3, which contain the same data as /mnt/lustre/file1, use the layouts as mirrors and add them to /mnt/lustre/file1 without verification. .SH AUTHOR @@ -108,6 +108,7 @@ The \fBlfs mirror extend\fR command is part of the Lustre filesystem. .BR lfs (1), .BR lfs-setstripe (1), .BR lfs-mirror-create (1), +.BR lfs-mirror-delete (1), .BR lfs-mirror-split (1), .BR lfs-mirror-resync (1), .BR lfs-mirror-verify (1) diff --git a/lustre/doc/lfs-mirror-split.1 b/lustre/doc/lfs-mirror-split.1 index d5259a9..d250b7f 100644 --- a/lustre/doc/lfs-mirror-split.1 +++ b/lustre/doc/lfs-mirror-split.1 @@ -64,6 +64,7 @@ The \fBlfs mirror split\fR command is part of the Lustre filesystem. .BR lfs (1), .BR lfs-setstripe (1), .BR lfs-mirror-create (1), +.BR lfs-mirror-delete (1), .BR lfs-mirror-extend (1), .BR lfs-mirror-resync (1), .BR lfs-mirror-verify (1) diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index 8a93e26..37c439e 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -384,7 +384,7 @@ test_0b() { # LU-11022 - remove mirror by pool name local=cnt cnt=$($LFS getstripe $tf | grep archive | wc -l) [ "$cnt" != "1" ] && error "unexpected mirror count $cnt" - $LFS mirror split --pool archive -d $tf || error "delete mirror" + $LFS mirror delete --pool archive $tf || error "delete mirror" cnt=$($LFS getstripe $tf | grep archive | wc -l) [ "$cnt" != "0" ] && error "mirror count after removal: $cnt" fi @@ -1812,7 +1812,7 @@ test_44() { verify_flr_state $tf "wp" # disallow destroying the last non-stale mirror - ! $LFS mirror split --mirror-id 1 -d $tf > /dev/null 2>&1 || + ! $LFS mirror delete --mirror-id 1 $tf > /dev/null 2>&1 || error "destroying mirror 1 should fail" # synchronize all mirrors of the file @@ -2312,7 +2312,7 @@ test_203() { #create 2 mirrors $LFS mirror create -N2 -c1 $tf || error "create FLR file $tf" #delete first mirror - $LFS mirror split --mirror-id=1 -d $tf || error "delete first mirror" + $LFS mirror delete --mirror-id=1 $tf || error "delete first mirror" $LFS getstripe $tf local old_id=$($LFS getstripe --mirror-id=2 -I $tf) diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 14907c8..6364a1c 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -147,6 +147,7 @@ enum setstripe_origin { SO_MIRROR_CREATE, SO_MIRROR_EXTEND, SO_MIRROR_SPLIT, + SO_MIRROR_DELETE, }; static int lfs_setstripe_internal(int argc, char **argv, enum setstripe_origin opc); @@ -171,6 +172,10 @@ static inline int lfs_mirror_split(int argc, char **argv) { return lfs_setstripe_internal(argc, argv, SO_MIRROR_SPLIT); } +static inline int lfs_mirror_delete(int argc, char **argv) +{ + return lfs_setstripe_internal(argc, argv, SO_MIRROR_DELETE); +} /* Setstripe and migrate share mostly the same parameters */ #define SSM_CMD_COMMON(cmd) \ @@ -288,19 +293,23 @@ command_t mirror_cmdlist[] = { .pc_help = "Create a mirrored file.\n" "usage: lfs mirror create " "<--mirror-count|-N[mirror_count]> " - "[setstripe options] ... \n" + "[setstripe options] ... ...\n" MIRROR_CREATE_HELP }, + { .pc_name = "delete", .pc_func = lfs_mirror_delete, + .pc_help = "delete a mirror from a file.\n" + "usage: lfs mirror delete {--comp-id|-I |-p } ...\n" + }, { .pc_name = "extend", .pc_func = lfs_mirror_extend, .pc_help = "Extend a mirrored file.\n" "usage: lfs mirror extend " "<--mirror-count|-N[mirror_count]> [--no-verify] " - "[setstripe options|-f ] ... \n" + "[setstripe options|-f ] ... ...\n" MIRROR_EXTEND_HELP }, { .pc_name = "split", .pc_func = lfs_mirror_split, .pc_help = "Split a mirrored file.\n" "usage: lfs mirror split <--mirror-id |\n" "\t <--component-id|-I |-p > [--destroy|-d]\n" - "\t [-f ] \n" + "\t [-f ] ...\n" "\tmirror_id: The numerical unique identifier for a mirror. It\n" "\t can be fetched by lfs getstripe command.\n" "\tcomp_id: Unique component ID within a mirror.\n" @@ -3113,6 +3122,10 @@ static int lfs_setstripe_internal(int argc, char **argv, migrate_mode = (opc == SO_MIGRATE); mirror_mode = (opc == SO_MIRROR_CREATE || opc == SO_MIRROR_EXTEND); setstripe_mode = (opc == SO_SETSTRIPE); + if (opc == SO_MIRROR_DELETE) { + delete = 1; + mirror_flags = MF_DESTROY; + } snprintf(cmd, sizeof(cmd), "%s %s", progname, argv[0]); progname = cmd; @@ -3715,11 +3728,11 @@ static int lfs_setstripe_internal(int argc, char **argv, goto usage_error; } - if (!comp_del && !comp_set && (opc != SO_MIRROR_SPLIT) && - comp_id != 0) { + if (!comp_del && !comp_set && opc != SO_MIRROR_SPLIT && + opc != SO_MIRROR_DELETE && comp_id != 0) { fprintf(stderr, - "%s %s: option -I can only be used with --component-del or --component-set or lfs mirror split\n", - progname, argv[0]); + "%s: option -I can only be used with --component-del or --component-set or lfs mirror split\n", + progname); goto usage_error; } @@ -3874,11 +3887,11 @@ static int lfs_setstripe_internal(int argc, char **argv, } else if (opc == SO_MIRROR_EXTEND) { result = mirror_extend(fname, mirror_list, mirror_flags); - } else if (opc == SO_MIRROR_SPLIT) { + } else if (opc == SO_MIRROR_SPLIT || opc == SO_MIRROR_DELETE) { if (!mirror_id && !comp_id && !lsa.lsa_pool_name) { fprintf(stderr, - "%s %s: no mirror id or component id or pool name" - " is specified\n", progname, argv[0]); + "%s: no mirror specified to delete from '%s'\n", + progname, fname); goto usage_error; } if (lsa.lsa_pool_name) -- 1.8.3.1