Skip to content

Commit 8a1761a

Browse files
kdavegregkh
authored andcommitted
btrfs: pass struct btrfs_inode to btrfs_iget_locked()
[ 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>
1 parent 569c6cd commit 8a1761a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

fs/btrfs/inode.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5601,7 +5601,7 @@ static int btrfs_find_actor(struct inode *inode, void *opaque)
56015601
args->root == BTRFS_I(inode)->root;
56025602
}
56035603

5604-
static struct inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
5604+
static struct btrfs_inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
56055605
{
56065606
struct inode *inode;
56075607
struct btrfs_iget_args args;
@@ -5613,7 +5613,9 @@ static struct inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
56135613
inode = iget5_locked_rcu(root->fs_info->sb, hashval, btrfs_find_actor,
56145614
btrfs_init_locked_inode,
56155615
(void *)&args);
5616-
return inode;
5616+
if (!inode)
5617+
return NULL;
5618+
return BTRFS_I(inode);
56175619
}
56185620

56195621
/*
@@ -5623,51 +5625,51 @@ static struct inode *btrfs_iget_locked(u64 ino, struct btrfs_root *root)
56235625
struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
56245626
struct btrfs_path *path)
56255627
{
5626-
struct inode *inode;
5628+
struct btrfs_inode *inode;
56275629
int ret;
56285630

56295631
inode = btrfs_iget_locked(ino, root);
56305632
if (!inode)
56315633
return ERR_PTR(-ENOMEM);
56325634

5633-
if (!(inode->i_state & I_NEW))
5634-
return inode;
5635+
if (!(inode->vfs_inode.i_state & I_NEW))
5636+
return &inode->vfs_inode;
56355637

5636-
ret = btrfs_read_locked_inode(BTRFS_I(inode), path);
5638+
ret = btrfs_read_locked_inode(inode, path);
56375639
if (ret)
56385640
return ERR_PTR(ret);
56395641

5640-
unlock_new_inode(inode);
5641-
return inode;
5642+
unlock_new_inode(&inode->vfs_inode);
5643+
return &inode->vfs_inode;
56425644
}
56435645

56445646
/*
56455647
* Get an inode object given its inode number and corresponding root.
56465648
*/
56475649
struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
56485650
{
5649-
struct inode *inode;
5651+
struct btrfs_inode *inode;
56505652
struct btrfs_path *path;
56515653
int ret;
56525654

56535655
inode = btrfs_iget_locked(ino, root);
56545656
if (!inode)
56555657
return ERR_PTR(-ENOMEM);
56565658

5657-
if (!(inode->i_state & I_NEW))
5658-
return inode;
5659+
if (!(inode->vfs_inode.i_state & I_NEW))
5660+
return &inode->vfs_inode;
56595661

56605662
path = btrfs_alloc_path();
56615663
if (!path)
56625664
return ERR_PTR(-ENOMEM);
56635665

5664-
ret = btrfs_read_locked_inode(BTRFS_I(inode), path);
5666+
ret = btrfs_read_locked_inode(inode, path);
56655667
btrfs_free_path(path);
56665668
if (ret)
56675669
return ERR_PTR(ret);
56685670

5669-
unlock_new_inode(inode);
5670-
return inode;
5671+
unlock_new_inode(&inode->vfs_inode);
5672+
return &inode->vfs_inode;
56715673
}
56725674

56735675
static struct inode *new_simple_dir(struct inode *dir,

0 commit comments

Comments
 (0)