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

Gao Xiang hsiangkao at linux.alibaba.com
Wed Sep 11 18:20:30 AEST 2024



On 2024/9/11 16:10, Hongzhen Luo wrote:
> 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.

> 
> Signed-off-by: Hongzhen Luo <hongzhen at linux.alibaba.com>
> ---
>   lib/blobchunk.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/blobchunk.c b/lib/blobchunk.c
> index 33dadd5..40b731b 100644
> --- a/lib/blobchunk.c
> +++ b/lib/blobchunk.c
> @@ -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);

>   	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;

>   				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

> -	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,



More information about the Linux-erofs mailing list