Skip to contentSkip to conversation

erofs-utils: lib: fix incorrect nblocks in block list for chunked inodes

PATCH Superseded Hongzhen Luo 2 participants 3 messages Sep 11, 2024 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 erofs-utils: lib: fix incorrect nblocks in block list for chunked inodes

Currently, the number of physical blocks (nblocks) for the last chunk written to the block list file is incorrectly recorded as the inode chunksize.

This patch writes the actual number of physical blocks for the inode in the last chunk to the block list file.

---
 lib/blobchunk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
lib/blobchunk.c +5 -1
index 33dadd5..a0f3d0e 100644
@@ -133,6 +133,7 @@ static int erofs_blob_hashmap_cmp(const void *a, const void *b,
 int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
 				   erofs_off_t off)
 {
+	erofs_blk_t remaining_blks = BLK_ROUND_UP(inode->sbi, inode->i_size);
 	struct erofs_inode_chunk_index idx = {0};
 	erofs_blk_t extent_start = EROFS_NULL_ADDR;
 	erofs_blk_t extent_end, chunkblks;
@@ -165,6 +166,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
 		if (extent_start == EROFS_NULL_ADDR ||
 		    idx.blkaddr != extent_end) {
 			if (extent_start != EROFS_NULL_ADDR) {
+				remaining_blks -= extent_end - extent_start;
 				tarerofs_blocklist_write(extent_start,
 						extent_end - extent_start,
 						source_offset);
@@ -187,9 +189,11 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
 			memcpy(inode->chunkindexes + dst, &idx, sizeof(idx));
 	}
 	off = roundup(off, unit);
-	if (extent_start != EROFS_NULL_ADDR)
+	if (extent_start != EROFS_NULL_ADDR) {
+		extent_end = min(extent_end, extent_start + remaining_blks);
 		tarerofs_blocklist_write(extent_start, extent_end - extent_start,
 					 source_offset);
+	}
 	erofs_droid_blocklist_write_extent(inode, extent_start,
 			extent_start == EROFS_NULL_ADDR ?
 					0 : extent_end - extent_start,
Signature · 1 line
2.43.5
#1 lore raw
Quoted 8 lines · Hongzhen Luo

Currently, the number of physical blocks (nblocks) for the last chunk written to the block list file is incorrectly recorded as the inode chunksize.

This patch writes the actual number of physical blocks for the inode in the last chunk to the block list file.

I guess it fixes

Fixes 7b46f7a0160a ("erofs-utils: lib: merge consecutive chunks if possible")
Fixes b6749839e710 ("erofs-utils: generate preallocated extents for tarerofs")

?

Quoted 24 lines
---
  lib/blobchunk.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
lib/blobchunk.c +2 -0
index 33dadd5..a0f3d0e 100644
@@ -133,6 +133,7 @@ static int erofs_blob_hashmap_cmp(const void *a, const void *b,
  int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
  				   erofs_off_t off)
  {
+	erofs_blk_t remaining_blks = BLK_ROUND_UP(inode->sbi, inode->i_size);
  	struct erofs_inode_chunk_index idx = {0};>   	erofs_blk_t extent_start = EROFS_NULL_ADDR;
  	erofs_blk_t extent_end, chunkblks;
@@ -165,6 +166,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
  		if (extent_start == EROFS_NULL_ADDR ||
  		    idx.blkaddr != extent_end) {
  			if (extent_start != EROFS_NULL_ADDR) {
+				remaining_blks -= extent_end - extent_start;
  				tarerofs_blocklist_write(extent_start,
  						extent_end - extent_start,
  						source_offset);

lib/blobchunk.c int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, · line 192

Quoted 5 lines
lib/blobchunk.c +1 -1
@@ -187,9 +189,11 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
  			memcpy(inode->chunkindexes + dst, &idx, sizeof(idx));
  	}
  	off = roundup(off, unit);
-	if (extent_start != EROFS_NULL_ADDR)
+	if (extent_start != EROFS_NULL_ADDR) {

You should move extent_end out of this block since erofs_droid_blocklist_write_extent() is impacted too.

Thanks,
Gao Xiang

#2 lore raw
Quoted 10 lines · Gao Xiang
Quoted 7 lines · Hongzhen Luo

Currently, the number of physical blocks (nblocks) for the last chunk written to the block list file is incorrectly recorded as the inode chunksize.

This patch writes the actual number of physical blocks for the inode in the last chunk to the block list file.

Quoted 9 lines
Quoted 1 line

I guess it fixes

Fixes 7b46f7a0160a ("erofs-utils: lib: merge consecutive chunks if possible")
Fixes b6749839e710 ("erofs-utils: generate preallocated extents for tarerofs")

?

Yes.

Quoted 29 lines
Quoted 29 lines

---
  lib/blobchunk.c | 6 +++++-

  1 file changed, 5 insertions(+), 1 deletion(-)
lib/blobchunk.c +1 -0
index 33dadd5..a0f3d0e 100644
@@ -133,6 +133,7 @@ static int erofs_blob_hashmap_cmp(const void *a, 
 const void *b,
   int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
                      erofs_off_t off)
   {
+    erofs_blk_t remaining_blks = BLK_ROUND_UP(inode->sbi, 
 inode->i_size);
       struct erofs_inode_chunk_index idx = {0};> erofs_blk_t extent_start = EROFS_NULL_ADDR;

      erofs_blk_t extent_end, chunkblks;

lib/blobchunk.c +0 -0
@@ -165,6 +166,7 @@ int erofs_blob_write_chunk_indexes(struct 
 erofs_inode *inode,

          if (extent_start == EROFS_NULL_ADDR || idx.blkaddr != extent_end) {
              if (extent_start != EROFS_NULL_ADDR) { +                remaining_blks -= extent_end - extent_start; tarerofs_blocklist_write(extent_start, extent_end - extent_start, source_offset);

lib/blobchunk.c +0 -0
@@ -187,9 +189,11 @@ int erofs_blob_write_chunk_indexes(struct 
 erofs_inode *inode,
Quoted 8 lines

lib/blobchunk.c int erofs_blob_write_chunk_indexes(struct erofs_inode *inode, · line 192

Quoted 5 lines
lib/blobchunk.c +1 -1
               memcpy(inode->chunkindexes + dst, &idx, sizeof(idx));
       }
       off = roundup(off, unit);
-    if (extent_start != EROFS_NULL_ADDR)
+    if (extent_start != EROFS_NULL_ADDR) {

You should move extent_end out of this block since erofs_droid_blocklist_write_extent() is impacted too.

Sure, i will fix this in the next patch.

Thanks,

Hongzhen

Quoted 3 lines

Thanks,
Gao Xiang