From: Nikolay Borisov <n.borisov.lkml@gmail.com>
To: Qu Wenruo <wqu@suse.de>, linux-btrfs@vger.kernel.org
Cc: dan.carpenter@oracle.com
Subject: Re: [PATCH 0/5] Unify the return value of alloc/clone_extent_buffer()
Date: Fri, 22 Feb 2019 15:29:32 +0200 [thread overview]
Message-ID: <7845f981-dbc3-6160-a329-33f0014ba973@gmail.com> (raw)
In-Reply-To: <b132529d-1246-4cb4-202a-37bf84e7ba43@suse.de>
On 22.02.19 г. 15:02 ч., Qu Wenruo wrote:
>
>
> On 2019/2/22 下午8:54, Nikolay Borisov wrote:
>>
>>
>> On 22.02.19 г. 12:16 ч., Qu Wenruo wrote:
>>> This patchset can be fetched from github:
>>> https://github.com/adam900710/linux/tree/cleanup_alloc_extent_buffer
>>> Which is based on v5.0-rc7
>>>
>>> There are 5 extent buffer alloc functions in btrfs:
>>> __alloc_extent_buffer();
>>> alloc_extent_buffer();
>>> __alloc_dummy_extent_buffer();
>>> alloc_dummy_extent_buffer();
>>> alloc_test_extent_buffer();
>>>
>>> However their return value is not unified for failure mode:
>>> __alloc_extent_buffer() Never fail
>>> alloc_extent_buffer() PTR_ERR()
>>> __alloc_dummy_extent_buffer() NULL
>>
>> This function can never return NULL, if __alloc_extent_buffer cannot
>> fail then the only error this function returns is ERR_PTR(ENOMEM);
>
> Nope.
>
> for (i = 0; i < num_pages; i++) {
> eb->pages[i] = alloc_page(GFP_NOFS);
> if (!eb->pages[i])
> goto err; <<< Page alloc failure here
> }
> ...
> err:
> for (; i > 0; i--)
> __free_page(eb->pages[i - 1]);
> __free_extent_buffer(eb);
> return NULL; << We got NULL.
Right, I was looking at the code AFTER having applied your patches. So I
agree with yout. However, the ordering of your patches and the
changelogs make it rather hard to understand. What I'd suggest regarding
the changelogs is - forget about unification, just say what you are
doing, which is always ensuring that an error is returned from
__alloc_extent_buffer in one patch - this should involve both changes to
__alloc_extent_buffer as well as it's (in)direct callers. Then you do
the same for other function. Otherwise review is somewhat hindered.
> }
>
> For __alloc_dummy_extent_buffer, that's the only failure case.
>
> And I'm interested how did you get the PTR_ERR() case?
>
>>
>>> alloc_dummy_extent_buffer() NULL
>> Same thing applies to this function
>
> Nope.
>
>>
>>> alloc_test_extent_buffer() NULL
>>
>> Same thing for this function, if we return exists then we must have
>> found it by find_extent_buffer hence it cannot be null. Otherwise we
>> return eb as allocated from alloc_dummy_extent_buffer. So how can null
>> be returned?
>
> And nope.
>
>>
>> To me it really seems none of the function could return a NULL value, no?
>
> Your misunderstand of __alloc_dummy_extent_buffer() makes the call chain
> all wrong.
>
> Thanks,
> Qu
>
>>
>>>
>>> This causes some wrapper function to have 2 failure modes, like
>>> btrfs_find_create_tree_block() can return NULL or PTR_ERR(-ENOMEM) for
>>> its failure.
>>>
>>> This inconsistent behavior is making static checker and reader crazy.
>>>
>>> This patchset will unify the failure more of above 5 functions to
>>> PTR_ERR().
>>>
>>> Qu Wenruo (5):
>>> btrfs: extent_io: Add comment about the return value of
>>> alloc_extent_buffer()
>>> btrfs: extent_io: Unify the return value of __alloc_extent_buffer()
>>> with alloc_extent_buffer()
>>> btrfs: extent_io: Unify the return value of
>>> alloc_dummy_extent_buffer() with alloc_extent_buffer()
>>> btrfs: extent_io: Unify the return value of alloc_test_extent_buffer()
>>> with alloc_extent_buffer()
>>> btrfs: extent_io: Unify the return value of
>>> btrfs_clone_extent_buffer() with alloc_extent_buffer()
>>>
>>> fs/btrfs/backref.c | 8 ++--
>>> fs/btrfs/ctree.c | 16 ++++----
>>> fs/btrfs/extent_io.c | 56 +++++++++++++++++---------
>>> fs/btrfs/qgroup.c | 5 ++-
>>> fs/btrfs/tests/extent-buffer-tests.c | 6 ++-
>>> fs/btrfs/tests/extent-io-tests.c | 4 +-
>>> fs/btrfs/tests/free-space-tree-tests.c | 3 +-
>>> fs/btrfs/tests/inode-tests.c | 6 ++-
>>> fs/btrfs/tests/qgroup-tests.c | 3 +-
>>> 9 files changed, 68 insertions(+), 39 deletions(-)
>>>
>>
>
next prev parent reply other threads:[~2019-02-22 13:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 10:16 [PATCH 0/5] Unify the return value of alloc/clone_extent_buffer() Qu Wenruo
2019-02-22 10:16 ` [PATCH 1/5] btrfs: extent_io: Add comment about the return value of alloc_extent_buffer() Qu Wenruo
2019-02-27 13:36 ` David Sterba
2019-02-27 13:41 ` Qu Wenruo
2019-02-27 13:44 ` David Sterba
2019-02-22 10:16 ` [PATCH 2/5] btrfs: extent_io: Unify the return value of __alloc_extent_buffer() with alloc_extent_buffer() Qu Wenruo
2019-02-22 10:16 ` [PATCH 3/5] btrfs: extent_io: Unify the return value of alloc_dummy_extent_buffer() " Qu Wenruo
2019-02-22 10:16 ` [PATCH 4/5] btrfs: extent_io: Unify the return value of alloc_test_extent_buffer() " Qu Wenruo
2019-02-22 10:16 ` [PATCH 5/5] btrfs: extent_io: Unify the return value of btrfs_clone_extent_buffer() " Qu Wenruo
2019-02-22 12:47 ` Nikolay Borisov
2019-02-22 12:53 ` Qu Wenruo
2019-02-22 13:02 ` [PATCH v1.1 " Qu Wenruo
2019-02-22 12:54 ` [PATCH 0/5] Unify the return value of alloc/clone_extent_buffer() Nikolay Borisov
2019-02-22 13:02 ` Qu Wenruo
2019-02-22 13:29 ` Nikolay Borisov [this message]
2019-02-22 13:31 ` Qu Wenruo
2019-02-27 14:11 ` David Sterba
2019-02-22 13:32 ` Qu Wenruo
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=7845f981-dbc3-6160-a329-33f0014ba973@gmail.com \
--to=n.borisov.lkml@gmail.com \
--cc=dan.carpenter@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.de \
/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).