btrfs: clear oneshot options on mount and remount
authorBoris Burkov <boris@bur.io>
Wed, 18 Nov 2020 23:06:20 +0000 (15:06 -0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 9 Dec 2020 18:16:08 +0000 (19:16 +0100)
Some options only apply during mount time and are cleared at the end
of mount. For now, the example is USEBACKUPROOT, but CLEAR_CACHE also
fits the bill, and this is a preparation patch for also clearing that
option.

One subtlety is that the current code only resets USEBACKUPROOT on rw
mounts, but the option is meaningfully "consumed" by a ro mount, so it
feels appropriate to clear in that case as well. A subsequent read-write
remount would not go through open_ctree, which is the only place that
checks the option, so the change should be benign.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/disk-io.h
fs/btrfs/super.c

index a3e0065..292ea49 100644 (file)
@@ -2871,6 +2871,16 @@ static int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info)
 }
 
 /*
+ * Some options only have meaning at mount time and shouldn't persist across
+ * remounts, or be displayed. Clear these at the end of mount and remount
+ * code paths.
+ */
+void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info)
+{
+       btrfs_clear_opt(fs_info->mount_opt, USEBACKUPROOT);
+}
+
+/*
  * Mounting logic specific to read-write file systems. Shared by open_ctree
  * and btrfs_remount when remounting from read-only to read-write.
  */
@@ -3359,7 +3369,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
        }
 
        if (sb_rdonly(sb))
-               return 0;
+               goto clear_oneshot;
 
        if (btrfs_test_opt(fs_info, CLEAR_CACHE) &&
            btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE)) {
@@ -3402,6 +3412,8 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
        }
        set_bit(BTRFS_FS_OPEN, &fs_info->flags);
 
+clear_oneshot:
+       btrfs_clear_oneshot_options(fs_info);
        return 0;
 
 fail_qgroup:
index b509d1a..7b3ecad 100644 (file)
@@ -50,6 +50,7 @@ struct extent_buffer *btrfs_find_create_tree_block(
                                                u64 bytenr, u64 owner_root,
                                                int level);
 void btrfs_clean_tree_block(struct extent_buffer *buf);
+void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info);
 int btrfs_start_pre_rw_mount(struct btrfs_fs_info *fs_info);
 int __cold open_ctree(struct super_block *sb,
               struct btrfs_fs_devices *fs_devices,
index 49b4a16..9351455 100644 (file)
@@ -1999,6 +1999,7 @@ out:
 
        wake_up_process(fs_info->transaction_kthread);
        btrfs_remount_cleanup(fs_info, old_opts);
+       btrfs_clear_oneshot_options(fs_info);
        clear_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
 
        return 0;