[PATCH 3/5] erofs-utils: wrap up superblock reservation for incremental builds

Gao Xiang hsiangkao at linux.alibaba.com
Thu Jun 13 02:18:24 AEST 2024


Refactor `erofs_buffer_init()` to wrap up necessary operations for full
builds.

Introduce another `erofs_buffer_init()` to specify start block address
for the upcoming incremental builds.

Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 include/erofs/cache.h    |  2 +-
 include/erofs/internal.h |  1 +
 lib/cache.c              | 11 ++---------
 lib/super.c              | 31 +++++++++++++++++++++++++++++++
 mkfs/main.c              | 17 +----------------
 5 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/include/erofs/cache.h b/include/erofs/cache.h
index 350cec6..f30fe9f 100644
--- a/include/erofs/cache.h
+++ b/include/erofs/cache.h
@@ -98,7 +98,7 @@ static inline int erofs_bh_flush_generic_end(struct erofs_buffer_head *bh)
 	return 0;
 }
 
-struct erofs_buffer_head *erofs_buffer_init(void);
+void erofs_buffer_init(erofs_blk_t startblk);
 int erofs_bh_balloon(struct erofs_buffer_head *bh, erofs_off_t incr);
 
 struct erofs_buffer_head *erofs_balloc(int type, erofs_off_t size,
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index 277295e..f8a01ce 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -397,6 +397,7 @@ int erofs_read_superblock(struct erofs_sb_info *sbi);
 void erofs_put_super(struct erofs_sb_info *sbi);
 int erofs_writesb(struct erofs_sb_info *sbi, struct erofs_buffer_head *sb_bh,
 		  erofs_blk_t *blocks);
+struct erofs_buffer_head *erofs_reserve_sb(void);
 
 /* namei.c */
 int erofs_read_inode_from_disk(struct erofs_inode *vi);
diff --git a/lib/cache.c b/lib/cache.c
index 664e598..328ca4a 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -38,21 +38,14 @@ const struct erofs_bhops erofs_skip_write_bhops = {
 	.flush = erofs_bh_flush_skip_write,
 };
 
-/* return buffer_head of erofs super block (with size 0) */
-struct erofs_buffer_head *erofs_buffer_init(void)
+void erofs_buffer_init(erofs_blk_t startblk)
 {
 	int i, j;
-	struct erofs_buffer_head *bh = erofs_balloc(META, 0, 0, 0);
-
-	if (IS_ERR(bh))
-		return bh;
-
-	bh->op = &erofs_skip_write_bhops;
 
 	for (i = 0; i < ARRAY_SIZE(mapped_buckets); i++)
 		for (j = 0; j < ARRAY_SIZE(mapped_buckets[0]); j++)
 			init_list_head(&mapped_buckets[i][j]);
-	return bh;
+	tail_blkaddr = startblk;
 }
 
 static void erofs_bupdate_mapped(struct erofs_buffer_block *bb)
diff --git a/lib/super.c b/lib/super.c
index 33e908a..c8c33b6 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -201,3 +201,34 @@ int erofs_writesb(struct erofs_sb_info *sbi, struct erofs_buffer_head *sb_bh,
 		erofs_bdrop(sb_bh, false);
 	return ret;
 }
+
+struct erofs_buffer_head *erofs_reserve_sb(void)
+{
+	struct erofs_buffer_head *bh;
+	int err;
+
+	erofs_buffer_init(0);
+	bh = erofs_balloc(META, 0, 0, 0);
+	if (IS_ERR(bh)) {
+		erofs_err("failed to allocate super: %s", PTR_ERR(bh));
+		return bh;
+	}
+	bh->op = &erofs_skip_write_bhops;
+	err = erofs_bh_balloon(bh, EROFS_SUPER_END);
+	if (err < 0) {
+		erofs_err("failed to balloon super: %s", erofs_strerror(err));
+		goto err_bdrop;
+	}
+
+	/* make sure that the super block should be the very first blocks */
+	(void)erofs_mapbh(bh->block);
+	if (erofs_btell(bh, false) != 0) {
+		erofs_err("failed to pin super block @ 0");
+		err = -EFAULT;
+		goto err_bdrop;
+	}
+	return bh;
+err_bdrop:
+	erofs_bdrop(bh, true);
+	return ERR_PTR(err);
+}
diff --git a/mkfs/main.c b/mkfs/main.c
index 6577267..1e8ca3c 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1244,24 +1244,9 @@ int main(int argc, char **argv)
 		sbi.blkszbits = src->blkszbits;
 	}
 
-	sb_bh = erofs_buffer_init();
+	sb_bh = erofs_reserve_sb();
 	if (IS_ERR(sb_bh)) {
 		err = PTR_ERR(sb_bh);
-		erofs_err("failed to initialize buffers: %s",
-			  erofs_strerror(err));
-		goto exit;
-	}
-	err = erofs_bh_balloon(sb_bh, EROFS_SUPER_END);
-	if (err < 0) {
-		erofs_err("failed to balloon erofs_super_block: %s",
-			  erofs_strerror(err));
-		goto exit;
-	}
-
-	/* make sure that the super block should be the very first blocks */
-	(void)erofs_mapbh(sb_bh->block);
-	if (erofs_btell(sb_bh, false) != 0) {
-		erofs_err("failed to reserve erofs_super_block");
 		goto exit;
 	}
 
-- 
2.39.3



More information about the Linux-erofs mailing list