Merge branch 'misc-cleanups-4.5' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / fs / btrfs / tests / free-space-tests.c
index cc287d4f46d2a7d02d8ed05b8b953460d79dea7f..c9ad97b1e690900c998ae5d0267622ac6b9f6364 100644 (file)
 #include "../free-space-cache.h"
 
 #define BITS_PER_BITMAP                (PAGE_CACHE_SIZE * 8)
-static struct btrfs_block_group_cache *init_test_block_group(void)
-{
-       struct btrfs_block_group_cache *cache;
-
-       cache = kzalloc(sizeof(*cache), GFP_NOFS);
-       if (!cache)
-               return NULL;
-       cache->free_space_ctl = kzalloc(sizeof(*cache->free_space_ctl),
-                                       GFP_NOFS);
-       if (!cache->free_space_ctl) {
-               kfree(cache);
-               return NULL;
-       }
-       cache->fs_info = btrfs_alloc_dummy_fs_info();
-       if (!cache->fs_info) {
-               kfree(cache->free_space_ctl);
-               kfree(cache);
-               return NULL;
-       }
-
-       cache->key.objectid = 0;
-       cache->key.offset = SZ_1G;
-       cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
-       cache->sectorsize = 4096;
-       cache->full_stripe_len = 4096;
-
-       spin_lock_init(&cache->lock);
-       INIT_LIST_HEAD(&cache->list);
-       INIT_LIST_HEAD(&cache->cluster_list);
-       INIT_LIST_HEAD(&cache->bg_list);
-
-       btrfs_init_free_space_ctl(cache);
-
-       return cache;
-}
 
 /*
  * This test just does basic sanity checking, making sure we can add an exten
@@ -440,9 +405,11 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
        int ret;
        u64 offset;
        u64 max_extent_size;
-
-       bool (*use_bitmap_op)(struct btrfs_free_space_ctl *,
-                             struct btrfs_free_space *);
+       const struct btrfs_free_space_op test_free_space_ops = {
+               .recalc_thresholds = cache->free_space_ctl->op->recalc_thresholds,
+               .use_bitmap = test_use_bitmap,
+       };
+       const struct btrfs_free_space_op *orig_free_space_ops;
 
        test_msg("Running space stealing from bitmap to extent\n");
 
@@ -464,8 +431,8 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
         * that forces use of bitmaps as soon as we have at least 1
         * extent entry.
         */
-       use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
-       cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
+       orig_free_space_ops = cache->free_space_ctl->op;
+       cache->free_space_ctl->op = &test_free_space_ops;
 
        /*
         * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
@@ -851,7 +818,7 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
        if (ret)
                return ret;
 
-       cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
+       cache->free_space_ctl->op = orig_free_space_ops;
        __btrfs_remove_free_space_cache(cache->free_space_ctl);
 
        return 0;
@@ -865,7 +832,7 @@ int btrfs_test_free_space_cache(void)
 
        test_msg("Running btrfs free space cache tests\n");
 
-       cache = init_test_block_group();
+       cache = btrfs_alloc_dummy_block_group(1024 * 1024 * 1024);
        if (!cache) {
                test_msg("Couldn't run the tests\n");
                return 0;
@@ -896,9 +863,7 @@ int btrfs_test_free_space_cache(void)
 
        ret = test_steal_space_from_bitmap_to_extent(cache);
 out:
-       __btrfs_remove_free_space_cache(cache->free_space_ctl);
-       kfree(cache->free_space_ctl);
-       kfree(cache);
+       btrfs_free_dummy_block_group(cache);
        btrfs_free_dummy_root(root);
        test_msg("Free space cache tests finished\n");
        return ret;