From: Gao Xiang <xiang@kernel.org>
To: linux-erofs@lists.ozlabs.org
Cc: Gao Xiang <xiang@kernel.org>
Subject: [PATCH v2 1/3] erofs-utils: lib: migrate `c_chunkbits` and `c_blobdev_path`
Date: Wed, 2 Sep 2026 23:53:30 +0800 [thread overview]
Message-ID: <20260902155333.57247-1-xiang@kernel.org> (raw)
Signed-off-by: Gao Xiang <xiang@kernel.org>
---
address Xusheng's comments:
https://lore.kernel.org/r/20260902071406.3292294-1-zhanxusheng@xiaomi.com
include/erofs/config.h | 2 --
include/erofs/importer.h | 1 +
lib/inode.c | 25 +++++++++--------
mkfs/main.c | 58 +++++++++++++++++++++-------------------
4 files changed, 46 insertions(+), 40 deletions(-)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 95d7e9f..c796c95 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -34,7 +34,6 @@ struct erofs_configure {
int c_dbg_lvl;
bool c_dry_run;
char c_timeinherit;
- char c_chunkbits;
char c_dedupe;
bool c_showprogress;
bool c_extra_ea_name_prefixes;
@@ -46,7 +45,6 @@ struct erofs_configure {
/* related arguments for mkfs.erofs */
char *c_img_path;
char *c_src_path;
- char *c_blobdev_path;
char *c_compress_hints_file;
char c_force_chunkformat;
u8 c_mkfs_metabox_algid;
diff --git a/include/erofs/importer.h b/include/erofs/importer.h
index 07e40b4..c09b169 100644
--- a/include/erofs/importer.h
+++ b/include/erofs/importer.h
@@ -63,6 +63,7 @@ struct erofs_importer_params {
bool all_fragments;
bool compress_dir;
char fragdedupe;
+ char chunkszbits_def;
};
struct erofs_importer {
diff --git a/lib/inode.c b/lib/inode.c
index ea3277b..728040a 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -704,13 +704,15 @@ static int erofs_write_unencoded_data(struct erofs_inode *inode,
return 0;
}
-int erofs_write_unencoded_file(struct erofs_inode *inode, int fd, u64 fpos)
+static int erofs_write_unencoded_file(const struct erofs_importer *im,
+ struct erofs_inode *inode, int fd, u64 fpos)
{
struct erofs_vfile vf = { .fd = fd };
+ char chunkbits = im->params->chunkszbits_def;
- if (cfg.c_chunkbits &&
+ if (chunkbits &&
inode->datasource != EROFS_INODE_DATA_SOURCE_REBUILD_BLOB) {
- inode->u.chunkbits = cfg.c_chunkbits;
+ inode->u.chunkbits = chunkbits;
/* chunk indexes when explicitly specified */
inode->u.chunkformat = 0;
if (cfg.c_force_chunkformat == FORCE_INODE_CHUNK_INDEXES)
@@ -1491,6 +1493,11 @@ static int erofs_inode_reserve_data_blocks(struct erofs_inode *inode)
return 0;
}
+struct erofs_mkfs_btctx {
+ struct erofs_importer *im;
+ bool rebuild, incremental;
+};
+
struct erofs_mkfs_job_ndir_ctx {
struct erofs_inode *inode;
void *ictx;
@@ -1498,7 +1505,8 @@ struct erofs_mkfs_job_ndir_ctx {
u64 fpos;
};
-static int erofs_mkfs_job_write_file(struct erofs_mkfs_job_ndir_ctx *ctx)
+static int erofs_mkfs_job_write_file(const struct erofs_mkfs_btctx *btctx,
+ struct erofs_mkfs_job_ndir_ctx *ctx)
{
struct erofs_inode *inode = ctx->inode;
int ret;
@@ -1519,7 +1527,7 @@ static int erofs_mkfs_job_write_file(struct erofs_mkfs_job_ndir_ctx *ctx)
}
}
/* fallback to all data uncompressed */
- ret = erofs_write_unencoded_file(inode, ctx->fd, ctx->fpos);
+ ret = erofs_write_unencoded_file(btctx->im, inode, ctx->fd, ctx->fpos);
out:
if (inode->datasource == EROFS_INODE_DATA_SOURCE_DISKBUF) {
erofs_diskbuf_close(inode->i_diskbuf);
@@ -1539,11 +1547,6 @@ out:
return ret;
}
-struct erofs_mkfs_btctx {
- struct erofs_importer *im;
- bool rebuild, incremental;
-};
-
static int erofs_mkfs_handle_nondirectory(const struct erofs_mkfs_btctx *btctx,
struct erofs_mkfs_job_ndir_ctx *ctx)
{
@@ -1575,7 +1578,7 @@ static int erofs_mkfs_handle_nondirectory(const struct erofs_mkfs_btctx *btctx,
if (inode->datasource == EROFS_INODE_DATA_SOURCE_RESVSP)
ret = erofs_inode_reserve_data_blocks(inode);
else if (ctx->fd >= 0)
- ret = erofs_mkfs_job_write_file(ctx);
+ ret = erofs_mkfs_job_write_file(btctx, ctx);
}
if (ret)
return ret;
diff --git a/mkfs/main.c b/mkfs/main.c
index 8da3753..ce29319 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -282,9 +282,11 @@ static void version(void)
static struct erofsmkfs_cfg {
struct z_erofs_paramset zcfgs[EROFS_MAX_COMPR_CFGS + 1];
+ char *blobdev_path;
/* < 0, xattr disabled and >= INT_MAX, always use inline xattrs */
long inlinexattr_tolerance;
bool inode_metazone;
+ char chunkbits;
u64 unix_timestamp;
unsigned int total_zcfgs;
} mkfscfg = {
@@ -1265,8 +1267,8 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
erofs_err("invalid chunksize %s", optarg);
return -EINVAL;
}
- cfg.c_chunkbits = ilog2(i);
- if ((1 << cfg.c_chunkbits) != i) {
+ mkfscfg.chunkbits = ilog2(i);
+ if ((1 << mkfscfg.chunkbits) != i) {
erofs_err("chunksize %s must be a power of two",
optarg);
return -EINVAL;
@@ -1277,7 +1279,7 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
quiet = true;
break;
case 13:
- cfg.c_blobdev_path = optarg;
+ mkfscfg.blobdev_path = optarg;
break;
case 14:
params->ignore_mtime = true;
@@ -1506,13 +1508,13 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
}
}
- if (cfg.c_blobdev_path && cfg.c_chunkbits < mkfs_blkszbits) {
+ if (mkfscfg.blobdev_path && mkfscfg.chunkbits < mkfs_blkszbits) {
erofs_err("--blobdev must be used together with --chunksize");
return -EINVAL;
}
/* TODO: can be implemented with (deviceslot) mapped_blkaddr */
- if (cfg.c_blobdev_path &&
+ if (mkfscfg.blobdev_path &&
cfg.c_force_chunkformat == FORCE_INODE_BLOCK_MAP) {
erofs_err("--blobdev cannot work with block map currently");
return -EINVAL;
@@ -1564,9 +1566,9 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
params->pclusterblks_max = pclustersize_max >> mkfs_blkszbits;
params->pclusterblks_def = params->pclusterblks_max;
}
- if (cfg.c_chunkbits && cfg.c_chunkbits < mkfs_blkszbits) {
+ if (mkfscfg.chunkbits && mkfscfg.chunkbits < mkfs_blkszbits) {
erofs_err("chunksize %u must be larger than block size",
- 1u << cfg.c_chunkbits);
+ 1u << mkfscfg.chunkbits);
return -EINVAL;
}
@@ -1579,10 +1581,10 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
* unaligned. Therefore, let's issue a warning here and still skip
* alignment for now.
*/
- if (cfg.c_chunkbits && dsunit &&
- (1u << (cfg.c_chunkbits - g_sbi.blkszbits)) < dsunit) {
+ if (mkfscfg.chunkbits && dsunit &&
+ (1u << (mkfscfg.chunkbits - g_sbi.blkszbits)) < dsunit) {
erofs_warn("chunksize %u bytes is smaller than dsunit %u blocks, ignore dsunit !",
- 1u << cfg.c_chunkbits, dsunit);
+ 1u << mkfscfg.chunkbits, dsunit);
}
if (pclustersize_packed) {
@@ -1896,26 +1898,28 @@ int main(int argc, char **argv)
importer_params.source = cfg.c_src_path;
importer_params.no_datainline = mkfs_no_datainline;
importer_params.dot_omitted = mkfs_dot_omitted;
+ if (importer_params.dedupe == EROFS_DEDUPE_FORCE_ON &&
+ !mkfscfg.chunkbits && !mkfscfg.total_zcfgs) {
+ erofs_err("Compression is not enabled. Turn on chunk-based data deduplication instead.");
+ mkfscfg.chunkbits = g_sbi.blkszbits;
+ }
+ importer_params.chunkszbits_def = mkfscfg.chunkbits;
err = erofs_importer_init(&importer);
if (err)
goto exit;
- if (importer_params.dedupe == EROFS_DEDUPE_FORCE_ON) {
- if (!g_sbi.available_compr_algs) {
- erofs_err("Compression is not enabled. Turn on chunk-based data deduplication instead.");
- cfg.c_chunkbits = g_sbi.blkszbits;
- } else {
- err = z_erofs_dedupe_init(erofs_blksiz(&g_sbi));
- if (err) {
- erofs_err("failed to initialize deduplication: %s",
- erofs_strerror(err));
- goto exit;
- }
+ if (importer_params.dedupe == EROFS_DEDUPE_FORCE_ON &&
+ g_sbi.available_compr_algs) {
+ err = z_erofs_dedupe_init(erofs_blksiz(&g_sbi));
+ if (err) {
+ erofs_err("failed to initialize deduplication: %s",
+ erofs_strerror(err));
+ goto exit;
}
}
cfg.c_dedupe = importer_params.dedupe;
- if (tar_index_512b || cfg.c_blobdev_path) {
+ if (tar_index_512b || mkfscfg.blobdev_path) {
err = erofs_mkfs_init_devices(&g_sbi, 1);
if (err) {
erofs_err("failed to generate device table: %s",
@@ -1924,9 +1928,9 @@ int main(int argc, char **argv)
}
}
- if (tar_index_512b || cfg.c_chunkbits) {
- if (g_sbi.extra_devices && cfg.c_blobdev_path) {
- g_sbi.devs[0].src_path = strdup(cfg.c_blobdev_path);
+ if (tar_index_512b || mkfscfg.chunkbits) {
+ if (g_sbi.extra_devices && mkfscfg.blobdev_path) {
+ g_sbi.devs[0].src_path = strdup(mkfscfg.blobdev_path);
if (!g_sbi.devs[0].src_path) {
err = -ENOMEM;
goto exit;
@@ -1937,7 +1941,7 @@ int main(int argc, char **argv)
goto exit;
}
- err = erofs_blob_init(&g_sbi, cfg.c_blobdev_path ? 1 : 0, cfg.c_chunkbits);
+ err = erofs_blob_init(&g_sbi, mkfscfg.blobdev_path ? 1 : 0, mkfscfg.chunkbits);
if (err)
goto exit;
}
@@ -2047,7 +2051,7 @@ int main(int argc, char **argv)
}
}
- if (erofstar.index_mode || cfg.c_chunkbits || g_sbi.extra_devices) {
+ if (erofstar.index_mode || mkfscfg.chunkbits || g_sbi.extra_devices) {
err = erofs_mkfs_dump_blobs(&g_sbi);
if (err)
goto exit;
--
2.47.3
next reply other threads:[~2026-09-02 15:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 15:53 Gao Xiang [this message]
2026-09-02 15:53 ` [PATCH v2 2/3] erofs-utils: mkfs: introduce ddev_id_def Gao Xiang
2026-09-02 15:53 ` [PATCH v2 3/3] erofs-utils: mkfs: enable `--blobdev` for flat inode layouts Gao Xiang
2026-09-03 7:57 ` [PATCH v3] " Yifan Zhao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260902155333.57247-1-xiang@kernel.org \
--to=xiang@kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox