Skip to content

Commit 93463ff

Browse files
naotakdave
authored andcommitted
btrfs: bail out reclaim process if filesystem is read-only
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: 18bb8bb ("btrfs: zoned: automatically reclaim zones") CC: [email protected] # 5.15+ Reviewed-by: Filipe Manana <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Naohiro Aota <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent a9f1897 commit 93463ff

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

fs/btrfs/block-group.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,8 +1794,15 @@ void btrfs_reclaim_bgs_work(struct work_struct *work)
17941794
}
17951795
spin_unlock(&bg->lock);
17961796

1797-
/* Get out fast, in case we're unmounting the filesystem */
1798-
if (btrfs_fs_closing(fs_info)) {
1797+
/*
1798+
* Get out fast, in case we're read-only or unmounting the
1799+
* filesystem. It is OK to drop block groups from the list even
1800+
* for the read-only case. As we did sb_start_write(),
1801+
* "mount -o remount,ro" won't happen and read-only filesystem
1802+
* means it is forced read-only due to a fatal error. So, it
1803+
* never gets back to read-write to let us reclaim again.
1804+
*/
1805+
if (btrfs_need_cleaner_sleep(fs_info)) {
17991806
up_write(&space_info->groups_sem);
18001807
goto next;
18011808
}

0 commit comments

Comments
 (0)