From f36f00811fddd8c1494cba080ebaaa44bbc284b2 Mon Sep 17 00:00:00 2001 From: Emoly Liu Date: Fri, 10 Apr 2020 10:20:04 +0800 Subject: [PATCH] LU-13301 lfs: return error when setstripe -o on inactive OSTs When running "lfs setstripe" on inactive OSTs with -o option, error code ENOTCONN returned by osp_statfs() for OST inactive state is mistreated as MDT disconnection by the client, then the client keeps trying to restore the connection to MDT and resend the request again and again. To fix this issue, the error code "ENOTCONN" is changed to other code (EREMOTEIO) for distinction. sanity.sh test_27cf is added to verify this patch. Signed-off-by: Emoly Liu Change-Id: I9ea10b4985c769e52ee54ff22ac69948073b7709 Reviewed-on: https://review.whamcloud.com/37751 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Li Xi Reviewed-by: Oleg Drokin --- lustre/lod/lod_qos.c | 10 +++++++++- lustre/tests/sanity.sh | 22 ++++++++++++++++++++++ lustre/utils/liblustreapi.c | 8 ++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lustre/lod/lod_qos.c b/lustre/lod/lod_qos.c index 2d6d369..110ad09 100644 --- a/lustre/lod/lod_qos.c +++ b/lustre/lod/lod_qos.c @@ -104,6 +104,7 @@ static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d, { struct lov_desc *desc = <d->ltd_lov_desc; int rc; + ENTRY; LASSERT(d); LASSERT(tgt); @@ -152,8 +153,15 @@ static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d, } spin_unlock(&d->lod_lock); } + if (rc == -ENOTCONN) { + /* In case that the ENOTCONN for inactive OST state is + * mistreated as MDT disconnection state by the client, + * this error should be changed to someone else. + */ + rc = -EREMOTEIO; + } - return rc; + RETURN(rc); } static int lod_is_tgt_usable(struct lu_tgt_descs *ltd, struct lu_tgt_desc *tgt) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index dbed968..950fad3 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -1635,6 +1635,28 @@ test_27ce() { } run_test 27ce "more stripes than OSTs with -o" +test_27cf() { + local osp_proc="osp.$FSNAME-OST0000-osc-MDT000*.active" + local pid=0 + + test_mkdir -p $DIR/$tdir || error "failed to mkdir $DIR/$tdir" + do_facet $SINGLEMDS "$LCTL set_param -n $osp_proc=0" + stack_trap "do_facet $SINGLEMDS $LCTL set_param -n $osp_proc=1" EXIT + wait_update_facet $SINGLEMDS "$LCTL get_param -n $osp_proc | grep 1" || + error "failed to set $osp_proc=0" + + $LFS setstripe -o 0 $DIR/$tdir/$tfile & + pid=$! + sleep 1 + do_facet $SINGLEMDS "$LCTL set_param -n $osp_proc=1" + wait_update_facet $SINGLEMDS "$LCTL get_param -n $osp_proc | grep 0" || + error "failed to set $osp_proc=1" + wait $pid + [[ $pid -ne 0 ]] || + error "should return error due to $osp_proc=0" +} +run_test 27cf "'setstripe -o' on inactive OSTs should return error" + test_27d() { test_mkdir $DIR/$tdir $LFS setstripe -c 0 -i -1 -S 0 $DIR/$tdir/$tfile || diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index a753dfc..1f1494f 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -714,11 +714,15 @@ retry_open: } if (ioctl(fd, LL_IOC_LOV_SETSTRIPE, lum) != 0) { - char *errmsg = "stripe already set"; + char errmsg[512] = "stripe already set"; rc = -errno; if (errno != EEXIST && errno != EALREADY) - errmsg = strerror(errno); + strncpy(errmsg, strerror(errno), sizeof(errmsg) - 1); + if (rc == -EREMOTEIO) + snprintf(errmsg, sizeof(errmsg), + "inactive OST among your specified %d OST(s)", + param->lsp_stripe_count); llapi_err_noerrno(LLAPI_MSG_ERROR, "setstripe error for '%s': %s", name, errmsg); -- 1.8.3.1