From 60376ce4a8396bc5cd777be05b6a9bf044520f42 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Fri, 14 Sep 2012 10:34:40 -0400 Subject: Btrfs: fix race in sync and freeze again I screwed this up, there is a race between checking if there is a running transaction and actually starting a transaction in sync where we could race with a freezer and get ourselves into trouble. To fix this we need to make a new join type to only do the try lock on the freeze stuff. If it fails we'll return EPERM and just return from sync. This fixes a hang Liu Bo reported when running xfstest 68 in a loop. Thanks, Reported-by: Liu Bo Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'fs/btrfs/transaction.c') diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index c01dec70c96..e4bfac8d54b 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -272,6 +272,7 @@ enum btrfs_trans_type { TRANS_JOIN, TRANS_USERSPACE, TRANS_JOIN_NOLOCK, + TRANS_JOIN_FREEZE, }; static int may_wait_transaction(struct btrfs_root *root, int type) @@ -341,7 +342,11 @@ again: if (!h) return ERR_PTR(-ENOMEM); - sb_start_intwrite(root->fs_info->sb); + if (!__sb_start_write(root->fs_info->sb, SB_FREEZE_FS, false)) { + if (type == TRANS_JOIN_FREEZE) + return ERR_PTR(-EPERM); + sb_start_intwrite(root->fs_info->sb); + } if (may_wait_transaction(root, type)) wait_current_trans(root); @@ -424,6 +429,11 @@ struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root return start_transaction(root, 0, TRANS_USERSPACE, 0); } +struct btrfs_trans_handle *btrfs_join_transaction_freeze(struct btrfs_root *root) +{ + return start_transaction(root, 0, TRANS_JOIN_FREEZE, 0); +} + /* wait for a transaction commit to be fully complete */ static noinline void wait_for_commit(struct btrfs_root *root, struct btrfs_transaction *commit) -- cgit v1.2.3-70-g09d2