From: Brian Foster Date: Fri, 5 Oct 2018 02:36:11 +0000 (-0500) Subject: xfs: refactor internal dfops initialization X-Git-Tag: v4.19.0-rc0~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3645e8edb3b194fb7c7ea9e329018ffe98f9609a;p=thirdparty%2Fxfsprogs-dev.git xfs: refactor internal dfops initialization Source kernel commit: 98719051e75ccf9eca18bd2b569de4ea637b4479 The current transaction allocation code conditionally initializes the ->t_dfops indirection pointer. Transaction commit/cancel check the validity of the pointer to determine whether to finish/cancel the internal dfops. This disallows the ability to use the internal dfops list as a temporary container (via xfs_trans_alloc_empty()). Refactor transaction allocation to always initialize ->t_dfops and check permanent reservation state on transaction commit/cancel. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Eric Sandeen --- diff --git a/libxfs/trans.c b/libxfs/trans.c index bda2d8c68..3221a3f52 100644 --- a/libxfs/trans.c +++ b/libxfs/trans.c @@ -274,13 +274,7 @@ libxfs_trans_alloc( INIT_LIST_HEAD(&tp->t_items); tp->t_firstblock = NULLFSBLOCK; - /* - * We only roll transactions with permanent log reservation. Don't init - * ->t_dfops to skip attempts to finish or cancel an empty dfops with a - * non-permanent res. - */ - if (resp->tr_logflags & XFS_TRANS_PERM_LOG_RES) - xfs_defer_init(tp, &tp->t_dfops_internal); + xfs_defer_init(tp, &tp->t_dfops_internal); error = xfs_trans_reserve(tp, resp, blocks, rtextents); if (error) { @@ -341,7 +335,7 @@ libxfs_trans_cancel( if (tp == NULL) goto out; - if (tp->t_dfops) + if (tp->t_flags & XFS_TRANS_PERM_LOG_RES) xfs_defer_cancel(tp); xfs_trans_free_items(tp); @@ -1002,8 +996,13 @@ __xfs_trans_commit( if (tp == NULL) return 0; - /* finish deferred items on final commit */ - if (!regrant && tp->t_dfops) { + /* + * Finish deferred items on final commit. Only permanent transactions + * should ever have deferred ops. + */ + WARN_ON_ONCE(xfs_defer_has_unfinished_work(tp->t_dfops) && + !(tp->t_flags & XFS_TRANS_PERM_LOG_RES)); + if (!regrant && (tp->t_flags & XFS_TRANS_PERM_LOG_RES)) { error = xfs_defer_finish_noroll(&tp); if (error) { xfs_defer_cancel(tp);