* [PATCH] erofs-utils: lib: refresh device table slots on incremental builds
@ 2026-09-03 23:21 Jonathan Calmels
2026-09-07 17:00 ` Gao Xiang
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Calmels @ 2026-09-03 23:21 UTC (permalink / raw)
To: linux-erofs; +Cc: Gao Xiang, Jonathan Calmels
When --incremental=data is run on a merged image, erofs_write_device_table()
leaves unified addresses and total block count stale after the primary device
grows. Fix it by rewriting the slots in place with updated uniaddr value.
Reproducer:
mkfs.erofs -Enoinline_data a.erofs a/
mkfs.erofs -Enoinline_data b.erofs b/
mkfs.erofs merged.erofs a.erofs b.erofs
mkfs.erofs --incremental=data merged.erofs c/
Signed-off-by: Jonathan Calmels <jcalmels@nvidia.com>
---
include/erofs/internal.h | 6 ++----
lib/super.c | 27 +++++++++++++++------------
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 95f5627..b10e447 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -123,10 +123,8 @@ struct erofs_sb_info {
u32 checksum;
u16 available_compr_algs;
u16 extra_devices;
- union {
- u16 devt_slotoff; /* used for mkfs */
- u16 device_id_mask; /* used for others */
- };
+ u16 devt_slotoff; /* used for mkfs */
+ u16 device_id_mask; /* used for others */
erofs_nid_t packed_nid;
erofs_nid_t metabox_nid;
diff --git a/lib/super.c b/lib/super.c
index 9e52dd8..672464c 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -52,6 +52,7 @@ static int erofs_init_devices(struct erofs_sb_info *sbi,
sbi->extra_devices = ondisk_extradevs;
sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1;
+ sbi->devt_slotoff = le16_to_cpu(dsb->devt_slotoff);
sbi->devs = calloc(ondisk_extradevs, sizeof(*sbi->devs));
if (!sbi->devs)
return -ENOMEM;
@@ -424,15 +425,15 @@ int erofs_write_device_table(struct erofs_sb_info *sbi)
if (!sbi->extra_devices)
goto out;
if (!bh) {
- if (erofs_sb_has_device_table(sbi))
- return 0;
- return -EINVAL;
- }
-
- pos = erofs_btell(bh, false);
- if (pos == EROFS_NULL_ADDR) {
- DBG_BUGON(1);
- return -EINVAL;
+ if (!erofs_sb_has_device_table(sbi))
+ return -EINVAL;
+ pos = sbi->devt_slotoff * EROFS_DEVT_SLOT_SIZE;
+ } else {
+ pos = erofs_btell(bh, false);
+ if (pos == EROFS_NULL_ADDR) {
+ DBG_BUGON(1);
+ return -EINVAL;
+ }
}
i = 0;
@@ -452,9 +453,11 @@ int erofs_write_device_table(struct erofs_sb_info *sbi)
nblocks += sbi->devs[i].blocks;
} while (++i < sbi->extra_devices);
- bh->op = &erofs_drop_directly_bhops;
- erofs_bdrop(bh, false);
- sbi->bh_devt = NULL;
+ if (bh) {
+ bh->op = &erofs_drop_directly_bhops;
+ erofs_bdrop(bh, false);
+ sbi->bh_devt = NULL;
+ }
out:
sbi->total_blocks = nblocks;
return 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] erofs-utils: lib: refresh device table slots on incremental builds
2026-09-03 23:21 [PATCH] erofs-utils: lib: refresh device table slots on incremental builds Jonathan Calmels
@ 2026-09-07 17:00 ` Gao Xiang
0 siblings, 0 replies; 2+ messages in thread
From: Gao Xiang @ 2026-09-07 17:00 UTC (permalink / raw)
To: Jonathan Calmels; +Cc: linux-erofs, Gao Xiang
Hi Jonathan,
On Thu, Sep 03, 2026 at 04:21:14PM -0700, Jonathan Calmels wrote:
> When --incremental=data is run on a merged image, erofs_write_device_table()
> leaves unified addresses and total block count stale after the primary device
> grows. Fix it by rewriting the slots in place with updated uniaddr value.
>
> Reproducer:
>
> mkfs.erofs -Enoinline_data a.erofs a/
> mkfs.erofs -Enoinline_data b.erofs b/
> mkfs.erofs merged.erofs a.erofs b.erofs
> mkfs.erofs --incremental=data merged.erofs c/
>
> Signed-off-by: Jonathan Calmels <jcalmels@nvidia.com>
Sorry for the delay. I've applied with minor changes.
Also it'd be better to have some basic functionality test case
targeting for experimental-tests.
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-07 17:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-03 23:21 [PATCH] erofs-utils: lib: refresh device table slots on incremental builds Jonathan Calmels
2026-09-07 17:00 ` Gao Xiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox