diff options
author | Christoph Hellwig <hch@lst.de> | 2011-07-08 08:34:42 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2011-07-08 08:34:42 -0400 |
commit | 7a249cf83da1813cfa71cfe1e265b40045eceb47 (patch) | |
tree | 0c665aad7d32614f7eaa5a11c1b534c8fb5037d3 /fs | |
parent | 33b8f7c2479dfcbc5c27174e44b5f659d9f33c70 (diff) |
xfs: fix filesystsem freeze race in xfs_trans_alloc
As pointed out by Jan xfs_trans_alloc can race with a concurrent filesystem
freeze when it sleeps during the memory allocation. Fix this by moving the
wait_for_freeze call after the memory allocation. This means moving the
freeze into the low-level _xfs_trans_alloc helper, which thus grows a new
argument. Also fix up some comments in that area while at it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Alex Elder <aelder@sgi.com>
Reviewed-by: Dave Chinner <david@fromorbit.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/xfs/xfs_fsops.c | 2 | ||||
-rw-r--r-- | fs/xfs/xfs_iomap.c | 3 | ||||
-rw-r--r-- | fs/xfs/xfs_mount.c | 14 | ||||
-rw-r--r-- | fs/xfs/xfs_trans.c | 27 | ||||
-rw-r--r-- | fs/xfs/xfs_trans.h | 10 |
5 files changed, 27 insertions, 29 deletions
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 9153d2c77ca..b7c492d293b 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c | |||
@@ -626,7 +626,7 @@ xfs_fs_log_dummy( | |||
626 | xfs_trans_t *tp; | 626 | xfs_trans_t *tp; |
627 | int error; | 627 | int error; |
628 | 628 | ||
629 | tp = _xfs_trans_alloc(mp, XFS_TRANS_DUMMY1, KM_SLEEP); | 629 | tp = _xfs_trans_alloc(mp, XFS_TRANS_DUMMY1, KM_SLEEP, false); |
630 | error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0, | 630 | error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0, |
631 | XFS_DEFAULT_LOG_COUNT); | 631 | XFS_DEFAULT_LOG_COUNT); |
632 | if (error) { | 632 | if (error) { |
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 091d82b94c4..982b71108f3 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c | |||
@@ -688,8 +688,7 @@ xfs_iomap_write_unwritten( | |||
688 | * the same inode that we complete here and might deadlock | 688 | * the same inode that we complete here and might deadlock |
689 | * on the iolock. | 689 | * on the iolock. |
690 | */ | 690 | */ |
691 | xfs_wait_for_freeze(mp, SB_FREEZE_TRANS); | 691 | tp = _xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE, KM_NOFS, true); |
692 | tp = _xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE, KM_NOFS); | ||
693 | tp->t_flags |= XFS_TRANS_RESERVE; | 692 | tp->t_flags |= XFS_TRANS_RESERVE; |
694 | error = xfs_trans_reserve(tp, resblks, | 693 | error = xfs_trans_reserve(tp, resblks, |
695 | XFS_WRITE_LOG_RES(mp), 0, | 694 | XFS_WRITE_LOG_RES(mp), 0, |
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index b49b82363d2..63659ee316b 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c | |||
@@ -1566,15 +1566,9 @@ xfs_fs_writable(xfs_mount_t *mp) | |||
1566 | } | 1566 | } |
1567 | 1567 | ||
1568 | /* | 1568 | /* |
1569 | * xfs_log_sbcount | ||
1570 | * | ||
1571 | * Called either periodically to keep the on disk superblock values | 1569 | * Called either periodically to keep the on disk superblock values |
1572 | * roughly up to date or from unmount to make sure the values are | 1570 | * roughly up to date or from unmount to make sure the values are |
1573 | * correct on a clean unmount. | 1571 | * correct on a clean unmount. |
1574 | * | ||
1575 | * Note this code can be called during the process of freezing, so | ||
1576 | * we may need to use the transaction allocator which does not not | ||
1577 | * block when the transaction subsystem is in its frozen state. | ||
1578 | */ | 1572 | */ |
1579 | int | 1573 | int |
1580 | xfs_log_sbcount( | 1574 | xfs_log_sbcount( |
@@ -1596,7 +1590,13 @@ xfs_log_sbcount( | |||
1596 | if (!xfs_sb_version_haslazysbcount(&mp->m_sb)) | 1590 | if (!xfs_sb_version_haslazysbcount(&mp->m_sb)) |
1597 | return 0; | 1591 | return 0; |
1598 | 1592 | ||
1599 | tp = _xfs_trans_alloc(mp, XFS_TRANS_SB_COUNT, KM_SLEEP); | 1593 | /* |
1594 | * We can be called during the process of freezing, so make sure | ||
1595 | * we go ahead even if the frozen for new transactions. We will | ||
1596 | * always use a sync transaction in the freeze path to make sure | ||
1597 | * the transaction has completed by the time we return. | ||
1598 | */ | ||
1599 | tp = _xfs_trans_alloc(mp, XFS_TRANS_SB_COUNT, KM_SLEEP, false); | ||
1600 | error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0, | 1600 | error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0, |
1601 | XFS_DEFAULT_LOG_COUNT); | 1601 | XFS_DEFAULT_LOG_COUNT); |
1602 | if (error) { | 1602 | if (error) { |
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index c83f63b33aa..2837220ea5c 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c | |||
@@ -566,31 +566,24 @@ xfs_trans_init( | |||
566 | 566 | ||
567 | /* | 567 | /* |
568 | * This routine is called to allocate a transaction structure. | 568 | * This routine is called to allocate a transaction structure. |
569 | * | ||
569 | * The type parameter indicates the type of the transaction. These | 570 | * The type parameter indicates the type of the transaction. These |
570 | * are enumerated in xfs_trans.h. | 571 | * 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. | ||
574 | */ | 572 | */ |
575 | xfs_trans_t * | 573 | struct xfs_trans * |
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 * | ||
585 | _xfs_trans_alloc( | 574 | _xfs_trans_alloc( |
586 | xfs_mount_t *mp, | 575 | struct xfs_mount *mp, |
587 | uint type, | 576 | uint type, |
588 | uint memflags) | 577 | uint memflags, |
578 | bool wait_for_freeze) | ||
589 | { | 579 | { |
590 | xfs_trans_t *tp; | 580 | struct xfs_trans *tp; |
591 | 581 | ||
592 | atomic_inc(&mp->m_active_trans); | 582 | atomic_inc(&mp->m_active_trans); |
593 | 583 | ||
584 | if (wait_for_freeze) | ||
585 | xfs_wait_for_freeze(mp, SB_FREEZE_TRANS); | ||
586 | |||
594 | tp = kmem_zone_zalloc(xfs_trans_zone, memflags); | 587 | tp = kmem_zone_zalloc(xfs_trans_zone, memflags); |
595 | tp->t_magic = XFS_TRANS_MAGIC; | 588 | tp->t_magic = XFS_TRANS_MAGIC; |
596 | tp->t_type = type; | 589 | tp->t_type = type; |
diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h index 06a9759b635..4e78432ce14 100644 --- a/fs/xfs/xfs_trans.h +++ b/fs/xfs/xfs_trans.h | |||
@@ -447,8 +447,14 @@ typedef struct xfs_trans { | |||
447 | /* | 447 | /* |
448 | * XFS transaction mechanism exported interfaces. | 448 | * XFS transaction mechanism exported interfaces. |
449 | */ | 449 | */ |
450 | xfs_trans_t *xfs_trans_alloc(struct xfs_mount *, uint); | 450 | xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, uint, bool); |
451 | xfs_trans_t *_xfs_trans_alloc(struct xfs_mount *, uint, uint); | 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 | |||
452 | xfs_trans_t *xfs_trans_dup(xfs_trans_t *); | 458 | xfs_trans_t *xfs_trans_dup(xfs_trans_t *); |
453 | int xfs_trans_reserve(xfs_trans_t *, uint, uint, uint, | 459 | int xfs_trans_reserve(xfs_trans_t *, uint, uint, uint, |
454 | uint, uint); | 460 | uint, uint); |