diff mbox series

[v4,6/8] btrfs: warn when remount will not create the free space tree

Message ID ee7999f13f788759fd3b9f223e4196abc8ee7300.1603318242.git.boris@bur.io
State New, archived
Headers show
Series btrfs: free space tree mounting fixes | expand

Commit Message

Boris Burkov Oct. 21, 2020, 11:06 p.m. UTC
If the remount is ro->ro, rw->ro, or rw->rw, we will not create the free
space tree. This can be surprising, so print a warning to dmesg to make
the failure more visible.

Signed-off-by: Boris Burkov <boris@bur.io>
---
 fs/btrfs/super.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index c78e3379fa93..5db278243a34 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1859,6 +1859,20 @@  static int btrfs_remount(struct super_block *sb, int *flags, char *data)
 	btrfs_resize_thread_pool(fs_info,
 		fs_info->thread_pool_size, old_thread_pool_size);
 
+	if (btrfs_test_opt(fs_info, FREE_SPACE_TREE) &&
+	    !btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE) &&
+	    ((!sb_rdonly(sb) || *flags & SB_RDONLY))) {
+		btrfs_warn(fs_info,
+	   "remount supports enabling free space tree only from ro to rw");
+		/*
+		 * if we aren't building the free space tree, reset
+		 * the space cache options to what they were before
+		 */
+		btrfs_clear_opt(fs_info->mount_opt, FREE_SPACE_TREE);
+		if (btrfs_free_space_cache_v1_active(fs_info))
+			btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE);
+	}
+
 	if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
 		goto out;