Backport of XFS umount hang fixes
v2 cover Backport of XFS umount hang fixes
Backport of this series:
https://lore.kernel.org/all/[email protected]/
I have added information in commit message upon conflict resolutions.
v2: Address Sasha's comments to v1 in the below mail:
https://lore.kernel.org/stable/2026-10-01-1-daily-reply-0012-re-xfs-umount-hang-backports@kernel.org/
Thanks,
Siddh
Darrick J. Wong (7):
xfs: hoist recovered bmap intent checks out of xfs_bui_item_recover
xfs: improve the code that checks recovered bmap intent items
xfs: hoist recovered rmap intent checks out of xfs_rui_item_recover
xfs: improve the code that checks recovered rmap intent items
xfs: hoist recovered refcount intent checks out of
xfs_cui_item_recover
xfs: improve the code that checks recovered refcount intent items
xfs: fix intermittent hang during quotacheck
Dave Chinner (11):
xfs: don't nest icloglock inside ic_callback_lock
xfs: convert XLOG_FORCED_SHUTDOWN() to xlog_is_shutdown()
xfs: log items should have a xlog pointer, not a mount
xfs: aborting inodes on shutdown may need buffer lock
xfs: remove xfs_buf_t typedef
xfs: buffer pins need to hold a buffer reference
xfs: xfs_ifree_cluster vs xfs_iflush_shutdown_abort deadlock
xfs: catch stale AGF/AGF metadata
xfs: rearrange code in xfs_buf_item.c
xfs: factor out stale buffer item completion
xfs: fix unmount hang with unflushable inodes stuck in the AIL
Guo Xuenan (1):
xfs: fix super block buf log item UAF during force shutdown
fs/xfs/libxfs/xfs_alloc.c | 61 ++++-- fs/xfs/libxfs/xfs_bmap.c | 6 +- fs/xfs/libxfs/xfs_btree.c | 10 +- fs/xfs/libxfs/xfs_ialloc.c | 38 +++- fs/xfs/libxfs/xfs_rtbitmap.c | 22 +- fs/xfs/xfs_bmap_item.c | 76 ++++--- fs/xfs/xfs_buf.c | 24 +-- fs/xfs/xfs_buf.h | 14 +- fs/xfs/xfs_buf_item.c | 384 ++++++++++++++++++++++------------- fs/xfs/xfs_buf_item.h | 3 +- fs/xfs/xfs_dquot_item.c | 5 +- fs/xfs/xfs_extfree_item.c | 2 +- fs/xfs/xfs_fsops.c | 2 +- fs/xfs/xfs_icache.c | 10 +- fs/xfs/xfs_inode.c | 9 +- fs/xfs/xfs_inode_item.c | 164 ++++++++++++--- fs/xfs/xfs_inode_item.h | 1 + fs/xfs/xfs_log.c | 50 ++--- fs/xfs/xfs_log_cil.c | 12 +- fs/xfs/xfs_log_priv.h | 7 +- fs/xfs/xfs_log_recover.c | 17 +- fs/xfs/xfs_qm.c | 7 + fs/xfs/xfs_refcount_item.c | 60 ++++-- fs/xfs/xfs_rmap_item.c | 75 ++++--- fs/xfs/xfs_rtalloc.c | 20 +- fs/xfs/xfs_rtalloc.h | 4 +- fs/xfs/xfs_symlink.c | 4 +- fs/xfs/xfs_trace.h | 4 +- fs/xfs/xfs_trans.c | 6 +- fs/xfs/xfs_trans.h | 3 +- fs/xfs/xfs_trans_buf.c | 16 +- 31 files changed, 723 insertions(+), 393 deletions(-)
Signature · 1 line
2.53.0
PATCH RESEND v2 1/19 xfs: hoist recovered bmap intent checks out of xfs_bui_item_recover
From: "Darrick J. Wong" <[email protected]>
When we recover a bmap intent from the log, we need to validate its contents before we try to replay them. Hoist the checking code into a separate function in preparation to refactor this code to use validation helpers.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_bmap_item.c | 74 +++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 27 deletions(-)
fs/xfs/xfs_bmap_item.c +47 -27
@@ -418,6 +418,49 @@ const struct xfs_defer_op_type xfs_bmap_update_defer_type = { .cancel_item = xfs_bmap_update_cancel_item, }; +/* Is this recovered BUI ok? */ +static inline bool +xfs_bui_validate ( +struct xfs_mount *mp, +struct xfs_bui_log_item *buip) +{ +struct xfs_map_extent *bmap; +xfs_fsblock_t startblock_fsb; +xfs_fsblock_t inode_fsb; + +/* Only one mapping operation per BUI... */ +if (buip->bui_format.bui_nextents !=XFS_BUI_MAX_FAST_EXTENTS ) +return false; + + bmap = &buip->bui_format.bui_extents[0 ]; + startblock_fsb =XFS_BB_TO_FSB (mp, +XFS_FSB_TO_DADDR (mp, bmap->me_startblock)); + inode_fsb =XFS_BB_TO_FSB (mp,XFS_FSB_TO_DADDR (mp, +XFS_INO_TO_FSB (mp, bmap->me_owner))); + +if (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS ) +return false; + +switch (bmap->me_flags &XFS_BMAP_EXTENT_TYPE_MASK ) { +case XFS_BMAP_MAP : +case XFS_BMAP_UNMAP : +break ; +default : +return false; + } + +if (startblock_fsb ==0 || + bmap->me_len ==0 || + inode_fsb ==0 || + startblock_fsb >= mp->m_sb.sb_dblocks || + bmap->me_len >= mp->m_sb.sb_agblocks || + inode_fsb >= mp->m_sb.sb_dblocks || + (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS )) +return false; + +return true; +} +/* * Process a bmap update intent item that was recovered from the log. * We need to update some inode's bmbt.
@@ -434,47 +477,24 @@ xfs_bui_item_recover(struct xfs_mount *mp = lip->li_mountp;struct xfs_map_extent *bmap;struct xfs_bud_log_item *budp; -xfs_fsblock_t startblock_fsb; -xfs_fsblock_t inode_fsb;xfs_filblks_t count;xfs_exntst_t state;unsigned int bui_type;int whichfork;int error =0 ; -/* Only one mapping operation per BUI... */ -if (buip->bui_format.bui_nextents !=XFS_BUI_MAX_FAST_EXTENTS ) +if (!xfs_bui_validate (mp, buip)) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + &buip->bui_format,sizeof (buip->bui_format));return -EFSCORRUPTED ; + } -/* -* First check the validity of the extent described by the -* BUI. If anything is bad, then toss the BUI. -*/ bmap = &buip->bui_format.bui_extents[0 ]; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, bmap->me_startblock)); - inode_fsb =XFS_BB_TO_FSB (mp,XFS_FSB_TO_DADDR (mp, -XFS_INO_TO_FSB (mp, bmap->me_owner))); state = (bmap->me_flags &XFS_BMAP_EXTENT_UNWRITTEN ) ?XFS_EXT_UNWRITTEN :XFS_EXT_NORM ; whichfork = (bmap->me_flags &XFS_BMAP_EXTENT_ATTR_FORK ) ?XFS_ATTR_FORK :XFS_DATA_FORK ; bui_type = bmap->me_flags &XFS_BMAP_EXTENT_TYPE_MASK ; -switch (bui_type) { -case XFS_BMAP_MAP : -case XFS_BMAP_UNMAP : -break ; -default : -return -EFSCORRUPTED ; - } -if (startblock_fsb ==0 || - bmap->me_len ==0 || - inode_fsb ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - bmap->me_len >= mp->m_sb.sb_agblocks || - inode_fsb >= mp->m_sb.sb_dblocks || - (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS )) -return -EFSCORRUPTED ;/* Grab the inode. */ error =xfs_iget (mp,NULL , bmap->me_owner,0 ,0 , &ip);
Signature · 1 line
2.53.0
PATCH RESEND v2 2/19 xfs: improve the code that checks recovered bmap intent items
In reply to Siddh Raman PantFrom: "Darrick J. Wong" <[email protected]>
The code that validates recovered bmap intent items is kind of a mess -- it doesn't use the standard xfs type validators, and it doesn't check for things that it should. Fix the validator function to use the standard validation helpers and look for more types of obvious errors.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_bmap_item.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
fs/xfs/xfs_bmap_item.c +13 -13
@@ -425,18 +425,12 @@ xfs_bui_validate( struct xfs_bui_log_item *buip) {struct xfs_map_extent *bmap; -xfs_fsblock_t startblock_fsb; -xfs_fsblock_t inode_fsb;/* Only one mapping operation per BUI... */ if (buip->bui_format.bui_nextents !=XFS_BUI_MAX_FAST_EXTENTS )return false; bmap = &buip->bui_format.bui_extents[0 ]; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, bmap->me_startblock)); - inode_fsb =XFS_BB_TO_FSB (mp,XFS_FSB_TO_DADDR (mp, -XFS_INO_TO_FSB (mp, bmap->me_owner)));if (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS )return false;
@@ -449,13 +443,19 @@ xfs_bui_validate(return false; } -if (startblock_fsb ==0 || - bmap->me_len ==0 || - inode_fsb ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - bmap->me_len >= mp->m_sb.sb_agblocks || - inode_fsb >= mp->m_sb.sb_dblocks || - (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS )) +if (!xfs_verify_ino (mp, bmap->me_owner)) +return false; + +if (bmap->me_startoff + bmap->me_len <= bmap->me_startoff) +return false; + +if (bmap->me_startblock + bmap->me_len <= bmap->me_startblock) +return false; + +if (!xfs_verify_fsbno (mp, bmap->me_startblock)) +return false; + +if (!xfs_verify_fsbno (mp, bmap->me_startblock + bmap->me_len -1 ))return false;return true;
Signature · 1 line
2.53.0
PATCH RESEND v2 3/19 xfs: hoist recovered rmap intent checks out of xfs_rui_item_recover
In reply to Siddh Raman PantFrom: "Darrick J. Wong" <[email protected]>
When we recover a rmap intent from the log, we need to validate its contents before we try to replay them. Hoist the checking code into a separate function in preparation to refactor this code to use validation helpers.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_rmap_item.c | 67 ++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 25 deletions(-)
fs/xfs/xfs_rmap_item.c +42 -25
@@ -460,6 +460,42 @@ const struct xfs_defer_op_type xfs_rmap_update_defer_type = { .cancel_item = xfs_rmap_update_cancel_item, }; +/* Is this recovered RUI ok? */ +static inline bool +xfs_rui_validate_map ( +struct xfs_mount *mp, +struct xfs_map_extent *rmap) +{ +xfs_fsblock_t startblock_fsb; +bool op_ok; + + startblock_fsb =XFS_BB_TO_FSB (mp, +XFS_FSB_TO_DADDR (mp, rmap->me_startblock)); +switch (rmap->me_flags &XFS_RMAP_EXTENT_TYPE_MASK ) { +case XFS_RMAP_EXTENT_MAP : +case XFS_RMAP_EXTENT_MAP_SHARED : +case XFS_RMAP_EXTENT_UNMAP : +case XFS_RMAP_EXTENT_UNMAP_SHARED : +case XFS_RMAP_EXTENT_CONVERT : +case XFS_RMAP_EXTENT_CONVERT_SHARED : +case XFS_RMAP_EXTENT_ALLOC : +case XFS_RMAP_EXTENT_FREE : + op_ok = true; +break ; +default : + op_ok = false; +break ; + } +if (!op_ok || startblock_fsb ==0 || + rmap->me_len ==0 || + startblock_fsb >= mp->m_sb.sb_dblocks || + rmap->me_len >= mp->m_sb.sb_agblocks || + (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS )) +return false; + +return true; +} +/* * Process an rmap update intent item that was recovered from the log. * We need to update the rmapbt.
@@ -475,10 +511,8 @@ xfs_rui_item_recover(struct xfs_trans *tp;struct xfs_btree_cur *rcur =NULL ;struct xfs_mount *mp = lip->li_mountp; -xfs_fsblock_t startblock_fsb;enum xfs_rmap_intent_type type;xfs_exntst_t state; -bool op_ok;int i;int whichfork;int error =0 ;
@@ -489,30 +523,13 @@ xfs_rui_item_recover(* just toss the RUI. */ for (i =0 ; i < ruip->rui_format.rui_nextents; i++) { - rmap = &ruip->rui_format.rui_extents[i]; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, rmap->me_startblock)); -switch (rmap->me_flags &XFS_RMAP_EXTENT_TYPE_MASK ) { -case XFS_RMAP_EXTENT_MAP : -case XFS_RMAP_EXTENT_MAP_SHARED : -case XFS_RMAP_EXTENT_UNMAP : -case XFS_RMAP_EXTENT_UNMAP_SHARED : -case XFS_RMAP_EXTENT_CONVERT : -case XFS_RMAP_EXTENT_CONVERT_SHARED : -case XFS_RMAP_EXTENT_ALLOC : -case XFS_RMAP_EXTENT_FREE : - op_ok = true; -break ; -default : - op_ok = false; -break ; - } -if (!op_ok || startblock_fsb ==0 || - rmap->me_len ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - rmap->me_len >= mp->m_sb.sb_agblocks || - (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS )) +if (!xfs_rui_validate_map (mp, + &ruip->rui_format.rui_extents[i])) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + &ruip->rui_format, +sizeof (ruip->rui_format));return -EFSCORRUPTED ; + } } error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
Signature · 1 line
2.53.0
PATCH RESEND v2 4/19 xfs: improve the code that checks recovered rmap intent items
In reply to Siddh Raman PantFrom: "Darrick J. Wong" <[email protected]>
The code that validates recovered rmap intent items is kind of a mess -- it doesn't use the standard xfs type validators, and it doesn't check for things that it should. Fix the validator function to use the standard validation helpers and look for more types of obvious errors.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_rmap_item.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
fs/xfs/xfs_rmap_item.c +18 -12
@@ -466,11 +466,9 @@ xfs_rui_validate_map( struct xfs_mount *mp, struct xfs_map_extent *rmap) { - xfs_fsblock_t startblock_fsb; -bool op_ok; +if (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS ) +return false; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, rmap->me_startblock));switch (rmap->me_flags &XFS_RMAP_EXTENT_TYPE_MASK ) {case XFS_RMAP_EXTENT_MAP :case XFS_RMAP_EXTENT_MAP_SHARED :
@@ -480,17 +478,25 @@ xfs_rui_validate_map(case XFS_RMAP_EXTENT_CONVERT_SHARED :case XFS_RMAP_EXTENT_ALLOC :case XFS_RMAP_EXTENT_FREE : - op_ok = true;break ;default : - op_ok = false; -break ; +return false; } -if (!op_ok || startblock_fsb ==0 || - rmap->me_len ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - rmap->me_len >= mp->m_sb.sb_agblocks || - (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS )) + +if (!XFS_RMAP_NON_INODE_OWNER (rmap->me_owner) && + !xfs_verify_ino (mp, rmap->me_owner)) +return false; + +if (rmap->me_startoff + rmap->me_len <= rmap->me_startoff) +return false; + +if (rmap->me_startblock + rmap->me_len <= rmap->me_startblock) +return false; + +if (!xfs_verify_fsbno (mp, rmap->me_startblock)) +return false; + +if (!xfs_verify_fsbno (mp, rmap->me_startblock + rmap->me_len -1 ))return false;return true;
Signature · 1 line
2.53.0
PATCH RESEND v2 5/19 xfs: hoist recovered refcount intent checks out of xfs_cui_item_recover
In reply to Siddh Raman PantFrom: "Darrick J. Wong" <[email protected]>
When we recover a refcount intent from the log, we need to validate its contents before we try to replay them. Hoist the checking code into a separate function in preparation to refactor this code to use validation helpers.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_refcount_item.c | 59 ++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 21 deletions(-)
fs/xfs/xfs_refcount_item.c +38 -21
@@ -417,6 +417,38 @@ const struct xfs_defer_op_type xfs_refcount_update_defer_type = { .cancel_item = xfs_refcount_update_cancel_item, }; +/* Is this recovered CUI ok? */ +static inline bool +xfs_cui_validate_phys ( +struct xfs_mount *mp, +struct xfs_phys_extent *refc) +{ +xfs_fsblock_t startblock_fsb; +bool op_ok; + + startblock_fsb =XFS_BB_TO_FSB (mp, +XFS_FSB_TO_DADDR (mp, refc->pe_startblock)); +switch (refc->pe_flags &XFS_REFCOUNT_EXTENT_TYPE_MASK ) { +case XFS_REFCOUNT_INCREASE : +case XFS_REFCOUNT_DECREASE : +case XFS_REFCOUNT_ALLOC_COW : +case XFS_REFCOUNT_FREE_COW : + op_ok = true; +break ; +default : + op_ok = false; +break ; + } +if (!op_ok || startblock_fsb ==0 || + refc->pe_len ==0 || + startblock_fsb >= mp->m_sb.sb_dblocks || + refc->pe_len >= mp->m_sb.sb_agblocks || + (refc->pe_flags & ~XFS_REFCOUNT_EXTENT_FLAGS )) +return false; + +return true; +} +/* * Process a refcount update intent item that was recovered from the log. * We need to update the refcountbt.
@@ -433,11 +465,9 @@ xfs_cui_item_recover(struct xfs_trans *tp;struct xfs_btree_cur *rcur =NULL ;struct xfs_mount *mp = lip->li_mountp; -xfs_fsblock_t startblock_fsb;xfs_fsblock_t new_fsb;xfs_extlen_t new_len;unsigned int refc_type; -bool op_ok;bool requeue_only = false;enum xfs_refcount_intent_type type;int i;
@@ -449,26 +479,13 @@ xfs_cui_item_recover(* just toss the CUI. */ for (i =0 ; i < cuip->cui_format.cui_nextents; i++) { - refc = &cuip->cui_format.cui_extents[i]; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, refc->pe_startblock)); -switch (refc->pe_flags &XFS_REFCOUNT_EXTENT_TYPE_MASK ) { -case XFS_REFCOUNT_INCREASE : -case XFS_REFCOUNT_DECREASE : -case XFS_REFCOUNT_ALLOC_COW : -case XFS_REFCOUNT_FREE_COW : - op_ok = true; -break ; -default : - op_ok = false; -break ; - } -if (!op_ok || startblock_fsb ==0 || - refc->pe_len ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - refc->pe_len >= mp->m_sb.sb_agblocks || - (refc->pe_flags & ~XFS_REFCOUNT_EXTENT_FLAGS )) +if (!xfs_cui_validate_phys (mp, + &cuip->cui_format.cui_extents[i])) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + &cuip->cui_format, +sizeof (cuip->cui_format));return -EFSCORRUPTED ; + } }/*
Signature · 1 line
2.53.0
PATCH RESEND v2 6/19 xfs: improve the code that checks recovered refcount intent items
In reply to Siddh Raman PantFrom: "Darrick J. Wong" <[email protected]>
The code that validates recovered refcount intent items is kind of a mess -- it doesn't use the standard xfs type validators, and it doesn't check for things that it should. Fix the validator function to use the standard validation helpers and look for more types of obvious errors.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
--- fs/xfs/xfs_refcount_item.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
fs/xfs/xfs_refcount_item.c +11 -12
@@ -423,27 +423,26 @@ xfs_cui_validate_phys( struct xfs_mount *mp, struct xfs_phys_extent *refc) { - xfs_fsblock_t startblock_fsb; -bool op_ok; +if (refc->pe_flags & ~XFS_REFCOUNT_EXTENT_FLAGS ) +return false; - startblock_fsb =XFS_BB_TO_FSB (mp, -XFS_FSB_TO_DADDR (mp, refc->pe_startblock));switch (refc->pe_flags &XFS_REFCOUNT_EXTENT_TYPE_MASK ) {case XFS_REFCOUNT_INCREASE :case XFS_REFCOUNT_DECREASE :case XFS_REFCOUNT_ALLOC_COW :case XFS_REFCOUNT_FREE_COW : - op_ok = true;break ;default : - op_ok = false; -break ; +return false; } -if (!op_ok || startblock_fsb ==0 || - refc->pe_len ==0 || - startblock_fsb >= mp->m_sb.sb_dblocks || - refc->pe_len >= mp->m_sb.sb_agblocks || - (refc->pe_flags & ~XFS_REFCOUNT_EXTENT_FLAGS )) + +if (refc->pe_startblock + refc->pe_len <= refc->pe_startblock) +return false; + +if (!xfs_verify_fsbno (mp, refc->pe_startblock)) +return false; + +if (!xfs_verify_fsbno (mp, refc->pe_startblock + refc->pe_len -1 ))return false;return true;
Signature · 1 line
2.53.0
PATCH RESEND v2 7/19 xfs: don't nest icloglock inside ic_callback_lock
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
It's completely unnecessary because callbacks are added to iclogs without holding the icloglock, hence no amount of ordering between the icloglock and ic_callback_lock will order the removal of callbacks from the iclog.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
5.10:
Fixed conflict due to the following missing commit:
956f6daa84bf ("xfs: add iclog state trace events")
--- fs/xfs/xfs_log.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-)
fs/xfs/xfs_log.c +4 -14
@@ -2721,10 +2721,7 @@ static voidxlog_state_do_iclog_callbacks ( struct xlog *log, struct xlog_in_core *iclog) - __releases(&log->l_icloglock) - __acquires(&log->l_icloglock) { - spin_unlock(&log->l_icloglock); spin_lock(&iclog->ic_callback_lock);while (!list_empty (&iclog->ic_callbacks)) {LIST_HEAD (tmp);
@@ -2736,12 +2733,6 @@ xlog_state_do_iclog_callbacks(spin_lock (&iclog->ic_callback_lock); } -/* -* Pick up the icloglock while still holding the callback lock so we -* serialise against anyone trying to add more callbacks to this iclog -* now we've finished processing. -*/ -spin_lock (&log->l_icloglock);spin_unlock (&iclog->ic_callback_lock); }
@@ -2782,13 +2773,12 @@ xlog_state_do_callback( iclog = iclog->ic_next;continue ; } +spin_unlock (&log->l_icloglock); -/* -* Running callbacks will drop the icloglock which means -* we'll have to run at least one more complete loop. -*/ - cycled_icloglock = true;xlog_state_do_iclog_callbacks (log, iclog); + cycled_icloglock = true; + +spin_lock (&log->l_icloglock);if (XLOG_FORCED_SHUTDOWN (log))wake_up_all (&iclog->ic_force_wait);else
Signature · 1 line
2.53.0
PATCH RESEND v2 8/19 xfs: convert XLOG_FORCED_SHUTDOWN() to xlog_is_shutdown()
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
Make it less shouty and a static inline before adding more calls through the log code.
Also convert internal log code that uses XFS_FORCED_SHUTDOWN(mount) to use xlog_is_shutdown(log) as well.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
5.10:
Fixed conflicts due to the following missing commits:
956f6daa84bf ("xfs: add iclog state trace events")
303591a0a947 ("xfs: cover the log during log quiesce")--- fs/xfs/xfs_log.c | 30 +++++++++++++++--------------- fs/xfs/xfs_log_cil.c | 10 +++++----- fs/xfs/xfs_log_priv.h | 7 +++++-- fs/xfs/xfs_log_recover.c | 9 +++------ fs/xfs/xfs_trans.c | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-)
fs/xfs/xfs_log.c +15 -15
@@ -244,7 +244,7 @@ xlog_grant_head_wait(list_add_tail (&tic->t_queue, &head->waiters); do { - if (XLOG_FORCED_SHUTDOWN(log)) + if (xlog_is_shutdown(log)) goto shutdown; xlog_grant_push_ail(log, need_bytes);
@@ -258,7 +258,7 @@ xlog_grant_head_wait(trace_xfs_log_grant_wake (log, tic);spin_lock (&head->lock); -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log)) goto shutdown; }while (xlog_space_left (log, &head->grant) < need_bytes);
@@ -361,7 +361,7 @@ xfs_log_writable(return false;if (xfs_readonly_buftarg (mp->m_log->l_targ))return false; -if (XFS_FORCED_SHUTDOWN (mp)) +if (xlog_is_shutdown (mp->m_log))return false;return true; }
@@ -378,7 +378,7 @@ xfs_log_regrant(int need_bytes;int error =0 ; -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log))return -EIO ;XFS_STATS_INC (mp, xs_try_logspace);
@@ -446,7 +446,7 @@ xfs_log_reserve(ASSERT (client ==XFS_TRANSACTION || client ==XFS_LOG ); -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log))return -EIO ;XFS_STATS_INC (mp, xs_try_logspace);
@@ -794,7 +794,7 @@ xlog_wait_on_iclog( {struct xlog *log = iclog->ic_log; -if (!XLOG_FORCED_SHUTDOWN (log) && +if (!xlog_is_shutdown (log) && iclog->ic_state !=XLOG_STATE_ACTIVE && iclog->ic_state !=XLOG_STATE_DIRTY ) {XFS_STATS_INC (log->l_mp, xs_log_force_sleep);
@@ -803,7 +803,7 @@ xlog_wait_on_iclog(spin_unlock (&log->l_icloglock); } -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log))return -EIO ;return 0 ; }
@@ -913,7 +913,7 @@ xfs_log_unmount_write(xfs_log_force (mp,XFS_LOG_SYNC ); -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log))return ;/*
@@ -1013,7 +1013,7 @@ xfs_log_space_wake(struct xlog *log = mp->m_log;int free_bytes; -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log))return ;if (!list_empty_careful (&log->l_write_head.waiters)) {
@@ -1479,7 +1479,7 @@ xlog_commit_record( };int error; -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log))return -EIO ; error = xlog_write(log, &vec, ticket, lsn, iclog, XLOG_COMMIT_TRANS,
@@ -1561,7 +1561,7 @@ xlog_grant_push_ail(xfs_lsn_t threshold_lsn; threshold_lsn =xlog_grant_push_threshold (log, need_bytes); -if (threshold_lsn ==NULLCOMMITLSN ||XLOG_FORCED_SHUTDOWN (log)) +if (threshold_lsn ==NULLCOMMITLSN ||xlog_is_shutdown (log))return ;/*
@@ -2779,7 +2779,7 @@ xlog_state_do_callback( cycled_icloglock = true;spin_lock (&log->l_icloglock); -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log))wake_up_all (&iclog->ic_force_wait);else xlog_state_clean_iclog (log, iclog);
@@ -2830,7 +2830,7 @@ xlog_state_done_syncing(* split log writes, on the second, we shut down the file system and * no iclogs should ever be attempted to be written to disk again. */ -if (!XLOG_FORCED_SHUTDOWN (log)) { +if (!xlog_is_shutdown (log)) {ASSERT (iclog->ic_state ==XLOG_STATE_SYNCING ); iclog->ic_state =XLOG_STATE_DONE_SYNC ; }
@@ -2878,7 +2878,7 @@ xlog_state_get_iclog_space( restart:spin_lock (&log->l_icloglock); -if (XLOG_FORCED_SHUTDOWN (log)) { +if (xlog_is_shutdown (log)) {spin_unlock (&log->l_icloglock);return -EIO ; }
@@ -3720,7 +3720,7 @@ xfs_log_force_umount(* No need to get locks for this. */ if (logerror && log->l_iclog->ic_state ==XLOG_STATE_IOERROR ) { -ASSERT (XLOG_FORCED_SHUTDOWN (log)); +ASSERT (xlog_is_shutdown (log));return 1 ; }
fs/xfs/xfs_log_cil.c +5 -5
@@ -576,7 +576,7 @@ xlog_cil_committed( struct xfs_cil_ctx *ctx) {struct xfs_mount *mp = ctx->cil->xc_log->l_mp; -bool abort =XLOG_FORCED_SHUTDOWN (ctx->cil->xc_log); +bool abort =xlog_is_shutdown (ctx->cil->xc_log);/* * If the I/O failed, we're aborting the commit and already shutdown.
@@ -827,7 +827,7 @@ xlog_cil_push_work(* shutdown, but then went back to sleep once already in the * shutdown state. */ -if (XLOG_FORCED_SHUTDOWN (log)) { +if (xlog_is_shutdown (log)) {spin_unlock (&cil->xc_push_lock); goto out_abort_free_ticket; }
@@ -888,7 +888,7 @@ xlog_cil_push_work( out_abort_free_ticket:xfs_log_ticket_ungrant (log, tic); out_abort: -ASSERT (XLOG_FORCED_SHUTDOWN (log)); +ASSERT (xlog_is_shutdown (log));xlog_cil_committed (ctx); }
@@ -1041,7 +1041,7 @@ xlog_cil_commit(xlog_cil_insert_items (log, tp); -if (regrant && !XLOG_FORCED_SHUTDOWN (log)) +if (regrant && !xlog_is_shutdown (log))xfs_log_ticket_regrant (log, tp->t_ticket);else xfs_log_ticket_ungrant (log, tp->t_ticket);
@@ -1114,7 +1114,7 @@ xlog_cil_force_seq(* shutdown, but then went back to sleep once already in the * shutdown state. */ -if (XLOG_FORCED_SHUTDOWN (log)) +if (xlog_is_shutdown (log)) goto out_shutdown;if (ctx->sequence > sequence)continue ;
fs/xfs/xfs_log_priv.h +5 -2
@@ -441,8 +441,11 @@ struct xlog {#define XLOG_BUF_CANCEL_BUCKET (log, blkno) \ ((log)->l_buf_cancel_table + ((uint64_t)blkno % XLOG_BC_TABLE_SIZE)) -#define XLOG_FORCED_SHUTDOWN (log) \ - (unlikely((log)->l_flags & XLOG_IO_ERROR)) +static inline bool +xlog_is_shutdown (struct xlog *log) +{ +return (log->l_flags &XLOG_IO_ERROR ); +}/* common routines */ extern int
fs/xfs/xfs_log_recover.c +3 -6
@@ -145,7 +145,7 @@ xlog_do_io( error =xfs_rw_bdev (log->l_targ->bt_bdev, log->l_logBBstart + blk_no,BBTOB (nbblks), data, op); -if (error && !XFS_FORCED_SHUTDOWN (log->l_mp)) { +if (error && !xlog_is_shutdown (log)) { xfs_alert(log->l_mp, "log recovery %s I/O error at daddr 0x%llx len %d error %d", op == REQ_OP_WRITE ? "write" : "read",
@@ -3288,10 +3288,7 @@ xlog_do_recover(if (error)return error; -/* -* If IO errors happened during recovery, bail out. -*/ -if (XFS_FORCED_SHUTDOWN (mp)) +if (xlog_is_shutdown (log))return -EIO ;/*
@@ -3313,7 +3310,7 @@ xlog_do_recover(xfs_buf_hold (bp); error =_xfs_buf_read (bp,XBF_READ );if (error) { -if (!XFS_FORCED_SHUTDOWN (mp)) { +if (!xlog_is_shutdown (log)) {xfs_buf_ioerror_alert (bp, __this_address);ASSERT (0 ); }
fs/xfs/xfs_trans.c +1 -1
@@ -901,7 +901,7 @@ __xfs_trans_commit(*/ xfs_trans_unreserve_and_mod_dquots (tp);if (tp->t_ticket) { -if (regrant && !XLOG_FORCED_SHUTDOWN (mp->m_log)) +if (regrant && !xlog_is_shutdown (mp->m_log))xfs_log_ticket_regrant (mp->m_log, tp->t_ticket);else xfs_log_ticket_ungrant (mp->m_log, tp->t_ticket);
Signature · 1 line
2.53.0
PATCH RESEND v2 9/19 xfs: log items should have a xlog pointer, not a mount
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
Log items belong to the log, not the xfs_mount. Convert the mount pointer in the log item to a xlog pointer in preparation for upcoming log centric changes to the log items.
Stable-dep-of: 7b5f775be14a ("xfs: fix unmount hang with unflushable inodes stuck in the AIL")
5.10:
Fixed conflicts due to the following missing commits:
38c26bfd90e1 ("xfs: replace xfs_sb_version checks with feature flag checks") 75c8c50fa16a ("xfs: replace XFS_FORCED_SHUTDOWN with xfs_is_shutdown")
Extra conversion in fs/xfs/xfs_dquot_item.c due to missing:
40b52225e58c ("xfs: remove support for disabling quota accounting on a mounted file system")
--- fs/xfs/xfs_bmap_item.c | 2 +- fs/xfs/xfs_buf_item.c | 5 +++-- fs/xfs/xfs_dquot_item.c | 5 +++-- fs/xfs/xfs_extfree_item.c | 2 +- fs/xfs/xfs_log.c | 2 +- fs/xfs/xfs_log_cil.c | 2 +- fs/xfs/xfs_refcount_item.c | 2 +- fs/xfs/xfs_rmap_item.c | 2 +- fs/xfs/xfs_trace.h | 4 ++-- fs/xfs/xfs_trans.c | 2 +- fs/xfs/xfs_trans.h | 3 ++- 11 files changed, 17 insertions(+), 14 deletions(-)
fs/xfs/xfs_bmap_item.c +1 -1
@@ -474,7 +474,7 @@ xfs_bui_item_recover(struct xfs_bui_log_item *buip =BUI_ITEM (lip);struct xfs_trans *tp;struct xfs_inode *ip =NULL ; -struct xfs_mount *mp = lip->li_mountp; +struct xfs_mount *mp = lip->li_log->l_mp;struct xfs_map_extent *bmap;struct xfs_bud_log_item *budp;xfs_filblks_t count;
fs/xfs/xfs_buf_item.c +3 -2
@@ -21,6 +21,7 @@#include "xfs_dquot.h" #include "xfs_trace.h" #include "xfs_log.h" +#include "xfs_log_priv.h" kmem_zone_t *xfs_buf_item_zone;
@@ -347,7 +348,7 @@ xfs_buf_item_format(* occurs during recovery. */ if (bip->bli_flags &XFS_BLI_INODE_BUF ) { -if (xfs_sb_version_has_v3inode (&lip->li_mountp->m_sb) || +if (xfs_sb_version_has_v3inode (&lip->li_log->l_mp->m_sb) || !((bip->bli_flags &XFS_BLI_INODE_ALLOC_BUF ) &&xfs_log_item_in_current_chkpt (lip))) bip->__bli_format.blf_flags |=XFS_BLF_INODE_BUF ;
@@ -535,7 +536,7 @@ xfs_buf_item_put(* that case, the bli is freed on buffer writeback completion. */ aborted =test_bit (XFS_LI_ABORTED , &lip->li_flags) || -XFS_FORCED_SHUTDOWN (lip->li_mountp); +xlog_is_shutdown (lip->li_log); dirty = bip->bli_flags &XFS_BLI_DIRTY ;if (dirty && !aborted)return false;
fs/xfs/xfs_dquot_item.c +3 -2
@@ -17,6 +17,7 @@#include "xfs_trans_priv.h" #include "xfs_qm.h" #include "xfs_log.h" +#include "xfs_log_priv.h" static inline struct xfs_dq_logitem *DQUOT_ITEM (struct xfs_log_item *lip) {
@@ -331,7 +332,7 @@ xfs_qm_qoff_logitem_relse(ASSERT (test_bit (XFS_LI_IN_AIL , &lip->li_flags) ||test_bit (XFS_LI_ABORTED , &lip->li_flags) || -XFS_FORCED_SHUTDOWN (lip->li_mountp)); +xlog_is_shutdown (lip->li_log));xfs_trans_ail_delete (lip,0 );kmem_free (lip->li_lv_shadow);kmem_free (qoff);
@@ -352,7 +353,7 @@ xfs_qm_qoff_logitem_init(xfs_log_item_init (mp, &qf->qql_item,XFS_LI_QUOTAOFF , start ? &xfs_qm_qoffend_logitem_ops : &xfs_qm_qoff_logitem_ops); - qf->qql_item.li_mountp = mp; + qf->qql_item.li_log = mp->m_log; qf->qql_start_lip = start; qf->qql_flags = flags;return qf;
fs/xfs/xfs_extfree_item.c +1 -1
@@ -588,7 +588,7 @@ xfs_efi_item_recover( struct list_head *capture_list) {struct xfs_efi_log_item *efip =EFI_ITEM (lip); -struct xfs_mount *mp = lip->li_mountp; +struct xfs_mount *mp = lip->li_log->l_mp;struct xfs_efd_log_item *efdp;struct xfs_trans *tp;struct xfs_extent *extp;
fs/xfs/xfs_log.c +1 -1
@@ -991,7 +991,7 @@ xfs_log_item_init(int type, const struct xfs_item_ops *ops) { - item->li_mountp = mp; + item->li_log = mp->m_log; item->li_ailp = mp->m_ail; item->li_type = type; item->li_ops = ops;
fs/xfs/xfs_log_cil.c +1 -1
@@ -1181,7 +1181,7 @@ boolxfs_log_item_in_current_chkpt ( struct xfs_log_item *lip) { -struct xfs_cil *cil = lip->li_mountp->m_log->l_cilp; +struct xfs_cil *cil = lip->li_log->l_cilp;if (list_empty (&lip->li_cil))return false;
fs/xfs/xfs_refcount_item.c +1 -1
@@ -463,7 +463,7 @@ xfs_cui_item_recover(struct xfs_cud_log_item *cudp;struct xfs_trans *tp;struct xfs_btree_cur *rcur =NULL ; -struct xfs_mount *mp = lip->li_mountp; +struct xfs_mount *mp = lip->li_log->l_mp;xfs_fsblock_t new_fsb;xfs_extlen_t new_len;unsigned int refc_type;
fs/xfs/xfs_rmap_item.c +1 -1
@@ -516,7 +516,7 @@ xfs_rui_item_recover(struct xfs_rud_log_item *rudp;struct xfs_trans *tp;struct xfs_btree_cur *rcur =NULL ; -struct xfs_mount *mp = lip->li_mountp; +struct xfs_mount *mp = lip->li_log->l_mp;enum xfs_rmap_intent_type type;xfs_exntst_t state;int i;
fs/xfs/xfs_trace.h +2 -2
@@ -1169,7 +1169,7 @@ DECLARE_EVENT_CLASS(xfs_log_item_class,__field (xfs_lsn_t, lsn) ),TP_fast_assign ( - __entry->dev = lip->li_mountp->m_super->s_dev; + __entry->dev = lip->li_log->l_mp->m_super->s_dev; __entry->lip = lip; __entry->type = lip->li_type; __entry->flags = lip->li_flags;
@@ -1222,7 +1222,7 @@ DECLARE_EVENT_CLASS(xfs_ail_class,__field (xfs_lsn_t, new_lsn) ),TP_fast_assign ( - __entry->dev = lip->li_mountp->m_super->s_dev; + __entry->dev = lip->li_log->l_mp->m_super->s_dev; __entry->lip = lip; __entry->type = lip->li_type; __entry->flags = lip->li_flags;
fs/xfs/xfs_trans.c +1 -1
@@ -644,7 +644,7 @@ xfs_trans_add_item(struct xfs_trans *tp, struct xfs_log_item *lip) { - ASSERT(lip->li_mountp == tp->t_mountp); + ASSERT(lip->li_log == tp->t_mountp->m_log);ASSERT (lip->li_ailp == tp->t_mountp->m_ail);ASSERT (list_empty (&lip->li_trans));ASSERT (!test_bit (XFS_LI_DIRTY , &lip->li_flags));
fs/xfs/xfs_trans.h +2 -1
@@ -8,6 +8,7 @@/* kernel only transaction subsystem defines */ +struct xlog ;struct xfs_buf ;struct xfs_buftarg ;struct xfs_efd_log_item ;
@@ -31,7 +32,7 @@ struct xfs_log_item {struct list_head li_ail;/* AIL pointers */ struct list_head li_trans;/* transaction list */ xfs_lsn_t li_lsn;/* last on-disk lsn */ -struct xfs_mount *li_mountp;/* ptr to fs mount */ +struct xlog *li_log;struct xfs_ail *li_ailp;/* ptr to AIL */ uint li_type;/* item type */ unsigned long li_flags;/* misc flags */
Signature · 1 line
2.53.0
PATCH RESEND v2 10/19 xfs: aborting inodes on shutdown may need buffer lock
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
Most buffer io list operations are run with the bp->b_lock held, but xfs_iflush_abort() can be called without the buffer lock being held resulting in inodes being removed from the buffer list while other list operations are occurring. This causes problems with corrupted bp->b_io_list inode lists during filesystem shutdown, leading to traversals that never end, double removals from the AIL, etc.
Fix this by passing the buffer to xfs_iflush_abort() if we have it locked. If the inode is attached to the buffer, we're going to have to remove it from the buffer list and we'd have to get the buffer off the inode log item to do that anyway.
If we don't have a buffer passed in (e.g. from xfs_reclaim_inode()) then we can determine if the inode has a log item and if it is attached to a buffer before we do anything else. If it does have an attached buffer, we can lock it safely (because the inode has a reference to it) and then perform the inode abort.
Stable-dep-of: 09234a632be4 ("xfs: xfs_ifree_cluster vs xfs_iflush_shutdown_abort deadlock")
--- fs/xfs/xfs_icache.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 164 ++++++++++++++++++++++++++++++++-------- fs/xfs/xfs_inode_item.h | 1 + 4 files changed, 137 insertions(+), 32 deletions(-)
fs/xfs/xfs_icache.c +1 -1
@@ -1040,7 +1040,7 @@ xfs_reclaim_inode(if (XFS_FORCED_SHUTDOWN (ip->i_mount)) {xfs_iunpin_wait (ip); -xfs_iflush_abort (ip); +xfs_iflush_shutdown_abort (ip); goto reclaim; }if (xfs_ipincount (ip))
fs/xfs/xfs_inode.c +1 -1
@@ -3613,7 +3613,7 @@ xfs_iflush_cluster(/* * We must use the safe variant here as on shutdown xfs_iflush_abort() -* can remove itself from the list. +* will remove itself from the list. */ list_for_each_entry_safe (lip, n, &bp->b_li_list, li_bio_list) { iip = (struct xfs_inode_log_item *)lip;
fs/xfs/xfs_inode_item.c +134 -30
190 lines not on this page · raw message
fs/xfs/xfs_inode_item.h +1 -0
@@ -44,6 +44,7 @@ static inline int xfs_inode_clean(struct xfs_inode *ip)extern void xfs_inode_item_init (struct xfs_inode *,struct xfs_mount *);extern void xfs_inode_item_destroy (struct xfs_inode *);extern void xfs_iflush_abort (struct xfs_inode *); +extern void xfs_iflush_shutdown_abort (struct xfs_inode *);extern int xfs_inode_item_format_convert (xfs_log_iovec_t *,struct xfs_inode_log_format *);
Signature · 1 line
2.53.0
PATCH RESEND v2 11/19 xfs: remove xfs_buf_t typedef
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
Prepare for kernel xfs_buf alignment by getting rid of the xfs_buf_t typedef from userspace.
[darrick: This patch is a port of a userspace patch removing the xfs_buf_t typedef in preparation to make the userspace xfs_buf code behave more like its kernel counterpart.]
Stable-dep-of: d2fe5c4c8d25 ("xfs: rearrange code in xfs_buf_item.c")
5.10:
2 extra conversions in fs/xfs/xfs_inode.c due to missing:
1abcf261016e ("xfs: move on-disk inode allocation out of xfs_ialloc()")
--- fs/xfs/libxfs/xfs_alloc.c | 16 ++++++++-------- fs/xfs/libxfs/xfs_bmap.c | 6 +++--- fs/xfs/libxfs/xfs_btree.c | 10 +++++----- fs/xfs/libxfs/xfs_ialloc.c | 4 ++-- fs/xfs/libxfs/xfs_rtbitmap.c | 22 +++++++++++----------- fs/xfs/xfs_buf.c | 24 ++++++++++++------------ fs/xfs/xfs_buf.h | 14 +++++++------- fs/xfs/xfs_buf_item.c | 4 ++-- fs/xfs/xfs_fsops.c | 2 +- fs/xfs/xfs_inode.c | 4 ++-- fs/xfs/xfs_log_recover.c | 8 ++++---- fs/xfs/xfs_rtalloc.c | 20 ++++++++++---------- fs/xfs/xfs_rtalloc.h | 4 ++-- fs/xfs/xfs_symlink.c | 4 ++-- fs/xfs/xfs_trans.c | 2 +- fs/xfs/xfs_trans_buf.c | 16 ++++++++-------- 16 files changed, 80 insertions(+), 80 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +8 -8
@@ -690,9 +690,9 @@ xfs_alloc_read_agfl( xfs_mount_t *mp, /* mount point structure */ xfs_trans_t *tp, /* transaction pointer */ xfs_agnumber_t agno, /* allocation group number */ - xfs_buf_t **bpp) /* buffer for the ag free block array */ + struct xfs_buf **bpp) /* buffer for the ag free block array */ { -xfs_buf_t *bp;/* return value */ +struct xfs_buf *bp;/* return value */ int error;ASSERT (agno !=NULLAGNUMBER );
@@ -2647,12 +2647,12 @@ xfs_alloc_fix_freelist(int /* error */ xfs_alloc_get_freelist (xfs_trans_t *tp,/* transaction pointer */ -xfs_buf_t *agbp,/* buffer containing the agf structure */ +struct xfs_buf *agbp,/* buffer containing the agf structure */ xfs_agblock_t *bnop,/* block address retrieved from freelist */ int btreeblk)/* destination is a AGF btree */ {struct xfs_agf *agf = agbp->b_addr; -xfs_buf_t *agflbp;/* buffer for a.g. freelist structure */ +struct xfs_buf *agflbp;/* buffer for a.g. freelist structure */ xfs_agblock_t bno;/* block number returned */ __be32 *agfl_bno;int error;
@@ -2711,7 +2711,7 @@ xfs_alloc_get_freelist(void xfs_alloc_log_agf (xfs_trans_t *tp,/* transaction pointer */ -xfs_buf_t *bp,/* buffer for a.g. freelist header */ +struct xfs_buf *bp,/* buffer for a.g. freelist header */ int fields)/* mask of fields to be logged (XFS_AGF_...) */ {int first;/* first byte offset */
@@ -2757,7 +2757,7 @@ xfs_alloc_pagf_init( xfs_agnumber_t agno, /* allocation group number */ int flags) /* XFS_ALLOC_FLAGS_... */ { -xfs_buf_t *bp; +struct xfs_buf *bp;int error; error =xfs_alloc_read_agf (mp, tp, agno, flags, &bp);
@@ -2772,8 +2772,8 @@ xfs_alloc_pagf_init(int /* error */ xfs_alloc_put_freelist (xfs_trans_t *tp,/* transaction pointer */ -xfs_buf_t *agbp,/* buffer for a.g. freelist header */ -xfs_buf_t *agflbp,/* buffer for a.g. free block array */ +struct xfs_buf *agbp,/* buffer for a.g. freelist header */ +struct xfs_buf *agflbp,/* buffer for a.g. free block array */ xfs_agblock_t bno,/* block being freed */ int btreeblk)/* block came from a AGF btree */ {
fs/xfs/libxfs/xfs_bmap.c +3 -3
@@ -321,7 +321,7 @@ xfs_bmap_check_leaf_extents(struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);struct xfs_btree_block *block;/* current btree block */ xfs_fsblock_t bno;/* block # of "block" */ -xfs_buf_t *bp;/* buffer for "block" */ +struct xfs_buf *bp;/* buffer for "block" */ int error;/* error return value */ xfs_extnum_t i=0 , j;/* index into the extents list */ int level;/* btree level, for checking */
@@ -592,7 +592,7 @@ xfs_bmap_btree_to_extents(struct xfs_btree_block *rblock = ifp->if_broot;struct xfs_btree_block *cblock;/* child btree block */ xfs_fsblock_t cbno;/* child block number */ -xfs_buf_t *cbp;/* child block's buffer */ +struct xfs_buf *cbp;/* child block's buffer */ int error;/* error return value */ __be64 *pp;/* ptr to block address */ struct xfs_owner_info oinfo;
@@ -830,7 +830,7 @@ xfs_bmap_local_to_extents(int flags;/* logging flags returned */ struct xfs_ifork *ifp;/* inode fork pointer */ xfs_alloc_arg_t args;/* allocation arguments */ -xfs_buf_t *bp;/* buffer for extent block */ +struct xfs_buf *bp;/* buffer for extent block */ struct xfs_bmbt_irec rec;struct xfs_iext_cursor icur;
fs/xfs/libxfs/xfs_btree.c +5 -5
@@ -394,7 +394,7 @@ xfs_btree_dup_cursor( xfs_btree_cur_t *cur, /* input cursor */ xfs_btree_cur_t **ncur) /* output cursor */ { -xfs_buf_t *bp;/* btree block's buffer pointer */ +struct xfs_buf *bp;/* btree block's buffer pointer */ int error;/* error return value */ int i;/* level number of btree block */ xfs_mount_t *mp;/* mount structure for filesystem */
@@ -698,7 +698,7 @@ xfs_btree_firstrec( int level) /* level to change */ {struct xfs_btree_block *block;/* generic btree block pointer */ -xfs_buf_t *bp;/* buffer containing block */ +struct xfs_buf *bp;/* buffer containing block */ /* * Get the block pointer for this level.
@@ -728,7 +728,7 @@ xfs_btree_lastrec( int level) /* level to change */ {struct xfs_btree_block *block;/* generic btree block pointer */ -xfs_buf_t *bp;/* buffer containing block */ +struct xfs_buf *bp;/* buffer containing block */ /* * Get the block pointer for this level.
@@ -990,7 +990,7 @@ STATIC voidxfs_btree_setbuf ( xfs_btree_cur_t *cur,/* btree cursor */ int lev, /* level in btree */ - xfs_buf_t *bp) /* new buffer to set */ + struct xfs_buf *bp) /* new buffer to set */ {struct xfs_btree_block *b;/* btree block */
@@ -1633,7 +1633,7 @@ xfs_btree_decrement( int *stat) /* success/failure */ {struct xfs_btree_block *block; -xfs_buf_t *bp; +struct xfs_buf *bp;int error;/* error return value */ int lev;union xfs_btree_ptr ptr;
fs/xfs/libxfs/xfs_ialloc.c +2 -2
@@ -2454,7 +2454,7 @@ xfs_imap(void xfs_ialloc_log_agi (xfs_trans_t *tp,/* transaction pointer */ -xfs_buf_t *bp,/* allocation group header buffer */ +struct xfs_buf *bp,/* allocation group header buffer */ int fields)/* bitmask of fields to log */ {int first;/* first byte number */
@@ -2675,7 +2675,7 @@ xfs_ialloc_pagi_init( xfs_trans_t *tp, /* transaction pointer */ xfs_agnumber_t agno) /* allocation group number */ { -xfs_buf_t *bp =NULL ; +struct xfs_buf *bp =NULL ;int error; error =xfs_ialloc_read_agi (mp, tp, agno, &bp);
fs/xfs/libxfs/xfs_rtbitmap.c +11 -11
@@ -56,9 +56,9 @@ xfs_rtbuf_get(xfs_trans_t *tp,/* transaction pointer */ xfs_rtblock_t block, /* block number in bitmap or summary */ int issum, /* is summary not bitmap */ - xfs_buf_t **bpp) /* output: buffer for the block */ + struct xfs_buf **bpp) /* output: buffer for the block */ { - xfs_buf_t *bp; /* block buffer, result */ + struct xfs_buf *bp; /* block buffer, result */xfs_inode_t *ip;/* bitmap or summary inode */ xfs_bmbt_irec_t map;int nmap =1 ;
@@ -101,7 +101,7 @@ xfs_rtfind_back(xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */ xfs_rtblock_t block;/* bitmap block number */ -xfs_buf_t *bp;/* buf for the block */ +struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */ xfs_rtblock_t firstbit;/* first useful bit in the word */
@@ -276,7 +276,7 @@ xfs_rtfind_forw(xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */ xfs_rtblock_t block;/* bitmap block number */ -xfs_buf_t *bp;/* buf for the block */ +struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */ xfs_rtblock_t i;/* current bit number rel. to start */
@@ -447,11 +447,11 @@ xfs_rtmodify_summary_int(int log,/* log2 of extent size */ xfs_rtblock_t bbno, /* bitmap block number */ int delta, /* change to make to summary info */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb, /* in/out: summary block number */ xfs_suminfo_t *sum) /* out: summary info for this block */ { - xfs_buf_t *bp; /* buffer for the summary block */ + struct xfs_buf *bp; /* buffer for the summary block */int error;/* error value */ xfs_fsblock_t sb;/* summary fsblock */ int so;/* index into the summary file */
@@ -517,7 +517,7 @@ xfs_rtmodify_summary( int log, /* log2 of extent size */ xfs_rtblock_t bbno, /* bitmap block number */ int delta, /* change to make to summary info */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb) /* in/out: summary block number */ { return xfs_rtmodify_summary_int(mp, tp, log, bbno,
@@ -539,7 +539,7 @@ xfs_rtmodify_range(xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */ xfs_rtblock_t block;/* bitmap block number */ -xfs_buf_t *bp;/* buf for the block */ +struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */ xfs_rtword_t *first;/* first used word in the buffer */
@@ -690,7 +690,7 @@ xfs_rtfree_range(xfs_trans_t *tp,/* transaction pointer */ xfs_rtblock_t start, /* starting block to free */ xfs_extlen_t len, /* length to free */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb) /* in/out: summary block number */ { xfs_rtblock_t end; /* end of the freed extent */
@@ -773,7 +773,7 @@ xfs_rtcheck_range(xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */ xfs_rtblock_t block;/* bitmap block number */ -xfs_buf_t *bp;/* buf for the block */ +struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */ xfs_rtblock_t i;/* current bit number rel. to start */
@@ -969,7 +969,7 @@ xfs_rtfree_extent(int error;/* error value */ xfs_mount_t *mp;/* file system mount structure */ xfs_fsblock_t sb;/* summary file block number */ -xfs_buf_t *sumbp =NULL ;/* summary file block buffer */ +struct xfs_buf *sumbp =NULL ;/* summary file block buffer */ mp = tp->t_mountp;
fs/xfs/xfs_buf.c +12 -12
@@ -278,7 +278,7 @@ _xfs_buf_alloc(*/ STATIC int_xfs_buf_get_pages ( -xfs_buf_t *bp, +struct xfs_buf *bp,int page_count) {/* Make sure that we have a page list */
@@ -302,7 +302,7 @@ _xfs_buf_get_pages(*/ STATIC void_xfs_buf_free_pages ( -xfs_buf_t *bp) +struct xfs_buf *bp) {if (bp->b_pages != bp->b_page_array) {kmem_free (bp->b_pages);
@@ -319,7 +319,7 @@ _xfs_buf_free_pages(*/ static void xfs_buf_free ( -xfs_buf_t *bp) +struct xfs_buf *bp) {trace_xfs_buf_free (bp, _RET_IP_);
@@ -352,7 +352,7 @@ xfs_buf_free(*/ STATIC intxfs_buf_allocate_memory ( -xfs_buf_t *bp, +struct xfs_buf *bp,uint flags) {size_t size;
@@ -463,7 +463,7 @@ xfs_buf_allocate_memory(*/ STATIC int_xfs_buf_map_pages ( -xfs_buf_t *bp, +struct xfs_buf *bp,uint flags) {ASSERT (bp->b_flags & _XBF_PAGES);
@@ -590,7 +590,7 @@ xfs_buf_find( struct xfs_buf **found_bp) {struct xfs_perag *pag; -xfs_buf_t *bp; +struct xfs_buf *bp;struct xfs_buf_map cmap = { .bm_bn = map[0 ].bm_bn };xfs_daddr_t eofs;int i;
@@ -762,7 +762,7 @@ xfs_buf_get_map(int _xfs_buf_read ( -xfs_buf_t *bp, +struct xfs_buf *bp,xfs_buf_flags_t flags) {ASSERT (!(flags &XBF_WRITE ));
@@ -1005,7 +1005,7 @@ xfs_buf_get_uncached(*/ void xfs_buf_hold ( -xfs_buf_t *bp) +struct xfs_buf *bp) {trace_xfs_buf_hold (bp, _RET_IP_);atomic_inc (&bp->b_hold);
@@ -1017,7 +1017,7 @@ xfs_buf_hold(*/ void xfs_buf_rele ( -xfs_buf_t *bp) +struct xfs_buf *bp) {struct xfs_perag *pag = bp->b_pag;bool release;
@@ -1161,7 +1161,7 @@ xfs_buf_unlock( STATIC voidxfs_buf_wait_unpin ( -xfs_buf_t *bp) +struct xfs_buf *bp) {DECLARE_WAITQUEUE (wait, current);
@@ -1373,7 +1373,7 @@ xfs_buf_ioend_work( struct work_struct *work) {struct xfs_buf *bp = -container_of (work, xfs_buf_t, b_ioend_work); + container_of(work, struct xfs_buf, b_ioend_work);xfs_buf_ioend (bp); }
@@ -1388,7 +1388,7 @@ xfs_buf_ioend_async(void __xfs_buf_ioerror ( -xfs_buf_t *bp, +struct xfs_buf *bp,int error,xfs_failaddr_t failaddr) {
fs/xfs/xfs_buf.h +7 -7
@@ -124,7 +124,7 @@ struct xfs_buf_ops {xfs_failaddr_t (*verify_struct)(struct xfs_buf *bp); }; -typedef struct xfs_buf { +struct xfs_buf {/* * first cacheline holds all the fields needed for an uncontended cache * hit to be fully processed. The semaphore straddles the cacheline
@@ -190,7 +190,7 @@ typedef struct xfs_buf {int b_last_error;const struct xfs_buf_ops *b_ops; -} xfs_buf_t; +};/* Finding and Reading Buffers */ struct xfs_buf *xfs_buf_incore(struct xfs_buftarg *target,
@@ -253,16 +253,16 @@ int _xfs_buf_read(struct xfs_buf *bp, xfs_buf_flags_t flags);void xfs_buf_hold (struct xfs_buf *bp);/* Releasing Buffers */ -extern void xfs_buf_rele (xfs_buf_t *); +extern void xfs_buf_rele (struct xfs_buf *);/* Locking and Unlocking Buffers */ -extern int xfs_buf_trylock (xfs_buf_t *); -extern void xfs_buf_lock (xfs_buf_t *); -extern void xfs_buf_unlock (xfs_buf_t *); +extern int xfs_buf_trylock (struct xfs_buf *); +extern void xfs_buf_lock (struct xfs_buf *); +extern void xfs_buf_unlock (struct xfs_buf *);#define xfs_buf_islocked (bp) \ ((bp)->b_sema.count <= 0) -static inline void xfs_buf_relse (xfs_buf_t *bp) +static inline void xfs_buf_relse (struct xfs_buf *bp) {xfs_buf_unlock (bp);xfs_buf_rele (bp);
fs/xfs/xfs_buf_item.c +2 -2
@@ -403,7 +403,7 @@ xfs_buf_item_unpin( int remove) {struct xfs_buf_log_item *bip =BUF_ITEM (lip); -xfs_buf_t *bp = bip->bli_buf; +struct xfs_buf *bp = bip->bli_buf;int stale = bip->bli_flags &XFS_BLI_STALE ;int freed;
@@ -931,7 +931,7 @@ xfs_buf_item_free(*/ void xfs_buf_item_relse ( -xfs_buf_t *bp) +struct xfs_buf *bp) {struct xfs_buf_log_item *bip = bp->b_log_item;
fs/xfs/xfs_fsops.c +1 -1
@@ -28,7 +28,7 @@ xfs_growfs_data_private( xfs_mount_t *mp, /* mount point for filesystem */ xfs_growfs_data_t *in) /* growfs data input struct */ { -xfs_buf_t *bp; +struct xfs_buf *bp;int error;xfs_agnumber_t nagcount;xfs_agnumber_t nagimax =0 ;
fs/xfs/xfs_inode.c +2 -2
@@ -799,7 +799,7 @@ xfs_ialloc(xfs_nlink_t nlink, dev_t rdev, prid_t prid, - xfs_buf_t **ialloc_context, + struct xfs_buf **ialloc_context, xfs_inode_t **ipp) { struct inode *dir = pip ? VFS_I(pip) : NULL;
@@ -956,7 +956,7 @@ xfs_dir_ialloc( {xfs_trans_t *tp;xfs_inode_t *ip; -xfs_buf_t *ialloc_context =NULL ; +struct xfs_buf *ialloc_context =NULL ;int code;void *dqinfo;uint tflags;
fs/xfs/xfs_log_recover.c +4 -4
@@ -2633,7 +2633,7 @@ xlog_recover_clear_agi_bucket( {xfs_trans_t *tp;xfs_agi_t *agi; -xfs_buf_t *agibp; +struct xfs_buf *agibp;int offset;int error;
@@ -2751,7 +2751,7 @@ xlog_recover_process_iunlinks(xfs_mount_t *mp;xfs_agnumber_t agno;xfs_agi_t *agi; -xfs_buf_t *agibp; +struct xfs_buf *agibp;xfs_agino_t agino;int bucket;int error;
@@ -3502,8 +3502,8 @@ xlog_recover_check_summary( struct xlog *log) {xfs_mount_t *mp; -xfs_buf_t *agfbp; -xfs_buf_t *agibp; +struct xfs_buf *agfbp; +struct xfs_buf *agibp;xfs_agnumber_t agno;uint64_t freeblks;uint64_t itotal;
fs/xfs/xfs_rtalloc.c +10 -10
@@ -32,7 +32,7 @@ xfs_rtget_summary(xfs_trans_t *tp,/* transaction pointer */ int log, /* log2 of extent size */ xfs_rtblock_t bbno, /* bitmap block number */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb, /* in/out: summary block number */ xfs_suminfo_t *sum) /* out: summary info for this block */ {
@@ -50,7 +50,7 @@ xfs_rtany_summary(int low,/* low log2 extent size */ int high, /* high log2 extent size */ xfs_rtblock_t bbno, /* bitmap block number */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb, /* in/out: summary block number */ int *stat) /* out: any good extents here? */ {
@@ -104,7 +104,7 @@ xfs_rtcopy_summary( xfs_trans_t *tp) /* transaction pointer */ {xfs_rtblock_t bbno;/* bitmap block number */ -xfs_buf_t *bp;/* summary buffer */ +struct xfs_buf *bp;/* summary buffer */ int error;/* error return value */ int log;/* summary level number (log length) */ xfs_suminfo_t sum;/* summary data */
@@ -144,7 +144,7 @@ xfs_rtallocate_range(xfs_trans_t *tp,/* transaction pointer */ xfs_rtblock_t start, /* start block to allocate */ xfs_extlen_t len, /* length to allocate */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb) /* in/out: summary block number */ { xfs_rtblock_t end; /* end of the allocated extent */
@@ -226,7 +226,7 @@ xfs_rtallocate_extent_block(xfs_extlen_t maxlen,/* maximum length to allocate */ xfs_extlen_t *len, /* out: actual length allocated */ xfs_rtblock_t *nextp, /* out: next block to try */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb, /* in/out: summary block number */ xfs_extlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock) /* out: start block allocated */
@@ -345,7 +345,7 @@ xfs_rtallocate_extent_exact(xfs_extlen_t minlen,/* minimum length to allocate */ xfs_extlen_t maxlen, /* maximum length to allocate */ xfs_extlen_t *len, /* out: actual length allocated */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb, /* in/out: summary block number */ xfs_extlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock) /* out: start block allocated */
@@ -424,7 +424,7 @@ xfs_rtallocate_extent_near(xfs_extlen_t minlen,/* minimum length to allocate */ xfs_extlen_t maxlen, /* maximum length to allocate */ xfs_extlen_t *len, /* out: actual length allocated */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb, /* in/out: summary block number */ xfs_extlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock) /* out: start block allocated */
@@ -626,7 +626,7 @@ xfs_rtallocate_extent_size(xfs_extlen_t minlen,/* minimum length to allocate */ xfs_extlen_t maxlen, /* maximum length to allocate */ xfs_extlen_t *len, /* out: actual length allocated */ - xfs_buf_t **rbpp, /* in/out: summary block buffer */ + struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb, /* in/out: summary block number */ xfs_extlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock) /* out: start block allocated */
@@ -900,7 +900,7 @@ xfs_growfs_rt( xfs_growfs_rt_t *in) /* growfs rt input struct */ {xfs_rtblock_t bmbno;/* bitmap block number */ -xfs_buf_t *bp;/* temporary buffer */ +struct xfs_buf *bp;/* temporary buffer */ int error;/* error return value */ xfs_mount_t *nmp;/* new (fake) mount structure */ xfs_rfsblock_t nrblocks;/* new number of realtime blocks */
@@ -1154,7 +1154,7 @@ xfs_rtallocate_extent(int error;/* error value */ xfs_rtblock_t r;/* result allocated block */ xfs_fsblock_t sb;/* summary file block number */ -xfs_buf_t *sumbp;/* summary file block buffer */ +struct xfs_buf *sumbp;/* summary file block buffer */ ASSERT (xfs_isilocked (mp->m_rbmip,XFS_ILOCK_EXCL ));ASSERT (minlen >0 && minlen <= maxlen);
fs/xfs/xfs_rtalloc.h +2 -2
@@ -115,10 +115,10 @@ int xfs_rtmodify_range(struct xfs_mount *mp, struct xfs_trans *tp, xfs_rtblock_t start, xfs_extlen_t len, int val);int xfs_rtmodify_summary_int (struct xfs_mount *mp,struct xfs_trans *tp,int log,xfs_rtblock_t bbno,int delta, -xfs_buf_t **rbpp,xfs_fsblock_t *rsb, +struct xfs_buf **rbpp,xfs_fsblock_t *rsb,xfs_suminfo_t *sum);int xfs_rtmodify_summary (struct xfs_mount *mp,struct xfs_trans *tp,int log, -xfs_rtblock_t bbno,int delta,xfs_buf_t **rbpp, +xfs_rtblock_t bbno,int delta,struct xfs_buf **rbpp,xfs_fsblock_t *rsb); int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp, xfs_rtblock_t start, xfs_extlen_t len,
fs/xfs/xfs_symlink.c +2 -2
@@ -154,7 +154,7 @@ xfs_symlink(const char *cur_chunk;int byte_cnt;int n; -xfs_buf_t *bp; +struct xfs_buf *bp;prid_t prid;struct xfs_dquot *udqp =NULL ;struct xfs_dquot *gdqp =NULL ;
@@ -366,7 +366,7 @@ STATIC intxfs_inactive_symlink_rmt ( struct xfs_inode *ip) { -xfs_buf_t *bp; +struct xfs_buf *bp;int done;int error;int i;
fs/xfs/xfs_trans.c +1 -1
@@ -460,7 +460,7 @@ xfs_trans_apply_sb_deltas( xfs_trans_t *tp) {xfs_dsb_t *sbp; -xfs_buf_t *bp; +struct xfs_buf *bp;int whole =0 ; bp =xfs_trans_getsb (tp);
fs/xfs/xfs_trans_buf.c +8 -8
@@ -121,7 +121,7 @@ xfs_trans_get_buf_map(xfs_buf_flags_t flags, struct xfs_buf **bpp) { - xfs_buf_t *bp; + struct xfs_buf *bp;struct xfs_buf_log_item *bip;int error;
@@ -401,7 +401,7 @@ xfs_trans_brelse(void xfs_trans_bhold (xfs_trans_t *tp, -xfs_buf_t *bp) +struct xfs_buf *bp) {struct xfs_buf_log_item *bip = bp->b_log_item;
@@ -422,7 +422,7 @@ xfs_trans_bhold(void xfs_trans_bhold_release (xfs_trans_t *tp, -xfs_buf_t *bp) +struct xfs_buf *bp) {struct xfs_buf_log_item *bip = bp->b_log_item;
@@ -538,7 +538,7 @@ xfs_trans_log_buf(void xfs_trans_binval (xfs_trans_t *tp, -xfs_buf_t *bp) +struct xfs_buf *bp) {struct xfs_buf_log_item *bip = bp->b_log_item;int i;
@@ -593,7 +593,7 @@ xfs_trans_binval(void xfs_trans_inode_buf (xfs_trans_t *tp, -xfs_buf_t *bp) +struct xfs_buf *bp) {struct xfs_buf_log_item *bip = bp->b_log_item;
@@ -618,7 +618,7 @@ xfs_trans_inode_buf(void xfs_trans_stale_inode_buf (xfs_trans_t *tp, -xfs_buf_t *bp) +struct xfs_buf *bp) {struct xfs_buf_log_item *bip = bp->b_log_item;
@@ -643,7 +643,7 @@ xfs_trans_stale_inode_buf(void xfs_trans_inode_alloc_buf (xfs_trans_t *tp, -xfs_buf_t *bp) +struct xfs_buf *bp) {struct xfs_buf_log_item *bip = bp->b_log_item;
@@ -737,7 +737,7 @@ xfs_trans_buf_copy_type(void xfs_trans_dquot_buf (xfs_trans_t *tp, -xfs_buf_t *bp, +struct xfs_buf *bp,uint type) {struct xfs_buf_log_item *bip = bp->b_log_item;
Signature · 1 line
2.53.0
PATCH RESEND v2 12/19 xfs: fix super block buf log item UAF during force shutdown
In reply to Siddh Raman PantFrom: Guo Xuenan <[email protected]>
[ Upstream commit 575689fc0ffa6c4bb4e72fd18e31a6525a6124e0 ]
xfs log io error will trigger xlog shut down, and end_io worker call xlog_state_shutdown_callbacks to unpin and release the buf log item. The race condition is that when there are some thread doing transaction commit and happened not to be intercepted by xlog_is_shutdown, then, these log item will be insert into CIL, when unpin and release these buf log item, UAF will occur. BTW, add delay before xlog_cil_commit can increase recurrence probability.
The following call graph actually encountered this bad situation.
fsstress io end worker kworker/0:1H-216
xlog_ioend_work
->xlog_force_shutdown
->xlog_state_shutdown_callbacks
->xlog_cil_process_committed
->xlog_cil_committed
->xfs_trans_committed_bulk
->xfs_trans_apply_sb_deltas ->li_ops->iop_unpin(lip, 1);
->xfs_trans_getsb
->_xfs_trans_bjoin
->xfs_buf_item_init
->if (bip) { return 0;} //relog
->xlog_cil_commit
->xlog_cil_insert_items //insert into CIL
->xfs_buf_ioend_fail(bp);
->xfs_buf_ioend
->xfs_buf_item_done
->xfs_buf_item_relse
->xfs_buf_item_freewhen cil push worker gather percpu cil and insert super block buf log item into ctx->log_items then uaf occurs.
==================================================================
BUG: KASAN: use-after-free in xlog_cil_push_work+0x1c8f/0x22f0 Write of size 8 at addr ffff88801800f3f0 by task kworker/u4:4/105 CPU: 0 PID: 105 Comm: kworker/u4:4 Tainted: G W 6.1.0-rc1-00001-g274115149b42 #136 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Workqueue: xfs-cil/sda xlog_cil_push_work Call Trace: <TASK> dump_stack_lvl+0x4d/0x66 print_report+0x171/0x4a6 kasan_report+0xb3/0x130 xlog_cil_push_work+0x1c8f/0x22f0 process_one_work+0x6f9/0xf70 worker_thread+0x578/0xf30 kthread+0x28c/0x330 ret_from_fork+0x1f/0x30 </TASK> Allocated by task 2145: kasan_save_stack+0x1e/0x40 kasan_set_track+0x21/0x30 __kasan_slab_alloc+0x54/0x60 kmem_cache_alloc+0x14a/0x510 xfs_buf_item_init+0x160/0x6d0 _xfs_trans_bjoin+0x7f/0x2e0 xfs_trans_getsb+0xb6/0x3f0 xfs_trans_apply_sb_deltas+0x1f/0x8c0 __xfs_trans_commit+0xa25/0xe10 xfs_symlink+0xe23/0x1660 xfs_vn_symlink+0x157/0x280 vfs_symlink+0x491/0x790 do_symlinkat+0x128/0x220 __x64_sys_symlink+0x7a/0x90 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd Freed by task 216: kasan_save_stack+0x1e/0x40 kasan_set_track+0x21/0x30 kasan_save_free_info+0x2a/0x40 __kasan_slab_free+0x105/0x1a0 kmem_cache_free+0xb6/0x460 xfs_buf_ioend+0x1e9/0x11f0 xfs_buf_item_unpin+0x3d6/0x840 xfs_trans_committed_bulk+0x4c2/0x7c0 xlog_cil_committed+0xab6/0xfb0 xlog_cil_process_committed+0x117/0x1e0 xlog_state_shutdown_callbacks+0x208/0x440 xlog_force_shutdown+0x1b3/0x3a0 xlog_ioend_work+0xef/0x1d0 process_one_work+0x6f9/0xf70 worker_thread+0x578/0xf30 kthread+0x28c/0x330 ret_from_fork+0x1f/0x30 The buggy address belongs to the object at ffff88801800f388 which belongs to the cache xfs_buf_item of size 272
The buggy address is located 104 bytes inside of
272-byte region [ffff88801800f388, ffff88801800f498)
The buggy address belongs to the physical page:
page:ffffea0000600380 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff88801800f208 pfn:0x1800e
head:ffffea0000600380 order:1 compound_mapcount:0 compound_pincount:0
flags: 0x1fffff80010200(slab|head|node=0|zone=1|lastcpupid=0x1fffff)
raw: 001fffff80010200 ffffea0000699788 ffff88801319db50 ffff88800fb50640
raw: ffff88801800f208 000000000015000a 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88801800f280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88801800f300: fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88801800f380: fc fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88801800f400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88801800f480: fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================Disabling lock debugging due to kernel taint
Stable-dep-of: d2fe5c4c8d25 ("xfs: rearrange code in xfs_buf_item.c")
--- fs/xfs/xfs_buf_item.c | 2 ++ 1 file changed, 2 insertions(+)
fs/xfs/xfs_buf_item.c +2 -0
@@ -938,6 +938,8 @@ xfs_buf_item_relse(trace_xfs_buf_item_relse (bp, _RET_IP_);ASSERT (!test_bit (XFS_LI_IN_AIL , &bip->bli_item.li_flags)); +if (atomic_read (&bip->bli_refcount)) +return ; bp->b_log_item =NULL ;xfs_buf_rele (bp);xfs_buf_item_free (bip);
Signature · 1 line
2.53.0
PATCH RESEND v2 13/19 xfs: fix intermittent hang during quotacheck
In reply to Siddh Raman PantFrom: "Darrick J. Wong" <[email protected]>
[ Upstream commit f0c2d7d2abca24d19831c99edea458704fac8087 ]
Every now and then, I see the following hang during mount time quotacheck when running fstests. Turning on KASAN seems to make it happen somewhat more frequently. I've edited the backtrace for brevity.
XFS (sdd): Quotacheck needed: Please wait.
XFS: Assertion failed: bp->b_flags & _XBF_DELWRI_Q, file: fs/xfs/xfs_buf.c, line: 2411
------------[ cut here ]------------ WARNING: CPU: 0 PID: 1831409 at fs/xfs/xfs_message.c:104 assfail+0x46/0x4a [xfs] CPU: 0 PID: 1831409 Comm: mount Tainted: G W 5.19.0-rc6-xfsx #rc6 09911566947b9f737b036b4af85e399e4b9aef64 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 RIP: 0010:assfail+0x46/0x4a [xfs] Code: a0 8f 41 a0 e8 45 fe ff ff 8a 1d 2c 36 10 00 80 fb 01 76 0f 0f b6 f3 48 c7 c7 c0 f0 4f a0 e8 10 f0 02 e1 80 e3 01 74 02 0f 0b <0f> 0b 5b c3 48 8d 45 10 48 89 e2 4c 89 e6 48 89 1c 24 48 89 44 24 RSP: 0018:ffffc900078c7b30 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff8880099ac000 RCX: 000000007fffffff RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffffa0418fa0 RBP: ffff8880197bc1c0 R08: 0000000000000000 R09: 000000000000000a R10: 000000000000000a R11: f000000000000000 R12: ffffc900078c7d20 R13: 00000000fffffff5 R14: ffffc900078c7d20 R15: 0000000000000000 FS: 00007f0449903800(0000) GS:ffff88803ec00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00005610ada631f0 CR3: 0000000014dd8002 CR4: 00000000001706f0 Call Trace: <TASK> xfs_buf_delwri_pushbuf+0x150/0x160 [xfs 4561f5b32c9bfb874ec98d58d0719464e1f87368] xfs_qm_flush_one+0xd6/0x130 [xfs 4561f5b32c9bfb874ec98d58d0719464e1f87368] xfs_qm_dquot_walk.isra.0+0x109/0x1e0 [xfs 4561f5b32c9bfb874ec98d58d0719464e1f87368] xfs_qm_quotacheck+0x319/0x490 [xfs 4561f5b32c9bfb874ec98d58d0719464e1f87368] xfs_qm_mount_quotas+0x65/0x2c0 [xfs 4561f5b32c9bfb874ec98d58d0719464e1f87368] xfs_mountfs+0x6b5/0xab0 [xfs 4561f5b32c9bfb874ec98d58d0719464e1f87368] xfs_fs_fill_super+0x781/0x990 [xfs 4561f5b32c9bfb874ec98d58d0719464e1f87368] get_tree_bdev+0x175/0x280 vfs_get_tree+0x1a/0x80 path_mount+0x6f5/0xaa0 __x64_sys_mount+0x103/0x140 do_syscall_64+0x2b/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0
I /think/ this can happen if xfs_qm_flush_one is racing with xfs_qm_dquot_isolate (i.e. dquot reclaim) when the second function has taken the dquot flush lock but xfs_qm_dqflush hasn't yet locked the dquot buffer, let alone queued it to the delwri list. In this case, flush_one will fail to get the dquot flush lock, but it can lock the incore buffer, but xfs_buf_delwri_pushbuf will then trip over this ASSERT, which checks that the buffer isn't on a delwri list. The hang results because the _delwri_submit_buffers ignores non DELWRI_Q buffers, which means that xfs_buf_iowait waits forever for an IO that has not yet been scheduled.
AFAICT, a reasonable solution here is to detect a dquot buffer that is not on a DELWRI list, drop it, and return -EAGAIN to try the flush again. It's not /that/ big of a deal if quotacheck writes the dquot buffer repeatedly before we even set QUOTA_CHKD.
Stable-dep-of: d62016b1a2df ("xfs: avoid dquot buffer pin deadlock")
--- fs/xfs/xfs_qm.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/xfs/xfs_qm.c +7 -0
@@ -1245,6 +1245,13 @@ xfs_qm_flush_one( error = -EINVAL ; goto out_unlock; } + +if (!(bp->b_flags & _XBF_DELWRI_Q)) { + error = -EAGAIN ; +xfs_buf_relse (bp); + goto out_unlock; + } +xfs_buf_unlock (bp);xfs_buf_delwri_pushbuf (bp, buffer_list);
Signature · 1 line
2.53.0
PATCH RESEND v2 14/19 xfs: buffer pins need to hold a buffer reference
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
[ Upstream commit 89a4bf0dc3857569a77061d3d5ea2ac85f7e13c6 ]
When a buffer is unpinned by xfs_buf_item_unpin(), we need to access the buffer after we've dropped the buffer log item reference count. This opens a window where we can have two racing unpins for the buffer item (e.g. shutdown checkpoint context callback processing racing with journal IO iclog completion processing) and both attempt to access the buffer after dropping the BLI reference count. If we are unlucky, the "BLI freed" context wins the race and frees the buffer before the "BLI still active" case checks the buffer pin count.
This results in a use after free that can only be triggered in active filesystem shutdown situations.
To fix this, we need to ensure that buffer existence extends beyond the BLI reference count checks and until the unpin processing is complete. This implies that a buffer pin operation must also take a buffer reference to ensure that the buffer cannot be freed until the buffer unpin processing is complete.
Stable-dep-of: 816c330b605c ("xfs: factor out stale buffer item completion")
--- fs/xfs/xfs_buf_item.c | 88 ++++++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 23 deletions(-)
fs/xfs/xfs_buf_item.c +65 -23
@@ -371,10 +371,18 @@ xfs_buf_item_format(* This is called to pin the buffer associated with the buf log item in memory * so it cannot be written out. * -* We also always take a reference to the buffer log item here so that the bli -* is held while the item is pinned in memory. This means that we can -* unconditionally drop the reference count a transaction holds when the -* transaction is completed. +* We take a reference to the buffer log item here so that the BLI life cycle +* extends at least until the buffer is unpinned via xfs_buf_item_unpin() and +* inserted into the AIL. +* +* We also need to take a reference to the buffer itself as the BLI unpin +* processing requires accessing the buffer after the BLI has dropped the final +* BLI reference. See xfs_buf_item_unpin() for an explanation. +* If unpins race to drop the final BLI reference and only the +* BLI owns a reference to the buffer, then the loser of the race can have the +* buffer fgreed from under it (e.g. on shutdown). Taking a buffer reference per +* pin count ensures the life cycle of the buffer extends for as +* long as we hold the buffer pin reference in xfs_buf_item_unpin(). */ STATIC void xfs_buf_item_pin(
@@ -389,13 +397,30 @@ xfs_buf_item_pin(trace_xfs_buf_item_pin (bip); +xfs_buf_hold (bip->bli_buf);atomic_inc (&bip->bli_refcount);atomic_inc (&bip->bli_buf->b_pin_count); }/* -* This is called to unpin the buffer associated with the buf log item which -* was previously pinned with a call to xfs_buf_item_pin(). +* This is called to unpin the buffer associated with the buf log item which was +* previously pinned with a call to xfs_buf_item_pin(). We enter this function +* with a buffer pin count, a buffer reference and a BLI reference. +* +* We must drop the BLI reference before we unpin the buffer because the AIL +* doesn't acquire a BLI reference whenever it accesses it. Therefore if the +* refcount drops to zero, the bli could still be AIL resident and the buffer +* submitted for I/O at any point before we return. This can result in IO +* completion freeing the buffer while we are still trying to access it here. +* This race condition can also occur in shutdown situations where we abort and +* unpin buffers from contexts other that journal IO completion. +* +* Hence we have to hold a buffer reference per pin count to ensure that the +* buffer cannot be freed until we have finished processing the unpin operation. +* The reference is taken in xfs_buf_item_pin(), and we must hold it until we +* are done processing the buffer state. In the case of an abort (remove = +* true) then we re-use the current pin reference as the IO reference we hand +* off to IO failure handling. */ STATIC void xfs_buf_item_unpin(
@@ -412,24 +437,18 @@ xfs_buf_item_unpin(trace_xfs_buf_item_unpin (bip); -/* -* Drop the bli ref associated with the pin and grab the hold required -* for the I/O simulation failure in the abort case. We have to do this -* before the pin count drops because the AIL doesn't acquire a bli -* reference. Therefore if the refcount drops to zero, the bli could -* still be AIL resident and the buffer submitted for I/O (and freed on -* completion) at any point before we return. This can be removed once -* the AIL properly holds a reference on the bli. -*/ freed =atomic_dec_and_test (&bip->bli_refcount); -if (freed && !stale && remove) -xfs_buf_hold (bp);if (atomic_dec_and_test (&bp->b_pin_count))wake_up_all (&bp->b_waiters); -/* nothing to do but drop the pin count if the bli is active */ -if (!freed) +/* +* Nothing to do but drop the buffer pin reference if the BLI is +* still active. +*/ +if (!freed) { +xfs_buf_rele (bp);return ; + }if (stale) {ASSERT (bip->bli_flags &XFS_BLI_STALE );
@@ -441,6 +460,15 @@ xfs_buf_item_unpin(trace_xfs_buf_item_unpin_stale (bip); +/* +* The buffer has been locked and referenced since it was marked +* stale so we own both lock and reference exclusively here. We +* do not need the pin reference any more, so drop it now so +* that we only have one reference to drop once item completion +* processing is complete. +*/ +xfs_buf_rele (bp); +/* * If we get called here because of an IO error, we may or may * not have the item on the AIL. xfs_trans_ail_delete() will
@@ -457,16 +485,30 @@ xfs_buf_item_unpin(ASSERT (bp->b_log_item ==NULL ); }xfs_buf_relse (bp); - }else if (remove) { +return ; + } + +if (remove) {/* -* The buffer must be locked and held by the caller to simulate -* an async I/O failure. We acquired the hold for this case -* before the buffer was unpinned. +* We need to simulate an async IO failures here to ensure that +* the correct error completion is run on this buffer. This +* requires a reference to the buffer and for the buffer to be +* locked. We can safely pass ownership of the pin reference to +* the IO to ensure that nothing can free the buffer while we +* wait for the lock and then run the IO failure completion. */ xfs_buf_lock (bp); bp->b_flags |=XBF_ASYNC ;xfs_buf_ioend_fail (bp); +return ; } + +/* +* BLI has no more active references - it will be moved to the AIL to +* manage the remaining BLI/buffer life cycle. There is nothing left for +* us to do here so drop the pin reference to the buffer. +*/ +xfs_buf_rele (bp); }STATIC uint
Signature · 1 line
2.53.0
PATCH RESEND v2 15/19 xfs: xfs_ifree_cluster vs xfs_iflush_shutdown_abort deadlock
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
Lock order of xfs_ifree_cluster() is cluster buffer -> try ILOCK -> IFLUSHING, except for the last inode in the cluster that is triggering the free. In that case, the lock order is ILOCK -> cluster buffer -> IFLUSHING.
xfs_iflush_cluster() uses cluster buffer -> try ILOCK -> IFLUSHING, so this can safely run concurrently with xfs_ifree_cluster().
xfs_inode_item_precommit() uses ILOCK -> cluster buffer, but this cannot race with xfs_ifree_cluster() so being in a different order will not trigger a deadlock.
xfs_reclaim_inode() during a filesystem shutdown uses ILOCK -> IFLUSHING -> cluster buffer via xfs_iflush_shutdown_abort(), and this deadlocks against xfs_ifree_cluster() like so:
sysrq: Show Blocked State
task:kworker/10:37 state:D stack:12560 pid:276182 tgid:276182 ppid:2 flags:0x00004000
Workqueue: xfs-inodegc/dm-3 xfs_inodegc_worker Call Trace: <TASK> __schedule+0x650/0xb10 schedule+0x6d/0xf0 schedule_timeout+0x8b/0x180 schedule_timeout_uninterruptible+0x1e/0x30 xfs_ifree+0x326/0x730 xfs_inactive_ifree+0xcb/0x230 xfs_inactive+0x2c8/0x380 xfs_inodegc_worker+0xaa/0x180 process_scheduled_works+0x1d4/0x400 worker_thread+0x234/0x2e0 kthread+0x147/0x170 ret_from_fork+0x3e/0x50 ret_from_fork_asm+0x1a/0x30 </TASK> task:fsync-tester state:D stack:12160 pid:2255943 tgid:2255943 ppid:3988702 flags:0x00004006 Call Trace: <TASK> __schedule+0x650/0xb10 schedule+0x6d/0xf0 schedule_timeout+0x31/0x180 __down_common+0xbe/0x1f0 __down+0x1d/0x30 down+0x48/0x50 xfs_buf_lock+0x3d/0xe0 xfs_iflush_shutdown_abort+0x51/0x1e0 xfs_icwalk_ag+0x386/0x690 xfs_reclaim_inodes_nr+0x114/0x160 xfs_fs_free_cached_objects+0x19/0x20 super_cache_scan+0x17b/0x1a0 do_shrink_slab+0x180/0x350 shrink_slab+0xf8/0x430 drop_slab+0x97/0xf0 drop_caches_sysctl_handler+0x59/0xc0 proc_sys_call_handler+0x189/0x280 proc_sys_write+0x13/0x20 vfs_write+0x33d/0x3f0 ksys_write+0x7c/0xf0 __x64_sys_write+0x1b/0x30 x64_sys_call+0x271d/0x2ee0 do_syscall_64+0x68/0x130 entry_SYSCALL_64_after_hwframe+0x76/0x7e
We can't change the lock order of xfs_ifree_cluster() - XFS_ISTALE and XFS_IFLUSHING are serialised through to journal IO completion by the cluster buffer lock being held.
There's quite a few asserts in the code that check that XFS_ISTALE does not occur out of sync with buffer locking (e.g. in xfs_iflush_cluster). There's also a dependency on the inode log item being removed from the buffer before XFS_IFLUSHING is cleared, also with asserts that trigger on this.
Further, we don't have a requirement for the inode to be locked when completing or aborting inode flushing because all the inode state updates are serialised by holding the cluster buffer lock across the IO to completion.
We can't check for XFS_IRECLAIM in xfs_ifree_mark_inode_stale() and skip the inode, because there is no guarantee that the inode will be reclaimed. Hence it *must* be marked XFS_ISTALE regardless of whether reclaim is preparing to free that inode. Similarly, we can't check for IFLUSHING before locking the inode because that would result in dirty inodes not being marked with ISTALE in the event of racing with XFS_IRECLAIM.
Hence we have to address this issue from the xfs_reclaim_inode() side. It is clear that we cannot hold the inode locked here when calling xfs_iflush_shutdown_abort() because it is the inode->buffer lock order that causes the deadlock against xfs_ifree_cluster().
Hence we need to drop the ILOCK before aborting the inode in the shutdown case. Once we've aborted the inode, we can grab the ILOCK again and then immediately reclaim it as it is now guaranteed to be clean.
Note that dropping the ILOCK in xfs_reclaim_inode() means that it can now be locked by xfs_ifree_mark_inode_stale() and seen whilst in this state. This is safe because we have left the XFS_IFLUSHING flag on the inode and so xfs_ifree_mark_inode_stale() will simply set XFS_ISTALE and move to the next inode. An ASSERT check in this path needs to be tweaked to take into account this new shutdown interaction.
5.10: Add header.
--- fs/xfs/xfs_icache.c | 8 ++++++++ fs/xfs/xfs_inode.c | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-)
fs/xfs/xfs_icache.c +8 -0
@@ -1040,7 +1040,15 @@ xfs_reclaim_inode(if (XFS_FORCED_SHUTDOWN (ip->i_mount)) {xfs_iunpin_wait (ip); +/* +* Avoid a ABBA deadlock on the inode cluster buffer vs +* concurrent xfs_ifree_cluster() trying to mark the inode +* stale. We don't need the inode locked to run the flush abort +* code, but the flush abort needs to lock the cluster buffer. +*/ +xfs_iunlock (ip,XFS_ILOCK_EXCL );xfs_iflush_shutdown_abort (ip); +xfs_ilock (ip,XFS_ILOCK_EXCL ); goto reclaim; }if (xfs_ipincount (ip))
fs/xfs/xfs_inode.c +2 -1
@@ -33,6 +33,7 @@#include "xfs_symlink.h" #include "xfs_trans_priv.h" #include "xfs_log.h" +#include "xfs_log_priv.h" #include "xfs_bmap_btree.h" #include "xfs_reflink.h"
@@ -2553,7 +2554,7 @@ xfs_ifree_mark_inode_stale( iip = ip->i_itemp;if (__xfs_iflags_test (ip,XFS_IFLUSHING )) {ASSERT (!list_empty (&iip->ili_item.li_bio_list)); -ASSERT (iip->ili_last_fields); +ASSERT (iip->ili_last_fields ||xlog_is_shutdown (mp->m_log)); goto out_iunlock; }
Signature · 1 line
2.53.0
PATCH RESEND v2 16/19 xfs: catch stale AGF/AGF metadata
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
There is a race condition that can trigger in dmflakey fstests that can result in asserts in xfs_ialloc_read_agi() and xfs_alloc_read_agf() firing. The asserts look like this:
XFS: Assertion failed: pag->pagf_freeblks == be32_to_cpu(agf->agf_freeblks), file: fs/xfs/libxfs/xfs_alloc.c, line: 3440
.....
Call Trace: <TASK> xfs_alloc_read_agf+0x2ad/0x3a0 xfs_alloc_fix_freelist+0x280/0x720 xfs_alloc_vextent_prepare_ag+0x42/0x120 xfs_alloc_vextent_iterate_ags+0x67/0x260 xfs_alloc_vextent_start_ag+0xe4/0x1c0 xfs_bmapi_allocate+0x6fe/0xc90 xfs_bmapi_convert_delalloc+0x338/0x560 xfs_map_blocks+0x354/0x580 iomap_writepages+0x52b/0xa70 xfs_vm_writepages+0xd7/0x100 do_writepages+0xe1/0x2c0 __writeback_single_inode+0x44/0x340 writeback_sb_inodes+0x2d0/0x570 __writeback_inodes_wb+0x9c/0xf0 wb_writeback+0x139/0x2d0 wb_workfn+0x23e/0x4c0 process_scheduled_works+0x1d4/0x400 worker_thread+0x234/0x2e0 kthread+0x147/0x170 ret_from_fork+0x3e/0x50 ret_from_fork_asm+0x1a/0x30
I've seen the AGI variant from scrub running on the filesysetm after unmount failed due to systemd interference:
XFS: Assertion failed: pag->pagi_freecount == be32_to_cpu(agi->agi_freecount) || xfs_is_shutdown(pag->pag_mount), file: fs/xfs/libxfs/xfs_ialloc.c, line: 2804
.....
Call Trace: <TASK> xfs_ialloc_read_agi+0xee/0x150 xchk_perag_drain_and_lock+0x7d/0x240 xchk_ag_init+0x34/0x90 xchk_inode_xref+0x7b/0x220 xchk_inode+0x14d/0x180 xfs_scrub_metadata+0x2e2/0x510 xfs_ioc_scrub_metadata+0x62/0xb0 xfs_file_ioctl+0x446/0xbf0 __se_sys_ioctl+0x6f/0xc0 __x64_sys_ioctl+0x1d/0x30 x64_sys_call+0x1879/0x2ee0 do_syscall_64+0x68/0x130 ? exc_page_fault+0x62/0xc0 entry_SYSCALL_64_after_hwframe+0x76/0x7e
Essentially, it is the same problem. When _flakey_drop_and_remount() loads the drop-writes table, it makes all writes silently fail. Writes are reported to the fs as completed successfully, but they are not issued to the backing store. The filesystem sees the successful write completion and marks the metadata buffer clean and removes it from the AIL.
If this happens at the same time as memory pressure is occuring, the now-clean AGF and/or AGI buffers can be reclaimed from memory.
Shortly afterwards, but before _flakey_drop_and_remount() runs unmount, background writeback is kicked and it tries to allocate blocks for the dirty pages in memory. This then tries to access the AGF buffer we just turfed out of memory. It's not found, so it gets read in from disk.
This is all fine, except for the fact that the last writeback of the AGF did not actually reach disk. The AGF on disk is stale compared to the in-memory state held by the perag, and so they don't match and the assert fires.
Then other operations on that inode hang because the task was killed whilst holding inode locks. e.g:
Workqueue: xfs-conv/dm-12 xfs_end_io Call Trace: <TASK> __schedule+0x650/0xb10 schedule+0x6d/0xf0 schedule_preempt_disabled+0x15/0x30 rwsem_down_write_slowpath+0x31a/0x5f0 down_write+0x43/0x60 xfs_ilock+0x1a8/0x210 xfs_trans_alloc_inode+0x9c/0x240 xfs_iomap_write_unwritten+0xe3/0x300 xfs_end_ioend+0x90/0x130 xfs_end_io+0xce/0x100 process_scheduled_works+0x1d4/0x400 worker_thread+0x234/0x2e0 kthread+0x147/0x170 ret_from_fork+0x3e/0x50 ret_from_fork_asm+0x1a/0x30 </TASK>
and it's all down hill from there.
Memory pressure is one way to trigger this, another is to run "echo 3 > /proc/sys/vm/drop_caches" randomly while tests are running.
Regardless of how it is triggered, this effectively takes down the system once umount hangs because it's holding a sb->s_umount lock exclusive and now every sync(1) call gets stuck on it.
Fix this by replacing the asserts with a corruption detection check and a shutdown.
6.12:
Fixed conflict due to the following missing commit:
e9c4d8bfb26c ("xfs: factor out a generic xfs_group structure")
6.6:
Fixed conflict due to the following missing commit:
e45ea3645178 ("xfs: split the agf_roots and agf_levels arrays")5.15:
Fixed conflict due to the following missing commits:
6f643c57d57c ("xfs: implement ->notify_failure() for XFS")
[Continuous range: a95fee40e3d4^..08d3e84feeb8]
08d3e84feeb8 ("xfs: pass perag to xfs_alloc_read_agf()")
76b47e528e3a ("xfs: kill xfs_alloc_pagf_init()")
99b13c7f0bd3 ("xfs: pass perag to xfs_ialloc_read_agi()")
a95fee40e3d4 ("xfs: kill xfs_ialloc_pagi_init()")5.10:
Fixed conflicts due to the following missing commits:
fs/xfs/libxfs/xfs_alloc.c, fs/xfs/libxfs/xfs_ialloc.c:
75c8c50fa16a ("xfs: replace XFS_FORCED_SHUTDOWN with xfs_is_shutdown")
fs/xfs/libxfs/xfs_ialloc.c:
9bbafc71919a ("xfs: move xfs_perag_get/put to xfs_ag.[ch]")--- fs/xfs/libxfs/xfs_alloc.c | 45 +++++++++++++++++++++++++++++--------- fs/xfs/libxfs/xfs_ialloc.c | 34 +++++++++++++++++++++++----- 2 files changed, 64 insertions(+), 15 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +35 -10
@@ -26,6 +26,7 @@#include "xfs_log.h" #include "xfs_ag_resv.h" #include "xfs_bmap.h" +#include "xfs_health.h" extern kmem_zone_t *xfs_bmap_free_item_zone;
@@ -3017,18 +3018,42 @@ xfs_alloc_read_agf( pag->pagf_init =1 ; pag->pagf_agflreset =xfs_agfl_needs_reset (mp, agf); } +#ifdef DEBUG - else if (!XFS_FORCED_SHUTDOWN(mp)) { -ASSERT (pag->pagf_freeblks ==be32_to_cpu (agf->agf_freeblks)); -ASSERT (pag->pagf_btreeblks ==be32_to_cpu (agf->agf_btreeblks)); -ASSERT (pag->pagf_flcount ==be32_to_cpu (agf->agf_flcount)); -ASSERT (pag->pagf_longest ==be32_to_cpu (agf->agf_longest)); -ASSERT (pag->pagf_levels[XFS_BTNUM_BNOi] == -be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNOi])); -ASSERT (pag->pagf_levels[XFS_BTNUM_CNTi] == -be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNTi])); +/* +* It's possible for the AGF to be out of sync if the block device is +* silently dropping writes. This can happen in fstests with dmflakey +* enabled, which allows the buffer to be cleaned and reclaimed by +* memory pressure and then re-read from disk here. We will get a +* stale version of the AGF from disk, and nothing good can happen from +* here. Hence if we detect this situation, immediately shut down the +* filesystem. +* +* This can also happen if we are already in the middle of a forced +* shutdown, so don't bother checking if we are already shut down. +*/ +if (!XFS_FORCED_SHUTDOWN (mp)) { +bool ok = true; + + ok &= pag->pagf_freeblks ==be32_to_cpu (agf->agf_freeblks); + ok &= pag->pagf_freeblks ==be32_to_cpu (agf->agf_freeblks); + ok &= pag->pagf_btreeblks ==be32_to_cpu (agf->agf_btreeblks); + ok &= pag->pagf_flcount ==be32_to_cpu (agf->agf_flcount); + ok &= pag->pagf_longest ==be32_to_cpu (agf->agf_longest); + ok &= pag->pagf_levels[XFS_BTNUM_BNOi] == +be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNOi]); + ok &= pag->pagf_levels[XFS_BTNUM_CNTi] == +be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNTi]); + +if (XFS_IS_CORRUPT (mp, !ok)) { +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGF ); +xfs_trans_brelse (tp, *bpp); + *bpp =NULL ; +xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE ); +return -EFSCORRUPTED ; + } } -#endif +#endif /* DEBUG */ return 0 ; }
fs/xfs/libxfs/xfs_ialloc.c +29 -5
@@ -27,6 +27,7 @@#include "xfs_trace.h" #include "xfs_log.h" #include "xfs_rmap.h" +#include "xfs_health.h" /* * Lookup a record by ino in the btree given by cur.
@@ -2034,7 +2035,7 @@ xfs_difree_inobt( goto error0; } -/* +/* * Change the inode free counts and log the ag/sb changes. */ be32_add_cpu (&agi->agi_freecount,1 );
@@ -2657,12 +2658,35 @@ xfs_ialloc_read_agi( pag->pagi_init =1 ; } +#ifdef DEBUG /* -* It's possible for these to be out of sync if -* we are in the middle of a forced shutdown. +* It's possible for the AGF to be out of sync if the block device is +* silently dropping writes. This can happen in fstests with dmflakey +* enabled, which allows the buffer to be cleaned and reclaimed by +* memory pressure and then re-read from disk here. We will get a +* stale version of the AGF from disk, and nothing good can happen from +* here. Hence if we detect this situation, immediately shut down the +* filesystem. +* +* This can also happen if we are already in the middle of a forced +* shutdown, so don't bother checking if we are already shut down. */ -ASSERT (pag->pagi_freecount ==be32_to_cpu (agi->agi_freecount) || -XFS_FORCED_SHUTDOWN (mp)); +if (!XFS_FORCED_SHUTDOWN (mp)) { +bool ok = true; + + ok &= pag->pagi_freecount ==be32_to_cpu (agi->agi_freecount); + ok &= pag->pagi_count ==be32_to_cpu (agi->agi_count); + +if (XFS_IS_CORRUPT (mp, !ok)) { +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGI ); +xfs_trans_brelse (tp, *bpp); + *bpp =NULL ; +xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE ); +return -EFSCORRUPTED ; + } + } +#endif /* DEBUG */ +return 0 ; }
Signature · 1 line
2.53.0
PATCH RESEND v2 17/19 xfs: rearrange code in xfs_buf_item.c
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
The code to initialise, release and free items is all the way down the bottom of the file. Upcoming fixes need to these functions earlier in the file, so move them to the top.
There is one code change in this move - the parameter to xfs_buf_item_relse() is changed from the xfs_buf to the xfs_buf_log_item - the thing that the function is releasing.
6.6:
Fixed conflict due to the following missing commits:
[Continuous range: 10634530f7ba^..d4c75a1b40cd]
d4c75a1b40cd ("xfs: convert remaining kmem_free() to kfree()")
49292576136f ("xfs: convert kmem_free() for kvmalloc users to kvfree()")
afdc115559c5 ("xfs: move kmem_to_page()")
f078d4ea8276 ("xfs: convert kmem_alloc() to kmalloc()")
10634530f7ba ("xfs: convert kmem_zalloc() to kzalloc()")Removed ASSERT in favour of existing atomic_read-and-return in xfs_buf_item_relse() due to the following missing commit:
3762113b597f ("xfs: don't lose solo superblock counter update transactions")
5.15:
Fixed conflict due to the following missing commit:
182696fb021f ("xfs: rename _zone variables to _cache")--- fs/xfs/xfs_buf_item.c | 118 +++++++++++++++++++++--------------------- fs/xfs/xfs_buf_item.h | 1 - 2 files changed, 60 insertions(+), 59 deletions(-)
fs/xfs/xfs_buf_item.c +60 -58
@@ -31,6 +31,63 @@ static inline struct xfs_buf_log_item *BUF_ITEM(struct xfs_log_item *lip) return container_of(lip, struct xfs_buf_log_item, bli_item); } +static void +xfs_buf_item_get_format ( +struct xfs_buf_log_item *bip, +int count) +{ +ASSERT (bip->bli_formats ==NULL ); + bip->bli_format_count = count; + +if (count ==1 ) { + bip->bli_formats = &bip->__bli_format; +return ; + } + + bip->bli_formats =kmem_zalloc (count *sizeof (struct xfs_buf_log_format ), +0 ); +} + +static void +xfs_buf_item_free_format ( +struct xfs_buf_log_item *bip) +{ +if (bip->bli_formats != &bip->__bli_format) { +kmem_free (bip->bli_formats); + bip->bli_formats =NULL ; + } +} + +static void +xfs_buf_item_free ( +struct xfs_buf_log_item *bip) +{ +xfs_buf_item_free_format (bip); +kmem_free (bip->bli_item.li_lv_shadow); +kmem_cache_free (xfs_buf_item_zone, bip); +} + +/* +* xfs_buf_item_relse() is called when the buf log item is no longer needed. +*/ +static void +xfs_buf_item_relse ( +struct xfs_buf_log_item *bip) +{ +struct xfs_buf *bp = bip->bli_buf; + +trace_xfs_buf_item_relse (bp, _RET_IP_); + +ASSERT (!test_bit (XFS_LI_IN_AIL , &bip->bli_item.li_flags)); + +if (atomic_read (&bip->bli_refcount)) +return ; + + bp->b_log_item =NULL ; +xfs_buf_rele (bp); +xfs_buf_item_free (bip); +} +/* Is this log iovec plausibly large enough to contain the buffer log format? */ bool xfs_buf_log_check_iovec(
@@ -481,7 +538,7 @@ xfs_buf_item_unpin(ASSERT (list_empty (&bp->b_li_list)); }else {xfs_trans_ail_delete (lip,SHUTDOWN_LOG_IO_ERROR ); -xfs_buf_item_relse (bp); +xfs_buf_item_relse (bip);ASSERT (bp->b_log_item ==NULL ); }xfs_buf_relse (bp);
@@ -591,7 +648,7 @@ xfs_buf_item_put(*/ if (aborted)xfs_trans_ail_delete (lip,0 ); -xfs_buf_item_relse (bip->bli_buf); +xfs_buf_item_relse (bip);return true; }
@@ -711,33 +768,6 @@ static const struct xfs_item_ops xfs_buf_item_ops = { .iop_push = xfs_buf_item_push, }; -STATIC void -xfs_buf_item_get_format ( -struct xfs_buf_log_item *bip, -int count) -{ -ASSERT (bip->bli_formats ==NULL ); - bip->bli_format_count = count; - -if (count ==1 ) { - bip->bli_formats = &bip->__bli_format; -return ; - } - - bip->bli_formats =kmem_zalloc (count *sizeof (struct xfs_buf_log_format ), -0 ); -} - -STATIC void -xfs_buf_item_free_format ( -struct xfs_buf_log_item *bip) -{ -if (bip->bli_formats != &bip->__bli_format) { -kmem_free (bip->bli_formats); - bip->bli_formats =NULL ; - } -} -/* * Allocate a new buf log item to go with the given buffer. * Set the buffer's b_log_item field to point to the new
@@ -959,34 +989,6 @@ xfs_buf_item_dirty_format(return false; } -STATIC void -xfs_buf_item_free ( -struct xfs_buf_log_item *bip) -{ -xfs_buf_item_free_format (bip); -kmem_free (bip->bli_item.li_lv_shadow); -kmem_cache_free (xfs_buf_item_zone, bip); -} - -/* -* xfs_buf_item_relse() is called when the buf log item is no longer needed. -*/ -void -xfs_buf_item_relse ( -struct xfs_buf *bp) -{ -struct xfs_buf_log_item *bip = bp->b_log_item; - -trace_xfs_buf_item_relse (bp, _RET_IP_); -ASSERT (!test_bit (XFS_LI_IN_AIL , &bip->bli_item.li_flags)); - -if (atomic_read (&bip->bli_refcount)) -return ; - bp->b_log_item =NULL ; -xfs_buf_rele (bp); -xfs_buf_item_free (bip); -} -void xfs_buf_item_done (struct xfs_buf *bp)
@@ -1006,5 +1008,5 @@ xfs_buf_item_done(xfs_trans_ail_delete (&bp->b_log_item->bli_item, (bp->b_flags & _XBF_LOGRECOVERY) ?0 :SHUTDOWN_CORRUPT_INCORE ); -xfs_buf_item_relse (bp); +xfs_buf_item_relse (bp->b_log_item); }
fs/xfs/xfs_buf_item.h +0 -1
@@ -51,7 +51,6 @@ struct xfs_buf_log_item {int xfs_buf_item_init (struct xfs_buf *,struct xfs_mount *);void xfs_buf_item_done (struct xfs_buf *bp); -void xfs_buf_item_relse (struct xfs_buf *);bool xfs_buf_item_put (struct xfs_buf_log_item *);void xfs_buf_item_log (struct xfs_buf_log_item *,uint ,uint );bool xfs_buf_item_dirty_format (struct xfs_buf_log_item *);
Signature · 1 line
2.53.0
PATCH RESEND v2 18/19 xfs: factor out stale buffer item completion
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
The stale buffer item completion handling is currently only done from BLI unpinning. We need to perform this function from where-ever the last reference to the BLI is dropped, so first we need to factor this code out into a helper.
--- fs/xfs/xfs_buf_item.c | 60 ++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 23 deletions(-)
fs/xfs/xfs_buf_item.c +37 -23
@@ -459,6 +459,42 @@ xfs_buf_item_pin(atomic_inc (&bip->bli_buf->b_pin_count); } +/* +* For a stale BLI, process all the necessary completions that must be +* performed when the final BLI reference goes away. The buffer will be +* referenced and locked here - we return to the caller with the buffer still +* referenced and locked for them to finalise processing of the buffer. +*/ +static void +xfs_buf_item_finish_stale ( +struct xfs_buf_log_item *bip) +{ +struct xfs_buf *bp = bip->bli_buf; +struct xfs_log_item *lip = &bip->bli_item; + +ASSERT (bip->bli_flags &XFS_BLI_STALE ); +ASSERT (xfs_buf_islocked (bp)); +ASSERT (bp->b_flags &XBF_STALE ); +ASSERT (bip->__bli_format.blf_flags &XFS_BLF_CANCEL ); +ASSERT (list_empty (&lip->li_trans)); +ASSERT (!bp->b_transp); + +if (bip->bli_flags &XFS_BLI_STALE_INODE ) { +xfs_buf_item_done (bp); +xfs_buf_inode_iodone (bp); +ASSERT (list_empty (&bp->b_li_list)); +return ; + } + +/* +* We may or may not be on the AIL here, xfs_trans_ail_delete() will do +* the right thing regardless of the situation in which we are called. +*/ +xfs_trans_ail_delete (lip,SHUTDOWN_LOG_IO_ERROR ); +xfs_buf_item_relse (bip); +ASSERT (bp->b_log_item ==NULL ); +} +/* * This is called to unpin the buffer associated with the buf log item which was * previously pinned with a call to xfs_buf_item_pin(). We enter this function
@@ -508,13 +544,6 @@ xfs_buf_item_unpin( }if (stale) { -ASSERT (bip->bli_flags &XFS_BLI_STALE ); -ASSERT (xfs_buf_islocked (bp)); -ASSERT (bp->b_flags &XBF_STALE ); -ASSERT (bip->__bli_format.blf_flags &XFS_BLF_CANCEL ); -ASSERT (list_empty (&lip->li_trans)); -ASSERT (!bp->b_transp); -trace_xfs_buf_item_unpin_stale (bip);/*
@@ -525,22 +554,7 @@ xfs_buf_item_unpin(* processing is complete. */ xfs_buf_rele (bp); - -/* -* If we get called here because of an IO error, we may or may -* not have the item on the AIL. xfs_trans_ail_delete() will -* take care of that situation. xfs_trans_ail_delete() drops -* the AIL lock. -*/ -if (bip->bli_flags &XFS_BLI_STALE_INODE ) { -xfs_buf_item_done (bp); -xfs_buf_inode_iodone (bp); -ASSERT (list_empty (&bp->b_li_list)); - }else { -xfs_trans_ail_delete (lip,SHUTDOWN_LOG_IO_ERROR ); -xfs_buf_item_relse (bip); -ASSERT (bp->b_log_item ==NULL ); - } +xfs_buf_item_finish_stale (bip);xfs_buf_relse (bp);return ; }
Signature · 1 line
2.53.0
PATCH RESEND v2 19/19 xfs: fix unmount hang with unflushable inodes stuck in the AIL
In reply to Siddh Raman PantFrom: Dave Chinner <[email protected]>
Unmount of a shutdown filesystem can hang with stale inode cluster buffers in the AIL like so:
[95964.140623] Call Trace: [95964.144641] __schedule+0x699/0xb70 [95964.154003] schedule+0x64/0xd0 [95964.156851] xfs_ail_push_all_sync+0x9b/0xf0 [95964.164816] xfs_unmount_flush_inodes+0x41/0x70 [95964.168698] xfs_unmountfs+0x7f/0x170 [95964.171846] xfs_fs_put_super+0x3b/0x90 [95964.175216] generic_shutdown_super+0x77/0x160 [95964.178060] kill_block_super+0x1b/0x40 [95964.180553] xfs_kill_sb+0x12/0x30 [95964.182796] deactivate_locked_super+0x38/0x100 [95964.185735] deactivate_super+0x41/0x50 [95964.188245] cleanup_mnt+0x9f/0x160 [95964.190519] __cleanup_mnt+0x12/0x20 [95964.192899] task_work_run+0x89/0xb0 [95964.195221] resume_user_mode_work+0x4f/0x60 [95964.197931] syscall_exit_to_user_mode+0x76/0xb0 [95964.201003] do_syscall_64+0x74/0x130
$ pstree -N mnt |grep umount |-check-parallel---nsexec---run_test.sh---753---umount
It always seems to be generic/753 that triggers this, and repeating a quick group test run triggers it every 10-15 iterations. Hence it generally triggers once up every 30-40 minutes of test time. just running generic/753 by itself or concurrently with a limited group of tests doesn't reproduce this issue at all.
Tracing on a hung system shows the AIL repeating every 50ms a log force followed by an attempt to push pinned, aborted inodes from the AIL (trimmed for brevity):
xfs_log_force: lsn 0x1c caller xfsaild+0x18e xfs_log_force: lsn 0x0 caller xlog_cil_flush+0xbd xfs_log_force: lsn 0x1c caller xfs_log_force+0x77 xfs_ail_pinned: lip 0xffff88826014afa0 lsn 1/37472 type XFS_LI_INODE flags IN_AIL|ABORTED xfs_ail_pinned: lip 0xffff88814000a708 lsn 1/37472 type XFS_LI_INODE flags IN_AIL|ABORTED xfs_ail_pinned: lip 0xffff88810b850c80 lsn 1/37472 type XFS_LI_INODE flags IN_AIL|ABORTED xfs_ail_pinned: lip 0xffff88810b850af0 lsn 1/37472 type XFS_LI_INODE flags IN_AIL|ABORTED xfs_ail_pinned: lip 0xffff888165cf0a28 lsn 1/37472 type XFS_LI_INODE flags IN_AIL|ABORTED xfs_ail_pinned: lip 0xffff88810b850bb8 lsn 1/37472 type XFS_LI_INODE flags IN_AIL|ABORTED
....
The inode log items are marked as aborted, which means that either:
a) a transaction commit has occurred, seen an error or shutdown, and called xfs_trans_free_items() to abort the items. This should happen before any pinning of log items occurs.
or
b) a dirty transaction has been cancelled. This should also happen before any pinning of log items occurs.
or
c) AIL insertion at journal IO completion is marked as aborted. In this case, the log item is pinned by the CIL until journal IO completes and hence needs to be unpinned. This is then done after the ->iop_committed() callback is run, so the pin count should be balanced correctly.
Yet none of these seemed to be occurring. Further tracing indicated this:
d) Shutdown during CIL pushing resulting in log item completion being called from checkpoint abort processing. Items are unpinned and released without serialisation against each other, journal IO completion or transaction commit completion.
In this case, we may still have a transaction commit in flight that holds a reference to a xfs_buf_log_item (BLI) after CIL insertion. e.g. a synchronous transaction will flush the CIL before the transaction is torn down. The concurrent CIL push then aborts insertion it and drops the commit/AIL reference to the BLI. This can leave the transaction commit context with the last reference to the BLI which is dropped here:
xfs_trans_free_items()
->iop_release
xfs_buf_item_release
xfs_buf_item_put
if (XFS_LI_ABORTED)
xfs_trans_ail_delete
xfs_buf_item_relse()
Unlike the journal completion ->iop_unpin path, this path does not run stale buffer completion process when it drops the last reference, hence leaving the stale inodes attached to the buffer sitting the AIL. There are no other references to those inodes, so there is no other mechanism to remove them from the AIL. Hence unmount hangs.
The buffer lock context for stale buffers is passed to the last BLI reference. This is normally the last BLI unpin on journal IO completion. The unpin then processes the stale buffer completion and releases the buffer lock. However, if the final unpin from journal IO completion (or CIL push abort) does not hold the last reference to the BLI, there -must- still be a transaction context that references the BLI, and so that context must perform the stale buffer completion processing before the buffer is unlocked and the BLI torn down.
The fix for this is to rework the xfs_buf_item_relse() path to run stale buffer completion processing if it drops the last reference to the BLI. We still hold the buffer locked, so the buffer owner and lock context is the same as if we passed the BLI and buffer to the ->iop_unpin() context to finish stale process on journal commit.
However, we have to be careful here. In a shutdown state, we can be freeing dirty BLIs from xfs_buf_item_put() via xfs_trans_brelse() and xfs_trans_bdetach(). The existing code handles this case by considering shutdown state as "aborted", but in doing so largely masks the failure to clean up stale BLI state from the xfs_buf_item_relse() path. i.e regardless of the shutdown state and whether the item is in the AIL, we must finish the stale buffer cleanup if we are are dropping the last BLI reference from the ->iop_relse path in transaction commit context.
--- fs/xfs/xfs_buf_item.c | 123 +++++++++++++++++++++++++++++------------- fs/xfs/xfs_buf_item.h | 2 +- 2 files changed, 87 insertions(+), 38 deletions(-)
fs/xfs/xfs_buf_item.c +86 -37
@@ -627,43 +627,42 @@ xfs_buf_item_push(* Drop the buffer log item refcount and take appropriate action. This helper * determines whether the bli must be freed or not, since a decrement to zero * does not necessarily mean the bli is unused. -* -* Return true if the bli is freed, false otherwise. */ -bool +void xfs_buf_item_put (struct xfs_buf_log_item *bip) { -struct xfs_log_item *lip = &bip->bli_item; -bool aborted; -bool dirty; + +ASSERT (xfs_buf_islocked (bip->bli_buf));/* drop the bli ref and return if it wasn't the last one */ if (!atomic_dec_and_test (&bip->bli_refcount)) -return false; +return ; + +/* If the BLI is in the AIL, then it is still dirty and in use */ +if (test_bit (XFS_LI_IN_AIL , &bip->bli_item.li_flags)) { +ASSERT (bip->bli_flags &XFS_BLI_DIRTY ); +return ; + }/* -* We dropped the last ref and must free the item if clean or aborted. -* If the bli is dirty and non-aborted, the buffer was clean in the -* transaction but still awaiting writeback from previous changes. In -* that case, the bli is freed on buffer writeback completion. +* In shutdown conditions, we can be asked to free a dirty BLI that +* isn't in the AIL. This can occur due to a checkpoint aborting a BLI +* instead of inserting it into the AIL at checkpoint IO completion. If +* there's another bli reference (e.g. a btree cursor holds a clean +* reference) and it is released via xfs_trans_brelse(), we can get here +* with that aborted, dirty BLI. In this case, it is safe to free the +* dirty BLI immediately, as it is not in the AIL and there are no +* other references to it. +* +* We should never get here with a stale BLI via that path as +* xfs_trans_brelse() specifically holds onto stale buffers rather than +* releasing them. */ - aborted =test_bit (XFS_LI_ABORTED , &lip->li_flags) || -xlog_is_shutdown (lip->li_log); - dirty = bip->bli_flags &XFS_BLI_DIRTY ; -if (dirty && !aborted) -return false; - -/* -* The bli is aborted or clean. An aborted item may be in the AIL -* regardless of dirty state. For example, consider an aborted -* transaction that invalidated a dirty bli and cleared the dirty -* state. -*/ -if (aborted) -xfs_trans_ail_delete (lip,0 ); +ASSERT (!(bip->bli_flags &XFS_BLI_DIRTY ) || +test_bit (XFS_LI_ABORTED , &bip->bli_item.li_flags)); +ASSERT (!(bip->bli_flags &XFS_BLI_STALE ));xfs_buf_item_relse (bip); -return true; }/*
@@ -684,6 +683,15 @@ xfs_buf_item_put(* if necessary but do not unlock the buffer. This is for support of * xfs_trans_bhold(). Make sure the XFS_BLI_HOLD field is cleared if we don't * free the item. +* +* If the XFS_BLI_STALE flag is set, the last reference to the BLI *must* +* perform a completion abort of any objects attached to the buffer for IO +* tracking purposes. This generally only happens in shutdown situations, +* normally xfs_buf_item_unpin() will drop the last BLI reference and perform +* completion processing. However, because transaction completion can race with +* checkpoint completion during a shutdown, this release context may end up +* being the last active reference to the BLI and so needs to perform this +* cleanup. */ STATIC void xfs_buf_item_release(
@@ -691,18 +699,19 @@ xfs_buf_item_release( {struct xfs_buf_log_item *bip =BUF_ITEM (lip);struct xfs_buf *bp = bip->bli_buf; -bool released;bool hold = bip->bli_flags &XFS_BLI_HOLD ;bool stale = bip->bli_flags &XFS_BLI_STALE ; -#if defined(DEBUG ) || defined(XFS_WARN ) -bool ordered = bip->bli_flags &XFS_BLI_ORDERED ; -bool dirty = bip->bli_flags &XFS_BLI_DIRTY ;bool aborted =test_bit (XFS_LI_ABORTED , &lip->li_flags); +bool dirty = bip->bli_flags &XFS_BLI_DIRTY ; +#if defined(DEBUG ) || defined(XFS_WARN ) +bool ordered = bip->bli_flags &XFS_BLI_ORDERED ;#endif trace_xfs_buf_item_release (bip); +ASSERT (xfs_buf_islocked (bp)); +/* * The bli dirty state should match whether the blf has logged segments * except for ordered buffers, where only the bli should be dirty.
@@ -718,16 +727,56 @@ xfs_buf_item_release( bp->b_transp =NULL ; bip->bli_flags &= ~(XFS_BLI_LOGGED |XFS_BLI_HOLD |XFS_BLI_ORDERED ); +/* If there are other references, then we have nothing to do. */ +if (!atomic_dec_and_test (&bip->bli_refcount)) + goto out_release; +/* -* Unref the item and unlock the buffer unless held or stale. Stale -* buffers remain locked until final unpin unless the bli is freed by -* the unref call. The latter implies shutdown because buffer -* invalidation dirties the bli and transaction. +* Stale buffer completion frees the BLI, unlocks and releases the +* buffer. Neither the BLI or buffer are safe to reference after this +* call, so there's nothing more we need to do here. +* +* If we get here with a stale buffer and references to the BLI remain, +* we must not unlock the buffer as the last BLI reference owns lock +* context, not us. */ - released =xfs_buf_item_put (bip); -if (hold || (stale && !released)) +if (stale) { +xfs_buf_item_finish_stale (bip); +xfs_buf_relse (bp); +ASSERT (!hold); +return ; + } + +/* +* Dirty or clean, aborted items are done and need to be removed from +* the AIL and released. This frees the BLI, but leaves the buffer +* locked and referenced. +*/ +if (aborted ||xlog_is_shutdown (lip->li_log)) { +ASSERT (list_empty (&bip->bli_buf->b_li_list)); +xfs_buf_item_done (bp); + goto out_release; + } + +/* +* Clean, unreferenced BLIs can be immediately freed, leaving the buffer +* locked and referenced. +* +* Dirty, unreferenced BLIs *must* be in the AIL awaiting writeback. +*/ +if (!dirty) +xfs_buf_item_relse (bip); +else +ASSERT (test_bit (XFS_LI_IN_AIL , &lip->li_flags)); + +/* Not safe to reference the BLI from here */ +out_release: +/* +* If we get here with a stale buffer, we must not unlock the +* buffer as the last BLI reference owns lock context, not us. +*/ +if (stale || hold)return ; -ASSERT (!stale || aborted);xfs_buf_relse (bp); }
fs/xfs/xfs_buf_item.h +1 -1
@@ -51,7 +51,7 @@ struct xfs_buf_log_item {int xfs_buf_item_init (struct xfs_buf *,struct xfs_mount *);void xfs_buf_item_done (struct xfs_buf *bp); -bool xfs_buf_item_put (struct xfs_buf_log_item *); +void xfs_buf_item_put (struct xfs_buf_log_item *bip);void xfs_buf_item_log (struct xfs_buf_log_item *,uint ,uint );bool xfs_buf_item_dirty_format (struct xfs_buf_log_item *);void xfs_buf_inode_iodone (struct xfs_buf *);
Signature · 1 line
2.53.0
5.10 xfstests_xfs:
Generic: Ran: 001 to 771 (661 tests; gaps) Excluded: 738 Failures before changes: Number: 19 IDs: 083, 091, 112, 127, 263, 269, 270, 363, 365, 373, 374, 681, 682, 700, 733, 749, 753, 754, 762 Failures after changes: Number: 19 IDs: 083, 091, 112, 127, 263, 269, 270, 363, 365, 373, 374, 681, 682, 700, 733, 749, 753, 754, 762 No new success or failure after changes. XFS: Ran: 001 to 789 (281 tests; gaps) Failures before changes: Number: 15 IDs: 019, 082, 104, 144, 179, 270, 300, 348, 442, 514, 515, 533, 597, 598, 609 Failures after changes: Number: 15 IDs: 019, 082, 104, 144, 179, 270, 300, 348, 442, 514, 515, 533, 597, 598, 609 No new success or failure after changes.
Thanks,
Siddh
Darrick J. Wong
Acked-byQuoted 25 lines · Siddh Raman Pant
5.10
xfstests_xfs:Generic: Ran: 001 to 771 (661 tests; gaps) Excluded: 738 Failures before changes: Number: 19 IDs: 083, 091, 112, 127, 263, 269, 270, 363, 365, 373, 374, 681, 682, 700, 733, 749, 753, 754, 762 Failures after changes: Number: 19 IDs: 083, 091, 112, 127, 263, 269, 270, 363, 365, 373, 374, 681, 682, 700, 733, 749, 753, 754, 762 No new success or failure after changes. XFS: Ran: 001 to 789 (281 tests; gaps) Failures before changes: Number: 15 IDs: 019, 082, 104, 144, 179, 270, 300, 348,
Quoted 8 lines
442, 514, 515, 533, 597, 598, 609 Failures after changes: Number: 15 IDs: 019, 082, 104, 144, 179, 270, 300, 348, 442, 514, 515, 533, 597, 598, 609 No new success or failure after changes.
Looks good to me,
--D
Quoted 3 lines
Thanks,
Siddh
Quoted 2 lines
Looks good to me,
Queued the series for 5.10, thanks.
Signature · 2 lines
Thanks, Sasha