btrfs: disable space cache related mount options for extent tree v2
authorJosef Bacik <josef@toxicpanda.com>
Wed, 15 Dec 2021 20:40:04 +0000 (15:40 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 14 Mar 2022 12:13:48 +0000 (13:13 +0100)
We cannot fall back on the slow caching for extent tree v2, which means
we can't just arbitrarily clear the free space trees at mount time.
Furthermore we can't do v1 space cache with extent tree v2.  Simply
ignore these mount options for extent tree v2 as they aren't relevant.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/super.c

index 1f4cda3..33cfc9e 100644 (file)
@@ -861,6 +861,14 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
                        break;
                case Opt_space_cache:
                case Opt_space_cache_version:
+                       /*
+                        * We already set FREE_SPACE_TREE above because we have
+                        * compat_ro(FREE_SPACE_TREE) set, and we aren't going
+                        * to allow v1 to be set for extent tree v2, simply
+                        * ignore this setting if we're extent tree v2.
+                        */
+                       if (btrfs_fs_incompat(info, EXTENT_TREE_V2))
+                               break;
                        if (token == Opt_space_cache ||
                            strcmp(args[0].from, "v1") == 0) {
                                btrfs_clear_opt(info->mount_opt,
@@ -881,6 +889,12 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
                        btrfs_set_opt(info->mount_opt, RESCAN_UUID_TREE);
                        break;
                case Opt_no_space_cache:
+                       /*
+                        * We cannot operate without the free space tree with
+                        * extent tree v2, ignore this option.
+                        */
+                       if (btrfs_fs_incompat(info, EXTENT_TREE_V2))
+                               break;
                        if (btrfs_test_opt(info, SPACE_CACHE)) {
                                btrfs_clear_and_info(info, SPACE_CACHE,
                                             "disabling disk space caching");
@@ -896,6 +910,12 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
        "the 'inode_cache' option is deprecated and has no effect since 5.11");
                        break;
                case Opt_clear_cache:
+                       /*
+                        * We cannot clear the free space tree with extent tree
+                        * v2, ignore this option.
+                        */
+                       if (btrfs_fs_incompat(info, EXTENT_TREE_V2))
+                               break;
                        btrfs_set_and_info(info, CLEAR_CACHE,
                                           "force clearing of disk cache");
                        break;