Skip to content

Commit c6be2bd

Browse files
lostjefflehsiangkao
authored andcommitted
erofs: register fscache volume
A new fscache based mode is going to be introduced for erofs, in which case on-demand read semantics is implemented through fscache. As the first step, register fscache volume for each erofs filesystem. That means, data blobs can not be shared among erofs filesystems. In the following iteration, we are going to introduce the domain semantics, in which case several erofs filesystems can belong to one domain, and data blobs can be shared among these erofs filesystems of one domain. 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 93b856b commit c6be2bd

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

fs/erofs/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,13 @@ config EROFS_FS_ZIP_LZMA
9898
systems will be readable without selecting this option.
9999

100100
If unsure, say N.
101+
102+
config EROFS_FS_ONDEMAND
103+
bool "EROFS fscache-based on-demand read support"
104+
depends on CACHEFILES_ONDEMAND && (EROFS_FS=m && FSCACHE || EROFS_FS=y && FSCACHE=y)
105+
default n
106+
help
107+
This permits EROFS to use fscache-backed data blobs with on-demand
108+
read support.
109+
110+
If unsure, say N.

fs/erofs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ erofs-objs := super.o inode.o data.o namei.o dir.o utils.o pcpubuf.o sysfs.o
55
erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
66
erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o
77
erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o
8+
erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o

fs/erofs/fscache.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (C) 2022, Alibaba Cloud
4+
*/
5+
#include <linux/fscache.h>
6+
#include "internal.h"
7+
8+
int erofs_fscache_register_fs(struct super_block *sb)
9+
{
10+
struct erofs_sb_info *sbi = EROFS_SB(sb);
11+
struct fscache_volume *volume;
12+
char *name;
13+
int ret = 0;
14+
15+
name = kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid);
16+
if (!name)
17+
return -ENOMEM;
18+
19+
volume = fscache_acquire_volume(name, NULL, NULL, 0);
20+
if (IS_ERR_OR_NULL(volume)) {
21+
erofs_err(sb, "failed to register volume for %s", name);
22+
ret = volume ? PTR_ERR(volume) : -EOPNOTSUPP;
23+
volume = NULL;
24+
}
25+
26+
sbi->volume = volume;
27+
kfree(name);
28+
return ret;
29+
}
30+
31+
void erofs_fscache_unregister_fs(struct super_block *sb)
32+
{
33+
struct erofs_sb_info *sbi = EROFS_SB(sb);
34+
35+
fscache_relinquish_volume(sbi->volume, NULL, false);
36+
sbi->volume = NULL;
37+
}

fs/erofs/internal.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct erofs_mount_opts {
7474
unsigned int max_sync_decompress_pages;
7575
#endif
7676
unsigned int mount_opt;
77+
char *fsid;
7778
};
7879

7980
struct erofs_dev_context {
@@ -146,6 +147,9 @@ struct erofs_sb_info {
146147
/* sysfs support */
147148
struct kobject s_kobj; /* /sys/fs/erofs/<devname> */
148149
struct completion s_kobj_unregister;
150+
151+
/* fscache support */
152+
struct fscache_volume *volume;
149153
};
150154

151155
#define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
@@ -593,6 +597,18 @@ static inline int z_erofs_load_lzma_config(struct super_block *sb,
593597
}
594598
#endif /* !CONFIG_EROFS_FS_ZIP */
595599

600+
/* fscache.c */
601+
#ifdef CONFIG_EROFS_FS_ONDEMAND
602+
int erofs_fscache_register_fs(struct super_block *sb);
603+
void erofs_fscache_unregister_fs(struct super_block *sb);
604+
#else
605+
static inline int erofs_fscache_register_fs(struct super_block *sb)
606+
{
607+
return 0;
608+
}
609+
static inline void erofs_fscache_unregister_fs(struct super_block *sb) {}
610+
#endif
611+
596612
#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
597613

598614
#endif /* __EROFS_INTERNAL_H */

fs/erofs/super.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
641641
if (erofs_is_fscache_mode(sb)) {
642642
sb->s_blocksize = EROFS_BLKSIZ;
643643
sb->s_blocksize_bits = LOG_BLOCK_SIZE;
644+
645+
err = erofs_fscache_register_fs(sb);
646+
if (err)
647+
return err;
644648
} else {
645649
if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
646650
erofs_err(sb, "failed to set erofs blksize");
@@ -808,6 +812,7 @@ static void erofs_kill_sb(struct super_block *sb)
808812

809813
erofs_free_dev_context(sbi->devs);
810814
fs_put_dax(sbi->dax_dev);
815+
erofs_fscache_unregister_fs(sb);
811816
kfree(sbi);
812817
sb->s_fs_info = NULL;
813818
}

0 commit comments

Comments
 (0)