erofs-utils: mkfs: print filesystem summaries after success
authorGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 12 Sep 2023 11:50:59 +0000 (19:50 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 12 Sep 2023 14:20:22 +0000 (22:20 +0800)
Users may be interested in some details of the generated image.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230912115059.1997278-1-hsiangkao@linux.alibaba.com
include/erofs/cache.h
include/erofs/internal.h
lib/blobchunk.c
lib/cache.c
lib/compress.c
mkfs/main.c

index dc2998520c64edc71da2e72647f949f7836672a0..de5584e6f7a1b42374dbd0e36c265d67b2316b7f 100644 (file)
@@ -112,6 +112,7 @@ erofs_blk_t erofs_mapbh(struct erofs_buffer_block *bb);
 bool erofs_bflush(struct erofs_buffer_block *bb);
 
 void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke);
+erofs_blk_t erofs_total_metablocks(void);
 
 #ifdef __cplusplus
 }
index ba4d6c6efdc3a17eaefde05f6a2efc9b6682cbcb..c36bb24ed1d0f10ad22642bfa6391d6a674d796a 100644 (file)
@@ -111,6 +111,10 @@ struct erofs_sb_info {
        u64 devsz;
        unsigned int nblobs;
        unsigned int blobfd[256];
+
+       struct list_head list;
+
+       u64 saved_by_deduplication;
 };
 
 /* make sure that any user of the erofs headers has atleast 64bit off_t type */
index cada5bb1f43a7c26b8ededb150f67cabd286336b..86b29c1275bcd1379dadbd07c21015dca2008926 100644 (file)
@@ -69,6 +69,7 @@ static struct erofs_blobchunk *erofs_blob_getchunk(struct erofs_sb_info *sbi,
        chunk = hashmap_get_from_hash(&blob_hashmap, hash, sha256);
        if (chunk) {
                DBG_BUGON(chunksize != chunk->chunksize);
+               sbi->saved_by_deduplication += chunksize;
                erofs_dbg("Found duplicated chunk at %u", chunk->blkaddr);
                return chunk;
        }
index 925054a1d434076c3e1accf228ed5e0804a66db4..5205d573d2c75d555da3c9ce9787702ef3e1f6f5 100644 (file)
@@ -14,7 +14,7 @@ static struct erofs_buffer_block blkh = {
        .list = LIST_HEAD_INIT(blkh.list),
        .blkaddr = NULL_ADDR,
 };
-static erofs_blk_t tail_blkaddr;
+static erofs_blk_t tail_blkaddr, erofs_metablkcnt;
 
 /* buckets for all mapped buffer blocks to boost up allocation */
 static struct list_head mapped_buckets[META + 1][EROFS_MAX_BLOCK_SIZE];
@@ -396,6 +396,8 @@ bool erofs_bflush(struct erofs_buffer_block *bb)
                        dev_fillzero(&sbi, erofs_pos(&sbi, blkaddr) - padding,
                                     padding, true);
 
+               if (p->type != DATA)
+                       erofs_metablkcnt += BLK_ROUND_UP(&sbi, p->buffers.off);
                erofs_dbg("block %u to %u flushed", p->blkaddr, blkaddr - 1);
                erofs_bfree(p);
        }
@@ -419,8 +421,14 @@ void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke)
        if (!list_empty(&bb->buffers.list))
                return;
 
+       if (!rollback && bb->type != DATA)
+               erofs_metablkcnt += BLK_ROUND_UP(&sbi, bb->buffers.off);
        erofs_bfree(bb);
-
        if (rollback)
                tail_blkaddr = blkaddr;
 }
+
+erofs_blk_t erofs_total_metablocks(void)
+{
+       return erofs_metablkcnt;
+}
index e5d310fba9dcbf1e0979e052f60c4c8bda6496da..8c794182f5f3b95c1fe1e716311399ecdcf18564 100644 (file)
@@ -221,6 +221,8 @@ static int z_erofs_compress_dedupe(struct z_erofs_vle_compress_ctx *ctx,
                        ctx->e.length -= delta;
                }
 
+               sbi->saved_by_deduplication +=
+                       dctx.e.compressedblks * erofs_blksiz(sbi);
                erofs_dbg("Dedupe %u %scompressed data (delta %d) to %u of %u blocks",
                          dctx.e.length, dctx.e.raw ? "un" : "",
                          delta, dctx.e.blkaddr, dctx.e.compressedblks);
@@ -975,6 +977,9 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd)
        z_erofs_dedupe_commit(false);
        z_erofs_write_mapheader(inode, compressmeta);
 
+       if (!ctx.fragemitted)
+               sbi->saved_by_deduplication += inode->fragment_size;
+
        /* if the entire file is a fragment, a simplified form is used. */
        if (inode->i_size == inode->fragment_size) {
                DBG_BUGON(inode->fragmentoff >> 63);
index 0bf6ab9dc9f3645839eae1ad818abd65f8450913..c7f404751015dbe48a1b121efc51cb290c85d055 100644 (file)
@@ -736,6 +736,25 @@ void erofs_show_progs(int argc, char *argv[])
                printf("%s %s\n", basename(argv[0]), cfg.c_version);
 }
 
+static void erofs_mkfs_showsummaries(erofs_blk_t nblocks)
+{
+       char uuid_str[37] = {};
+
+       if (!(cfg.c_dbg_lvl > EROFS_ERR && cfg.c_showprogress))
+               return;
+
+       erofs_uuid_unparse_lower(sbi.uuid, uuid_str);
+
+       fprintf(stdout, "------\nFilesystem UUID: %s\n"
+               "Filesystem total blocks: %u (of %u-byte blocks)\n"
+               "Filesystem total inodes: %llu\n"
+               "Filesystem total metadata blocks: %u\n"
+               "Filesystem total deduplicated bytes (of source files): %llu\n",
+               uuid_str, nblocks, 1U << sbi.blkszbits, sbi.inos | 0ULL,
+               erofs_total_metablocks(),
+               sbi.saved_by_deduplication | 0ULL);
+}
+
 int main(int argc, char **argv)
 {
        int err = 0;
@@ -745,7 +764,6 @@ int main(int argc, char **argv)
        struct stat st;
        erofs_blk_t nblocks;
        struct timeval t;
-       char uuid_str[37];
        FILE *packedfile = NULL;
 
        erofs_init_configure();
@@ -910,8 +928,6 @@ int main(int argc, char **argv)
                          erofs_strerror(err));
                goto exit;
        }
-       erofs_uuid_unparse_lower(sbi.uuid, uuid_str);
-       erofs_info("filesystem UUID: %s", uuid_str);
 
        erofs_inode_manager_init();
 
@@ -957,7 +973,6 @@ int main(int argc, char **argv)
        erofs_iput(root_inode);
 
        if (erofstar.index_mode || cfg.c_chunkbits) {
-               erofs_info("total metadata: %u blocks", erofs_mapbh(NULL));
                if (erofstar.index_mode && !erofstar.mapfile)
                        sbi.devs[0].blocks =
                                BLK_ROUND_UP(&sbi, erofstar.offset);
@@ -1017,8 +1032,8 @@ exit:
                erofs_err("\tCould not format the device : %s\n",
                          erofs_strerror(err));
                return 1;
-       } else {
-               erofs_update_progressinfo("Build completed.\n");
        }
+       erofs_update_progressinfo("Build completed.\n");
+       erofs_mkfs_showsummaries(nblocks);
        return 0;
 }