Skip to content

Commit a488d8a

Browse files
fdmananakdave
authored andcommitted
btrfs: return a btrfs_inode from btrfs_iget_logging()
All callers of btrfs_iget_logging() are interested in the btrfs_inode structure rather than the VFS inode, so make btrfs_iget_logging() return the btrfs_inode instead, avoiding lots of BTRFS_I() calls. Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 7ef3cbf commit a488d8a

File tree

1 file changed

+45
-49
lines changed

1 file changed

+45
-49
lines changed

fs/btrfs/tree-log.c

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void wait_log_commit(struct btrfs_root *root, int transid);
138138
* and once to do all the other items.
139139
*/
140140

141-
static struct inode *btrfs_iget_logging(u64 objectid, struct btrfs_root *root)
141+
static struct btrfs_inode *btrfs_iget_logging(u64 objectid, struct btrfs_root *root)
142142
{
143143
unsigned int nofs_flag;
144144
struct inode *inode;
@@ -154,7 +154,10 @@ static struct inode *btrfs_iget_logging(u64 objectid, struct btrfs_root *root)
154154
inode = btrfs_iget(objectid, root);
155155
memalloc_nofs_restore(nofs_flag);
156156

157-
return inode;
157+
if (IS_ERR(inode))
158+
return ERR_CAST(inode);
159+
160+
return BTRFS_I(inode);
158161
}
159162

160163
/*
@@ -616,12 +619,12 @@ static int read_alloc_one_name(struct extent_buffer *eb, void *start, int len,
616619
static noinline struct inode *read_one_inode(struct btrfs_root *root,
617620
u64 objectid)
618621
{
619-
struct inode *inode;
622+
struct btrfs_inode *inode;
620623

621624
inode = btrfs_iget_logging(objectid, root);
622625
if (IS_ERR(inode))
623-
inode = NULL;
624-
return inode;
626+
return NULL;
627+
return &inode->vfs_inode;
625628
}
626629

627630
/* replays a single extent in 'eb' at 'slot' with 'key' into the
@@ -5481,7 +5484,6 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
54815484
ihold(&curr_inode->vfs_inode);
54825485

54835486
while (true) {
5484-
struct inode *vfs_inode;
54855487
struct btrfs_key key;
54865488
struct btrfs_key found_key;
54875489
u64 next_index;
@@ -5497,7 +5499,7 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
54975499
struct extent_buffer *leaf = path->nodes[0];
54985500
struct btrfs_dir_item *di;
54995501
struct btrfs_key di_key;
5500-
struct inode *di_inode;
5502+
struct btrfs_inode *di_inode;
55015503
int log_mode = LOG_INODE_EXISTS;
55025504
int type;
55035505

@@ -5524,17 +5526,16 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
55245526
goto out;
55255527
}
55265528

5527-
if (!need_log_inode(trans, BTRFS_I(di_inode))) {
5528-
btrfs_add_delayed_iput(BTRFS_I(di_inode));
5529+
if (!need_log_inode(trans, di_inode)) {
5530+
btrfs_add_delayed_iput(di_inode);
55295531
break;
55305532
}
55315533

55325534
ctx->log_new_dentries = false;
55335535
if (type == BTRFS_FT_DIR)
55345536
log_mode = LOG_INODE_ALL;
5535-
ret = btrfs_log_inode(trans, BTRFS_I(di_inode),
5536-
log_mode, ctx);
5537-
btrfs_add_delayed_iput(BTRFS_I(di_inode));
5537+
ret = btrfs_log_inode(trans, di_inode, log_mode, ctx);
5538+
btrfs_add_delayed_iput(di_inode);
55385539
if (ret)
55395540
goto out;
55405541
if (ctx->log_new_dentries) {
@@ -5576,14 +5577,13 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans,
55765577
kfree(dir_elem);
55775578

55785579
btrfs_add_delayed_iput(curr_inode);
5579-
curr_inode = NULL;
55805580

5581-
vfs_inode = btrfs_iget_logging(ino, root);
5582-
if (IS_ERR(vfs_inode)) {
5583-
ret = PTR_ERR(vfs_inode);
5581+
curr_inode = btrfs_iget_logging(ino, root);
5582+
if (IS_ERR(curr_inode)) {
5583+
ret = PTR_ERR(curr_inode);
5584+
curr_inode = NULL;
55845585
break;
55855586
}
5586-
curr_inode = BTRFS_I(vfs_inode);
55875587
}
55885588
out:
55895589
btrfs_free_path(path);
@@ -5661,7 +5661,7 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans,
56615661
struct btrfs_log_ctx *ctx)
56625662
{
56635663
struct btrfs_ino_list *ino_elem;
5664-
struct inode *inode;
5664+
struct btrfs_inode *inode;
56655665

56665666
/*
56675667
* It's rare to have a lot of conflicting inodes, in practice it is not
@@ -5752,12 +5752,12 @@ static int add_conflicting_inode(struct btrfs_trans_handle *trans,
57525752
* inode in LOG_INODE_EXISTS mode and rename operations update the log,
57535753
* so that the log ends up with the new name and without the old name.
57545754
*/
5755-
if (!need_log_inode(trans, BTRFS_I(inode))) {
5756-
btrfs_add_delayed_iput(BTRFS_I(inode));
5755+
if (!need_log_inode(trans, inode)) {
5756+
btrfs_add_delayed_iput(inode);
57575757
return 0;
57585758
}
57595759

5760-
btrfs_add_delayed_iput(BTRFS_I(inode));
5760+
btrfs_add_delayed_iput(inode);
57615761

57625762
ino_elem = kmalloc(sizeof(*ino_elem), GFP_NOFS);
57635763
if (!ino_elem)
@@ -5793,7 +5793,7 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
57935793
*/
57945794
while (!list_empty(&ctx->conflict_inodes)) {
57955795
struct btrfs_ino_list *curr;
5796-
struct inode *inode;
5796+
struct btrfs_inode *inode;
57975797
u64 ino;
57985798
u64 parent;
57995799

@@ -5829,9 +5829,8 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
58295829
* dir index key range logged for the directory. So we
58305830
* must make sure the deletion is recorded.
58315831
*/
5832-
ret = btrfs_log_inode(trans, BTRFS_I(inode),
5833-
LOG_INODE_ALL, ctx);
5834-
btrfs_add_delayed_iput(BTRFS_I(inode));
5832+
ret = btrfs_log_inode(trans, inode, LOG_INODE_ALL, ctx);
5833+
btrfs_add_delayed_iput(inode);
58355834
if (ret)
58365835
break;
58375836
continue;
@@ -5847,8 +5846,8 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
58475846
* it again because if some other task logged the inode after
58485847
* that, we can avoid doing it again.
58495848
*/
5850-
if (!need_log_inode(trans, BTRFS_I(inode))) {
5851-
btrfs_add_delayed_iput(BTRFS_I(inode));
5849+
if (!need_log_inode(trans, inode)) {
5850+
btrfs_add_delayed_iput(inode);
58525851
continue;
58535852
}
58545853

@@ -5859,8 +5858,8 @@ static int log_conflicting_inodes(struct btrfs_trans_handle *trans,
58595858
* well because during a rename we pin the log and update the
58605859
* log with the new name before we unpin it.
58615860
*/
5862-
ret = btrfs_log_inode(trans, BTRFS_I(inode), LOG_INODE_EXISTS, ctx);
5863-
btrfs_add_delayed_iput(BTRFS_I(inode));
5861+
ret = btrfs_log_inode(trans, inode, LOG_INODE_EXISTS, ctx);
5862+
btrfs_add_delayed_iput(inode);
58645863
if (ret)
58655864
break;
58665865
}
@@ -6351,7 +6350,7 @@ static int log_new_delayed_dentries(struct btrfs_trans_handle *trans,
63516350

63526351
list_for_each_entry(item, delayed_ins_list, log_list) {
63536352
struct btrfs_dir_item *dir_item;
6354-
struct inode *di_inode;
6353+
struct btrfs_inode *di_inode;
63556354
struct btrfs_key key;
63566355
int log_mode = LOG_INODE_EXISTS;
63576356

@@ -6367,21 +6366,21 @@ static int log_new_delayed_dentries(struct btrfs_trans_handle *trans,
63676366
break;
63686367
}
63696368

6370-
if (!need_log_inode(trans, BTRFS_I(di_inode))) {
6371-
btrfs_add_delayed_iput(BTRFS_I(di_inode));
6369+
if (!need_log_inode(trans, di_inode)) {
6370+
btrfs_add_delayed_iput(di_inode);
63726371
continue;
63736372
}
63746373

63756374
if (btrfs_stack_dir_ftype(dir_item) == BTRFS_FT_DIR)
63766375
log_mode = LOG_INODE_ALL;
63776376

63786377
ctx->log_new_dentries = false;
6379-
ret = btrfs_log_inode(trans, BTRFS_I(di_inode), log_mode, ctx);
6378+
ret = btrfs_log_inode(trans, di_inode, log_mode, ctx);
63806379

63816380
if (!ret && ctx->log_new_dentries)
6382-
ret = log_new_dir_dentries(trans, BTRFS_I(di_inode), ctx);
6381+
ret = log_new_dir_dentries(trans, di_inode, ctx);
63836382

6384-
btrfs_add_delayed_iput(BTRFS_I(di_inode));
6383+
btrfs_add_delayed_iput(di_inode);
63856384

63866385
if (ret)
63876386
break;
@@ -6789,7 +6788,7 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans,
67896788
ptr = btrfs_item_ptr_offset(leaf, slot);
67906789
while (cur_offset < item_size) {
67916790
struct btrfs_key inode_key;
6792-
struct inode *dir_inode;
6791+
struct btrfs_inode *dir_inode;
67936792

67946793
inode_key.type = BTRFS_INODE_ITEM_KEY;
67956794
inode_key.offset = 0;
@@ -6838,18 +6837,16 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans,
68386837
goto out;
68396838
}
68406839

6841-
if (!need_log_inode(trans, BTRFS_I(dir_inode))) {
6842-
btrfs_add_delayed_iput(BTRFS_I(dir_inode));
6840+
if (!need_log_inode(trans, dir_inode)) {
6841+
btrfs_add_delayed_iput(dir_inode);
68436842
continue;
68446843
}
68456844

68466845
ctx->log_new_dentries = false;
6847-
ret = btrfs_log_inode(trans, BTRFS_I(dir_inode),
6848-
LOG_INODE_ALL, ctx);
6846+
ret = btrfs_log_inode(trans, dir_inode, LOG_INODE_ALL, ctx);
68496847
if (!ret && ctx->log_new_dentries)
6850-
ret = log_new_dir_dentries(trans,
6851-
BTRFS_I(dir_inode), ctx);
6852-
btrfs_add_delayed_iput(BTRFS_I(dir_inode));
6848+
ret = log_new_dir_dentries(trans, dir_inode, ctx);
6849+
btrfs_add_delayed_iput(dir_inode);
68536850
if (ret)
68546851
goto out;
68556852
}
@@ -6874,7 +6871,7 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans,
68746871
struct extent_buffer *leaf;
68756872
int slot;
68766873
struct btrfs_key search_key;
6877-
struct inode *inode;
6874+
struct btrfs_inode *inode;
68786875
u64 ino;
68796876
int ret = 0;
68806877

@@ -6889,11 +6886,10 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans,
68896886
if (IS_ERR(inode))
68906887
return PTR_ERR(inode);
68916888

6892-
if (BTRFS_I(inode)->generation >= trans->transid &&
6893-
need_log_inode(trans, BTRFS_I(inode)))
6894-
ret = btrfs_log_inode(trans, BTRFS_I(inode),
6895-
LOG_INODE_EXISTS, ctx);
6896-
btrfs_add_delayed_iput(BTRFS_I(inode));
6889+
if (inode->generation >= trans->transid &&
6890+
need_log_inode(trans, inode))
6891+
ret = btrfs_log_inode(trans, inode, LOG_INODE_EXISTS, ctx);
6892+
btrfs_add_delayed_iput(inode);
68976893
if (ret)
68986894
return ret;
68996895

0 commit comments

Comments
 (0)