This is a note to let you know that I've just added the patch titled btrfs: bail out reclaim process if filesystem is read-only to the 6.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: btrfs-bail-out-reclaim-process-if-filesystem-is-read-only.patch and it can be found in the queue-6.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 93463ff7b54626f8276c0bd3d3f968fbf8d5d380 Mon Sep 17 00:00:00 2001 From: Naohiro Aota <naota@xxxxxxxxx> Date: Tue, 6 Jun 2023 14:36:35 +0900 Subject: btrfs: bail out reclaim process if filesystem is read-only From: Naohiro Aota <naota@xxxxxxxxx> commit 93463ff7b54626f8276c0bd3d3f968fbf8d5d380 upstream. 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 block groups 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@xxxxxxxxxxxxxxx # 5.15+ Reviewed-by: Filipe Manana <fdmanana@xxxxxxxx> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx> Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxx> Signed-off-by: David Sterba <dsterba@xxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/btrfs/block-group.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1798,8 +1798,15 @@ void btrfs_reclaim_bgs_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 remount,ro" won't happen and read-only filesystem + * means it is forced read-only due to a fatal error. So, it + * never gets back to read-write to let us reclaim again. + */ + if (btrfs_need_cleaner_sleep(fs_info)) { up_write(&space_info->groups_sem); goto next; } Patches currently in stable-queue which might be from naota@xxxxxxxxx are queue-6.4/btrfs-bail-out-reclaim-process-if-filesystem-is-read-only.patch queue-6.4/btrfs-move-out-now-unused-bg-from-the-reclaim-list.patch queue-6.4/btrfs-delete-unused-bgs-while-reclaiming-bgs.patch queue-6.4/btrfs-reinsert-bgs-failed-to-reclaim.patch