From 0354fa98966eef9874b3fe6818c2c6f1a2433297 Mon Sep 17 00:00:00 2001 From: Alex Zhuravlev Date: Thu, 17 Dec 2020 12:15:50 +0300 Subject: [PATCH] LU-14262 utils: lfs to set component flags by pool name so it'd be easy to set flags (like prefer) on the components residing on specific OST identified by pool. Signed-off-by: Alex Zhuravlev Change-Id: I733f92fe186682dc8d34512edf75b49e565c457f Reviewed-on: https://review.whamcloud.com/41024 Reviewed-by: Andreas Dilger Reviewed-by: John L. Hammond Tested-by: jenkins Reviewed-by: Oleg Drokin --- lustre/tests/sanity-flr.sh | 33 ++++++++++++++++++ lustre/utils/lfs.c | 85 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 110 insertions(+), 8 deletions(-) diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index f9bbf7f..9c53120 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -3015,6 +3015,39 @@ function test_205() { } run_test 205 "lfs mirror extend to set prefer flag" +function test_206() { + # create a new OST pool + local pool_name=$TESTNAME + + create_pool $FSNAME.$pool_name || + error "create OST pool $pool_name failed" + # add OSTs into the pool + pool_add_targets $pool_name 0 1 || + error "add OSTs into pool $pool_name failed" + + $LFS setstripe -c1 --pool=$pool_name $DIR/$tfile || + error "can't setstripe" + $LFS mirror extend -N $DIR/$tfile || + error "can't create replica" + if $LFS getstripe $DIR/$tfile | grep -q prefer ; then + $LFS getstripe $DIR/$tfile + error "prefer found" + fi + $LFS setstripe --comp-set --comp-flags=prefer -p $pool_name $DIR/$tfile || { + $LFS getstripe $DIR/$tfile + error "can't setstripe prefer" + } + + if ! $LFS getstripe $DIR/$tfile | grep -q prefer ; then + $LFS getstripe $DIR/$tfile + error "no prefer found" + fi + + # destroy OST pool + destroy_test_pools +} +run_test 206 "lfs setstripe -pool .. --comp-flags=.. " + complete $SECONDS check_and_cleanup_lustre exit_status diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 938a24c..df9027e 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -139,6 +139,13 @@ static int lfs_migrate_to_dom(int fd, int fdv, char *name, struct llapi_stripe_param *param, struct llapi_layout *layout); +struct pool_to_id_cbdata { + const char *pool; + __u32 id; +}; +static int find_comp_id_by_pool(struct llapi_layout *layout, void *cbdata); +static int find_mirror_id_by_pool(struct llapi_layout *layout, void *cbdata); + enum setstripe_origin { SO_SETSTRIPE, SO_MIGRATE, @@ -1128,7 +1135,40 @@ static int migrate_nonblock(int fd, int fdv) return 0; } -static int lfs_component_set(char *fname, int comp_id, +static +int lfs_layout_compid_by_pool(char *fname, const char *pool, int *comp_id) +{ + struct pool_to_id_cbdata data = { .pool = pool }; + struct llapi_layout *layout = NULL; + int rc; + + layout = llapi_layout_get_by_path(fname, 0); + if (!layout) { + fprintf(stderr, + "error %s: file '%s' couldn't get layout: rc=%d\n", + progname, fname, errno); + rc = -errno; + goto free_layout; + } + rc = llapi_layout_sanity(layout, false, true); + if (rc < 0) { + llapi_layout_sanity_perror(errno); + goto free_layout; + } + rc = llapi_layout_comp_iterate(layout, find_comp_id_by_pool, &data); + if (rc < 0) + goto free_layout; + + *comp_id = data.id; + rc = 0; + +free_layout: + if (layout) + llapi_layout_free(layout); + return rc; +} + +static int lfs_component_set(char *fname, int comp_id, const char *pool, __u32 flags, __u32 neg_flags) { __u32 ids[2]; @@ -1136,6 +1176,18 @@ static int lfs_component_set(char *fname, int comp_id, size_t count = 0; int rc; + if (!comp_id) { + if (pool == NULL) { + fprintf(stderr, + "error %s: neither component id nor pool is specified\n", + progname); + return -EINVAL; + } + rc = lfs_layout_compid_by_pool(fname, pool, &comp_id); + if (rc) + return rc; + } + if (flags) { ids[count] = comp_id; flags_array[count] = flags; @@ -1925,10 +1977,26 @@ static int find_comp_id(struct llapi_layout *layout, void *cbdata) return LLAPI_LAYOUT_ITER_CONT; } -struct pool_to_id_cbdata { - const char *pool; - __u32 id; -}; +static int find_mirror_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 find_comp_id_by_pool(struct llapi_layout *layout, void *cbdata) { @@ -1943,7 +2011,7 @@ static int find_comp_id_by_pool(struct llapi_layout *layout, void *cbdata) if (strcmp(d->pool, buf)) return LLAPI_LAYOUT_ITER_CONT; - rc = llapi_layout_mirror_id_get(layout, &id); + rc = llapi_layout_comp_id_get(layout, &id); if (rc < 0) return rc; d->id = id; @@ -2064,7 +2132,7 @@ static int mirror_split(const char *fname, __u32 id, const char *pool, if (mflags & MF_COMP_POOL) { struct pool_to_id_cbdata data = { .pool = pool }; - rc = llapi_layout_comp_iterate(layout, find_comp_id_by_pool, + rc = llapi_layout_comp_iterate(layout, find_mirror_id_by_pool, &data); mirror_id = data.id; } else if (mflags & MF_COMP_ID) { @@ -3826,7 +3894,7 @@ static int lfs_setstripe_internal(int argc, char **argv, } } - if (comp_set && !comp_id) { + if (comp_set && !comp_id && !lsa.lsa_pool_name) { fprintf(stderr, "%s %s: --component-set doesn't have component-id set\n", progname, argv[0]); @@ -4078,6 +4146,7 @@ static int lfs_setstripe_internal(int argc, char **argv, layout); } else if (comp_set != 0) { result = lfs_component_set(fname, comp_id, + lsa.lsa_pool_name, lsa.lsa_comp_flags, lsa.lsa_comp_neg_flags); } else if (comp_del != 0) { -- 1.8.3.1