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/super.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'fs/btrfs/super.c') diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 867e8e799dea..903ab2d7068a 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -854,16 +854,13 @@ int btrfs_sync_fs(struct super_block *sb, int wait) btrfs_wait_ordered_extents(root, 0, 0); - spin_lock(&fs_info->trans_lock); - if (!fs_info->running_transaction) { - spin_unlock(&fs_info->trans_lock); - return 0; - } - spin_unlock(&fs_info->trans_lock); - - trans = btrfs_join_transaction(root); - if (IS_ERR(trans)) + trans = btrfs_join_transaction_freeze(root); + if (IS_ERR(trans)) { + /* Frozen, don't bother */ + if (PTR_ERR(trans) == -EPERM) + return 0; return PTR_ERR(trans); + } return btrfs_commit_transaction(trans, root); } -- cgit v1.2.3