Skip to contentSkip to conversation

erofs-utils: lib: refresh device table slots on incremental builds

PATCH In review Jonathan Calmels 2 participants 2 messages Sep 3 – Sep 7 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: refresh device table slots on incremental builds

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/

---
 include/erofs/internal.h |  6 ++----
 lib/super.c              | 27 +++++++++++++++------------
 2 files changed, 17 insertions(+), 16 deletions(-)
include/erofs/internal.h +2 -4
index 95f5627..b10e447 100644
@@ -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;
 
lib/super.c +15 -12
index 9e52dd8..672464c 100644
@@ -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;
Signature · 1 line
2.53.0
#1 lore raw

Hi Jonathan,

Quoted 4 lines · 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.

Quoted 8 lines

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/

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