summaryrefslogtreecommitdiffstats
path: root/drivers/lightnvm/pblk-core.c
diff options
context:
space:
mode:
authorJavier González <javier@javigon.com>2018-06-01 15:04:16 +0200
committerJens Axboe <axboe@kernel.dk>2018-06-01 07:43:53 -0600
commit1d8b33e05cea69a1b0b7f2f2a7c102b6583a984f (patch)
treee591e7a0e7ace394454241a3e42675dc34dff0c7 /drivers/lightnvm/pblk-core.c
parent2deeefc02dfff6b554020eb62aecf98814641372 (diff)
downloadblackbird-op-linux-1d8b33e05cea69a1b0b7f2f2a7c102b6583a984f.tar.gz
blackbird-op-linux-1d8b33e05cea69a1b0b7f2f2a7c102b6583a984f.zip
lightnvm: pblk: recheck for bad lines at runtime
Bad blocks can grow at runtime. Check that the number of valid blocks in a line are within the sanity threshold before allocating the line for new writes. Signed-off-by: Javier González <javier@cnexlabs.com> Signed-off-by: Matias Bjørling <mb@lightnvm.io> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/lightnvm/pblk-core.c')
-rw-r--r--drivers/lightnvm/pblk-core.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/drivers/lightnvm/pblk-core.c b/drivers/lightnvm/pblk-core.c
index 934341b10493..f34ce522348e 100644
--- a/drivers/lightnvm/pblk-core.c
+++ b/drivers/lightnvm/pblk-core.c
@@ -1174,7 +1174,8 @@ static int pblk_prepare_new_line(struct pblk *pblk, struct pblk_line *line)
static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line)
{
struct pblk_line_meta *lm = &pblk->lm;
- int blk_to_erase;
+ int blk_in_line = atomic_read(&line->blk_in_line);
+ int blk_to_erase, ret;
line->map_bitmap = kzalloc(lm->sec_bitmap_len, GFP_ATOMIC);
if (!line->map_bitmap)
@@ -1183,8 +1184,8 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line)
/* will be initialized using bb info from map_bitmap */
line->invalid_bitmap = kmalloc(lm->sec_bitmap_len, GFP_ATOMIC);
if (!line->invalid_bitmap) {
- kfree(line->map_bitmap);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto fail_free_map_bitmap;
}
/* Bad blocks do not need to be erased */
@@ -1199,16 +1200,19 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line)
blk_to_erase = pblk_prepare_new_line(pblk, line);
line->state = PBLK_LINESTATE_FREE;
} else {
- blk_to_erase = atomic_read(&line->blk_in_line);
+ blk_to_erase = blk_in_line;
+ }
+
+ if (blk_in_line < lm->min_blk_line) {
+ ret = -EAGAIN;
+ goto fail_free_invalid_bitmap;
}
if (line->state != PBLK_LINESTATE_FREE) {
- kfree(line->map_bitmap);
- kfree(line->invalid_bitmap);
- spin_unlock(&line->lock);
WARN(1, "pblk: corrupted line %d, state %d\n",
line->id, line->state);
- return -EAGAIN;
+ ret = -EINTR;
+ goto fail_free_invalid_bitmap;
}
line->state = PBLK_LINESTATE_OPEN;
@@ -1222,6 +1226,16 @@ static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line)
kref_init(&line->ref);
return 0;
+
+fail_free_invalid_bitmap:
+ spin_unlock(&line->lock);
+ kfree(line->invalid_bitmap);
+ line->invalid_bitmap = NULL;
+fail_free_map_bitmap:
+ kfree(line->map_bitmap);
+ line->map_bitmap = NULL;
+
+ return ret;
}
int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line)
@@ -1292,10 +1306,14 @@ retry:
ret = pblk_line_prepare(pblk, line);
if (ret) {
- if (ret == -EAGAIN) {
+ switch (ret) {
+ case -EAGAIN:
+ list_add(&line->list, &l_mg->bad_list);
+ goto retry;
+ case -EINTR:
list_add(&line->list, &l_mg->corrupt_list);
goto retry;
- } else {
+ default:
pr_err("pblk: failed to prepare line %d\n", line->id);
list_add(&line->list, &l_mg->free_list);
l_mg->nr_free_lines++;
OpenPOWER on IntegriCloud