Skip to content

Commit 8ad7c62

Browse files
Christoph Hellwigdjwong
Christoph Hellwig
authored andcommitted
xfs: remove the ip argument to xfs_defer_finish
And instead require callers to explicitly join the inode using xfs_defer_ijoin. Also consolidate the defer error handling in a few places using a goto label. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 882d878 commit 8ad7c62

15 files changed

+129
-116
lines changed

fs/xfs/libxfs/xfs_attr.c

+73-67
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,12 @@ xfs_attr_set(
328328
*/
329329
xfs_defer_init(args.dfops, args.firstblock);
330330
error = xfs_attr_shortform_to_leaf(&args);
331-
if (!error)
332-
error = xfs_defer_finish(&args.trans, args.dfops, dp);
333-
if (error) {
334-
args.trans = NULL;
335-
xfs_defer_cancel(&dfops);
336-
goto out;
337-
}
331+
if (error)
332+
goto out_defer_cancel;
333+
xfs_defer_ijoin(args.dfops, dp);
334+
error = xfs_defer_finish(&args.trans, args.dfops);
335+
if (error)
336+
goto out_defer_cancel;
338337

339338
/*
340339
* Commit the leaf transformation. We'll need another (linked)
@@ -373,6 +372,9 @@ xfs_attr_set(
373372

374373
return error;
375374

375+
out_defer_cancel:
376+
xfs_defer_cancel(&dfops);
377+
args.trans = NULL;
376378
out:
377379
if (args.trans)
378380
xfs_trans_cancel(args.trans);
@@ -593,13 +595,12 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
593595
*/
594596
xfs_defer_init(args->dfops, args->firstblock);
595597
error = xfs_attr3_leaf_to_node(args);
596-
if (!error)
597-
error = xfs_defer_finish(&args->trans, args->dfops, dp);
598-
if (error) {
599-
args->trans = NULL;
600-
xfs_defer_cancel(args->dfops);
601-
return error;
602-
}
598+
if (error)
599+
goto out_defer_cancel;
600+
xfs_defer_ijoin(args->dfops, dp);
601+
error = xfs_defer_finish(&args->trans, args->dfops);
602+
if (error)
603+
goto out_defer_cancel;
603604

604605
/*
605606
* Commit the current trans (including the inode) and start
@@ -684,14 +685,12 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
684685
xfs_defer_init(args->dfops, args->firstblock);
685686
error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
686687
/* bp is gone due to xfs_da_shrink_inode */
687-
if (!error)
688-
error = xfs_defer_finish(&args->trans,
689-
args->dfops, dp);
690-
if (error) {
691-
args->trans = NULL;
692-
xfs_defer_cancel(args->dfops);
693-
return error;
694-
}
688+
if (error)
689+
goto out_defer_cancel;
690+
xfs_defer_ijoin(args->dfops, dp);
691+
error = xfs_defer_finish(&args->trans, args->dfops);
692+
if (error)
693+
goto out_defer_cancel;
695694
}
696695

697696
/*
@@ -706,6 +705,10 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
706705
error = xfs_attr3_leaf_clearflag(args);
707706
}
708707
return error;
708+
out_defer_cancel:
709+
xfs_defer_cancel(args->dfops);
710+
args->trans = NULL;
711+
return error;
709712
}
710713

711714
/*
@@ -747,15 +750,18 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
747750
xfs_defer_init(args->dfops, args->firstblock);
748751
error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
749752
/* bp is gone due to xfs_da_shrink_inode */
750-
if (!error)
751-
error = xfs_defer_finish(&args->trans, args->dfops, dp);
752-
if (error) {
753-
args->trans = NULL;
754-
xfs_defer_cancel(args->dfops);
755-
return error;
756-
}
753+
if (error)
754+
goto out_defer_cancel;
755+
xfs_defer_ijoin(args->dfops, dp);
756+
error = xfs_defer_finish(&args->trans, args->dfops);
757+
if (error)
758+
goto out_defer_cancel;
757759
}
758760
return 0;
761+
out_defer_cancel:
762+
xfs_defer_cancel(args->dfops);
763+
args->trans = NULL;
764+
return error;
759765
}
760766

761767
/*
@@ -872,14 +878,12 @@ xfs_attr_node_addname(xfs_da_args_t *args)
872878
state = NULL;
873879
xfs_defer_init(args->dfops, args->firstblock);
874880
error = xfs_attr3_leaf_to_node(args);
875-
if (!error)
876-
error = xfs_defer_finish(&args->trans,
877-
args->dfops, dp);
878-
if (error) {
879-
args->trans = NULL;
880-
xfs_defer_cancel(args->dfops);
881-
goto out;
882-
}
881+
if (error)
882+
goto out_defer_cancel;
883+
xfs_defer_ijoin(args->dfops, dp);
884+
error = xfs_defer_finish(&args->trans, args->dfops);
885+
if (error)
886+
goto out_defer_cancel;
883887

884888
/*
885889
* Commit the node conversion and start the next
@@ -900,13 +904,12 @@ xfs_attr_node_addname(xfs_da_args_t *args)
900904
*/
901905
xfs_defer_init(args->dfops, args->firstblock);
902906
error = xfs_da3_split(state);
903-
if (!error)
904-
error = xfs_defer_finish(&args->trans, args->dfops, dp);
905-
if (error) {
906-
args->trans = NULL;
907-
xfs_defer_cancel(args->dfops);
908-
goto out;
909-
}
907+
if (error)
908+
goto out_defer_cancel;
909+
xfs_defer_ijoin(args->dfops, dp);
910+
error = xfs_defer_finish(&args->trans, args->dfops);
911+
if (error)
912+
goto out_defer_cancel;
910913
} else {
911914
/*
912915
* Addition succeeded, update Btree hashvals.
@@ -999,14 +1002,12 @@ xfs_attr_node_addname(xfs_da_args_t *args)
9991002
if (retval && (state->path.active > 1)) {
10001003
xfs_defer_init(args->dfops, args->firstblock);
10011004
error = xfs_da3_join(state);
1002-
if (!error)
1003-
error = xfs_defer_finish(&args->trans,
1004-
args->dfops, dp);
1005-
if (error) {
1006-
args->trans = NULL;
1007-
xfs_defer_cancel(args->dfops);
1008-
goto out;
1009-
}
1005+
if (error)
1006+
goto out_defer_cancel;
1007+
xfs_defer_ijoin(args->dfops, dp);
1008+
error = xfs_defer_finish(&args->trans, args->dfops);
1009+
if (error)
1010+
goto out_defer_cancel;
10101011
}
10111012

10121013
/*
@@ -1032,6 +1033,10 @@ xfs_attr_node_addname(xfs_da_args_t *args)
10321033
if (error)
10331034
return error;
10341035
return retval;
1036+
out_defer_cancel:
1037+
xfs_defer_cancel(args->dfops);
1038+
args->trans = NULL;
1039+
goto out;
10351040
}
10361041

10371042
/*
@@ -1122,13 +1127,12 @@ xfs_attr_node_removename(xfs_da_args_t *args)
11221127
if (retval && (state->path.active > 1)) {
11231128
xfs_defer_init(args->dfops, args->firstblock);
11241129
error = xfs_da3_join(state);
1125-
if (!error)
1126-
error = xfs_defer_finish(&args->trans, args->dfops, dp);
1127-
if (error) {
1128-
args->trans = NULL;
1129-
xfs_defer_cancel(args->dfops);
1130-
goto out;
1131-
}
1130+
if (error)
1131+
goto out_defer_cancel;
1132+
xfs_defer_ijoin(args->dfops, dp);
1133+
error = xfs_defer_finish(&args->trans, args->dfops);
1134+
if (error)
1135+
goto out_defer_cancel;
11321136
/*
11331137
* Commit the Btree join operation and start a new trans.
11341138
*/
@@ -1156,14 +1160,12 @@ xfs_attr_node_removename(xfs_da_args_t *args)
11561160
xfs_defer_init(args->dfops, args->firstblock);
11571161
error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
11581162
/* bp is gone due to xfs_da_shrink_inode */
1159-
if (!error)
1160-
error = xfs_defer_finish(&args->trans,
1161-
args->dfops, dp);
1162-
if (error) {
1163-
args->trans = NULL;
1164-
xfs_defer_cancel(args->dfops);
1165-
goto out;
1166-
}
1163+
if (error)
1164+
goto out_defer_cancel;
1165+
xfs_defer_ijoin(args->dfops, dp);
1166+
error = xfs_defer_finish(&args->trans, args->dfops);
1167+
if (error)
1168+
goto out_defer_cancel;
11671169
} else
11681170
xfs_trans_brelse(args->trans, bp);
11691171
}
@@ -1172,6 +1174,10 @@ xfs_attr_node_removename(xfs_da_args_t *args)
11721174
out:
11731175
xfs_da_state_free(state);
11741176
return error;
1177+
out_defer_cancel:
1178+
xfs_defer_cancel(args->dfops);
1179+
args->trans = NULL;
1180+
goto out;
11751181
}
11761182

11771183
/*

fs/xfs/libxfs/xfs_attr_remote.c

+20-15
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,12 @@ xfs_attr_rmtval_set(
467467
error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno,
468468
blkcnt, XFS_BMAPI_ATTRFORK, args->firstblock,
469469
args->total, &map, &nmap, args->dfops);
470-
if (!error)
471-
error = xfs_defer_finish(&args->trans, args->dfops, dp);
472-
if (error) {
473-
args->trans = NULL;
474-
xfs_defer_cancel(args->dfops);
475-
return error;
476-
}
470+
if (error)
471+
goto out_defer_cancel;
472+
xfs_defer_ijoin(args->dfops, dp);
473+
error = xfs_defer_finish(&args->trans, args->dfops);
474+
if (error)
475+
goto out_defer_cancel;
477476

478477
ASSERT(nmap == 1);
479478
ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
@@ -539,6 +538,10 @@ xfs_attr_rmtval_set(
539538
}
540539
ASSERT(valuelen == 0);
541540
return 0;
541+
out_defer_cancel:
542+
xfs_defer_cancel(args->dfops);
543+
args->trans = NULL;
544+
return error;
542545
}
543546

544547
/*
@@ -609,14 +612,12 @@ xfs_attr_rmtval_remove(
609612
error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
610613
XFS_BMAPI_ATTRFORK, 1, args->firstblock,
611614
args->dfops, &done);
612-
if (!error)
613-
error = xfs_defer_finish(&args->trans, args->dfops,
614-
args->dp);
615-
if (error) {
616-
args->trans = NULL;
617-
xfs_defer_cancel(args->dfops);
618-
return error;
619-
}
615+
if (error)
616+
goto out_defer_cancel;
617+
xfs_defer_ijoin(args->dfops, args->dp);
618+
error = xfs_defer_finish(&args->trans, args->dfops);
619+
if (error)
620+
goto out_defer_cancel;
620621

621622
/*
622623
* Close out trans and start the next one in the chain.
@@ -626,4 +627,8 @@ xfs_attr_rmtval_remove(
626627
return error;
627628
}
628629
return 0;
630+
out_defer_cancel:
631+
xfs_defer_cancel(args->dfops);
632+
args->trans = NULL;
633+
return error;
629634
}

fs/xfs/libxfs/xfs_bmap.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ xfs_bmap_add_attrfork(
11961196
xfs_log_sb(tp);
11971197
}
11981198

1199-
error = xfs_defer_finish(&tp, &dfops, NULL);
1199+
error = xfs_defer_finish(&tp, &dfops);
12001200
if (error)
12011201
goto bmap_cancel;
12021202
error = xfs_trans_commit(tp);
@@ -6402,7 +6402,7 @@ xfs_bmap_split_extent(
64026402
if (error)
64036403
goto out;
64046404

6405-
error = xfs_defer_finish(&tp, &dfops, NULL);
6405+
error = xfs_defer_finish(&tp, &dfops);
64066406
if (error)
64076407
goto out;
64086408

fs/xfs/libxfs/xfs_defer.c

+2-6
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ xfs_defer_has_unfinished_work(
277277

278278
/*
279279
* Add this inode to the deferred op. Each joined inode is relogged
280-
* each time we roll the transaction, in addition to any inode passed
281-
* to xfs_defer_finish().
280+
* each time we roll the transaction.
282281
*/
283282
int
284283
xfs_defer_ijoin(
@@ -310,8 +309,7 @@ xfs_defer_ijoin(
310309
int
311310
xfs_defer_finish(
312311
struct xfs_trans **tp,
313-
struct xfs_defer_ops *dop,
314-
struct xfs_inode *ip)
312+
struct xfs_defer_ops *dop)
315313
{
316314
struct xfs_defer_pending *dfp;
317315
struct list_head *li;
@@ -324,8 +322,6 @@ xfs_defer_finish(
324322

325323
trace_xfs_defer_finish((*tp)->t_mountp, dop);
326324

327-
xfs_defer_ijoin(dop, ip);
328-
329325
/* Until we run out of pending work to finish... */
330326
while (xfs_defer_has_unfinished_work(dop)) {
331327
/* Log intents for work items sitting in the intake. */

fs/xfs/libxfs/xfs_defer.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ struct xfs_defer_ops {
7272

7373
void xfs_defer_add(struct xfs_defer_ops *dop, enum xfs_defer_ops_type type,
7474
struct list_head *h);
75-
int xfs_defer_finish(struct xfs_trans **tp, struct xfs_defer_ops *dop,
76-
struct xfs_inode *ip);
75+
int xfs_defer_finish(struct xfs_trans **tp, struct xfs_defer_ops *dop);
7776
void xfs_defer_cancel(struct xfs_defer_ops *dop);
7877
void xfs_defer_init(struct xfs_defer_ops *dop, xfs_fsblock_t *fbp);
7978
bool xfs_defer_has_unfinished_work(struct xfs_defer_ops *dop);

fs/xfs/libxfs/xfs_refcount.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ xfs_refcount_recover_cow_leftovers(
16791679
xfs_bmap_add_free(mp, &dfops, fsb,
16801680
rr->rr_rrec.rc_blockcount, NULL);
16811681

1682-
error = xfs_defer_finish(&tp, &dfops, NULL);
1682+
error = xfs_defer_finish(&tp, &dfops);
16831683
if (error)
16841684
goto out_defer;
16851685

fs/xfs/xfs_bmap_item.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ xfs_bui_recover(
502502
}
503503

504504
/* Finish transaction, free inodes. */
505-
error = xfs_defer_finish(&tp, &dfops, NULL);
505+
error = xfs_defer_finish(&tp, &dfops);
506506
if (error)
507507
goto err_dfops;
508508

0 commit comments

Comments
 (0)