Skip to content

Commit 0f85e24

Browse files
josefbacikkdave
authored andcommitted
btrfs: add fs context handling functions
We are going to use the fs context to hold the mount options, so allocate the btrfs_fs_context when we're asked to init the fs context, and free it in the free callback. Reviewed-by: Christian Brauner <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 17b3612 commit 0f85e24

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

fs/btrfs/super.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,10 +2642,44 @@ static void btrfs_kill_super(struct super_block *sb)
26422642
btrfs_free_fs_info(fs_info);
26432643
}
26442644

2645-
static const struct fs_context_operations btrfs_fs_context_ops __maybe_unused = {
2645+
static void btrfs_free_fs_context(struct fs_context *fc)
2646+
{
2647+
struct btrfs_fs_context *ctx = fc->fs_private;
2648+
2649+
if (!ctx)
2650+
return;
2651+
2652+
kfree(ctx->subvol_name);
2653+
kfree(ctx);
2654+
}
2655+
2656+
static const struct fs_context_operations btrfs_fs_context_ops = {
26462657
.parse_param = btrfs_parse_param,
2658+
.free = btrfs_free_fs_context,
26472659
};
26482660

2661+
static int __maybe_unused btrfs_init_fs_context(struct fs_context *fc)
2662+
{
2663+
struct btrfs_fs_context *ctx;
2664+
2665+
ctx = kzalloc(sizeof(struct btrfs_fs_context), GFP_KERNEL);
2666+
if (!ctx)
2667+
return -ENOMEM;
2668+
2669+
ctx->thread_pool_size = min_t(unsigned long, num_online_cpus() + 2, 8);
2670+
ctx->max_inline = BTRFS_DEFAULT_MAX_INLINE;
2671+
ctx->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
2672+
ctx->subvol_objectid = BTRFS_FS_TREE_OBJECTID;
2673+
#ifndef CONFIG_BTRFS_FS_POSIX_ACL
2674+
ctx->noacl = true;
2675+
#endif
2676+
2677+
fc->fs_private = ctx;
2678+
fc->ops = &btrfs_fs_context_ops;
2679+
2680+
return 0;
2681+
}
2682+
26492683
static struct file_system_type btrfs_fs_type = {
26502684
.owner = THIS_MODULE,
26512685
.name = "btrfs",

0 commit comments

Comments
 (0)