Commit e3cb339f authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba
Browse files

btrfs: export the caching control helpers



Man a lot of people use this stuff.

Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 6f410d1b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -170,6 +170,9 @@ void btrfs_wait_block_group_cache_progress(struct btrfs_block_group_cache *cache
int btrfs_wait_block_group_cache_done(struct btrfs_block_group_cache *cache);
int btrfs_cache_block_group(struct btrfs_block_group_cache *cache,
			    int load_cache_only);
void btrfs_put_caching_control(struct btrfs_caching_control *ctl);
struct btrfs_caching_control *btrfs_get_caching_control(
		struct btrfs_block_group_cache *cache);

static inline int btrfs_block_group_cache_done(
		struct btrfs_block_group_cache *cache)
+18 −18
Original line number Diff line number Diff line
@@ -182,8 +182,8 @@ static int exclude_super_stripes(struct btrfs_block_group_cache *cache)
	return 0;
}

static struct btrfs_caching_control *
get_caching_control(struct btrfs_block_group_cache *cache)
struct btrfs_caching_control *btrfs_get_caching_control(
		struct btrfs_block_group_cache *cache)
{
	struct btrfs_caching_control *ctl;

@@ -199,7 +199,7 @@ get_caching_control(struct btrfs_block_group_cache *cache)
	return ctl;
}

static void put_caching_control(struct btrfs_caching_control *ctl)
void btrfs_put_caching_control(struct btrfs_caching_control *ctl)
{
	if (refcount_dec_and_test(&ctl->count))
		kfree(ctl);
@@ -455,7 +455,7 @@ static noinline void caching_thread(struct btrfs_work *work)

	wake_up(&caching_ctl->wait);

	put_caching_control(caching_ctl);
	btrfs_put_caching_control(caching_ctl);
	btrfs_put_block_group(block_group);
}

@@ -504,7 +504,7 @@ int btrfs_cache_block_group(struct btrfs_block_group_cache *cache,
		schedule();

		finish_wait(&ctl->wait, &wait);
		put_caching_control(ctl);
		btrfs_put_caching_control(ctl);
		spin_lock(&cache->lock);
	}

@@ -557,7 +557,7 @@ int btrfs_cache_block_group(struct btrfs_block_group_cache *cache,

		wake_up(&caching_ctl->wait);
		if (ret == 1) {
			put_caching_control(caching_ctl);
			btrfs_put_caching_control(caching_ctl);
			btrfs_free_excluded_extents(cache);
			return 0;
		}
@@ -579,7 +579,7 @@ int btrfs_cache_block_group(struct btrfs_block_group_cache *cache,
	}

	if (load_cache_only) {
		put_caching_control(caching_ctl);
		btrfs_put_caching_control(caching_ctl);
		return 0;
	}

@@ -4153,7 +4153,7 @@ static int __exclude_logged_extent(struct btrfs_fs_info *fs_info,
		return -EINVAL;

	btrfs_cache_block_group(block_group, 0);
	caching_ctl = get_caching_control(block_group);
	caching_ctl = btrfs_get_caching_control(block_group);

	if (!caching_ctl) {
		/* Logic error */
@@ -4183,7 +4183,7 @@ static int __exclude_logged_extent(struct btrfs_fs_info *fs_info,
		}
out_lock:
		mutex_unlock(&caching_ctl->mutex);
		put_caching_control(caching_ctl);
		btrfs_put_caching_control(caching_ctl);
	}
	btrfs_put_block_group(block_group);
	return ret;
@@ -4306,7 +4306,7 @@ void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info)
		if (btrfs_block_group_cache_done(cache)) {
			cache->last_byte_to_unpin = (u64)-1;
			list_del_init(&caching_ctl->list);
			put_caching_control(caching_ctl);
			btrfs_put_caching_control(caching_ctl);
		} else {
			cache->last_byte_to_unpin = caching_ctl->progress;
		}
@@ -4937,14 +4937,14 @@ void btrfs_wait_block_group_cache_progress(struct btrfs_block_group_cache *cache
{
	struct btrfs_caching_control *caching_ctl;

	caching_ctl = get_caching_control(cache);
	caching_ctl = btrfs_get_caching_control(cache);
	if (!caching_ctl)
		return;

	wait_event(caching_ctl->wait, btrfs_block_group_cache_done(cache) ||
		   (cache->free_space_ctl->free_space >= num_bytes));

	put_caching_control(caching_ctl);
	btrfs_put_caching_control(caching_ctl);
}

int btrfs_wait_block_group_cache_done(struct btrfs_block_group_cache *cache)
@@ -4952,14 +4952,14 @@ int btrfs_wait_block_group_cache_done(struct btrfs_block_group_cache *cache)
	struct btrfs_caching_control *caching_ctl;
	int ret = 0;

	caching_ctl = get_caching_control(cache);
	caching_ctl = btrfs_get_caching_control(cache);
	if (!caching_ctl)
		return (cache->cached == BTRFS_CACHE_ERROR) ? -EIO : 0;

	wait_event(caching_ctl->wait, btrfs_block_group_cache_done(cache));
	if (cache->cached == BTRFS_CACHE_ERROR)
		ret = -EIO;
	put_caching_control(caching_ctl);
	btrfs_put_caching_control(caching_ctl);
	return ret;
}

@@ -7482,7 +7482,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
		caching_ctl = list_entry(info->caching_block_groups.next,
					 struct btrfs_caching_control, list);
		list_del(&caching_ctl->list);
		put_caching_control(caching_ctl);
		btrfs_put_caching_control(caching_ctl);
	}
	up_write(&info->commit_root_sem);

@@ -8202,7 +8202,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
	}

	if (block_group->has_caching_ctl)
		caching_ctl = get_caching_control(block_group);
		caching_ctl = btrfs_get_caching_control(block_group);
	if (block_group->cached == BTRFS_CACHE_STARTED)
		btrfs_wait_block_group_cache_done(block_group);
	if (block_group->has_caching_ctl) {
@@ -8223,8 +8223,8 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
		up_write(&fs_info->commit_root_sem);
		if (caching_ctl) {
			/* Once for the caching bgs list and once for us. */
			put_caching_control(caching_ctl);
			put_caching_control(caching_ctl);
			btrfs_put_caching_control(caching_ctl);
			btrfs_put_caching_control(caching_ctl);
		}
	}