diff options
-rw-r--r-- | fs/btrfs/transaction.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index c9265a603488..a4fe5494d01b 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c | |||
@@ -342,7 +342,15 @@ again: | |||
342 | if (!h) | 342 | if (!h) |
343 | return ERR_PTR(-ENOMEM); | 343 | return ERR_PTR(-ENOMEM); |
344 | 344 | ||
345 | if (!__sb_start_write(root->fs_info->sb, SB_FREEZE_FS, false)) { | 345 | /* |
346 | * If we are JOIN_NOLOCK we're already committing a transaction and | ||
347 | * waiting on this guy, so we don't need to do the sb_start_intwrite | ||
348 | * because we're already holding a ref. We need this because we could | ||
349 | * have raced in and did an fsync() on a file which can kick a commit | ||
350 | * and then we deadlock with somebody doing a freeze. | ||
351 | */ | ||
352 | if (type != TRANS_JOIN_NOLOCK && | ||
353 | !__sb_start_write(root->fs_info->sb, SB_FREEZE_FS, false)) { | ||
346 | if (type == TRANS_JOIN_FREEZE) | 354 | if (type == TRANS_JOIN_FREEZE) |
347 | return ERR_PTR(-EPERM); | 355 | return ERR_PTR(-EPERM); |
348 | sb_start_intwrite(root->fs_info->sb); | 356 | sb_start_intwrite(root->fs_info->sb); |
@@ -601,7 +609,8 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, | |||
601 | } | 609 | } |
602 | } | 610 | } |
603 | 611 | ||
604 | sb_end_intwrite(root->fs_info->sb); | 612 | if (lock) |
613 | sb_end_intwrite(root->fs_info->sb); | ||
605 | 614 | ||
606 | WARN_ON(cur_trans != info->running_transaction); | 615 | WARN_ON(cur_trans != info->running_transaction); |
607 | WARN_ON(atomic_read(&cur_trans->num_writers) < 1); | 616 | WARN_ON(atomic_read(&cur_trans->num_writers) < 1); |