From: Filipe Manana <fdmanana@kernel.org>
To: dsterba@suse.cz, Nikolay Borisov <nborisov@suse.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/3] btrfs: introduce btrfs_find_inode
Date: Thu, 4 Aug 2022 16:52:21 +0100 [thread overview]
Message-ID: <20220804155221.GA1840473@falcondesktop> (raw)
In-Reply-To: <20220804152823.GT13489@twin.jikos.cz>
On Thu, Aug 04, 2022 at 05:28:24PM +0200, David Sterba wrote:
> On Thu, Jul 21, 2022 at 04:50:04PM +0300, Nikolay Borisov wrote:
> > This function holds common code for searching the root's inode rb tree.
> > It will be used to reduce code duplication in future patches.
> >
> > Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> > ---
> > fs/btrfs/ctree.h | 1 +
> > fs/btrfs/inode.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 45 insertions(+)
> >
> > diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> > index 0ae7f6530da1..fc0a0ab01761 100644
> > --- a/fs/btrfs/ctree.h
> > +++ b/fs/btrfs/ctree.h
> > @@ -3311,6 +3311,7 @@ int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index);
> > int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
> > struct btrfs_inode *dir, struct btrfs_inode *inode,
> > const char *name, int name_len);
> > +struct rb_node *btrfs_find_inode(struct btrfs_root *root, const u64 objectid);
> > int btrfs_add_link(struct btrfs_trans_handle *trans,
> > struct btrfs_inode *parent_inode, struct btrfs_inode *inode,
> > const char *name, int name_len, int add_backref, u64 index);
> > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> > index 5fc831a8eba1..c11169ba28b2 100644
> > --- a/fs/btrfs/inode.c
> > +++ b/fs/btrfs/inode.c
> > @@ -4587,6 +4587,50 @@ static noinline int may_destroy_subvol(struct btrfs_root *root)
> > return ret;
> > }
> >
> > +/**
> > + * btrfs_find_inode - returns the rb_node pointing to the inode with an ino
> > + * equal or larger than @objectid
>
> Please use the simplified format that we have in btrfs.
>
> > + *
> > + * @root: root which is going to be searched for an inode
> > + * @objectid: ino being searched for, if no exact match can be found the
> > + * function returns the first largest inode
> > + *
> > + * Returns the rb_node pointing to the specified inode or returns NULL if no
> > + * match is found.
> > + *
> > + */
> > +struct rb_node *btrfs_find_inode(struct btrfs_root *root, const u64 objectid)
>
> Const arguments for int types does not make sense.
It makes sense to me, as much as declaring local variables as const, and I don't
recall you ever complain about local const variables before (I do it often, and
I'm not the only one).
Once I read the const part, I can tell for sure that nowhere in the function the
value of the argument is changed.
It happens often that large functions use an int argument as if it was a local
variable and change its value later on, which makes reading the code often a bit
more time consuming and often leads to mistakest too.
> The root can be made
> const, compile tested, no complaints.
>
> > +{
> > + struct rb_node *node = root->inode_tree.rb_node;
> > + struct rb_node *prev = NULL;
> > + struct btrfs_inode *entry;
> > +
> > + lockdep_assert_held(&root->inode_lock);
> > +
> > + while (node) {
> > + prev = node;
> > + entry = rb_entry(node, struct btrfs_inode, rb_node);
> > +
> > + if (objectid < btrfs_ino(entry))
> > + node = node->rb_left;
> > + else if (objectid > btrfs_ino(entry))
> > + node = node->rb_right;
> > + else
> > + break;
> > + }
> > +
> > + if (!node) {
> > + while (prev) {
> > + entry = rb_entry(prev, struct btrfs_inode, rb_node);
> > + if (objectid <= btrfs_ino(entry))
> > + return prev;
> > + prev = rb_next(prev);
> > + }
> > + }
> > +
> > + return node;
> > +}
> > +
> > /* Delete all dentries for inodes belonging to the root */
> > static void btrfs_prune_dentries(struct btrfs_root *root)
> > {
> > --
> > 2.25.1
next prev parent reply other threads:[~2022-08-04 15:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 13:50 [PATCH 0/3] Remove duplicate code in btrfs_prune_dentries/find_next_inode Nikolay Borisov
2022-07-21 13:50 ` [PATCH 1/3] btrfs: introduce btrfs_find_inode Nikolay Borisov
2022-08-04 15:28 ` David Sterba
2022-08-04 15:52 ` Filipe Manana [this message]
2022-08-04 16:08 ` David Sterba
2022-08-04 16:22 ` Filipe Manana
2022-07-21 13:50 ` [PATCH 2/3] btrfs: use btrfs_find_inode in btrfs_prune_dentries Nikolay Borisov
2022-08-04 15:41 ` David Sterba
2022-08-04 16:18 ` Nikolay Borisov
2022-07-21 13:50 ` [PATCH 3/3] btrfs: use btrfs_find_inode in find_next_inode Nikolay Borisov
2022-07-21 15:36 ` [PATCH 0/3] Remove duplicate code in btrfs_prune_dentries/find_next_inode Sweet Tea Dorminy
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=20220804155221.GA1840473@falcondesktop \
--to=fdmanana@kernel.org \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@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