Skip to contentSkip to conversation

erofs-utils: code for handling incorrect debug level.

PATCH Superseded Pratik Shinde 5 participants 11 messages Aug 4, 2019 – Aug 5, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 include/erofs/print.h | 18 +++++++++++++-----
 mkfs/main.c           | 19 ++++++++-----------
 2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,				\
@@ -64,4 +73,3 @@
 
 
 #endif
-
mkfs/main.c +8 -11
index fdb65fd..d915d00 100644
@@ -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_MSG_MIN
+			    || cfg.c_dbg_lvl > EROFS_MSG_MAX) {
+				fprintf(stderr,
+					"invalid debug level %d\n",
+					cfg.c_dbg_lvl);
+				return -EINVAL;
+			}
 			break;
 
 		case 'E':
Signature · 1 line
2.9.3
#1 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Quoted 93 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 include/erofs/print.h | 18 +++++++++++++-----
 mkfs/main.c           | 19 ++++++++-----------
 2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,				\
@@ -64,4 +73,3 @@
 
 
 #endif
-
mkfs/main.c +0 -10
index fdb65fd..d915d00 100644
@@ -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) \

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 106

Quoted 10 lines
mkfs/main.c +6 -1
@@ -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_MSG_MIN
+			    || cfg.c_dbg_lvl > EROFS_MSG_MAX) {
+				fprintf(stderr,
+					"invalid debug level %d\n",
+					cfg.c_dbg_lvl);

How about using erofs_err as my previous patch attached?
I wonder if there are some specfic reasons to directly use fprintf instead?

I will apply it with this minor fixup (no need to resend again), if you have other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -0
+				return -EINVAL;
+			}
 			break;
 
 		case 'E':
Signature · 1 line
2.9.3
#2 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Hi Gao,

I used fprintf here because we are printing this error message in case of invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to print the
error message using erofs_err() with c_dbg_lvl = -1,
it will not print anything.
While applying the minor fixup, just reset the c_dbg_lvl to 0 , so that
erofs_err() will be able to log the error message.

--Pratik.

Quoted 109 lines · Gao Xiang

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char

Quoted 93 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 include/erofs/print.h | 18 +++++++++++++-----
 mkfs/main.c           | 19 ++++++++-----------
 2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,                               \
@@ -64,4 +73,3 @@
 
 
 #endif
-
mkfs/main.c +0 -10
index fdb65fd..d915d00 100644
@@ -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[])

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 106

Quoted 10 lines
mkfs/main.c +6 -1
                      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) {
+                             fprintf(stderr,
+                                     "invalid debug level %d\n",
+                                     cfg.c_dbg_lvl);

How about using erofs_err as my previous patch attached?
I wonder if there are some specfic reasons to directly use fprintf instead?

Quoted 16 lines

I will apply it with this minor fixup (no need to resend again), if you have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                      break;
 
              case 'E':
--

2.9.3

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/linux-erofs/attachments/20190804/f5d04a4e/attachment.htm>

#3 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Hi Pratik,

Quoted 10 lines · Pratik Shinde

Hi Gao,

I used fprintf here because we are printing this error message in case of invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to print the
error message using erofs_err() with c_dbg_lvl = -1,
it will not print anything.

Yes, so c_dbg_lvl should be kept in default level (0) before checking its vaildity I think.

Quoted 2 lines

While applying the minor fixup, just reset the c_dbg_lvl to 0 , so that erofs_err() will be able to log the error message.

Since there could be some messages already printed with erofs_xxx before mkfs_parse_options_cfg(), I think we can use default level (0) before checking its vaildity and switch to the given level after it, as below:

case 'd':
- cfg.c_dbg_lvl = parse_num_from_str(optarg);
+ i = atoi(optarg);
+ if (i < EROFS_MSG_MIN || i > EROFS_MSG_MAX) {
+ erofs_err("invalid debug level %d", i);
+ return -EINVAL;
+ }
+ cfg.c_dbg_lvl = i;

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=26097242976cce68e21d8b569dfda63fb68f356c

Do you agree? :)

Thanks,
Gao Xiang

Quoted 131 lines

--Pratik.

Quoted 125 lines · Gao Xiang

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char

Quoted 93 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 include/erofs/print.h | 18 +++++++++++++-----
 mkfs/main.c           | 19 ++++++++-----------
 2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,                               \
@@ -64,4 +73,3 @@
 
 
 #endif
-
mkfs/main.c +0 -10
index fdb65fd..d915d00 100644
@@ -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[])

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 106

Quoted 10 lines
mkfs/main.c +6 -1
                      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) {
+                             fprintf(stderr,
+                                     "invalid debug level %d\n",
+                                     cfg.c_dbg_lvl);

How about using erofs_err as my previous patch attached?
I wonder if there are some specfic reasons to directly use fprintf instead?

I will apply it with this minor fixup (no need to resend again), if you have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                      break;
 
              case 'E':
--

2.9.3

#4 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Hi Gao,

I Agree with your suggestion. Thanks for the additional code change. I think thats pretty much our final patch. :)

-Pratik

Quoted 153 lines · Gao Xiang,

Hi Pratik,

Quoted 10 lines · Pratik Shinde

Hi Gao,

I used fprintf here because we are printing this error message in case of invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to print the
error message using erofs_err() with c_dbg_lvl = -1,
it will not print anything.

Yes, so c_dbg_lvl should be kept in default level (0) before checking its vaildity I think.

Quoted 2 lines

While applying the minor fixup, just reset the c_dbg_lvl to 0 , so that erofs_err() will be able to log the error message.

Since there could be some messages already printed with erofs_xxx before mkfs_parse_options_cfg(), I think we can use default level (0) before checking its vaildity and switch to the given level after it, as below:

                case 'd':
(quoted diff) +6 -1
-                       cfg.c_dbg_lvl = parse_num_from_str(optarg);
+                       i = atoi(optarg);
+                       if (i < EROFS_MSG_MIN || i > EROFS_MSG_MAX) {
+                               erofs_err("invalid debug level %d", i);
+                               return -EINVAL;
+                       }
+                       cfg.c_dbg_lvl = i;

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=26097242976cce68e21d8b569dfda63fb68f356c

Do you agree? :)

Thanks,
Gao Xiang

Quoted 112 lines

--Pratik.

Quoted 106 lines · Gao Xiang

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char

Quoted 93 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 include/erofs/print.h | 18 +++++++++++++-----
 mkfs/main.c           | 19 ++++++++-----------
 2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,                               \
@@ -64,4 +73,3 @@
 
 
 #endif
-
mkfs/main.c +0 -10
index fdb65fd..d915d00 100644
@@ -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[])

Quoted 10 lines
mkfs/main.c +6 -1
                      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) {
+                             fprintf(stderr,
+                                     "invalid debug level %d\n",
+                                     cfg.c_dbg_lvl);
Quoted 21 lines
Quoted 2 lines
Quoted 2 lines

How about using erofs_err as my previous patch attached? I wonder if there are some specfic reasons to directly use fprintf

instead?

Quoted 17 lines
Quoted 17 lines

I will apply it with this minor fixup (no need to resend again), if you have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                      break;
 
              case 'E':
--

2.9.3

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/linux-erofs/attachments/20190804/71f12240/attachment.htm>

#5 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Shinde and Gao
Does the variable name of debug level use another name ? like d ? The i is usual a temporary increase or decrease self variable.

? 2019/8/4 19:39, Pratik Shinde ??:

Quoted 184 lines

Hi Gao,

I Agree with your suggestion. Thanks for the additional code change. I think thats pretty much our final patch. :)

-Pratik

Quoted 174 lines · Gao Xiang,

Hi Pratik,

Quoted 10 lines · Pratik Shinde

Hi Gao,

I used fprintf here because we are printing this error message in case of invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to print the
error message using erofs_err() with c_dbg_lvl = -1,
it will not print anything.

Yes, so c_dbg_lvl should be kept in default level (0) before checking its vaildity I think.

Quoted 2 lines

While applying the minor fixup, just reset the c_dbg_lvl to 0 , so that erofs_err() will be able to log the error message.

Since there could be some messages already printed with erofs_xxx before mkfs_parse_options_cfg(), I think we can use default level (0) before checking its vaildity and switch to the given level after it, as below:

                 case 'd':
(quoted diff) +6 -1
-                       cfg.c_dbg_lvl = parse_num_from_str(optarg);
+                       i = atoi(optarg);
+                       if (i < EROFS_MSG_MIN || i > EROFS_MSG_MAX) {
+                               erofs_err("invalid debug level %d", i);
+                               return -EINVAL;
+                       }
+                       cfg.c_dbg_lvl = i;

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=26097242976cce68e21d8b569dfda63fb68f356c

Do you agree? :)

Thanks,
Gao Xiang

Quoted 114 lines

--Pratik.

Quoted 108 lines · Gao Xiang

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char

Quoted 93 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
  include/erofs/print.h | 18 +++++++++++++-----
  mkfs/main.c           | 19 ++++++++-----------
  2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,                               \
@@ -64,4 +73,3 @@
 
 
  #endif
-
mkfs/main.c +0 -10
index fdb65fd..d915d00 100644
@@ -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[])

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 106

Quoted 10 lines
mkfs/main.c +6 -1
                       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) {
+                             fprintf(stderr,
+                                     "invalid debug level %d\n",
+                                     cfg.c_dbg_lvl);

How about using erofs_err as my previous patch attached? I wonder if there are some specfic reasons to directly use fprintf

instead?

Quoted 17 lines
Quoted 17 lines

I will apply it with this minor fixup (no need to resend again), if you have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                       break;
 
               case 'E':
--

2.9.3

#6 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Hi Guifu,

Quoted 3 lines · Li Guifu

Shinde and Gao
Does the variable name of debug level use another name ? like d ? The i is usual a temporary increase or decrease self variable.

I think we can use a common varible name in order to avoid too many temporary variables, maybe i' is not the best naming, but i' also stands for "a integer".

Maybe we can give a better naming? can you name it and submit another patch? I personally don't like define too many used-once variables... How do you think?

Thanks,
Gao Xiang

Quoted 186 lines

?? 2019/8/4 19:39, Pratik Shinde ????:

Quoted 184 lines

Hi Gao,

I Agree with your suggestion. Thanks for the additional code change. I think thats pretty much our final patch. :)

-Pratik

Quoted 174 lines · Gao Xiang,

Hi Pratik,

Quoted 10 lines · Pratik Shinde

Hi Gao,

I used fprintf here because we are printing this error message in case of invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to print the
error message using erofs_err() with c_dbg_lvl = -1,
it will not print anything.

Yes, so c_dbg_lvl should be kept in default level (0) before checking its vaildity I think.

Quoted 2 lines

While applying the minor fixup, just reset the c_dbg_lvl to 0 , so that erofs_err() will be able to log the error message.

Since there could be some messages already printed with erofs_xxx before mkfs_parse_options_cfg(), I think we can use default level (0) before checking its vaildity and switch to the given level after it, as below:

                 case 'd':
(quoted diff) +6 -1
-                       cfg.c_dbg_lvl = parse_num_from_str(optarg);
+                       i = atoi(optarg);
+                       if (i < EROFS_MSG_MIN || i > EROFS_MSG_MAX) {
+                               erofs_err("invalid debug level %d", i);
+                               return -EINVAL;
+                       }
+                       cfg.c_dbg_lvl = i;

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=26097242976cce68e21d8b569dfda63fb68f356c

Do you agree? :)

Thanks,
Gao Xiang

Quoted 114 lines

--Pratik.

Quoted 108 lines · Gao Xiang

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char

Quoted 93 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
  include/erofs/print.h | 18 +++++++++++++-----
  mkfs/main.c           | 19 ++++++++-----------
  2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,                               \
@@ -64,4 +73,3 @@
 
 
  #endif
-
mkfs/main.c +0 -10
index fdb65fd..d915d00 100644
@@ -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[])

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char *argv[]) · line 106

Quoted 10 lines
mkfs/main.c +6 -1
                       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) {
+                             fprintf(stderr,
+                                     "invalid debug level %d\n",
+                                     cfg.c_dbg_lvl);

How about using erofs_err as my previous patch attached? I wonder if there are some specfic reasons to directly use fprintf

instead?

Quoted 17 lines
Quoted 17 lines

I will apply it with this minor fixup (no need to resend again), if you have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                       break;
 
               case 'E':
--

2.9.3

#7 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

GAO
it's a good suggest, you're right

? 2019/8/4 23:25, Gao Xiang ??:

Quoted 204 lines

Hi Guifu,

Quoted 3 lines · Li Guifu

Shinde and Gao
Does the variable name of debug level use another name ? like d ? The i is usual a temporary increase or decrease self variable.

I think we can use a common varible name in order to avoid too many temporary variables, maybe i' is not the best naming, but i' also stands for "a integer".

Maybe we can give a better naming? can you name it and submit another patch? I personally don't like define too many used-once variables... How do you think?

Thanks,
Gao Xiang

Quoted 186 lines

?? 2019/8/4 19:39, Pratik Shinde ????:

Quoted 184 lines

Hi Gao,

I Agree with your suggestion. Thanks for the additional code change. I think thats pretty much our final patch. :)

-Pratik

Quoted 174 lines · Gao Xiang,

Hi Pratik,

Quoted 10 lines · Pratik Shinde

Hi Gao,

I used fprintf here because we are printing this error message in case of invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to print the
error message using erofs_err() with c_dbg_lvl = -1,
it will not print anything.

Yes, so c_dbg_lvl should be kept in default level (0) before checking its vaildity I think.

Quoted 2 lines

While applying the minor fixup, just reset the c_dbg_lvl to 0 , so that erofs_err() will be able to log the error message.

Since there could be some messages already printed with erofs_xxx before mkfs_parse_options_cfg(), I think we can use default level (0) before checking its vaildity and switch to the given level after it, as below:

                  case 'd':
(quoted diff) +6 -1
-                       cfg.c_dbg_lvl = parse_num_from_str(optarg);
+                       i = atoi(optarg);
+                       if (i < EROFS_MSG_MIN || i > EROFS_MSG_MAX) {
+                               erofs_err("invalid debug level %d", i);
+                               return -EINVAL;
+                       }
+                       cfg.c_dbg_lvl = i;

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=26097242976cce68e21d8b569dfda63fb68f356c

Do you agree? :)

Thanks,
Gao Xiang

Quoted 114 lines

--Pratik.

Quoted 108 lines · Gao Xiang

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char

Quoted 93 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
   include/erofs/print.h | 18 +++++++++++++-----
   mkfs/main.c           | 19 ++++++++-----------
   2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,                               \
@@ -64,4 +73,3 @@
 
 
   #endif
-
mkfs/main.c +0 -10
index fdb65fd..d915d00 100644
@@ -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[])

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char · line 106

Quoted 10 lines
mkfs/main.c +6 -1
                        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) {
+                             fprintf(stderr,
+                                     "invalid debug level %d\n",
+                                     cfg.c_dbg_lvl);

How about using erofs_err as my previous patch attached? I wonder if there are some specfic reasons to directly use fprintf

instead?

Quoted 17 lines
Quoted 17 lines

I will apply it with this minor fixup (no need to resend again), if you have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                        break;
 
                case 'E':
--

2.9.3

#8 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Hi Guifu,

Quoted 2 lines · Li Guifu

GAO
it's a good suggest, you're right

I know that you don't have outgoing email permission when you are at work. I think you need to request this permission from your boss again.

And could you take some spare time off work and review erofs-utils patches? That is of great help to erofs community. :)

Thanks,
Gao Xiang

Quoted 206 lines

?? 2019/8/4 23:25, Gao Xiang ????:

Quoted 204 lines

Hi Guifu,

Quoted 3 lines · Li Guifu

Shinde and Gao
Does the variable name of debug level use another name ? like d ? The i is usual a temporary increase or decrease self variable.

I think we can use a common varible name in order to avoid too many temporary variables, maybe i' is not the best naming, but i' also stands for "a integer".

Maybe we can give a better naming? can you name it and submit another patch? I personally don't like define too many used-once variables... How do you think?

Thanks,
Gao Xiang

Quoted 186 lines

?? 2019/8/4 19:39, Pratik Shinde ????:

Quoted 184 lines

Hi Gao,

I Agree with your suggestion. Thanks for the additional code change. I think thats pretty much our final patch. :)

-Pratik

Quoted 174 lines · Gao Xiang,

Hi Pratik,

Quoted 10 lines · Pratik Shinde

Hi Gao,

I used fprintf here because we are printing this error message in case of invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to print the
error message using erofs_err() with c_dbg_lvl = -1,
it will not print anything.

Yes, so c_dbg_lvl should be kept in default level (0) before checking its vaildity I think.

Quoted 2 lines

While applying the minor fixup, just reset the c_dbg_lvl to 0 , so that erofs_err() will be able to log the error message.

Since there could be some messages already printed with erofs_xxx before mkfs_parse_options_cfg(), I think we can use default level (0) before checking its vaildity and switch to the given level after it, as below:

                  case 'd':
(quoted diff) +6 -1
-                       cfg.c_dbg_lvl = parse_num_from_str(optarg);
+                       i = atoi(optarg);
+                       if (i < EROFS_MSG_MIN || i > EROFS_MSG_MAX) {
+                               erofs_err("invalid debug level %d", i);
+                               return -EINVAL;
+                       }
+                       cfg.c_dbg_lvl = i;

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=26097242976cce68e21d8b569dfda63fb68f356c

Do you agree? :)

Thanks,
Gao Xiang

Quoted 114 lines

--Pratik.

Quoted 108 lines · Gao Xiang

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char

Quoted 93 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'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
   include/erofs/print.h | 18 +++++++++++++-----
   mkfs/main.c           | 19 ++++++++-----------
   2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +13 -5
index bc0b8d4..296cbbf 100644
@@ -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__,                               \
@@ -64,4 +73,3 @@
 
 
   #endif
-
mkfs/main.c +0 -10
index fdb65fd..d915d00 100644
@@ -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[])

mkfs/main.c static int mkfs_parse_options_cfg(int argc, char · line 106

Quoted 10 lines
mkfs/main.c +6 -1
                        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) {
+                             fprintf(stderr,
+                                     "invalid debug level %d\n",
+                                     cfg.c_dbg_lvl);

How about using erofs_err as my previous patch attached? I wonder if there are some specfic reasons to directly use fprintf

instead?

Quoted 17 lines
Quoted 17 lines

I will apply it with this minor fixup (no need to resend again), if you have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                        break;
 
                case 'E':
--

2.9.3

#9 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Hi Gao & Guifu,

In order to eliminate use of a temp variable, I think we can safely do following:

    case 'd':
                        cfg.c_dbg_lvl = atoi(optarg);
                        if (cfg.c_dbg_lvl < EROFS_MSG_MIN
                            || cfg.c_dbg_lvl > EROFS_MSG_MAX) {
                                cfg.c_dbg_lvl = 0;      // reset the value
of debug level to '0'
                                erofs_err("invalid debug level %d\n",
                                        atoi(optarg));
                                return -EINVAL;
                        }
                        break;

I found this version much cleaner. Although it involves extra call to atoi(). but thats trivial.
Let me know your thoughts.

Quoted 240 lines · Gao Xiang

Hi Guifu,

Quoted 2 lines · Li Guifu

GAO
it's a good suggest, you're right

I know that you don't have outgoing email permission when you are at work. I think you need to request this permission from your boss again.

And could you take some spare time off work and review erofs-utils patches? That is of great help to erofs community. :)

Thanks,
Gao Xiang

Quoted 25 lines

?? 2019/8/4 23:25, Gao Xiang ????:

Quoted 23 lines

Hi Guifu,

Quoted 3 lines · Li Guifu

Shinde and Gao
Does the variable name of debug level use another name ? like d ? The i is usual a temporary increase or decrease self variable.

I think we can use a common varible name in order to avoid too many temporary variables, maybe i' is not the best naming, but i' also stands for "a integer".

Maybe we can give a better naming? can you name it and submit another patch? I personally don't like define too many used-once variables... How do you think?

Thanks,
Gao Xiang

Quoted 5 lines

?? 2019/8/4 19:39, Pratik Shinde ????:

Quoted 3 lines

Hi Gao,

I Agree with your suggestion. Thanks for the additional code

change. I

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

think thats pretty much our final patch. :)

-Pratik

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Gao Xiang,
Quoted 7 lines

Hi Pratik,

Quoted 3 lines · Pratik Shinde

Hi Gao,

I used fprintf here because we are printing this error message

in case of

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to

print the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

error message using erofs_err() with c_dbg_lvl = -1, it will not print anything.

Yes, so c_dbg_lvl should be kept in default level (0) before checking its vaildity I think.

Quoted 1 line

While applying the minor fixup, just reset the c_dbg_lvl to 0

, so that

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

erofs_err() will be able to log the error message.

Since there could be some messages already printed with

erofs_xxx before

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

mkfs_parse_options_cfg(), I think we can use default level (0)

before

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

checking its vaildity and switch to the given level after it, as

below:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
                  case 'd':

- cfg.c_dbg_lvl =

parse_num_from_str(optarg);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       i = atoi(optarg);
+                       if (i < EROFS_MSG_MIN || i >

EROFS_MSG_MAX) {

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ erofs_err("invalid debug level

%d", i);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
(quoted diff) +3 -0
+                               return -EINVAL;
+                       }
+                       cfg.c_dbg_lvl = i;

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=26097242976cce68e21d8b569dfda63fb68f356c

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Do you agree? :)

Thanks,
Gao Xiang

Quoted 5 lines

--Pratik.

On Sun, Aug 4, 2019 at 3:47 PM Gao Xiang <hsiangkao at aol.com>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On Sun, Aug 04, 2019 at 01:49:43PM +0530, Pratik Shinde

Quoted 29 lines · wrote:
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

handling the case of incorrect debug level. Added an enumerated type for supported debug levels. Using 'atoi' in place of 'parse_num_from_str'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
   include/erofs/print.h | 18 +++++++++++++-----
   mkfs/main.c           | 19 ++++++++-----------
   2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +9 -0
index bc0b8d4..296cbbf 100644
@@ -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] "
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/erofs/print.h line 30

Quoted 5 lines
include/erofs/print.h +0 -0
   #ifndef pr_fmt
@@ -19,7 +28,7 @@
   #endif
 
   #define erofs_dbg(fmt, ...) do {
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 22

Quoted 1 line
include/erofs/print.h +0 -1
-     if (cfg.c_dbg_lvl >= 7) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 31

Quoted 1 line
include/erofs/print.h +1 -0
+     if (cfg.c_dbg_lvl >= EROFS_DBG) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 32

Quoted 1 line
include/erofs/print.h +0 -0
                fprintf(stdout,
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 33

Quoted 1 line
include/erofs/print.h +0 -0
                        pr_fmt(fmt),
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 34

Quoted 1 line
include/erofs/print.h +0 -0
                        __func__,
     \
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

include/erofs/print.h line 40

Quoted 4 lines
include/erofs/print.h +0 -0
@@ -29,7 +38,7 @@
   } while (0)
 
   #define erofs_info(fmt, ...) do {
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 32

Quoted 1 line
include/erofs/print.h +0 -1
-     if (cfg.c_dbg_lvl >= 3) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 41

Quoted 1 line
include/erofs/print.h +1 -0
+     if (cfg.c_dbg_lvl >= EROFS_INFO) {
    \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 42

Quoted 1 line
include/erofs/print.h +0 -0
                fprintf(stdout,
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 43

Quoted 1 line
include/erofs/print.h +0 -0
                        pr_fmt(fmt),
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 44

Quoted 1 line
include/erofs/print.h +0 -0
                        __func__,
     \
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

include/erofs/print.h line 51

Quoted 4 lines
include/erofs/print.h +0 -0
@@ -40,7 +49,7 @@
   } while (0)
 
   #define erofs_warn(fmt, ...) do {
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 43

Quoted 1 line
include/erofs/print.h +0 -1
-     if (cfg.c_dbg_lvl >= 2) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 52

Quoted 1 line
include/erofs/print.h +1 -0
+     if (cfg.c_dbg_lvl >= EROFS_WARN) {
    \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 53

Quoted 1 line
include/erofs/print.h +0 -0
                fprintf(stdout,
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 54

Quoted 1 line
include/erofs/print.h +0 -0
                        pr_fmt(fmt),
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 55

Quoted 1 line
include/erofs/print.h +0 -0
                        __func__,
     \
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

include/erofs/print.h line 62

Quoted 4 lines
include/erofs/print.h +0 -0
@@ -51,7 +60,7 @@
   } while (0)
 
   #define erofs_err(fmt, ...) do {
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 54

Quoted 1 line
include/erofs/print.h +0 -1
-     if (cfg.c_dbg_lvl >= 0) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 63

Quoted 1 line
include/erofs/print.h +1 -0
+     if (cfg.c_dbg_lvl >= EROFS_ERR) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 64

Quoted 1 line
include/erofs/print.h +0 -0
                fprintf(stderr,
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 65

Quoted 1 line
include/erofs/print.h +0 -0
                        "Err: " pr_fmt(fmt),
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 66

Quoted 1 line
include/erofs/print.h +0 -0
                        __func__,
     \
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
include/erofs/print.h +0 -1
@@ -64,4 +73,3 @@
 
 
   #endif
-
mkfs/main.c +0 -0
index fdb65fd..d915d00 100644
@@ -30,16 +30,6 @@ static void usage(void)
        fprintf(stderr, " -EX[,...] X=extended options\n");
   }
 
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mkfs/main.c +0 -6
-u64 parse_num_from_str(const char *str)
-{
-     u64 num      = 0;
-     char *endptr = NULL;
-
-     num = strtoull(str, &endptr, 10);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

mkfs/main.c static int mkfs_parse_options_cfg(int

Quoted 8 lines
mkfs/main.c +0 -4
-     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

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

*argv[])

Quoted 4 lines
mkfs/main.c +0 -1
                        break;
 
                case 'd':
-                     cfg.c_dbg_lvl =

parse_num_from_str(optarg);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mkfs/main.c static int mkfs_parse_options_cfg(int · line 103

Quoted 3 lines
mkfs/main.c +3 -0
+                     cfg.c_dbg_lvl = atoi(optarg);
+                     if (cfg.c_dbg_lvl < EROFS_MSG_MIN
+                         || cfg.c_dbg_lvl >

EROFS_MSG_MAX) {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

mkfs/main.c static int mkfs_parse_options_cfg(int · line 105

Quoted 2 lines
mkfs/main.c +2 -0
+                             fprintf(stderr,
+                                     "invalid debug level

%d\n",

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
mkfs/main.c +1 -0
+                                     cfg.c_dbg_lvl);
Quoted 25 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

How about using erofs_err as my previous patch attached? I wonder if there are some specfic reasons to directly use

fprintf

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

instead?

Quoted 2 lines
Quoted 2 lines

I will apply it with this minor fixup (no need to resend

again), if you

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines

have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                        break;
 
                case 'E':
--

2.9.3

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/linux-erofs/attachments/20190805/a1eaace9/attachment.htm>

#10 lore raw

PATCH v2 1/1 erofs-utils: code for handling incorrect debug level.

Hi Pratik,

Quoted 11 lines · Pratik Shinde

Hi Gao & Guifu,

In order to eliminate use of a temp variable, I think we can safely do following:

    case 'd':
                        cfg.c_dbg_lvl = atoi(optarg);
                        if (cfg.c_dbg_lvl < EROFS_MSG_MIN
                            || cfg.c_dbg_lvl > EROFS_MSG_MAX) {
                                cfg.c_dbg_lvl = 0;      // reset the value

of debug level to '0'

The default level is set in erofs_init_configure() in config.c by design, and no need to reset again (BTW, the default value could not be 0, maybe 9 or even -1 to for silent mode in the future).

Saving the old value before could help, but I think in that way we need to introduce another temp variable to save old default value.

I think that is minor, if there are better names here, we can rename i', or you can submit another patch to introduce another temp variable to replace i'.

Thanks,
Gao Xiang

Quoted 278 lines
                                erofs_err("invalid debug level %d\n",
                                        atoi(optarg));
                                return -EINVAL;
                        }
                        break;

I found this version much cleaner. Although it involves extra call to atoi(). but thats trivial.
Let me know your thoughts.

Quoted 265 lines · Gao Xiang

Hi Guifu,

Quoted 2 lines · Li Guifu

GAO
it's a good suggest, you're right

I know that you don't have outgoing email permission when you are at work. I think you need to request this permission from your boss again.

And could you take some spare time off work and review erofs-utils patches? That is of great help to erofs community. :)

Thanks,
Gao Xiang

Quoted 25 lines

?? 2019/8/4 23:25, Gao Xiang ????:

Quoted 23 lines

Hi Guifu,

Quoted 3 lines · Li Guifu

Shinde and Gao
Does the variable name of debug level use another name ? like d ? The i is usual a temporary increase or decrease self variable.

I think we can use a common varible name in order to avoid too many temporary variables, maybe i' is not the best naming, but i' also stands for "a integer".

Maybe we can give a better naming? can you name it and submit another patch? I personally don't like define too many used-once variables... How do you think?

Thanks,
Gao Xiang

Quoted 5 lines

?? 2019/8/4 19:39, Pratik Shinde ????:

Quoted 3 lines

Hi Gao,

I Agree with your suggestion. Thanks for the additional code

change. I

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

think thats pretty much our final patch. :)

-Pratik

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · Gao Xiang,
Quoted 7 lines

Hi Pratik,

Quoted 3 lines · Pratik Shinde

Hi Gao,

I used fprintf here because we are printing this error message

in case of

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

invalid 'cfg.c_dbg_lvl'. Hence I thought
we cannot rely on erofs_err().
e.g

$ mkfs.erofs -d -1 <erofs image> <directory>
In this case debug level is '-1' which is invalid.If we try to

print the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

error message using erofs_err() with c_dbg_lvl = -1, it will not print anything.

Yes, so c_dbg_lvl should be kept in default level (0) before checking its vaildity I think.

Quoted 1 line

While applying the minor fixup, just reset the c_dbg_lvl to 0

, so that

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

erofs_err() will be able to log the error message.

Since there could be some messages already printed with

erofs_xxx before

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

mkfs_parse_options_cfg(), I think we can use default level (0)

before

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

checking its vaildity and switch to the given level after it, as

below:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
                  case 'd':

- cfg.c_dbg_lvl =

parse_num_from_str(optarg);

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+                       i = atoi(optarg);
+                       if (i < EROFS_MSG_MIN || i >

EROFS_MSG_MAX) {

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ erofs_err("invalid debug level

%d", i);

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
(quoted diff) +3 -0
+                               return -EINVAL;
+                       }
+                       cfg.c_dbg_lvl = i;

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?h=dev&id=26097242976cce68e21d8b569dfda63fb68f356c

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Do you agree? :)

Thanks,
Gao Xiang

Quoted 5 lines

--Pratik.

On Sun, Aug 4, 2019 at 3:47 PM Gao Xiang <hsiangkao at aol.com>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

On Sun, Aug 04, 2019 at 01:49:43PM +0530, Pratik Shinde

Quoted 29 lines · wrote:
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines

handling the case of incorrect debug level. Added an enumerated type for supported debug levels. Using 'atoi' in place of 'parse_num_from_str'.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
   include/erofs/print.h | 18 +++++++++++++-----
   mkfs/main.c           | 19 ++++++++-----------
   2 files changed, 21 insertions(+), 16 deletions(-)
include/erofs/print.h +9 -0
index bc0b8d4..296cbbf 100644
@@ -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] "
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/erofs/print.h line 30

Quoted 5 lines
include/erofs/print.h +0 -0
   #ifndef pr_fmt
@@ -19,7 +28,7 @@
   #endif
 
   #define erofs_dbg(fmt, ...) do {
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 22

Quoted 1 line
include/erofs/print.h +0 -1
-     if (cfg.c_dbg_lvl >= 7) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 31

Quoted 1 line
include/erofs/print.h +1 -0
+     if (cfg.c_dbg_lvl >= EROFS_DBG) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 32

Quoted 1 line
include/erofs/print.h +0 -0
                fprintf(stdout,
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 33

Quoted 1 line
include/erofs/print.h +0 -0
                        pr_fmt(fmt),
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 34

Quoted 1 line
include/erofs/print.h +0 -0
                        __func__,
     \
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

include/erofs/print.h line 40

Quoted 4 lines
include/erofs/print.h +0 -0
@@ -29,7 +38,7 @@
   } while (0)
 
   #define erofs_info(fmt, ...) do {
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 32

Quoted 1 line
include/erofs/print.h +0 -1
-     if (cfg.c_dbg_lvl >= 3) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 41

Quoted 1 line
include/erofs/print.h +1 -0
+     if (cfg.c_dbg_lvl >= EROFS_INFO) {
    \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 42

Quoted 1 line
include/erofs/print.h +0 -0
                fprintf(stdout,
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 43

Quoted 1 line
include/erofs/print.h +0 -0
                        pr_fmt(fmt),
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 44

Quoted 1 line
include/erofs/print.h +0 -0
                        __func__,
     \
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

include/erofs/print.h line 51

Quoted 4 lines
include/erofs/print.h +0 -0
@@ -40,7 +49,7 @@
   } while (0)
 
   #define erofs_warn(fmt, ...) do {
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 43

Quoted 1 line
include/erofs/print.h +0 -1
-     if (cfg.c_dbg_lvl >= 2) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 52

Quoted 1 line
include/erofs/print.h +1 -0
+     if (cfg.c_dbg_lvl >= EROFS_WARN) {
    \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 53

Quoted 1 line
include/erofs/print.h +0 -0
                fprintf(stdout,
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 54

Quoted 1 line
include/erofs/print.h +0 -0
                        pr_fmt(fmt),
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 55

Quoted 1 line
include/erofs/print.h +0 -0
                        __func__,
     \
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

include/erofs/print.h line 62

Quoted 4 lines
include/erofs/print.h +0 -0
@@ -51,7 +60,7 @@
   } while (0)
 
   #define erofs_err(fmt, ...) do {
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 54

Quoted 1 line
include/erofs/print.h +0 -1
-     if (cfg.c_dbg_lvl >= 0) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 63

Quoted 1 line
include/erofs/print.h +1 -0
+     if (cfg.c_dbg_lvl >= EROFS_ERR) {

\

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 64

Quoted 1 line
include/erofs/print.h +0 -0
                fprintf(stderr,
     \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 65

Quoted 1 line
include/erofs/print.h +0 -0
                        "Err: " pr_fmt(fmt),
      \
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

include/erofs/print.h line 66

Quoted 1 line
include/erofs/print.h +0 -0
                        __func__,
     \
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
include/erofs/print.h +0 -1
@@ -64,4 +73,3 @@
 
 
   #endif
-
mkfs/main.c +0 -0
index fdb65fd..d915d00 100644
@@ -30,16 +30,6 @@ static void usage(void)
        fprintf(stderr, " -EX[,...] X=extended options\n");
   }
 
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mkfs/main.c +0 -6
-u64 parse_num_from_str(const char *str)
-{
-     u64 num      = 0;
-     char *endptr = NULL;
-
-     num = strtoull(str, &endptr, 10);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

mkfs/main.c static int mkfs_parse_options_cfg(int

Quoted 8 lines
mkfs/main.c +0 -4
-     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

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

*argv[])

Quoted 4 lines
mkfs/main.c +0 -1
                        break;
 
                case 'd':
-                     cfg.c_dbg_lvl =

parse_num_from_str(optarg);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mkfs/main.c static int mkfs_parse_options_cfg(int · line 103

Quoted 3 lines
mkfs/main.c +3 -0
+                     cfg.c_dbg_lvl = atoi(optarg);
+                     if (cfg.c_dbg_lvl < EROFS_MSG_MIN
+                         || cfg.c_dbg_lvl >

EROFS_MSG_MAX) {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

mkfs/main.c static int mkfs_parse_options_cfg(int · line 105

Quoted 2 lines
mkfs/main.c +2 -0
+                             fprintf(stderr,
+                                     "invalid debug level

%d\n",

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

mkfs/main.c static int mkfs_parse_options_cfg(int · line 106

Quoted 1 line
mkfs/main.c +1 -0
+                                     cfg.c_dbg_lvl);

How about using erofs_err as my previous patch attached? I wonder if there are some specfic reasons to directly use

fprintf

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

instead?

Quoted 2 lines
Quoted 2 lines

I will apply it with this minor fixup (no need to resend

again), if you

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 15 lines
Quoted 15 lines

have
other considerations, reply me in this thread, thanks. :)

Thanks,
Gao Xiang

Quoted 8 lines
mkfs/main.c +2 -1
+                             return -EINVAL;
+                     }
                        break;
 
                case 'E':
--

2.9.3