erofs-utils: fix multi-threaded compression in tarerofs mode
PATCH 1/1 erofs-utils: fix multi-threaded compression in tarerofs mode
Since pread() can be used during multi-threaded compression, it's necessary to pass fpos in to indicate the absolute offset.
Fixes aec8487dce4c ("erofs-utils: mkfs: introduce inner-file multi-threaded compression")
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/compress.h | 2 +- lib/compress.c | 14 +++++++++----- lib/inode.c | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-)
include/erofs/compress.h +1 -1
@@ -18,7 +18,7 @@ extern "C"#define Z_EROFS_COMPR_QUEUE_SZ (EROFS_CONFIG_COMPR_MAX_SZ * 2)void z_erofs_drop_inline_pcluster (struct erofs_inode *inode); -int erofs_write_compressed_file (struct erofs_inode *inode,int fd); +int erofs_write_compressed_file (struct erofs_inode *inode,int fd,u64 fpos);int z_erofs_compress_init (struct erofs_sb_info *sbi,struct erofs_buffer_head *bh);
lib/compress.c +9 -5
@@ -38,8 +38,9 @@ struct z_erofs_extent_item {struct z_erofs_compress_ictx {/* inode context */ struct erofs_inode *inode; -int fd;unsigned int pclustersize; +int fd; +u64 fpos;u32 tof_chksum;bool fix_dedupedfrag;
@@ -990,7 +991,8 @@ void z_erofs_drop_inline_pcluster(struct erofs_inode *inode)int z_erofs_compress_segment (struct z_erofs_compress_sctx *ctx,u64 offset,erofs_blk_t blkaddr) { -int fd = ctx->ictx->fd; +struct z_erofs_compress_ictx *ictx = ctx->ictx; +int fd = ictx->fd; ctx->blkaddr = blkaddr;while (ctx->remaining) {
@@ -1000,7 +1002,8 @@ int z_erofs_compress_segment(struct z_erofs_compress_sctx *ctx, ret = (offset ==-1 ?read (fd, ctx->queue + ctx->tail, rx) : -pread (fd, ctx->queue + ctx->tail, rx, offset)); +pread (fd, ctx->queue + ctx->tail, rx, + ictx->fpos + offset));if (ret != rx)return -errno;
@@ -1238,7 +1241,7 @@ int z_erofs_mt_compress(struct z_erofs_compress_ictx *ictx, }#endif -int erofs_write_compressed_file (struct erofs_inode *inode,int fd) +int erofs_write_compressed_file (struct erofs_inode *inode,int fd,u64 fpos) {static u8 g_queue[Z_EROFS_COMPR_QUEUE_SZ ];struct erofs_buffer_head *bh;
@@ -1313,9 +1316,10 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd) blkaddr =erofs_mapbh (bh->block);/* start_blkaddr */ ctx.inode = inode; ctx.pclustersize =z_erofs_get_max_pclustersize (inode); + ctx.fd = fd; + ctx.fpos = fpos; ctx.metacur = compressmeta +Z_EROFS_LEGACY_MAP_HEADER_SIZE ;init_list_head (&ctx.extents); - ctx.fd = fd; ctx.fix_dedupedfrag = false; ctx.fragemitted = false; sctx = (struct z_erofs_compress_sctx ) { .ictx = &ctx, };
lib/inode.c +2 -2
@@ -493,7 +493,7 @@ int erofs_write_file(struct erofs_inode *inode, int fd, u64 fpos) }if (cfg.c_compr_opts[0 ].alg &&erofs_file_is_compressible (inode)) { - ret =erofs_write_compressed_file (inode, fd); + ret =erofs_write_compressed_file (inode, fd, fpos);if (!ret || ret != -ENOSPC )return ret;
@@ -1340,7 +1340,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(int fd, const char *name) inode->nid = inode->sbi->packed_nid; } - ret =erofs_write_compressed_file (inode, fd); + ret =erofs_write_compressed_file (inode, fd,0 );if (ret == -ENOSPC ) { ret =lseek (fd,0 ,SEEK_SET );if (ret <0 )
Signature · 1 line
2.39.3