All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 8/8] btrfs-progs: qgroups: export qgroups usage information as JSON
Date: Wed, 7 Mar 2018 10:28:27 -0500	[thread overview]
Message-ID: <a5cf785d-f8a1-9396-99d7-260f3610d531@suse.com> (raw)
In-Reply-To: <2250ef0b-13a2-1a8f-cd19-ea69adf27e7b@gmx.com>


[-- Attachment #1.1: Type: text/plain, Size: 2478 bytes --]

On 3/7/18 1:34 AM, Qu Wenruo wrote:
> 
> 
> On 2018年03月03日 02:47, jeffm@suse.com wrote:
>> diff --git a/configure.ac b/configure.ac
>> index 56d17c3a..6aec672a 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -197,6 +197,12 @@ PKG_STATIC(UUID_LIBS_STATIC, [uuid])
>>  PKG_CHECK_MODULES(ZLIB, [zlib])
>>  PKG_STATIC(ZLIB_LIBS_STATIC, [zlib])
>>  
>> +PKG_CHECK_MODULES(JSON, [json-c], [
> 
> Json-c is quite common and also used by cryptsetup, so pretty good
> library choice.

Yep, so that puts it in the base system packages of most distros.

>> diff --git a/qgroup.c b/qgroup.c
>> index 2d0a6947..f632a45c 100644
>> --- a/qgroup.c
>> +++ b/qgroup.c
>>  	return ret;
>>  }
>>  
>> +#ifdef HAVE_JSON
>> +static void format_qgroupid(char *buf, size_t size, u64 qgroupid)
>> +{
>> +	int ret;
>> +
>> +	ret = snprintf(buf, size, "%llu/%llu",
>> +		       btrfs_qgroup_level(qgroupid),
>> +		       btrfs_qgroup_subvid(qgroupid));
>> +	ASSERT(ret < sizeof(buf));
> 
> This is designed to catch truncated snprintf(), right?
> This can be addressed by setting up the @buf properly.
> (See below)
> 
> And in fact, due to that super magic number, we won't hit this ASSERT()
> anyway.

Yep, but ASSERTs are there to detect/prevent developer mistakes.  This
should only trigger due to a simple bug, so we ASSERT rather than handle
the error gracefully.

[...]

>> +static bool export_one_qgroup(json_object *container,
>> +			     const struct btrfs_qgroup *qgroup, bool compat)
>> +{
>> +	json_object *obj = json_object_new_object();
>> +	json_object *tmp;
>> +	char buf[42];
> 
> Answer to the ultimate question of life, the universe, and everything. :)
> 
> Although according to the format level/subvolid, it should be
> count_digits(MAX_U16) + 1 + count_digits(MAX_U48) + 1. (1 for '/' and 1
> for '\n')
> 
> Could be defined as a macro as:
> #define QGROUP_FORMAT_BUF_LEN (count_digits(1ULL<<16) + 1 + \
>                                count_digits(1ULL<<48) + 1)

Which would mean we'd execute count_digits twice for every qgroup to
resolve a constant.  I'll replace the magic number with a define though.

> BTW, the result is just 22.
It's a worst-case.  We're using %llu, so 42 is the length of two 64-bit
numbers in base ten, plus the slash and nul terminator.  In practice we
won't hit the limit, but it doesn't hurt.

Thanks for the review.

-Jeff

-- 
Jeff Mahoney
SUSE Labs


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 854 bytes --]

  reply	other threads:[~2018-03-07 15:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-02 18:46 [PATCH 0/8] btrfs-progs: qgroups usability [corrected] jeffm
2018-03-02 18:46 ` [PATCH 1/8] btrfs-progs: quota: Add -W option to rescan to wait without starting rescan jeffm
2018-03-02 18:59   ` Nikolay Borisov
2018-03-03  2:46     ` Jeff Mahoney
2018-03-02 18:46 ` [PATCH 2/8] btrfs-progs: qgroups: fix misleading index check jeffm
2018-03-07  8:05   ` Nikolay Borisov
2018-03-02 18:46 ` [PATCH 3/8] btrfs-progs: constify pathnames passed as arguments jeffm
2018-03-07  8:17   ` Nikolay Borisov
2018-03-07 20:45     ` Jeff Mahoney
2018-03-02 18:47 ` [PATCH 4/8] btrfs-progs: qgroups: add pathname to show output jeffm
2018-03-07  5:45   ` Qu Wenruo
2018-03-07 16:37     ` Jeff Mahoney
2018-03-02 18:47 ` [PATCH 5/8] btrfs-progs: qgroups: introduce and use info and limit structures jeffm
2018-03-07  9:19   ` Nikolay Borisov
2018-03-02 18:47 ` [PATCH 6/8] btrfs-progs: qgroups: introduce btrfs_qgroup_query jeffm
2018-03-07  5:58   ` Qu Wenruo
2018-03-07 19:42     ` Jeff Mahoney
2018-03-07  6:08   ` Qu Wenruo
2018-03-07  8:02   ` Misono, Tomohiro
2018-03-07 20:24     ` Jeff Mahoney
2018-03-02 18:47 ` [PATCH 7/8] btrfs-progs: subvolume: add quota info to btrfs sub show jeffm
2018-03-07  6:09   ` Qu Wenruo
2018-03-07 20:21     ` Jeff Mahoney
2018-03-02 18:47 ` [PATCH 8/8] btrfs-progs: qgroups: export qgroups usage information as JSON jeffm
2018-03-07  6:34   ` Qu Wenruo
2018-03-07 15:28     ` Jeff Mahoney [this message]
2018-03-06 12:10 ` [PATCH 0/8] btrfs-progs: qgroups usability [corrected] Qu Wenruo
2018-03-06 14:59   ` Jeffrey Mahoney
2018-03-07  6:11 ` Qu Wenruo
  -- strict thread matches above, loose matches on Subject: below --
2018-03-02 18:39 [PATCH 0/8] btrfs-progs: qgroups usability jeffm
2018-03-02 18:40 ` [PATCH 8/8] btrfs-progs: qgroups: export qgroups usage information as JSON jeffm

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=a5cf785d-f8a1-9396-99d7-260f3610d531@suse.com \
    --to=jeffm@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.com \
    /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 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.