Skip to content

Commit

Permalink
bcache: check return value of prio_read()
Browse files Browse the repository at this point in the history
Now if prio_read() failed during starting a cache set, we can print
out error message in run_cache_set() and handle the failure properly.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Coly Li authored and Jens Axboe committed Feb 1, 2020
1 parent d1c3cc3 commit 49d08d5
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions drivers/md/bcache/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,13 @@ int bch_prio_write(struct cache *ca, bool wait)
return 0;
}

static void prio_read(struct cache *ca, uint64_t bucket)
static int prio_read(struct cache *ca, uint64_t bucket)
{
struct prio_set *p = ca->disk_buckets;
struct bucket_disk *d = p->data + prios_per_bucket(ca), *end = d;
struct bucket *b;
unsigned int bucket_nr = 0;
int ret = -EIO;

for (b = ca->buckets;
b < ca->buckets + ca->sb.nbuckets;
Expand All @@ -627,11 +628,15 @@ static void prio_read(struct cache *ca, uint64_t bucket)
prio_io(ca, bucket, REQ_OP_READ, 0);

if (p->csum !=
bch_crc64(&p->magic, bucket_bytes(ca) - 8))
bch_crc64(&p->magic, bucket_bytes(ca) - 8)) {
pr_warn("bad csum reading priorities");
goto out;
}

if (p->magic != pset_magic(&ca->sb))
if (p->magic != pset_magic(&ca->sb)) {
pr_warn("bad magic reading priorities");
goto out;
}

bucket = p->next_bucket;
d = p->data;
Expand All @@ -640,6 +645,10 @@ static void prio_read(struct cache *ca, uint64_t bucket)
b->prio = le16_to_cpu(d->prio);
b->gen = b->last_gc = d->gen;
}

ret = 0;
out:
return ret;
}

/* Bcache device */
Expand Down Expand Up @@ -1873,8 +1882,10 @@ static int run_cache_set(struct cache_set *c)
j = &list_entry(journal.prev, struct journal_replay, list)->j;

err = "IO error reading priorities";
for_each_cache(ca, c, i)
prio_read(ca, j->prio_bucket[ca->sb.nr_this_dev]);
for_each_cache(ca, c, i) {
if (prio_read(ca, j->prio_bucket[ca->sb.nr_this_dev]))
goto err;
}

/*
* If prio_read() fails it'll call cache_set_error and we'll
Expand Down

0 comments on commit 49d08d5

Please sign in to comment.