aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/transaction.c
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fusionio.com>2012-09-14 10:34:40 -0400
committerChris Mason <chris.mason@fusionio.com>2012-10-04 09:39:56 -0400
commit60376ce4a8396bc5cd777be05b6a9bf044520f42 (patch)
tree9648ab1c651557c640b8cdd24ce18d75b434c510 /fs/btrfs/transaction.c
parentb3ae244e7174d981c09ad7a6a68e7909d600aaca (diff)
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 <bo.li.liu@oracle.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r--fs/btrfs/transaction.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index c01dec70c960..e4bfac8d54b8 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -272,6 +272,7 @@ enum btrfs_trans_type {
272 TRANS_JOIN, 272 TRANS_JOIN,
273 TRANS_USERSPACE, 273 TRANS_USERSPACE,
274 TRANS_JOIN_NOLOCK, 274 TRANS_JOIN_NOLOCK,
275 TRANS_JOIN_FREEZE,
275}; 276};
276 277
277static int may_wait_transaction(struct btrfs_root *root, int type) 278static int may_wait_transaction(struct btrfs_root *root, int type)
@@ -341,7 +342,11 @@ again:
341 if (!h) 342 if (!h)
342 return ERR_PTR(-ENOMEM); 343 return ERR_PTR(-ENOMEM);
343 344
344 sb_start_intwrite(root->fs_info->sb); 345 if (!__sb_start_write(root->fs_info->sb, SB_FREEZE_FS, false)) {
346 if (type == TRANS_JOIN_FREEZE)
347 return ERR_PTR(-EPERM);
348 sb_start_intwrite(root->fs_info->sb);
349 }
345 350
346 if (may_wait_transaction(root, type)) 351 if (may_wait_transaction(root, type))
347 wait_current_trans(root); 352 wait_current_trans(root);
@@ -424,6 +429,11 @@ struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *root
424 return start_transaction(root, 0, TRANS_USERSPACE, 0); 429 return start_transaction(root, 0, TRANS_USERSPACE, 0);
425} 430}
426 431
432struct btrfs_trans_handle *btrfs_join_transaction_freeze(struct btrfs_root *root)
433{
434 return start_transaction(root, 0, TRANS_JOIN_FREEZE, 0);
435}
436
427/* wait for a transaction commit to be fully complete */ 437/* wait for a transaction commit to be fully complete */
428static noinline void wait_for_commit(struct btrfs_root *root, 438static noinline void wait_for_commit(struct btrfs_root *root,
429 struct btrfs_transaction *commit) 439 struct btrfs_transaction *commit)