Skip to contentSkip to conversation

erofs-utils: mkfs: don't generate encoded extents for ztailpacking

PATCH New Gao Xiang 1 participant 3 messages Jul 16, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/3 erofs-utils: mkfs: don't generate encoded extents for ztailpacking

.. Need more library work for ztailpacking.

Fixes f978245e9da8 ("erofs-utils: support encoded extents")
---
 lib/compress.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/compress.c +4 -1
index a57bb6a3..22fb5d6d 100644
@@ -1142,7 +1142,8 @@ static void *z_erofs_write_indexes(struct z_erofs_compress_ictx *ctx)
 	struct z_erofs_extent_item *ei, *n;
 	void *metabuf;
 
-	if (erofs_sb_has_48bit(sbi)) {
+	/* TODO: support writing encoded extents for ztailpacking later. */
+	if (erofs_sb_has_48bit(sbi) && !inode->idata_size) {
 		metabuf = z_erofs_write_extents(ctx);
 		if (metabuf != ERR_PTR(-EAGAIN)) {
 			if (IS_ERR(metabuf))
@@ -1181,6 +1182,8 @@ static void *z_erofs_write_indexes(struct z_erofs_compress_ictx *ctx)
 	ctx->metacur = metabuf + Z_EROFS_LEGACY_MAP_HEADER_SIZE;
 	ctx->clusterofs = 0;
 	list_for_each_entry_safe(ei, n, &ctx->extents, list) {
+		DBG_BUGON(ei->list.next != &ctx->extents &&
+			  ctx->clusterofs + ei->e.length < erofs_blksiz(sbi));
 		z_erofs_write_full_indexes(ctx, &ei->e);
 
 		list_del(&ei->list);
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/3 erofs-utils: lib: consolidate erofs_iflush()

.. Avoid erofs_dev_write() and use the bdev virtual file instead.

---
 include/erofs/internal.h |  3 +-
 lib/blobchunk.c          |  6 ++--
 lib/inode.c              | 67 +++++++++++++++++++---------------------
 lib/super.c              |  1 -
 4 files changed, 35 insertions(+), 42 deletions(-)
include/erofs/internal.h +1 -2
index b5df8a48..65d40840 100644
@@ -95,7 +95,6 @@ struct erofs_sb_info {
 	u32 feature_compat;
 	u32 feature_incompat;
 
-	unsigned char islotbits;
 	unsigned char blkszbits;
 
 	u32 sb_size;			/* total superblock size */
@@ -293,7 +292,7 @@ static inline erofs_off_t erofs_iloc(struct erofs_inode *inode)
 	struct erofs_sb_info *sbi = inode->sbi;
 
 	return erofs_pos(sbi, sbi->meta_blkaddr) +
-			(inode->nid << sbi->islotbits);
+			(inode->nid << EROFS_ISLOTBITS);
 }
 
 static inline bool is_inode_layout_compression(struct erofs_inode *inode)
lib/blobchunk.c +3 -3
index 3388ce0d..bbc69cfb 100644
@@ -193,7 +193,6 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
 		else
 			memcpy(inode->chunkindexes + dst, &idx, sizeof(idx));
 	}
-	off = roundup(off, unit);
 	if (extent_start != EROFS_NULL_ADDR) {
 		extent_end = min(extent_end, extent_start + remaining_blks);
 		zeroedlen = inode->i_size & (erofs_blksiz(sbi) - 1);
@@ -202,8 +201,9 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
 		tarerofs_blocklist_write(extent_start, extent_end - extent_start,
 					 source_offset, zeroedlen);
 	}
-	return erofs_dev_write(inode->sbi, inode->chunkindexes, off,
-			       inode->extent_isize);
+	off = roundup(off, unit);
+	return erofs_io_pwrite(&sbi->bdev, inode->chunkindexes,
+			       off, inode->extent_isize);
 }
 
 int erofs_blob_mergechunks(struct erofs_inode *inode, unsigned int chunkbits,
lib/inode.c +31 -36

109 lines not on this page · raw message

lib/super.c +0 -1
index 0533a7c8..e5364d27 100644
@@ -114,7 +114,6 @@ int erofs_read_superblock(struct erofs_sb_info *sbi)
 	sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
 	sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start);
 	sbi->xattr_prefix_count = dsb->xattr_prefix_count;
-	sbi->islotbits = EROFS_ISLOTBITS;
 	if (erofs_sb_has_48bit(sbi) && dsb->rootnid_8b) {
 		sbi->root_nid = le64_to_cpu(dsb->rootnid_8b);
 		sbi->primarydevice_blocks = (sbi->primarydevice_blocks << 32) |
Signature · 1 line
2.43.5
author
#2 lore raw

PATCH 3/3 erofs-utils: use virtual file interface for the buffer manager

In reply to Gao Xiang

In order to prepare for the upcoming metadata compression.

---
 include/erofs/cache.h    |  9 +++++----
 include/erofs/internal.h |  6 ------
 include/erofs/io.h       |  2 +-
 lib/cache.c              | 12 +++++++++---
 lib/io.c                 |  6 +++---
 mkfs/main.c              |  4 ++--
 6 files changed, 20 insertions(+), 19 deletions(-)
include/erofs/cache.h +5 -4
index 0c665e8f..d5618c00 100644
@@ -57,18 +57,18 @@ struct erofs_buffer_block {
 };
 
 struct erofs_bufmgr {
-	struct erofs_sb_info *sbi;
-
 	/* buckets for all buffer blocks to boost up allocation */
 	struct list_head watermeter[META + 1][2][EROFS_MAX_BLOCK_SIZE];
 	unsigned long bktmap[META + 1][2][EROFS_MAX_BLOCK_SIZE / BITS_PER_LONG];
 
 	struct erofs_buffer_block blkh;
-	erofs_blk_t tail_blkaddr, metablkcnt;
+	struct erofs_sb_info *sbi;
+	struct erofs_vfile *vf;
 
 	/* last mapped buffer block to accelerate erofs_mapbh() */
 	struct erofs_buffer_block *last_mapped_block;
 
+	erofs_blk_t tail_blkaddr, metablkcnt;
 	/* align data block addresses to multiples of `dsunit` */
 	unsigned int dsunit;
 };
@@ -122,7 +122,8 @@ static inline int erofs_bh_flush_generic_end(struct erofs_buffer_head *bh)
 }
 
 struct erofs_bufmgr *erofs_buffer_init(struct erofs_sb_info *sbi,
-				       erofs_blk_t startblk);
+				       erofs_blk_t startblk,
+				       struct erofs_vfile *vf);
 int erofs_bh_balloon(struct erofs_buffer_head *bh, erofs_off_t incr);
 
 struct erofs_buffer_head *erofs_balloc(struct erofs_bufmgr *bmgr,
include/erofs/internal.h +0 -6
index 65d40840..1431c16d 100644
@@ -487,12 +487,6 @@ static inline int erofs_dev_write(struct erofs_sb_info *sbi, const void *buf,
 	return 0;
 }
 
-static inline int erofs_dev_fillzero(struct erofs_sb_info *sbi, u64 offset,
-				     size_t len, bool pad)
-{
-	return erofs_io_fallocate(&sbi->bdev, offset, len, pad);
-}
-
 static inline int erofs_dev_resize(struct erofs_sb_info *sbi,
 				   erofs_blk_t blocks)
 {
include/erofs/io.h +1 -1
index 101a5ba4..14d6e45f 100644
@@ -59,7 +59,7 @@ ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void *buf, u64 pos, size_t
 ssize_t erofs_io_pwritev(struct erofs_vfile *vf, const struct iovec *iov,
 			 int iovcnt, u64 pos);
 int erofs_io_fsync(struct erofs_vfile *vf);
-ssize_t erofs_io_fallocate(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
+int erofs_io_fallocate(struct erofs_vfile *vf, u64 offset, size_t len, bool pad);
 int erofs_io_ftruncate(struct erofs_vfile *vf, u64 length);
 ssize_t erofs_io_pread(struct erofs_vfile *vf, void *buf, u64 offset, size_t len);
 ssize_t erofs_io_read(struct erofs_vfile *vf, void *buf, size_t len);
lib/cache.c +9 -3
index b3cf1c48..079465ed 100644
@@ -29,7 +29,8 @@ const struct erofs_bhops erofs_skip_write_bhops = {
 };
 
 struct erofs_bufmgr *erofs_buffer_init(struct erofs_sb_info *sbi,
-				       erofs_blk_t startblk)
+				       erofs_blk_t startblk,
+				       struct erofs_vfile *vf)
 {
 	unsigned int blksiz = erofs_blksiz(sbi);
 	struct erofs_bufmgr *bmgr;
@@ -54,6 +55,7 @@ struct erofs_bufmgr *erofs_buffer_init(struct erofs_sb_info *sbi,
 	bmgr->last_mapped_block = &bmgr->blkh;
 	bmgr->metablkcnt = 0;
 	bmgr->dsunit = 0;
+	bmgr->vf = vf ?: &sbi->bdev;
 	return bmgr;
 }
 
@@ -482,9 +484,13 @@ int erofs_bflush(struct erofs_bufmgr *bmgr,
 			continue;
 
 		padding = blksiz - (p->buffers.off & (blksiz - 1));
-		if (padding != blksiz)
-			erofs_dev_fillzero(sbi, erofs_pos(sbi, blkaddr) - padding,
+		if (padding != blksiz) {
+			ret = erofs_io_fallocate(bmgr->vf,
+					   erofs_pos(sbi, blkaddr) - padding,
 					   padding, true);
+			if (ret < 0)
+				return ret;
+		}
 
 		if (p->type != DATA)
 			bmgr->metablkcnt += p->buffers.nblocks;
lib/io.c +3 -3
index aa043cae..983d9bf9 100644
@@ -147,8 +147,8 @@ int erofs_io_fsync(struct erofs_vfile *vf)
 	return 0;
 }
 
-ssize_t erofs_io_fallocate(struct erofs_vfile *vf, u64 offset,
-			   size_t len, bool zeroout)
+int erofs_io_fallocate(struct erofs_vfile *vf, u64 offset,
+		       size_t len, bool zeroout)
 {
 	static const char zero[EROFS_MAX_BLOCK_SIZE] = {0};
 	ssize_t ret;
@@ -167,7 +167,7 @@ ssize_t erofs_io_fallocate(struct erofs_vfile *vf, u64 offset,
 	while (len > EROFS_MAX_BLOCK_SIZE) {
 		ret = erofs_io_pwrite(vf, zero, offset, EROFS_MAX_BLOCK_SIZE);
 		if (ret < 0)
-			return ret;
+			return (int)ret;
 		len -= ret;
 		offset += ret;
 	}
mkfs/main.c +2 -2
index fce26336..30804d10 100644
@@ -1377,7 +1377,7 @@ int main(int argc, char **argv)
 	}
 
 	if (!incremental_mode) {
-		g_sbi.bmgr = erofs_buffer_init(&g_sbi, 0);
+		g_sbi.bmgr = erofs_buffer_init(&g_sbi, 0, NULL);
 		if (!g_sbi.bmgr) {
 			err = -ENOMEM;
 			goto exit;
@@ -1405,7 +1405,7 @@ int main(int argc, char **argv)
 			u.startblk = DIV_ROUND_UP(u.st.st_size, erofs_blksiz(&g_sbi));
 		else
 			u.startblk = g_sbi.primarydevice_blocks;
-		g_sbi.bmgr = erofs_buffer_init(&g_sbi, u.startblk);
+		g_sbi.bmgr = erofs_buffer_init(&g_sbi, u.startblk, NULL);
 		if (!g_sbi.bmgr) {
 			err = -ENOMEM;
 			goto exit;
Signature · 1 line
2.43.5