erofs-utils: lib: fix incorrect nblocks in block list for chunked inodes
authorHongzhen Luo <hongzhen@linux.alibaba.com>
Wed, 11 Sep 2024 08:55:31 +0000 (16:55 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 11 Sep 2024 11:01:09 +0000 (19:01 +0800)
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.

Fixes: 7b46f7a0160a ("erofs-utils: lib: merge consecutive chunks if possible")
Fixes: b6749839e710 ("erofs-utils: generate preallocated extents for tarerofs")
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240911085531.2133723-1-hongzhen@linux.alibaba.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
lib/blobchunk.c

index 33dadd595172570811b3690be2018e572273f031..6c2ea0e19e1b9f508bf43cedd9e48db9d9f75811 100644 (file)
@@ -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,6 +189,7 @@ 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);
        if (extent_start != EROFS_NULL_ADDR)
                tarerofs_blocklist_write(extent_start, extent_end - extent_start,
                                         source_offset);