[PATCH 26/29] xfs: return -EAGAIN when nowait meets sync in transaction commit

Hao Xu
2023-08-25T14:11:49Z

if the log transaction is a sync one, let's fail the nowait try and
return -EAGAIN directly since sync transaction means blocked by IO.

Signed-off-by: Hao Xu <howeyxu@tencent.com>
---
fs/xfs/xfs_trans.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index 7988b4c7f36e..f1f84a3dd456 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -968,12 +968,24 @@ __xfs_trans_commit(
xfs_csn_t commit_seq = 0;
int error = 0;
int sync = tp->t_flags & XFS_TRANS_SYNC;
+ bool nowait = tp->t_flags & XFS_TRANS_NOWAIT;
+ bool perm_log = tp->t_flags & XFS_TRANS_PERM_LOG_RES;

trace_xfs_trans_commit(tp, _RET_IP_);

+ if (nowait && sync) {
+ /*
+ * Currently nowait is only from xfs_vn_update_time()
+ * so perm_log is always false here, but let's make
+ * code general.
+ */
+ if (perm_log)
+ xfs_defer_cancel(tp);
+ goto out_unreserve;
+ }
error = xfs_trans_run_precommits(tp);
if (error) {
- if (tp->t_flags & XFS_TRANS_PERM_LOG_RES)
+ if (perm_log)
xfs_defer_cancel(tp);
goto out_unreserve;
}
--
2.25.1