Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38a6dd2b authored by Coly Li's avatar Coly Li Committed by Greg Kroah-Hartman
Browse files

bcache: remove 'int n' from parameter list of bch_bucket_alloc_set()



[ Upstream commit 17e4aed8309ff28670271546c2c3263eb12f5eb6 ]

The parameter 'int n' from bch_bucket_alloc_set() is not cleared
defined. From the code comments n is the number of buckets to alloc, but
from the code itself 'n' is the maximum cache to iterate. Indeed all the
locations where bch_bucket_alloc_set() is called, 'n' is alwasy 1.

This patch removes the confused and unnecessary 'int n' from parameter
list of  bch_bucket_alloc_set(), and explicitly allocates only 1 bucket
for its caller.

Signed-off-by: default avatarColy Li <colyli@suse.de>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Stable-dep-of: 80fca8a10b60 ("bcache: Fix __bch_btree_node_alloc to make the failure behavior consistent")
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent edb81d6e
Loading
Loading
Loading
Loading
+15 −20
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@
 *
 * bch_bucket_alloc() allocates a single bucket from a specific cache.
 *
 * bch_bucket_alloc_set() allocates one or more buckets from different caches
 * bch_bucket_alloc_set() allocates one  bucket from different caches
 * out of a cache set.
 *
 * free_some_buckets() drives all the processes described above. It's called
@@ -488,34 +488,29 @@ void bch_bucket_free(struct cache_set *c, struct bkey *k)
}

int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
			   struct bkey *k, int n, bool wait)
			   struct bkey *k, bool wait)
{
	int i;
	struct cache *ca;
	long b;

	/* No allocation if CACHE_SET_IO_DISABLE bit is set */
	if (unlikely(test_bit(CACHE_SET_IO_DISABLE, &c->flags)))
		return -1;

	lockdep_assert_held(&c->bucket_lock);
	BUG_ON(!n || n > c->caches_loaded || n > MAX_CACHES_PER_SET);

	bkey_init(k);

	/* sort by free space/prio of oldest data in caches */

	for (i = 0; i < n; i++) {
		struct cache *ca = c->cache_by_alloc[i];
		long b = bch_bucket_alloc(ca, reserve, wait);

	ca = c->cache_by_alloc[0];
	b = bch_bucket_alloc(ca, reserve, wait);
	if (b == -1)
		goto err;

		k->ptr[i] = MAKE_PTR(ca->buckets[b].gen,
	k->ptr[0] = MAKE_PTR(ca->buckets[b].gen,
			     bucket_to_sector(c, b),
			     ca->sb.nr_this_dev);

		SET_KEY_PTRS(k, i + 1);
	}
	SET_KEY_PTRS(k, 1);

	return 0;
err:
@@ -525,12 +520,12 @@ int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
}

int bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
			 struct bkey *k, int n, bool wait)
			 struct bkey *k, bool wait)
{
	int ret;

	mutex_lock(&c->bucket_lock);
	ret = __bch_bucket_alloc_set(c, reserve, k, n, wait);
	ret = __bch_bucket_alloc_set(c, reserve, k, wait);
	mutex_unlock(&c->bucket_lock);
	return ret;
}
@@ -638,7 +633,7 @@ bool bch_alloc_sectors(struct cache_set *c,

		spin_unlock(&c->data_bucket_lock);

		if (bch_bucket_alloc_set(c, watermark, &alloc.key, 1, wait))
		if (bch_bucket_alloc_set(c, watermark, &alloc.key, wait))
			return false;

		spin_lock(&c->data_bucket_lock);
+2 −2
Original line number Diff line number Diff line
@@ -970,9 +970,9 @@ void bch_bucket_free(struct cache_set *c, struct bkey *k);

long bch_bucket_alloc(struct cache *ca, unsigned int reserve, bool wait);
int __bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
			   struct bkey *k, int n, bool wait);
			   struct bkey *k, bool wait);
int bch_bucket_alloc_set(struct cache_set *c, unsigned int reserve,
			 struct bkey *k, int n, bool wait);
			 struct bkey *k, bool wait);
bool bch_alloc_sectors(struct cache_set *c, struct bkey *k,
		       unsigned int sectors, unsigned int write_point,
		       unsigned int write_prio, bool wait);
+1 −1
Original line number Diff line number Diff line
@@ -1141,7 +1141,7 @@ struct btree *__bch_btree_node_alloc(struct cache_set *c, struct btree_op *op,

	mutex_lock(&c->bucket_lock);
retry:
	if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, wait))
	if (__bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, wait))
		goto err;

	bkey_put(c, &k.key);
+1 −1
Original line number Diff line number Diff line
@@ -428,7 +428,7 @@ static int __uuid_write(struct cache_set *c)
	closure_init_stack(&cl);
	lockdep_assert_held(&bch_register_lock);

	if (bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, true))
	if (bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, true))
		return 1;

	SET_KEY_SIZE(&k.key, c->sb.bucket_size);