Skip to content

Commit 9c0cc9c

Browse files
lostjefflehsiangkao
authored andcommitted
erofs: add 'fsid' mount option
Introduce 'fsid' mount option to enable on-demand read sementics, in which case, erofs will be mounted from data blobs. Users could specify the name of primary data blob by this mount option. Signed-off-by: Jeffle Xu <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Chao Yu <[email protected]> Tested-by: Zichen Tian <[email protected]> Tested-by: Jia Zhu <[email protected]> Tested-by: Yan Song <[email protected]> Signed-off-by: Gao Xiang <[email protected]>
1 parent c665b39 commit 9c0cc9c

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

fs/erofs/super.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ static int erofs_read_superblock(struct super_block *sb)
372372

373373
if (erofs_sb_has_ztailpacking(sbi))
374374
erofs_info(sb, "EXPERIMENTAL compressed inline data feature in use. Use at your own risk!");
375+
if (erofs_is_fscache_mode(sb))
376+
erofs_info(sb, "EXPERIMENTAL fscache-based on-demand read feature in use. Use at your own risk!");
375377
out:
376378
erofs_put_metabuf(&buf);
377379
return ret;
@@ -400,6 +402,7 @@ enum {
400402
Opt_dax,
401403
Opt_dax_enum,
402404
Opt_device,
405+
Opt_fsid,
403406
Opt_err
404407
};
405408

@@ -424,6 +427,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {
424427
fsparam_flag("dax", Opt_dax),
425428
fsparam_enum("dax", Opt_dax_enum, erofs_dax_param_enums),
426429
fsparam_string("device", Opt_device),
430+
fsparam_string("fsid", Opt_fsid),
427431
{}
428432
};
429433

@@ -519,6 +523,16 @@ static int erofs_fc_parse_param(struct fs_context *fc,
519523
}
520524
++ctx->devs->extra_devices;
521525
break;
526+
case Opt_fsid:
527+
#ifdef CONFIG_EROFS_FS_ONDEMAND
528+
kfree(ctx->opt.fsid);
529+
ctx->opt.fsid = kstrdup(param->string, GFP_KERNEL);
530+
if (!ctx->opt.fsid)
531+
return -ENOMEM;
532+
#else
533+
errorfc(fc, "fsid option not supported");
534+
#endif
535+
break;
522536
default:
523537
return -ENOPARAM;
524538
}
@@ -643,6 +657,7 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
643657

644658
sb->s_fs_info = sbi;
645659
sbi->opt = ctx->opt;
660+
ctx->opt.fsid = NULL;
646661
sbi->devs = ctx->devs;
647662
ctx->devs = NULL;
648663

@@ -730,6 +745,11 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
730745

731746
static int erofs_fc_get_tree(struct fs_context *fc)
732747
{
748+
struct erofs_fs_context *ctx = fc->fs_private;
749+
750+
if (IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && ctx->opt.fsid)
751+
return get_tree_nodev(fc, erofs_fc_fill_super);
752+
733753
return get_tree_bdev(fc, erofs_fc_fill_super);
734754
}
735755

@@ -779,6 +799,7 @@ static void erofs_fc_free(struct fs_context *fc)
779799
struct erofs_fs_context *ctx = fc->fs_private;
780800

781801
erofs_free_dev_context(ctx->devs);
802+
kfree(ctx->opt.fsid);
782803
kfree(ctx);
783804
}
784805

@@ -819,7 +840,10 @@ static void erofs_kill_sb(struct super_block *sb)
819840

820841
WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
821842

822-
kill_block_super(sb);
843+
if (erofs_is_fscache_mode(sb))
844+
generic_shutdown_super(sb);
845+
else
846+
kill_block_super(sb);
823847

824848
sbi = EROFS_SB(sb);
825849
if (!sbi)
@@ -829,6 +853,7 @@ static void erofs_kill_sb(struct super_block *sb)
829853
fs_put_dax(sbi->dax_dev);
830854
erofs_fscache_unregister_cookie(&sbi->s_fscache);
831855
erofs_fscache_unregister_fs(sb);
856+
kfree(sbi->opt.fsid);
832857
kfree(sbi);
833858
sb->s_fs_info = NULL;
834859
}
@@ -978,6 +1003,10 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)
9781003
seq_puts(seq, ",dax=always");
9791004
if (test_opt(opt, DAX_NEVER))
9801005
seq_puts(seq, ",dax=never");
1006+
#ifdef CONFIG_EROFS_FS_ONDEMAND
1007+
if (opt->fsid)
1008+
seq_printf(seq, ",fsid=%s", opt->fsid);
1009+
#endif
9811010
return 0;
9821011
}
9831012

fs/erofs/sysfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ int erofs_register_sysfs(struct super_block *sb)
205205

206206
sbi->s_kobj.kset = &erofs_root;
207207
init_completion(&sbi->s_kobj_unregister);
208-
err = kobject_init_and_add(&sbi->s_kobj, &erofs_sb_ktype, NULL,
209-
"%s", sb->s_id);
208+
err = kobject_init_and_add(&sbi->s_kobj, &erofs_sb_ktype, NULL, "%s",
209+
erofs_is_fscache_mode(sb) ? sbi->opt.fsid : sb->s_id);
210210
if (err)
211211
goto put_sb_kobj;
212212
return 0;

0 commit comments

Comments
 (0)