Skip to content

Commit 49d08d5

Browse files
Coly Liaxboe
authored andcommitted
bcache: check return value of prio_read()
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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent d1c3cc3 commit 49d08d5

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

drivers/md/bcache/super.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,13 @@ int bch_prio_write(struct cache *ca, bool wait)
609609
return 0;
610610
}
611611

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

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

629630
if (p->csum !=
630-
bch_crc64(&p->magic, bucket_bytes(ca) - 8))
631+
bch_crc64(&p->magic, bucket_bytes(ca) - 8)) {
631632
pr_warn("bad csum reading priorities");
633+
goto out;
634+
}
632635

633-
if (p->magic != pset_magic(&ca->sb))
636+
if (p->magic != pset_magic(&ca->sb)) {
634637
pr_warn("bad magic reading priorities");
638+
goto out;
639+
}
635640

636641
bucket = p->next_bucket;
637642
d = p->data;
@@ -640,6 +645,10 @@ static void prio_read(struct cache *ca, uint64_t bucket)
640645
b->prio = le16_to_cpu(d->prio);
641646
b->gen = b->last_gc = d->gen;
642647
}
648+
649+
ret = 0;
650+
out:
651+
return ret;
643652
}
644653

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

18751884
err = "IO error reading priorities";
1876-
for_each_cache(ca, c, i)
1877-
prio_read(ca, j->prio_bucket[ca->sb.nr_this_dev]);
1885+
for_each_cache(ca, c, i) {
1886+
if (prio_read(ca, j->prio_bucket[ca->sb.nr_this_dev]))
1887+
goto err;
1888+
}
18781889

18791890
/*
18801891
* If prio_read() fails it'll call cache_set_error and we'll

0 commit comments

Comments
 (0)