erofs-utils: wrap up superblock reservation for incremental builds
authorGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 12 Jun 2024 16:18:24 +0000 (00:18 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 13 Jun 2024 02:44:24 +0000 (10:44 +0800)
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@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240612161826.711279-3-hsiangkao@linux.alibaba.com
include/erofs/cache.h
include/erofs/internal.h
lib/cache.c
lib/super.c
mkfs/main.c

index 350cec685bf6d33591faffa0bcf2fa9d34f980dc..f30fe9f9a2ac04171abaeccf1a026b5fe4aa7483 100644 (file)
@@ -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,
index 277295e1552184c3ab9bb259449e51cda09feb00..f8a01cee5d8d64b147b2cb01655228d671714025 100644 (file)
@@ -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);
index 664e598198ef919b0af2fbaba95c64673ea57cbe..328ca4a265b71a54827c1e30f8fb4a76d55637b2 100644 (file)
@@ -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)
index 33e908a51ad3224efd943401ca074a124b7ec1b5..c8c33b63fdfbdc0928a9e69c1eb65343362d7790 100644 (file)
@@ -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);
+}
index 65772676fa0946dad510f4df2b5b6ec8db375773..1e8ca3cba9c7a2a856b6df6b31b27f235bc14820 100644 (file)
@@ -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;
        }