From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Jeff Mahoney <jeffm@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 3/5] btrfs-progs: qgroups: use parse_size instead of open coding it
Date: Wed, 14 Aug 2019 09:51:08 +0800 [thread overview]
Message-ID: <698f8ba6-d00f-b9d5-41e3-620d821a0f1e@gmx.com> (raw)
In-Reply-To: <20190814010402.22546-3-jeffm@suse.com>
[-- Attachment #1.1: Type: text/plain, Size: 2251 bytes --]
On 2019/8/14 上午9:04, Jeff Mahoney wrote:
> The only difference between parse_limit and parse_size is that
> parse_limit accepts "none" as a valid input. That's easy enough
> to handle as a special case and lets us drop the duplicate code.
>
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> cmds/qgroup.c | 58 ++++------------------------------------------------------
> 1 file changed, 4 insertions(+), 54 deletions(-)
>
> diff --git a/cmds/qgroup.c b/cmds/qgroup.c
> index 59b43c98..ba81052a 100644
> --- a/cmds/qgroup.c
> +++ b/cmds/qgroup.c
> @@ -159,56 +159,6 @@ static int _cmd_qgroup_create(int create, int argc, char **argv)
> return 0;
> }
>
> -static int parse_limit(const char *p, unsigned long long *s)
> -{
> - char *endptr;
> - unsigned long long size;
> - unsigned long long CLEAR_VALUE = -1;
> -
> - if (strcasecmp(p, "none") == 0) {
> - *s = CLEAR_VALUE;
> - return 1;
> - }
> -
> - if (p[0] == '-')
> - return 0;
> -
> - size = strtoull(p, &endptr, 10);
> - if (p == endptr)
> - return 0;
> -
> - switch (*endptr) {
> - case 'T':
> - case 't':
> - size *= 1024;
> - /* fallthrough */
> - case 'G':
> - case 'g':
> - size *= 1024;
> - /* fallthrough */
> - case 'M':
> - case 'm':
> - size *= 1024;
> - /* fallthrough */
> - case 'K':
> - case 'k':
> - size *= 1024;
> - ++endptr;
> - break;
> - case 0:
> - break;
> - default:
> - return 0;
> - }
> -
> - if (*endptr)
> - return 0;
> -
> - *s = size;
> -
> - return 1;
> -}
> -
> static const char * const cmd_qgroup_assign_usage[] = {
> "btrfs qgroup assign [options] <src> <dst> <path>",
> "Assign SRC as the child qgroup of DST",
> @@ -455,10 +405,10 @@ static int cmd_qgroup_limit(const struct cmd_struct *cmd, int argc, char **argv)
> if (check_argc_min(argc - optind, 2))
> return 1;
>
> - if (!parse_limit(argv[optind], &size)) {
> - error("invalid size argument: %s", argv[optind]);
> - return 1;
> - }
> + if (!strcasecmp(argv[optind], "none"))
> + size = -1ULL;
> + else
> + size = parse_size(argv[optind]);
>
> memset(&args, 0, sizeof(args));
> if (compressed)
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-08-14 1:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-14 1:03 [PATCH 1/5] btrfs-progs: mkfs: treat btrfs_add_to_fsid as fatal error Jeff Mahoney
2019-08-14 1:03 ` [PATCH 2/5] btrfs-progs: btrfs_add_to_fsid: check if adding device would overflow Jeff Mahoney
2019-08-14 1:50 ` Qu Wenruo
2019-08-27 15:23 ` David Sterba
2019-08-14 1:04 ` [PATCH 3/5] btrfs-progs: qgroups: use parse_size instead of open coding it Jeff Mahoney
2019-08-14 1:51 ` Qu Wenruo [this message]
2019-08-14 1:04 ` [PATCH 4/5] btrfs-progs: resize: more sensible error messages for bad sizes Jeff Mahoney
2019-08-14 1:53 ` Qu Wenruo
2019-08-27 15:22 ` David Sterba
2019-08-14 1:04 ` [PATCH 5/5] btrfs-progs: mkfs: print error messages instead of just error number Jeff Mahoney
2019-08-14 1:54 ` Qu Wenruo
2019-08-14 2:30 ` Jeff Mahoney
2019-08-14 1:48 ` [PATCH 1/5] btrfs-progs: mkfs: treat btrfs_add_to_fsid as fatal error Qu Wenruo
2019-08-27 15:27 ` David Sterba
2019-08-27 15:30 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=698f8ba6-d00f-b9d5-41e3-620d821a0f1e@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=jeffm@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).