Skip to contentSkip to conversation

erofs-utils: error handling for incorrect dbg lvl & compression algorithm

PATCH New Pratik Shinde 2 participants 3 messages Aug 1, 2019 – Aug 2, 2019 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: error handling for incorrect dbg lvl & compression algorithm

handling the case of incorrect debug level. also, an early check for valid compression algorithm.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 mkfs/main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mkfs/main.c +12 -0
index fdb65fd..4231d13 100644
@@ -105,10 +105,22 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 				}
 			}
 			cfg.c_compr_alg_master = strndup(optarg, i);
+			if (strcmp(cfg.c_compr_alg_master, "lz4")
+			    && strcmp(cfg.c_compr_alg_master, "lz4hc")) {
+				erofs_err("invalid compressor algorithm %s",
+					  cfg.c_compr_alg_master);
+				return -EINVAL;
+			}
 			break;
 
 		case 'd':
 			cfg.c_dbg_lvl = parse_num_from_str(optarg);
+			if (cfg.c_dbg_lvl < 0 || cfg.c_dbg_lvl > 9) {
+				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 1/1 erofs-utils: error handling for incorrect dbg lvl & compression algorithm

Hi Pratik,

Quoted 13 lines · Pratik Shinde

handling the case of incorrect debug level. also, an early check for valid compression algorithm.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 mkfs/main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mkfs/main.c +0 -0
index fdb65fd..4231d13 100644

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

Quoted 9 lines
mkfs/main.c +6 -0
@@ -105,10 +105,22 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 				}
 			}
 			cfg.c_compr_alg_master = strndup(optarg, i);
+			if (strcmp(cfg.c_compr_alg_master, "lz4")
+			    && strcmp(cfg.c_compr_alg_master, "lz4hc")) {
+				erofs_err("invalid compressor algorithm %s",
+					  cfg.c_compr_alg_master);
+				return -EINVAL;
+			}

It should be do in the compressors, and we have:
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/tree/lib/compressor.c?h=dev#n74

I'd like to know if some problems are out with the above code...

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

Quoted 5 lines
mkfs/main.c +1 -0
 			break;
 
 		case 'd':
 			cfg.c_dbg_lvl = parse_num_from_str(optarg);
+			if (cfg.c_dbg_lvl < 0 || cfg.c_dbg_lvl > 9) {

I think we cannot directly do like the above since
not all compression algorithm levels are 0~9 (and the default level could be -1). take a look at struct erofs_compressor and it has

	int default_level;
	int best_level;

I think maybe we have to define "worst_level" as well, and
it could be better do the above check in "int z_erofs_compress_init(void)"

Thanks,
Gao Xiang

Quoted 11 lines
mkfs/main.c +5 -0
+				fprintf(stderr,
+					"invalid debug level %d\n",
+					cfg.c_dbg_lvl);
+				return -EINVAL;
+			}
 			break;
 
 		case 'E':
Signature · 1 line
2.9.3

A message that is not in the archive (sent off-list or not yet received): CAGu0czT-HLnhAKQV6OhtgNu83fGDdHKu7+NZK15m-K7md3zVUQ@mail.gmail.com

#3 lore raw

PATCH 1/1 erofs-utils: error handling for incorrect dbg lvl & compression algorithm

[maybe better to add linux-erofs to record all the discusssions...]

Quoted 5 lines · Pratik Shinde

Hi Gao,

I think you misunderstood, the code change is for 'debug level' and not 'compressor level'. whose valid range is 0-9.
otherwise erofs_err() will not print anything.

Sorry... You are right and I think it is useful, but could you use another way rather than hard-coded "0-9" directly? maybe we need to update include/erofs/print.h as well to avoid hard-coded "such cfg.c_dbg_lvl >= 7"...

maybe it could be

enum {
	EROFS_ERR = 0,
	....
	EROFS_DEBUG = 9,
};
Quoted 5 lines

Regarding the check for compressor algorithm name: the current code has no problem, I just thought it will be good
valid it in mkfs_parse_options_cfg() itself. In the current code, its detected after we allocate entire super-block buffer.
thats the reason why I mentioned 'early check'.

Hmmm... I think there are little difference, if it really needs, how about adding a callback in compressor call .show_name() to avoid hard-code as well...

(IMO, I think there is little difference checking in z_erofs_compress_init() later, rare prople care about buffer init :)...)

Thanks,
Gao Xiang

Quoted 69 lines

--Pratik.

Quoted 64 lines · Gao Xiang

Hi Pratik,

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

Quoted 13 lines · Pratik Shinde

handling the case of incorrect debug level. also, an early check for valid compression algorithm.

Signed-off-by Pratik Shinde <pratikshinde320 at gmail.com>
---
 mkfs/main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
mkfs/main.c +0 -0
index fdb65fd..4231d13 100644
@@ -105,10 +105,22 @@ static int mkfs_parse_options_cfg(int argc, char

*argv[])

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

Quoted 6 lines
mkfs/main.c +3 -0
                              }
                      }
                      cfg.c_compr_alg_master = strndup(optarg, i);
+                     if (strcmp(cfg.c_compr_alg_master, "lz4")
+                         && strcmp(cfg.c_compr_alg_master, "lz4hc")) {
+                             erofs_err("invalid compressor algorithm

%s",

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

Quoted 3 lines
mkfs/main.c +3 -0
+                                       cfg.c_comprz_erofs_compress_init_alg_master);
+                             return -EINVAL;
+                     }

It should be do in the compressors, and we have:

https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/tree/lib/compressor.c?h=dev#n74

I'd like to know if some problems are out with the above code...

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

Quoted 5 lines
mkfs/main.c +1 -0
                      break;
 
              case 'd':
                      cfg.c_dbg_lvl = parse_num_from_str(optarg);
+                     if (cfg.c_dbg_lvl < 0 || cfg.c_dbg_lvl > 9) {

I think we cannot directly do like the above since
not all compression algorithm levels are 0~9 (and the default level could be -1).
take a look at struct erofs_compressor and it has

        int default_level;
        int best_level;

I think maybe we have to define "worst_level" as well, and
it could be better do the above check in "int z_erofs_compress_init(void)"

Thanks,
Gao Xiang

Quoted 11 lines
mkfs/main.c +5 -1
+                             fprintf(stderr,
+                                     "invalid debug level %d\n",
+                                     cfg.c_dbg_lvl);
+                             return -EINVAL;
+                     }
                      break;
 
              case 'E':
--

2.9.3