Skip to content

Commit b2ce397

Browse files
author
Alex Elder
committed
Revert "xfs: fix filesystsem freeze race in xfs_trans_alloc"
This reverts commit 7a249cf. That commit created a situation that could lead to a filesystem hang. As Dave Chinner pointed out, xfs_trans_alloc() could hold a reference to m_active_trans (i.e., keep it non-zero) and then wait for SB_FREEZE_TRANS to complete. Meanwhile a filesystem freeze request could set SB_FREEZE_TRANS and then wait for m_active_trans to drop to zero. Nobody benefits from this sequence of events... Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Alex Elder <[email protected]>
1 parent 81463b1 commit b2ce397

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

fs/xfs/xfs_fsops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ xfs_fs_log_dummy(
626626
xfs_trans_t *tp;
627627
int error;
628628

629-
tp = _xfs_trans_alloc(mp, XFS_TRANS_DUMMY1, KM_SLEEP, false);
629+
tp = _xfs_trans_alloc(mp, XFS_TRANS_DUMMY1, KM_SLEEP);
630630
error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0,
631631
XFS_DEFAULT_LOG_COUNT);
632632
if (error) {

fs/xfs/xfs_iomap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ xfs_iomap_write_unwritten(
688688
* the same inode that we complete here and might deadlock
689689
* on the iolock.
690690
*/
691-
tp = _xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE, KM_NOFS, true);
691+
xfs_wait_for_freeze(mp, SB_FREEZE_TRANS);
692+
tp = _xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE, KM_NOFS);
692693
tp->t_flags |= XFS_TRANS_RESERVE;
693694
error = xfs_trans_reserve(tp, resblks,
694695
XFS_WRITE_LOG_RES(mp), 0,

fs/xfs/xfs_mount.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,9 +1559,15 @@ xfs_fs_writable(xfs_mount_t *mp)
15591559
}
15601560

15611561
/*
1562+
* xfs_log_sbcount
1563+
*
15621564
* Called either periodically to keep the on disk superblock values
15631565
* roughly up to date or from unmount to make sure the values are
15641566
* correct on a clean unmount.
1567+
*
1568+
* Note this code can be called during the process of freezing, so
1569+
* we may need to use the transaction allocator which does not not
1570+
* block when the transaction subsystem is in its frozen state.
15651571
*/
15661572
int
15671573
xfs_log_sbcount(
@@ -1583,13 +1589,7 @@ xfs_log_sbcount(
15831589
if (!xfs_sb_version_haslazysbcount(&mp->m_sb))
15841590
return 0;
15851591

1586-
/*
1587-
* We can be called during the process of freezing, so make sure
1588-
* we go ahead even if the frozen for new transactions. We will
1589-
* always use a sync transaction in the freeze path to make sure
1590-
* the transaction has completed by the time we return.
1591-
*/
1592-
tp = _xfs_trans_alloc(mp, XFS_TRANS_SB_COUNT, KM_SLEEP, false);
1592+
tp = _xfs_trans_alloc(mp, XFS_TRANS_SB_COUNT, KM_SLEEP);
15931593
error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0,
15941594
XFS_DEFAULT_LOG_COUNT);
15951595
if (error) {

fs/xfs/xfs_trans.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,24 +566,31 @@ xfs_trans_init(
566566

567567
/*
568568
* This routine is called to allocate a transaction structure.
569-
*
570569
* The type parameter indicates the type of the transaction. These
571570
* are enumerated in xfs_trans.h.
571+
*
572+
* Dynamically allocate the transaction structure from the transaction
573+
* zone, initialize it, and return it to the caller.
572574
*/
573-
struct xfs_trans *
575+
xfs_trans_t *
576+
xfs_trans_alloc(
577+
xfs_mount_t *mp,
578+
uint type)
579+
{
580+
xfs_wait_for_freeze(mp, SB_FREEZE_TRANS);
581+
return _xfs_trans_alloc(mp, type, KM_SLEEP);
582+
}
583+
584+
xfs_trans_t *
574585
_xfs_trans_alloc(
575-
struct xfs_mount *mp,
576-
uint type,
577-
uint memflags,
578-
bool wait_for_freeze)
586+
xfs_mount_t *mp,
587+
uint type,
588+
uint memflags)
579589
{
580-
struct xfs_trans *tp;
590+
xfs_trans_t *tp;
581591

582592
atomic_inc(&mp->m_active_trans);
583593

584-
if (wait_for_freeze)
585-
xfs_wait_for_freeze(mp, SB_FREEZE_TRANS);
586-
587594
tp = kmem_zone_zalloc(xfs_trans_zone, memflags);
588595
tp->t_magic = XFS_TRANS_MAGIC;
589596
tp->t_type = type;

fs/xfs/xfs_trans.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,8 @@ typedef struct xfs_trans {
447447
/*
448448
* XFS transaction mechanism exported interfaces.
449449
*/
450-
xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, uint, bool);
451-
452-
static inline struct xfs_trans *
453-
xfs_trans_alloc(struct xfs_mount *mp, uint type)
454-
{
455-
return _xfs_trans_alloc(mp, type, KM_SLEEP, true);
456-
}
457-
450+
xfs_trans_t *xfs_trans_alloc(struct xfs_mount *, uint);
451+
xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, uint);
458452
xfs_trans_t *xfs_trans_dup(xfs_trans_t *);
459453
int xfs_trans_reserve(xfs_trans_t *, uint, uint, uint,
460454
uint, uint);

0 commit comments

Comments
 (0)