btrfs: get fs_info from block group in next_block_group
[sfrench/cifs-2.6.git] / fs / btrfs / extent-tree.c
index ecb590a1e6137d02b4a0194698ce7586c1d368e3..7a0f3e1519996b86e099125de0785e22023fa706 100644 (file)
@@ -2876,91 +2876,6 @@ int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans)
        return btrfs_check_space_for_delayed_refs(trans->fs_info);
 }
 
-struct async_delayed_refs {
-       struct btrfs_root *root;
-       u64 transid;
-       int count;
-       int error;
-       int sync;
-       struct completion wait;
-       struct btrfs_work work;
-};
-
-static inline struct async_delayed_refs *
-to_async_delayed_refs(struct btrfs_work *work)
-{
-       return container_of(work, struct async_delayed_refs, work);
-}
-
-static void delayed_ref_async_start(struct btrfs_work *work)
-{
-       struct async_delayed_refs *async = to_async_delayed_refs(work);
-       struct btrfs_trans_handle *trans;
-       struct btrfs_fs_info *fs_info = async->root->fs_info;
-       int ret;
-
-       /* if the commit is already started, we don't need to wait here */
-       if (btrfs_transaction_blocked(fs_info))
-               goto done;
-
-       trans = btrfs_join_transaction(async->root);
-       if (IS_ERR(trans)) {
-               async->error = PTR_ERR(trans);
-               goto done;
-       }
-
-       /* Don't bother flushing if we got into a different transaction */
-       if (trans->transid > async->transid)
-               goto end;
-
-       ret = btrfs_run_delayed_refs(trans, async->count);
-       if (ret)
-               async->error = ret;
-end:
-       ret = btrfs_end_transaction(trans);
-       if (ret && !async->error)
-               async->error = ret;
-done:
-       if (async->sync)
-               complete(&async->wait);
-       else
-               kfree(async);
-}
-
-int btrfs_async_run_delayed_refs(struct btrfs_fs_info *fs_info,
-                                unsigned long count, u64 transid, int wait)
-{
-       struct async_delayed_refs *async;
-       int ret;
-
-       async = kmalloc(sizeof(*async), GFP_NOFS);
-       if (!async)
-               return -ENOMEM;
-
-       async->root = fs_info->tree_root;
-       async->count = count;
-       async->error = 0;
-       async->transid = transid;
-       if (wait)
-               async->sync = 1;
-       else
-               async->sync = 0;
-       init_completion(&async->wait);
-
-       btrfs_init_work(&async->work, btrfs_extent_refs_helper,
-                       delayed_ref_async_start, NULL, NULL);
-
-       btrfs_queue_work(fs_info->extent_workers, &async->work);
-
-       if (wait) {
-               wait_for_completion(&async->wait);
-               ret = async->error;
-               kfree(async);
-               return ret;
-       }
-       return 0;
-}
-
 /*
  * this starts processing the delayed reference count updates and
  * extent insertions we have queued up so far.  count can be
@@ -3341,10 +3256,10 @@ fail:
 
 }
 
-static struct btrfs_block_group_cache *
-next_block_group(struct btrfs_fs_info *fs_info,
-                struct btrfs_block_group_cache *cache)
+static struct btrfs_block_group_cache *next_block_group(
+               struct btrfs_block_group_cache *cache)
 {
+       struct btrfs_fs_info *fs_info = cache->fs_info;
        struct rb_node *node;
 
        spin_lock(&fs_info->block_group_cache_lock);
@@ -3411,8 +3326,7 @@ again:
                if (block_group->ro)
                        goto out_free;
 
-               ret = create_free_space_inode(fs_info, trans, block_group,
-                                             path);
+               ret = create_free_space_inode(trans, block_group, path);
                if (ret)
                        goto out_free;
                goto again;
@@ -3645,8 +3559,7 @@ again:
 
                if (cache->disk_cache_state == BTRFS_DC_SETUP) {
                        cache->io_ctl.inode = NULL;
-                       ret = btrfs_write_out_cache(fs_info, trans,
-                                                   cache, path);
+                       ret = btrfs_write_out_cache(trans, cache, path);
                        if (ret == 0 && cache->io_ctl.inode) {
                                num_started++;
                                should_put = 0;
@@ -3736,9 +3649,9 @@ again:
        return ret;
 }
 
-int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
-                                  struct btrfs_fs_info *fs_info)
+int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
 {
+       struct btrfs_fs_info *fs_info = trans->fs_info;
        struct btrfs_block_group_cache *cache;
        struct btrfs_transaction *cur_trans = trans->transaction;
        int ret = 0;
@@ -3801,8 +3714,7 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
 
                if (!ret && cache->disk_cache_state == BTRFS_DC_SETUP) {
                        cache->io_ctl.inode = NULL;
-                       ret = btrfs_write_out_cache(fs_info, trans,
-                                                   cache, path);
+                       ret = btrfs_write_out_cache(trans, cache, path);
                        if (ret == 0 && cache->io_ctl.inode) {
                                num_started++;
                                should_put = 0;
@@ -6351,9 +6263,9 @@ void btrfs_delalloc_release_space(struct inode *inode,
 }
 
 static int update_block_group(struct btrfs_trans_handle *trans,
-                             struct btrfs_fs_info *info, u64 bytenr,
-                             u64 num_bytes, int alloc)
+                             u64 bytenr, u64 num_bytes, int alloc)
 {
+       struct btrfs_fs_info *info = trans->fs_info;
        struct btrfs_block_group_cache *cache = NULL;
        u64 total = num_bytes;
        u64 old_val;
@@ -6434,7 +6346,6 @@ static int update_block_group(struct btrfs_trans_handle *trans,
                if (list_empty(&cache->dirty_list)) {
                        list_add_tail(&cache->dirty_list,
                                      &trans->transaction->dirty_bgs);
-                       trans->transaction->num_dirty_bgs++;
                        trans->delayed_ref_updates++;
                        btrfs_get_block_group(cache);
                }
@@ -7188,7 +7099,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
                        goto out;
                }
 
-               ret = update_block_group(trans, info, bytenr, num_bytes, 0);
+               ret = update_block_group(trans, bytenr, num_bytes, 0);
                if (ret) {
                        btrfs_abort_transaction(trans, ret);
                        goto out;
@@ -8360,7 +8271,7 @@ static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
        if (ret)
                return ret;
 
-       ret = update_block_group(trans, fs_info, ins->objectid, ins->offset, 1);
+       ret = update_block_group(trans, ins->objectid, ins->offset, 1);
        if (ret) { /* -ENOENT, logic error */
                btrfs_err(fs_info, "update block group failed for %llu %llu",
                        ins->objectid, ins->offset);
@@ -8450,7 +8361,7 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans,
        if (ret)
                return ret;
 
-       ret = update_block_group(trans, fs_info, extent_key.objectid,
+       ret = update_block_group(trans, extent_key.objectid,
                                 fs_info->nodesize, 1);
        if (ret) { /* -ENOENT, logic error */
                btrfs_err(fs_info, "update block group failed for %llu %llu",
@@ -10139,7 +10050,7 @@ void btrfs_put_block_group_cache(struct btrfs_fs_info *info)
                        if (block_group->iref)
                                break;
                        spin_unlock(&block_group->lock);
-                       block_group = next_block_group(info, block_group);
+                       block_group = next_block_group(block_group);
                }
                if (!block_group) {
                        if (last == 0)
@@ -10640,7 +10551,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, u64 bytes_used,
        struct btrfs_block_group_cache *cache;
        int ret;
 
-       btrfs_set_log_full_commit(fs_info, trans);
+       btrfs_set_log_full_commit(trans);
 
        cache = btrfs_create_block_group_cache(fs_info, chunk_offset, size);
        if (!cache)
@@ -11385,7 +11296,7 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
        int ret = 0;
 
        cache = btrfs_lookup_first_block_group(fs_info, range->start);
-       for (; cache; cache = next_block_group(fs_info, cache)) {
+       for (; cache; cache = next_block_group(cache)) {
                if (cache->key.objectid >= (range->start + range->len)) {
                        btrfs_put_block_group(cache);
                        break;