Skip to content

Commit b6c2b63

Browse files
author
Chandan Babu R
committed
Merge tag 'fix-efi-recovery-6.6_2023-09-12' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.6-fixesA
xfs: fix EFI recovery livelocks This series fixes a customer-reported transaction reservation bug introduced ten years ago that could result in livelocks during log recovery. Log intent item recovery single-steps each step of a deferred op chain, which means that each step only needs to allocate one transaction's worth of space in the log, not an entire chain all at once. This single-stepping is critical to unpinning the log tail since there's nobody else to do it for us. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org> * tag 'fix-efi-recovery-6.6_2023-09-12' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: reserve less log space when recovering log intent items
2 parents f41d7d7 + 3c919b0 commit b6c2b63

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

fs/xfs/libxfs/xfs_log_recover.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,26 @@ void xlog_check_buf_cancel_table(struct xlog *log);
131131
#define xlog_check_buf_cancel_table(log) do { } while (0)
132132
#endif
133133

134+
/*
135+
* Transform a regular reservation into one suitable for recovery of a log
136+
* intent item.
137+
*
138+
* Intent recovery only runs a single step of the transaction chain and defers
139+
* the rest to a separate transaction. Therefore, we reduce logcount to 1 here
140+
* to avoid livelocks if the log grant space is nearly exhausted due to the
141+
* recovered intent pinning the tail. Keep the same logflags to avoid tripping
142+
* asserts elsewhere. Struct copies abound below.
143+
*/
144+
static inline struct xfs_trans_res
145+
xlog_recover_resv(const struct xfs_trans_res *r)
146+
{
147+
struct xfs_trans_res ret = {
148+
.tr_logres = r->tr_logres,
149+
.tr_logcount = 1,
150+
.tr_logflags = r->tr_logflags,
151+
};
152+
153+
return ret;
154+
}
155+
134156
#endif /* __XFS_LOG_RECOVER_H__ */

fs/xfs/xfs_attr_item.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ xfs_attri_item_recover(
547547
struct xfs_inode *ip;
548548
struct xfs_da_args *args;
549549
struct xfs_trans *tp;
550-
struct xfs_trans_res tres;
550+
struct xfs_trans_res resv;
551551
struct xfs_attri_log_format *attrp;
552552
struct xfs_attri_log_nameval *nv = attrip->attri_nameval;
553553
int error;
@@ -618,8 +618,9 @@ xfs_attri_item_recover(
618618
goto out;
619619
}
620620

621-
xfs_init_attr_trans(args, &tres, &total);
622-
error = xfs_trans_alloc(mp, &tres, total, 0, XFS_TRANS_RESERVE, &tp);
621+
xfs_init_attr_trans(args, &resv, &total);
622+
resv = xlog_recover_resv(&resv);
623+
error = xfs_trans_alloc(mp, &resv, total, 0, XFS_TRANS_RESERVE, &tp);
623624
if (error)
624625
goto out;
625626

fs/xfs/xfs_bmap_item.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ xfs_bui_item_recover(
490490
struct list_head *capture_list)
491491
{
492492
struct xfs_bmap_intent fake = { };
493+
struct xfs_trans_res resv;
493494
struct xfs_bui_log_item *buip = BUI_ITEM(lip);
494495
struct xfs_trans *tp;
495496
struct xfs_inode *ip = NULL;
@@ -515,7 +516,8 @@ xfs_bui_item_recover(
515516
return error;
516517

517518
/* Allocate transaction and do the work. */
518-
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
519+
resv = xlog_recover_resv(&M_RES(mp)->tr_itruncate);
520+
error = xfs_trans_alloc(mp, &resv,
519521
XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK), 0, 0, &tp);
520522
if (error)
521523
goto err_rele;

fs/xfs/xfs_extfree_item.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ xfs_efi_item_recover(
660660
struct xfs_log_item *lip,
661661
struct list_head *capture_list)
662662
{
663+
struct xfs_trans_res resv;
663664
struct xfs_efi_log_item *efip = EFI_ITEM(lip);
664665
struct xfs_mount *mp = lip->li_log->l_mp;
665666
struct xfs_efd_log_item *efdp;
@@ -683,7 +684,8 @@ xfs_efi_item_recover(
683684
}
684685
}
685686

686-
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
687+
resv = xlog_recover_resv(&M_RES(mp)->tr_itruncate);
688+
error = xfs_trans_alloc(mp, &resv, 0, 0, 0, &tp);
687689
if (error)
688690
return error;
689691
efdp = xfs_trans_get_efd(tp, efip, efip->efi_format.efi_nextents);

fs/xfs/xfs_refcount_item.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ xfs_cui_item_recover(
477477
struct xfs_log_item *lip,
478478
struct list_head *capture_list)
479479
{
480+
struct xfs_trans_res resv;
480481
struct xfs_cui_log_item *cuip = CUI_ITEM(lip);
481482
struct xfs_cud_log_item *cudp;
482483
struct xfs_trans *tp;
@@ -514,8 +515,9 @@ xfs_cui_item_recover(
514515
* doesn't fit. We need to reserve enough blocks to handle a
515516
* full btree split on either end of the refcount range.
516517
*/
517-
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
518-
mp->m_refc_maxlevels * 2, 0, XFS_TRANS_RESERVE, &tp);
518+
resv = xlog_recover_resv(&M_RES(mp)->tr_itruncate);
519+
error = xfs_trans_alloc(mp, &resv, mp->m_refc_maxlevels * 2, 0,
520+
XFS_TRANS_RESERVE, &tp);
519521
if (error)
520522
return error;
521523

fs/xfs/xfs_rmap_item.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ xfs_rui_item_recover(
507507
struct xfs_log_item *lip,
508508
struct list_head *capture_list)
509509
{
510+
struct xfs_trans_res resv;
510511
struct xfs_rui_log_item *ruip = RUI_ITEM(lip);
511512
struct xfs_rud_log_item *rudp;
512513
struct xfs_trans *tp;
@@ -530,8 +531,9 @@ xfs_rui_item_recover(
530531
}
531532
}
532533

533-
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
534-
mp->m_rmap_maxlevels, 0, XFS_TRANS_RESERVE, &tp);
534+
resv = xlog_recover_resv(&M_RES(mp)->tr_itruncate);
535+
error = xfs_trans_alloc(mp, &resv, mp->m_rmap_maxlevels, 0,
536+
XFS_TRANS_RESERVE, &tp);
535537
if (error)
536538
return error;
537539
rudp = xfs_trans_get_rud(tp, ruip);

0 commit comments

Comments
 (0)