From 5e65d6a8e57a5a17c4c7e043cb46e86bf82b7782 Mon Sep 17 00:00:00 2001 From: Vitaly Fertman Date: Mon, 17 Jan 2022 21:49:52 +0300 Subject: [PATCH] LU-14645 utils: fix API for llapi_sanity_check fix the previous patch which introduced a change in API. Fixes: 149934fe28 ("LU-14645 utils: setstripe cleanup") Signed-off-by: Vitaly Fertman Change-Id: I43ae6822768ac70c9348af270c17830b13133f8c Reviewed-on: https://review.whamcloud.com/46151 Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Alexander Boyko Reviewed-by: Oleg Drokin --- lustre/include/lustre/lustreapi.h | 9 ++++++--- lustre/tests/llapi_layout_test.c | 4 ++-- lustre/utils/lfs.c | 10 ++++++---- lustre/utils/liblustreapi.c | 12 ++++++------ lustre/utils/liblustreapi_layout.c | 40 +++++++++++++++++++++++++++----------- lustre/utils/lustreapi_internal.h | 16 ++++++++------- 6 files changed, 58 insertions(+), 33 deletions(-) diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 8cb362b..65ed22a 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -995,7 +995,7 @@ int llapi_layout_pool_name_get(const struct llapi_layout *layout, * \retval -1 Invalid argument, errno set to EINVAL. */ int llapi_layout_pool_name_set(struct llapi_layout *layout, - char *pool_name); + const char *pool_name); /******************** File Creation ********************/ @@ -1216,8 +1216,11 @@ int llapi_mirror_punch(int fd, unsigned int id, off_t start, size_t length); 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, const char *fname, - bool incomplete, bool flr); +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 890dd8d..f67fb9d 100644 --- a/lustre/tests/llapi_layout_test.c +++ b/lustre/tests/llapi_layout_test.c @@ -1366,7 +1366,7 @@ void test30(void) /* set non-contiguous extent will fail */ rc = llapi_layout_comp_extent_set(layout, start[1] * 2, end[1]); ASSERTF(rc == 0, "errno %d", errno); - rc = llapi_layout_sanity(layout, NULL, false, false); + rc = llapi_layout_sanity(layout, false, false); ASSERTF(rc == 12 /*LSE_NOT_ADJACENT_PREV*/, "rc %d", rc); rc = llapi_layout_comp_extent_set(layout, start[1], end[1]); @@ -1734,7 +1734,7 @@ void test34(void) layout = llapi_layout_get_by_path(path, 0); ASSERTF(layout != NULL, "errno = %d", errno); - rc = llapi_layout_sanity(layout, NULL, false, false); + rc = llapi_layout_sanity(layout, false, false); ASSERTF(rc == 0, "errno %d", errno); } diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 466f44c..2724832 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(layout, fname, false, true); + rc = llapi_layout_sanity_fsname_check(layout, fname, false, true); if (rc < 0) { llapi_layout_sanity_perror(errno); goto free_layout; @@ -1512,7 +1512,8 @@ static int mirror_create_sanity_check(const char *fname, return -ENODATA; } - rc = llapi_layout_sanity(layout, fname, false, true); + rc = llapi_layout_sanity_fsname_check(layout, fname, + false, true); llapi_layout_free(layout); @@ -1544,7 +1545,8 @@ static int mirror_create_sanity_check(const char *fname, } } - rc = llapi_layout_sanity(list->m_layout, fname, false, true); + rc = llapi_layout_sanity_fsname_check(list->m_layout, fname, + false, true); if (rc) { llapi_layout_sanity_perror(rc); return rc; @@ -2114,7 +2116,7 @@ static int mirror_split(const char *fname, __u32 id, const char *pool, return -EINVAL; } - rc = llapi_layout_sanity(layout, fname, false, true); + rc = llapi_layout_sanity_fsname_check(layout, fname, 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 99f8b1b..27725be 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -402,10 +402,10 @@ int llapi_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len) /* XXX: llapi_xxx() functions return negative values upon failure */ -int llapi_layout_search_ost(__u32 ost, char *pname, char *fsname) +int llapi_layout_search_ost(__u32 ost, const char *pname, char *fsname) { char ostname[MAX_OBD_NAME + 64]; - char *pool_name = pname; + const char *pool_name = pname; int rc = 0; /** @@ -446,7 +446,7 @@ int llapi_layout_search_ost(__u32 ost, char *pname, char *fsname) * < 0, error code on failre */ static int llapi_stripe_param_verify(const struct llapi_stripe_param *param, - char **pool_name, + const char **pool_name, char *fsname) { int count; @@ -492,8 +492,8 @@ static int llapi_stripe_param_verify(const struct llapi_stripe_param *param, if (param->lsp_stripe_pattern == LOV_PATTERN_MDT) { rc = -EINVAL; llapi_error(LLAPI_MSG_ERROR, rc, - "Invalid pattern: %d, must be specified with -E\n", - param->lsp_stripe_pattern); + "Invalid pattern: '-L mdt', must be specified " + "with -E\n"); goto out; } else { if (!llapi_stripe_count_is_valid(count)) { @@ -679,7 +679,7 @@ int llapi_file_open_param(const char *name, int flags, mode_t mode, { char fsname[MAX_OBD_NAME + 1] = { 0 }; struct lov_user_md *lum = NULL; - char *pool_name = param->lsp_pool; + const char *pool_name = param->lsp_pool; size_t lum_size; int fd, rc; diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index c90972b..8fdc15f 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -1538,7 +1538,7 @@ int llapi_layout_pool_name_get(const struct llapi_layout *layout, char *dest, * \retval -1 if arguments are invalid or pool name is too long */ int llapi_layout_pool_name_set(struct llapi_layout *layout, - char *pool_name) + const char *pool_name) { struct llapi_layout_comp *comp; @@ -1586,9 +1586,9 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode, } if (layout) { - rc = llapi_layout_sanity((struct llapi_layout *)layout, - path, false, - !!(layout->llot_mirror_count > 1)); + rc = llapi_layout_sanity_fsname_check( + (struct llapi_layout *)layout, path, false, + !!(layout->llot_mirror_count > 1)); if (rc) { llapi_layout_sanity_perror(rc); return -1; @@ -2218,7 +2218,8 @@ int llapi_layout_file_comp_add(const char *path, goto out; } - rc = llapi_layout_sanity(existing_layout, path, false, false); + rc = llapi_layout_sanity_fsname_check(existing_layout, path, + false, false); if (rc) { tmp_errno = errno; llapi_layout_sanity_perror(rc); @@ -2353,7 +2354,8 @@ int llapi_layout_file_comp_del(const char *path, uint32_t id, uint32_t flags) goto out; } - rc = llapi_layout_sanity(existing_layout, path, false, false); + rc = llapi_layout_sanity_fsname_check(existing_layout, path, + false, false); if (rc) { tmp_errno = errno; llapi_layout_sanity_perror(rc); @@ -2513,7 +2515,8 @@ int llapi_layout_file_comp_set(const char *path, uint32_t *ids, uint32_t *flags, goto out; } - rc = llapi_layout_sanity(existing_layout, path, false, false); + rc = llapi_layout_sanity_fsname_check(existing_layout, path, + false, false); if (rc) { tmp_errno = errno; llapi_layout_sanity_perror(rc); @@ -3447,10 +3450,10 @@ void llapi_layout_sanity_perror(int error) * \retval 0, success, positive: various errors, see * llapi_layout_sanity_perror, -1, failure */ -int llapi_layout_sanity(struct llapi_layout *layout, - const char *fname, - bool incomplete, - bool flr) +static int __llapi_layout_sanity(struct llapi_layout *layout, + const char *fname, + bool incomplete, + bool flr) { struct llapi_layout_sanity_args args = { { 0 } }; struct llapi_layout_comp *curr; @@ -3498,6 +3501,21 @@ 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 3d291dc..95c57ff 100644 --- a/lustre/utils/lustreapi_internal.h +++ b/lustre/utils/lustreapi_internal.h @@ -131,10 +131,10 @@ 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(char **pool_name, +static inline bool llapi_pool_name_is_valid(const char **pool_name, const char *fsname) { - char *ptr; + const char *ptr; if (*pool_name == NULL) return false; @@ -145,10 +145,12 @@ static inline bool llapi_pool_name_is_valid(char **pool_name, */ ptr = strchr(*pool_name, '.'); if (ptr != NULL) { - *ptr = '\0'; - if (fsname != NULL && strcmp(*pool_name, fsname) != 0) { - *ptr = '.'; - return false; + if (fsname != NULL) { + int fslen = strlen(fsname); + + if (fslen != ptr - *pool_name || + strncmp(*pool_name, fsname, fslen) != 0) + return false; } *pool_name = ptr + 1; } @@ -160,7 +162,7 @@ static inline bool llapi_pool_name_is_valid(char **pool_name, } -int llapi_layout_search_ost(__u32 ost, char *pname, char *fsname); +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". */ -- 1.8.3.1