From: David Sterba <dsterba@suse.cz>
To: Nikolay Borisov <nborisov@suse.com>
Cc: Qu Wenruo <quwenruo.btrfs@gmx.com>, WenRuo Qu <wqu@suse.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 5/5] btrfs: ctree: Checking key orders before merged tree blocks
Date: Wed, 24 Jul 2019 18:24:32 +0200 [thread overview]
Message-ID: <20190724162432.GR2868@twin.jikos.cz> (raw)
In-Reply-To: <49581349-af2d-f800-c3fc-095ef96ab755@suse.com>
On Wed, Jul 10, 2019 at 03:12:37PM +0300, Nikolay Borisov wrote:
> On 10.07.19 г. 15:02 ч., Qu Wenruo wrote:
> > On 2019/7/10 下午7:19, Nikolay Borisov wrote:
> >> nit: I wonder if it will make it a bit easier to reason about the code
> >> if that function is renamed to valid_cross_block_key_order and make it
> >> return true or false, then it's callers will do if
> >> (!valid_cross_block_key_ordered) {
> >> return -EUCLEAN
> >> }>
> > I'm always uncertain what's the correct schema for check function.
> >
> > Sometimes we have bool check_whatever() sometimes we have bool
> > is_whatever(), and sometimes we have int check_whatever().
> >
> > If we have a good guidance for btrfs, it will be a no-brain choice.
>
> There is no such guidance in this case my logic is that this function
> really returns a boolean value - 0 or -EUCLEAN to make that explicit I'd
> define it as returning bool and rename it to valid_cross_block_key_order
> to really emphasize the fact it's a predicated-type of function. Thus if
> someone reads the they will be certain that this function return either
> true or false depending on whether the input parameters make sense.
Also what
https://www.kernel.org/doc/html/v4.10/process/coding-style.html#function-return-values-and-names
says.
Int in place of bool is in the old code, we should use bool in new code,
and convert the old code eventually. The naming of predicates prefixed
wich check_ sounds understandable to me, like going through a check
list, if it's ok continue, otherwise exit.
if (check_this_is_fine())
goto out_it_is_not;
Using 'is_' could be possible in some cases, and eg. for is_fstree or
is_bad_inode is ok.
> Whereas right now I will have to go and look at the implementation to
> determine what are the return values because of the "int" return type.
>
> Again, that's just me and if you deem it doesn't bring value then feel
> free to ignore it.
I think this becomes important in a large code base that btrfs is slowly
turning into, so it's not just you. As I have to read a lot of code I
can notice patterns that are easy to understand and where checking other
files is necessary, which takes time and is distracting. New code should
follow the best practices and old code should be updated when changed.
prev parent reply other threads:[~2019-07-24 16:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-10 8:02 [PATCH 0/5] btrfs: Enhanced runtime defence against fuzzed images Qu Wenruo
2019-07-10 8:02 ` [PATCH 1/5] btrfs: extent_io: Do extra check for extent buffer read write functions Qu Wenruo
2019-07-10 10:42 ` Nikolay Borisov
2019-07-10 10:58 ` WenRuo Qu
2019-07-24 16:00 ` David Sterba
2019-07-24 22:54 ` Qu Wenruo
2019-07-25 6:39 ` Nikolay Borisov
2019-07-10 8:02 ` [PATCH 2/5] btrfs: extent-tree: Kill BUG_ON() in __btrfs_free_extent() and do better comment Qu Wenruo
2019-07-10 10:48 ` Nikolay Borisov
2019-07-10 11:00 ` WenRuo Qu
2019-07-10 8:02 ` [PATCH 3/5] btrfs: Detect unbalanced tree with empty leaf before crashing btree operations Qu Wenruo
2019-07-10 10:54 ` Nikolay Borisov
2019-07-10 8:02 ` [PATCH 4/5] btrfs: extent-tree: Kill the BUG_ON() in insert_inline_extent_backref() Qu Wenruo
2019-07-10 11:12 ` Nikolay Borisov
2019-07-10 8:02 ` [PATCH 5/5] btrfs: ctree: Checking key orders before merged tree blocks Qu Wenruo
2019-07-10 11:19 ` Nikolay Borisov
2019-07-10 12:02 ` Qu Wenruo
2019-07-10 12:12 ` Nikolay Borisov
2019-07-24 16:24 ` David Sterba [this message]
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=20190724162432.GR2868@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.com \
--cc=quwenruo.btrfs@gmx.com \
--cc=wqu@suse.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