btrfs: set clear_cache if we use usebackuproot
authorJosef Bacik <josef@toxicpanda.com>
Wed, 22 Nov 2023 17:17:54 +0000 (12:17 -0500)
committerDavid Sterba <dsterba@suse.com>
Fri, 15 Dec 2023 19:27:05 +0000 (20:27 +0100)
We're currently setting this when we try to load the roots and we see
that usebackuproot is set.  Instead set this at mount option parsing
time.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Acked-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/super.c

index 12daa8a36ba163bee82515f47e5618703e863129..00c9181fd356bfd71571ee949f86e7e8ca23f2c4 100644 (file)
@@ -2630,9 +2630,6 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info)
                         */
                        btrfs_set_super_log_root(sb, 0);
 
-                       /* We can't trust the free space cache either */
-                       btrfs_set_opt(fs_info->mount_opt, CLEAR_CACHE);
-
                        btrfs_warn(fs_info, "try to load backup roots slot %d", i);
                        ret = read_backup_root(fs_info, i);
                        backup_index = ret;
index 95d6392a1acf8b6eb6512cb1acc82bddbc202618..04352d3861a26f7a030823d388cf63faf29ec5da 100644 (file)
@@ -452,6 +452,12 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
                        btrfs_warn(NULL,
                "'recovery' is deprecated, use 'rescue=usebackuproot' instead");
                        btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT);
+
+                       /*
+                        * If we're loading the backup roots we can't trust the
+                        * space cache.
+                        */
+                       btrfs_set_opt(ctx->mount_opt, CLEAR_CACHE);
                }
                break;
        case Opt_nologreplay:
@@ -550,6 +556,9 @@ static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
                btrfs_warn(NULL,
                           "'usebackuproot' is deprecated, use 'rescue=usebackuproot' instead");
                btrfs_set_opt(ctx->mount_opt, USEBACKUPROOT);
+
+               /* If we're loading the backup roots we can't trust the space cache. */
+               btrfs_set_opt(ctx->mount_opt, CLEAR_CACHE);
                break;
        case Opt_skip_balance:
                btrfs_set_opt(ctx->mount_opt, SKIP_BALANCE);