Skip to content

Commit b204e5c

Browse files
fdmananakdave
authored andcommitted
btrfs: make btrfs_iget() return a btrfs inode instead
It's an internal function and most of the time the callers are doing a lot of BTRFS_I() calls on the returned VFS inode to get the btrfs inode, so change the return type to struct btrfs_inode instead. Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 14d063e commit b204e5c

File tree

9 files changed

+76
-71
lines changed

9 files changed

+76
-71
lines changed

fs/btrfs/btrfs_inode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ int __init btrfs_init_cachep(void);
595595
void __cold btrfs_destroy_cachep(void);
596596
struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
597597
struct btrfs_path *path);
598-
struct inode *btrfs_iget(u64 ino, struct btrfs_root *root);
598+
struct btrfs_inode *btrfs_iget(u64 ino, struct btrfs_root *root);
599599
struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
600600
struct folio *folio, u64 start, u64 len);
601601
int btrfs_update_inode(struct btrfs_trans_handle *trans,

fs/btrfs/defrag.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static int btrfs_run_defrag_inode(struct btrfs_fs_info *fs_info,
225225
struct file_ra_state *ra)
226226
{
227227
struct btrfs_root *inode_root;
228-
struct inode *inode;
228+
struct btrfs_inode *inode;
229229
struct btrfs_ioctl_defrag_range_args range;
230230
int ret = 0;
231231
u64 cur = 0;
@@ -250,24 +250,24 @@ static int btrfs_run_defrag_inode(struct btrfs_fs_info *fs_info,
250250
goto cleanup;
251251
}
252252

253-
if (cur >= i_size_read(inode)) {
254-
iput(inode);
253+
if (cur >= i_size_read(&inode->vfs_inode)) {
254+
iput(&inode->vfs_inode);
255255
goto cleanup;
256256
}
257257

258258
/* Do a chunk of defrag */
259-
clear_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags);
259+
clear_bit(BTRFS_INODE_IN_DEFRAG, &inode->runtime_flags);
260260
memset(&range, 0, sizeof(range));
261261
range.len = (u64)-1;
262262
range.start = cur;
263263
range.extent_thresh = defrag->extent_thresh;
264-
file_ra_state_init(ra, inode->i_mapping);
264+
file_ra_state_init(ra, inode->vfs_inode.i_mapping);
265265

266266
sb_start_write(fs_info->sb);
267-
ret = btrfs_defrag_file(BTRFS_I(inode), ra, &range, defrag->transid,
267+
ret = btrfs_defrag_file(inode, ra, &range, defrag->transid,
268268
BTRFS_DEFRAG_BATCH);
269269
sb_end_write(fs_info->sb);
270-
iput(inode);
270+
iput(&inode->vfs_inode);
271271

272272
if (ret < 0)
273273
goto cleanup;

fs/btrfs/export.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,
7575
{
7676
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
7777
struct btrfs_root *root;
78-
struct inode *inode;
78+
struct btrfs_inode *inode;
7979

8080
if (objectid < BTRFS_FIRST_FREE_OBJECTID)
8181
return ERR_PTR(-ESTALE);
@@ -89,12 +89,12 @@ struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid,
8989
if (IS_ERR(inode))
9090
return ERR_CAST(inode);
9191

92-
if (generation != 0 && generation != inode->i_generation) {
93-
iput(inode);
92+
if (generation != 0 && generation != inode->vfs_inode.i_generation) {
93+
iput(&inode->vfs_inode);
9494
return ERR_PTR(-ESTALE);
9595
}
9696

97-
return d_obtain_alias(inode);
97+
return d_obtain_alias(&inode->vfs_inode);
9898
}
9999

100100
static struct dentry *btrfs_fh_to_parent(struct super_block *sb, struct fid *fh,
@@ -146,6 +146,7 @@ static struct dentry *btrfs_fh_to_dentry(struct super_block *sb, struct fid *fh,
146146
struct dentry *btrfs_get_parent(struct dentry *child)
147147
{
148148
struct btrfs_inode *dir = BTRFS_I(d_inode(child));
149+
struct btrfs_inode *inode;
149150
struct btrfs_root *root = dir->root;
150151
struct btrfs_fs_info *fs_info = root->fs_info;
151152
struct btrfs_path *path;
@@ -210,7 +211,11 @@ struct dentry *btrfs_get_parent(struct dentry *child)
210211
found_key.offset, 0);
211212
}
212213

213-
return d_obtain_alias(btrfs_iget(key.objectid, root));
214+
inode = btrfs_iget(key.objectid, root);
215+
if (IS_ERR(inode))
216+
return ERR_CAST(inode);
217+
218+
return d_obtain_alias(&inode->vfs_inode);
214219
fail:
215220
btrfs_free_path(path);
216221
return ERR_PTR(ret);

fs/btrfs/inode.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,7 +3547,6 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
35473547
struct extent_buffer *leaf;
35483548
struct btrfs_key key, found_key;
35493549
struct btrfs_trans_handle *trans;
3550-
struct inode *inode;
35513550
u64 last_objectid = 0;
35523551
int ret = 0, nr_unlink = 0;
35533552

@@ -3566,6 +3565,8 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
35663565
key.offset = (u64)-1;
35673566

35683567
while (1) {
3568+
struct btrfs_inode *inode;
3569+
35693570
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
35703571
if (ret < 0)
35713572
goto out;
@@ -3689,10 +3690,10 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
36893690
* deleted but wasn't. The inode number may have been reused,
36903691
* but either way, we can delete the orphan item.
36913692
*/
3692-
if (!inode || inode->i_nlink) {
3693+
if (!inode || inode->vfs_inode.i_nlink) {
36933694
if (inode) {
3694-
ret = btrfs_drop_verity_items(BTRFS_I(inode));
3695-
iput(inode);
3695+
ret = btrfs_drop_verity_items(inode);
3696+
iput(&inode->vfs_inode);
36963697
inode = NULL;
36973698
if (ret)
36983699
goto out;
@@ -3715,7 +3716,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
37153716
nr_unlink++;
37163717

37173718
/* this will do delete_inode and everything for us */
3718-
iput(inode);
3719+
iput(&inode->vfs_inode);
37193720
}
37203721
/* release the path since we're done with it */
37213722
btrfs_release_path(path);
@@ -5665,7 +5666,7 @@ struct inode *btrfs_iget_path(u64 ino, struct btrfs_root *root,
56655666
/*
56665667
* Get an inode object given its inode number and corresponding root.
56675668
*/
5668-
struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
5669+
struct btrfs_inode *btrfs_iget(u64 ino, struct btrfs_root *root)
56695670
{
56705671
struct btrfs_inode *inode;
56715672
struct btrfs_path *path;
@@ -5676,7 +5677,7 @@ struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
56765677
return ERR_PTR(-ENOMEM);
56775678

56785679
if (!(inode->vfs_inode.i_state & I_NEW))
5679-
return &inode->vfs_inode;
5680+
return inode;
56805681

56815682
path = btrfs_alloc_path();
56825683
if (!path)
@@ -5688,7 +5689,7 @@ struct inode *btrfs_iget(u64 ino, struct btrfs_root *root)
56885689
return ERR_PTR(ret);
56895690

56905691
unlock_new_inode(&inode->vfs_inode);
5691-
return &inode->vfs_inode;
5692+
return inode;
56925693
}
56935694

56945695
static struct btrfs_inode *new_simple_dir(struct inode *dir,
@@ -5748,7 +5749,7 @@ static inline u8 btrfs_inode_type(const struct btrfs_inode *inode)
57485749
struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
57495750
{
57505751
struct btrfs_fs_info *fs_info = inode_to_fs_info(dir);
5751-
struct inode *inode;
5752+
struct btrfs_inode *inode;
57525753
struct btrfs_root *root = BTRFS_I(dir)->root;
57535754
struct btrfs_root *sub_root = root;
57545755
struct btrfs_key location = { 0 };
@@ -5765,49 +5766,48 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
57655766
if (location.type == BTRFS_INODE_ITEM_KEY) {
57665767
inode = btrfs_iget(location.objectid, root);
57675768
if (IS_ERR(inode))
5768-
return inode;
5769+
return ERR_CAST(inode);
57695770

57705771
/* Do extra check against inode mode with di_type */
5771-
if (btrfs_inode_type(BTRFS_I(inode)) != di_type) {
5772+
if (btrfs_inode_type(inode) != di_type) {
57725773
btrfs_crit(fs_info,
57735774
"inode mode mismatch with dir: inode mode=0%o btrfs type=%u dir type=%u",
5774-
inode->i_mode, btrfs_inode_type(BTRFS_I(inode)),
5775+
inode->vfs_inode.i_mode, btrfs_inode_type(inode),
57755776
di_type);
5776-
iput(inode);
5777+
iput(&inode->vfs_inode);
57775778
return ERR_PTR(-EUCLEAN);
57785779
}
5779-
return inode;
5780+
return &inode->vfs_inode;
57805781
}
57815782

57825783
ret = fixup_tree_root_location(fs_info, BTRFS_I(dir), dentry,
57835784
&location, &sub_root);
57845785
if (ret < 0) {
5785-
if (ret != -ENOENT) {
5786+
if (ret != -ENOENT)
57865787
inode = ERR_PTR(ret);
5787-
} else {
5788-
struct btrfs_inode *b_inode;
5789-
5790-
b_inode = new_simple_dir(dir, &location, root);
5791-
inode = &b_inode->vfs_inode;
5792-
}
5788+
else
5789+
inode = new_simple_dir(dir, &location, root);
57935790
} else {
57945791
inode = btrfs_iget(location.objectid, sub_root);
57955792
btrfs_put_root(sub_root);
57965793

57975794
if (IS_ERR(inode))
5798-
return inode;
5795+
return ERR_CAST(inode);
57995796

58005797
down_read(&fs_info->cleanup_work_sem);
5801-
if (!sb_rdonly(inode->i_sb))
5798+
if (!sb_rdonly(inode->vfs_inode.i_sb))
58025799
ret = btrfs_orphan_cleanup(sub_root);
58035800
up_read(&fs_info->cleanup_work_sem);
58045801
if (ret) {
5805-
iput(inode);
5802+
iput(&inode->vfs_inode);
58065803
inode = ERR_PTR(ret);
58075804
}
58085805
}
58095806

5810-
return inode;
5807+
if (IS_ERR(inode))
5808+
return ERR_CAST(inode);
5809+
5810+
return &inode->vfs_inode;
58115811
}
58125812

58135813
static int btrfs_dentry_delete(const struct dentry *dentry)
@@ -6460,7 +6460,7 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
64606460
path = NULL;
64616461

64626462
if (args->subvol) {
6463-
struct inode *parent;
6463+
struct btrfs_inode *parent;
64646464

64656465
/*
64666466
* Subvolumes inherit properties from their parent subvolume,
@@ -6471,8 +6471,8 @@ int btrfs_create_new_inode(struct btrfs_trans_handle *trans,
64716471
ret = PTR_ERR(parent);
64726472
} else {
64736473
ret = btrfs_inode_inherit_props(trans, BTRFS_I(inode),
6474-
BTRFS_I(parent));
6475-
iput(parent);
6474+
parent);
6475+
iput(&parent->vfs_inode);
64766476
}
64776477
} else {
64786478
ret = btrfs_inode_inherit_props(trans, BTRFS_I(inode),

fs/btrfs/ioctl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,6 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
18321832
struct btrfs_path *path;
18331833
struct btrfs_key key, key2;
18341834
struct extent_buffer *leaf;
1835-
struct inode *temp_inode;
18361835
char *ptr;
18371836
int slot;
18381837
int len;
@@ -1860,6 +1859,8 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
18601859
key.type = BTRFS_INODE_REF_KEY;
18611860
key.offset = (u64)-1;
18621861
while (1) {
1862+
struct btrfs_inode *temp_inode;
1863+
18631864
ret = btrfs_search_backwards(root, &key, path);
18641865
if (ret < 0)
18651866
goto out_put;
@@ -1914,9 +1915,9 @@ static int btrfs_search_path_in_tree_user(struct mnt_idmap *idmap,
19141915
ret = PTR_ERR(temp_inode);
19151916
goto out_put;
19161917
}
1917-
ret = inode_permission(idmap, temp_inode,
1918+
ret = inode_permission(idmap, &temp_inode->vfs_inode,
19181919
MAY_READ | MAY_EXEC);
1919-
iput(temp_inode);
1920+
iput(&temp_inode->vfs_inode);
19201921
if (ret) {
19211922
ret = -EACCES;
19221923
goto out_put;

fs/btrfs/relocation.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,14 +3246,16 @@ static int delete_block_group_cache(struct btrfs_fs_info *fs_info,
32463246
{
32473247
struct btrfs_root *root = fs_info->tree_root;
32483248
struct btrfs_trans_handle *trans;
3249+
struct btrfs_inode *btrfs_inode;
32493250
int ret = 0;
32503251

32513252
if (inode)
32523253
goto truncate;
32533254

3254-
inode = btrfs_iget(ino, root);
3255-
if (IS_ERR(inode))
3255+
btrfs_inode = btrfs_iget(ino, root);
3256+
if (IS_ERR(btrfs_inode))
32563257
return -ENOENT;
3258+
inode = &btrfs_inode->vfs_inode;
32573259

32583260
truncate:
32593261
ret = btrfs_check_trunc_cache_free_space(fs_info,
@@ -3764,7 +3766,7 @@ static noinline_for_stack struct inode *create_reloc_inode(
37643766
struct btrfs_fs_info *fs_info,
37653767
const struct btrfs_block_group *group)
37663768
{
3767-
struct inode *inode = NULL;
3769+
struct btrfs_inode *inode = NULL;
37683770
struct btrfs_trans_handle *trans;
37693771
struct btrfs_root *root;
37703772
u64 objectid;
@@ -3792,18 +3794,19 @@ static noinline_for_stack struct inode *create_reloc_inode(
37923794
inode = NULL;
37933795
goto out;
37943796
}
3795-
BTRFS_I(inode)->reloc_block_group_start = group->start;
3797+
inode->reloc_block_group_start = group->start;
37963798

3797-
ret = btrfs_orphan_add(trans, BTRFS_I(inode));
3799+
ret = btrfs_orphan_add(trans, inode);
37983800
out:
37993801
btrfs_put_root(root);
38003802
btrfs_end_transaction(trans);
38013803
btrfs_btree_balance_dirty(fs_info);
38023804
if (ret) {
3803-
iput(inode);
3805+
if (inode)
3806+
iput(&inode->vfs_inode);
38043807
inode = ERR_PTR(ret);
38053808
}
3806-
return inode;
3809+
return &inode->vfs_inode;
38073810
}
38083811

38093812
/*

0 commit comments

Comments
 (0)