aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/libxfs/xfs_defer.c
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2018-12-12 11:46:22 -0500
committerDarrick J. Wong <darrick.wong@oracle.com>2018-12-12 11:47:16 -0500
commit02b100fb83f9b0f8719deef6c4ed973b4d9ce00c (patch)
tree7851231aa2e3edf3865cb806d654bc07e3ab94aa /fs/xfs/libxfs/xfs_defer.c
parentbc9f2b7c8a732d896753709cc9d495780ba7e9f9 (diff)
xfs: streamline defer op type handling
There's no need to bundle a pointer to the defer op type into the defer op control structure. Instead, store the defer op type enum, which enables us to shorten some of the lines. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Eric Sandeen <sandeen@redhat.com> Reviewed-by: Brian Foster <bfoster@redhat.com>
Diffstat (limited to 'fs/xfs/libxfs/xfs_defer.c')
-rw-r--r--fs/xfs/libxfs/xfs_defer.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/fs/xfs/libxfs/xfs_defer.c b/fs/xfs/libxfs/xfs_defer.c
index 277117a8ad13..94f00427de98 100644
--- a/fs/xfs/libxfs/xfs_defer.c
+++ b/fs/xfs/libxfs/xfs_defer.c
@@ -191,15 +191,15 @@ xfs_defer_create_intents(
191{ 191{
192 struct list_head *li; 192 struct list_head *li;
193 struct xfs_defer_pending *dfp; 193 struct xfs_defer_pending *dfp;
194 const struct xfs_defer_op_type *ops;
194 195
195 list_for_each_entry(dfp, &tp->t_dfops, dfp_list) { 196 list_for_each_entry(dfp, &tp->t_dfops, dfp_list) {
196 dfp->dfp_intent = dfp->dfp_type->create_intent(tp, 197 ops = defer_op_types[dfp->dfp_type];
197 dfp->dfp_count); 198 dfp->dfp_intent = ops->create_intent(tp, dfp->dfp_count);
198 trace_xfs_defer_create_intent(tp->t_mountp, dfp); 199 trace_xfs_defer_create_intent(tp->t_mountp, dfp);
199 list_sort(tp->t_mountp, &dfp->dfp_work, 200 list_sort(tp->t_mountp, &dfp->dfp_work, ops->diff_items);
200 dfp->dfp_type->diff_items);
201 list_for_each(li, &dfp->dfp_work) 201 list_for_each(li, &dfp->dfp_work)
202 dfp->dfp_type->log_item(tp, dfp->dfp_intent, li); 202 ops->log_item(tp, dfp->dfp_intent, li);
203 } 203 }
204} 204}
205 205
@@ -210,14 +210,16 @@ xfs_defer_trans_abort(
210 struct list_head *dop_pending) 210 struct list_head *dop_pending)
211{ 211{
212 struct xfs_defer_pending *dfp; 212 struct xfs_defer_pending *dfp;
213 const struct xfs_defer_op_type *ops;
213 214
214 trace_xfs_defer_trans_abort(tp, _RET_IP_); 215 trace_xfs_defer_trans_abort(tp, _RET_IP_);
215 216
216 /* Abort intent items that don't have a done item. */ 217 /* Abort intent items that don't have a done item. */
217 list_for_each_entry(dfp, dop_pending, dfp_list) { 218 list_for_each_entry(dfp, dop_pending, dfp_list) {
219 ops = defer_op_types[dfp->dfp_type];
218 trace_xfs_defer_pending_abort(tp->t_mountp, dfp); 220 trace_xfs_defer_pending_abort(tp->t_mountp, dfp);
219 if (dfp->dfp_intent && !dfp->dfp_done) { 221 if (dfp->dfp_intent && !dfp->dfp_done) {
220 dfp->dfp_type->abort_intent(dfp->dfp_intent); 222 ops->abort_intent(dfp->dfp_intent);
221 dfp->dfp_intent = NULL; 223 dfp->dfp_intent = NULL;
222 } 224 }
223 } 225 }
@@ -321,18 +323,20 @@ xfs_defer_cancel_list(
321 struct xfs_defer_pending *pli; 323 struct xfs_defer_pending *pli;
322 struct list_head *pwi; 324 struct list_head *pwi;
323 struct list_head *n; 325 struct list_head *n;
326 const struct xfs_defer_op_type *ops;
324 327
325 /* 328 /*
326 * Free the pending items. Caller should already have arranged 329 * Free the pending items. Caller should already have arranged
327 * for the intent items to be released. 330 * for the intent items to be released.
328 */ 331 */
329 list_for_each_entry_safe(dfp, pli, dop_list, dfp_list) { 332 list_for_each_entry_safe(dfp, pli, dop_list, dfp_list) {
333 ops = defer_op_types[dfp->dfp_type];
330 trace_xfs_defer_cancel_list(mp, dfp); 334 trace_xfs_defer_cancel_list(mp, dfp);
331 list_del(&dfp->dfp_list); 335 list_del(&dfp->dfp_list);
332 list_for_each_safe(pwi, n, &dfp->dfp_work) { 336 list_for_each_safe(pwi, n, &dfp->dfp_work) {
333 list_del(pwi); 337 list_del(pwi);
334 dfp->dfp_count--; 338 dfp->dfp_count--;
335 dfp->dfp_type->cancel_item(pwi); 339 ops->cancel_item(pwi);
336 } 340 }
337 ASSERT(dfp->dfp_count == 0); 341 ASSERT(dfp->dfp_count == 0);
338 kmem_free(dfp); 342 kmem_free(dfp);
@@ -356,7 +360,7 @@ xfs_defer_finish_noroll(
356 struct list_head *n; 360 struct list_head *n;
357 void *state; 361 void *state;
358 int error = 0; 362 int error = 0;
359 void (*cleanup_fn)(struct xfs_trans *, void *, int); 363 const struct xfs_defer_op_type *ops;
360 LIST_HEAD(dop_pending); 364 LIST_HEAD(dop_pending);
361 365
362 ASSERT((*tp)->t_flags & XFS_TRANS_PERM_LOG_RES); 366 ASSERT((*tp)->t_flags & XFS_TRANS_PERM_LOG_RES);
@@ -379,18 +383,18 @@ xfs_defer_finish_noroll(
379 /* Log an intent-done item for the first pending item. */ 383 /* Log an intent-done item for the first pending item. */
380 dfp = list_first_entry(&dop_pending, struct xfs_defer_pending, 384 dfp = list_first_entry(&dop_pending, struct xfs_defer_pending,
381 dfp_list); 385 dfp_list);
386 ops = defer_op_types[dfp->dfp_type];
382 trace_xfs_defer_pending_finish((*tp)->t_mountp, dfp); 387 trace_xfs_defer_pending_finish((*tp)->t_mountp, dfp);
383 dfp->dfp_done = dfp->dfp_type->create_done(*tp, dfp->dfp_intent, 388 dfp->dfp_done = ops->create_done(*tp, dfp->dfp_intent,
384 dfp->dfp_count); 389 dfp->dfp_count);
385 cleanup_fn = dfp->dfp_type->finish_cleanup;
386 390
387 /* Finish the work items. */ 391 /* Finish the work items. */
388 state = NULL; 392 state = NULL;
389 list_for_each_safe(li, n, &dfp->dfp_work) { 393 list_for_each_safe(li, n, &dfp->dfp_work) {
390 list_del(li); 394 list_del(li);
391 dfp->dfp_count--; 395 dfp->dfp_count--;
392 error = dfp->dfp_type->finish_item(*tp, li, 396 error = ops->finish_item(*tp, li, dfp->dfp_done,
393 dfp->dfp_done, &state); 397 &state);
394 if (error == -EAGAIN) { 398 if (error == -EAGAIN) {
395 /* 399 /*
396 * Caller wants a fresh transaction; 400 * Caller wants a fresh transaction;
@@ -406,8 +410,8 @@ xfs_defer_finish_noroll(
406 * xfs_defer_cancel will take care of freeing 410 * xfs_defer_cancel will take care of freeing
407 * all these lists and stuff. 411 * all these lists and stuff.
408 */ 412 */
409 if (cleanup_fn) 413 if (ops->finish_cleanup)
410 cleanup_fn(*tp, state, error); 414 ops->finish_cleanup(*tp, state, error);
411 goto out; 415 goto out;
412 } 416 }
413 } 417 }
@@ -419,20 +423,19 @@ xfs_defer_finish_noroll(
419 * a Fresh Transaction while Finishing 423 * a Fresh Transaction while Finishing
420 * Deferred Work" above. 424 * Deferred Work" above.
421 */ 425 */
422 dfp->dfp_intent = dfp->dfp_type->create_intent(*tp, 426 dfp->dfp_intent = ops->create_intent(*tp,
423 dfp->dfp_count); 427 dfp->dfp_count);
424 dfp->dfp_done = NULL; 428 dfp->dfp_done = NULL;
425 list_for_each(li, &dfp->dfp_work) 429 list_for_each(li, &dfp->dfp_work)
426 dfp->dfp_type->log_item(*tp, dfp->dfp_intent, 430 ops->log_item(*tp, dfp->dfp_intent, li);
427 li);
428 } else { 431 } else {
429 /* Done with the dfp, free it. */ 432 /* Done with the dfp, free it. */
430 list_del(&dfp->dfp_list); 433 list_del(&dfp->dfp_list);
431 kmem_free(dfp); 434 kmem_free(dfp);
432 } 435 }
433 436
434 if (cleanup_fn) 437 if (ops->finish_cleanup)
435 cleanup_fn(*tp, state, error); 438 ops->finish_cleanup(*tp, state, error);
436 } 439 }
437 440
438out: 441out:
@@ -492,6 +495,7 @@ xfs_defer_add(
492 struct list_head *li) 495 struct list_head *li)
493{ 496{
494 struct xfs_defer_pending *dfp = NULL; 497 struct xfs_defer_pending *dfp = NULL;
498 const struct xfs_defer_op_type *ops;
495 499
496 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); 500 ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
497 BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX); 501 BUILD_BUG_ON(ARRAY_SIZE(defer_op_types) != XFS_DEFER_OPS_TYPE_MAX);
@@ -504,15 +508,15 @@ xfs_defer_add(
504 if (!list_empty(&tp->t_dfops)) { 508 if (!list_empty(&tp->t_dfops)) {
505 dfp = list_last_entry(&tp->t_dfops, 509 dfp = list_last_entry(&tp->t_dfops,
506 struct xfs_defer_pending, dfp_list); 510 struct xfs_defer_pending, dfp_list);
507 if (dfp->dfp_type->type != type || 511 ops = defer_op_types[dfp->dfp_type];
508 (dfp->dfp_type->max_items && 512 if (dfp->dfp_type != type ||
509 dfp->dfp_count >= dfp->dfp_type->max_items)) 513 (ops->max_items && dfp->dfp_count >= ops->max_items))
510 dfp = NULL; 514 dfp = NULL;
511 } 515 }
512 if (!dfp) { 516 if (!dfp) {
513 dfp = kmem_alloc(sizeof(struct xfs_defer_pending), 517 dfp = kmem_alloc(sizeof(struct xfs_defer_pending),
514 KM_SLEEP | KM_NOFS); 518 KM_SLEEP | KM_NOFS);
515 dfp->dfp_type = defer_op_types[type]; 519 dfp->dfp_type = type;
516 dfp->dfp_intent = NULL; 520 dfp->dfp_intent = NULL;
517 dfp->dfp_done = NULL; 521 dfp->dfp_done = NULL;
518 dfp->dfp_count = 0; 522 dfp->dfp_count = 0;