lightnvm: pblk: refactor emeta consistency check
authorHans Holmberg <hans.holmberg@cnexlabs.com>
Fri, 5 Jan 2018 13:16:08 +0000 (14:16 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 5 Jan 2018 15:50:12 +0000 (08:50 -0700)
Currently pblk_recov_get_lba list does two separate things:
it checks the consistency of the emeta and extracts the lba list.

This patch separates the consistency check to make the code easier
to read and to prepare for version checks of the line emeta
persistent data format version.

Signed-off-by: Hans Holmberg <hans.holmberg@cnexlabs.com>
Signed-off-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/lightnvm/pblk-gc.c
drivers/lightnvm/pblk-recovery.c
drivers/lightnvm/pblk.h

index 9c8e114c8a545ca45cbea56660a2838f4a67e812..cec9a56dda146712ef06a917afaf1c326f67385e 100644 (file)
@@ -169,7 +169,14 @@ static void pblk_gc_line_prepare_ws(struct work_struct *work)
         * the line untouched. TODO: Implement a recovery routine that scans and
         * moves all sectors on the line.
         */
-       lba_list = pblk_recov_get_lba_list(pblk, emeta_buf);
+
+       ret = pblk_recov_check_emeta(pblk, emeta_buf);
+       if (ret) {
+               pr_err("pblk: inconsistent emeta (line %d)\n", line->id);
+               goto fail_free_emeta;
+       }
+
+       lba_list = emeta_to_lbas(pblk, emeta_buf);
        if (!lba_list) {
                pr_err("pblk: could not interpret emeta (line %d)\n", line->id);
                goto fail_free_emeta;
index 1b272ae8a315af2cee175de970a37ea3add7a652..39a2e193edcc24cd1c34d722a74556fb7d1632d5 100644 (file)
@@ -111,18 +111,18 @@ int pblk_recov_setup_rq(struct pblk *pblk, struct pblk_c_ctx *c_ctx,
        return 0;
 }
 
-__le64 *pblk_recov_get_lba_list(struct pblk *pblk, struct line_emeta *emeta_buf)
+int pblk_recov_check_emeta(struct pblk *pblk, struct line_emeta *emeta_buf)
 {
        u32 crc;
 
        crc = pblk_calc_emeta_crc(pblk, emeta_buf);
        if (le32_to_cpu(emeta_buf->crc) != crc)
-               return NULL;
+               return 1;
 
        if (le32_to_cpu(emeta_buf->header.identifier) != PBLK_MAGIC)
-               return NULL;
+               return 1;
 
-       return emeta_to_lbas(pblk, emeta_buf);
+       return 0;
 }
 
 static int pblk_recov_l2p_from_emeta(struct pblk *pblk, struct pblk_line *line)
@@ -137,7 +137,7 @@ static int pblk_recov_l2p_from_emeta(struct pblk *pblk, struct pblk_line *line)
        u64 nr_valid_lbas, nr_lbas = 0;
        u64 i;
 
-       lba_list = pblk_recov_get_lba_list(pblk, emeta_buf);
+       lba_list = emeta_to_lbas(pblk, emeta_buf);
        if (!lba_list)
                return 1;
 
@@ -938,6 +938,11 @@ struct pblk_line *pblk_recov_l2p(struct pblk *pblk)
                        goto next;
                }
 
+               if (pblk_recov_check_emeta(pblk, line->emeta->buf)) {
+                       pblk_recov_l2p_from_oob(pblk, line);
+                       goto next;
+               }
+
                if (pblk_recov_l2p_from_emeta(pblk, line))
                        pblk_recov_l2p_from_oob(pblk, line);
 
index 1dbb0bf4d9a328a064c7cf774a25497c2683cfa6..8851b18bb0991578ea6fd8b40b807beacb71b056 100644 (file)
@@ -808,7 +808,7 @@ int pblk_submit_read_gc(struct pblk *pblk, struct pblk_gc_rq *gc_rq);
 void pblk_submit_rec(struct work_struct *work);
 struct pblk_line *pblk_recov_l2p(struct pblk *pblk);
 int pblk_recov_pad(struct pblk *pblk);
-__le64 *pblk_recov_get_lba_list(struct pblk *pblk, struct line_emeta *emeta);
+int pblk_recov_check_emeta(struct pblk *pblk, struct line_emeta *emeta);
 int pblk_recov_setup_rq(struct pblk *pblk, struct pblk_c_ctx *c_ctx,
                        struct pblk_rec_ctx *recovery, u64 *comp_bits,
                        unsigned int comp);