All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs-progs: parser related cleanups
@ 2024-01-17  4:10 Qu Wenruo
  2024-01-17  4:10 ` [PATCH 1/2] btrfs-progs: use parse_u64() to implement arg_strtou64() Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qu Wenruo @ 2024-01-17  4:10 UTC (permalink / raw)
  To: linux-btrfs

Btrfs-progs has two types of parsers:

- parse_*()
  Those would return 0 for a good parse, and save the value into a
  pointer.
  Callers are responsible to handle the error.

- arg_strto*()
  Those would directly return the parsed value, and call exit(1)
  directly for errors.

However this split is not perfect:

- A lot of code can be shared between them
  In fact, mostly arg_strto*() can be implement using parse_*().
  The only difference is in how detailed the error string would be.

- parse_size_from_string() doesn't follow the scheme
  It follows arg_strto*() behavior but has the parse_*() name.

This patch would:

- Use parse_u64() to implement arg_strtou64()
  The first patch.

- Use parse_u64_with_suffix() to implement arg_strtou64_with_suffix()
  The new helper parse_u64_with_suffix() would replace the old
  parse_size_from_string() and do the proper error handling.

Qu Wenruo (2):
  btrfs-progs: use parse_u64() to implement arg_strtou64()
  btrfs-progs: implement arg_strtou64_with_suffix() with a new helper

 cmds/filesystem.c     | 15 ++++----
 cmds/qgroup.c         |  3 +-
 cmds/reflink.c        |  7 ++--
 cmds/scrub.c          |  2 +-
 common/parse-utils.c  | 85 ++++++++++++++++++++++++++++---------------
 common/parse-utils.h  |  2 +-
 common/string-utils.c | 45 +++++++++++++++--------
 common/string-utils.h |  3 ++
 convert/main.c        |  3 +-
 kernel-shared/zoned.c |  4 +-
 mkfs/main.c           |  6 +--
 11 files changed, 110 insertions(+), 65 deletions(-)

--
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-17 19:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-17  4:10 [PATCH 0/2] btrfs-progs: parser related cleanups Qu Wenruo
2024-01-17  4:10 ` [PATCH 1/2] btrfs-progs: use parse_u64() to implement arg_strtou64() Qu Wenruo
2024-01-17  4:10 ` [PATCH 2/2] btrfs-progs: implement arg_strtou64_with_suffix() with a new helper Qu Wenruo
2024-01-17 19:34 ` [PATCH 0/2] btrfs-progs: parser related cleanups David Sterba

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.