Skip to contentSkip to conversation

gfs2: fix race between gfs2_freeze_func and unmount

PATCH New Abhi Das 1 participant 2 messages Apr 30, 2019 GFS2 file system

lore
Share & tools
lore

Abhi Das

author
#0 lore raw

PATCH 1/1 gfs2: fix race between gfs2_freeze_func and unmount

gfs2_unfreee() doesn't wait for gfs2_freeze_func() to complete. If a umount is issued right after unfreeze, it could result in an inconsistent filesystem because some journal data (statfs update) wasn't written out.

This patch causes gfs2_unfreeze() to wait for gfs2_freeze_func() to complete before returning to the user.

---
 fs/gfs2/incore.h | 1 +
 fs/gfs2/super.c  | 8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)
fs/gfs2/incore.h +1 -0
index 78c8e761b321..b15755068593 100644
@@ -621,6 +621,7 @@ enum {
 	SDF_SKIP_DLM_UNLOCK	= 8,
 	SDF_FORCE_AIL_FLUSH     = 9,
 	SDF_AIL1_IO_ERROR	= 10,
+	SDF_FS_FROZEN           = 11,
 };
 
 enum gfs2_freeze_state {
fs/gfs2/super.c +5 -3
index a6a325b2a78b..a81d7a5afe39 100644
@@ -973,8 +973,7 @@ void gfs2_freeze_func(struct work_struct *work)
 	if (error) {
 		printk(KERN_INFO "GFS2: couldn't get freeze lock : %d\n", error);
 		gfs2_assert_withdraw(sdp, 0);
-	}
-	else {
+	} else {
 		atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
 		error = thaw_super(sb);
 		if (error) {
@@ -987,6 +986,8 @@ void gfs2_freeze_func(struct work_struct *work)
 		gfs2_glock_dq_uninit(&freeze_gh);
 	}
 	deactivate_super(sb);
+	clear_bit(SDF_FS_FROZEN, &sdp->sd_flags);
+	wake_up_bit(&sdp->sd_flags, SDF_FS_FROZEN);
 	return;
 }
 
@@ -1029,6 +1030,7 @@ static int gfs2_freeze(struct super_block *sb)
 		msleep(1000);
 	}
 	error = 0;
+	set_bit(SDF_FS_FROZEN, &sdp->sd_flags);
 out:
 	mutex_unlock(&sdp->sd_freeze_mutex);
 	return error;
@@ -1053,7 +1055,7 @@ static int gfs2_unfreeze(struct super_block *sb)
 
 	gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
 	mutex_unlock(&sdp->sd_freeze_mutex);
-	return 0;
+	return wait_on_bit(&sdp->sd_flags, SDF_FS_FROZEN, TASK_INTERRUPTIBLE);
 }
 
 /**
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 gfs2: fix race between gfs2_freeze_func and unmount

NACK. Andreas mentioned that the description could be more descriptive and that we should be using clear_bit_unlock() instead of clear_bit(). I'll post a v2 shortly with these changes.

Cheers!
--Abhi

Quoted 67 lines · Abhi Das

gfs2_unfreee() doesn't wait for gfs2_freeze_func() to complete. If a umount is issued right after unfreeze, it could result in an inconsistent filesystem because some journal data (statfs update) wasn't written out.

This patch causes gfs2_unfreeze() to wait for gfs2_freeze_func() to complete before returning to the user.

---
 fs/gfs2/incore.h | 1 +
 fs/gfs2/super.c  | 8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)
fs/gfs2/incore.h +1 -0
index 78c8e761b321..b15755068593 100644
@@ -621,6 +621,7 @@ enum {
        SDF_SKIP_DLM_UNLOCK     = 8,
        SDF_FORCE_AIL_FLUSH     = 9,
        SDF_AIL1_IO_ERROR       = 10,
+       SDF_FS_FROZEN           = 11,
 };
 
 enum gfs2_freeze_state {
fs/gfs2/super.c +1 -2
index a6a325b2a78b..a81d7a5afe39 100644
@@ -973,8 +973,7 @@ void gfs2_freeze_func(struct work_struct *work)
        if (error) {
                printk(KERN_INFO "GFS2: couldn't get freeze lock : %d\n",
 error);
                gfs2_assert_withdraw(sdp, 0);
-       }
-       else {
+       } else {
                atomic_set(&sdp->sd_freeze_state, SFS_UNFROZEN);
                error = thaw_super(sb);
                if (error) {
fs/gfs2/super.c +4 -1
@@ -987,6 +986,8 @@ void gfs2_freeze_func(struct work_struct *work)
                gfs2_glock_dq_uninit(&freeze_gh);
        }
        deactivate_super(sb);
+       clear_bit(SDF_FS_FROZEN, &sdp->sd_flags);
+       wake_up_bit(&sdp->sd_flags, SDF_FS_FROZEN);
        return;
 }
 
@@ -1029,6 +1030,7 @@ static int gfs2_freeze(struct super_block *sb)
                msleep(1000);
        }
        error = 0;
+       set_bit(SDF_FS_FROZEN, &sdp->sd_flags);
 out:
        mutex_unlock(&sdp->sd_freeze_mutex);
        return error;
@@ -1053,7 +1055,7 @@ static int gfs2_unfreeze(struct super_block *sb)
 
        gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
        mutex_unlock(&sdp->sd_freeze_mutex);
-       return 0;
+       return wait_on_bit(&sdp->sd_flags, SDF_FS_FROZEN,
 TASK_INTERRUPTIBLE);
 }
 
Quoted 5 lines

/**
--
2.20.1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/cluster-devel/attachments/20190430/deea5fe8/attachment.htm>