Whamcloud - gitweb
LU-14731 mdd: clear orphans changelog entries 01/43901/4
authorJohn L. Hammond <jhammond@whamcloud.com>
Wed, 2 Jun 2021 17:05:01 +0000 (12:05 -0500)
committerOleg Drokin <green@whamcloud.com>
Mon, 21 Jun 2021 22:17:53 +0000 (22:17 +0000)
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 <jhammond@whamcloud.com>
Change-Id: I03b0c1002a0e16f26af8ec23bf06c9a07dec858a
Reviewed-on: https://review.whamcloud.com/43901
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alexander Boyko <alexander.boyko@hpe.com>
Reviewed-by: Mike Pershin <mpershin@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/mdd/mdd_device.c
lustre/tests/sanity.sh
lustre/tests/test-framework.sh

index e7923f1..59a852d 100644 (file)
@@ -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;
 
index 543c3fd..ea94563 100755 (executable)
@@ -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"
 
index f640200..f06aa14 100755 (executable)
@@ -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