Skip to content

Commit e0bf7d1

Browse files
Hongzhen Luohsiangkao
authored andcommitted
erofs: support user-defined fingerprint name
When creating the EROFS image, users can specify the fingerprint name. This is to prepare for the upcoming inode page cache share. Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com> Signed-off-by: Hongbo Li <lihongbo22@huawei.com> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 4340ca4 commit e0bf7d1

5 files changed

Lines changed: 36 additions & 2 deletions

File tree

fs/erofs/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,12 @@ config EROFS_FS_PCPU_KTHREAD_HIPRI
194194
at higher priority.
195195

196196
If unsure, say N.
197+
198+
config EROFS_FS_PAGE_CACHE_SHARE
199+
bool "EROFS page cache share support (experimental)"
200+
depends on EROFS_FS && EROFS_FS_XATTR && !EROFS_FS_ONDEMAND
201+
help
202+
This enables page cache sharing among inodes with identical
203+
content fingerprints on the same machine.
204+
205+
If unsure, say N.

fs/erofs/erofs_fs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#define EROFS_FEATURE_COMPAT_XATTR_FILTER 0x00000004
1818
#define EROFS_FEATURE_COMPAT_SHARED_EA_IN_METABOX 0x00000008
1919
#define EROFS_FEATURE_COMPAT_PLAIN_XATTR_PFX 0x00000010
20-
20+
#define EROFS_FEATURE_COMPAT_ISHARE_XATTRS 0x00000020
2121

2222
/*
2323
* Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
@@ -83,7 +83,8 @@ struct erofs_super_block {
8383
__le32 xattr_prefix_start; /* start of long xattr prefixes */
8484
__le64 packed_nid; /* nid of the special packed inode */
8585
__u8 xattr_filter_reserved; /* reserved for xattr name filter */
86-
__u8 reserved[3];
86+
__u8 ishare_xattr_prefix_id;
87+
__u8 reserved[2];
8788
__le32 build_time; /* seconds added to epoch for mkfs time */
8889
__le64 rootnid_8b; /* (48BIT on) nid of root directory */
8990
__le64 reserved2;

fs/erofs/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct erofs_sb_info {
131131
u32 xattr_blkaddr;
132132
u32 xattr_prefix_start;
133133
u8 xattr_prefix_count;
134+
u8 ishare_xattr_prefix_id;
134135
struct erofs_xattr_prefix_item *xattr_prefixes;
135136
unsigned int xattr_filter_reserved;
136137
#endif
@@ -235,6 +236,7 @@ EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
235236
EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER)
236237
EROFS_FEATURE_FUNCS(shared_ea_in_metabox, compat, COMPAT_SHARED_EA_IN_METABOX)
237238
EROFS_FEATURE_FUNCS(plain_xattr_pfx, compat, COMPAT_PLAIN_XATTR_PFX)
239+
EROFS_FEATURE_FUNCS(ishare_xattrs, compat, COMPAT_ISHARE_XATTRS)
238240

239241
static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_t nid)
240242
{

fs/erofs/super.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ static int erofs_read_superblock(struct super_block *sb)
320320
sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start);
321321
sbi->xattr_prefix_count = dsb->xattr_prefix_count;
322322
sbi->xattr_filter_reserved = dsb->xattr_filter_reserved;
323+
if (erofs_sb_has_ishare_xattrs(sbi)) {
324+
if (dsb->ishare_xattr_prefix_id >= sbi->xattr_prefix_count) {
325+
erofs_err(sb, "invalid ishare xattr prefix id %u",
326+
dsb->ishare_xattr_prefix_id);
327+
ret = -EFSCORRUPTED;
328+
goto out;
329+
}
330+
sbi->ishare_xattr_prefix_id = dsb->ishare_xattr_prefix_id;
331+
}
323332
#endif
324333
sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
325334
if (erofs_sb_has_48bit(sbi) && dsb->rootnid_8b) {

fs/erofs/xattr.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,19 @@ int erofs_xattr_prefixes_init(struct super_block *sb)
530530
}
531531

532532
erofs_put_metabuf(&buf);
533+
if (!ret && erofs_sb_has_ishare_xattrs(sbi)) {
534+
struct erofs_xattr_prefix_item *pf = pfs + sbi->ishare_xattr_prefix_id;
535+
struct erofs_xattr_long_prefix *newpfx;
536+
537+
newpfx = krealloc(pf->prefix,
538+
sizeof(*newpfx) + pf->infix_len + 1, GFP_KERNEL);
539+
if (newpfx) {
540+
newpfx->infix[pf->infix_len] = '\0';
541+
pf->prefix = newpfx;
542+
} else {
543+
ret = -ENOMEM;
544+
}
545+
}
533546
sbi->xattr_prefixes = pfs;
534547
if (ret)
535548
erofs_xattr_prefixes_cleanup(sb);

0 commit comments

Comments
 (0)