Skip to contentSkip to conversation

erofs-utils: lib: don't abort on compression fallback

PATCH In review Yifan Zhao 2 participants 4 messages Jun 23 Library code

lore
Share & tools
lore

Yifan Zhao

author
#0 lore raw

PATCH v2 1/2 erofs-utils: lib: don't abort on compression fallback

File-level compression fallback is control flow, not a real error. Return an erofs-specific status code for it instead of overloading -ENOSPC, which can also report real space failures.

Keep the global compression context reusable for that fallback while preserving the fatal state for real errors.

Fixes a729584ef975 ("erofs-utils: mkfs: avoid hanging if fragment is on and tmpdir is full")
Assisted-by Codex:GPT-5.5
---
 include/erofs/err.h |  1 +
 lib/compress.c      | 10 +++++++---
 lib/inode.c         |  6 +++---
 3 files changed, 11 insertions(+), 6 deletions(-)
include/erofs/err.h +1 -0
index 7dacc91..ef882c9 100644
@@ -29,6 +29,7 @@ static inline const char *erofs_strerror(int err)
 }
 
 #define MAX_ERRNO (4095)
+#define EROFS_ERRNO_COMPR_FALLBACK	(MAX_ERRNO + 1)
 #define IS_ERR_VALUE(x)                                                        \
 	((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
 
lib/compress.c +7 -3
index ea07409..edc29ed 100644
@@ -1375,7 +1375,7 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 	    legacymetasize >= inode->i_size) {
 		z_erofs_dedupe_ext_commit(true);
 		z_erofs_dedupe_commit(true);
-		ret = -ENOSPC;
+		ret = -EROFS_ERRNO_COMPR_FALLBACK;
 		goto err_free_meta;
 	}
 	z_erofs_dedupe_ext_commit(false);
@@ -2031,7 +2031,11 @@ err_free_idata:
 out:
 #ifdef EROFS_MT_ENABLED
 	pthread_mutex_lock(&ictx->mutex);
-	ictx->seg_num = ret < 0 ? INT_MAX : 0;
+	if (ret < 0 && ret != -EROFS_ERRNO_COMPR_FALLBACK)
+		/* mark as failed to avoid further processing */
+		ictx->seg_num = INT_MAX;
+	else
+		ictx->seg_num = 0;
 	pthread_cond_signal(&ictx->cond);
 	pthread_mutex_unlock(&ictx->mutex);
 #endif
@@ -2044,7 +2048,7 @@ int erofs_begin_compress_dir(struct erofs_importer *im,
 {
 	if (!im->params->compress_dir ||
 	    inode->i_size < Z_EROFS_LEGACY_MAP_HEADER_SIZE)
-		return -ENOSPC;
+		return -EROFS_ERRNO_COMPR_FALLBACK;
 
 	inode->z_advise |= Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
 	erofs_sb_set_fragments(inode->sbi);
lib/inode.c +3 -3
index c225faa..9f3d7e6 100644
@@ -1507,7 +1507,7 @@ static int erofs_mkfs_job_write_file(struct erofs_mkfs_job_ndir_ctx *ctx)
 
 	if (ctx->ictx) {
 		ret = erofs_write_compressed_file(ctx->ictx);
-		if (ret != -ENOSPC)
+		if (ret != -EROFS_ERRNO_COMPR_FALLBACK)
 			goto out;
 		if (lseek(ctx->fd, ctx->fpos, SEEK_SET) < 0) {
 			ret = -errno;
@@ -1594,7 +1594,7 @@ static int erofs_mkfs_create_directory(const struct erofs_mkfs_btctx *ctx,
 		inode->datalayout = EROFS_INODE_FLAT_INLINE;
 
 		ret = erofs_begin_compress_dir(ctx->im, inode);
-		if (ret && ret != -ENOSPC)
+		if (ret && ret != -EROFS_ERRNO_COMPR_FALLBACK)
 			return ret;
 	} else {
 		DBG_BUGON(inode->datalayout != EROFS_INODE_FLAT_PLAIN);
@@ -2391,7 +2391,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_importer *im,
 		ret = erofs_write_compressed_file(ictx);
 		if (!ret)
 			goto out;
-		if (ret != -ENOSPC)
+		if (ret != -EROFS_ERRNO_COMPR_FALLBACK)
 			 return ERR_PTR(ret);
 
 		ret = lseek(fd, 0, SEEK_SET);
Signature · 1 line
2.47.3
author
#1 lore raw

PATCH v2 2/2 erofs-utils: lib: honor rebuild whiteouts for recreated dirs

When rebuilding from upper to lower, a whiteout below an already recreated directory should keep that directory but stop older lower entries from being merged into it.

Only treat the lower whiteout as an opaque marker when the upper entry is a directory. If the upper entry is not a directory, keep the normal upper-exists behavior and ignore the lower entry.

---
 lib/rebuild.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/rebuild.c +7 -1
index 51dfe18..108a464 100644
@@ -401,7 +401,13 @@ static int erofs_rebuild_dirent_iter(struct erofs_dir_context *ctx)
 			.nid = ctx->de_nid
 		};
 		ret = erofs_read_inode_from_disk(&src);
-		if (ret || !S_ISDIR(src.i_mode))
+		if (ret)
+			goto out;
+		if (erofs_inode_is_whiteout(&src)) {
+			d->inode->opaque = true;
+			goto out;
+		}
+		if (!S_ISDIR(src.i_mode))
 			goto out;
 		mergedir = d->inode;
 		inode = dir = &src;
Signature · 1 line
2.47.3
#2 lore raw
In reply to Yifan Zhao
Quoted 23 lines · Yifan Zhao

File-level compression fallback is control flow, not a real error. Return an erofs-specific status code for it instead of overloading -ENOSPC, which can also report real space failures.

Keep the global compression context reusable for that fallback while preserving the fatal state for real errors.

Fixes a729584ef975 ("erofs-utils: mkfs: avoid hanging if fragment is on and tmpdir is full")
Assisted-by Codex:GPT-5.5
---
  include/erofs/err.h |  1 +
  lib/compress.c      | 10 +++++++---
  lib/inode.c         |  6 +++---
  3 files changed, 11 insertions(+), 6 deletions(-)
include/erofs/err.h +0 -0
index 7dacc91..ef882c9 100644

include/erofs/err.h static inline const char *erofs_strerror(int err) · line 32

Quoted 4 lines
include/erofs/err.h +1 -0
@@ -29,6 +29,7 @@ static inline const char *erofs_strerror(int err)
  }
 
  #define MAX_ERRNO (4095)
+#define EROFS_ERRNO_COMPR_FALLBACK	(MAX_ERRNO + 1)

hmmm, the naming is not quite good, I will think out a new name and manually change it.

#3 lore raw

PATCH v3 1/2 erofs-utils: lib: don't abort on compression fallback

In reply to Yifan Zhao

From: Yifan Zhao <[email protected]>

File-level compression fallback is control flow, not a real error. Return an erofs-specific status code for it instead of overloading -ENOSPC, which can also report real space failures.

Keep the global compression context reusable for that fallback while preserving the fatal state for real errors.

Fixes a729584ef975 ("erofs-utils: mkfs: avoid hanging if fragment is on and tmpdir is full")
Assisted-by Codex:GPT-5.5
---
 include/erofs/err.h |  3 +++
 lib/compress.c      | 10 +++++++---
 lib/inode.c         |  6 +++---
 3 files changed, 13 insertions(+), 6 deletions(-)
include/erofs/err.h +3 -0
index 7dacc917a4c1..bf5a4e1cf9b7 100644
@@ -53,6 +53,9 @@ static inline void * ERR_CAST(const void *ptr)
 	return (void *) ptr;
 }
 
+/* EROFS-specific error codes */
+#define EROFS_RETCODE_FALLBACK		MAX_ERRNO
+
 #ifdef __cplusplus
 }
 #endif
lib/compress.c +7 -3
index ea07409defef..0f448e400a2d 100644
@@ -1375,7 +1375,7 @@ int erofs_commit_compressed_file(struct z_erofs_compress_ictx *ictx,
 	    legacymetasize >= inode->i_size) {
 		z_erofs_dedupe_ext_commit(true);
 		z_erofs_dedupe_commit(true);
-		ret = -ENOSPC;
+		ret = EROFS_RETCODE_FALLBACK;
 		goto err_free_meta;
 	}
 	z_erofs_dedupe_ext_commit(false);
@@ -2031,7 +2031,11 @@ err_free_idata:
 out:
 #ifdef EROFS_MT_ENABLED
 	pthread_mutex_lock(&ictx->mutex);
-	ictx->seg_num = ret < 0 ? INT_MAX : 0;
+	if (ret < 0 && ret != EROFS_RETCODE_FALLBACK)
+		/* mark as failed to avoid further processing */
+		ictx->seg_num = INT_MAX;
+	else
+		ictx->seg_num = 0;
 	pthread_cond_signal(&ictx->cond);
 	pthread_mutex_unlock(&ictx->mutex);
 #endif
@@ -2044,7 +2048,7 @@ int erofs_begin_compress_dir(struct erofs_importer *im,
 {
 	if (!im->params->compress_dir ||
 	    inode->i_size < Z_EROFS_LEGACY_MAP_HEADER_SIZE)
-		return -ENOSPC;
+		return EROFS_RETCODE_FALLBACK;
 
 	inode->z_advise |= Z_EROFS_ADVISE_FRAGMENT_PCLUSTER;
 	erofs_sb_set_fragments(inode->sbi);
lib/inode.c +3 -3
index c225faa121e7..4c2d094bac7e 100644
@@ -1507,7 +1507,7 @@ static int erofs_mkfs_job_write_file(struct erofs_mkfs_job_ndir_ctx *ctx)
 
 	if (ctx->ictx) {
 		ret = erofs_write_compressed_file(ctx->ictx);
-		if (ret != -ENOSPC)
+		if (ret != EROFS_RETCODE_FALLBACK)
 			goto out;
 		if (lseek(ctx->fd, ctx->fpos, SEEK_SET) < 0) {
 			ret = -errno;
@@ -1594,7 +1594,7 @@ static int erofs_mkfs_create_directory(const struct erofs_mkfs_btctx *ctx,
 		inode->datalayout = EROFS_INODE_FLAT_INLINE;
 
 		ret = erofs_begin_compress_dir(ctx->im, inode);
-		if (ret && ret != -ENOSPC)
+		if (ret && ret != EROFS_RETCODE_FALLBACK)
 			return ret;
 	} else {
 		DBG_BUGON(inode->datalayout != EROFS_INODE_FLAT_PLAIN);
@@ -2391,7 +2391,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_importer *im,
 		ret = erofs_write_compressed_file(ictx);
 		if (!ret)
 			goto out;
-		if (ret != -ENOSPC)
+		if (ret != EROFS_RETCODE_FALLBACK)
 			 return ERR_PTR(ret);
 
 		ret = lseek(fd, 0, SEEK_SET);
Signature · 1 line
2.43.5