summaryrefslogtreecommitdiff
path: root/libbcache/alloc.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2017-03-09 08:27:30 -0900
committerKent Overstreet <kent.overstreet@gmail.com>2017-03-09 09:14:11 -0900
commitac1b32acb4ca8c59c0e4911a8d3b27fd72dc54af (patch)
treee73a6ea5ddb6f3ece6a3e6c069ffa9ecc5e1ee44 /libbcache/alloc.c
parenta17f7bcec7ed810a247c24e56229af8f43a9a6ae (diff)
cmd_device_fail
Add a comamnd for setting a device as failed, update bcache sources
Diffstat (limited to 'libbcache/alloc.c')
-rw-r--r--libbcache/alloc.c49
1 files changed, 22 insertions, 27 deletions
diff --git a/libbcache/alloc.c b/libbcache/alloc.c
index 93f0c2f1..a0f8d64f 100644
--- a/libbcache/alloc.c
+++ b/libbcache/alloc.c
@@ -138,7 +138,7 @@ static void pd_controllers_update(struct work_struct *work)
-1);
group_for_each_cache_rcu(ca, &c->tiers[i].devs, iter) {
- struct bucket_stats_cache stats = bch_bucket_stats_read_cache(ca);
+ struct bch_dev_usage stats = bch_dev_usage_read(ca);
unsigned bucket_bits = ca->bucket_bits + 9;
u64 size = (ca->mi.nbuckets -
@@ -1304,9 +1304,7 @@ static unsigned open_bucket_sectors_free(struct cache_set *c,
struct cache_member_rcu *mi = cache_member_info_get(c);
unsigned i, sectors_free = UINT_MAX;
- BUG_ON(nr_replicas > ob->nr_ptrs);
-
- for (i = 0; i < nr_replicas; i++)
+ for (i = 0; i < min(nr_replicas, ob->nr_ptrs); i++)
sectors_free = min(sectors_free,
ob_ptr_sectors_free(ob, mi, &ob->ptrs[i]));
@@ -1369,11 +1367,13 @@ static int open_bucket_add_buckets(struct cache_set *c,
struct write_point *wp,
struct open_bucket *ob,
unsigned nr_replicas,
+ unsigned nr_replicas_required,
enum alloc_reserve reserve,
struct closure *cl)
{
long caches_used[BITS_TO_LONGS(BCH_SB_MEMBERS_MAX)];
- int i, dst;
+ unsigned i;
+ int ret;
/*
* We might be allocating pointers to add to an existing extent
@@ -1388,23 +1388,17 @@ static int open_bucket_add_buckets(struct cache_set *c,
memset(caches_used, 0, sizeof(caches_used));
- /*
- * Shuffle pointers to devices we already have to the end:
- * bch_bucket_alloc_set() will add new pointers to the statr of @b, and
- * bch_alloc_sectors_done() will add the first nr_replicas ptrs to @e:
- */
- for (i = dst = ob->nr_ptrs - 1; i >= 0; --i)
- if (__test_and_set_bit(ob->ptrs[i].dev, caches_used)) {
- if (i != dst) {
- swap(ob->ptrs[i], ob->ptrs[dst]);
- swap(ob->ptr_offset[i], ob->ptr_offset[dst]);
- }
- --dst;
- nr_replicas++;
- }
+ for (i = 0; i < ob->nr_ptrs; i++)
+ __set_bit(ob->ptrs[i].dev, caches_used);
+
+ ret = bch_bucket_alloc_set(c, wp, ob, nr_replicas,
+ reserve, caches_used, cl);
+
+ if (ret == -EROFS &&
+ ob->nr_ptrs >= nr_replicas_required)
+ ret = 0;
- return bch_bucket_alloc_set(c, wp, ob, nr_replicas,
- reserve, caches_used, cl);
+ return ret;
}
/*
@@ -1413,6 +1407,7 @@ static int open_bucket_add_buckets(struct cache_set *c,
struct open_bucket *bch_alloc_sectors_start(struct cache_set *c,
struct write_point *wp,
unsigned nr_replicas,
+ unsigned nr_replicas_required,
enum alloc_reserve reserve,
struct closure *cl)
{
@@ -1466,6 +1461,7 @@ retry:
}
ret = open_bucket_add_buckets(c, wp, ob, nr_replicas,
+ nr_replicas_required,
reserve, cl);
if (ret) {
mutex_unlock(&ob->lock);
@@ -1498,10 +1494,6 @@ void bch_alloc_sectors_append_ptrs(struct cache_set *c, struct bkey_i_extent *e,
* __bch_write() will only write to the pointers we add here:
*/
- /*
- * XXX: don't add pointers to devices @e already has
- */
- BUG_ON(nr_replicas > ob->nr_ptrs);
BUG_ON(sectors > ob->sectors_free);
/* didn't use all the ptrs: */
@@ -1510,7 +1502,7 @@ void bch_alloc_sectors_append_ptrs(struct cache_set *c, struct bkey_i_extent *e,
rcu_read_lock();
- for (i = 0; i < nr_replicas; i++) {
+ for (i = 0; i < min(ob->nr_ptrs, nr_replicas); i++) {
EBUG_ON(bch_extent_has_device(extent_i_to_s_c(e), ob->ptrs[i].dev));
tmp = ob->ptrs[i];
@@ -1576,12 +1568,15 @@ struct open_bucket *bch_alloc_sectors(struct cache_set *c,
struct write_point *wp,
struct bkey_i_extent *e,
unsigned nr_replicas,
+ unsigned nr_replicas_required,
enum alloc_reserve reserve,
struct closure *cl)
{
struct open_bucket *ob;
- ob = bch_alloc_sectors_start(c, wp, nr_replicas, reserve, cl);
+ ob = bch_alloc_sectors_start(c, wp, nr_replicas,
+ nr_replicas_required,
+ reserve, cl);
if (IS_ERR_OR_NULL(ob))
return ob;