Skip to content

Commit ad21f15

Browse files
josefbacikkdave
authored andcommitted
btrfs: switch to the new mount API
Now that we have all of the parts in place to use the new mount API, switch our fs_type to use the new callbacks. There are a few things that have to be done at the same time because of the order of operations changes that come along with the new mount API. These must be done in the same patch otherwise things will go wrong. 1. Export and use btrfs_check_options in open_ctree(). This is because the options are done ahead of time, and we need to check them once we have the feature flags loaded. 2. Update the free space cache settings. Since we're coming in with the options already set we need to make sure we don't undo what the user has asked for. 3. Set our sb_flags at init_fs_context time, the fs_context stuff is trying to manage the sb_flagss itself, so move that into init_fs_context and out of the fill super part. Additionally I've marked the unused functions with __maybe_unused and will remove them in a future patch. Reviewed-by: Johannes Thumshirn <[email protected]> Acked-by: Christian Brauner <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f044b31 commit ad21f15

File tree

3 files changed

+60
-41
lines changed

3 files changed

+60
-41
lines changed

fs/btrfs/disk-io.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,14 +3316,21 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
33163316
*/
33173317
btrfs_set_free_space_cache_settings(fs_info);
33183318

3319-
ret = btrfs_parse_options(fs_info, options, sb->s_flags);
3320-
if (ret)
3319+
if (!btrfs_check_options(fs_info, &fs_info->mount_opt, sb->s_flags)) {
3320+
ret = -EINVAL;
33213321
goto fail_alloc;
3322+
}
33223323

33233324
ret = btrfs_check_features(fs_info, !sb_rdonly(sb));
33243325
if (ret < 0)
33253326
goto fail_alloc;
33263327

3328+
/*
3329+
* At this point our mount options are validated, if we set ->max_inline
3330+
* to something non-standard make sure we truncate it to sectorsize.
3331+
*/
3332+
fs_info->max_inline = min_t(u64, fs_info->max_inline, fs_info->sectorsize);
3333+
33273334
if (sectorsize < PAGE_SIZE) {
33283335
struct btrfs_subpage_info *subpage_info;
33293336

fs/btrfs/super.c

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static const struct constant_table btrfs_parameter_fragment[] = {
307307
};
308308
#endif
309309

310-
static const struct fs_parameter_spec btrfs_fs_parameters[] __maybe_unused = {
310+
static const struct fs_parameter_spec btrfs_fs_parameters[] = {
311311
fsparam_flag_no("acl", Opt_acl),
312312
fsparam_flag_no("autodefrag", Opt_defrag),
313313
fsparam_flag_no("barrier", Opt_barrier),
@@ -738,8 +738,8 @@ static bool check_ro_option(struct btrfs_fs_info *fs_info,
738738
return false;
739739
}
740740

741-
static bool check_options(struct btrfs_fs_info *info, unsigned long *mount_opt,
742-
unsigned long flags)
741+
bool btrfs_check_options(struct btrfs_fs_info *info, unsigned long *mount_opt,
742+
unsigned long flags)
743743
{
744744
bool ret = true;
745745

@@ -788,18 +788,6 @@ static bool check_options(struct btrfs_fs_info *info, unsigned long *mount_opt,
788788
*/
789789
void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info)
790790
{
791-
if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE))
792-
btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
793-
else if (btrfs_free_space_cache_v1_active(fs_info)) {
794-
if (btrfs_is_zoned(fs_info)) {
795-
btrfs_info(fs_info,
796-
"zoned: clearing existing space cache");
797-
btrfs_set_super_cache_generation(fs_info->super_copy, 0);
798-
} else {
799-
btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE);
800-
}
801-
}
802-
803791
if (fs_info->sectorsize < PAGE_SIZE) {
804792
btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE);
805793
if (!btrfs_test_opt(fs_info, FREE_SPACE_TREE)) {
@@ -809,6 +797,35 @@ void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info)
809797
btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
810798
}
811799
}
800+
801+
/*
802+
* At this point our mount options are populated, so we only mess with
803+
* these settings if we don't have any settings already.
804+
*/
805+
if (btrfs_test_opt(fs_info, FREE_SPACE_TREE))
806+
return;
807+
808+
if (btrfs_is_zoned(fs_info) &&
809+
btrfs_free_space_cache_v1_active(fs_info)) {
810+
btrfs_info(fs_info, "zoned: clearing existing space cache");
811+
btrfs_set_super_cache_generation(fs_info->super_copy, 0);
812+
return;
813+
}
814+
815+
if (btrfs_test_opt(fs_info, SPACE_CACHE))
816+
return;
817+
818+
if (btrfs_test_opt(fs_info, NOSPACECACHE))
819+
return;
820+
821+
/*
822+
* At this point we don't have explicit options set by the user, set
823+
* them ourselves based on the state of the file system.
824+
*/
825+
if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE))
826+
btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
827+
else if (btrfs_free_space_cache_v1_active(fs_info))
828+
btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE);
812829
}
813830

814831
static int parse_rescue_options(struct btrfs_fs_info *info, const char *options)
@@ -1345,7 +1362,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
13451362
}
13461363
}
13471364
out:
1348-
if (!ret && !check_options(info, &info->mount_opt, new_flags))
1365+
if (!ret && !btrfs_check_options(info, &info->mount_opt, new_flags))
13491366
ret = -EINVAL;
13501367
return ret;
13511368
}
@@ -1646,10 +1663,6 @@ static int btrfs_fill_super(struct super_block *sb,
16461663
#endif
16471664
sb->s_xattr = btrfs_xattr_handlers;
16481665
sb->s_time_gran = 1;
1649-
#ifdef CONFIG_BTRFS_FS_POSIX_ACL
1650-
sb->s_flags |= SB_POSIXACL;
1651-
#endif
1652-
sb->s_flags |= SB_I_VERSION;
16531666
sb->s_iflags |= SB_I_CGROUPWB;
16541667

16551668
err = super_setup_bdi(sb);
@@ -1929,7 +1942,7 @@ static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
19291942
* Note: This is based on mount_bdev from fs/super.c with a few additions
19301943
* for multiple device setup. Make sure to keep it in sync.
19311944
*/
1932-
static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
1945+
static __maybe_unused struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
19331946
int flags, const char *device_name, void *data)
19341947
{
19351948
struct block_device *bdev = NULL;
@@ -2062,7 +2075,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
20622075
* 3. Call mount_subvol() to get the dentry of subvolume. Since there is
20632076
* "btrfs subvolume set-default", mount_subvol() is called always.
20642077
*/
2065-
static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
2078+
static __maybe_unused struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
20662079
const char *device_name, void *data)
20672080
{
20682081
struct vfsmount *mnt_root;
@@ -2485,7 +2498,7 @@ static int btrfs_reconfigure(struct fs_context *fc)
24852498
set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
24862499

24872500
if (!mount_reconfigure &&
2488-
!check_options(fs_info, &ctx->mount_opt, fc->sb_flags))
2501+
!btrfs_check_options(fs_info, &ctx->mount_opt, fc->sb_flags))
24892502
return -EINVAL;
24902503

24912504
ret = btrfs_check_features(fs_info, !(fc->sb_flags & SB_RDONLY));
@@ -3147,7 +3160,7 @@ static const struct fs_context_operations btrfs_fs_context_ops = {
31473160
.free = btrfs_free_fs_context,
31483161
};
31493162

3150-
static int __maybe_unused btrfs_init_fs_context(struct fs_context *fc)
3163+
static int btrfs_init_fs_context(struct fs_context *fc)
31513164
{
31523165
struct btrfs_fs_context *ctx;
31533166

@@ -3168,24 +3181,22 @@ static int __maybe_unused btrfs_init_fs_context(struct fs_context *fc)
31683181
ctx->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
31693182
}
31703183

3184+
#ifdef CONFIG_BTRFS_FS_POSIX_ACL
3185+
fc->sb_flags |= SB_POSIXACL;
3186+
#endif
3187+
fc->sb_flags |= SB_I_VERSION;
3188+
31713189
return 0;
31723190
}
31733191

31743192
static struct file_system_type btrfs_fs_type = {
3175-
.owner = THIS_MODULE,
3176-
.name = "btrfs",
3177-
.mount = btrfs_mount,
3178-
.kill_sb = btrfs_kill_super,
3179-
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA,
3180-
};
3181-
3182-
static struct file_system_type btrfs_root_fs_type = {
3183-
.owner = THIS_MODULE,
3184-
.name = "btrfs",
3185-
.mount = btrfs_mount_root,
3186-
.kill_sb = btrfs_kill_super,
3187-
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP,
3188-
};
3193+
.owner = THIS_MODULE,
3194+
.name = "btrfs",
3195+
.init_fs_context = btrfs_init_fs_context,
3196+
.parameters = btrfs_fs_parameters,
3197+
.kill_sb = btrfs_kill_super,
3198+
.fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP,
3199+
};
31893200

31903201
MODULE_ALIAS_FS("btrfs");
31913202

@@ -3398,7 +3409,6 @@ static const struct super_operations btrfs_super_ops = {
33983409
.destroy_inode = btrfs_destroy_inode,
33993410
.free_inode = btrfs_free_inode,
34003411
.statfs = btrfs_statfs,
3401-
.remount_fs = btrfs_remount,
34023412
.freeze_fs = btrfs_freeze,
34033413
.unfreeze_fs = btrfs_unfreeze,
34043414
};

fs/btrfs/super.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#ifndef BTRFS_SUPER_H
44
#define BTRFS_SUPER_H
55

6+
bool btrfs_check_options(struct btrfs_fs_info *info, unsigned long *mount_opt,
7+
unsigned long flags);
68
int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
79
unsigned long new_flags);
810
int btrfs_sync_fs(struct super_block *sb, int wait);

0 commit comments

Comments
 (0)