From 61c232554dae25340369e19baa98424e76288a22 Mon Sep 17 00:00:00 2001 From: Rajeev Mishra Date: Mon, 11 Mar 2024 18:53:11 +0000 Subject: [PATCH] LU-17025 llapi: restore 'pool=ignore' functionality Changes to llapi_stripe_param_verify() and related llapi file creation functions to verify that the given pool name is valid introduced a bug that disallowed the 'ignore' pool name, which is used to create files without any pool name. Allow the reserved pool names from lov_pool_is_reserved() to be used even (especially!) if the named pool does not exist. Revert the changes to ost-pools.sh::test_32() that created the 'ignore_pool' pool, and go back to checking that 'ignore' will create a file that does not use any pool. Change the pool name validation to only do fsname lookup if the pool name is actually specified, instead of looking up fsname but not actually using it for anything. Fixes: ee7dfc5ad1 ("LU-17025 llapi: Verify stripe pool name") Signed-off-by: Rajeev Mishra Change-Id: I9368f28a41fd9af6b6f0e9468df0e7dfd728db1c Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/54355 Reviewed-by: Shaun Tancheff Reviewed-by: Petros Koutoupis Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo --- lustre/tests/ost-pools.sh | 12 ++++------ lustre/utils/liblustreapi.c | 32 ++++++++++++++----------- lustre/utils/liblustreapi_layout.c | 48 ++++++++++++++++++++++++++------------ 3 files changed, 55 insertions(+), 37 deletions(-) diff --git a/lustre/tests/ost-pools.sh b/lustre/tests/ost-pools.sh index e275403..12b0ff6 100755 --- a/lustre/tests/ost-pools.sh +++ b/lustre/tests/ost-pools.sh @@ -1930,20 +1930,16 @@ test_32() { # LU-15707 ( $LFS getstripe -p $DIR/$tdir | grep -q $pool ) || error "fail to set pool on $DIR/$tdir" - local ig_pool="ignore_pool" - - pool_add $ig_pool || error "add $ig_pool failed" - - $LFS setstripe -p $ig_pool $DIR/$tdir/$tfile || + $LFS setstripe -p ignore $DIR/$tdir/$tfile || error "setstripe fail on $DIR/$tdir/$tfile" - ( $LFS getstripe -p $DIR/$tdir/$tfile | grep -q $ig_pool ) || + ! ( $LFS getstripe -p $DIR/$tdir/$tfile | egrep -q "[^ ]+" ) || error "fail to create $DIR/$tdir/$tfile without pool" # Test with start index local got idx for ((idx = 0; idx < OSTCOUNT; idx++)); do - $LFS setstripe -p $ig_pool -i $idx $DIR/$tdir/$tfile.$idx || + $LFS setstripe -p ignore -i $idx $DIR/$tdir/$tfile.$idx || error "setstripe -i fail on $DIR/$tdir/$tfile.$idx" got=$($LFS getstripe -i $DIR/$tdir/$tfile.$idx) @@ -1952,7 +1948,7 @@ test_32() { # LU-15707 done # Test with ost list - $LFS setstripe -p $ig_pool -o 1,0 $DIR/$tdir/$tfile.1_0 || + $LFS setstripe -p ignore -o 1,0 $DIR/$tdir/$tfile.1_0 || error "setstripe --ost fail on $DIR/$tdir/$tfile.1_0" got=$($LFS getstripe -i $DIR/$tdir/$tfile.1_0) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index bafd87f..464f711 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -424,14 +424,16 @@ static int llapi_stripe_param_verify(const struct llapi_stripe_param *param, goto out; } - /* Make sure the pool exists */ - rc = llapi_search_ost(fsname, *pool_name, NULL); - if (rc < 0) { - llapi_error(LLAPI_MSG_ERROR, rc, - "pool '%s fsname %s' does not exist", - *pool_name, fsname); - rc = -EINVAL; - goto out; + if (!lov_pool_is_ignored((const char *) *pool_name)) { + /* Make sure the pool exists */ + rc = llapi_search_ost(fsname, *pool_name, NULL); + if (rc < 0) { + llapi_error(LLAPI_MSG_ERROR, rc, + "pool '%s fsname %s' does not exist", + *pool_name, fsname); + rc = -EINVAL; + goto out; + } } } @@ -561,14 +563,16 @@ int llapi_file_open_param(const char *name, int flags, mode_t mode, struct lov_user_md *lum = NULL; const char *pool_name = param->lsp_pool; size_t lum_size; - int fd, rc; + int fd, rc = 0; /* 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; + if (pool_name && !lov_pool_is_ignored(pool_name)) { + 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. */ diff --git a/lustre/utils/liblustreapi_layout.c b/lustre/utils/liblustreapi_layout.c index 05f4dae..640cc7d 100644 --- a/lustre/utils/liblustreapi_layout.c +++ b/lustre/utils/liblustreapi_layout.c @@ -1775,6 +1775,9 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode, struct lov_user_md *lum; size_t lum_size; char fsname[MAX_OBD_NAME + 1] = { 0 }; + struct llapi_layout_comp *comp; + + comp = __llapi_layout_cur_comp(layout); if (path == NULL || (layout != NULL && layout->llot_magic != LLAPI_LAYOUT_MAGIC)) { @@ -1784,10 +1787,13 @@ int llapi_layout_file_open(const char *path, int open_flags, mode_t mode, if (layout) { /* Make sure we are on a Lustre file system */ - rc = llapi_search_fsname(path, fsname); - if (rc) { - errno = ENOTTY; - return -1; + if (comp->llc_pool_name[0] != '\0' && + !lov_pool_is_ignored(comp->llc_pool_name)) { + rc = llapi_search_fsname(path, fsname); + if (rc) { + errno = ENOTTY; + return -1; + } } rc = llapi_layout_v2_sanity((struct llapi_layout *)layout, false, @@ -2405,6 +2411,7 @@ int llapi_layout_file_comp_add(const char *path, struct llapi_layout *existing_layout = NULL; struct lov_user_md *lum = NULL; char fsname[MAX_OBD_NAME + 1] = { 0 }; + struct llapi_layout_comp *comp; if (path == NULL || layout == NULL || layout->llot_magic != LLAPI_LAYOUT_MAGIC) { @@ -2433,11 +2440,16 @@ int llapi_layout_file_comp_add(const char *path, goto out; } - rc = llapi_search_fsname(path, fsname); - if (rc) { - tmp_errno = -rc; - rc = -1; - goto out; + comp = __llapi_layout_cur_comp(layout); + + if (comp->llc_pool_name[0] != '\0' && + !lov_pool_is_ignored(comp->llc_pool_name)) { + rc = llapi_search_fsname(path, fsname); + if (rc) { + tmp_errno = -rc; + rc = -1; + goto out; + } } rc = llapi_layout_v2_sanity(existing_layout, false, false, fsname); @@ -2736,11 +2748,16 @@ int llapi_layout_file_comp_set(const char *path, uint32_t *ids, uint32_t *flags, goto out; } - rc = llapi_search_fsname(path, fsname); - if (rc) { - tmp_errno = -rc; - rc = -1; - goto out; + comp = __llapi_layout_cur_comp(layout); + + if (comp && comp->llc_pool_name[0] != '\0' && + !lov_pool_is_ignored(comp->llc_pool_name)) { + rc = llapi_search_fsname(path, fsname); + if (rc) { + tmp_errno = -rc; + rc = -1; + goto out; + } } rc = llapi_layout_v2_sanity(existing_layout, false, false, fsname); @@ -3596,7 +3613,8 @@ static inline int verify_pool_name(char *fsname, struct llapi_layout *layout) comp = __llapi_layout_cur_comp(layout); if (!comp) return 0; - if (comp->llc_pool_name[0] == '\0') + if (comp->llc_pool_name[0] == '\0' || + lov_pool_is_ignored(comp->llc_pool_name)) return 0; /* check if the pool name exist */ if (llapi_search_ost(fsname, comp->llc_pool_name, NULL) < 0) -- 1.8.3.1