erofs-utils: mkfs: show per-file progress
PATCH 1/1 erofs-utils: mkfs: show per-file progress
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 <[email protected]>
--- 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(-)
include/erofs/config.h +3 -0
@@ -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
include/erofs/print.h +14 -12
@@ -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)
lib/config.c +34 -0
@@ -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); +}
lib/inode.c +1 -0
@@ -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);
mkfs/main.c +6 -1
@@ -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 ; }
Signature · 1 line
2.24.4
PATCH v2 1/1 erofs-utils: mkfs: show per-file progress
From: Gao Xiang <[email protected]>
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 <[email protected]>
---
changes since v1:
- trim over long paths according to TIOCGWINSZ reporting.
configure.ac | 2 ++ include/erofs/config.h | 4 +++ include/erofs/print.h | 26 +++++++++-------- lib/config.c | 64 ++++++++++++++++++++++++++++++++++++++++++ lib/inode.c | 6 +++- mkfs/main.c | 7 ++++- 6 files changed, 95 insertions(+), 14 deletions(-)
configure.ac +2 -0
@@ -140,6 +140,8 @@ AC_CHECK_HEADERS(m4_flatten([ unistd.h ])) +AC_HEADER_TIOCGWINSZ + # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE AC_TYPE_INT64_T
include/erofs/config.h +4 -0
@@ -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,9 @@ static inline int erofs_selabel_open(const char *file_contexts) }#endif +void erofs_update_progressinfo (const char *fmt, ...); +char *erofs_trim_for_progressinfo (const char *str,int placeholder); +#ifdef __cplusplus }#endif
include/erofs/print.h +14 -12
@@ -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)
lib/config.c +64 -0
76 lines not on this page · raw message
lib/inode.c +5 -1
@@ -1083,7 +1083,7 @@ static struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir)erofs_fixup_meta_blkaddr (dir);list_for_each_entry (d, &dir->i_subdirs, d_child) { -char buf[PATH_MAX ]; +char buf[PATH_MAX ], *trimmed;unsigned char ftype;if (is_dot_dotdot (d->name)) {
@@ -1098,6 +1098,10 @@ static struct erofs_inode *erofs_mkfs_build_tree(struct erofs_inode *dir) goto fail; } + trimmed =erofs_trim_for_progressinfo (erofs_fspath (buf), +sizeof ("Processing ..." ) -1 ); +erofs_update_progressinfo ("Processing %s ..." , trimmed); +free (trimmed); d->inode =erofs_mkfs_build_tree_from_path (dir, buf);if (IS_ERR (d->inode)) { ret =PTR_ERR (d->inode);
mkfs/main.c +6 -1
@@ -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.\n" ); }return 0 ; }
Signature · 1 line
2.30.2