Merge branch 'freespace-tree' into for-linus-4.5
authorChris Mason <clm@fb.com>
Fri, 18 Dec 2015 19:11:10 +0000 (11:11 -0800)
committerChris Mason <clm@fb.com>
Fri, 18 Dec 2015 19:11:10 +0000 (11:11 -0800)
Signed-off-by: Chris Mason <clm@fb.com>
1  2 
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/extent_io.c
fs/btrfs/extent_io.h
fs/btrfs/super.c
fs/btrfs/tests/btrfs-tests.c
fs/btrfs/tests/free-space-tests.c
include/trace/events/btrfs.h

index 35489e7129a7e8de9d0232279d41d3bbd19ae1df,ed610f9c04b29fc43d5efc51ae3737b8f2a053aa..cf87979a153e69c027b3a01cb96df1dc8a511158
@@@ -2182,8 -2206,7 +2243,9 @@@ struct btrfs_ioctl_defrag_range_args 
  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR      (1 << 22)
  #define BTRFS_MOUNT_RESCAN_UUID_TREE  (1 << 23)
 -#define BTRFS_MOUNT_FREE_SPACE_TREE   (1 << 24)
 +#define BTRFS_MOUNT_FRAGMENT_DATA     (1 << 24)
 +#define BTRFS_MOUNT_FRAGMENT_METADATA (1 << 25)
++#define BTRFS_MOUNT_FREE_SPACE_TREE   (1 << 26)
  
  #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
  #define BTRFS_DEFAULT_MAX_INLINE      (8192)
Simple merge
index 4b89680a192338c7a70a4c909e3c4374abe41284,a4a4f593ec71d34bb988dcfa430db208866ca2c5..8abb344e3dcb003ec5a3410e9cbbd23073e49db9
@@@ -407,10 -387,8 +407,9 @@@ static int load_extent_tree_free(struc
        u64 total_found = 0;
        u64 last = 0;
        u32 nritems;
-       int ret = -ENOMEM;
+       int ret;
 +      bool wakeup = true;
  
-       caching_ctl = container_of(work, struct btrfs_caching_control, work);
        block_group = caching_ctl->block_group;
        fs_info = block_group->fs_info;
        extent_root = fs_info->extent_root;
@@@ -521,10 -486,9 +518,10 @@@ next
                        else
                                last = key.objectid + key.offset;
  
-                       if (total_found > (1024 * 1024 * 2)) {
+                       if (total_found > CACHING_CTL_WAKE_UP) {
                                total_found = 0;
 -                              wake_up(&caching_ctl->wait);
 +                              if (wakeup)
 +                                      wake_up(&caching_ctl->wait);
                        }
                }
                path->slots[0]++;
        total_found += add_new_free_space(block_group, fs_info, last,
                                          block_group->key.objectid +
                                          block_group->key.offset);
+       caching_ctl->progress = (u64)-1;
+ out:
+       btrfs_free_path(path);
+       return ret;
+ }
+ static noinline void caching_thread(struct btrfs_work *work)
+ {
+       struct btrfs_block_group_cache *block_group;
+       struct btrfs_fs_info *fs_info;
+       struct btrfs_caching_control *caching_ctl;
+       int ret;
+       caching_ctl = container_of(work, struct btrfs_caching_control, work);
+       block_group = caching_ctl->block_group;
+       fs_info = block_group->fs_info;
+       mutex_lock(&caching_ctl->mutex);
+       down_read(&fs_info->commit_root_sem);
+       if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE))
+               ret = load_free_space_tree(caching_ctl);
+       else
+               ret = load_extent_tree_free(caching_ctl);
        spin_lock(&block_group->lock);
        block_group->caching_ctl = NULL;
-       block_group->cached = BTRFS_CACHE_FINISHED;
+       block_group->cached = ret ? BTRFS_CACHE_ERROR : BTRFS_CACHE_FINISHED;
        spin_unlock(&block_group->lock);
  
- err:
-       btrfs_free_path(path);
-       up_read(&fs_info->commit_root_sem);
-       free_excluded_extents(extent_root, block_group);
 +#ifdef CONFIG_BTRFS_DEBUG
 +      if (btrfs_should_fragment_free_space(extent_root, block_group)) {
 +              u64 bytes_used;
 +
 +              spin_lock(&block_group->space_info->lock);
 +              spin_lock(&block_group->lock);
 +              bytes_used = block_group->key.offset -
 +                      btrfs_block_group_used(&block_group->item);
 +              block_group->space_info->bytes_used += bytes_used >> 1;
 +              spin_unlock(&block_group->lock);
 +              spin_unlock(&block_group->space_info->lock);
 +              fragment_free_space(extent_root, block_group);
 +      }
 +#endif
 +
 +      caching_ctl->progress = (u64)-1;
 +
+       up_read(&fs_info->commit_root_sem);
+       free_excluded_extents(fs_info->extent_root, block_group);
        mutex_unlock(&caching_ctl->mutex);
- out:
-       if (ret) {
-               spin_lock(&block_group->lock);
-               block_group->caching_ctl = NULL;
-               block_group->cached = BTRFS_CACHE_ERROR;
-               spin_unlock(&block_group->lock);
-       }
        wake_up(&caching_ctl->wait);
  
        put_caching_control(caching_ctl);
Simple merge
Simple merge
Simple merge
index 9626252ee6b47d2b391f3383cfa9b3bb80e4110c,ba28cefdf9e7b6d0b787199136471d2d68649941..b1d920b3007017c2014d28217cb5efa1d7ed4d96
@@@ -169,3 -175,49 +175,55 @@@ void btrfs_free_dummy_root(struct btrfs
        kfree(root);
  }
  
+ struct btrfs_block_group_cache *
+ btrfs_alloc_dummy_block_group(unsigned long length)
+ {
+       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 = length;
+       cache->key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
+       cache->sectorsize = 4096;
+       cache->full_stripe_len = 4096;
+       INIT_LIST_HEAD(&cache->list);
+       INIT_LIST_HEAD(&cache->cluster_list);
+       INIT_LIST_HEAD(&cache->bg_list);
+       btrfs_init_free_space_ctl(cache);
+       mutex_init(&cache->free_space_lock);
+       return cache;
+ }
+ void btrfs_free_dummy_block_group(struct btrfs_block_group_cache *cache)
+ {
+       if (!cache)
+               return;
+       __btrfs_remove_free_space_cache(cache->free_space_ctl);
+       kfree(cache->free_space_ctl);
+       kfree(cache);
+ }
+ void btrfs_init_dummy_trans(struct btrfs_trans_handle *trans)
+ {
+       memset(trans, 0, sizeof(*trans));
+       trans->transid = 1;
+       INIT_LIST_HEAD(&trans->qgroup_ref_list);
+       trans->type = __TRANS_DUMMY;
+ }
index 8b72b005bfb9a212518a711a2e476c2d70b47b24,bae6c599f6045a7eae995f179f123e180862e80b..cd3e300b9ba5c9152d9f2b3210469262dcd4a861
@@@ -922,10 -872,7 +887,8 @@@ 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;
  }
Simple merge