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