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/xfs/xfs_trans.c | |
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/xfs/xfs_trans.c')
-rw-r--r-- | fs/xfs/xfs_trans.c | 27 |
1 files changed, 10 insertions, 17 deletions
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; |