From 1d3ee3ed2b56d73f392e1b2a033f7d274f5202d9 Mon Sep 17 00:00:00 2001 From: Henri Doreau Date: Thu, 27 Nov 2014 14:51:09 +0100 Subject: [PATCH] LU-5957 mdt: Update MDT flags after layout swap Swap MOF_LOV_CREATED flags between MDT objects after a layout swap to guarantee that layout will be re-created on next write if its LOV has been deleted. Signed-off-by: Henri Doreau Change-Id: I3d0497d8be2a7335c1fb43e10af2b222243e6a81 Reviewed-on: http://review.whamcloud.com/12877 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: frank zago Reviewed-by: Oleg Drokin --- lustre/mdt/mdt_handler.c | 32 +++++++++++++++++++++++++++++++- lustre/tests/sanity.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index b19f7c7..aec10b3 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -1234,6 +1234,32 @@ out: return rc; } +/** + * Exchange MOF_LOV_CREATED flags between two objects after a + * layout swap. No assumption is made on whether o1 or o2 have + * created objects or not. + * + * \param[in,out] o1 First swap layout object + * \param[in,out] o2 Second swap layout object + */ +static void mdt_swap_lov_flag(struct mdt_object *o1, struct mdt_object *o2) +{ + __u64 o1_flags; + + mutex_lock(&o1->mot_lov_mutex); + mutex_lock(&o2->mot_lov_mutex); + + o1_flags = o1->mot_flags; + o1->mot_flags = (o1->mot_flags & ~MOF_LOV_CREATED) | + (o2->mot_flags & MOF_LOV_CREATED); + + o2->mot_flags = (o2->mot_flags & ~MOF_LOV_CREATED) | + (o1_flags & MOF_LOV_CREATED); + + mutex_unlock(&o2->mot_lov_mutex); + mutex_unlock(&o1->mot_lov_mutex); +} + static int mdt_swap_layouts(struct tgt_session_info *tsi) { struct mdt_thread_info *info; @@ -1319,7 +1345,11 @@ static int mdt_swap_layouts(struct tgt_session_info *tsi) rc = mo_swap_layouts(info->mti_env, mdt_object_child(o1), mdt_object_child(o2), msl->msl_flags); - GOTO(unlock2, rc); + if (rc < 0) + GOTO(unlock2, rc); + + mdt_swap_lov_flag(o1, o2); + unlock2: mdt_object_unlock(info, o2, lh2, rc); unlock1: diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index e06ab8e..b22ccfe 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -11148,6 +11148,39 @@ test_184d() { } run_test 184d "allow stripeless layouts swap" +test_184e() { + check_swap_layouts_support && return 0 + [ -z "$(which getfattr 2>/dev/null)" ] && + skip "no getfattr command" && return 0 + + local file1=$DIR/$tdir/$tfile-1 + local file2=$DIR/$tdir/$tfile-2 + local file3=$DIR/$tdir/$tfile-3 + local lovea + + mkdir -p $DIR/$tdir + touch $file1 || error "create $file1 failed" + $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file2 || + error "create $file2 failed" + $OPENFILE -f O_CREAT:O_LOV_DELAY_CREATE $file3 || + error "create $file3 failed" + + $LFS swap_layouts $file1 $file2 || + error "swap $file1 $file2 layouts failed" + + lovea=$(getfattr -n trusted.lov $file1 | grep ^trusted) + [[ -z "$lovea" ]] || error "$file1 shouldn't have lovea" + + echo 123 > $file1 || error "Should be able to write into $file1" + + $LFS swap_layouts $file1 $file3 || + error "swap $file1 $file3 layouts failed" + + echo 123 > $file1 || error "Should be able to write into $file1" + + rm -rf $file1 $file2 $file3 +} +run_test 184e "Recreate layout after stripeless layout swaps" test_185() { # LU-2441 # LU-3553 - no volatile file support in old servers -- 1.8.3.1