From: Vitaly Fertman Date: Mon, 17 Jan 2022 19:54:12 +0000 (+0300) Subject: LU-14645 utils: optimise setstripe X-Git-Tag: 2.15.0-RC1~39 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=cd1f8527d414a12ec7eb5b69fe30509a45b33ad4;p=fs%2Flustre-release.git LU-14645 utils: optimise setstripe skip some excessive checks: - do not check the file is on lustre fs, the following ioctl does it; - do not check the stripe-index is valid, done on MDS side; - do not check the pool exists for a !PFL file (align with a setstripe for PFL files); Signed-off-by: Vitaly Fertman Change-Id: Ia21f85c3ab73a970bad8d11e175c0063ab3a307f Reviewed-on: https://review.whamcloud.com/46152 Tested-by: jenkins Reviewed-by: Alexander Boyko Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 65ed22a..0284da0 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -1217,10 +1217,6 @@ int llapi_heat_get(int fd, struct lu_heat *heat); int llapi_heat_set(int fd, __u64 flags); int llapi_layout_sanity(struct llapi_layout *layout, bool incomplete, bool flr); -int llapi_layout_sanity_fsname_check(struct llapi_layout *layout, - const char *pathname, - bool incomplete, - bool flr); void llapi_layout_sanity_perror(int error); int llapi_layout_dom_size(struct llapi_layout *layout, uint64_t *size); diff --git a/lustre/tests/llapi_layout_test.c b/lustre/tests/llapi_layout_test.c index f67fb9d..f875f91 100644 --- a/lustre/tests/llapi_layout_test.c +++ b/lustre/tests/llapi_layout_test.c @@ -932,7 +932,7 @@ void test21(void) ASSERTF(layout != NULL, "errno = %d", errno); fd = llapi_layout_file_create(template, 0, 0640, layout); - ASSERTF(fd == -1 && errno == ENOENT, + ASSERTF(fd == -1 && errno == ENOTTY, "fd = %d, errno = %d, template = %s", fd, errno, template); llapi_layout_free(layout); } diff --git a/lustre/tests/ost-pools.sh b/lustre/tests/ost-pools.sh index 217a8a9..a01532d 100755 --- a/lustre/tests/ost-pools.sh +++ b/lustre/tests/ost-pools.sh @@ -596,10 +596,6 @@ test_6() { $LFS setstripe -c 2 -p $INVALID_POOL $POOL_DIR 2>/dev/null [[ $? -ne 0 ]] || error "setstripe to invalid pool did not fail." - # If the pool name does not exist, the command should fail - $LFS setstripe -c 2 -p $NON_EXISTANT_POOL $POOL_DIR 2>/dev/null - [[ $? -ne 0 ]] || error "setstripe to non-existant pool did not fail." - # lfs setstripe should work as before if a pool name is not specified. $LFS setstripe -c -1 $POOL_DIR [[ $? -eq 0 ]] || error "$LFS setstripe -c -1 $POOL_DIR failed." @@ -696,10 +692,6 @@ test_7c() $LFS setstripe -c 1 $DIR/$tdir/testfile1 --pool "${pool}X" && error "setstripe succedeed" - # setstripe with the same pool name minus 1 letter - $LFS setstripe -c 1 $DIR/$tdir/testfile1 --pool "${pool%?}" && - error "setstripe succedeed" - rm -f $DIR/$tdir/testfile1 destroy_pool_int $FSNAME.$pool diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 2724832..b6261f6 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -1047,7 +1047,7 @@ int lfs_layout_compid_by_pool(char *fname, const char *pool, int *comp_id) rc = -errno; goto free_layout; } - rc = llapi_layout_sanity_fsname_check(layout, fname, false, true); + rc = llapi_layout_sanity(layout, false, true); if (rc < 0) { llapi_layout_sanity_perror(errno); goto free_layout; @@ -1512,8 +1512,7 @@ static int mirror_create_sanity_check(const char *fname, return -ENODATA; } - rc = llapi_layout_sanity_fsname_check(layout, fname, - false, true); + rc = llapi_layout_sanity(layout, false, true); llapi_layout_free(layout); @@ -1545,8 +1544,7 @@ static int mirror_create_sanity_check(const char *fname, } } - rc = llapi_layout_sanity_fsname_check(list->m_layout, fname, - false, true); + rc = llapi_layout_sanity(list->m_layout, false, true); if (rc) { llapi_layout_sanity_perror(rc); return rc; @@ -2116,7 +2114,7 @@ static int mirror_split(const char *fname, __u32 id, const char *pool, return -EINVAL; } - rc = llapi_layout_sanity_fsname_check(layout, fname, false, true); + rc = llapi_layout_sanity(layout, false, true); if (rc) { llapi_layout_sanity_perror(rc); goto free_layout; diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 27725be..1efc766 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -400,39 +400,6 @@ int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len) return 0; } -/* XXX: llapi_xxx() functions return negative values upon failure */ - -int llapi_layout_search_ost(__u32 ost, const char *pname, char *fsname) -{ - char ostname[MAX_OBD_NAME + 64]; - const char *pool_name = pname; - int rc = 0; - - /** - * The current policy is that the pool does not have to exist at the - * setstripe time, see sanity-pfl/-flr tests. - * If this logic will change, re-enable it. - * - * if (pname && strlen(pname) == 0) - */ - pool_name = NULL; - - snprintf(ostname, sizeof(ostname), "%s-OST%04x_UUID", - fsname, ost); - rc = llapi_search_ost(fsname, pool_name, ostname); - if (rc <= 0) { - if (rc == 0) - rc = -ENODEV; - - llapi_error(LLAPI_MSG_ERROR, rc, - "%s: cannot find OST %s in %s", __func__, ostname, - pool_name != NULL ? "pool" : "system"); - return rc; - } - - return 0; -} - /** * Verify the setstripe parameters before using. * This is a pair method for comp_args_to_layout()/llapi_layout_sanity_cb() @@ -446,8 +413,7 @@ int llapi_layout_search_ost(__u32 ost, const char *pname, char *fsname) * < 0, error code on failre */ static int llapi_stripe_param_verify(const struct llapi_stripe_param *param, - const char **pool_name, - char *fsname) + const char **pool_name) { int count; static int page_size; @@ -506,55 +472,14 @@ static int llapi_stripe_param_verify(const struct llapi_stripe_param *param, /* Make sure we have a good pool */ if (*pool_name != NULL) { - if (!llapi_pool_name_is_valid(pool_name, fsname)) { + if (!llapi_pool_name_is_valid(pool_name)) { rc = -EINVAL; llapi_error(LLAPI_MSG_ERROR, rc, - "Pool '%s' is not on filesystem '%s'", - *pool_name, fsname); + "Invalid Poolname '%s'", *pool_name); goto out; } - - /* Make sure the pool exists and is non-empty */ - rc = llapi_search_ost(fsname, *pool_name, NULL); - if (rc < 1) { - char *err = rc == 0 ? "has no OSTs" : "does not exist"; - - rc = -EINVAL; - llapi_error(LLAPI_MSG_ERROR, rc, "pool '%s.%s' %s", - fsname, *pool_name, err); - goto out; - } - rc = 0; } - /* sanity check of target list */ - if (param->lsp_is_specific) { - bool found = false; - int i; - - for (i = 0; i < count; i++) { - rc = llapi_layout_search_ost(param->lsp_osts[i], - *pool_name, fsname); - if (rc) - goto out; - - /* Make sure stripe offset is in OST list. */ - if (param->lsp_osts[i] == param->lsp_stripe_offset) - found = true; - } - if (!found) { - rc = -EINVAL; - llapi_error(LLAPI_MSG_ERROR, rc, - "%s: stripe offset '%d' is not in the target list", - __func__, param->lsp_stripe_offset); - goto out; - } - } else if (param->lsp_stripe_offset != -1) { - rc = llapi_layout_search_ost(param->lsp_stripe_offset, - *pool_name, fsname); - if (rc) - goto out; - } out: errno = -rc; return rc; @@ -677,23 +602,13 @@ int llapi_get_agent_uuid(char *path, char *buf, size_t bufsize) int llapi_file_open_param(const char *name, int flags, mode_t mode, const struct llapi_stripe_param *param) { - char fsname[MAX_OBD_NAME + 1] = { 0 }; struct lov_user_md *lum = NULL; const char *pool_name = param->lsp_pool; size_t lum_size; int fd, rc; - /* Make sure we are on a Lustre file system */ - rc = llapi_search_fsname(name, fsname); - if (rc) { - llapi_error(LLAPI_MSG_ERROR, rc, - "'%s' is not on a Lustre filesystem", - name); - return rc; - } - /* Check if the stripe pattern is sane. */ - rc = llapi_stripe_param_verify(param, &pool_name, fsname); + rc = llapi_stripe_param_verify(param, &pool_name); if (rc != 0) return rc; diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index 8fdc15f..2adb66b 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -1546,7 +1546,7 @@ int llapi_layout_pool_name_set(struct llapi_layout *layout, if (comp == NULL) return -1; - if (!llapi_pool_name_is_valid(&pool_name, NULL)) { + if (!llapi_pool_name_is_valid(&pool_name)) { errno = EINVAL; return -1; } @@ -1586,8 +1586,7 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode, } if (layout) { - rc = llapi_layout_sanity_fsname_check( - (struct llapi_layout *)layout, path, false, + rc = llapi_layout_sanity((struct llapi_layout *)layout, false, !!(layout->llot_mirror_count > 1)); if (rc) { llapi_layout_sanity_perror(rc); @@ -2218,8 +2217,7 @@ int llapi_layout_file_comp_add(const char *path, goto out; } - rc = llapi_layout_sanity_fsname_check(existing_layout, path, - false, false); + rc = llapi_layout_sanity(existing_layout, false, false); if (rc) { tmp_errno = errno; llapi_layout_sanity_perror(rc); @@ -2354,8 +2352,7 @@ int llapi_layout_file_comp_del(const char *path, uint32_t id, uint32_t flags) goto out; } - rc = llapi_layout_sanity_fsname_check(existing_layout, path, - false, false); + rc = llapi_layout_sanity(existing_layout, false, false); if (rc) { tmp_errno = errno; llapi_layout_sanity_perror(rc); @@ -2515,8 +2512,7 @@ int llapi_layout_file_comp_set(const char *path, uint32_t *ids, uint32_t *flags, goto out; } - rc = llapi_layout_sanity_fsname_check(existing_layout, path, - false, false); + rc = llapi_layout_sanity(existing_layout, false, false); if (rc) { tmp_errno = errno; llapi_layout_sanity_perror(rc); @@ -3158,7 +3154,6 @@ enum llapi_layout_comp_sanity_error { LSE_START_GT_END, LSE_ALIGN_END, LSE_ALIGN_EXT, - LSE_UNKNOWN_OST, LSE_LAST, }; @@ -3195,12 +3190,9 @@ const char *const llapi_layout_strerror[] = "The component end must be aligned by the stripe size", [LSE_ALIGN_EXT] = "The extension size must be aligned by the stripe size", - [LSE_UNKNOWN_OST] = - "An unknown OST idx is specified", }; struct llapi_layout_sanity_args { - char lsa_fsname[MAX_OBD_NAME + 1]; bool lsa_incomplete; bool lsa_flr; bool lsa_ondisk; @@ -3380,34 +3372,6 @@ static int llapi_layout_sanity_cb(struct llapi_layout *layout, goto out_err; } - if (args->lsa_fsname[0] != '\0') { - int i, rc = 0; - - if (comp->llc_pattern & LLAPI_LAYOUT_SPECIFIC) { - assert(comp->llc_stripe_count <= - comp->llc_objects_count); - - for (i = 0; i < comp->llc_stripe_count && rc == 0; i++){ - if (comp->llc_objects[i].l_ost_idx == - LLAPI_LAYOUT_IDX_MAX) { - args->lsa_rc = -1; - goto out_err; - } - rc = llapi_layout_search_ost( - comp->llc_objects[i].l_ost_idx, - comp->llc_pool_name, args->lsa_fsname); - } - } else if (comp->llc_stripe_offset != LLAPI_LAYOUT_DEFAULT) { - rc = llapi_layout_search_ost( - comp->llc_stripe_offset, - comp->llc_pool_name, args->lsa_fsname); - } - if (rc) { - args->lsa_rc = LSE_UNKNOWN_OST; - goto out_err; - } - } - return LLAPI_LAYOUT_ITER_CONT; out_err: @@ -3450,12 +3414,11 @@ void llapi_layout_sanity_perror(int error) * \retval 0, success, positive: various errors, see * llapi_layout_sanity_perror, -1, failure */ -static int __llapi_layout_sanity(struct llapi_layout *layout, - const char *fname, - bool incomplete, - bool flr) +int llapi_layout_sanity(struct llapi_layout *layout, + bool incomplete, + bool flr) { - struct llapi_layout_sanity_args args = { { 0 } }; + struct llapi_layout_sanity_args args = { 0 }; struct llapi_layout_comp *curr; int rc = 0; @@ -3466,17 +3429,6 @@ static int __llapi_layout_sanity(struct llapi_layout *layout, if (!curr) return 0; - /* Make sure we are on a Lustre file system */ - if (fname) { - rc = llapi_search_fsname(fname, args.lsa_fsname); - if (rc) { - llapi_error(LLAPI_MSG_ERROR, rc, - "'%s' is not on a Lustre filesystem", - fname); - return rc; - } - } - /* Set up args */ args.lsa_rc = 0; args.lsa_flr = flr; @@ -3501,21 +3453,6 @@ static int __llapi_layout_sanity(struct llapi_layout *layout, return rc; } -int llapi_layout_sanity(struct llapi_layout *layout, - bool incomplete, - bool flr) -{ - return __llapi_layout_sanity(layout, NULL, incomplete, flr); -} - -int llapi_layout_sanity_fsname_check(struct llapi_layout *layout, - const char *pathname, - bool incomplete, - bool flr) -{ - return __llapi_layout_sanity(layout, pathname, incomplete, flr); -} - int llapi_layout_dom_size(struct llapi_layout *layout, uint64_t *size) { uint64_t pattern, start; diff --git a/lustre/utils/lustreapi_internal.h b/lustre/utils/lustreapi_internal.h index 95c57ff..7284ea9 100644 --- a/lustre/utils/lustreapi_internal.h +++ b/lustre/utils/lustreapi_internal.h @@ -131,29 +131,17 @@ static inline bool llapi_stripe_index_is_valid(int64_t index) return index >= -1 && index <= LOV_V1_INSANE_STRIPE_COUNT; } -static inline bool llapi_pool_name_is_valid(const char **pool_name, - const char *fsname) +static inline bool llapi_pool_name_is_valid(const char **pool_name) { const char *ptr; if (*pool_name == NULL) return false; - /** - * in case user gives the full pool name ., - * strip the fsname - */ + /* Strip off any 'fsname.' portion. */ ptr = strchr(*pool_name, '.'); - if (ptr != NULL) { - if (fsname != NULL) { - int fslen = strlen(fsname); - - if (fslen != ptr - *pool_name || - strncmp(*pool_name, fsname, fslen) != 0) - return false; - } + if (ptr != NULL) *pool_name = ptr + 1; - } if (strlen(*pool_name) > LOV_MAXPOOLNAME) return false; @@ -161,9 +149,6 @@ static inline bool llapi_pool_name_is_valid(const char **pool_name, return true; } - -int llapi_layout_search_ost(__u32 ost, const char *pname, char *fsname); - /* Compatibility macro for legacy llapi functions that use "offset" * terminology instead of the preferred "index". */ #define llapi_stripe_offset_is_valid(os) llapi_stripe_index_is_valid(os)