erofs-utils: mkfs: fix `-Eall-fragments` for multi-threaded compression
authorGao Xiang <hsiangkao@linux.alibaba.com>
Sat, 12 Oct 2024 03:52:13 +0000 (11:52 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Sat, 12 Oct 2024 11:07:38 +0000 (19:07 +0800)
If `-Eall-fragments` is specified when multi-threaded compression is
enabled, it should only apply to the packed inode instead of other
real inodes for now.

Fixes: 10c1590c0920 ("erofs-utils: enable multi-threaded support for `-Eall-fragments`")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20241012035213.3729725-1-hsiangkao@linux.alibaba.com
lib/compress.c

index 5d6fb2a030e25bc530fb6766587c72ecb1718396..cbd46205229cadadaa0d2fe6d513267322fc5fc3 100644 (file)
@@ -1456,12 +1456,8 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
        inode->idata_size = 0;
        inode->fragment_size = 0;
 
-       if (z_erofs_mt_enabled) {
-               ictx = malloc(sizeof(*ictx));
-               if (!ictx)
-                       return ERR_PTR(-ENOMEM);
-               ictx->fd = dup(fd);
-       } else {
+       if (!z_erofs_mt_enabled ||
+           (cfg.c_all_fragments && !erofs_is_packed_inode(inode))) {
 #ifdef EROFS_MT_ENABLED
                pthread_mutex_lock(&g_ictx.mutex);
                if (g_ictx.seg_num)
@@ -1471,6 +1467,11 @@ void *erofs_begin_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
 #endif
                ictx = &g_ictx;
                ictx->fd = fd;
+       } else {
+               ictx = malloc(sizeof(*ictx));
+               if (!ictx)
+                       return ERR_PTR(-ENOMEM);
+               ictx->fd = dup(fd);
        }
 
        ictx->ccfg = &erofs_ccfg[inode->z_algorithmtype[0]];