From 723065fca5b0dc2f93848de47a0b82b11a6bbb1a Mon Sep 17 00:00:00 2001 From: wang di Date: Thu, 24 Sep 2015 00:35:33 -0700 Subject: [PATCH] LU-6868 mdd: add changelog for migration Add changelog for migration, so robinhood policy engine can handle the migration command. Add test_160d to verify the migration changelog Signed-off-by: wang di Change-Id: Iaa33dee607fcd79285f59bd3131d70b7e5329622 Reviewed-on: http://review.whamcloud.com/16645 Tested-by: Jenkins Reviewed-by: Andreas Dilger Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Henri Doreau Reviewed-by: Oleg Drokin --- lustre/include/lustre/lustre_user.h | 3 ++- lustre/mdd/mdd_dir.c | 22 ++++++++++++++++++++-- lustre/tests/sanity.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index ecb0a8c..ce073c9 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -732,6 +732,7 @@ enum changelog_rec_type { CL_MTIME = 17, /* Precedence: setattr > mtime > ctime > atime */ CL_CTIME = 18, CL_ATIME = 19, + CL_MIGRATE = 20, CL_LAST }; @@ -739,7 +740,7 @@ static inline const char *changelog_type2str(int type) { static const char *changelog_str[] = { "MARK", "CREAT", "MKDIR", "HLINK", "SLINK", "MKNOD", "UNLNK", "RMDIR", "RENME", "RNMTO", "OPEN", "CLOSE", "LYOUT", "TRUNC", - "SATTR", "XATTR", "HSM", "MTIME", "CTIME", "ATIME", + "SATTR", "XATTR", "HSM", "MTIME", "CTIME", "ATIME", "MIGRT" }; if (type >= 0 && type < CL_LAST) diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 8cb25d4..658a4d7 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -3762,8 +3762,9 @@ static int mdd_declare_migrate_update_name(const struct lu_env *env, struct linkea_data *ldata, struct thandle *handle) { - struct lu_attr *la_flag = MDD_ENV_VAR(env, tattr); - int rc; + struct mdd_device *mdd = mdo2mdd(&mdd_sobj->mod_obj); + struct lu_attr *la_flag = MDD_ENV_VAR(env, tattr); + int rc; /* Revert IMMUTABLE flag */ la_flag->la_valid = LA_FLAGS; @@ -3842,6 +3843,10 @@ static int mdd_declare_migrate_update_name(const struct lu_env *env, return rc; rc = mdo_declare_attr_set(env, mdd_pobj, parent_la, handle); + if (rc != 0) + return rc; + + rc = mdd_declare_changelog_store(env, mdd, lname, NULL, handle); return rc; } @@ -3977,6 +3982,19 @@ static int mdd_migrate_update_name(const struct lu_env *env, if (rc != 0) GOTO(out_unlock, rc); + rc = mdd_changelog_ns_store(env, mdd, CL_MIGRATE, 0, mdd_tobj, + mdo2fid(mdd_pobj), mdo2fid(mdd_sobj), + mdo2fid(mdd_pobj), lname, lname, handle); + if (rc != 0) { + CWARN("%s: changelog for migrate %s "DFID + "under "DFID" failed: rc = %d\n", + mdd2obd_dev(mdd)->obd_name, lname->ln_name, + PFID(mdd_object_fid(mdd_sobj)), + PFID(mdd_object_fid(mdd_pobj)), rc); + /* Sigh, there are no easy way to migrate back the object, so + * let's reset the result to 0 for now XXX */ + rc = 0; + } out_unlock: mdd_write_unlock(env, mdd_sobj); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 5423200..6a4ed0e 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -10589,6 +10589,36 @@ test_160c() { } run_test 160c "verify that changelog log catch the truncate event" +test_160d() { + remote_mds_nodsh && skip "remote MDS with nodsh" && return + [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return + + local server_version=$(lustre_version_code mds1) + local CL_MASK_PARAM="mdd.$MDT0.changelog_mask" + + [[ $server_version -ge $(version_code 2.7.60) ]] || + { skip "Need MDS version at least 2.7.60+"; return; } + [ $PARALLEL == "yes" ] && skip "skip parallel run" && return + + # Registration step + local USER=$(do_facet mds1 $LCTL --device $MDT0 \ + changelog_register -n) + + mkdir -p $DIR/$tdir/migrate_dir + $LFS changelog_clear $MDT0 $USER 0 + + $LFS migrate -m 1 $DIR/$tdir/migrate_dir || error "migrate fails" + $LFS changelog $MDT0 + MIGRATES=$($LFS changelog $MDT0 | tail -5 | grep -c "MIGRT") + $LFS changelog_clear $MDT0 $USER 0 + [ $MIGRATES -eq 1 ] || + error "MIGRATE changelog mask count $MIGRATES != 1" + + # Deregistration step + do_facet mds1 $LCTL --device $MDT0 changelog_deregister $USER +} +run_test 160d "verify that changelog log catch the migrate event" + test_161a() { [ $PARALLEL == "yes" ] && skip "skip parallel run" && return test_mkdir -p -c1 $DIR/$tdir -- 1.8.3.1