From: "zhangyi (F)" <yi.zhang@huawei.com>
To: Andreas Dilger <adilger@dilger.ca>
Cc: Ext4 Developers List <linux-ext4@vger.kernel.org>,
Theodore Ts'o <tytso@mit.edu>, Wang Shilong <wshilong@ddn.com>,
Miao Xie <miaoxie@huawei.com>
Subject: Re: [PATCH 2/2] ext4: clean up group state test macros with predicate functions
Date: Wed, 19 Dec 2018 12:47:10 +0800 [thread overview]
Message-ID: <0173dff1-127d-96d8-cd70-e94935e6230c@huawei.com> (raw)
In-Reply-To: <1095F3A1-32A9-42A7-BE1C-40A7212015D0@dilger.ca>
On 2018/12/19 3:51, Andreas Dilger Wrote:
> On Dec 18, 2018, at 5:00 AM, zhangyi (F) <yi.zhang@huawei.com> wrote:
>>
>> Create separate predicate functions to test/set/clear/test_and_set
>> bb_state flags in ext4_group_info like features testing, and then
>> replace all old macros and the places where we use
>> EXT4_GROUP_INFO_XXX_BIT directly.
>>
>> Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
>> ---
>> +#define EXT4_MB_GROUP_STATE_FUNCS(name, statename) \
>> +static inline int ext4_mb_grp_##name(struct ext4_group_info *grp) \
>> +{ \
>> + return test_bit(EXT4_GROUP_INFO_##statename##_BIT, \
>> + &(grp->bb_state)); \
>> +} \
>> +static inline void ext4_mb_grp_set_##name(struct ext4_group_info *grp) \
>> +{ \
>> + set_bit(EXT4_GROUP_INFO_##statename##_BIT, &(grp->bb_state)); \
>> +} \
>> +static inline void ext4_mb_grp_clear_##name(struct ext4_group_info *grp)\
>> +{ \
>> + clear_bit(EXT4_GROUP_INFO_##statename##_BIT, &(grp->bb_state)); \
>> +} \
>> +static inline int ext4_mb_grp_test_and_set_##name(struct ext4_group_info *grp) \
>> +{ \
>> + return test_and_set_bit(EXT4_GROUP_INFO_##statename##_BIT, \
>> + &(grp->bb_state)); \
>> +}
>> +
>> +EXT4_MB_GROUP_STATE_FUNCS(need_init, NEED_INIT)
>> +EXT4_MB_GROUP_STATE_FUNCS(trimmed, WAS_TRIMMED)
>> +EXT4_MB_GROUP_STATE_FUNCS(bbitmap_corrupt, BBITMAP_CORRUPT)
>> +EXT4_MB_GROUP_STATE_FUNCS(ibitmap_corrupt, IBITMAP_CORRUPT)
>
> One problem with macros like this that internally expand to multiple
> functions is that there is now nowhere in this code where, for example,
> the declaration of ext4_mb_grp_test_and_set_bbitmap_corrupt() can be
> found. That makes it hard to understand the code, because tags for this
> function name will not work, and even a grep through the entire code for
> this string will not show the function implementation, only users. One
> would have to search for only the "ext4_mb_grp_test_and_set" part, or
> "ext4_mb_grp_clear" to find the above macros.
>
> If such macros-that-generate-functions are being used, my preference is
> that at least a comment block is added that spells out the full function
> names, so that at least a grep will find them, like:
>
> /*
> * These macros implement the following functions:
> * - ext4_mb_grp_need_init(), ext4_mb_grp_test_and_set_need_init(),
> * ext4_mb_grp_set_need_init(), ext4_mb_grp_clear_need_init()
> * - ...
> * - ...
> */
>
> Yes, this is a bit cumbersome the rare times a new function is added, but
> it really makes the code easier to understand in the future, without forcing
> a cut-and-paste of the body of each function. I don't know how many times
> I've had to search for commonly-used functions like buffer_uptodate() or
> buffer_dirty() in the code without being able to find them easily.
>
Thanks for your comments. Indeed, I also had the same hard time as you said.
I am not so sure why we have been using these maco functions for ext4 features
and ext4_inode_info bit flags. But I think it's still worth to unify them.
I will add the comment block as your suggested and post the second version,
BTW, I read the commit 3f61c0cc706 "ext4: add prototypes for macro-generated
functions" you posted, it's also a good choice.
Thanks,
Yi.
next prev parent reply other threads:[~2018-12-19 4:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-18 12:00 [PATCH 1/2] ext4: fix race when setting the bitmap corrupted flag again zhangyi (F)
2018-12-18 12:00 ` [PATCH 2/2] ext4: clean up group state test macros with predicate functions zhangyi (F)
2018-12-18 14:40 ` Wang Shilong
2018-12-19 3:48 ` zhangyi (F)
2018-12-18 19:51 ` Andreas Dilger
2018-12-19 4:47 ` zhangyi (F) [this message]
2018-12-19 4:55 ` Andreas Dilger
2018-12-18 14:25 ` [PATCH 1/2] ext4: fix race when setting the bitmap corrupted flag again Wang Shilong
2018-12-19 3:35 ` zhangyi (F)
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=0173dff1-127d-96d8-cd70-e94935e6230c@huawei.com \
--to=yi.zhang@huawei.com \
--cc=adilger@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=miaoxie@huawei.com \
--cc=tytso@mit.edu \
--cc=wshilong@ddn.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 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).