Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcache: explicitly make cache_set only have single cache

Currently although the bcache code has a framework for multiple caches
in a cache set, but indeed the multiple caches never completed and users
use md raid1 for multiple copies of the cached data.

This patch does the following change in struct cache_set, to explicitly
make a cache_set only have single cache,
- Change pointer array "*cache[MAX_CACHES_PER_SET]" to a single pointer
"*cache".
- Remove pointer array "*cache_by_alloc[MAX_CACHES_PER_SET]".
- Remove "caches_loaded".

Now the code looks as exactly what it does in practic: only one cache is
used in the cache set.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Coly Li and committed by
Jens Axboe
697e2349 17e4aed8

+12 -17
+1 -1
drivers/md/bcache/alloc.c
··· 501 501 502 502 bkey_init(k); 503 503 504 - ca = c->cache_by_alloc[0]; 504 + ca = c->cache; 505 505 b = bch_bucket_alloc(ca, reserve, wait); 506 506 if (b == -1) 507 507 goto err;
+3 -5
drivers/md/bcache/bcache.h
··· 519 519 520 520 struct cache_sb sb; 521 521 522 - struct cache *cache[MAX_CACHES_PER_SET]; 523 - struct cache *cache_by_alloc[MAX_CACHES_PER_SET]; 524 - int caches_loaded; 522 + struct cache *cache; 525 523 526 524 struct bcache_device **devices; 527 525 unsigned int devices_max_used; ··· 806 808 const struct bkey *k, 807 809 unsigned int ptr) 808 810 { 809 - return c->cache[PTR_DEV(k, ptr)]; 811 + return c->cache; 810 812 } 811 813 812 814 static inline size_t PTR_BUCKET_NR(struct cache_set *c, ··· 888 890 /* Looping macros */ 889 891 890 892 #define for_each_cache(ca, cs, iter) \ 891 - for (iter = 0; ca = cs->cache[iter], iter < (cs)->sb.nr_in_set; iter++) 893 + for (iter = 0; ca = cs->cache, iter < 1; iter++) 892 894 893 895 #define for_each_bucket(b, ca) \ 894 896 for (b = (ca)->buckets + (ca)->sb.first_bucket; \
+8 -11
drivers/md/bcache/super.c
··· 1674 1674 for_each_cache(ca, c, i) 1675 1675 if (ca) { 1676 1676 ca->set = NULL; 1677 - c->cache[ca->sb.nr_this_dev] = NULL; 1677 + c->cache = NULL; 1678 1678 kobject_put(&ca->kobj); 1679 1679 } 1680 1680 ··· 2165 2165 2166 2166 list_for_each_entry(c, &bch_cache_sets, list) 2167 2167 if (!memcmp(c->sb.set_uuid, ca->sb.set_uuid, 16)) { 2168 - if (c->cache[ca->sb.nr_this_dev]) 2168 + if (c->cache) 2169 2169 return "duplicate cache set member"; 2170 2170 2171 2171 if (!can_attach_cache(ca, c)) ··· 2215 2215 2216 2216 kobject_get(&ca->kobj); 2217 2217 ca->set = c; 2218 - ca->set->cache[ca->sb.nr_this_dev] = ca; 2219 - c->cache_by_alloc[c->caches_loaded++] = ca; 2218 + ca->set->cache = ca; 2220 2219 2221 - if (c->caches_loaded == c->sb.nr_in_set) { 2222 - err = "failed to run cache set"; 2223 - if (run_cache_set(c) < 0) 2224 - goto err; 2225 - } 2220 + err = "failed to run cache set"; 2221 + if (run_cache_set(c) < 0) 2222 + goto err; 2226 2223 2227 2224 return NULL; 2228 2225 err: ··· 2236 2239 unsigned int i; 2237 2240 2238 2241 if (ca->set) { 2239 - BUG_ON(ca->set->cache[ca->sb.nr_this_dev] != ca); 2240 - ca->set->cache[ca->sb.nr_this_dev] = NULL; 2242 + BUG_ON(ca->set->cache != ca); 2243 + ca->set->cache = NULL; 2241 2244 } 2242 2245 2243 2246 free_pages((unsigned long) ca->disk_buckets, ilog2(meta_bucket_pages(&ca->sb)));