[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250708120143.3572-1-liubo03@inspur.com>
Date: Tue, 8 Jul 2025 08:01:43 -0400
From: Bo Liu <liubo03@...pur.com>
To: <xiang@...nel.org>, <chao@...nel.org>
CC: <linux-erofs@...ts.ozlabs.org>, <linux-kernel@...r.kernel.org>, Bo Liu
<liubo03@...pur.com>
Subject: [PATCH] erofs: support metadata compression
Filesystem metadata has a high degree of redundancy, so
should compress well in the general case.
To implement this feature, we make a special on-disk inode
which keeps all metadata as its data, and then compress the
special on-disk inode with the given algorithm.
Signed-off-by: Bo Liu <liubo03@...pur.com>
---
fs/erofs/data.c | 4 +++-
fs/erofs/erofs_fs.h | 2 +-
fs/erofs/internal.h | 7 +++++++
fs/erofs/super.c | 10 ++++++++++
4 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 6a329c329f43..34c82421af4c 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -55,7 +55,9 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb)
buf->file = NULL;
buf->off = sbi->dif0.fsoff;
- if (erofs_is_fileio_mode(sbi)) {
+ if (erofs_is_metadata_comp_mode(sbi))
+ buf->mapping = sbi->meta_inode->i_mapping;
+ else if (erofs_is_fileio_mode(sbi)) {
buf->file = sbi->dif0.file; /* some fs like FUSE needs it */
buf->mapping = buf->file->f_mapping;
} else if (erofs_is_fscache_mode(sb))
diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h
index 767fb4acdc93..bf1ef306ca3c 100644
--- a/fs/erofs/erofs_fs.h
+++ b/fs/erofs/erofs_fs.h
@@ -82,7 +82,7 @@ struct erofs_super_block {
__u8 reserved[3];
__le32 build_time; /* seconds added to epoch for mkfs time */
__le64 rootnid_8b; /* (48BIT on) nid of root directory */
- __u8 reserved2[8];
+ __le64 meta_nid; /* meta data nid */
};
/*
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index a32c03a80c70..a2437e5eada2 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -125,6 +125,7 @@ struct erofs_sb_info {
struct erofs_sb_lz4_info lz4;
#endif /* CONFIG_EROFS_FS_ZIP */
struct inode *packed_inode;
+ struct inode *meta_inode;
struct erofs_dev_context *devs;
u64 total_blocks;
@@ -148,6 +149,7 @@ struct erofs_sb_info {
/* what we really care is nid, rather than ino.. */
erofs_nid_t root_nid;
erofs_nid_t packed_nid;
+ erofs_nid_t meta_nid;
/* used for statfs, f_files - f_favail */
u64 inos;
@@ -190,6 +192,11 @@ static inline bool erofs_is_fscache_mode(struct super_block *sb)
!erofs_is_fileio_mode(EROFS_SB(sb)) && !sb->s_bdev;
}
+static inline bool erofs_is_metadata_comp_mode(struct erofs_sb_info *sbi)
+{
+ return sbi->meta_inode;
+}
+
enum {
EROFS_ZIP_CACHE_DISABLED,
EROFS_ZIP_CACHE_READAHEAD,
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index e1e9f06e8342..9bc40083cd00 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -324,6 +324,7 @@ static int erofs_read_superblock(struct super_block *sb)
sbi->epoch = (s64)le64_to_cpu(dsb->epoch);
sbi->fixed_nsec = le32_to_cpu(dsb->fixed_nsec);
super_set_uuid(sb, (void *)dsb->uuid, sizeof(dsb->uuid));
+ sbi->meta_nid = le64_to_cpu(dsb->meta_nid);
/* parse on-disk compression configurations */
ret = z_erofs_parse_cfgs(sb, dsb);
@@ -691,6 +692,13 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
sbi->packed_inode = inode;
}
+ if (sbi->meta_nid) {
+ inode = erofs_iget(sb, sbi->meta_nid);
+ if (IS_ERR(inode))
+ return PTR_ERR(inode);
+ sbi->meta_inode = inode;
+ }
+
inode = erofs_iget(sb, sbi->root_nid);
if (IS_ERR(inode))
return PTR_ERR(inode);
@@ -845,6 +853,8 @@ static void erofs_drop_internal_inodes(struct erofs_sb_info *sbi)
{
iput(sbi->packed_inode);
sbi->packed_inode = NULL;
+ iput(sbi->meta_inode);
+ sbi->meta_inode = NULL;
#ifdef CONFIG_EROFS_FS_ZIP
iput(sbi->managed_cache);
sbi->managed_cache = NULL;
--
2.31.1
Powered by blists - more mailing lists