Skip to content

Commit 2d1d3eb

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 <[email protected]> Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Jingbo Xu <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Chao Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Gao Xiang: trivial conflict due to a warning message. ] Signed-off-by: Gao Xiang <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 189c768 commit 2d1d3eb

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
@@ -84,13 +84,6 @@ struct erofs_dev_context {
8484
bool flatdev;
8585
};
8686

87-
struct erofs_fs_context {
88-
struct erofs_mount_opts opt;
89-
struct erofs_dev_context *devs;
90-
char *fsid;
91-
char *domain_id;
92-
};
93-
9487
/* all filesystem-wide lz4 configurations */
9588
struct erofs_sb_lz4_info {
9689
/* # 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
@@ -370,18 +370,18 @@ static int erofs_read_superblock(struct super_block *sb)
370370
return ret;
371371
}
372372

373-
static void erofs_default_options(struct erofs_fs_context *ctx)
373+
static void erofs_default_options(struct erofs_sb_info *sbi)
374374
{
375375
#ifdef CONFIG_EROFS_FS_ZIP
376-
ctx->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND;
377-
ctx->opt.max_sync_decompress_pages = 3;
378-
ctx->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO;
376+
sbi->opt.cache_strategy = EROFS_ZIP_CACHE_READAROUND;
377+
sbi->opt.max_sync_decompress_pages = 3;
378+
sbi->opt.sync_decompress = EROFS_SYNC_DECOMPRESS_AUTO;
379379
#endif
380380
#ifdef CONFIG_EROFS_FS_XATTR
381-
set_opt(&ctx->opt, XATTR_USER);
381+
set_opt(&sbi->opt, XATTR_USER);
382382
#endif
383383
#ifdef CONFIG_EROFS_FS_POSIX_ACL
384-
set_opt(&ctx->opt, POSIX_ACL);
384+
set_opt(&sbi->opt, POSIX_ACL);
385385
#endif
386386
}
387387

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

431431
switch (mode) {
432432
case EROFS_MOUNT_DAX_ALWAYS:
433433
warnfc(fc, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
434-
set_opt(&ctx->opt, DAX_ALWAYS);
435-
clear_opt(&ctx->opt, DAX_NEVER);
434+
set_opt(&sbi->opt, DAX_ALWAYS);
435+
clear_opt(&sbi->opt, DAX_NEVER);
436436
return true;
437437
case EROFS_MOUNT_DAX_NEVER:
438-
set_opt(&ctx->opt, DAX_NEVER);
439-
clear_opt(&ctx->opt, DAX_ALWAYS);
438+
set_opt(&sbi->opt, DAX_NEVER);
439+
clear_opt(&sbi->opt, DAX_ALWAYS);
440440
return true;
441441
default:
442442
DBG_BUGON(1);
@@ -451,7 +451,7 @@ static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
451451
static int erofs_fc_parse_param(struct fs_context *fc,
452452
struct fs_parameter *param)
453453
{
454-
struct erofs_fs_context *ctx = fc->fs_private;
454+
struct erofs_sb_info *sbi = fc->s_fs_info;
455455
struct fs_parse_result result;
456456
struct erofs_device_info *dif;
457457
int opt, ret;
@@ -464,26 +464,26 @@ static int erofs_fc_parse_param(struct fs_context *fc,
464464
case Opt_user_xattr:
465465
#ifdef CONFIG_EROFS_FS_XATTR
466466
if (result.boolean)
467-
set_opt(&ctx->opt, XATTR_USER);
467+
set_opt(&sbi->opt, XATTR_USER);
468468
else
469-
clear_opt(&ctx->opt, XATTR_USER);
469+
clear_opt(&sbi->opt, XATTR_USER);
470470
#else
471471
errorfc(fc, "{,no}user_xattr options not supported");
472472
#endif
473473
break;
474474
case Opt_acl:
475475
#ifdef CONFIG_EROFS_FS_POSIX_ACL
476476
if (result.boolean)
477-
set_opt(&ctx->opt, POSIX_ACL);
477+
set_opt(&sbi->opt, POSIX_ACL);
478478
else
479-
clear_opt(&ctx->opt, POSIX_ACL);
479+
clear_opt(&sbi->opt, POSIX_ACL);
480480
#else
481481
errorfc(fc, "{,no}acl options not supported");
482482
#endif
483483
break;
484484
case Opt_cache_strategy:
485485
#ifdef CONFIG_EROFS_FS_ZIP
486-
ctx->opt.cache_strategy = result.uint_32;
486+
sbi->opt.cache_strategy = result.uint_32;
487487
#else
488488
errorfc(fc, "compression not supported, cache_strategy ignored");
489489
#endif
@@ -505,27 +505,27 @@ static int erofs_fc_parse_param(struct fs_context *fc,
505505
kfree(dif);
506506
return -ENOMEM;
507507
}
508-
down_write(&ctx->devs->rwsem);
509-
ret = idr_alloc(&ctx->devs->tree, dif, 0, 0, GFP_KERNEL);
510-
up_write(&ctx->devs->rwsem);
508+
down_write(&sbi->devs->rwsem);
509+
ret = idr_alloc(&sbi->devs->tree, dif, 0, 0, GFP_KERNEL);
510+
up_write(&sbi->devs->rwsem);
511511
if (ret < 0) {
512512
kfree(dif->path);
513513
kfree(dif);
514514
return ret;
515515
}
516-
++ctx->devs->extra_devices;
516+
++sbi->devs->extra_devices;
517517
break;
518518
#ifdef CONFIG_EROFS_FS_ONDEMAND
519519
case Opt_fsid:
520-
kfree(ctx->fsid);
521-
ctx->fsid = kstrdup(param->string, GFP_KERNEL);
522-
if (!ctx->fsid)
520+
kfree(sbi->fsid);
521+
sbi->fsid = kstrdup(param->string, GFP_KERNEL);
522+
if (!sbi->fsid)
523523
return -ENOMEM;
524524
break;
525525
case Opt_domain_id:
526-
kfree(ctx->domain_id);
527-
ctx->domain_id = kstrdup(param->string, GFP_KERNEL);
528-
if (!ctx->domain_id)
526+
kfree(sbi->domain_id);
527+
sbi->domain_id = kstrdup(param->string, GFP_KERNEL);
528+
if (!sbi->domain_id)
529529
return -ENOMEM;
530530
break;
531531
#else
@@ -582,28 +582,14 @@ static const struct export_operations erofs_export_ops = {
582582
static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
583583
{
584584
struct inode *inode;
585-
struct erofs_sb_info *sbi;
586-
struct erofs_fs_context *ctx = fc->fs_private;
585+
struct erofs_sb_info *sbi = EROFS_SB(sb);
587586
int err;
588587

589588
sb->s_magic = EROFS_SUPER_MAGIC;
590589
sb->s_flags |= SB_RDONLY | SB_NOATIME;
591590
sb->s_maxbytes = MAX_LFS_FILESIZE;
592591
sb->s_op = &erofs_sops;
593592

594-
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
595-
if (!sbi)
596-
return -ENOMEM;
597-
598-
sb->s_fs_info = sbi;
599-
sbi->opt = ctx->opt;
600-
sbi->devs = ctx->devs;
601-
ctx->devs = NULL;
602-
sbi->fsid = ctx->fsid;
603-
ctx->fsid = NULL;
604-
sbi->domain_id = ctx->domain_id;
605-
ctx->domain_id = NULL;
606-
607593
sbi->blkszbits = PAGE_SHIFT;
608594
if (erofs_is_fscache_mode(sb)) {
609595
sb->s_blocksize = PAGE_SIZE;
@@ -707,9 +693,9 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
707693

708694
static int erofs_fc_get_tree(struct fs_context *fc)
709695
{
710-
struct erofs_fs_context *ctx = fc->fs_private;
696+
struct erofs_sb_info *sbi = fc->s_fs_info;
711697

712-
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && ctx->fsid)
698+
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && sbi->fsid)
713699
return get_tree_nodev(fc, erofs_fc_fill_super);
714700

715701
return get_tree_bdev(fc, erofs_fc_fill_super);
@@ -719,19 +705,19 @@ static int erofs_fc_reconfigure(struct fs_context *fc)
719705
{
720706
struct super_block *sb = fc->root->d_sb;
721707
struct erofs_sb_info *sbi = EROFS_SB(sb);
722-
struct erofs_fs_context *ctx = fc->fs_private;
708+
struct erofs_sb_info *new_sbi = fc->s_fs_info;
723709

724710
DBG_BUGON(!sb_rdonly(sb));
725711

726-
if (ctx->fsid || ctx->domain_id)
712+
if (new_sbi->fsid || new_sbi->domain_id)
727713
erofs_info(sb, "ignoring reconfiguration for fsid|domain_id.");
728714

729-
if (test_opt(&ctx->opt, POSIX_ACL))
715+
if (test_opt(&new_sbi->opt, POSIX_ACL))
730716
fc->sb_flags |= SB_POSIXACL;
731717
else
732718
fc->sb_flags &= ~SB_POSIXACL;
733719

734-
sbi->opt = ctx->opt;
720+
sbi->opt = new_sbi->opt;
735721

736722
fc->sb_flags |= SB_RDONLY;
737723
return 0;
@@ -762,12 +748,15 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs)
762748

763749
static void erofs_fc_free(struct fs_context *fc)
764750
{
765-
struct erofs_fs_context *ctx = fc->fs_private;
751+
struct erofs_sb_info *sbi = fc->s_fs_info;
752+
753+
if (!sbi)
754+
return;
766755

767-
erofs_free_dev_context(ctx->devs);
768-
kfree(ctx->fsid);
769-
kfree(ctx->domain_id);
770-
kfree(ctx);
756+
erofs_free_dev_context(sbi->devs);
757+
kfree(sbi->fsid);
758+
kfree(sbi->domain_id);
759+
kfree(sbi);
771760
}
772761

773762
static const struct fs_context_operations erofs_context_ops = {
@@ -779,21 +768,22 @@ static const struct fs_context_operations erofs_context_ops = {
779768

780769
static int erofs_init_fs_context(struct fs_context *fc)
781770
{
782-
struct erofs_fs_context *ctx;
771+
struct erofs_sb_info *sbi;
783772

784-
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
785-
if (!ctx)
773+
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
774+
if (!sbi)
786775
return -ENOMEM;
787-
ctx->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL);
788-
if (!ctx->devs) {
789-
kfree(ctx);
776+
777+
sbi->devs = kzalloc(sizeof(struct erofs_dev_context), GFP_KERNEL);
778+
if (!sbi->devs) {
779+
kfree(sbi);
790780
return -ENOMEM;
791781
}
792-
fc->fs_private = ctx;
782+
fc->s_fs_info = sbi;
793783

794-
idr_init(&ctx->devs->tree);
795-
init_rwsem(&ctx->devs->rwsem);
796-
erofs_default_options(ctx);
784+
idr_init(&sbi->devs->tree);
785+
init_rwsem(&sbi->devs->rwsem);
786+
erofs_default_options(sbi);
797787
fc->ops = &erofs_context_ops;
798788
return 0;
799789
}

0 commit comments

Comments
 (0)