Skip to contentSkip to conversation

erofs-utils: lib: only apply `fix_dedupedfrag` to the last segment

PATCH New Gao Xiang 1 participant 4 messages Apr 5, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/4 erofs-utils: lib: only apply `fix_dedupedfrag` to the last segment

Only the segment containing the fragment needs to be fixed.

Fixes b8cc6a36b560 ("erofs-utils: mkfs: implement multi-threaded fragments")
---
 lib/compress.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/compress.c +2 -1
index 5ecb9c8..4b966d8 100644
@@ -729,6 +729,7 @@ fix_dedupedfrag:
 static int z_erofs_compress_one(struct z_erofs_compress_sctx *ctx)
 {
 	struct z_erofs_compress_ictx *ictx = ctx->ictx;
+	bool tsg = ctx->seg_idx + 1 >= ictx->seg_num;
 	struct z_erofs_extent_item *ei;
 
 	while (ctx->tail > ctx->head) {
@@ -753,7 +754,7 @@ static int z_erofs_compress_one(struct z_erofs_compress_sctx *ctx)
 		}
 
 		ctx->pivot = ei;
-		if (ictx->fix_dedupedfrag && !ictx->fragemitted &&
+		if (tsg && ictx->fix_dedupedfrag && !ictx->fragemitted &&
 		    z_erofs_fixup_deduped_fragment(ctx))
 			break;
 
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/4 erofs-utils: lib: drop unused `ret` assignment

Coverity-id: 548921

---
 lib/compress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/compress.c +1 -1
index 4b966d8..bff0e0b 100644
@@ -1202,7 +1202,7 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 	}
 
 	if (ptotal) {
-		ret = erofs_bh_balloon(bh, ptotal);
+		(void)erofs_bh_balloon(bh, ptotal);
 	} else {
 		if (!cfg.c_fragments && !cfg.c_dedupe)
 			DBG_BUGON(!inode->idata_size);
Signature · 1 line
2.43.5
author
#2 lore raw

PATCH 3/4 erofs-utils: lib: fix an API usage error

In reply to Gao Xiang

Coverity-id: 548920

---
 lib/compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/compress.c +2 -2
index bff0e0b..a7d5e53 100644
@@ -1208,8 +1208,8 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 			DBG_BUGON(!inode->idata_size);
 	}
 
-	erofs_info("compressed %s (%llu bytes) into %u bytes",
-		   inode->i_srcpath, inode->i_size | 0ULL, ptotal);
+	erofs_info("compressed %s (%llu bytes) into %llu bytes",
+		   inode->i_srcpath, inode->i_size | 0ULL, ptotal | 0ULL);
 
 	if (inode->idata_size) {
 		bh->op = &erofs_skip_write_bhops;
Signature · 1 line
2.43.5
author
#3 lore raw

PATCH 4/4 erofs-utils: lib: fix two integer handling issues

In reply to Gao Xiang

Coverity-id: 548918
Coverity-id: 548919

---
 lib/compress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/compress.c +2 -2
index a7d5e53..9f71022 100644
@@ -1169,7 +1169,7 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 
 	/* fall back to no compression mode */
 	DBG_BUGON(pstart < (!!inode->idata_size) << bbits);
-	ptotal -= (!!inode->idata_size) << bbits;
+	ptotal -= (u64)(!!inode->idata_size) << bbits;
 
 	compressmeta = z_erofs_write_indexes(ictx);
 	if (!compressmeta) {
@@ -1687,7 +1687,7 @@ int erofs_write_compressed_file(struct z_erofs_compress_ictx *ictx)
 		ret = PTR_ERR(bh);
 		goto err_free_idata;
 	}
-	pstart = erofs_mapbh(NULL, bh->block) << sbi->blkszbits;
+	pstart = erofs_pos(sbi, erofs_mapbh(NULL, bh->block));
 
 	ictx->seg_num = 1;
 	sctx = (struct z_erofs_compress_sctx) {
Signature · 1 line
2.43.5