Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 CNEX Labs |
| 3 | * Initial: Javier Gonzalez <javier@cnexlabs.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version |
| 7 | * 2 as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * General Public License for more details. |
| 13 | * |
| 14 | * pblk-recovery.c - pblk's recovery path |
| 15 | */ |
| 16 | |
| 17 | #include "pblk.h" |
| 18 | |
Hans Holmberg | 06bc072 | 2018-01-05 14:16:08 +0100 | [diff] [blame] | 19 | int pblk_recov_check_emeta(struct pblk *pblk, struct line_emeta *emeta_buf) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 20 | { |
| 21 | u32 crc; |
| 22 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 23 | crc = pblk_calc_emeta_crc(pblk, emeta_buf); |
| 24 | if (le32_to_cpu(emeta_buf->crc) != crc) |
Hans Holmberg | 06bc072 | 2018-01-05 14:16:08 +0100 | [diff] [blame] | 25 | return 1; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 26 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 27 | if (le32_to_cpu(emeta_buf->header.identifier) != PBLK_MAGIC) |
Hans Holmberg | 06bc072 | 2018-01-05 14:16:08 +0100 | [diff] [blame] | 28 | return 1; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 29 | |
Hans Holmberg | 06bc072 | 2018-01-05 14:16:08 +0100 | [diff] [blame] | 30 | return 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static int pblk_recov_l2p_from_emeta(struct pblk *pblk, struct pblk_line *line) |
| 34 | { |
| 35 | struct nvm_tgt_dev *dev = pblk->dev; |
| 36 | struct nvm_geo *geo = &dev->geo; |
| 37 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 38 | struct pblk_emeta *emeta = line->emeta; |
| 39 | struct line_emeta *emeta_buf = emeta->buf; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 40 | __le64 *lba_list; |
Hans Holmberg | 75610cd | 2017-10-13 14:46:38 +0200 | [diff] [blame] | 41 | u64 data_start, data_end; |
| 42 | u64 nr_valid_lbas, nr_lbas = 0; |
| 43 | u64 i; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 44 | |
Hans Holmberg | 06bc072 | 2018-01-05 14:16:08 +0100 | [diff] [blame] | 45 | lba_list = emeta_to_lbas(pblk, emeta_buf); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 46 | if (!lba_list) |
| 47 | return 1; |
| 48 | |
| 49 | data_start = pblk_line_smeta_start(pblk, line) + lm->smeta_sec; |
Hans Holmberg | 75610cd | 2017-10-13 14:46:38 +0200 | [diff] [blame] | 50 | data_end = line->emeta_ssec; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 51 | nr_valid_lbas = le64_to_cpu(emeta_buf->nr_valid_lbas); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 52 | |
Hans Holmberg | 9295709 | 2017-10-13 14:46:35 +0200 | [diff] [blame] | 53 | for (i = data_start; i < data_end; i++) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 54 | struct ppa_addr ppa; |
| 55 | int pos; |
| 56 | |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 57 | ppa = addr_to_gen_ppa(pblk, i, line->id); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 58 | pos = pblk_ppa_to_pos(geo, ppa); |
| 59 | |
| 60 | /* Do not update bad blocks */ |
| 61 | if (test_bit(pos, line->blk_bitmap)) |
| 62 | continue; |
| 63 | |
| 64 | if (le64_to_cpu(lba_list[i]) == ADDR_EMPTY) { |
| 65 | spin_lock(&line->lock); |
| 66 | if (test_and_set_bit(i, line->invalid_bitmap)) |
Dan Carpenter | 2a79efd | 2017-04-15 20:55:52 +0200 | [diff] [blame] | 67 | WARN_ONCE(1, "pblk: rec. double invalidate:\n"); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 68 | else |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 69 | le32_add_cpu(line->vsc, -1); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 70 | spin_unlock(&line->lock); |
| 71 | |
| 72 | continue; |
| 73 | } |
| 74 | |
| 75 | pblk_update_map(pblk, le64_to_cpu(lba_list[i]), ppa); |
| 76 | nr_lbas++; |
| 77 | } |
| 78 | |
| 79 | if (nr_valid_lbas != nr_lbas) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 80 | pblk_err(pblk, "line %d - inconsistent lba list(%llu/%llu)\n", |
Hans Holmberg | 75610cd | 2017-10-13 14:46:38 +0200 | [diff] [blame] | 81 | line->id, nr_valid_lbas, nr_lbas); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 82 | |
| 83 | line->left_msecs = 0; |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int pblk_calc_sec_in_line(struct pblk *pblk, struct pblk_line *line) |
| 89 | { |
| 90 | struct nvm_tgt_dev *dev = pblk->dev; |
| 91 | struct nvm_geo *geo = &dev->geo; |
| 92 | struct pblk_line_meta *lm = &pblk->lm; |
| 93 | int nr_bb = bitmap_weight(line->blk_bitmap, lm->blk_per_line); |
| 94 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 95 | return lm->sec_per_line - lm->smeta_sec - lm->emeta_sec[0] - |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 96 | nr_bb * geo->clba; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | struct pblk_recov_alloc { |
| 100 | struct ppa_addr *ppa_list; |
| 101 | struct pblk_sec_meta *meta_list; |
| 102 | struct nvm_rq *rqd; |
| 103 | void *data; |
| 104 | dma_addr_t dma_ppa_list; |
| 105 | dma_addr_t dma_meta_list; |
| 106 | }; |
| 107 | |
| 108 | static int pblk_recov_read_oob(struct pblk *pblk, struct pblk_line *line, |
| 109 | struct pblk_recov_alloc p, u64 r_ptr) |
| 110 | { |
| 111 | struct nvm_tgt_dev *dev = pblk->dev; |
| 112 | struct nvm_geo *geo = &dev->geo; |
| 113 | struct ppa_addr *ppa_list; |
| 114 | struct pblk_sec_meta *meta_list; |
| 115 | struct nvm_rq *rqd; |
| 116 | struct bio *bio; |
| 117 | void *data; |
| 118 | dma_addr_t dma_ppa_list, dma_meta_list; |
| 119 | u64 r_ptr_int; |
| 120 | int left_ppas; |
| 121 | int rq_ppas, rq_len; |
| 122 | int i, j; |
| 123 | int ret = 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 124 | |
| 125 | ppa_list = p.ppa_list; |
| 126 | meta_list = p.meta_list; |
| 127 | rqd = p.rqd; |
| 128 | data = p.data; |
| 129 | dma_ppa_list = p.dma_ppa_list; |
| 130 | dma_meta_list = p.dma_meta_list; |
| 131 | |
| 132 | left_ppas = line->cur_sec - r_ptr; |
| 133 | if (!left_ppas) |
| 134 | return 0; |
| 135 | |
| 136 | r_ptr_int = r_ptr; |
| 137 | |
| 138 | next_read_rq: |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 139 | memset(rqd, 0, pblk_g_rq_size); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 140 | |
| 141 | rq_ppas = pblk_calc_secs(pblk, left_ppas, 0); |
| 142 | if (!rq_ppas) |
| 143 | rq_ppas = pblk->min_write_pgs; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 144 | rq_len = rq_ppas * geo->csecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 145 | |
| 146 | bio = bio_map_kern(dev->q, data, rq_len, GFP_KERNEL); |
| 147 | if (IS_ERR(bio)) |
| 148 | return PTR_ERR(bio); |
| 149 | |
| 150 | bio->bi_iter.bi_sector = 0; /* internal bio */ |
| 151 | bio_set_op_attrs(bio, REQ_OP_READ, 0); |
| 152 | |
| 153 | rqd->bio = bio; |
| 154 | rqd->opcode = NVM_OP_PREAD; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 155 | rqd->meta_list = meta_list; |
| 156 | rqd->nr_ppas = rq_ppas; |
| 157 | rqd->ppa_list = ppa_list; |
| 158 | rqd->dma_ppa_list = dma_ppa_list; |
| 159 | rqd->dma_meta_list = dma_meta_list; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 160 | |
Javier González | f9c1015 | 2017-06-26 11:57:20 +0200 | [diff] [blame] | 161 | if (pblk_io_aligned(pblk, rq_ppas)) |
Matias Bjørling | d7b6801 | 2018-10-09 13:11:32 +0200 | [diff] [blame] | 162 | rqd->is_seq = 1; |
Javier González | f9c1015 | 2017-06-26 11:57:20 +0200 | [diff] [blame] | 163 | |
Hans Holmberg | d68a934 | 2018-10-09 13:11:46 +0200 | [diff] [blame^] | 164 | ppa_list = nvm_rq_to_ppa_list(rqd); |
| 165 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 166 | for (i = 0; i < rqd->nr_ppas; ) { |
| 167 | struct ppa_addr ppa; |
| 168 | int pos; |
| 169 | |
| 170 | ppa = addr_to_gen_ppa(pblk, r_ptr_int, line->id); |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 171 | pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 172 | |
| 173 | while (test_bit(pos, line->blk_bitmap)) { |
| 174 | r_ptr_int += pblk->min_write_pgs; |
| 175 | ppa = addr_to_gen_ppa(pblk, r_ptr_int, line->id); |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 176 | pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | for (j = 0; j < pblk->min_write_pgs; j++, i++, r_ptr_int++) |
Hans Holmberg | d68a934 | 2018-10-09 13:11:46 +0200 | [diff] [blame^] | 180 | ppa_list[i] = |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 181 | addr_to_gen_ppa(pblk, r_ptr_int, line->id); |
| 182 | } |
| 183 | |
| 184 | /* If read fails, more padding is needed */ |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 185 | ret = pblk_submit_io_sync(pblk, rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 186 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 187 | pblk_err(pblk, "I/O submission failed: %d\n", ret); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 188 | return ret; |
| 189 | } |
| 190 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 191 | atomic_dec(&pblk->inflight_io); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 192 | |
| 193 | /* At this point, the read should not fail. If it does, it is a problem |
| 194 | * we cannot recover from here. Need FTL log. |
| 195 | */ |
Javier González | 5d201f0 | 2018-01-05 14:16:15 +0100 | [diff] [blame] | 196 | if (rqd->error && rqd->error != NVM_RSP_WARN_HIGHECC) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 197 | pblk_err(pblk, "L2P recovery failed (%d)\n", rqd->error); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 198 | return -EINTR; |
| 199 | } |
| 200 | |
| 201 | for (i = 0; i < rqd->nr_ppas; i++) { |
| 202 | u64 lba = le64_to_cpu(meta_list[i].lba); |
| 203 | |
| 204 | if (lba == ADDR_EMPTY || lba > pblk->rl.nr_secs) |
| 205 | continue; |
| 206 | |
Hans Holmberg | d68a934 | 2018-10-09 13:11:46 +0200 | [diff] [blame^] | 207 | pblk_update_map(pblk, lba, ppa_list[i]); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | left_ppas -= rq_ppas; |
| 211 | if (left_ppas > 0) |
| 212 | goto next_read_rq; |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 217 | static void pblk_recov_complete(struct kref *ref) |
| 218 | { |
| 219 | struct pblk_pad_rq *pad_rq = container_of(ref, struct pblk_pad_rq, ref); |
| 220 | |
| 221 | complete(&pad_rq->wait); |
| 222 | } |
| 223 | |
| 224 | static void pblk_end_io_recov(struct nvm_rq *rqd) |
| 225 | { |
Hans Holmberg | d68a934 | 2018-10-09 13:11:46 +0200 | [diff] [blame^] | 226 | struct ppa_addr *ppa_list = nvm_rq_to_ppa_list(rqd); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 227 | struct pblk_pad_rq *pad_rq = rqd->private; |
| 228 | struct pblk *pblk = pad_rq->pblk; |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 229 | |
Hans Holmberg | d68a934 | 2018-10-09 13:11:46 +0200 | [diff] [blame^] | 230 | pblk_up_page(pblk, ppa_list, rqd->nr_ppas); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 231 | |
Javier González | e2cddf2 | 2017-10-13 14:46:19 +0200 | [diff] [blame] | 232 | pblk_free_rqd(pblk, rqd, PBLK_WRITE_INT); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 233 | |
| 234 | atomic_dec(&pblk->inflight_io); |
| 235 | kref_put(&pad_rq->ref, pblk_recov_complete); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 236 | } |
| 237 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 238 | static int pblk_recov_pad_oob(struct pblk *pblk, struct pblk_line *line, |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 239 | int left_ppas) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 240 | { |
| 241 | struct nvm_tgt_dev *dev = pblk->dev; |
| 242 | struct nvm_geo *geo = &dev->geo; |
| 243 | struct ppa_addr *ppa_list; |
| 244 | struct pblk_sec_meta *meta_list; |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 245 | struct pblk_pad_rq *pad_rq; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 246 | struct nvm_rq *rqd; |
| 247 | struct bio *bio; |
| 248 | void *data; |
| 249 | dma_addr_t dma_ppa_list, dma_meta_list; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 250 | __le64 *lba_list = emeta_to_lbas(pblk, line->emeta->buf); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 251 | u64 w_ptr = line->cur_sec; |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 252 | int left_line_ppas, rq_ppas, rq_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 253 | int i, j; |
| 254 | int ret = 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 255 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 256 | spin_lock(&line->lock); |
| 257 | left_line_ppas = line->left_msecs; |
| 258 | spin_unlock(&line->lock); |
| 259 | |
| 260 | pad_rq = kmalloc(sizeof(struct pblk_pad_rq), GFP_KERNEL); |
| 261 | if (!pad_rq) |
| 262 | return -ENOMEM; |
| 263 | |
Kees Cook | fad953c | 2018-06-12 14:27:37 -0700 | [diff] [blame] | 264 | data = vzalloc(array_size(pblk->max_write_pgs, geo->csecs)); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 265 | if (!data) { |
| 266 | ret = -ENOMEM; |
| 267 | goto free_rq; |
| 268 | } |
| 269 | |
| 270 | pad_rq->pblk = pblk; |
| 271 | init_completion(&pad_rq->wait); |
| 272 | kref_init(&pad_rq->ref); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 273 | |
| 274 | next_pad_rq: |
| 275 | rq_ppas = pblk_calc_secs(pblk, left_ppas, 0); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 276 | if (rq_ppas < pblk->min_write_pgs) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 277 | pblk_err(pblk, "corrupted pad line %d\n", line->id); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 278 | goto fail_free_pad; |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 281 | rq_len = rq_ppas * geo->csecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 282 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 283 | meta_list = nvm_dev_dma_alloc(dev->parent, GFP_KERNEL, &dma_meta_list); |
| 284 | if (!meta_list) { |
| 285 | ret = -ENOMEM; |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 286 | goto fail_free_pad; |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | ppa_list = (void *)(meta_list) + pblk_dma_meta_size; |
| 290 | dma_ppa_list = dma_meta_list + pblk_dma_meta_size; |
| 291 | |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 292 | bio = pblk_bio_map_addr(pblk, data, rq_ppas, rq_len, |
| 293 | PBLK_VMALLOC_META, GFP_KERNEL); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 294 | if (IS_ERR(bio)) { |
| 295 | ret = PTR_ERR(bio); |
Javier González | 2942f50 | 2017-10-13 14:46:10 +0200 | [diff] [blame] | 296 | goto fail_free_meta; |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 297 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 298 | |
| 299 | bio->bi_iter.bi_sector = 0; /* internal bio */ |
| 300 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); |
| 301 | |
Javier González | e2cddf2 | 2017-10-13 14:46:19 +0200 | [diff] [blame] | 302 | rqd = pblk_alloc_rqd(pblk, PBLK_WRITE_INT); |
Javier González | 2942f50 | 2017-10-13 14:46:10 +0200 | [diff] [blame] | 303 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 304 | rqd->bio = bio; |
| 305 | rqd->opcode = NVM_OP_PWRITE; |
Matias Bjørling | d7b6801 | 2018-10-09 13:11:32 +0200 | [diff] [blame] | 306 | rqd->is_seq = 1; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 307 | rqd->meta_list = meta_list; |
| 308 | rqd->nr_ppas = rq_ppas; |
| 309 | rqd->ppa_list = ppa_list; |
| 310 | rqd->dma_ppa_list = dma_ppa_list; |
| 311 | rqd->dma_meta_list = dma_meta_list; |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 312 | rqd->end_io = pblk_end_io_recov; |
| 313 | rqd->private = pad_rq; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 314 | |
| 315 | for (i = 0; i < rqd->nr_ppas; ) { |
| 316 | struct ppa_addr ppa; |
| 317 | int pos; |
| 318 | |
| 319 | w_ptr = pblk_alloc_page(pblk, line, pblk->min_write_pgs); |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 320 | ppa = addr_to_gen_ppa(pblk, w_ptr, line->id); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 321 | pos = pblk_ppa_to_pos(geo, ppa); |
| 322 | |
| 323 | while (test_bit(pos, line->blk_bitmap)) { |
| 324 | w_ptr += pblk->min_write_pgs; |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 325 | ppa = addr_to_gen_ppa(pblk, w_ptr, line->id); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 326 | pos = pblk_ppa_to_pos(geo, ppa); |
| 327 | } |
| 328 | |
| 329 | for (j = 0; j < pblk->min_write_pgs; j++, i++, w_ptr++) { |
| 330 | struct ppa_addr dev_ppa; |
Javier González | f417aa0 | 2017-06-30 17:56:34 +0200 | [diff] [blame] | 331 | __le64 addr_empty = cpu_to_le64(ADDR_EMPTY); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 332 | |
| 333 | dev_ppa = addr_to_gen_ppa(pblk, w_ptr, line->id); |
| 334 | |
| 335 | pblk_map_invalidate(pblk, dev_ppa); |
Javier González | caa69fa | 2017-06-26 11:57:12 +0200 | [diff] [blame] | 336 | lba_list[w_ptr] = meta_list[i].lba = addr_empty; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 337 | rqd->ppa_list[i] = dev_ppa; |
| 338 | } |
| 339 | } |
| 340 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 341 | kref_get(&pad_rq->ref); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 342 | pblk_down_page(pblk, rqd->ppa_list, rqd->nr_ppas); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 343 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 344 | ret = pblk_submit_io(pblk, rqd); |
| 345 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 346 | pblk_err(pblk, "I/O submission failed: %d\n", ret); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 347 | pblk_up_page(pblk, rqd->ppa_list, rqd->nr_ppas); |
| 348 | goto fail_free_bio; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 351 | left_line_ppas -= rq_ppas; |
| 352 | left_ppas -= rq_ppas; |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 353 | if (left_ppas && left_line_ppas) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 354 | goto next_pad_rq; |
| 355 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 356 | kref_put(&pad_rq->ref, pblk_recov_complete); |
| 357 | |
| 358 | if (!wait_for_completion_io_timeout(&pad_rq->wait, |
| 359 | msecs_to_jiffies(PBLK_COMMAND_TIMEOUT_MS))) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 360 | pblk_err(pblk, "pad write timed out\n"); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 361 | ret = -ETIME; |
| 362 | } |
| 363 | |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 364 | if (!pblk_line_is_full(line)) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 365 | pblk_err(pblk, "corrupted padded line: %d\n", line->id); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 366 | |
| 367 | vfree(data); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 368 | free_rq: |
| 369 | kfree(pad_rq); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 370 | return ret; |
| 371 | |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 372 | fail_free_bio: |
| 373 | bio_put(bio); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 374 | fail_free_meta: |
| 375 | nvm_dev_dma_free(dev->parent, meta_list, dma_meta_list); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 376 | fail_free_pad: |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 377 | kfree(pad_rq); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 378 | vfree(data); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 379 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /* When this function is called, it means that not all upper pages have been |
| 383 | * written in a page that contains valid data. In order to recover this data, we |
| 384 | * first find the write pointer on the device, then we pad all necessary |
| 385 | * sectors, and finally attempt to read the valid data |
| 386 | */ |
| 387 | static int pblk_recov_scan_all_oob(struct pblk *pblk, struct pblk_line *line, |
| 388 | struct pblk_recov_alloc p) |
| 389 | { |
| 390 | struct nvm_tgt_dev *dev = pblk->dev; |
| 391 | struct nvm_geo *geo = &dev->geo; |
| 392 | struct ppa_addr *ppa_list; |
| 393 | struct pblk_sec_meta *meta_list; |
| 394 | struct nvm_rq *rqd; |
| 395 | struct bio *bio; |
| 396 | void *data; |
| 397 | dma_addr_t dma_ppa_list, dma_meta_list; |
| 398 | u64 w_ptr = 0, r_ptr; |
| 399 | int rq_ppas, rq_len; |
| 400 | int i, j; |
| 401 | int ret = 0; |
| 402 | int rec_round; |
| 403 | int left_ppas = pblk_calc_sec_in_line(pblk, line) - line->cur_sec; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 404 | |
| 405 | ppa_list = p.ppa_list; |
| 406 | meta_list = p.meta_list; |
| 407 | rqd = p.rqd; |
| 408 | data = p.data; |
| 409 | dma_ppa_list = p.dma_ppa_list; |
| 410 | dma_meta_list = p.dma_meta_list; |
| 411 | |
| 412 | /* we could recover up until the line write pointer */ |
| 413 | r_ptr = line->cur_sec; |
| 414 | rec_round = 0; |
| 415 | |
| 416 | next_rq: |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 417 | memset(rqd, 0, pblk_g_rq_size); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 418 | |
| 419 | rq_ppas = pblk_calc_secs(pblk, left_ppas, 0); |
| 420 | if (!rq_ppas) |
| 421 | rq_ppas = pblk->min_write_pgs; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 422 | rq_len = rq_ppas * geo->csecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 423 | |
| 424 | bio = bio_map_kern(dev->q, data, rq_len, GFP_KERNEL); |
| 425 | if (IS_ERR(bio)) |
| 426 | return PTR_ERR(bio); |
| 427 | |
| 428 | bio->bi_iter.bi_sector = 0; /* internal bio */ |
| 429 | bio_set_op_attrs(bio, REQ_OP_READ, 0); |
| 430 | |
| 431 | rqd->bio = bio; |
| 432 | rqd->opcode = NVM_OP_PREAD; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 433 | rqd->meta_list = meta_list; |
| 434 | rqd->nr_ppas = rq_ppas; |
| 435 | rqd->ppa_list = ppa_list; |
| 436 | rqd->dma_ppa_list = dma_ppa_list; |
| 437 | rqd->dma_meta_list = dma_meta_list; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 438 | |
Javier González | f9c1015 | 2017-06-26 11:57:20 +0200 | [diff] [blame] | 439 | if (pblk_io_aligned(pblk, rq_ppas)) |
Matias Bjørling | d7b6801 | 2018-10-09 13:11:32 +0200 | [diff] [blame] | 440 | rqd->is_seq = 1; |
Javier González | f9c1015 | 2017-06-26 11:57:20 +0200 | [diff] [blame] | 441 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 442 | for (i = 0; i < rqd->nr_ppas; ) { |
| 443 | struct ppa_addr ppa; |
| 444 | int pos; |
| 445 | |
| 446 | w_ptr = pblk_alloc_page(pblk, line, pblk->min_write_pgs); |
| 447 | ppa = addr_to_gen_ppa(pblk, w_ptr, line->id); |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 448 | pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 449 | |
| 450 | while (test_bit(pos, line->blk_bitmap)) { |
| 451 | w_ptr += pblk->min_write_pgs; |
| 452 | ppa = addr_to_gen_ppa(pblk, w_ptr, line->id); |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 453 | pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | for (j = 0; j < pblk->min_write_pgs; j++, i++, w_ptr++) |
| 457 | rqd->ppa_list[i] = |
| 458 | addr_to_gen_ppa(pblk, w_ptr, line->id); |
| 459 | } |
| 460 | |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 461 | ret = pblk_submit_io_sync(pblk, rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 462 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 463 | pblk_err(pblk, "I/O submission failed: %d\n", ret); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 464 | return ret; |
| 465 | } |
| 466 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 467 | atomic_dec(&pblk->inflight_io); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 468 | |
| 469 | /* This should not happen since the read failed during normal recovery, |
| 470 | * but the media works funny sometimes... |
| 471 | */ |
| 472 | if (!rec_round++ && !rqd->error) { |
| 473 | rec_round = 0; |
| 474 | for (i = 0; i < rqd->nr_ppas; i++, r_ptr++) { |
| 475 | u64 lba = le64_to_cpu(meta_list[i].lba); |
| 476 | |
| 477 | if (lba == ADDR_EMPTY || lba > pblk->rl.nr_secs) |
| 478 | continue; |
| 479 | |
| 480 | pblk_update_map(pblk, lba, rqd->ppa_list[i]); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /* Reached the end of the written line */ |
| 485 | if (rqd->error == NVM_RSP_ERR_EMPTYPAGE) { |
| 486 | int pad_secs, nr_error_bits, bit; |
| 487 | int ret; |
| 488 | |
| 489 | bit = find_first_bit((void *)&rqd->ppa_status, rqd->nr_ppas); |
| 490 | nr_error_bits = rqd->nr_ppas - bit; |
| 491 | |
| 492 | /* Roll back failed sectors */ |
| 493 | line->cur_sec -= nr_error_bits; |
| 494 | line->left_msecs += nr_error_bits; |
| 495 | bitmap_clear(line->map_bitmap, line->cur_sec, nr_error_bits); |
| 496 | |
| 497 | pad_secs = pblk_pad_distance(pblk); |
| 498 | if (pad_secs > line->left_msecs) |
| 499 | pad_secs = line->left_msecs; |
| 500 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 501 | ret = pblk_recov_pad_oob(pblk, line, pad_secs); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 502 | if (ret) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 503 | pblk_err(pblk, "OOB padding failed (err:%d)\n", ret); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 504 | |
| 505 | ret = pblk_recov_read_oob(pblk, line, p, r_ptr); |
| 506 | if (ret) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 507 | pblk_err(pblk, "OOB read failed (err:%d)\n", ret); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 508 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 509 | left_ppas = 0; |
| 510 | } |
| 511 | |
| 512 | left_ppas -= rq_ppas; |
| 513 | if (left_ppas > 0) |
| 514 | goto next_rq; |
| 515 | |
| 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | static int pblk_recov_scan_oob(struct pblk *pblk, struct pblk_line *line, |
| 520 | struct pblk_recov_alloc p, int *done) |
| 521 | { |
| 522 | struct nvm_tgt_dev *dev = pblk->dev; |
| 523 | struct nvm_geo *geo = &dev->geo; |
| 524 | struct ppa_addr *ppa_list; |
| 525 | struct pblk_sec_meta *meta_list; |
| 526 | struct nvm_rq *rqd; |
| 527 | struct bio *bio; |
| 528 | void *data; |
| 529 | dma_addr_t dma_ppa_list, dma_meta_list; |
| 530 | u64 paddr; |
| 531 | int rq_ppas, rq_len; |
| 532 | int i, j; |
| 533 | int ret = 0; |
| 534 | int left_ppas = pblk_calc_sec_in_line(pblk, line); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 535 | |
| 536 | ppa_list = p.ppa_list; |
| 537 | meta_list = p.meta_list; |
| 538 | rqd = p.rqd; |
| 539 | data = p.data; |
| 540 | dma_ppa_list = p.dma_ppa_list; |
| 541 | dma_meta_list = p.dma_meta_list; |
| 542 | |
| 543 | *done = 1; |
| 544 | |
| 545 | next_rq: |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 546 | memset(rqd, 0, pblk_g_rq_size); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 547 | |
| 548 | rq_ppas = pblk_calc_secs(pblk, left_ppas, 0); |
| 549 | if (!rq_ppas) |
| 550 | rq_ppas = pblk->min_write_pgs; |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 551 | rq_len = rq_ppas * geo->csecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 552 | |
| 553 | bio = bio_map_kern(dev->q, data, rq_len, GFP_KERNEL); |
| 554 | if (IS_ERR(bio)) |
| 555 | return PTR_ERR(bio); |
| 556 | |
| 557 | bio->bi_iter.bi_sector = 0; /* internal bio */ |
| 558 | bio_set_op_attrs(bio, REQ_OP_READ, 0); |
| 559 | |
| 560 | rqd->bio = bio; |
| 561 | rqd->opcode = NVM_OP_PREAD; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 562 | rqd->meta_list = meta_list; |
| 563 | rqd->nr_ppas = rq_ppas; |
| 564 | rqd->ppa_list = ppa_list; |
| 565 | rqd->dma_ppa_list = dma_ppa_list; |
| 566 | rqd->dma_meta_list = dma_meta_list; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 567 | |
Javier González | f9c1015 | 2017-06-26 11:57:20 +0200 | [diff] [blame] | 568 | if (pblk_io_aligned(pblk, rq_ppas)) |
Matias Bjørling | d7b6801 | 2018-10-09 13:11:32 +0200 | [diff] [blame] | 569 | rqd->is_seq = 1; |
Javier González | f9c1015 | 2017-06-26 11:57:20 +0200 | [diff] [blame] | 570 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 571 | for (i = 0; i < rqd->nr_ppas; ) { |
| 572 | struct ppa_addr ppa; |
| 573 | int pos; |
| 574 | |
| 575 | paddr = pblk_alloc_page(pblk, line, pblk->min_write_pgs); |
| 576 | ppa = addr_to_gen_ppa(pblk, paddr, line->id); |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 577 | pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 578 | |
| 579 | while (test_bit(pos, line->blk_bitmap)) { |
| 580 | paddr += pblk->min_write_pgs; |
| 581 | ppa = addr_to_gen_ppa(pblk, paddr, line->id); |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 582 | pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | for (j = 0; j < pblk->min_write_pgs; j++, i++, paddr++) |
| 586 | rqd->ppa_list[i] = |
| 587 | addr_to_gen_ppa(pblk, paddr, line->id); |
| 588 | } |
| 589 | |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 590 | ret = pblk_submit_io_sync(pblk, rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 591 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 592 | pblk_err(pblk, "I/O submission failed: %d\n", ret); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 593 | bio_put(bio); |
| 594 | return ret; |
| 595 | } |
| 596 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 597 | atomic_dec(&pblk->inflight_io); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 598 | |
| 599 | /* Reached the end of the written line */ |
| 600 | if (rqd->error) { |
| 601 | int nr_error_bits, bit; |
| 602 | |
| 603 | bit = find_first_bit((void *)&rqd->ppa_status, rqd->nr_ppas); |
| 604 | nr_error_bits = rqd->nr_ppas - bit; |
| 605 | |
| 606 | /* Roll back failed sectors */ |
| 607 | line->cur_sec -= nr_error_bits; |
| 608 | line->left_msecs += nr_error_bits; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 609 | bitmap_clear(line->map_bitmap, line->cur_sec, nr_error_bits); |
| 610 | |
| 611 | left_ppas = 0; |
| 612 | rqd->nr_ppas = bit; |
| 613 | |
| 614 | if (rqd->error != NVM_RSP_ERR_EMPTYPAGE) |
| 615 | *done = 0; |
| 616 | } |
| 617 | |
| 618 | for (i = 0; i < rqd->nr_ppas; i++) { |
| 619 | u64 lba = le64_to_cpu(meta_list[i].lba); |
| 620 | |
| 621 | if (lba == ADDR_EMPTY || lba > pblk->rl.nr_secs) |
| 622 | continue; |
| 623 | |
| 624 | pblk_update_map(pblk, lba, rqd->ppa_list[i]); |
| 625 | } |
| 626 | |
| 627 | left_ppas -= rq_ppas; |
| 628 | if (left_ppas > 0) |
| 629 | goto next_rq; |
| 630 | |
| 631 | return ret; |
| 632 | } |
| 633 | |
| 634 | /* Scan line for lbas on out of bound area */ |
| 635 | static int pblk_recov_l2p_from_oob(struct pblk *pblk, struct pblk_line *line) |
| 636 | { |
| 637 | struct nvm_tgt_dev *dev = pblk->dev; |
| 638 | struct nvm_geo *geo = &dev->geo; |
| 639 | struct nvm_rq *rqd; |
| 640 | struct ppa_addr *ppa_list; |
| 641 | struct pblk_sec_meta *meta_list; |
| 642 | struct pblk_recov_alloc p; |
| 643 | void *data; |
| 644 | dma_addr_t dma_ppa_list, dma_meta_list; |
| 645 | int done, ret = 0; |
| 646 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 647 | meta_list = nvm_dev_dma_alloc(dev->parent, GFP_KERNEL, &dma_meta_list); |
Javier González | 2942f50 | 2017-10-13 14:46:10 +0200 | [diff] [blame] | 648 | if (!meta_list) |
| 649 | return -ENOMEM; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 650 | |
| 651 | ppa_list = (void *)(meta_list) + pblk_dma_meta_size; |
| 652 | dma_ppa_list = dma_meta_list + pblk_dma_meta_size; |
| 653 | |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 654 | data = kcalloc(pblk->max_write_pgs, geo->csecs, GFP_KERNEL); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 655 | if (!data) { |
| 656 | ret = -ENOMEM; |
| 657 | goto free_meta_list; |
| 658 | } |
| 659 | |
Javier González | e2cddf2 | 2017-10-13 14:46:19 +0200 | [diff] [blame] | 660 | rqd = pblk_alloc_rqd(pblk, PBLK_READ); |
Javier González | 2942f50 | 2017-10-13 14:46:10 +0200 | [diff] [blame] | 661 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 662 | p.ppa_list = ppa_list; |
| 663 | p.meta_list = meta_list; |
| 664 | p.rqd = rqd; |
| 665 | p.data = data; |
| 666 | p.dma_ppa_list = dma_ppa_list; |
| 667 | p.dma_meta_list = dma_meta_list; |
| 668 | |
| 669 | ret = pblk_recov_scan_oob(pblk, line, p, &done); |
| 670 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 671 | pblk_err(pblk, "could not recover L2P from OOB\n"); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 672 | goto out; |
| 673 | } |
| 674 | |
| 675 | if (!done) { |
| 676 | ret = pblk_recov_scan_all_oob(pblk, line, p); |
| 677 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 678 | pblk_err(pblk, "could not recover L2P from OOB\n"); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 679 | goto out; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | if (pblk_line_is_full(line)) |
| 684 | pblk_line_recov_close(pblk, line); |
| 685 | |
| 686 | out: |
| 687 | kfree(data); |
| 688 | free_meta_list: |
| 689 | nvm_dev_dma_free(dev->parent, meta_list, dma_meta_list); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 690 | |
| 691 | return ret; |
| 692 | } |
| 693 | |
| 694 | /* Insert lines ordered by sequence number (seq_num) on list */ |
| 695 | static void pblk_recov_line_add_ordered(struct list_head *head, |
| 696 | struct pblk_line *line) |
| 697 | { |
| 698 | struct pblk_line *t = NULL; |
| 699 | |
| 700 | list_for_each_entry(t, head, list) |
| 701 | if (t->seq_nr > line->seq_nr) |
| 702 | break; |
| 703 | |
| 704 | __list_add(&line->list, t->list.prev, &t->list); |
| 705 | } |
| 706 | |
Hans Holmberg | 75610cd | 2017-10-13 14:46:38 +0200 | [diff] [blame] | 707 | static u64 pblk_line_emeta_start(struct pblk *pblk, struct pblk_line *line) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 708 | { |
| 709 | struct nvm_tgt_dev *dev = pblk->dev; |
| 710 | struct nvm_geo *geo = &dev->geo; |
| 711 | struct pblk_line_meta *lm = &pblk->lm; |
Hans Holmberg | 75610cd | 2017-10-13 14:46:38 +0200 | [diff] [blame] | 712 | unsigned int emeta_secs; |
| 713 | u64 emeta_start; |
| 714 | struct ppa_addr ppa; |
| 715 | int pos; |
| 716 | |
| 717 | emeta_secs = lm->emeta_sec[0]; |
| 718 | emeta_start = lm->sec_per_line; |
| 719 | |
| 720 | while (emeta_secs) { |
| 721 | emeta_start--; |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 722 | ppa = addr_to_gen_ppa(pblk, emeta_start, line->id); |
Hans Holmberg | 75610cd | 2017-10-13 14:46:38 +0200 | [diff] [blame] | 723 | pos = pblk_ppa_to_pos(geo, ppa); |
| 724 | if (!test_bit(pos, line->blk_bitmap)) |
| 725 | emeta_secs--; |
| 726 | } |
| 727 | |
| 728 | return emeta_start; |
| 729 | } |
| 730 | |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 731 | static int pblk_recov_check_line_version(struct pblk *pblk, |
| 732 | struct line_emeta *emeta) |
| 733 | { |
| 734 | struct line_header *header = &emeta->header; |
| 735 | |
| 736 | if (header->version_major != EMETA_VERSION_MAJOR) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 737 | pblk_err(pblk, "line major version mismatch: %d, expected: %d\n", |
| 738 | header->version_major, EMETA_VERSION_MAJOR); |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 739 | return 1; |
| 740 | } |
| 741 | |
Matias Bjørling | 99b8dad | 2018-07-13 10:48:38 +0200 | [diff] [blame] | 742 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 743 | if (header->version_minor > EMETA_VERSION_MINOR) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 744 | pblk_info(pblk, "newer line minor version found: %d\n", |
Matias Bjørling | 99b8dad | 2018-07-13 10:48:38 +0200 | [diff] [blame] | 745 | header->version_minor); |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 746 | #endif |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 751 | static void pblk_recov_wa_counters(struct pblk *pblk, |
| 752 | struct line_emeta *emeta) |
| 753 | { |
| 754 | struct pblk_line_meta *lm = &pblk->lm; |
| 755 | struct line_header *header = &emeta->header; |
| 756 | struct wa_counters *wa = emeta_to_wa(lm, emeta); |
| 757 | |
| 758 | /* WA counters were introduced in emeta version 0.2 */ |
| 759 | if (header->version_major > 0 || header->version_minor >= 2) { |
| 760 | u64 user = le64_to_cpu(wa->user); |
| 761 | u64 pad = le64_to_cpu(wa->pad); |
| 762 | u64 gc = le64_to_cpu(wa->gc); |
| 763 | |
| 764 | atomic64_set(&pblk->user_wa, user); |
| 765 | atomic64_set(&pblk->pad_wa, pad); |
| 766 | atomic64_set(&pblk->gc_wa, gc); |
| 767 | |
| 768 | pblk->user_rst_wa = user; |
| 769 | pblk->pad_rst_wa = pad; |
| 770 | pblk->gc_rst_wa = gc; |
| 771 | } |
| 772 | } |
| 773 | |
Hans Holmberg | 9156f36 | 2018-03-30 00:05:22 +0200 | [diff] [blame] | 774 | static int pblk_line_was_written(struct pblk_line *line, |
Hans Holmberg | b06be28 | 2018-06-01 16:41:12 +0200 | [diff] [blame] | 775 | struct pblk *pblk) |
Hans Holmberg | 9156f36 | 2018-03-30 00:05:22 +0200 | [diff] [blame] | 776 | { |
| 777 | |
Hans Holmberg | b06be28 | 2018-06-01 16:41:12 +0200 | [diff] [blame] | 778 | struct pblk_line_meta *lm = &pblk->lm; |
| 779 | struct nvm_tgt_dev *dev = pblk->dev; |
| 780 | struct nvm_geo *geo = &dev->geo; |
| 781 | struct nvm_chk_meta *chunk; |
| 782 | struct ppa_addr bppa; |
| 783 | int smeta_blk; |
Hans Holmberg | 9156f36 | 2018-03-30 00:05:22 +0200 | [diff] [blame] | 784 | |
Hans Holmberg | b06be28 | 2018-06-01 16:41:12 +0200 | [diff] [blame] | 785 | if (line->state == PBLK_LINESTATE_BAD) |
| 786 | return 0; |
Hans Holmberg | 9156f36 | 2018-03-30 00:05:22 +0200 | [diff] [blame] | 787 | |
Hans Holmberg | b06be28 | 2018-06-01 16:41:12 +0200 | [diff] [blame] | 788 | smeta_blk = find_first_zero_bit(line->blk_bitmap, lm->blk_per_line); |
| 789 | if (smeta_blk >= lm->blk_per_line) |
| 790 | return 0; |
| 791 | |
| 792 | bppa = pblk->luns[smeta_blk].bppa; |
| 793 | chunk = &line->chks[pblk_ppa_to_pos(geo, bppa)]; |
| 794 | |
| 795 | if (chunk->state & NVM_CHK_ST_FREE) |
| 796 | return 0; |
| 797 | |
| 798 | return 1; |
Hans Holmberg | 9156f36 | 2018-03-30 00:05:22 +0200 | [diff] [blame] | 799 | } |
| 800 | |
Hans Holmberg | 75610cd | 2017-10-13 14:46:38 +0200 | [diff] [blame] | 801 | struct pblk_line *pblk_recov_l2p(struct pblk *pblk) |
| 802 | { |
| 803 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 804 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 805 | struct pblk_line *line, *tline, *data_line = NULL; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 806 | struct pblk_smeta *smeta; |
| 807 | struct pblk_emeta *emeta; |
| 808 | struct line_smeta *smeta_buf; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 809 | int found_lines = 0, recovered_lines = 0, open_lines = 0; |
| 810 | int is_next = 0; |
| 811 | int meta_line; |
| 812 | int i, valid_uuid = 0; |
| 813 | LIST_HEAD(recov_list); |
| 814 | |
| 815 | /* TODO: Implement FTL snapshot */ |
| 816 | |
| 817 | /* Scan recovery - takes place when FTL snapshot fails */ |
| 818 | spin_lock(&l_mg->free_lock); |
| 819 | meta_line = find_first_zero_bit(&l_mg->meta_bitmap, PBLK_DATA_LINES); |
| 820 | set_bit(meta_line, &l_mg->meta_bitmap); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 821 | smeta = l_mg->sline_meta[meta_line]; |
| 822 | emeta = l_mg->eline_meta[meta_line]; |
Javier González | 8224cbd | 2017-06-30 17:56:38 +0200 | [diff] [blame] | 823 | smeta_buf = (struct line_smeta *)smeta; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 824 | spin_unlock(&l_mg->free_lock); |
| 825 | |
| 826 | /* Order data lines using their sequence number */ |
| 827 | for (i = 0; i < l_mg->nr_lines; i++) { |
| 828 | u32 crc; |
| 829 | |
| 830 | line = &pblk->lines[i]; |
| 831 | |
| 832 | memset(smeta, 0, lm->smeta_len); |
| 833 | line->smeta = smeta; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 834 | line->lun_bitmap = ((void *)(smeta_buf)) + |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 835 | sizeof(struct line_smeta); |
| 836 | |
Hans Holmberg | b06be28 | 2018-06-01 16:41:12 +0200 | [diff] [blame] | 837 | if (!pblk_line_was_written(line, pblk)) |
Hans Holmberg | 9156f36 | 2018-03-30 00:05:22 +0200 | [diff] [blame] | 838 | continue; |
| 839 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 840 | /* Lines that cannot be read are assumed as not written here */ |
| 841 | if (pblk_line_read_smeta(pblk, line)) |
| 842 | continue; |
| 843 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 844 | crc = pblk_calc_smeta_crc(pblk, smeta_buf); |
| 845 | if (le32_to_cpu(smeta_buf->crc) != crc) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 846 | continue; |
| 847 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 848 | if (le32_to_cpu(smeta_buf->header.identifier) != PBLK_MAGIC) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 849 | continue; |
| 850 | |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 851 | if (smeta_buf->header.version_major != SMETA_VERSION_MAJOR) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 852 | pblk_err(pblk, "found incompatible line version %u\n", |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 853 | smeta_buf->header.version_major); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 854 | return ERR_PTR(-EINVAL); |
| 855 | } |
| 856 | |
| 857 | /* The first valid instance uuid is used for initialization */ |
| 858 | if (!valid_uuid) { |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 859 | memcpy(pblk->instance_uuid, smeta_buf->header.uuid, 16); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 860 | valid_uuid = 1; |
| 861 | } |
| 862 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 863 | if (memcmp(pblk->instance_uuid, smeta_buf->header.uuid, 16)) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 864 | pblk_debug(pblk, "ignore line %u due to uuid mismatch\n", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 865 | i); |
| 866 | continue; |
| 867 | } |
| 868 | |
| 869 | /* Update line metadata */ |
| 870 | spin_lock(&line->lock); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 871 | line->id = le32_to_cpu(smeta_buf->header.id); |
| 872 | line->type = le16_to_cpu(smeta_buf->header.type); |
| 873 | line->seq_nr = le64_to_cpu(smeta_buf->seq_nr); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 874 | spin_unlock(&line->lock); |
| 875 | |
| 876 | /* Update general metadata */ |
| 877 | spin_lock(&l_mg->free_lock); |
| 878 | if (line->seq_nr >= l_mg->d_seq_nr) |
| 879 | l_mg->d_seq_nr = line->seq_nr + 1; |
| 880 | l_mg->nr_free_lines--; |
| 881 | spin_unlock(&l_mg->free_lock); |
| 882 | |
| 883 | if (pblk_line_recov_alloc(pblk, line)) |
| 884 | goto out; |
| 885 | |
| 886 | pblk_recov_line_add_ordered(&recov_list, line); |
| 887 | found_lines++; |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 888 | pblk_debug(pblk, "recovering data line %d, seq:%llu\n", |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 889 | line->id, smeta_buf->seq_nr); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | if (!found_lines) { |
| 893 | pblk_setup_uuid(pblk); |
| 894 | |
| 895 | spin_lock(&l_mg->free_lock); |
| 896 | WARN_ON_ONCE(!test_and_clear_bit(meta_line, |
| 897 | &l_mg->meta_bitmap)); |
| 898 | spin_unlock(&l_mg->free_lock); |
| 899 | |
| 900 | goto out; |
| 901 | } |
| 902 | |
| 903 | /* Verify closed blocks and recover this portion of L2P table*/ |
| 904 | list_for_each_entry_safe(line, tline, &recov_list, list) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 905 | recovered_lines++; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 906 | |
Hans Holmberg | 75610cd | 2017-10-13 14:46:38 +0200 | [diff] [blame] | 907 | line->emeta_ssec = pblk_line_emeta_start(pblk, line); |
Javier González | 8224cbd | 2017-06-30 17:56:38 +0200 | [diff] [blame] | 908 | line->emeta = emeta; |
| 909 | memset(line->emeta->buf, 0, lm->emeta_len[0]); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 910 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 911 | if (pblk_line_read_emeta(pblk, line, line->emeta->buf)) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 912 | pblk_recov_l2p_from_oob(pblk, line); |
| 913 | goto next; |
| 914 | } |
| 915 | |
Hans Holmberg | 06bc072 | 2018-01-05 14:16:08 +0100 | [diff] [blame] | 916 | if (pblk_recov_check_emeta(pblk, line->emeta->buf)) { |
| 917 | pblk_recov_l2p_from_oob(pblk, line); |
| 918 | goto next; |
| 919 | } |
| 920 | |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 921 | if (pblk_recov_check_line_version(pblk, line->emeta->buf)) |
| 922 | return ERR_PTR(-EINVAL); |
| 923 | |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 924 | pblk_recov_wa_counters(pblk, line->emeta->buf); |
| 925 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 926 | if (pblk_recov_l2p_from_emeta(pblk, line)) |
| 927 | pblk_recov_l2p_from_oob(pblk, line); |
| 928 | |
| 929 | next: |
| 930 | if (pblk_line_is_full(line)) { |
| 931 | struct list_head *move_list; |
| 932 | |
| 933 | spin_lock(&line->lock); |
| 934 | line->state = PBLK_LINESTATE_CLOSED; |
| 935 | move_list = pblk_line_gc_list(pblk, line); |
| 936 | spin_unlock(&line->lock); |
| 937 | |
| 938 | spin_lock(&l_mg->gc_lock); |
| 939 | list_move_tail(&line->list, move_list); |
| 940 | spin_unlock(&l_mg->gc_lock); |
| 941 | |
Javier González | e72ec1d | 2017-10-13 14:46:09 +0200 | [diff] [blame] | 942 | kfree(line->map_bitmap); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 943 | line->map_bitmap = NULL; |
| 944 | line->smeta = NULL; |
| 945 | line->emeta = NULL; |
| 946 | } else { |
| 947 | if (open_lines > 1) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 948 | pblk_err(pblk, "failed to recover L2P\n"); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 949 | |
| 950 | open_lines++; |
| 951 | line->meta_line = meta_line; |
| 952 | data_line = line; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | spin_lock(&l_mg->free_lock); |
| 957 | if (!open_lines) { |
| 958 | WARN_ON_ONCE(!test_and_clear_bit(meta_line, |
| 959 | &l_mg->meta_bitmap)); |
| 960 | pblk_line_replace_data(pblk); |
| 961 | } else { |
| 962 | /* Allocate next line for preparation */ |
| 963 | l_mg->data_next = pblk_line_get(pblk); |
| 964 | if (l_mg->data_next) { |
| 965 | l_mg->data_next->seq_nr = l_mg->d_seq_nr++; |
| 966 | l_mg->data_next->type = PBLK_LINETYPE_DATA; |
| 967 | is_next = 1; |
| 968 | } |
| 969 | } |
| 970 | spin_unlock(&l_mg->free_lock); |
| 971 | |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 972 | if (is_next) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 973 | pblk_line_erase(pblk, l_mg->data_next); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 974 | |
| 975 | out: |
| 976 | if (found_lines != recovered_lines) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 977 | pblk_err(pblk, "failed to recover all found lines %d/%d\n", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 978 | found_lines, recovered_lines); |
| 979 | |
| 980 | return data_line; |
| 981 | } |
| 982 | |
| 983 | /* |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 984 | * Pad current line |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 985 | */ |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 986 | int pblk_recov_pad(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 987 | { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 988 | struct pblk_line *line; |
| 989 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 990 | int left_msecs; |
| 991 | int ret = 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 992 | |
| 993 | spin_lock(&l_mg->free_lock); |
| 994 | line = l_mg->data_line; |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 995 | left_msecs = line->left_msecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 996 | spin_unlock(&l_mg->free_lock); |
| 997 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 998 | ret = pblk_recov_pad_oob(pblk, line, left_msecs); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 999 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1000 | pblk_err(pblk, "tear down padding failed (%d)\n", ret); |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 1001 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1004 | pblk_line_close_meta(pblk, line); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1005 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1006 | } |