* [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines
@ 2025-04-06 15:26 Integral
2025-04-06 15:27 ` [PATCH 2/2] bcachefs: refactor if statements in bch2_opt_compression_parse() Integral
2025-04-06 17:35 ` [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines Kent Overstreet
0 siblings, 2 replies; 4+ messages in thread
From: Integral @ 2025-04-06 15:26 UTC (permalink / raw)
To: Kent Overstreet, Kent Overstreet; +Cc: linux-bcachefs, linux-kernel, Integral
When an invalid compression type or level is passed as an argument
to `--compression`, two error messages are squashed into one line:
> bcachefs format --compression=lzo bcachefs-comp.img
invalid option: invalid compression typecompression: parse error
> bcachefs format --compression=lz4:16 bcachefs-comp.img
invalid option: invalid compression levelcompression: parse error
To resolve this issue, add a newline character at the end of the
first error message to separate them into two lines.
Signed-off-by: Integral <integral@archlinuxcn.org>
---
fs/bcachefs/compress.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
index 28ed32449913..d68c3c7896a3 100644
--- a/fs/bcachefs/compress.c
+++ b/fs/bcachefs/compress.c
@@ -714,7 +714,7 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
ret = match_string(bch2_compression_opts, -1, type_str);
if (ret < 0 && err)
- prt_str(err, "invalid compression type");
+ prt_str(err, "invalid compression type\n");
if (ret < 0)
goto err;
@@ -729,7 +729,7 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
if (!ret && level > 15)
ret = -EINVAL;
if (ret < 0 && err)
- prt_str(err, "invalid compression level");
+ prt_str(err, "invalid compression level\n");
if (ret < 0)
goto err;
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] bcachefs: refactor if statements in bch2_opt_compression_parse()
2025-04-06 15:26 [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines Integral
@ 2025-04-06 15:27 ` Integral
2025-04-06 17:37 ` Kent Overstreet
2025-04-06 17:35 ` [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines Kent Overstreet
1 sibling, 1 reply; 4+ messages in thread
From: Integral @ 2025-04-06 15:27 UTC (permalink / raw)
To: Kent Overstreet, Kent Overstreet; +Cc: linux-bcachefs, linux-kernel, Integral
Refactor if statements in bch2_opt_compression_parse() to make it
simpler & clearer.
Signed-off-by: Integral <integral@archlinuxcn.org>
---
fs/bcachefs/compress.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
index d68c3c7896a3..adf939b47107 100644
--- a/fs/bcachefs/compress.c
+++ b/fs/bcachefs/compress.c
@@ -713,10 +713,11 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
level_str = p;
ret = match_string(bch2_compression_opts, -1, type_str);
- if (ret < 0 && err)
- prt_str(err, "invalid compression type\n");
- if (ret < 0)
+ if (ret < 0) {
+ if (err)
+ prt_str(err, "invalid compression type\n");
goto err;
+ }
opt.type = ret;
@@ -724,14 +725,13 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
unsigned level;
ret = kstrtouint(level_str, 10, &level);
- if (!ret && !opt.type && level)
- ret = -EINVAL;
- if (!ret && level > 15)
+ if (!ret && ((!opt.type && level) || level > 15))
ret = -EINVAL;
- if (ret < 0 && err)
- prt_str(err, "invalid compression level\n");
- if (ret < 0)
+ if (ret < 0) {
+ if (err)
+ prt_str(err, "invalid compression level\n");
goto err;
+ }
opt.level = level;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines
2025-04-06 15:26 [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines Integral
2025-04-06 15:27 ` [PATCH 2/2] bcachefs: refactor if statements in bch2_opt_compression_parse() Integral
@ 2025-04-06 17:35 ` Kent Overstreet
1 sibling, 0 replies; 4+ messages in thread
From: Kent Overstreet @ 2025-04-06 17:35 UTC (permalink / raw)
To: Integral; +Cc: Kent Overstreet, linux-bcachefs, linux-kernel
On Sun, Apr 06, 2025 at 11:26:59PM +0800, Integral wrote:
> When an invalid compression type or level is passed as an argument
> to `--compression`, two error messages are squashed into one line:
>
> > bcachefs format --compression=lzo bcachefs-comp.img
> invalid option: invalid compression typecompression: parse error
>
> > bcachefs format --compression=lz4:16 bcachefs-comp.img
> invalid option: invalid compression levelcompression: parse error
>
> To resolve this issue, add a newline character at the end of the
> first error message to separate them into two lines.
>
> Signed-off-by: Integral <integral@archlinuxcn.org>
Applied
I've also been working on consistent indentation for multiline error/log
messages, so that we can see grouping better.
If you want to add that, the new helper is
printbuf_indent_add_nextline()
With that we can initialize a printbuffer and at the same time set it so
that lines after the first are two space indented.
> ---
> fs/bcachefs/compress.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
> index 28ed32449913..d68c3c7896a3 100644
> --- a/fs/bcachefs/compress.c
> +++ b/fs/bcachefs/compress.c
> @@ -714,7 +714,7 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
>
> ret = match_string(bch2_compression_opts, -1, type_str);
> if (ret < 0 && err)
> - prt_str(err, "invalid compression type");
> + prt_str(err, "invalid compression type\n");
> if (ret < 0)
> goto err;
>
> @@ -729,7 +729,7 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
> if (!ret && level > 15)
> ret = -EINVAL;
> if (ret < 0 && err)
> - prt_str(err, "invalid compression level");
> + prt_str(err, "invalid compression level\n");
> if (ret < 0)
> goto err;
>
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] bcachefs: refactor if statements in bch2_opt_compression_parse()
2025-04-06 15:27 ` [PATCH 2/2] bcachefs: refactor if statements in bch2_opt_compression_parse() Integral
@ 2025-04-06 17:37 ` Kent Overstreet
0 siblings, 0 replies; 4+ messages in thread
From: Kent Overstreet @ 2025-04-06 17:37 UTC (permalink / raw)
To: Integral; +Cc: Kent Overstreet, linux-bcachefs, linux-kernel
On Sun, Apr 06, 2025 at 11:27:00PM +0800, Integral wrote:
> Refactor if statements in bch2_opt_compression_parse() to make it
> simpler & clearer.
>
> Signed-off-by: Integral <integral@archlinuxcn.org>
> ---
> fs/bcachefs/compress.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
> index d68c3c7896a3..adf939b47107 100644
> --- a/fs/bcachefs/compress.c
> +++ b/fs/bcachefs/compress.c
> @@ -713,10 +713,11 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
> level_str = p;
>
> ret = match_string(bch2_compression_opts, -1, type_str);
> - if (ret < 0 && err)
> - prt_str(err, "invalid compression type\n");
> - if (ret < 0)
> + if (ret < 0) {
> + if (err)
> + prt_str(err, "invalid compression type\n");
> goto err;
> + }
I prefer the old code for this one
>
> opt.type = ret;
>
> @@ -724,14 +725,13 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
> unsigned level;
>
> ret = kstrtouint(level_str, 10, &level);
> - if (!ret && !opt.type && level)
> - ret = -EINVAL;
> - if (!ret && level > 15)
> + if (!ret && ((!opt.type && level) || level > 15))
> ret = -EINVAL;
This part does look better, though.
> - if (ret < 0 && err)
> - prt_str(err, "invalid compression level\n");
> - if (ret < 0)
> + if (ret < 0) {
> + if (err)
> + prt_str(err, "invalid compression level\n");
> goto err;
> + }
>
> opt.level = level;
> }
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-06 17:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-06 15:26 [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines Integral
2025-04-06 15:27 ` [PATCH 2/2] bcachefs: refactor if statements in bch2_opt_compression_parse() Integral
2025-04-06 17:37 ` Kent Overstreet
2025-04-06 17:35 ` [PATCH 1/2] bcachefs: split error messages of invalid compression into two lines Kent Overstreet
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.