From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org
Cc: Gao Xiang <hsiangkao@linux.alibaba.com>
Subject: [PATCH] erofs-utils: mkfs: show per-file progress
Date: Mon, 16 May 2022 15:10:33 +0800 [thread overview]
Message-ID: <20220516071033.96151-1-hsiangkao@linux.alibaba.com> (raw)
Generally, users want to know the latest progress since it may take
long time to build a image. Let's add a per-file progress as a start.
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
include/erofs/config.h | 3 +++
include/erofs/print.h | 26 ++++++++++++++------------
lib/config.c | 34 ++++++++++++++++++++++++++++++++++
lib/inode.c | 1 +
mkfs/main.c | 7 ++++++-
5 files changed, 58 insertions(+), 13 deletions(-)
diff --git a/include/erofs/config.h b/include/erofs/config.h
index 1e985b0..aeacb7b 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -45,6 +45,7 @@ struct erofs_configure {
bool c_noinline_data;
bool c_ztailpacking;
bool c_ignore_mtime;
+ bool c_showprogress;
#ifdef HAVE_LIBSELINUX
struct selabel_handle *sehnd;
@@ -92,6 +93,8 @@ static inline int erofs_selabel_open(const char *file_contexts)
}
#endif
+void erofs_update_progressinfo(const char *fmt, ...);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/erofs/print.h b/include/erofs/print.h
index f188a6b..a896d75 100644
--- a/include/erofs/print.h
+++ b/include/erofs/print.h
@@ -41,37 +41,39 @@ enum {
#define PR_FMT_FUNC_LINE(fmt) pr_fmt(fmt), __func__, __LINE__
#endif
+void erofs_msg(int dbglv, const char *fmt, ...);
+
#define erofs_dbg(fmt, ...) do { \
if (cfg.c_dbg_lvl >= EROFS_DBG) { \
- fprintf(stdout, \
- "<D> " PR_FMT_FUNC_LINE(fmt), \
- ##__VA_ARGS__); \
+ erofs_msg(EROFS_DBG, \
+ "<D> " PR_FMT_FUNC_LINE(fmt), \
+ ##__VA_ARGS__); \
} \
} while (0)
#define erofs_info(fmt, ...) do { \
if (cfg.c_dbg_lvl >= EROFS_INFO) { \
- fprintf(stdout, \
- "<I> " PR_FMT_FUNC_LINE(fmt), \
- ##__VA_ARGS__); \
+ erofs_msg(EROFS_INFO, \
+ "<I> " PR_FMT_FUNC_LINE(fmt), \
+ ##__VA_ARGS__); \
fflush(stdout); \
} \
} while (0)
#define erofs_warn(fmt, ...) do { \
if (cfg.c_dbg_lvl >= EROFS_WARN) { \
- fprintf(stdout, \
- "<W> " PR_FMT_FUNC_LINE(fmt), \
- ##__VA_ARGS__); \
+ erofs_msg(EROFS_WARN, \
+ "<W> " PR_FMT_FUNC_LINE(fmt), \
+ ##__VA_ARGS__); \
fflush(stdout); \
} \
} while (0)
#define erofs_err(fmt, ...) do { \
if (cfg.c_dbg_lvl >= EROFS_ERR) { \
- fprintf(stderr, \
- "<E> " PR_FMT_FUNC_LINE(fmt), \
- ##__VA_ARGS__); \
+ erofs_msg(EROFS_ERR, \
+ "<E> " PR_FMT_FUNC_LINE(fmt), \
+ ##__VA_ARGS__); \
} \
} while (0)
diff --git a/lib/config.c b/lib/config.c
index 24db751..0ae3120 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -6,6 +6,7 @@
*/
#include <string.h>
#include <stdlib.h>
+#include <stdarg.h>
#include "erofs/print.h"
#include "erofs/internal.h"
#include "liberofs_private.h"
@@ -91,3 +92,36 @@ int erofs_selabel_open(const char *file_contexts)
return 0;
}
#endif
+
+bool __erofs_is_progressmsg;
+
+void erofs_msg(int dbglv, const char *fmt, ...)
+{
+ va_list ap;
+ FILE *f = dbglv >= EROFS_ERR ? stderr : stdout;
+
+ if (__erofs_is_progressmsg) {
+ fputc('\n', f);
+ __erofs_is_progressmsg = false;
+ }
+ va_start(ap, fmt);
+ vfprintf(f, fmt, ap);
+ va_end(ap);
+}
+
+void erofs_update_progressinfo(const char *fmt, ...)
+{
+ char msg[1024];
+ va_list ap;
+
+ if (cfg.c_dbg_lvl >= EROFS_INFO || !cfg.c_showprogress)
+ return;
+
+ va_start(ap, fmt);
+ vsprintf(msg, fmt, ap);
+ va_end(ap);
+
+ printf("\r\033[K%s", msg);
+ __erofs_is_progressmsg = true;
+ fflush(stdout);
+}
diff --git a/lib/inode.c b/lib/inode.c
index 6c6e42e..cafac40 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -1098,6 +1098,7 @@ static struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)
goto fail;
}
+ erofs_update_progressinfo("Processing %s ...", buf);
d->inode = erofs_mkfs_build_tree_from_path(dir, buf);
if (IS_ERR(d->inode)) {
ret = PTR_ERR(d->inode);
diff --git a/mkfs/main.c b/mkfs/main.c
index 25b72ad..0e09b38 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -423,8 +423,10 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
erofs_err("unexpected argument: %s\n", argv[optind]);
return -EINVAL;
}
- if (quiet)
+ if (quiet) {
cfg.c_dbg_lvl = EROFS_ERR;
+ cfg.c_showprogress = false;
+ }
return 0;
}
@@ -520,6 +522,7 @@ static int erofs_mkfs_superblock_csum_set(void)
static void erofs_mkfs_default_options(void)
{
+ cfg.c_showprogress = true;
cfg.c_legacy_compress = false;
sbi.feature_incompat = EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
sbi.feature_compat = EROFS_FEATURE_COMPAT_SB_CHKSUM |
@@ -738,6 +741,8 @@ exit:
erofs_err("\tCould not format the device : %s\n",
erofs_strerror(err));
return 1;
+ } else {
+ erofs_update_progressinfo("Build completed.");
}
return 0;
}
--
2.24.4
next reply other threads:[~2022-05-16 7:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-16 7:10 Gao Xiang [this message]
2022-05-16 17:24 ` [PATCH v2] erofs-utils: mkfs: show per-file progress Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220516071033.96151-1-hsiangkao@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox