Skip to content

Commit 93b856b

Browse files
lostjefflehsiangkao
authored andcommitted
erofs: add fscache mode check helper
Until then erofs is exactly blockdev based filesystem. A new fscache-based mode is going to be introduced for erofs to support scenarios where on-demand read semantics is needed, e.g. container image distribution. In this case, erofs could be mounted from data blobs through fscache. Add a helper checking which mode erofs works in, and twist the code in preparation for the upcoming fscache mode. 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]> Signed-off-by: Gao Xiang <[email protected]>
1 parent 94d7894 commit 93b856b

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

fs/erofs/internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ struct erofs_sb_info {
161161
#define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)
162162
#define test_opt(opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option)
163163

164+
static inline bool erofs_is_fscache_mode(struct super_block *sb)
165+
{
166+
return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !sb->s_bdev;
167+
}
168+
164169
enum {
165170
EROFS_ZIP_CACHE_DISABLED,
166171
EROFS_ZIP_CACHE_READAHEAD,

fs/erofs/super.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,19 @@ static int erofs_init_devices(struct super_block *sb,
260260
}
261261
dis = ptr + erofs_blkoff(pos);
262262

263-
bdev = blkdev_get_by_path(dif->path,
264-
FMODE_READ | FMODE_EXCL,
265-
sb->s_type);
266-
if (IS_ERR(bdev)) {
267-
err = PTR_ERR(bdev);
268-
break;
263+
if (!erofs_is_fscache_mode(sb)) {
264+
bdev = blkdev_get_by_path(dif->path,
265+
FMODE_READ | FMODE_EXCL,
266+
sb->s_type);
267+
if (IS_ERR(bdev)) {
268+
err = PTR_ERR(bdev);
269+
break;
270+
}
271+
dif->bdev = bdev;
272+
dif->dax_dev = fs_dax_get_by_bdev(bdev,
273+
&dif->dax_part_off);
269274
}
270-
dif->bdev = bdev;
271-
dif->dax_dev = fs_dax_get_by_bdev(bdev, &dif->dax_part_off);
275+
272276
dif->blocks = le32_to_cpu(dis->blocks);
273277
dif->mapped_blkaddr = le32_to_cpu(dis->mapped_blkaddr);
274278
sbi->total_blocks += dif->blocks;
@@ -625,21 +629,28 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
625629

626630
sb->s_magic = EROFS_SUPER_MAGIC;
627631

628-
if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
629-
erofs_err(sb, "failed to set erofs blksize");
630-
return -EINVAL;
631-
}
632-
633632
sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
634633
if (!sbi)
635634
return -ENOMEM;
636635

637636
sb->s_fs_info = sbi;
638637
sbi->opt = ctx->opt;
639-
sbi->dax_dev = fs_dax_get_by_bdev(sb->s_bdev, &sbi->dax_part_off);
640638
sbi->devs = ctx->devs;
641639
ctx->devs = NULL;
642640

641+
if (erofs_is_fscache_mode(sb)) {
642+
sb->s_blocksize = EROFS_BLKSIZ;
643+
sb->s_blocksize_bits = LOG_BLOCK_SIZE;
644+
} else {
645+
if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
646+
erofs_err(sb, "failed to set erofs blksize");
647+
return -EINVAL;
648+
}
649+
650+
sbi->dax_dev = fs_dax_get_by_bdev(sb->s_bdev,
651+
&sbi->dax_part_off);
652+
}
653+
643654
err = erofs_read_superblock(sb);
644655
if (err)
645656
return err;
@@ -897,7 +908,10 @@ static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
897908
{
898909
struct super_block *sb = dentry->d_sb;
899910
struct erofs_sb_info *sbi = EROFS_SB(sb);
900-
u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
911+
u64 id = 0;
912+
913+
if (!erofs_is_fscache_mode(sb))
914+
id = huge_encode_dev(sb->s_bdev->bd_dev);
901915

902916
buf->f_type = sb->s_magic;
903917
buf->f_bsize = EROFS_BLKSIZ;

0 commit comments

Comments
 (0)