From c7d8fe31064990d7053436ccd720c531bc78a2dc Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Wed, 2 Jun 2021 12:05:01 -0500 Subject: [PATCH] LU-14731 mdd: clear orphans changelog entries In mdd_changelog_llog_init(), adjust the orphan changelog index logic to account for the case when no users are registered. Add sanity test_160n() to verify this. Signed-off-by: John L. Hammond Change-Id: I03b0c1002a0e16f26af8ec23bf06c9a07dec858a Reviewed-on: https://review.whamcloud.com/43901 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alexander Boyko Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- lustre/mdd/mdd_device.c | 20 +++++++++++--------- lustre/tests/sanity.sh | 35 +++++++++++++++++++++++++++++++++++ lustre/tests/test-framework.sh | 1 + 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index e7923f1..59a852d 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -267,7 +267,8 @@ static int changelog_user_detect_orphan_cb(const struct lu_env *env, struct llog_handle *llh, struct llog_rec_hdr *hdr, void *data) { - struct mdd_device *mdd = ((struct changelog_orphan_data *)data)->mdd; + struct changelog_orphan_data *user_orphan = data; + struct mdd_device *mdd = user_orphan->mdd; struct llog_changelog_user_rec *rec = container_of(hdr, struct llog_changelog_user_rec, cur_hdr); @@ -289,9 +290,7 @@ static int changelog_user_detect_orphan_cb(const struct lu_env *env, rec->cur_hdr.lrh_index, rec->cur_id, rec->cur_endrec, PFID(&llh->lgh_id.lgl_oi.oi_fid)); - if (((struct changelog_orphan_data *)data)->index == 0 || - rec->cur_endrec < ((struct changelog_orphan_data *)data)->index) - ((struct changelog_orphan_data *)data)->index = rec->cur_endrec; + user_orphan->index = min_t(__u64, user_orphan->index, rec->cur_endrec); return 0; } @@ -449,11 +448,14 @@ static int mdd_changelog_llog_init(const struct lu_env *env, { struct obd_device *obd = mdd2obd_dev(mdd); struct llog_ctxt *ctxt = NULL, *uctxt = NULL; - struct changelog_orphan_data changelog_orphan = { .index = 0, - .mdd = mdd }, - user_orphan = { .index = 0, - .mdd = mdd }; - int rc; + struct changelog_orphan_data changelog_orphan = { + .mdd = mdd, + .index = -1, + }, user_orphan = { + .mdd = mdd, + .index = -1, + }; + int rc; ENTRY; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 543c3fd..ea94563 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -16191,6 +16191,41 @@ test_160n() { } run_test 160n "Changelog destroy race" +test_160p() { + remote_mds_nodsh && skip "remote MDS with nodsh" && return + [[ $MDS1_VERSION -ge $(version_code 2.14.51) ]] || + skip "Need MDS version at least 2.14.51" + [[ "$mds1_FSTYPE" == "ldiskfs" ]] || skip "ldiskfs only test" + local cl_users + local cl_user1 + local entry_count + + # Create a user + changelog_register || error "first changelog_register failed" + + cl_users=(${CL_USERS[mds1]}) + cl_user1="${cl_users[0]}" + + test_mkdir -p -i0 -c1 $DIR/$tdir || error "test_mkdir $tdir failed" + createmany -m $DIR/$tdir/$tfile 50 || + error "create $DIR/$tdir/$tfile failed" + unlinkmany $DIR/$tdir/$tfile 50 || error "unlinkmany failed" + rm -rf $DIR/$tdir + + # check changelogs have been generated + entry_count=$(changelog_dump | wc -l) + ((entry_count != 0)) || error "no changelog entries found" + + # remove changelog_users and check that orphan entries are removed + stop mds1 + do_facet mds1 "$DEBUGFS -w -R 'rm changelog_users' $(mdsdevname 1)" + start mds1 || error "cannot start mdt" + entry_count=$(changelog_dump | wc -l) + ((entry_count == 0)) || + error "found $entry_count changelog entries, expected none" +} +run_test 160p "Changelog orphan cleanup with no users" + test_161a() { [ $PARALLEL == "yes" ] && skip "skip parallel run" diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index f640200..f06aa14 100755 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -9471,6 +9471,7 @@ changelog_clear() { # so reorder to get same order than in changelog_register() local cl_facets=$(echo "${!CL_USERS[@]}" | tr " " "\n" | sort | tr "\n" " ") + local cl_user for facet in $cl_facets; do for cl_user in ${CL_USERS[$facet]}; do -- 1.8.3.1