Skip to contentSkip to conversation

f2fs: don't set RO when shutting down f2fs

PATCH In review Jaegeuk Kim 3 participants 8 messages Apr 4, 2024 – Apr 10, 2024 F2FS file system

lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/1 f2fs: don't set RO when shutting down f2fs

Shutdown does not check the error of thaw_super due to readonly, which causes a deadlock like below.

f2fs_ioc_shutdown(F2FS_GOING_DOWN_FULLSYNC) issue_discard_thread
- bdev_freeze
- freeze_super
- f2fs_stop_checkpoint()
- f2fs_handle_critical_error - sb_start_write
- set RO - waiting
- bdev_thaw
- thaw_super_locked
- return -EINVAL, if sb_rdonly()
- f2fs_stop_discard_thread
-> wait for kthread_stop(discard_thread);

---
 fs/f2fs/super.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
fs/f2fs/super.c +9 -2
index df9765b41dac..ba6288e870c5 100644
@@ -4135,9 +4135,16 @@ void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason,
 	if (shutdown)
 		set_sbi_flag(sbi, SBI_IS_SHUTDOWN);
 
-	/* continue filesystem operators if errors=continue */
-	if (continue_fs || f2fs_readonly(sb))
+	/*
+	 * Continue filesystem operators if errors=continue. Should not set
+	 * RO by shutdown, since RO bypasses thaw_super which can hang the
+	 * system.
+	 */
+	if (continue_fs || f2fs_readonly(sb) ||
+				reason == STOP_CP_REASON_SHUTDOWN) {
+		f2fs_warn(sbi, "Stopped filesystem due to readon: %d", reason);
 		return;
+	}
 
 	f2fs_warn(sbi, "Remounting filesystem read-only");
 	/*
Signature · 1 line
2.44.0.478.gd926399ef9-goog
maintainer
#1 lore raw
Quoted 30 lines · Jaegeuk Kim

Shutdown does not check the error of thaw_super due to readonly, which causes a deadlock like below.

f2fs_ioc_shutdown(F2FS_GOING_DOWN_FULLSYNC) issue_discard_thread
- bdev_freeze
- freeze_super
- f2fs_stop_checkpoint()
- f2fs_handle_critical_error - sb_start_write
- set RO - waiting
- bdev_thaw
- thaw_super_locked
- return -EINVAL, if sb_rdonly()
- f2fs_stop_discard_thread
-> wait for kthread_stop(discard_thread);

---
  fs/f2fs/super.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -1
index df9765b41dac..ba6288e870c5 100644
@@ -4135,9 +4135,16 @@ void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason,
  	if (shutdown)
  		set_sbi_flag(sbi, SBI_IS_SHUTDOWN);
 
-	/* continue filesystem operators if errors=continue */

fs/f2fs/super.c void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason, · line 4146

Quoted 10 lines
fs/f2fs/super.c +8 -1
-	if (continue_fs || f2fs_readonly(sb))
+	/*
+	 * Continue filesystem operators if errors=continue. Should not set
+	 * RO by shutdown, since RO bypasses thaw_super which can hang the
+	 * system.
+	 */
+	if (continue_fs || f2fs_readonly(sb) ||
+				reason == STOP_CP_REASON_SHUTDOWN) {
+		f2fs_warn(sbi, "Stopped filesystem due to readon: %d", reason);
  		return;

Do we need to set RO after bdev_thaw() in f2fs_do_shutdown()?

Thanks,

Quoted 4 lines
fs/f2fs/super.c +1 -0
+	}
 
  	f2fs_warn(sbi, "Remounting filesystem read-only");
  	/*
author maintainer
#2 lore raw
Quoted 34 lines · Chao Yu
Quoted 33 lines · Jaegeuk Kim

Shutdown does not check the error of thaw_super due to readonly, which causes a deadlock like below.

f2fs_ioc_shutdown(F2FS_GOING_DOWN_FULLSYNC) issue_discard_thread
- bdev_freeze
- freeze_super
- f2fs_stop_checkpoint()
- f2fs_handle_critical_error - sb_start_write
- set RO - waiting
- bdev_thaw
- thaw_super_locked
- return -EINVAL, if sb_rdonly()
- f2fs_stop_discard_thread
-> wait for kthread_stop(discard_thread);

---
  fs/f2fs/super.c | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
fs/f2fs/super.c +3 -2
index df9765b41dac..ba6288e870c5 100644
@@ -4135,9 +4135,16 @@ void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason,
  	if (shutdown)
  		set_sbi_flag(sbi, SBI_IS_SHUTDOWN);
-	/* continue filesystem operators if errors=continue */
-	if (continue_fs || f2fs_readonly(sb))
+	/*
+	 * Continue filesystem operators if errors=continue. Should not set
+	 * RO by shutdown, since RO bypasses thaw_super which can hang the
Quoted 8 lines

fs/f2fs/super.c void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason, · line 4146

Quoted 6 lines
fs/f2fs/super.c +5 -0
+	 * system.
+	 */
+	if (continue_fs || f2fs_readonly(sb) ||
+				reason == STOP_CP_REASON_SHUTDOWN) {
+		f2fs_warn(sbi, "Stopped filesystem due to readon: %d", reason);
  		return;

Do we need to set RO after bdev_thaw() in f2fs_do_shutdown()?

IIRC, shutdown doesn't need to set RO as we stopped the checkpoint. I'm more concerned on any side effect caused by this RO change.

Quoted 6 lines

Thanks,

Quoted 3 lines
fs/f2fs/super.c +1 -0
+	}
  	f2fs_warn(sbi, "Remounting filesystem read-only");
  	/*
maintainer
#3 lore raw
Quoted 44 lines · Jaegeuk Kim
Quoted 34 lines · Chao Yu
Quoted 33 lines · Jaegeuk Kim

Shutdown does not check the error of thaw_super due to readonly, which causes a deadlock like below.

f2fs_ioc_shutdown(F2FS_GOING_DOWN_FULLSYNC) issue_discard_thread
- bdev_freeze
- freeze_super
- f2fs_stop_checkpoint()
- f2fs_handle_critical_error - sb_start_write
- set RO - waiting
- bdev_thaw
- thaw_super_locked
- return -EINVAL, if sb_rdonly()
- f2fs_stop_discard_thread

    -> wait for kthread_stop(discard_thread);
---
   fs/f2fs/super.c | 11 +++++++++--
   1 file changed, 9 insertions(+), 2 deletions(-)
fs/f2fs/super.c +3 -2
index df9765b41dac..ba6288e870c5 100644
@@ -4135,9 +4135,16 @@ void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason,
   	if (shutdown)
   		set_sbi_flag(sbi, SBI_IS_SHUTDOWN);
-	/* continue filesystem operators if errors=continue */
-	if (continue_fs || f2fs_readonly(sb))
+	/*
+	 * Continue filesystem operators if errors=continue. Should not set
+	 * RO by shutdown, since RO bypasses thaw_super which can hang the
Quoted 8 lines

fs/f2fs/super.c void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason, · line 4146

Quoted 6 lines
fs/f2fs/super.c +5 -0
+	 * system.
+	 */
+	if (continue_fs || f2fs_readonly(sb) ||
+				reason == STOP_CP_REASON_SHUTDOWN) {
+		f2fs_warn(sbi, "Stopped filesystem due to readon: %d", reason);
   		return;

Do we need to set RO after bdev_thaw() in f2fs_do_shutdown()?

Quoted 2 lines

IIRC, shutdown doesn't need to set RO as we stopped the checkpoint. I'm more concerned on any side effect caused by this RO change.

Okay, I just wonder whether we need to follow semantics of errors=remount-ro semantics, but it looks fine since shutdown operation simulated by ioctl could not be treated as an inner critical error,

errors=%s Specify f2fs behavior on critical errors. This supports modes:
"panic", "continue" and "remount-ro", respectively, trigger panic immediately, continue without doing anything, and remount the partition in read-only mode. By default it uses "continue" mode.

Also, it keeps the behavior consistent w/ what we do for errors=panic case.

	if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_PANIC &&
				!shutdown && !system_going_down() &&
				^^^^^^^^^
				!is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN))
		panic("F2FS-fs (device %s): panic forced after error\n",
							sb->s_id);

Thanks,

Quoted 7 lines
Quoted 7 lines

Thanks,

Quoted 3 lines
fs/f2fs/super.c +1 -0
+	}
   	f2fs_warn(sbi, "Remounting filesystem read-only");
   	/*
#4 lore raw
In reply to Jaegeuk Kim
Quoted 29 lines · Jaegeuk Kim

Shutdown does not check the error of thaw_super due to readonly, which causes a deadlock like below.

f2fs_ioc_shutdown(F2FS_GOING_DOWN_FULLSYNC) issue_discard_thread
- bdev_freeze
- freeze_super
- f2fs_stop_checkpoint()
- f2fs_handle_critical_error - sb_start_write
- set RO - waiting
- bdev_thaw
- thaw_super_locked
- return -EINVAL, if sb_rdonly()
- f2fs_stop_discard_thread
-> wait for kthread_stop(discard_thread);

---
 fs/f2fs/super.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index df9765b41dac..ba6288e870c5 100644
@@ -4135,9 +4135,16 @@ void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason,
        if (shutdown)
                set_sbi_flag(sbi, SBI_IS_SHUTDOWN);

fs/f2fs/super.c void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason, · line 4144

Quoted 10 lines
fs/f2fs/super.c +7 -2
 
-       /* continue filesystem operators if errors=continue */
-       if (continue_fs || f2fs_readonly(sb))
+       /*
+        * Continue filesystem operators if errors=continue. Should not set
+        * RO by shutdown, since RO bypasses thaw_super which can hang the
+        * system.
+        */
+       if (continue_fs || f2fs_readonly(sb) ||
+                               reason == STOP_CP_REASON_SHUTDOWN) {

I think we can use "shutdown" variable instead of "reason == STOP_CP_REASON_SHUTDOWN" to be concise.

fs/f2fs/super.c void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason, · line 4145

Quoted 1 line
fs/f2fs/super.c +1 -0
+               f2fs_warn(sbi, "Stopped filesystem due to readon: %d", reason);

readon -> reason?

Quoted 14 lines
fs/f2fs/super.c +1 -1
                return;
+       }
 
        f2fs_warn(sbi, "Remounting filesystem read-only");
        /*
--

2.44.0.478.gd926399ef9-goog

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#5 lore raw
In reply to Jaegeuk Kim

Shutdown does not check the error of thaw_super due to readonly, which causes a deadlock like below.

f2fs_ioc_shutdown(F2FS_GOING_DOWN_FULLSYNC) issue_discard_thread
- bdev_freeze
- freeze_super
- f2fs_stop_checkpoint()
- f2fs_handle_critical_error - sb_start_write
- set RO - waiting
- bdev_thaw
- thaw_super_locked
- return -EINVAL, if sb_rdonly()
- f2fs_stop_discard_thread
-> wait for kthread_stop(discard_thread);

---

Change log from v1:
- use better variable
- fix typo

 fs/f2fs/super.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/super.c +8 -2
index 8ac4734c2df6..df32573d1f62 100644
@@ -4159,9 +4159,15 @@ void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason,
 	if (shutdown)
 		set_sbi_flag(sbi, SBI_IS_SHUTDOWN);
 
-	/* continue filesystem operators if errors=continue */
-	if (continue_fs || f2fs_readonly(sb))
+	/*
+	 * Continue filesystem operators if errors=continue. Should not set
+	 * RO by shutdown, since RO bypasses thaw_super which can hang the
+	 * system.
+	 */
+	if (continue_fs || f2fs_readonly(sb) || shutdown) {
+		f2fs_warn(sbi, "Stopped filesystem due to reason: %d", reason);
 		return;
+	}
 
 	f2fs_warn(sbi, "Remounting filesystem read-only");
 	/*
Signature · 1 line
2.44.0.478.gd926399ef9-goog
Reviewed-by
#6 lore raw
Quoted 50 lines · Jaegeuk Kim

Shutdown does not check the error of thaw_super due to readonly, which causes a deadlock like below.

f2fs_ioc_shutdown(F2FS_GOING_DOWN_FULLSYNC) issue_discard_thread
- bdev_freeze
- freeze_super
- f2fs_stop_checkpoint()
- f2fs_handle_critical_error - sb_start_write
- set RO - waiting
- bdev_thaw
- thaw_super_locked
- return -EINVAL, if sb_rdonly()
- f2fs_stop_discard_thread
-> wait for kthread_stop(discard_thread);

---

Change log from v1:
- use better variable
- fix typo

 fs/f2fs/super.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/super.c +8 -3
index 8ac4734c2df6..df32573d1f62 100644
@@ -4159,9 +4159,15 @@ void f2fs_handle_critical_error(struct f2fs_sb_info *sbi, unsigned char reason,
        if (shutdown)
                set_sbi_flag(sbi, SBI_IS_SHUTDOWN);
 
-       /* continue filesystem operators if errors=continue */
-       if (continue_fs || f2fs_readonly(sb))
+       /*
+        * Continue filesystem operators if errors=continue. Should not set
+        * RO by shutdown, since RO bypasses thaw_super which can hang the
+        * system.
+        */
+       if (continue_fs || f2fs_readonly(sb) || shutdown) {
+               f2fs_warn(sbi, "Stopped filesystem due to reason: %d", reason);
                return;
+       }
 
        f2fs_warn(sbi, "Remounting filesystem read-only");
        /*
--
Quoted 3 lines

2.44.0.478.gd926399ef9-goog

Quoted 5 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer Reviewed-by
#7 lore raw
In reply to Jaegeuk Kim
Quoted 15 lines · Jaegeuk Kim

Shutdown does not check the error of thaw_super due to readonly, which causes a deadlock like below.

f2fs_ioc_shutdown(F2FS_GOING_DOWN_FULLSYNC) issue_discard_thread
- bdev_freeze
- freeze_super
- f2fs_stop_checkpoint()
- f2fs_handle_critical_error - sb_start_write
- set RO - waiting
- bdev_thaw
- thaw_super_locked
- return -EINVAL, if sb_rdonly()
- f2fs_stop_discard_thread
-> wait for kthread_stop(discard_thread);

Quoted 2 lines

Thanks,