aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGao Xiang <hsiangkao@linux.alibaba.com>2023-09-12 19:50:59 +0800
committerGao Xiang <hsiangkao@linux.alibaba.com>2023-09-12 22:20:22 +0800
commit6d018b65da3935f0148a1325b8dccd6e4bfbe993 (patch)
tree2a2f08f30a26e825c7f65673e0c6b3749b8c6a15
parent391aba1c212d136e453b2f73c8201c6457bbbf6f (diff)
downloaderofs-utils-6d018b65da3935f0148a1325b8dccd6e4bfbe993.tar.gz
erofs-utils: mkfs: print filesystem summaries after success
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
-rw-r--r--include/erofs/cache.h1
-rw-r--r--include/erofs/internal.h4
-rw-r--r--lib/blobchunk.c1
-rw-r--r--lib/cache.c12
-rw-r--r--lib/compress.c5
-rw-r--r--mkfs/main.c27
6 files changed, 42 insertions, 8 deletions
diff --git a/include/erofs/cache.h b/include/erofs/cache.h
index dc29985..de5584e 100644
--- a/include/erofs/cache.h
+++ b/include/erofs/cache.h
@@ -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
}
diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index ba4d6c6..c36bb24 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -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 */
diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index cada5bb..86b29c1 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -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;
}
diff --git a/lib/cache.c b/lib/cache.c
index 925054a..5205d57 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -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;
+}
diff --git a/lib/compress.c b/lib/compress.c
index e5d310f..8c79418 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -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);
diff --git a/mkfs/main.c b/mkfs/main.c
index 0bf6ab9..c7f4047 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -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;
}