xfs: add a XFS_TRANS_WRITECOUNT_TRYLOCK flag
PATCH v3 1/2 xfs: add a XFS_TRANS_WRITECOUNT_TRYLOCK flag
From: Aditya Prakash Srivastava <[email protected]>
Introduce a new transaction allocation flag, XFS_TRANS_WRITECOUNT_TRYLOCK. When this flag is specified, __xfs_trans_alloc() attempts to obtain freeze protection using sb_start_intwrite_trylock() instead of blocking indefinitely on sb_start_intwrite().
If the trylock fails, the allocation is aborted gracefully: the freshly allocated transaction handle is freed, and the function returns the appropriate error pointer ERR_PTR(-EAGAIN), which is then propagated to the caller by xfs_trans_alloc().
Also add an assertion in __xfs_trans_alloc() to ensure that both XFS_TRANS_NO_WRITECOUNT and XFS_TRANS_WRITECOUNT_TRYLOCK are never specified at the same time, as they are mutually exclusive.
--- fs/xfs/libxfs/xfs_shared.h | 3 +++ fs/xfs/xfs_trans.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_shared.h +3 -0
@@ -164,6 +164,9 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,/* Transaction has locked the rtbitmap and rtsum inodes */ #define XFS_TRANS_RTBITMAP_LOCKED (1u << 9) +/* Try lock filesystem superblock for freeze protection */ +#define XFS_TRANS_WRITECOUNT_TRYLOCK (1u << 10) +/* * Field values for xfs_trans_mod_sb. */
fs/xfs/xfs_trans.c +11 -1
@@ -216,10 +216,18 @@ __xfs_trans_alloc(struct xfs_trans *tp;ASSERT (!(flags &XFS_TRANS_RES_FDBLKS ) ||xfs_has_lazysbcount (mp)); +ASSERT (!((flags &XFS_TRANS_NO_WRITECOUNT ) && + (flags &XFS_TRANS_WRITECOUNT_TRYLOCK ))); tp =kmem_cache_zalloc (xfs_trans_cache,GFP_KERNEL | __GFP_NOFAIL); -if (!(flags &XFS_TRANS_NO_WRITECOUNT )) +if (flags &XFS_TRANS_WRITECOUNT_TRYLOCK ) { +if (!sb_start_intwrite_trylock (mp->m_super)) { +kmem_cache_free (xfs_trans_cache, tp); +return ERR_PTR (-EAGAIN ); + } + }else if (!(flags &XFS_TRANS_NO_WRITECOUNT )) {sb_start_intwrite (mp->m_super); + }xfs_trans_set_context (tp); tp->t_flags = flags; tp->t_mountp = mp;
@@ -252,6 +260,8 @@ xfs_trans_alloc(*/ retry: tp =__xfs_trans_alloc (mp, flags); +if (IS_ERR (tp)) +return PTR_ERR (tp);WARN_ON (mp->m_super->s_writers.frozen ==SB_FREEZE_COMPLETE ); error =xfs_trans_reserve (tp, resp, blocks, rtextents);if (error == -ENOSPC && want_retry) {
Signature · 1 line
2.47.3