summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2017-08-28 13:21:03 -0400
committerDarrick J. Wong <darrick.wong@oracle.com>2017-09-01 13:55:30 -0400
commit411350df14a3d6f1c769ea64a8b43a71f8d9760e (patch)
tree6ce47a2df6894777f7147bbc4fee7fca6e9fcc34
parentf2e9ad212def50bcf4c098c6288779dd97fff0f0 (diff)
xfs: refactor xfs_trans_roll
Split xfs_trans_roll into a low-level helper that just rolls the actual transaction and a new higher level xfs_trans_roll_inode that takes care of logging and rejoining the inode. This gets rid of the NULL inode case, and allows to simplify the special cases in the deferred operation code. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/libxfs/xfs_attr.c16
-rw-r--r--fs/xfs/libxfs/xfs_attr_leaf.c6
-rw-r--r--fs/xfs/libxfs/xfs_attr_remote.c4
-rw-r--r--fs/xfs/libxfs/xfs_defer.c23
-rw-r--r--fs/xfs/xfs_attr_inactive.c6
-rw-r--r--fs/xfs/xfs_inode.c4
-rw-r--r--fs/xfs/xfs_trans.c28
-rw-r--r--fs/xfs/xfs_trans.h3
-rw-r--r--fs/xfs/xfs_trans_inode.c14
9 files changed, 48 insertions, 56 deletions
diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c
index de7b9bd30bec..bafa0f6bfafa 100644
--- a/fs/xfs/libxfs/xfs_attr.c
+++ b/fs/xfs/libxfs/xfs_attr.c
@@ -341,7 +341,7 @@ xfs_attr_set(
341 * transaction to add the new attribute to the leaf. 341 * transaction to add the new attribute to the leaf.
342 */ 342 */
343 343
344 error = xfs_trans_roll(&args.trans, dp); 344 error = xfs_trans_roll_inode(&args.trans, dp);
345 if (error) 345 if (error)
346 goto out; 346 goto out;
347 347
@@ -605,7 +605,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
605 * Commit the current trans (including the inode) and start 605 * Commit the current trans (including the inode) and start
606 * a new one. 606 * a new one.
607 */ 607 */
608 error = xfs_trans_roll(&args->trans, dp); 608 error = xfs_trans_roll_inode(&args->trans, dp);
609 if (error) 609 if (error)
610 return error; 610 return error;
611 611
@@ -620,7 +620,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
620 * Commit the transaction that added the attr name so that 620 * Commit the transaction that added the attr name so that
621 * later routines can manage their own transactions. 621 * later routines can manage their own transactions.
622 */ 622 */
623 error = xfs_trans_roll(&args->trans, dp); 623 error = xfs_trans_roll_inode(&args->trans, dp);
624 if (error) 624 if (error)
625 return error; 625 return error;
626 626
@@ -697,7 +697,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
697 /* 697 /*
698 * Commit the remove and start the next trans in series. 698 * Commit the remove and start the next trans in series.
699 */ 699 */
700 error = xfs_trans_roll(&args->trans, dp); 700 error = xfs_trans_roll_inode(&args->trans, dp);
701 701
702 } else if (args->rmtblkno > 0) { 702 } else if (args->rmtblkno > 0) {
703 /* 703 /*
@@ -885,7 +885,7 @@ restart:
885 * Commit the node conversion and start the next 885 * Commit the node conversion and start the next
886 * trans in the chain. 886 * trans in the chain.
887 */ 887 */
888 error = xfs_trans_roll(&args->trans, dp); 888 error = xfs_trans_roll_inode(&args->trans, dp);
889 if (error) 889 if (error)
890 goto out; 890 goto out;
891 891
@@ -925,7 +925,7 @@ restart:
925 * Commit the leaf addition or btree split and start the next 925 * Commit the leaf addition or btree split and start the next
926 * trans in the chain. 926 * trans in the chain.
927 */ 927 */
928 error = xfs_trans_roll(&args->trans, dp); 928 error = xfs_trans_roll_inode(&args->trans, dp);
929 if (error) 929 if (error)
930 goto out; 930 goto out;
931 931
@@ -1012,7 +1012,7 @@ restart:
1012 /* 1012 /*
1013 * Commit and start the next trans in the chain. 1013 * Commit and start the next trans in the chain.
1014 */ 1014 */
1015 error = xfs_trans_roll(&args->trans, dp); 1015 error = xfs_trans_roll_inode(&args->trans, dp);
1016 if (error) 1016 if (error)
1017 goto out; 1017 goto out;
1018 1018
@@ -1132,7 +1132,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)
1132 /* 1132 /*
1133 * Commit the Btree join operation and start a new trans. 1133 * Commit the Btree join operation and start a new trans.
1134 */ 1134 */
1135 error = xfs_trans_roll(&args->trans, dp); 1135 error = xfs_trans_roll_inode(&args->trans, dp);
1136 if (error) 1136 if (error)
1137 goto out; 1137 goto out;
1138 } 1138 }
diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index c6c15e5717e4..5c16db86b38f 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -2608,7 +2608,7 @@ xfs_attr3_leaf_clearflag(
2608 /* 2608 /*
2609 * Commit the flag value change and start the next trans in series. 2609 * Commit the flag value change and start the next trans in series.
2610 */ 2610 */
2611 return xfs_trans_roll(&args->trans, args->dp); 2611 return xfs_trans_roll_inode(&args->trans, args->dp);
2612} 2612}
2613 2613
2614/* 2614/*
@@ -2659,7 +2659,7 @@ xfs_attr3_leaf_setflag(
2659 /* 2659 /*
2660 * Commit the flag value change and start the next trans in series. 2660 * Commit the flag value change and start the next trans in series.
2661 */ 2661 */
2662 return xfs_trans_roll(&args->trans, args->dp); 2662 return xfs_trans_roll_inode(&args->trans, args->dp);
2663} 2663}
2664 2664
2665/* 2665/*
@@ -2777,7 +2777,7 @@ xfs_attr3_leaf_flipflags(
2777 /* 2777 /*
2778 * Commit the flag value change and start the next trans in series. 2778 * Commit the flag value change and start the next trans in series.
2779 */ 2779 */
2780 error = xfs_trans_roll(&args->trans, args->dp); 2780 error = xfs_trans_roll_inode(&args->trans, args->dp);
2781 2781
2782 return error; 2782 return error;
2783} 2783}
diff --git a/fs/xfs/libxfs/xfs_attr_remote.c b/fs/xfs/libxfs/xfs_attr_remote.c
index 5236d8e45146..433c36714e40 100644
--- a/fs/xfs/libxfs/xfs_attr_remote.c
+++ b/fs/xfs/libxfs/xfs_attr_remote.c
@@ -484,7 +484,7 @@ xfs_attr_rmtval_set(
484 /* 484 /*
485 * Start the next trans in the chain. 485 * Start the next trans in the chain.
486 */ 486 */
487 error = xfs_trans_roll(&args->trans, dp); 487 error = xfs_trans_roll_inode(&args->trans, dp);
488 if (error) 488 if (error)
489 return error; 489 return error;
490 } 490 }
@@ -621,7 +621,7 @@ xfs_attr_rmtval_remove(
621 /* 621 /*
622 * Close out trans and start the next one in the chain. 622 * Close out trans and start the next one in the chain.
623 */ 623 */
624 error = xfs_trans_roll(&args->trans, args->dp); 624 error = xfs_trans_roll_inode(&args->trans, args->dp);
625 if (error) 625 if (error)
626 return error; 626 return error;
627 } 627 }
diff --git a/fs/xfs/libxfs/xfs_defer.c b/fs/xfs/libxfs/xfs_defer.c
index 5c2929f94bd3..4ea2f068d95c 100644
--- a/fs/xfs/libxfs/xfs_defer.c
+++ b/fs/xfs/libxfs/xfs_defer.c
@@ -240,23 +240,19 @@ xfs_defer_trans_abort(
240STATIC int 240STATIC int
241xfs_defer_trans_roll( 241xfs_defer_trans_roll(
242 struct xfs_trans **tp, 242 struct xfs_trans **tp,
243 struct xfs_defer_ops *dop, 243 struct xfs_defer_ops *dop)
244 struct xfs_inode *ip)
245{ 244{
246 int i; 245 int i;
247 int error; 246 int error;
248 247
249 /* Log all the joined inodes except the one we passed in. */ 248 /* Log all the joined inodes. */
250 for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++) { 249 for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++)
251 if (dop->dop_inodes[i] == ip)
252 continue;
253 xfs_trans_log_inode(*tp, dop->dop_inodes[i], XFS_ILOG_CORE); 250 xfs_trans_log_inode(*tp, dop->dop_inodes[i], XFS_ILOG_CORE);
254 }
255 251
256 trace_xfs_defer_trans_roll((*tp)->t_mountp, dop); 252 trace_xfs_defer_trans_roll((*tp)->t_mountp, dop);
257 253
258 /* Roll the transaction. */ 254 /* Roll the transaction. */
259 error = xfs_trans_roll(tp, ip); 255 error = xfs_trans_roll(tp);
260 if (error) { 256 if (error) {
261 trace_xfs_defer_trans_roll_error((*tp)->t_mountp, dop, error); 257 trace_xfs_defer_trans_roll_error((*tp)->t_mountp, dop, error);
262 xfs_defer_trans_abort(*tp, dop, error); 258 xfs_defer_trans_abort(*tp, dop, error);
@@ -264,12 +260,9 @@ xfs_defer_trans_roll(
264 } 260 }
265 dop->dop_committed = true; 261 dop->dop_committed = true;
266 262
267 /* Rejoin the joined inodes except the one we passed in. */ 263 /* Rejoin the joined inodes. */
268 for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++) { 264 for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++)
269 if (dop->dop_inodes[i] == ip)
270 continue;
271 xfs_trans_ijoin(*tp, dop->dop_inodes[i], 0); 265 xfs_trans_ijoin(*tp, dop->dop_inodes[i], 0);
272 }
273 266
274 return error; 267 return error;
275} 268}
@@ -331,13 +324,15 @@ xfs_defer_finish(
331 324
332 trace_xfs_defer_finish((*tp)->t_mountp, dop); 325 trace_xfs_defer_finish((*tp)->t_mountp, dop);
333 326
327 xfs_defer_join(dop, ip);
328
334 /* Until we run out of pending work to finish... */ 329 /* Until we run out of pending work to finish... */
335 while (xfs_defer_has_unfinished_work(dop)) { 330 while (xfs_defer_has_unfinished_work(dop)) {
336 /* Log intents for work items sitting in the intake. */ 331 /* Log intents for work items sitting in the intake. */
337 xfs_defer_intake_work(*tp, dop); 332 xfs_defer_intake_work(*tp, dop);
338 333
339 /* Roll the transaction. */ 334 /* Roll the transaction. */
340 error = xfs_defer_trans_roll(tp, dop, ip); 335 error = xfs_defer_trans_roll(tp, dop);
341 if (error) 336 if (error)
342 goto out; 337 goto out;
343 338
diff --git a/fs/xfs/xfs_attr_inactive.c b/fs/xfs/xfs_attr_inactive.c
index be0b79d8900f..ebd66b19fbfc 100644
--- a/fs/xfs/xfs_attr_inactive.c
+++ b/fs/xfs/xfs_attr_inactive.c
@@ -97,7 +97,7 @@ xfs_attr3_leaf_freextent(
97 /* 97 /*
98 * Roll to next transaction. 98 * Roll to next transaction.
99 */ 99 */
100 error = xfs_trans_roll(trans, dp); 100 error = xfs_trans_roll_inode(trans, dp);
101 if (error) 101 if (error)
102 return error; 102 return error;
103 } 103 }
@@ -308,7 +308,7 @@ xfs_attr3_node_inactive(
308 /* 308 /*
309 * Atomically commit the whole invalidate stuff. 309 * Atomically commit the whole invalidate stuff.
310 */ 310 */
311 error = xfs_trans_roll(trans, dp); 311 error = xfs_trans_roll_inode(trans, dp);
312 if (error) 312 if (error)
313 return error; 313 return error;
314 } 314 }
@@ -375,7 +375,7 @@ xfs_attr3_root_inactive(
375 /* 375 /*
376 * Commit the invalidate and start the next transaction. 376 * Commit the invalidate and start the next transaction.
377 */ 377 */
378 error = xfs_trans_roll(trans, dp); 378 error = xfs_trans_roll_inode(trans, dp);
379 379
380 return error; 380 return error;
381} 381}
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 97045e8dfed5..f739a031986d 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1055,7 +1055,7 @@ xfs_dir_ialloc(
1055 tp->t_flags &= ~(XFS_TRANS_DQ_DIRTY); 1055 tp->t_flags &= ~(XFS_TRANS_DQ_DIRTY);
1056 } 1056 }
1057 1057
1058 code = xfs_trans_roll(&tp, NULL); 1058 code = xfs_trans_roll(&tp);
1059 if (committed != NULL) 1059 if (committed != NULL)
1060 *committed = 1; 1060 *committed = 1;
1061 1061
@@ -1611,7 +1611,7 @@ xfs_itruncate_extents(
1611 if (error) 1611 if (error)
1612 goto out_bmap_cancel; 1612 goto out_bmap_cancel;
1613 1613
1614 error = xfs_trans_roll(&tp, ip); 1614 error = xfs_trans_roll_inode(&tp, ip);
1615 if (error) 1615 if (error)
1616 goto out; 1616 goto out;
1617 } 1617 }
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 2011620008de..a87f657f59c9 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -1035,25 +1035,18 @@ xfs_trans_cancel(
1035 */ 1035 */
1036int 1036int
1037xfs_trans_roll( 1037xfs_trans_roll(
1038 struct xfs_trans **tpp, 1038 struct xfs_trans **tpp)
1039 struct xfs_inode *dp)
1040{ 1039{
1041 struct xfs_trans *trans; 1040 struct xfs_trans *trans = *tpp;
1042 struct xfs_trans_res tres; 1041 struct xfs_trans_res tres;
1043 int error; 1042 int error;
1044 1043
1045 /* 1044 /*
1046 * Ensure that the inode is always logged.
1047 */
1048 trans = *tpp;
1049 if (dp)
1050 xfs_trans_log_inode(trans, dp, XFS_ILOG_CORE);
1051
1052 /*
1053 * Copy the critical parameters from one trans to the next. 1045 * Copy the critical parameters from one trans to the next.
1054 */ 1046 */
1055 tres.tr_logres = trans->t_log_res; 1047 tres.tr_logres = trans->t_log_res;
1056 tres.tr_logcount = trans->t_log_count; 1048 tres.tr_logcount = trans->t_log_count;
1049
1057 *tpp = xfs_trans_dup(trans); 1050 *tpp = xfs_trans_dup(trans);
1058 1051
1059 /* 1052 /*
@@ -1067,10 +1060,8 @@ xfs_trans_roll(
1067 if (error) 1060 if (error)
1068 return error; 1061 return error;
1069 1062
1070 trans = *tpp;
1071
1072 /* 1063 /*
1073 * Reserve space in the log for th next transaction. 1064 * Reserve space in the log for the next transaction.
1074 * This also pushes items in the "AIL", the list of logged items, 1065 * This also pushes items in the "AIL", the list of logged items,
1075 * out to disk if they are taking up space at the tail of the log 1066 * out to disk if they are taking up space at the tail of the log
1076 * that we want to use. This requires that either nothing be locked 1067 * that we want to use. This requires that either nothing be locked
@@ -1078,14 +1069,5 @@ xfs_trans_roll(
1078 * the prior and the next transactions. 1069 * the prior and the next transactions.
1079 */ 1070 */
1080 tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; 1071 tres.tr_logflags = XFS_TRANS_PERM_LOG_RES;
1081 error = xfs_trans_reserve(trans, &tres, 0, 0); 1072 return xfs_trans_reserve(*tpp, &tres, 0, 0);
1082 /*
1083 * Ensure that the inode is in the new transaction and locked.
1084 */
1085 if (error)
1086 return error;
1087
1088 if (dp)
1089 xfs_trans_ijoin(trans, dp, 0);
1090 return 0;
1091} 1073}
diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h
index 7d627721e4b3..b25d3d22e289 100644
--- a/fs/xfs/xfs_trans.h
+++ b/fs/xfs/xfs_trans.h
@@ -228,7 +228,8 @@ int xfs_trans_free_extent(struct xfs_trans *,
228 struct xfs_efd_log_item *, xfs_fsblock_t, 228 struct xfs_efd_log_item *, xfs_fsblock_t,
229 xfs_extlen_t, struct xfs_owner_info *); 229 xfs_extlen_t, struct xfs_owner_info *);
230int xfs_trans_commit(struct xfs_trans *); 230int xfs_trans_commit(struct xfs_trans *);
231int xfs_trans_roll(struct xfs_trans **, struct xfs_inode *); 231int xfs_trans_roll(struct xfs_trans **);
232int xfs_trans_roll_inode(struct xfs_trans **, struct xfs_inode *);
232void xfs_trans_cancel(xfs_trans_t *); 233void xfs_trans_cancel(xfs_trans_t *);
233int xfs_trans_ail_init(struct xfs_mount *); 234int xfs_trans_ail_init(struct xfs_mount *);
234void xfs_trans_ail_destroy(struct xfs_mount *); 235void xfs_trans_ail_destroy(struct xfs_mount *);
diff --git a/fs/xfs/xfs_trans_inode.c b/fs/xfs/xfs_trans_inode.c
index dab8daa676f9..daa7615497f9 100644
--- a/fs/xfs/xfs_trans_inode.c
+++ b/fs/xfs/xfs_trans_inode.c
@@ -134,3 +134,17 @@ xfs_trans_log_inode(
134 flags |= ip->i_itemp->ili_last_fields; 134 flags |= ip->i_itemp->ili_last_fields;
135 ip->i_itemp->ili_fields |= flags; 135 ip->i_itemp->ili_fields |= flags;
136} 136}
137
138int
139xfs_trans_roll_inode(
140 struct xfs_trans **tpp,
141 struct xfs_inode *ip)
142{
143 int error;
144
145 xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE);
146 error = xfs_trans_roll(tpp);
147 if (!error)
148 xfs_trans_ijoin(*tpp, ip, 0);
149 return error;
150}