erofs-utils: code for handling incorrect debug level.
PATCH 1/1 erofs-utils: code for handling incorrect debug level.
handling the case of incorrect debug level. Added an enumerated type for supported debug levels. Using 'atoi' in place of 'parse_num_from_str'.
I have dropped the check for invalid compression algo name(which was there in last patch)
Note:I think this patch covers different set of code changes than previous patch,Hence I am sending a new patch instead of 'v2' of previous patch.
--- include/erofs/print.h | 16 ++++++++++++---- mkfs/main.c | 19 ++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-)
include/erofs/print.h +12 -4
@@ -12,6 +12,14 @@#include "config.h" #include <stdio.h> +enum { +EROFS_ERR =0 , +EROFS_WARN =2 , +EROFS_INFO =3 , +EROFS_DBG =7 , +EROFS_DBG_MAX =9 +}; +#define FUNC_LINE_FMT "%s() Line[%d] "#ifndef pr_fmt
@@ -19,7 +27,7 @@#endif #define erofs_dbg (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 7) { \ + if (cfg.c_dbg_lvl >= EROFS_DBG) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \
@@ -29,7 +37,7 @@ } while (0)#define erofs_info (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 3) { \ + if (cfg.c_dbg_lvl >= EROFS_INFO) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \
@@ -40,7 +48,7 @@ } while (0)#define erofs_warn (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 2) { \ + if (cfg.c_dbg_lvl >= EROFS_WARN) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \
@@ -51,7 +59,7 @@ } while (0)#define erofs_err (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 0) { \ + if (cfg.c_dbg_lvl >= EROFS_ERR) { \ fprintf(stderr, \ "Err: " pr_fmt(fmt), \ __func__, \
mkfs/main.c +8 -11
@@ -30,16 +30,6 @@ static void usage(void)fprintf (stderr," -EX[,...] X=extended options\n" ); } -u64 parse_num_from_str (const char *str) -{ -u64 num =0 ; -char *endptr =NULL ; - - num =strtoull (str, &endptr,10 ); -BUG_ON (num ==ULLONG_MAX ); -return num; -} -static int parse_extended_opts (const char *opts) {#define MATCH_EXTENTED_OPT (opt, token, keylen) \
@@ -108,7 +98,14 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])break ;case 'd' : - cfg.c_dbg_lvl =parse_num_from_str (optarg); + cfg.c_dbg_lvl =atoi (optarg); +if (cfg.c_dbg_lvl <EROFS_ERR + || cfg.c_dbg_lvl >EROFS_DBG_MAX ) { +fprintf (stderr, +"invalid debug level %d\n" , + cfg.c_dbg_lvl); +return -EINVAL ; + }break ;case 'E' :
Signature · 1 line
2.9.3
PATCH 1/1 erofs-utils: code for handling incorrect debug level.
Hi Pratik,
Quoted 10 lines · Pratik Shinde
handling the case of incorrect debug level. Added an enumerated type for supported debug levels. Using 'atoi' in place of '
parse_num_from_str'.I have dropped the check for invalid compression algo name(which was there in last patch)
Note:I think this patch covers different set of code changes than previous patch,Hence I am sending a new patch instead of 'v2' of previous patch.Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
It looks good to me, and I'd like to introduce "EROFS_MSG_MIN / EROFS_MSG_MAX" as well. Do you agree with these modifications attached below? :)
Thanks,
Gao Xiang
include/erofs/print.h +13 -4
@@ -12,6 +12,15 @@#include "config.h" #include <stdio.h> +enum { +EROFS_MSG_MIN =0 , +EROFS_ERR =0 , +EROFS_WARN =2 , +EROFS_INFO =3 , +EROFS_DBG =7 , +EROFS_MSG_MAX =9 +}; +#define FUNC_LINE_FMT "%s() Line[%d] "#ifndef pr_fmt
@@ -19,7 +28,7 @@#endif #define erofs_dbg (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 7) { \ + if (cfg.c_dbg_lvl >= EROFS_DBG) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \
@@ -29,7 +38,7 @@ } while (0)#define erofs_info (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 3) { \ + if (cfg.c_dbg_lvl >= EROFS_INFO) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \
@@ -40,7 +49,7 @@ } while (0)#define erofs_warn (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 2) { \ + if (cfg.c_dbg_lvl >= EROFS_WARN) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \
@@ -51,7 +60,7 @@ } while (0)#define erofs_err (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 0) { \ + if (cfg.c_dbg_lvl >= EROFS_ERR) { \ fprintf(stderr, \ "Err: " pr_fmt(fmt), \ __func__, \
mkfs/main.c +7 -11
@@ -30,16 +30,6 @@ static void usage(void)fprintf (stderr," -EX[,...] X=extended options\n" ); } -u64 parse_num_from_str (const char *str) -{ -u64 num =0 ; -char *endptr =NULL ; - - num =strtoull (str, &endptr,10 ); -BUG_ON (num ==ULLONG_MAX ); -return num; -} -static int parse_extended_opts (const char *opts) {#define MATCH_EXTENTED_OPT (opt, token, keylen) \
@@ -108,7 +98,13 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])break ;case 'd' : - cfg.c_dbg_lvl =parse_num_from_str (optarg); + cfg.c_dbg_lvl =atoi (optarg); +if (cfg.c_dbg_lvl <EROFS_MSG_MIN + || cfg.c_dbg_lvl >EROFS_MSG_MAX ) { +erofs_err ("invalid debug level %d" , + cfg.c_dbg_lvl); +return -EINVAL ; + }break ;case 'E' :
Signature · 1 line
2.17.1
PATCH 1/1 erofs-utils: code for handling incorrect debug level.
Hi Gao,
Yes, I will include those changes and resend the patch.
--Pratik.
Quoted 116 lines · Gao Xiang
Hi Pratik,
Quoted 5 lines · Pratik Shinde
handling the case of incorrect debug level. Added an enumerated type for supported debug levels. Using 'atoi' in place of '
parse_num_from_str'.I have dropped the check for invalid compression algo name(which was
there
Quoted 2 lines
in last patch)
Note:I think this patch covers different set of code changes thanprevious
Quoted 3 lines
patch,Hence I am sending a new patch instead of 'v2' of previous patch.
Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>It looks good to me, and I'd like to introduce "
EROFS_MSG_MIN/EROFS_MSG_MAX" as well.
Do you agree with these modifications attached below? :)Thanks,
Gao Xianginclude/erofs/print.h +13
-4@@ -12,6 +12,15 @@#include "config.h" #include <stdio.h> +enum { +EROFS_MSG_MIN =0 , +EROFS_ERR =0 , +EROFS_WARN =2 , +EROFS_INFO =3 , +EROFS_DBG =7 , +EROFS_MSG_MAX =9 +}; +#define FUNC_LINE_FMT "%s() Line[%d] "#ifndef pr_fmt@@ -19,7 +28,7 @@#endif #define erofs_dbg (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 7) { \ + if (cfg.c_dbg_lvl >= EROFS_DBG) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \@@ -29,7 +38,7 @@ } while (0)#define erofs_info (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 3) { \ + if (cfg.c_dbg_lvl >= EROFS_INFO) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \@@ -40,7 +49,7 @@ } while (0)#define erofs_warn (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 2) { \ + if (cfg.c_dbg_lvl >= EROFS_WARN) { \ fprintf(stdout, \ pr_fmt(fmt), \ __func__, \@@ -51,7 +60,7 @@ } while (0)#define erofs_err (fmt, ...) do { \ - if (cfg.c_dbg_lvl >= 0) { \ + if (cfg.c_dbg_lvl >= EROFS_ERR) { \ fprintf(stderr, \ "Err: " pr_fmt(fmt), \ __func__, \mkfs/main.c +7
-11@@ -30,16 +30,6 @@ static void usage(void)fprintf (stderr," -EX[,...] X=extended options\n" ); } -u64 parse_num_from_str (const char *str) -{ -u64 num =0 ; -char *endptr =NULL ; - - num =strtoull (str, &endptr,10 ); -BUG_ON (num ==ULLONG_MAX ); -return num; -} -static int parse_extended_opts (const char *opts) {#define MATCH_EXTENTED_OPT (opt, token, keylen) \@@ -108,7 +98,13 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) break;case 'd' : - cfg.c_dbg_lvl =parse_num_from_str (optarg); + cfg.c_dbg_lvl =atoi (optarg); +if (cfg.c_dbg_lvl <EROFS_MSG_MIN + || cfg.c_dbg_lvl >EROFS_MSG_MAX ) { +erofs_err ("invalid debug level %d" , + cfg.c_dbg_lvl); +return -EINVAL ; + }break ;case 'E':
Quoted 4 lines
--
2.17.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/linux-erofs/attachments/20190804/096c8598/attachment.htm>