Skip to contentSkip to conversation

f2fs: avoid setting SBI_NEED_FSCK on transient resize failure with -EAGAIN

PATCH Superseded Daeho Jeong 2 participants 5 messages Aug 18 – Aug 20 1 message not in the archive F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: avoid setting SBI_NEED_FSCK on transient resize failure with -EAGAIN

From: Daeho Jeong <[email protected]>

When f2fs_resize_fs() fails due to transient lock contention or retryable GC failure in free_segment_range() returning -EAGAIN, no filesystem metadata has been modified on-disk yet. The filesystem remains completely consistent and clean.

However, the current error recovery path unconditionally sets the SBI_NEED_FSCK flag on any error, forcing an unnecessary and time-consuming fsck.f2fs repair on the subsequent mount/reboot.

Fix this by guarding set_sbi_flag(sbi, SBI_NEED_FSCK) with if (err != -EAGAIN), avoiding false-positive filesystem corruption flags on transient resize retries.

---
 fs/f2fs/gc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +4 -2
index 192b16ac02f8..787133ee2eb2 100644
@@ -2446,8 +2446,10 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
 recover_out:
 	clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
 	if (err) {
-		set_sbi_flag(sbi, SBI_NEED_FSCK);
-		f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+		if (err != -EAGAIN) {
+			set_sbi_flag(sbi, SBI_NEED_FSCK);
+			f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+		}
 
 		spin_lock(&sbi->stat_lock);
 		sbi->user_block_count += shrunk_blocks;
Signature · 1 line
2.55.0.691.gc56d675ccc-goog
maintainer
#1 lore raw
Quoted 6 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

When f2fs_resize_fs() fails due to transient lock contention or retryable GC failure in free_segment_range() returning -EAGAIN, no filesystem metadata has been modified on-disk yet. The filesystem remains completely consistent and clean.

Any way to make sure EAGAIN is from free_segment_range(), in case we return EAGAIN from 1) any other places that we may miss to check now or 2) we changed the code to return EAGAIN in future.

Thanks,

Quoted 32 lines

However, the current error recovery path unconditionally sets the SBI_NEED_FSCK flag on any error, forcing an unnecessary and time-consuming fsck.f2fs repair on the subsequent mount/reboot.

Fix this by guarding set_sbi_flag(sbi, SBI_NEED_FSCK) with if (err != -EAGAIN), avoiding false-positive filesystem corruption flags on transient resize retries.

---
 fs/f2fs/gc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +4 -2
index 192b16ac02f8..787133ee2eb2 100644
@@ -2446,8 +2446,10 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
 recover_out:
 	clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
 	if (err) {
-		set_sbi_flag(sbi, SBI_NEED_FSCK);
-		f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+		if (err != -EAGAIN) {
+			set_sbi_flag(sbi, SBI_NEED_FSCK);
+			f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+		}
 
 		spin_lock(&sbi->stat_lock);
 		sbi->user_block_count += shrunk_blocks;
#2 lore raw
Quoted 4 lines · Chao Yu
Quoted 2 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

Quoted 8 lines
Quoted 4 lines

When f2fs_resize_fs() fails due to transient lock contention or retryable GC failure in free_segment_range() returning -EAGAIN, no filesystem metadata has been modified on-disk yet. The filesystem remains completely consistent and clean.

Any way to make sure EAGAIN is from free_segment_range(), in case we return EAGAIN from 1) any other places that we may miss to check now or 2) we changed the code to return EAGAIN in future.

Makes sense.

In fact, if free_segment_range() fails with ANY error (e.g., -EAGAIN, -ENOMEM, -ERESTARTSYS, etc.), no on-disk superblock or filesystem metadata has been modified yet, and free_segment_range() safely restores all in-memory counters (MAIN_SECS, free_sections) before returning. Therefore, setting SBI_NEED_FSCK is not needed for all errors occurring in free_segment_range().

To make this explicit and defensive against any future changes, we can separate the error recovery path with dedicated labels as follows:

err = free_segment_range(sbi, secs, false);
if (err)
- goto recover_out;
+ goto recover_user_blocks;

  update_sb_metadata(sbi, -secs);

...

recover_out:
+ set_sbi_flag(sbi, SBI_NEED_FSCK);
+ f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); +recover_user_blocks:
clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
if (err) {
- set_sbi_flag(sbi, SBI_NEED_FSCK);
- f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); -
spin_lock(&sbi->stat_lock);
sbi->user_block_count += shrunk_blocks; spin_unlock(&sbi->stat_lock);

Thanks,

Quoted 36 lines

Thanks,

Quoted 32 lines

However, the current error recovery path unconditionally sets the SBI_NEED_FSCK flag on any error, forcing an unnecessary and time-consuming fsck.f2fs repair on the subsequent mount/reboot.

Fix this by guarding set_sbi_flag(sbi, SBI_NEED_FSCK) with if (err != -EAGAIN), avoiding false-positive filesystem corruption flags on transient resize retries.

---
 fs/f2fs/gc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +4 -2
index 192b16ac02f8..787133ee2eb2 100644
@@ -2446,8 +2446,10 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
 recover_out:
      clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
      if (err) {
-             set_sbi_flag(sbi, SBI_NEED_FSCK);
-             f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+             if (err != -EAGAIN) {
+                     set_sbi_flag(sbi, SBI_NEED_FSCK);
+                     f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+             }
 
              spin_lock(&sbi->stat_lock);
              sbi->user_block_count += shrunk_blocks;
maintainer
#3 lore raw
Quoted 14 lines · Daeho Jeong
Quoted 4 lines · Chao Yu
Quoted 2 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

Quoted 8 lines
Quoted 4 lines

When f2fs_resize_fs() fails due to transient lock contention or retryable GC failure in free_segment_range() returning -EAGAIN, no filesystem metadata has been modified on-disk yet. The filesystem remains completely consistent and clean.

Any way to make sure EAGAIN is from free_segment_range(), in case we return EAGAIN from 1) any other places that we may miss to check now or 2) we changed the code to return EAGAIN in future.

Quoted 7 lines

Makes sense.

In fact, if free_segment_range() fails with ANY error (e.g., -EAGAIN, -ENOMEM, -ERESTARTSYS, etc.), no on-disk superblock or filesystem metadata has been modified yet, and free_segment_range() safely restores all in-memory counters (MAIN_SECS, free_sections) before returning. Therefore, setting SBI_NEED_FSCK is not needed for all errors occurring in free_segment_range().

Yeah, better.

Quoted 9 lines

To make this explicit and defensive against any future changes, we can separate the error recovery path with dedicated labels as follows:

err = free_segment_range(sbi, secs, false);
if (err)
- goto recover_out;
+ goto recover_user_blocks;

Quoted 8 lines
  update_sb_metadata(sbi, -secs);

...

recover_out:
+ set_sbi_flag(sbi, SBI_NEED_FSCK);
+ f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); +recover_user_blocks:

How about this?

recover_out:

	if (err) {
		f2fs_bug_on(sbi, err == -EAGAIN);
		set_sbi_flag(sbi, SBI_NEED_FSCK);
		f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
	}

recover_user_blocks:

Thanks,

Quoted 47 lines

clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
if (err) {
- set_sbi_flag(sbi, SBI_NEED_FSCK);
- f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); -
spin_lock(&sbi->stat_lock);
sbi->user_block_count += shrunk_blocks; spin_unlock(&sbi->stat_lock);

Thanks,

Quoted 36 lines

Thanks,

Quoted 32 lines

However, the current error recovery path unconditionally sets the SBI_NEED_FSCK flag on any error, forcing an unnecessary and time-consuming fsck.f2fs repair on the subsequent mount/reboot.

Fix this by guarding set_sbi_flag(sbi, SBI_NEED_FSCK) with if (err != -EAGAIN), avoiding false-positive filesystem corruption flags on transient resize retries.

---
 fs/f2fs/gc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +4 -2
index 192b16ac02f8..787133ee2eb2 100644
@@ -2446,8 +2446,10 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
 recover_out:
      clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
      if (err) {
-             set_sbi_flag(sbi, SBI_NEED_FSCK);
-             f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+             if (err != -EAGAIN) {
+                     set_sbi_flag(sbi, SBI_NEED_FSCK);
+                     f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+             }
 
              spin_lock(&sbi->stat_lock);
              sbi->user_block_count += shrunk_blocks;

A message that is not in the archive (sent off-list or not yet received): CABdZyexzNgVLcdSFRkt=AZnkgW5Q40m3Hf8JFk63WuTGhQ0S7w@mail.gmail.com

#5 lore raw
Quoted 90 lines · Daeho Jeong
Quoted 86 lines · Chao Yu
Quoted 14 lines · Daeho Jeong
Quoted 4 lines · Chao Yu
Quoted 2 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

Quoted 8 lines
Quoted 4 lines

When f2fs_resize_fs() fails due to transient lock contention or retryable GC failure in free_segment_range() returning -EAGAIN, no filesystem metadata has been modified on-disk yet. The filesystem remains completely consistent and clean.

Any way to make sure EAGAIN is from free_segment_range(), in case we return EAGAIN from 1) any other places that we may miss to check now or 2) we changed the code to return EAGAIN in future.

Quoted 7 lines

Makes sense.

In fact, if free_segment_range() fails with ANY error (e.g., -EAGAIN, -ENOMEM, -ERESTARTSYS, etc.), no on-disk superblock or filesystem metadata has been modified yet, and free_segment_range() safely restores all in-memory counters (MAIN_SECS, free_sections) before returning. Therefore, setting SBI_NEED_FSCK is not needed for all errors occurring in free_segment_range().

Yeah, better.

Quoted 9 lines

To make this explicit and defensive against any future changes, we can separate the error recovery path with dedicated labels as follows:

err = free_segment_range(sbi, secs, false);
if (err)
- goto recover_out;
+ goto recover_user_blocks;

Quoted 8 lines
  update_sb_metadata(sbi, -secs);

...

recover_out:
+ set_sbi_flag(sbi, SBI_NEED_FSCK);
+ f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); +recover_user_blocks:

How about this?

recover_out:

        if (err) {
                f2fs_bug_on(sbi, err == -EAGAIN);
                set_sbi_flag(sbi, SBI_NEED_FSCK);
                f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
        }

recover_user_blocks:

Thanks,

Quoted 29 lines

clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
if (err) {
- set_sbi_flag(sbi, SBI_NEED_FSCK);
- f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); -
spin_lock(&sbi->stat_lock);
sbi->user_block_count += shrunk_blocks; spin_unlock(&sbi->stat_lock);

Thanks,

Quoted 18 lines

Thanks,

Quoted 15 lines

However, the current error recovery path unconditionally sets the SBI_NEED_FSCK flag on any error, forcing an unnecessary and time-consuming fsck.f2fs repair on the subsequent mount/reboot.

Fix this by guarding set_sbi_flag(sbi, SBI_NEED_FSCK) with if (err != -EAGAIN), avoiding false-positive filesystem corruption flags on transient resize retries.

---
 fs/f2fs/gc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
fs/f2fs/gc.c +0 -0
index 192b16ac02f8..787133ee2eb2 100644
@@ -2446,8 +2446,10 @@ int f2fs_resize_fs(struct file *filp, __u64 block_count)
 recover_out:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

fs/f2fs/gc.c int f2fs_resize_fs(struct file *filp, __u64 block_count) · line 2452

Quoted 8 lines
fs/f2fs/gc.c +4 -2
      clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
      if (err) {
-             set_sbi_flag(sbi, SBI_NEED_FSCK);
-             f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+             if (err != -EAGAIN) {
+                     set_sbi_flag(sbi, SBI_NEED_FSCK);
+                     f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
+             }

Got it. Thanks~

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
fs/f2fs/gc.c +0 -0
              spin_lock(&sbi->stat_lock);
              sbi->user_block_count += shrunk_blocks;