Merge branch 'misc-cleanups-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / fs / btrfs / transaction.c
index fc82b02aff5cc9f8a8bb81b3bb2e6569e0fb8aab..b6031ce474f7c06f90c764c0bf520a95480ef561 100644 (file)
@@ -75,6 +75,23 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction)
                        list_del_init(&em->list);
                        free_extent_map(em);
                }
+               /*
+                * If any block groups are found in ->deleted_bgs then it's
+                * because the transaction was aborted and a commit did not
+                * happen (things failed before writing the new superblock
+                * and calling btrfs_finish_extent_commit()), so we can not
+                * discard the physical locations of the block groups.
+                */
+               while (!list_empty(&transaction->deleted_bgs)) {
+                       struct btrfs_block_group_cache *cache;
+
+                       cache = list_first_entry(&transaction->deleted_bgs,
+                                                struct btrfs_block_group_cache,
+                                                bg_list);
+                       list_del_init(&cache->bg_list);
+                       btrfs_put_block_group_trimming(cache);
+                       btrfs_put_block_group(cache);
+               }
                kmem_cache_free(btrfs_transaction_cachep, transaction);
        }
 }
@@ -1324,17 +1341,11 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
        u64 root_flags;
        uuid_le new_uuid;
 
-       path = btrfs_alloc_path();
-       if (!path) {
-               pending->error = -ENOMEM;
-               return 0;
-       }
+       ASSERT(pending->path);
+       path = pending->path;
 
-       new_root_item = kmalloc(sizeof(*new_root_item), GFP_NOFS);
-       if (!new_root_item) {
-               pending->error = -ENOMEM;
-               goto root_item_alloc_fail;
-       }
+       ASSERT(pending->root_item);
+       new_root_item = pending->root_item;
 
        pending->error = btrfs_find_free_objectid(tree_root, &objectid);
        if (pending->error)
@@ -1567,8 +1578,10 @@ clear_skip_qgroup:
        btrfs_clear_skip_qgroup(trans);
 no_free_objectid:
        kfree(new_root_item);
-root_item_alloc_fail:
+       pending->root_item = NULL;
        btrfs_free_path(path);
+       pending->path = NULL;
+
        return ret;
 }