Skip to content

Commit

Permalink
btrfs: pass struct btrfs_inode to btrfs_iget_locked()
Browse files Browse the repository at this point in the history
[ Upstream commit 4ea2fb9 ]

Pass a struct btrfs_inode to btrfs_inode() as it's an internal
interface, allowing to remove some use of BTRFS_I.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Stable-dep-of: 48c1d1b ("btrfs: fix the inode leak in btrfs_iget()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
David Sterba authored and Greg Kroah-Hartman committed May 9, 2025
1 parent 569c6cd commit 8a1761a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -5601,7 +5601,7 @@ static int btrfs_find_actor(struct inode *inode, void *opaque)
args->root == BTRFS_I(inode)->root;
}

static struct inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
static struct btrfs_inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
{
struct inode *inode;
struct btrfs_iget_args args;
Expand All @@ -5613,7 +5613,9 @@ static struct inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
inode = iget5_locked_rcu(root->fs_info->sb, hashval, btrfs_find_actor,
btrfs_init_locked_inode,
(void *)&args);
return inode;
if (!inode)
return NULL;
return BTRFS_I(inode);
}

/*
Expand All @@ -5623,51 +5625,51 @@ static struct inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
struct btrfs_path *path)
{
struct inode *inode;
struct btrfs_inode *inode;
int ret;

inode = btrfs_iget_locked(ino, root);
if (!inode)
return ERR_PTR(-ENOMEM);

if (!(inode->i_state & I_NEW))
return inode;
if (!(inode->vfs_inode.i_state & I_NEW))
return &inode->vfs_inode;

ret = btrfs_read_locked_inode(BTRFS_I(inode), path);
ret = btrfs_read_locked_inode(inode, path);
if (ret)
return ERR_PTR(ret);

unlock_new_inode(inode);
return inode;
unlock_new_inode(&inode->vfs_inode);
return &inode->vfs_inode;
}

/*
* Get an inode object given its inode number and corresponding root.
*/
struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
{
struct inode *inode;
struct btrfs_inode *inode;
struct btrfs_path *path;
int ret;

inode = btrfs_iget_locked(ino, root);
if (!inode)
return ERR_PTR(-ENOMEM);

if (!(inode->i_state & I_NEW))
return inode;
if (!(inode->vfs_inode.i_state & I_NEW))
return &inode->vfs_inode;

path = btrfs_alloc_path();
if (!path)
return ERR_PTR(-ENOMEM);

ret = btrfs_read_locked_inode(BTRFS_I(inode), path);
ret = btrfs_read_locked_inode(inode, path);
btrfs_free_path(path);
if (ret)
return ERR_PTR(ret);

unlock_new_inode(inode);
return inode;
unlock_new_inode(&inode->vfs_inode);
return &inode->vfs_inode;
}

static struct inode *new_simple_dir(struct inode *dir,
Expand Down

0 comments on commit 8a1761a

Please sign in to comment.