Skip to contentSkip to conversation

erofs-utils: lib: drop the cached block when the metabuf source changes

PATCH New Zhan Xusheng 1 participant 2 messages Nov 13 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 erofs-utils: lib: drop the cached block when the metabuf source changes

From: Zhan Xusheng <[email protected]>

erofs_bread() reuses buf->base when the block number matches buf->blocknr, but erofs_init_metabuf() can switch buf->vf between the metabox and the device without resetting it. The xattr code reads the inline xattrs through the metabox and then the shared xattrs through the device on the same buffer. If both are at the same block number, the shared entries are looked up in the metabox block and not found.

With 40 files that each have one inline and one shared xattr:

  mkfs.erofs -m4096 t.img src
  fsck.erofs --extract=out --xattrs t.img

35 of the extracted files have no shared xattr. Without -m all 40 are correct. erofsfuse and mkfs.erofs rebuild mode use the same path; a rebuild of the image above (built with --chunksize=4096) drops the shared xattr from the same 35 files.

Reset blocknr when the source changes.

Fixes c6903c7e32a1 ("erofs-utils: dump,fsck,fuse: support metadata compression")
---
 lib/data.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/data.c +6 -1
index 91809d0..9b5d00f 100644
@@ -70,8 +70,13 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
 void erofs_init_metabuf(struct erofs_buf *buf, struct erofs_sb_info *sbi,
 			bool in_mbox)
 {
+	struct erofs_vfile *vf = in_mbox ? NULL : &sbi->bdev;
+
+	/* the cached block belongs to the previous file */
+	if (buf->vf != vf)
+		buf->blocknr = ~0ULL;
 	buf->sbi = sbi;
-	buf->vf = in_mbox ? NULL : &sbi->bdev;
+	buf->vf = vf;
 }
 
 void *erofs_read_metabuf(struct erofs_buf *buf, struct erofs_sb_info *sbi,

base-commit: b9dd73fb478ac88fc142e6430ed71be43dc65cab

Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 erofs-utils: lib: fix metabox inline reads of compressed files

From: Zhan Xusheng <[email protected]>

For an inode in the metabox, a tail-packed pcluster is in the metabox and m_pa is an offset into it. "erofs-utils: lib: fix metabox inline data reads" handles that in erofs_read_one_data(), but z_erofs_read_one_data() still reads m_pa from the device:

  mkfs.erofs -m4096 -zlz4 -Eztailpacking t.img src
  fsck.erofs --extract=out t.img

fsck.erofs fails with "Failed to extract filesystem", and files whose last pcluster is tail-packed are extracted with wrong contents.

Read such pclusters through the metabox as well.

Fixes c6903c7e32a1 ("erofs-utils: dump,fsck,fuse: support metadata compression")

---
Complements b9dd73f, which fixes the uncompressed path.

 lib/data.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
lib/data.c +14 -0
index 9b5d00f..8de7162 100644
@@ -315,6 +315,19 @@ int z_erofs_read_one_data(struct erofs_inode *inode,
 				   inode->fragmentoff + skip);
 	}
 
+	if ((map->m_flags & EROFS_MAP_META) &&
+	    erofs_inode_in_metabox(inode)) {
+		struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
+		void *src;
+
+		src = erofs_read_metabuf(&buf, sbi, map->m_pa, true);
+		if (IS_ERR(src))
+			return PTR_ERR(src);
+		memcpy(raw, src, map->m_plen);
+		erofs_put_metabuf(&buf);
+		goto decompress;
+	}
+
 	/* no device id here, thus it will always succeed */
 	mdev = (struct erofs_map_dev) {
 		.m_pa = map->m_pa,
@@ -329,6 +342,7 @@ int z_erofs_read_one_data(struct erofs_inode *inode,
 	if (ret < 0)
 		return ret;
 
+decompress:
 	ret = z_erofs_decompress(&(struct z_erofs_decompress_req) {
 			.sbi = sbi,
 			.in = raw,
Signature · 1 line
2.43.0