diff mbox series

[3/4] btrfs: bail out reclaim process if filesystem is read-only

Message ID d0a60acec35353dd7ad535bdddec0907857f2dd6.1686028197.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: fixes for reclaim | expand

Commit Message

Naohiro Aota June 6, 2023, 5:36 a.m. UTC
When a filesystem is read-only, we cannot reclaim a block group as it
cannot rewrite the data. Just bail out in that case.

Note that it can drop BGs in this case. As we did sb_start_write(),
read-only filesystem means we got a fatal error and forced read-only. There
is no chance to reclaim them again.

Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones")
CC: stable@vger.kernel.org # 5.15+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/block-group.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Filipe Manana June 6, 2023, 10:16 a.m. UTC | #1
On Tue, Jun 6, 2023 at 7:21 AM Naohiro Aota <naota@elisp.net> wrote:
>
> When a filesystem is read-only, we cannot reclaim a block group as it
> cannot rewrite the data. Just bail out in that case.
>
> Note that it can drop BGs in this case. As we did sb_start_write(),
> read-only filesystem means we got a fatal error and forced read-only. There
> is no chance to reclaim them again.
>
> Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones")
> CC: stable@vger.kernel.org # 5.15+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---
>  fs/btrfs/block-group.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index d5bba02167be..db9bee071434 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -1794,8 +1794,15 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
>                 }
>                 spin_unlock(&bg->lock);
>
> -               /* Get out fast, in case we're unmounting the filesystem */
> -               if (btrfs_fs_closing(fs_info)) {
> +               /*
> +                * Get out fast, in case we're read-only or unmounting the
> +                * filesystem. It is OK to drop block groups from the list even
> +                * for the read-only case. As we did sb_start_write(), "mount -o
> +                * ro" won't happen and read-only FS means it is forced

I think here you mean "mount -o remount,ro", just to be more clear.

> +                * read-only due to a fatal error. So, it never get back to

get -> gets

> +                * read-write to let us reclaime again.

reclaime -> reclaim

Other than that, it looks good to me.

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Thanks.
> +                */
> +               if (btrfs_need_cleaner_sleep(fs_info)) {
>                         up_write(&space_info->groups_sem);
>                         goto next;
>                 }
> --
> 2.40.1
>
Johannes Thumshirn June 6, 2023, 11:34 a.m. UTC | #2
With Filipe's comments incorporated:

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
diff mbox series

Patch

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index d5bba02167be..db9bee071434 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1794,8 +1794,15 @@  void btrfs_reclaim_bgs_work(struct work_struct *work)
 		}
 		spin_unlock(&bg->lock);
 
-		/* Get out fast, in case we're unmounting the filesystem */
-		if (btrfs_fs_closing(fs_info)) {
+		/*
+		 * Get out fast, in case we're read-only or unmounting the
+		 * filesystem. It is OK to drop block groups from the list even
+		 * for the read-only case. As we did sb_start_write(), "mount -o
+		 * ro" won't happen and read-only FS means it is forced
+		 * read-only due to a fatal error. So, it never get back to
+		 * read-write to let us reclaime again.
+		 */
+		if (btrfs_need_cleaner_sleep(fs_info)) {
 			up_write(&space_info->groups_sem);
 			goto next;
 		}