gfs2: Replace sd_freeze_state with SDF_FROZEN flag
authorAndreas Gruenbacher <agruenba@redhat.com>
Thu, 18 Aug 2022 14:12:24 +0000 (16:12 +0200)
committerAndreas Gruenbacher <agruenba@redhat.com>
Mon, 3 Jul 2023 20:30:23 +0000 (22:30 +0200)
Replace sd_freeze_state with a new SDF_FROZEN flag.

There no longer is a need for indicating that a freeze is in progress
(SDF_STARTING_FREEZE); we are now protecting the critical sections with
the sd_freeze_mutex.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/incore.h
fs/gfs2/log.c
fs/gfs2/ops_fstype.c
fs/gfs2/recovery.c
fs/gfs2/super.c
fs/gfs2/sys.c
fs/gfs2/trans.c

index 1f10529ebcf59de54cf7d74d4b9b388d98cf0b3d..8b1b50d19de1bf0ddf62139000ec7b333ada886c 100644 (file)
@@ -608,12 +608,7 @@ enum {
                                         withdrawing */
        SDF_DEACTIVATING        = 15,
        SDF_EVICTING            = 16,
-};
-
-enum gfs2_freeze_state {
-       SFS_UNFROZEN            = 0,
-       SFS_STARTING_FREEZE     = 1,
-       SFS_FROZEN              = 2,
+       SDF_FROZEN              = 17,
 };
 
 #define GFS2_FSNAME_LEN                256
@@ -841,7 +836,6 @@ struct gfs2_sbd {
 
        /* For quiescing the filesystem */
        struct gfs2_holder sd_freeze_gh;
-       atomic_t sd_freeze_state;
        struct mutex sd_freeze_mutex;
 
        char sd_fsname[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2];
index dca535311deef671c09329978e16080f5344dac2..aa568796207c0439d7b355511ba8e7004b896f39 100644 (file)
@@ -914,9 +914,8 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
 {
        blk_opf_t op_flags = REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC;
-       enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state);
 
-       gfs2_assert_withdraw(sdp, (state != SFS_FROZEN));
+       gfs2_assert_withdraw(sdp, !test_bit(SDF_FROZEN, &sdp->sd_flags));
 
        if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) {
                gfs2_ordered_wait(sdp);
@@ -1036,7 +1035,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
 {
        struct gfs2_trans *tr = NULL;
        unsigned int reserved_blocks = 0, used_blocks = 0;
-       enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state);
+       bool frozen = test_bit(SDF_FROZEN, &sdp->sd_flags);
        unsigned int first_log_head;
        unsigned int reserved_revokes = 0;
 
@@ -1067,7 +1066,7 @@ repeat:
                if (tr) {
                        sdp->sd_log_tr = NULL;
                        tr->tr_first = first_log_head;
-                       if (unlikely (state == SFS_FROZEN)) {
+                       if (unlikely(frozen)) {
                                if (gfs2_assert_withdraw_delayed(sdp,
                                       !tr->tr_num_buf_new && !tr->tr_num_databuf_new))
                                        goto out_withdraw;
@@ -1092,7 +1091,7 @@ repeat:
        if (flags & GFS2_LOG_HEAD_FLUSH_SHUTDOWN)
                clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
 
-       if (unlikely(state == SFS_FROZEN))
+       if (unlikely(frozen))
                if (gfs2_assert_withdraw_delayed(sdp, !reserved_revokes))
                        goto out_withdraw;
 
index 4ce5718719ace3bd9f5a7e088db9e3b109500686..24acd17e530cbaa06453d60c1dd270d97216f45d 100644 (file)
@@ -135,7 +135,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
        init_rwsem(&sdp->sd_log_flush_lock);
        atomic_set(&sdp->sd_log_in_flight, 0);
        init_waitqueue_head(&sdp->sd_log_flush_wait);
-       atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
        mutex_init(&sdp->sd_freeze_mutex);
 
        return sdp;
index afeda936e2beb0ce58856706816e9edc9dad2c8d..9c7a9f640badda89059935374062b784cc9dc581 100644 (file)
@@ -467,7 +467,7 @@ void gfs2_recover_func(struct work_struct *work)
        if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
                mutex_lock(&sdp->sd_freeze_mutex);
 
-               if (atomic_read(&sdp->sd_freeze_state) != SFS_UNFROZEN) {
+               if (test_bit(SDF_FROZEN, &sdp->sd_flags)) {
                        mutex_unlock(&sdp->sd_freeze_mutex);
                        fs_warn(sdp, "jid=%u: Can't replay: filesystem "
                                "is frozen\n", jd->jd_jid);
index 81c8d07a45409018400e55c91e6a4a3cdb36c7a7..6dcbfb9b930612feb7913f94845265927c9d36c8 100644 (file)
@@ -689,26 +689,19 @@ static int gfs2_freeze_locally(struct gfs2_sbd *sdp)
        struct super_block *sb = sdp->sd_vfs;
        int error;
 
-       atomic_set(&sdp->sd_freeze_state, SFS_STARTING_FREEZE);
-
        error = freeze_super(sb);
        if (error)
-               goto fail;
+               return error;
 
        if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
                gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_FREEZE |
                               GFS2_LFC_FREEZE_GO_SYNC);
                if (gfs2_withdrawn(sdp)) {
                        thaw_super(sb);
-                       error = -EIO;
-                       goto fail;
+                       return -EIO;
                }
        }
        return 0;
-
-fail:
-       atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
-       return error;
 }
 
 static int gfs2_do_thaw(struct gfs2_sbd *sdp)
@@ -737,7 +730,7 @@ void gfs2_freeze_func(struct work_struct *work)
 
        mutex_lock(&sdp->sd_freeze_mutex);
        error = -EBUSY;
-       if (atomic_read(&sdp->sd_freeze_state) != SFS_UNFROZEN)
+       if (test_bit(SDF_FROZEN, &sdp->sd_flags))
                goto freeze_failed;
 
        error = gfs2_freeze_locally(sdp);
@@ -745,13 +738,13 @@ void gfs2_freeze_func(struct work_struct *work)
                goto freeze_failed;
 
        gfs2_freeze_unlock(&sdp->sd_freeze_gh);
-       atomic_set(&sdp->sd_freeze_state, SFS_FROZEN);
+       set_bit(SDF_FROZEN, &sdp->sd_flags);
 
        error = gfs2_do_thaw(sdp);
        if (error)
                goto out;
 
-       atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
+       clear_bit(SDF_FROZEN, &sdp->sd_flags);
        goto out;
 
 freeze_failed:
@@ -776,7 +769,7 @@ static int gfs2_freeze_super(struct super_block *sb)
        if (!mutex_trylock(&sdp->sd_freeze_mutex))
                return -EBUSY;
        error = -EBUSY;
-       if (atomic_read(&sdp->sd_freeze_state) != SFS_UNFROZEN)
+       if (test_bit(SDF_FROZEN, &sdp->sd_flags))
                goto out;
 
        for (;;) {
@@ -811,7 +804,7 @@ static int gfs2_freeze_super(struct super_block *sb)
 out:
        if (!error) {
                set_bit(SDF_FREEZE_INITIATOR, &sdp->sd_flags);
-               atomic_set(&sdp->sd_freeze_state, SFS_FROZEN);
+               set_bit(SDF_FROZEN, &sdp->sd_flags);
        }
        mutex_unlock(&sdp->sd_freeze_mutex);
        return error;
@@ -840,7 +833,7 @@ static int gfs2_thaw_super(struct super_block *sb)
 
        if (!error) {
                clear_bit(SDF_FREEZE_INITIATOR, &sdp->sd_flags);
-               atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
+               clear_bit(SDF_FROZEN, &sdp->sd_flags);
        }
 out:
        mutex_unlock(&sdp->sd_freeze_mutex);
index bc752de0157370b4e66d22b7ec91ced8018462a5..2dfbe2f188dd08ea433f437c60880fb332da3984 100644 (file)
@@ -82,6 +82,7 @@ static ssize_t status_show(struct gfs2_sbd *sdp, char *buf)
                     "RO Recovery:              %d\n"
                     "Skip DLM Unlock:          %d\n"
                     "Force AIL Flush:          %d\n"
+                    "FS Freeze Initiator:      %d\n"
                     "FS Frozen:                %d\n"
                     "Withdrawing:              %d\n"
                     "Withdraw In Prog:         %d\n"
@@ -112,6 +113,7 @@ static ssize_t status_show(struct gfs2_sbd *sdp, char *buf)
                     test_bit(SDF_SKIP_DLM_UNLOCK, &f),
                     test_bit(SDF_FORCE_AIL_FLUSH, &f),
                     test_bit(SDF_FREEZE_INITIATOR, &f),
+                    test_bit(SDF_FROZEN, &f),
                     test_bit(SDF_WITHDRAWING, &f),
                     test_bit(SDF_WITHDRAW_IN_PROG, &f),
                     test_bit(SDF_REMOTE_WITHDRAW, &f),
index 63fec11ef2ce3fe8c37ff0f76a923444ee0df7d6..ec1631257978a89fa930bef50340df7a1653f68f 100644 (file)
@@ -233,7 +233,6 @@ void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh)
        struct gfs2_bufdata *bd;
        struct gfs2_meta_header *mh;
        struct gfs2_trans *tr = current->journal_info;
-       enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state);
 
        lock_buffer(bh);
        if (buffer_pinned(bh)) {
@@ -267,7 +266,7 @@ void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh)
                       (unsigned long long)bd->bd_bh->b_blocknr);
                BUG();
        }
-       if (unlikely(state == SFS_FROZEN)) {
+       if (unlikely(test_bit(SDF_FROZEN, &sdp->sd_flags))) {
                fs_info(sdp, "GFS2:adding buf while frozen\n");
                gfs2_assert_withdraw(sdp, 0);
        }