From: Leo Martins <loemra.dev@gmail.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 1/2] btrfs: remove conditional path allocation from read_locked_inode, add path allocation to iget
Date: Tue, 13 Aug 2024 13:27:33 -0700 [thread overview]
Message-ID: <32dea3edada81f7901f7f7e39f4e3729888dea46.1723580508.git.loemra.dev@gmail.com> (raw)
In-Reply-To: <cover.1723580508.git.loemra.dev@gmail.com>
Move the path allocation from inside btrfs_read_locked_inode to
btrfs_iget. This makes the code easier to reason about as it is clear
where the allocation occurs and who is in charge of freeing the path.
I have investigated all of the callers of btrfs_iget_path to make sure
that it is never called with a null path with the expectation
of a path allocation. All of the null calls seem to come from btrfs_iget
so it makes sense to do the allocation within btrfs_iget.
---
fs/btrfs/inode.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 07858d63378f..b89b4b1bd3da 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3790,10 +3790,9 @@ static int btrfs_init_file_extent_tree(struct btrfs_inode *inode)
* read an inode from the btree into the in-memory inode
*/
static int btrfs_read_locked_inode(struct inode *inode,
- struct btrfs_path *in_path)
+ struct btrfs_path *path)
{
struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
- struct btrfs_path *path = in_path;
struct extent_buffer *leaf;
struct btrfs_inode_item *inode_item;
struct btrfs_root *root = BTRFS_I(inode)->root;
@@ -3813,18 +3812,10 @@ static int btrfs_read_locked_inode(struct inode *inode,
if (!ret)
filled = true;
- if (!path) {
- path = btrfs_alloc_path();
- if (!path)
- return -ENOMEM;
- }
-
btrfs_get_inode_key(BTRFS_I(inode), &location);
ret = btrfs_lookup_inode(NULL, root, path, &location, 0);
if (ret) {
- if (path != in_path)
- btrfs_free_path(path);
return ret;
}
@@ -3960,8 +3951,6 @@ static int btrfs_read_locked_inode(struct inode *inode,
btrfs_ino(BTRFS_I(inode)),
btrfs_root_id(root), ret);
}
- if (path != in_path)
- btrfs_free_path(path);
if (!maybe_acls)
cache_no_acl(inode);
@@ -5631,7 +5620,15 @@ struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
{
- return btrfs_iget_path(ino, root, NULL);
+ struct btrfs_path *path = btrfs_alloc_path();
+
+ if (!path)
+ return ERR_PTR(-ENOMEM);
+
+ struct inode *inode = btrfs_iget_path(ino, root, path);
+
+ btrfs_free_path(path);
+ return inode;
}
static struct inode *new_simple_dir(struct inode *dir,
--
2.43.5
next prev parent reply other threads:[~2024-08-13 20:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-13 20:27 [PATCH 0/2] btrfs: clean up btrfs_iget, btrfs_iget_path usage Leo Martins
2024-08-13 20:27 ` Leo Martins [this message]
2024-08-13 22:21 ` [PATCH 1/2] btrfs: remove conditional path allocation from read_locked_inode, add path allocation to iget David Sterba
2024-08-13 20:27 ` [PATCH 2/2] btrfs: move clean up code from btrfs_iget_path to btrfs_read_locked_inode Leo Martins
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=32dea3edada81f7901f7f7e39f4e3729888dea46.1723580508.git.loemra.dev@gmail.com \
--to=loemra.dev@gmail.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/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