From b399a2d8cbe195eb93e6000d19e24e5ed8864b69 Mon Sep 17 00:00:00 2001 From: Fan Yong Date: Sun, 15 May 2016 23:20:41 +0800 Subject: [PATCH] LU-7429 tests: inject lfsck failure properly In sanity-lfsck test_23, we need to inject some failure stub to simulate the case of dangling name entry. But the original mean may misguide the LFSCK to regard it as bad name entry. On the other hand, the test scripts injects some test delay that may cause the LFSCK to run slowly, so need more time to wait the LFSCK status changes. Signed-off-by: Fan Yong Change-Id: I36c6c1bd8d07d2af6680e18b6c722e3bfa3a0062 Reviewed-on: http://review.whamcloud.com/20916 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Jian Yu --- lustre/mdd/mdd_dir.c | 28 +++++++++++++--------------- lustre/tests/sanity-lfsck.sh | 32 +++++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index c722509..8ab41e45 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -1254,9 +1254,13 @@ static int mdd_declare_link(const struct lu_env *env, struct lu_attr *la, struct linkea_data *data) { + struct lu_fid tfid = *mdo2fid(c); int rc; - rc = mdo_declare_index_insert(env, p, mdo2fid(c), mdd_object_type(c), + if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3)) + tfid.f_oid = cfs_fail_val; + + rc = mdo_declare_index_insert(env, p, &tfid, mdd_object_type(c), name->ln_name, handle); if (rc != 0) return rc; @@ -1301,8 +1305,9 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj, struct mdd_object *mdd_sobj = md2mdd_obj(src_obj); struct lu_attr *cattr = MDD_ENV_VAR(env, cattr); struct lu_attr *tattr = MDD_ENV_VAR(env, tattr); - struct mdd_device *mdd = mdo2mdd(src_obj); - struct thandle *handle; + struct mdd_device *mdd = mdo2mdd(src_obj); + struct thandle *handle; + struct lu_fid *tfid = &mdd_env_info(env)->mti_fid2; struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data; int rc; ENTRY; @@ -1351,19 +1356,12 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj, GOTO(out_unlock, rc); } - if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3)) { - struct lu_fid tfid = *mdo2fid(mdd_sobj); - - tfid.f_oid++; - rc = __mdd_index_insert_only(env, mdd_tobj, &tfid, - mdd_object_type(mdd_sobj), - name, handle); - } else { - rc = __mdd_index_insert_only(env, mdd_tobj, mdo2fid(mdd_sobj), - mdd_object_type(mdd_sobj), - name, handle); - } + *tfid = *mdo2fid(mdd_sobj); + if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3)) + tfid->f_oid = cfs_fail_val; + rc = __mdd_index_insert_only(env, mdd_tobj, tfid, + mdd_object_type(mdd_sobj), name, handle); if (rc != 0) { mdo_ref_del(env, mdd_sobj, handle); GOTO(out_unlock, rc); diff --git a/lustre/tests/sanity-lfsck.sh b/lustre/tests/sanity-lfsck.sh index 55b0f5d..482d295 100644 --- a/lustre/tests/sanity-lfsck.sh +++ b/lustre/tests/sanity-lfsck.sh @@ -3047,11 +3047,22 @@ test_23b() { echo "dummy" > $DIR/$tdir/d0/f0 || error "(2) Fail to touch on MDT0" echo "dead" > $DIR/$tdir/d0/f1 || error "(3) Fail to touch on MDT0" + local OID=$($LFS path2fid $DIR/$tdir/d0/f1 | awk -F':' '{print $2}') + OID=$(printf %d $OID) + + if [ $OID -eq 1 ]; then + # To guarantee that the f0 and f1 are in the same FID seq + rm -f $DIR/$tdir/d0/f0 || + error "(3.1) Fail to unlink $DIR/$tdir/d0/f0" + echo "dummy" > $DIR/$tdir/d0/f0 || + error "(3.2) Fail to touch on MDT0" + fi + echo "Inject failure stub on MDT0 to simulate dangling name entry" #define OBD_FAIL_LFSCK_DANGLING3 0x1621 - do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1621 + do_facet $SINGLEMDS $LCTL set_param fail_val=$OID fail_loc=0x1621 ln $DIR/$tdir/d0/f0 $DIR/$tdir/d0/foo || error "(4) Fail to hard link" - do_facet $SINGLEMDS $LCTL set_param fail_loc=0 + do_facet $SINGLEMDS $LCTL set_param fail_val=0 fail_loc=0 rm -f $DIR/$tdir/d0/f1 || error "(5) Fail to unlink $DIR/$tdir/d0/f1" @@ -3106,11 +3117,22 @@ test_23c() { echo "dummy" > $DIR/$tdir/d0/f0 || error "(2) Fail to touch on MDT0" echo "dead" > $DIR/$tdir/d0/f1 || error "(3) Fail to touch on MDT0" + local OID=$($LFS path2fid $DIR/$tdir/d0/f1 | awk -F':' '{print $2}') + OID=$(printf %d $OID) + + if [ $OID -eq 1 ]; then + # To guarantee that the f0 and f1 are in the same FID seq + rm -f $DIR/$tdir/d0/f0 || + error "(3.1) Fail to unlink $DIR/$tdir/d0/f0" + echo "dummy" > $DIR/$tdir/d0/f0 || + error "(3.2) Fail to touch on MDT0" + fi + echo "Inject failure stub on MDT0 to simulate dangling name entry" #define OBD_FAIL_LFSCK_DANGLING3 0x1621 - do_facet $SINGLEMDS $LCTL set_param fail_loc=0x1621 + do_facet $SINGLEMDS $LCTL set_param fail_val=$OID fail_loc=0x1621 ln $DIR/$tdir/d0/f0 $DIR/$tdir/d0/foo || error "(4) Fail to hard link" - do_facet $SINGLEMDS $LCTL set_param fail_loc=0 + do_facet $SINGLEMDS $LCTL set_param fail_val=0 fail_loc=0 rm -f $DIR/$tdir/d0/f1 || error "(5) Fail to unlink $DIR/$tdir/d0/f1" @@ -3126,7 +3148,7 @@ test_23c() { error "(7) Fail to start LFSCK for namespace" wait_update_facet client "stat $DIR/$tdir/d0/foo | - awk '/Size/ { print \\\$2 }'" "0" 32 || { + awk '/Size/ { print \\\$2 }'" "0" $LTIME || { stat $DIR/$tdir/guard $SHOW_NAMESPACE error "(8) unexpected size" -- 1.8.3.1