From: Alex Zhuravlev Date: Wed, 26 Jun 2019 10:32:16 +0000 (+0400) Subject: LU-11022 lfs: remove mirror by pool name X-Git-Tag: 2.12.57~92 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=0c710a46cfb43366dc57ff6e83e414086b1d0e6c LU-11022 lfs: remove mirror by pool name lfs mirror split --pool Change-Id: I012e68729b94657236ba3fc530fc7b7485529ed2 Signed-off-by: Alex Zhuravlev Reviewed-on: https://review.whamcloud.com/35329 Reviewed-by: Andreas Dilger Tested-by: jenkins Reviewed-by: Patrick Farrell Tested-by: Maloo --- diff --git a/lustre/doc/lfs-mirror-split.1 b/lustre/doc/lfs-mirror-split.1 index a86754b..34386f9 100644 --- a/lustre/doc/lfs-mirror-split.1 +++ b/lustre/doc/lfs-mirror-split.1 @@ -4,15 +4,15 @@ lfs mirror split \- split a specified mirror from an existing mirrored file .SH SYNOPSIS .B lfs mirror split {\fB\-\-mirror\-id\fR <\fImirror_id\fR> | \fB\-\-component\-id\fR|\fB\-I\fR -<\fIcomp_id\fR>} +<\fIcomp_id\fR> |\fB\-\-pool\fR <\fIpool\fR>} [\fB\-\-destroy\fR|\fB\-d\fR] [\fB\-f\fR <\fInew_file\fR>] <\fImirrored_file\fR> .SH DESCRIPTION This command splits a mirror with mirror ID <\fImirror_id\fR> or containing -a component with <\fIcomp_id\fR> out of a mirrored -file specified by the path name \fImirrored_file\fR. By default, the layout of -the split mirror will be stored into a new file named +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. +By default, the layout of the split mirror will be stored into a new file named <\fImirrored_file\fR>.mirror~<\fImirror_id\fR>. If \fB\-\-destroy\fR|\fB\-d\fR option is specified, then the split mirror will be destroyed. If \fB\-f\fR <\fInew_file\fR> option is specified, then the layout of the split @@ -31,7 +31,10 @@ 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 withiin a mirror. +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. .TP .BR \-\-destroy\fR|\fB\-d\fR This option indicates the split mirror will be destroyed. @@ -51,6 +54,9 @@ Split a mirror with ID 2 out of /mnt/lustre/file1 and destroy it. .B lfs mirror split --mirror-id 3 -f /mnt/lustre/file2 /mnt/lustre/file1 Split a mirror with ID 3 out of /mnt/lustre/file1 and store it into /mnt/lustre/file2. +.TP +.B lfs mirror split --pool lustre-nvme -d /mnt/lustre/file1 +Split a mirror on pool lustre-nvme 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 diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index d4bf66c..47ef7be 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -380,6 +380,15 @@ test_0b() { verify_comp_attr stripe-count $tf ${ids[5]} $OSTCOUNT verify_comp_attr_with_parent pool $tf ${ids[5]} + if [ $MDS1_VERSION -ge $(version_code 2.12.55) ]; then + # 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" + cnt=$($LFS getstripe $tf | grep archive | wc -l) + [ "$cnt" != "0" ] && error "mirror count after removal: $cnt" + fi + # destroy OST pool destroy_test_pools } diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 6927d84..7db51ce 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -293,12 +293,13 @@ command_t mirror_cmdlist[] = { 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 > [--destroy|-d] \n" + "usage: lfs mirror split <--mirror-id |\n" + "\t <--component-id|-I |-p > [--destroy|-d]\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" + "\tpool: Components on specified pool.\n" "\tnew_file: This option indicates the layout of the split\n" "\t mirror will be stored into. If not specified,\n" "\t a new file named .mirror~\n" @@ -1337,6 +1338,7 @@ enum mirror_flags { MF_NO_VERIFY = 0x1, MF_DESTROY = 0x2, MF_COMP_ID = 0x4, + MF_COMP_POOL = 0x8, }; /** @@ -1791,7 +1793,33 @@ static int find_comp_id(struct llapi_layout *layout, void *cbdata) return LLAPI_LAYOUT_ITER_CONT; } -static int mirror_split(const char *fname, __u32 id, + +struct pool_to_id_cbdata { + const char *pool; + __u32 id; +}; +static int find_comp_id_by_pool(struct llapi_layout *layout, void *cbdata) +{ + char buf[LOV_MAXPOOLNAME + 1]; + struct pool_to_id_cbdata *d = (void *)cbdata; + uint32_t id; + int rc; + + rc = llapi_layout_pool_name_get(layout, buf, sizeof(buf)); + if (rc < 0) + return rc; + if (strcmp(d->pool, buf)) + return LLAPI_LAYOUT_ITER_CONT; + + rc = llapi_layout_mirror_id_get(layout, &id); + if (rc < 0) + return rc; + d->id = id; + + return LLAPI_LAYOUT_ITER_STOP; +} + +static int mirror_split(const char *fname, __u32 id, const char *pool, enum mirror_flags mflags, const char *victim_file) { struct llapi_layout *layout; @@ -1834,7 +1862,13 @@ static int mirror_split(const char *fname, __u32 id, goto free_layout; } - if (mflags & MF_COMP_ID) { + if (mflags & MF_COMP_POOL) { + struct pool_to_id_cbdata data = { .pool = pool }; + + rc = llapi_layout_comp_iterate(layout, find_comp_id_by_pool, + &data); + id = data.id; + } else if (mflags & MF_COMP_ID) { rc = llapi_layout_comp_iterate(layout, find_comp_id, &id); id = mirror_id_of(id); } else { @@ -2113,7 +2147,6 @@ static inline bool setstripe_args_specified(struct lfs_setstripe_args *lsa) lsa->lsa_stripe_count != LLAPI_LAYOUT_DEFAULT || lsa->lsa_stripe_off != LLAPI_LAYOUT_DEFAULT || lsa->lsa_pattern != LLAPI_LAYOUT_RAID0 || - lsa->lsa_pool_name != NULL || lsa->lsa_comp_end != 0); } @@ -3651,17 +3684,20 @@ static int lfs_setstripe_internal(int argc, char **argv, result = mirror_extend(fname, mirror_list, mirror_flags); } else if (opc == SO_MIRROR_SPLIT) { - if (mirror_id == 0 && comp_id == 0) { + if (!mirror_id && !comp_id && !lsa.lsa_pool_name) { fprintf(stderr, - "%s %s: no mirror id or component id is specified\n", - progname, argv[0]); + "%s %s: no mirror id or component id or pool name" + " is specified\n", progname, argv[0]); goto usage_error; } - if (mirror_id != 0) + if (lsa.lsa_pool_name) + mirror_flags |= MF_COMP_POOL; + else if (mirror_id != 0) comp_id = mirror_id; else mirror_flags |= MF_COMP_ID; - result = mirror_split(fname, comp_id, mirror_flags, + result = mirror_split(fname, comp_id, lsa.lsa_pool_name, + mirror_flags, has_m_file ? mirror_list->m_file : NULL); } else if (layout != NULL) {