Skip to contentSkip to conversation

erofs-utils: lib: fix the incorrect nblocks number under chunk mode

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: fix the incorrect nblocks number under chunk mode

Currently, in chunk mode, the number of blocks (nblocks) for the last chunk written to the blocklist file is the size of the chunk, which may not be consistent with the size of the original file in the last chunk. This patch writes the actual number of blocks of the file in the last chunk to the blocklist file.

---
 lib/blobchunk.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/blobchunk.c +7 -2
index 33dadd5..40b731b 100644
@@ -135,6 +135,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
 {
 	struct erofs_inode_chunk_index idx = {0};
 	erofs_blk_t extent_start = EROFS_NULL_ADDR;
+	erofs_blk_t front_blks = 0, tail_blks;
 	erofs_blk_t extent_end, chunkblks;
 	erofs_off_t source_offset;
 	unsigned int dst, src, unit;
@@ -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) {
+				front_blks += extent_end - extent_start;
 				tarerofs_blocklist_write(extent_start,
 						extent_end - extent_start,
 						source_offset);
@@ -187,9 +189,12 @@ 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)
-		tarerofs_blocklist_write(extent_start, extent_end - extent_start,
+	if (extent_start != EROFS_NULL_ADDR) {
+		tail_blks = BLK_ROUND_UP(inode->sbi, inode->i_size)
+			    - front_blks;
+		tarerofs_blocklist_write(extent_start, tail_blks,
 					 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 5 lines · Hongzhen Luo

Currently, in chunk mode, the number of blocks (nblocks) for the last chunk written to the blocklist file is the size of the chunk, which may not be consistent with the size of the original file in the last chunk. This patch writes the actual number of blocks of the file in the last chunk to the blocklist file.

subject:

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.

Quoted 11 lines
---
  lib/blobchunk.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
lib/blobchunk.c +0 -0
index 33dadd5..40b731b 100644

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

Quoted 4 lines
lib/blobchunk.c +1 -0
@@ -135,6 +135,7 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
  {
  	struct erofs_inode_chunk_index idx = {0};
  	erofs_blk_t extent_start = EROFS_NULL_ADDR;
+	erofs_blk_t front_blks = 0, tail_blks;

Personally I think it can be improved as:

	erofs_blk_t remaining_blks = BLK_ROUND_UP(inode->sbi, inode->i_size);

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

Quoted 8 lines
lib/blobchunk.c +1 -0
  	erofs_blk_t extent_end, chunkblks;
  	erofs_off_t source_offset;
  	unsigned int dst, src, unit;
@@ -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) {
+				front_blks += extent_end - extent_start;
				remaining_blks -= extent_end - extent_start;

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

Quoted 7 lines
lib/blobchunk.c +0 -0
  				tarerofs_blocklist_write(extent_start,
  						extent_end - extent_start,
  						source_offset);
@@ -187,9 +189,12 @@ int erofs_blob_write_chunk_indexes(struct erofs_inode *inode,
  			memcpy(inode->chunkindexes + dst, &idx, sizeof(idx));
  	}
  	off = roundup(off, unit);
	extent_end = min(extent_end, extent_start + remaining_blks);

Thanks,
Gao Xiang

Quoted 11 lines
lib/blobchunk.c +5 -2
-	if (extent_start != EROFS_NULL_ADDR)
-		tarerofs_blocklist_write(extent_start, extent_end - extent_start,
+	if (extent_start != EROFS_NULL_ADDR) {
+		tail_blks = BLK_ROUND_UP(inode->sbi, inode->i_size)
+			    - front_blks;
+		tarerofs_blocklist_write(extent_start, tail_blks,
  					 source_offset);
+	}
  	erofs_droid_blocklist_write_extent(inode, extent_start,
  			extent_start == EROFS_NULL_ADDR ?
  					0 : extent_end - extent_start,
#2 lore raw
Quoted 39 lines · Gao Xiang
Quoted 5 lines · Hongzhen Luo

Currently, in chunk mode, the number of blocks (nblocks) for the last chunk written to the blocklist file is the size of the chunk, which may not be consistent with the size of the original file in the last chunk. This patch writes the actual number of blocks of the file in the last chunk to the blocklist file.

subject:

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.

Quoted 11 lines

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

  1 file changed, 7 insertions(+), 2 deletions(-)
lib/blobchunk.c +0 -0
index 33dadd5..40b731b 100644

lib/blobchunk.c int erofs_blob_write_chunk_indexes(struct · line 139

Quoted 5 lines
lib/blobchunk.c +1 -0
@@ -135,6 +135,7 @@ int erofs_blob_write_chunk_indexes(struct 
 erofs_inode *inode,
   {
       struct erofs_inode_chunk_index idx = {0};
       erofs_blk_t extent_start = EROFS_NULL_ADDR;
+    erofs_blk_t front_blks = 0, tail_blks;

Personally I think it can be improved as:

Quoted 2 lines

    erofs_blk_t remaining_blks = BLK_ROUND_UP(inode->sbi, inode->i_size);

Sure, I will send the next patch soon.

Quoted 23 lines
Quoted 9 lines
lib/blobchunk.c +0 -0
       erofs_blk_t extent_end, chunkblks;
       erofs_off_t source_offset;

      unsigned int dst, src, unit;

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) { +                front_blks += extent_end - extent_start;

                remaining_blks -= extent_end - extent_start;

lib/blobchunk.c int erofs_blob_write_chunk_indexes(struct · line 192

Quoted 8 lines

tarerofs_blocklist_write(extent_start, extent_end - extent_start, source_offset);

lib/blobchunk.c +0 -0
@@ -187,9 +189,12 @@ int erofs_blob_write_chunk_indexes(struct 
 erofs_inode *inode,
               memcpy(inode->chunkindexes + dst, &idx, sizeof(idx));
       }
       off = roundup(off, unit);

    extent_end = min(extent_end, extent_start + remaining_blks);

Quoted 3 lines

Thanks,
Gao Xiang

Thanks,

Hongzhen

Quoted 12 lines
Quoted 12 lines
lib/blobchunk.c +5 -2
-    if (extent_start != EROFS_NULL_ADDR)
-        tarerofs_blocklist_write(extent_start, extent_end - 
 extent_start,
+    if (extent_start != EROFS_NULL_ADDR) {
+        tail_blks = BLK_ROUND_UP(inode->sbi, inode->i_size)
+                - front_blks;
+        tarerofs_blocklist_write(extent_start, tail_blks,
                        source_offset);
+    }
       erofs_droid_blocklist_write_extent(inode, extent_start,

              extent_start == EROFS_NULL_ADDR ? 0 : extent_end - extent_start,