Skip to content

Commit 3924179

Browse files
LiBaokun96gregkh
authored andcommitted
erofs: get rid of erofs_fs_context
commit 07abe43 upstream. Instead of allocating the erofs_sb_info in fill_super() allocate it during erofs_init_fs_context() and ensure that erofs can always have the info available during erofs_kill_sb(). After this erofs_fs_context is no longer needed, replace ctx with sbi, no functional changes. Suggested-by: Jingbo Xu <jefflexu@linux.alibaba.com> Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Reviewed-by: Chao Yu <chao@kernel.org> Link: https://lore.kernel.org/r/20240419123611.947084-2-libaokun1@huawei.com [ Gao Xiang: trivial conflict due to a warning message. ] Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fcb05fe commit 3924179

File tree

2 files changed

+53
-70
lines changed

2 files changed

+53
-70
lines changed

fs/erofs/internal.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ struct erofs_dev_context {
8282
bool flatdev;
8383
};
8484

85-
struct erofs_fs_context {
86-
struct erofs_mount_opts opt;
87-
struct erofs_dev_context *devs;
88-
char *fsid;
89-
char *domain_id;
90-
};
91-
9285
/* all filesystem-wide lz4 configurations */
9386
struct erofs_sb_lz4_info {
9487
/* # of pages needed for EROFS lz4 rolling decompression */

fs/erofs/super.c

Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,18 @@ static int erofs_read_superblock(struct super_block *sb)
367367
return ret;
368368
}
369369

370-
static void erofs_default_options(struct erofs_fs_context *ctx)
370+
static void erofs_default_options(struct erofs_sb_info *sbi)
371371
{
372372
#ifdef CONFIG_EROFS_FS_ZIP
373-
ctx->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND;
374-
ctx->opt.max_sync_decompress_pages = 3;
375-
ctx->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO;
373+
sbi->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND;
374+
sbi->opt.max_sync_decompress_pages = 3;
375+
sbi->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO;
376376
#endif
377377
#ifdef CONFIG_EROFS_FS_XATTR
378-
set_opt(&ctx->opt, XATTR_USER);
378+
set_opt(&sbi->opt, XATTR_USER);
379379
#endif
380380
#ifdef CONFIG_EROFS_FS_POSIX_ACL
381-
set_opt(&ctx->opt, POSIX_ACL);
381+
set_opt(&sbi->opt, POSIX_ACL);
382382
#endif
383383
}
384384

@@ -423,17 +423,17 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {
423423
static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
424424
{
425425
#ifdef CONFIG_FS_DAX
426-
struct erofs_fs_context *ctx = fc->fs_private;
426+
struct erofs_sb_info *sbi = fc->s_fs_info;
427427

428428
switch (mode) {
429429
case EROFS_MOUNT_DAX_ALWAYS:
430430
warnfc(fc, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
431-
set_opt(&ctx->opt, DAX_ALWAYS);
432-
clear_opt(&ctx->opt, DAX_NEVER);
431+
set_opt(&sbi->opt, DAX_ALWAYS);
432+
clear_opt(&sbi->opt, DAX_NEVER);
433433
return true;
434434
case EROFS_MOUNT_DAX_NEVER:
435-
set_opt(&ctx->opt, DAX_NEVER);
436-
clear_opt(&ctx->opt, DAX_ALWAYS);
435+
set_opt(&sbi->opt, DAX_NEVER);
436+
clear_opt(&sbi->opt, DAX_ALWAYS);
437437
return true;
438438
default:
439439
DBG_BUGON(1);
@@ -448,7 +448,7 @@ static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
448448
static int erofs_fc_parse_param(struct fs_context *fc,
449449
struct fs_parameter *param)
450450
{
451-
struct erofs_fs_context *ctx = fc->fs_private;
451+
struct erofs_sb_info *sbi = fc->s_fs_info;
452452
struct fs_parse_result result;
453453
struct erofs_device_info *dif;
454454
int opt, ret;
@@ -461,26 +461,26 @@ static int erofs_fc_parse_param(struct fs_context *fc,
461461
case Opt_user_xattr:
462462
#ifdef CONFIG_EROFS_FS_XATTR
463463
if (result.boolean)
464-
set_opt(&ctx->opt, XATTR_USER);
464+
set_opt(&sbi->opt, XATTR_USER);
465465
else
466-
clear_opt(&ctx->opt, XATTR_USER);
466+
clear_opt(&sbi->opt, XATTR_USER);
467467
#else
468468
errorfc(fc, "{,no}user_xattr options not supported");
469469
#endif
470470
break;
471471
case Opt_acl:
472472
#ifdef CONFIG_EROFS_FS_POSIX_ACL
473473
if (result.boolean)
474-
set_opt(&ctx->opt, POSIX_ACL);
474+
set_opt(&sbi->opt, POSIX_ACL);
475475
else
476-
clear_opt(&ctx->opt, POSIX_ACL);
476+
clear_opt(&sbi->opt, POSIX_ACL);
477477
#else
478478
errorfc(fc, "{,no}acl options not supported");
479479
#endif
480480
break;
481481
case Opt_cache_strategy:
482482
#ifdef CONFIG_EROFS_FS_ZIP
483-
ctx->opt.cache_strategy = result.uint_32;
483+
sbi->opt.cache_strategy = result.uint_32;
484484
#else
485485
errorfc(fc, "compression not supported, cache_strategy ignored");
486486
#endif
@@ -502,27 +502,27 @@ static int erofs_fc_parse_param(struct fs_context *fc,
502502
kfree(dif);
503503
return -ENOMEM;
504504
}
505-
down_write(&ctx->devs->rwsem);
506-
ret = idr_alloc(&ctx->devs->tree, dif, 0, 0, GFP_KERNEL);
507-
up_write(&ctx->devs->rwsem);
505+
down_write(&sbi->devs->rwsem);
506+
ret = idr_alloc(&sbi->devs->tree, dif, 0, 0, GFP_KERNEL);
507+
up_write(&sbi->devs->rwsem);
508508
if (ret < 0) {
509509
kfree(dif->path);
510510
kfree(dif);
511511
return ret;
512512
}
513-
++ctx->devs->extra_devices;
513+
++sbi->devs->extra_devices;
514514
break;
515515
#ifdef CONFIG_EROFS_FS_ONDEMAND
516516
case Opt_fsid:
517-
kfree(ctx->fsid);
518-
ctx->fsid = kstrdup(param->string, GFP_KERNEL);
519-
if (!ctx->fsid)
517+
kfree(sbi->fsid);
518+
sbi->fsid = kstrdup(param->string, GFP_KERNEL);
519+
if (!sbi->fsid)
520520
return -ENOMEM;
521521
break;
522522
case Opt_domain_id:
523-
kfree(ctx->domain_id);
524-
ctx->domain_id = kstrdup(param->string, GFP_KERNEL);
525-
if (!ctx->domain_id)
523+
kfree(sbi->domain_id);
524+
sbi->domain_id = kstrdup(param->string, GFP_KERNEL);
525+
if (!sbi->domain_id)
526526
return -ENOMEM;
527527
break;
528528
#else
@@ -578,28 +578,14 @@ static const struct export_operations erofs_export_ops = {
578578
static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
579579
{
580580
struct inode *inode;
581-
struct erofs_sb_info *sbi;
582-
struct erofs_fs_context *ctx = fc->fs_private;
581+
struct erofs_sb_info *sbi = EROFS_SB(sb);
583582
int err;
584583

585584
sb->s_magic = EROFS_SUPER_MAGIC;
586585
sb->s_flags |= SB_RDONLY | SB_NOATIME;
587586
sb->s_maxbytes = MAX_LFS_FILESIZE;
588587
sb->s_op = &erofs_sops;
589588

590-
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
591-
if (!sbi)
592-
return -ENOMEM;
593-
594-
sb->s_fs_info = sbi;
595-
sbi->opt = ctx->opt;
596-
sbi->devs = ctx->devs;
597-
ctx->devs = NULL;
598-
sbi->fsid = ctx->fsid;
599-
ctx->fsid = NULL;
600-
sbi->domain_id = ctx->domain_id;
601-
ctx->domain_id = NULL;
602-
603589
sbi->blkszbits = PAGE_SHIFT;
604590
if (erofs_is_fscache_mode(sb)) {
605591
sb->s_blocksize = PAGE_SIZE;
@@ -703,9 +689,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
703689

704690
static int erofs_fc_get_tree(struct fs_context *fc)
705691
{
706-
struct erofs_fs_context *ctx = fc->fs_private;
692+
struct erofs_sb_info *sbi = fc->s_fs_info;
707693

708-
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && ctx->fsid)
694+
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid)
709695
return get_tree_nodev(fc, erofs_fc_fill_super);
710696

711697
return get_tree_bdev(fc, erofs_fc_fill_super);
@@ -715,19 +701,19 @@ static int erofs_fc_reconfigure(struct fs_context *fc)
715701
{
716702
struct super_block *sb = fc->root->d_sb;
717703
struct erofs_sb_info *sbi = EROFS_SB(sb);
718-
struct erofs_fs_context *ctx = fc->fs_private;
704+
struct erofs_sb_info *new_sbi = fc->s_fs_info;
719705

720706
DBG_BUGON(!sb_rdonly(sb));
721707

722-
if (ctx->fsid || ctx->domain_id)
708+
if (new_sbi->fsid || new_sbi->domain_id)
723709
erofs_info(sb, "ignoring reconfiguration for fsid|domain_id.");
724710

725-
if (test_opt(&ctx->opt, POSIX_ACL))
711+
if (test_opt(&new_sbi->opt, POSIX_ACL))
726712
fc->sb_flags |= SB_POSIXACL;
727713
else
728714
fc->sb_flags &= ~SB_POSIXACL;
729715

730-
sbi->opt = ctx->opt;
716+
sbi->opt = new_sbi->opt;
731717

732718
fc->sb_flags |= SB_RDONLY;
733719
return 0;
@@ -758,12 +744,15 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs)
758744

759745
static void erofs_fc_free(struct fs_context *fc)
760746
{
761-
struct erofs_fs_context *ctx = fc->fs_private;
747+
struct erofs_sb_info *sbi = fc->s_fs_info;
748+
749+
if (!sbi)
750+
return;
762751

763-
erofs_free_dev_context(ctx->devs);
764-
kfree(ctx->fsid);
765-
kfree(ctx->domain_id);
766-
kfree(ctx);
752+
erofs_free_dev_context(sbi->devs);
753+
kfree(sbi->fsid);
754+
kfree(sbi->domain_id);
755+
kfree(sbi);
767756
}
768757

769758
static const struct fs_context_operations erofs_context_ops = {
@@ -775,21 +764,22 @@ static const struct fs_context_operations erofs_context_ops = {
775764

776765
static int erofs_init_fs_context(struct fs_context *fc)
777766
{
778-
struct erofs_fs_context *ctx;
767+
struct erofs_sb_info *sbi;
779768

780-
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
781-
if (!ctx)
769+
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
770+
if (!sbi)
782771
return -ENOMEM;
783-
ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL);
784-
if (!ctx->devs) {
785-
kfree(ctx);
772+
773+
sbi->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL);
774+
if (!sbi->devs) {
775+
kfree(sbi);
786776
return -ENOMEM;
787777
}
788-
fc->fs_private = ctx;
778+
fc->s_fs_info = sbi;
789779

790-
idr_init(&ctx->devs->tree);
791-
init_rwsem(&ctx->devs->rwsem);
792-
erofs_default_options(ctx);
780+
idr_init(&sbi->devs->tree);
781+
init_rwsem(&sbi->devs->rwsem);
782+
erofs_default_options(sbi);
793783
fc->ops = &erofs_context_ops;
794784
return 0;
795785
}

0 commit comments

Comments
 (0)