[PATCH] erofs-utils: use chunk-based data deduplication if compression is off

Gao Xiang hsiangkao at linux.alibaba.com
Mon Oct 17 14:17:36 AEDT 2022


After this patch, "-E dedupe" can now support chunk-based data
deduplication with block-sized chunks if compression is off.

Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 mkfs/main.c | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/mkfs/main.c b/mkfs/main.c
index 00a2deb..77d635c 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -663,12 +663,6 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	if (cfg.c_chunkbits) {
-		err = erofs_blob_init(cfg.c_blobdev_path);
-		if (err)
-			return 1;
-	}
-
 	err = lstat64(cfg.c_src_path, &st);
 	if (err)
 		return 1;
@@ -747,15 +741,6 @@ int main(int argc, char **argv)
 		goto exit;
 	}
 
-	if (cfg.c_dedupe) {
-		err = z_erofs_dedupe_init(EROFS_BLKSIZ);
-		if (err) {
-			erofs_err("failed to initialize deduplication: %s",
-				  erofs_strerror(err));
-			goto exit;
-		}
-	}
-
 	err = z_erofs_compress_init(sb_bh);
 	if (err) {
 		erofs_err("failed to initialize compressor: %s",
@@ -763,6 +748,26 @@ int main(int argc, char **argv)
 		goto exit;
 	}
 
+	if (cfg.c_dedupe) {
+		if (!cfg.c_compr_alg_master) {
+			erofs_err("Compression is not enabled.  Turn on chunk-based data deduplication instead.");
+			cfg.c_chunkbits = LOG_BLOCK_SIZE;
+		} else {
+			err = z_erofs_dedupe_init(EROFS_BLKSIZ);
+			if (err) {
+				erofs_err("failed to initialize deduplication: %s",
+					  erofs_strerror(err));
+				goto exit;
+			}
+		}
+	}
+
+	if (cfg.c_chunkbits) {
+		err = erofs_blob_init(cfg.c_blobdev_path);
+		if (err)
+			return 1;
+	}
+
 	err = erofs_generate_devtable();
 	if (err) {
 		erofs_err("failed to generate device table: %s",
-- 
2.24.4



More information about the Linux-erofs mailing list