aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Bo <bo.li.liu@oracle.com>2013-02-27 08:28:25 -0500
committerJosef Bacik <jbacik@fusionio.com>2013-02-28 13:33:52 -0500
commitf094ac32aba3a51c00e970a2ea029339af2ca048 (patch)
tree88330927384b9ff597f6330a000e463079c02846
parent3321719ed67440bba1b0c5ae19c30d640263ccc8 (diff)
Btrfs: fix NULL pointer after aborting a transaction
While doing cleanup work on an aborted transaction, we've set the global running transaction pointer to NULL _before_ waiting all other transaction handles to finish, so others'd hit NULL pointer crash when referencing the global running transaction pointer. This first sets a hint to avoid new transaction handle joining, then waits other existing handles to abort or finish so that we can safely set the above global pointer to NULL. Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
-rw-r--r--fs/btrfs/transaction.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 4330433b7b4f..3733c4939a27 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1447,6 +1447,7 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,
1447 struct btrfs_root *root, int err) 1447 struct btrfs_root *root, int err)
1448{ 1448{
1449 struct btrfs_transaction *cur_trans = trans->transaction; 1449 struct btrfs_transaction *cur_trans = trans->transaction;
1450 DEFINE_WAIT(wait);
1450 1451
1451 WARN_ON(trans->use_count > 1); 1452 WARN_ON(trans->use_count > 1);
1452 1453
@@ -1455,8 +1456,13 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans,
1455 spin_lock(&root->fs_info->trans_lock); 1456 spin_lock(&root->fs_info->trans_lock);
1456 list_del_init(&cur_trans->list); 1457 list_del_init(&cur_trans->list);
1457 if (cur_trans == root->fs_info->running_transaction) { 1458 if (cur_trans == root->fs_info->running_transaction) {
1459 root->fs_info->trans_no_join = 1;
1460 spin_unlock(&root->fs_info->trans_lock);
1461 wait_event(cur_trans->writer_wait,
1462 atomic_read(&cur_trans->num_writers) == 1);
1463
1464 spin_lock(&root->fs_info->trans_lock);
1458 root->fs_info->running_transaction = NULL; 1465 root->fs_info->running_transaction = NULL;
1459 root->fs_info->trans_no_join = 0;
1460 } 1466 }
1461 spin_unlock(&root->fs_info->trans_lock); 1467 spin_unlock(&root->fs_info->trans_lock);
1462 1468