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 release: Javier Gonzalez <javier@cnexlabs.com> |
| 5 | * Matias Bjorling <matias@cnexlabs.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License version |
| 9 | * 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * pblk-core.c - pblk's core functionality |
| 17 | * |
| 18 | */ |
| 19 | |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 20 | #define CREATE_TRACE_POINTS |
| 21 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 22 | #include "pblk.h" |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 23 | #include "pblk-trace.h" |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 24 | |
Javier González | 8bd4002 | 2017-10-13 14:46:44 +0200 | [diff] [blame] | 25 | static void pblk_line_mark_bb(struct work_struct *work) |
| 26 | { |
| 27 | struct pblk_line_ws *line_ws = container_of(work, struct pblk_line_ws, |
| 28 | ws); |
| 29 | struct pblk *pblk = line_ws->pblk; |
| 30 | struct nvm_tgt_dev *dev = pblk->dev; |
| 31 | struct ppa_addr *ppa = line_ws->priv; |
| 32 | int ret; |
| 33 | |
Matias Bjørling | aff3fb1 | 2018-10-09 13:11:36 +0200 | [diff] [blame] | 34 | ret = nvm_set_chunk_meta(dev, ppa, 1, NVM_BLK_T_GRWN_BAD); |
Javier González | 8bd4002 | 2017-10-13 14:46:44 +0200 | [diff] [blame] | 35 | if (ret) { |
| 36 | struct pblk_line *line; |
| 37 | int pos; |
| 38 | |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 39 | line = pblk_ppa_to_line(pblk, *ppa); |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 40 | pos = pblk_ppa_to_pos(&dev->geo, *ppa); |
Javier González | 8bd4002 | 2017-10-13 14:46:44 +0200 | [diff] [blame] | 41 | |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 42 | pblk_err(pblk, "failed to mark bb, line:%d, pos:%d\n", |
Javier González | 8bd4002 | 2017-10-13 14:46:44 +0200 | [diff] [blame] | 43 | line->id, pos); |
| 44 | } |
| 45 | |
| 46 | kfree(ppa); |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 47 | mempool_free(line_ws, &pblk->gen_ws_pool); |
Javier González | 8bd4002 | 2017-10-13 14:46:44 +0200 | [diff] [blame] | 48 | } |
| 49 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 50 | static void pblk_mark_bb(struct pblk *pblk, struct pblk_line *line, |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 51 | struct ppa_addr ppa_addr) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 52 | { |
| 53 | struct nvm_tgt_dev *dev = pblk->dev; |
| 54 | struct nvm_geo *geo = &dev->geo; |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 55 | struct ppa_addr *ppa; |
| 56 | int pos = pblk_ppa_to_pos(geo, ppa_addr); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 57 | |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 58 | pblk_debug(pblk, "erase failed: line:%d, pos:%d\n", line->id, pos); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 59 | atomic_long_inc(&pblk->erase_failed); |
| 60 | |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 61 | atomic_dec(&line->blk_in_line); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 62 | if (test_and_set_bit(pos, line->blk_bitmap)) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 63 | pblk_err(pblk, "attempted to erase bb: line:%d, pos:%d\n", |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 64 | line->id, pos); |
| 65 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 66 | /* Not necessary to mark bad blocks on 2.0 spec. */ |
| 67 | if (geo->version == NVM_OCSSD_SPEC_20) |
| 68 | return; |
| 69 | |
| 70 | ppa = kmalloc(sizeof(struct ppa_addr), GFP_ATOMIC); |
| 71 | if (!ppa) |
| 72 | return; |
| 73 | |
| 74 | *ppa = ppa_addr; |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 75 | pblk_gen_run_ws(pblk, NULL, ppa, pblk_line_mark_bb, |
| 76 | GFP_ATOMIC, pblk->bb_wq); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void __pblk_end_io_erase(struct pblk *pblk, struct nvm_rq *rqd) |
| 80 | { |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 81 | struct nvm_tgt_dev *dev = pblk->dev; |
| 82 | struct nvm_geo *geo = &dev->geo; |
| 83 | struct nvm_chk_meta *chunk; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 84 | struct pblk_line *line; |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 85 | int pos; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 86 | |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 87 | line = pblk_ppa_to_line(pblk, rqd->ppa_addr); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 88 | pos = pblk_ppa_to_pos(geo, rqd->ppa_addr); |
| 89 | chunk = &line->chks[pos]; |
| 90 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 91 | atomic_dec(&line->left_seblks); |
| 92 | |
| 93 | if (rqd->error) { |
Hans Holmberg | 4209c31 | 2018-10-09 13:11:55 +0200 | [diff] [blame] | 94 | trace_pblk_chunk_reset(pblk_disk_name(pblk), |
| 95 | &rqd->ppa_addr, PBLK_CHUNK_RESET_FAILED); |
| 96 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 97 | chunk->state = NVM_CHK_ST_OFFLINE; |
| 98 | pblk_mark_bb(pblk, line, rqd->ppa_addr); |
| 99 | } else { |
Hans Holmberg | 4209c31 | 2018-10-09 13:11:55 +0200 | [diff] [blame] | 100 | trace_pblk_chunk_reset(pblk_disk_name(pblk), |
| 101 | &rqd->ppa_addr, PBLK_CHUNK_RESET_DONE); |
| 102 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 103 | chunk->state = NVM_CHK_ST_FREE; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 104 | } |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 105 | |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 106 | trace_pblk_chunk_state(pblk_disk_name(pblk), &rqd->ppa_addr, |
| 107 | chunk->state); |
| 108 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 109 | atomic_dec(&pblk->inflight_io); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /* Erase completion assumes that only one block is erased at the time */ |
| 113 | static void pblk_end_io_erase(struct nvm_rq *rqd) |
| 114 | { |
| 115 | struct pblk *pblk = rqd->private; |
| 116 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 117 | __pblk_end_io_erase(pblk, rqd); |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 118 | mempool_free(rqd, &pblk->e_rq_pool); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 119 | } |
| 120 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 121 | /* |
| 122 | * Get information for all chunks from the device. |
| 123 | * |
Javier González | 090ee26 | 2018-10-09 13:12:01 +0200 | [diff] [blame] | 124 | * The caller is responsible for freeing (vmalloc) the returned structure |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 125 | */ |
Matias Bjørling | aff3fb1 | 2018-10-09 13:11:36 +0200 | [diff] [blame] | 126 | struct nvm_chk_meta *pblk_get_chunk_meta(struct pblk *pblk) |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 127 | { |
| 128 | struct nvm_tgt_dev *dev = pblk->dev; |
| 129 | struct nvm_geo *geo = &dev->geo; |
| 130 | struct nvm_chk_meta *meta; |
| 131 | struct ppa_addr ppa; |
| 132 | unsigned long len; |
| 133 | int ret; |
| 134 | |
| 135 | ppa.ppa = 0; |
| 136 | |
| 137 | len = geo->all_chunks * sizeof(*meta); |
Javier González | 090ee26 | 2018-10-09 13:12:01 +0200 | [diff] [blame] | 138 | meta = vzalloc(len); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 139 | if (!meta) |
| 140 | return ERR_PTR(-ENOMEM); |
| 141 | |
Matias Bjørling | aff3fb1 | 2018-10-09 13:11:36 +0200 | [diff] [blame] | 142 | ret = nvm_get_chunk_meta(dev, ppa, geo->all_chunks, meta); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 143 | if (ret) { |
Hans Holmberg | 6916cf5 | 2019-02-11 13:25:03 +0100 | [diff] [blame] | 144 | vfree(meta); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 145 | return ERR_PTR(-EIO); |
| 146 | } |
| 147 | |
| 148 | return meta; |
| 149 | } |
| 150 | |
| 151 | struct nvm_chk_meta *pblk_chunk_get_off(struct pblk *pblk, |
| 152 | struct nvm_chk_meta *meta, |
| 153 | struct ppa_addr ppa) |
| 154 | { |
| 155 | struct nvm_tgt_dev *dev = pblk->dev; |
| 156 | struct nvm_geo *geo = &dev->geo; |
| 157 | int ch_off = ppa.m.grp * geo->num_chk * geo->num_lun; |
| 158 | int lun_off = ppa.m.pu * geo->num_chk; |
| 159 | int chk_off = ppa.m.chk; |
| 160 | |
| 161 | return meta + ch_off + lun_off + chk_off; |
| 162 | } |
| 163 | |
Javier González | 0880a9a | 2017-06-26 11:57:19 +0200 | [diff] [blame] | 164 | void __pblk_map_invalidate(struct pblk *pblk, struct pblk_line *line, |
| 165 | u64 paddr) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 166 | { |
| 167 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 168 | struct list_head *move_list = NULL; |
| 169 | |
| 170 | /* Lines being reclaimed (GC'ed) cannot be invalidated. Before the L2P |
| 171 | * table is modified with reclaimed sectors, a check is done to endure |
| 172 | * that newer updates are not overwritten. |
| 173 | */ |
| 174 | spin_lock(&line->lock); |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 175 | WARN_ON(line->state == PBLK_LINESTATE_FREE); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 176 | |
| 177 | if (test_and_set_bit(paddr, line->invalid_bitmap)) { |
| 178 | WARN_ONCE(1, "pblk: double invalidate\n"); |
| 179 | spin_unlock(&line->lock); |
| 180 | return; |
| 181 | } |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 182 | le32_add_cpu(line->vsc, -1); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 183 | |
| 184 | if (line->state == PBLK_LINESTATE_CLOSED) |
| 185 | move_list = pblk_line_gc_list(pblk, line); |
| 186 | spin_unlock(&line->lock); |
| 187 | |
| 188 | if (move_list) { |
| 189 | spin_lock(&l_mg->gc_lock); |
| 190 | spin_lock(&line->lock); |
| 191 | /* Prevent moving a line that has just been chosen for GC */ |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 192 | if (line->state == PBLK_LINESTATE_GC) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 193 | spin_unlock(&line->lock); |
| 194 | spin_unlock(&l_mg->gc_lock); |
| 195 | return; |
| 196 | } |
| 197 | spin_unlock(&line->lock); |
| 198 | |
| 199 | list_move_tail(&line->list, move_list); |
| 200 | spin_unlock(&l_mg->gc_lock); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void pblk_map_invalidate(struct pblk *pblk, struct ppa_addr ppa) |
| 205 | { |
| 206 | struct pblk_line *line; |
| 207 | u64 paddr; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 208 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 209 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 210 | /* Callers must ensure that the ppa points to a device address */ |
| 211 | BUG_ON(pblk_addr_in_cache(ppa)); |
| 212 | BUG_ON(pblk_ppa_empty(ppa)); |
| 213 | #endif |
| 214 | |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 215 | line = pblk_ppa_to_line(pblk, ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 216 | paddr = pblk_dev_ppa_to_line_addr(pblk, ppa); |
| 217 | |
| 218 | __pblk_map_invalidate(pblk, line, paddr); |
| 219 | } |
| 220 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 221 | static void pblk_invalidate_range(struct pblk *pblk, sector_t slba, |
| 222 | unsigned int nr_secs) |
| 223 | { |
| 224 | sector_t lba; |
| 225 | |
| 226 | spin_lock(&pblk->trans_lock); |
| 227 | for (lba = slba; lba < slba + nr_secs; lba++) { |
| 228 | struct ppa_addr ppa; |
| 229 | |
| 230 | ppa = pblk_trans_map_get(pblk, lba); |
| 231 | |
| 232 | if (!pblk_addr_in_cache(ppa) && !pblk_ppa_empty(ppa)) |
| 233 | pblk_map_invalidate(pblk, ppa); |
| 234 | |
| 235 | pblk_ppa_set_empty(&ppa); |
| 236 | pblk_trans_map_set(pblk, lba, ppa); |
| 237 | } |
| 238 | spin_unlock(&pblk->trans_lock); |
| 239 | } |
| 240 | |
Javier González | 45dcf29 | 2018-10-09 13:12:02 +0200 | [diff] [blame] | 241 | int pblk_alloc_rqd_meta(struct pblk *pblk, struct nvm_rq *rqd) |
| 242 | { |
| 243 | struct nvm_tgt_dev *dev = pblk->dev; |
| 244 | |
| 245 | rqd->meta_list = nvm_dev_dma_alloc(dev->parent, GFP_KERNEL, |
| 246 | &rqd->dma_meta_list); |
| 247 | if (!rqd->meta_list) |
| 248 | return -ENOMEM; |
| 249 | |
| 250 | if (rqd->nr_ppas == 1) |
| 251 | return 0; |
| 252 | |
Igor Konopko | 24828d0 | 2018-12-11 20:16:24 +0100 | [diff] [blame] | 253 | rqd->ppa_list = rqd->meta_list + pblk_dma_meta_size(pblk); |
| 254 | rqd->dma_ppa_list = rqd->dma_meta_list + pblk_dma_meta_size(pblk); |
Javier González | 45dcf29 | 2018-10-09 13:12:02 +0200 | [diff] [blame] | 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | void pblk_free_rqd_meta(struct pblk *pblk, struct nvm_rq *rqd) |
| 260 | { |
| 261 | struct nvm_tgt_dev *dev = pblk->dev; |
| 262 | |
| 263 | if (rqd->meta_list) |
| 264 | nvm_dev_dma_free(dev->parent, rqd->meta_list, |
| 265 | rqd->dma_meta_list); |
| 266 | } |
| 267 | |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 268 | /* Caller must guarantee that the request is a valid type */ |
| 269 | struct nvm_rq *pblk_alloc_rqd(struct pblk *pblk, int type) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 270 | { |
| 271 | mempool_t *pool; |
| 272 | struct nvm_rq *rqd; |
| 273 | int rq_size; |
| 274 | |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 275 | switch (type) { |
| 276 | case PBLK_WRITE: |
| 277 | case PBLK_WRITE_INT: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 278 | pool = &pblk->w_rq_pool; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 279 | rq_size = pblk_w_rq_size; |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 280 | break; |
| 281 | case PBLK_READ: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 282 | pool = &pblk->r_rq_pool; |
Javier González | 084ec9b | 2017-06-26 16:27:13 -0600 | [diff] [blame] | 283 | rq_size = pblk_g_rq_size; |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 284 | break; |
| 285 | default: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 286 | pool = &pblk->e_rq_pool; |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 287 | rq_size = pblk_g_rq_size; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | rqd = mempool_alloc(pool, GFP_KERNEL); |
| 291 | memset(rqd, 0, rq_size); |
| 292 | |
| 293 | return rqd; |
| 294 | } |
| 295 | |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 296 | /* Typically used on completion path. Cannot guarantee request consistency */ |
| 297 | void pblk_free_rqd(struct pblk *pblk, struct nvm_rq *rqd, int type) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 298 | { |
| 299 | mempool_t *pool; |
| 300 | |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 301 | switch (type) { |
| 302 | case PBLK_WRITE: |
| 303 | kfree(((struct pblk_c_ctx *)nvm_rq_to_pdu(rqd))->lun_bitmap); |
Gustavo A. R. Silva | 884b031 | 2018-07-13 10:48:43 +0200 | [diff] [blame] | 304 | /* fall through */ |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 305 | case PBLK_WRITE_INT: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 306 | pool = &pblk->w_rq_pool; |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 307 | break; |
| 308 | case PBLK_READ: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 309 | pool = &pblk->r_rq_pool; |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 310 | break; |
| 311 | case PBLK_ERASE: |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 312 | pool = &pblk->e_rq_pool; |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 313 | break; |
| 314 | default: |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 315 | pblk_err(pblk, "trying to free unknown rqd type\n"); |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 316 | return; |
| 317 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 318 | |
Javier González | 45dcf29 | 2018-10-09 13:12:02 +0200 | [diff] [blame] | 319 | pblk_free_rqd_meta(pblk, rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 320 | mempool_free(rqd, pool); |
| 321 | } |
| 322 | |
| 323 | void pblk_bio_free_pages(struct pblk *pblk, struct bio *bio, int off, |
| 324 | int nr_pages) |
| 325 | { |
| 326 | struct bio_vec bv; |
| 327 | int i; |
| 328 | |
| 329 | WARN_ON(off + nr_pages != bio->bi_vcnt); |
| 330 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 331 | for (i = off; i < nr_pages + off; i++) { |
| 332 | bv = bio->bi_io_vec[i]; |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 333 | mempool_free(bv.bv_page, &pblk->page_bio_pool); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
| 337 | int pblk_bio_add_pages(struct pblk *pblk, struct bio *bio, gfp_t flags, |
| 338 | int nr_pages) |
| 339 | { |
| 340 | struct request_queue *q = pblk->dev->q; |
| 341 | struct page *page; |
| 342 | int i, ret; |
| 343 | |
| 344 | for (i = 0; i < nr_pages; i++) { |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 345 | page = mempool_alloc(&pblk->page_bio_pool, flags); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 346 | |
| 347 | ret = bio_add_pc_page(q, bio, page, PBLK_EXPOSED_PAGE_SIZE, 0); |
| 348 | if (ret != PBLK_EXPOSED_PAGE_SIZE) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 349 | pblk_err(pblk, "could not add page to bio\n"); |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 350 | mempool_free(page, &pblk->page_bio_pool); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 351 | goto err; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return 0; |
| 356 | err: |
Igor Konopko | f142ac0 | 2018-06-01 16:41:08 +0200 | [diff] [blame] | 357 | pblk_bio_free_pages(pblk, bio, (bio->bi_vcnt - i), i); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 358 | return -1; |
| 359 | } |
| 360 | |
Hans Holmberg | cc9c9a0 | 2018-06-01 16:41:13 +0200 | [diff] [blame] | 361 | void pblk_write_kick(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 362 | { |
| 363 | wake_up_process(pblk->writer_ts); |
| 364 | mod_timer(&pblk->wtimer, jiffies + msecs_to_jiffies(1000)); |
| 365 | } |
| 366 | |
Kees Cook | 87c1d2d | 2017-10-17 21:10:19 -0700 | [diff] [blame] | 367 | void pblk_write_timer_fn(struct timer_list *t) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 368 | { |
Kees Cook | 87c1d2d | 2017-10-17 21:10:19 -0700 | [diff] [blame] | 369 | struct pblk *pblk = from_timer(pblk, t, wtimer); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 370 | |
| 371 | /* kick the write thread every tick to flush outstanding data */ |
| 372 | pblk_write_kick(pblk); |
| 373 | } |
| 374 | |
| 375 | void pblk_write_should_kick(struct pblk *pblk) |
| 376 | { |
| 377 | unsigned int secs_avail = pblk_rb_read_count(&pblk->rwb); |
| 378 | |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 379 | if (secs_avail >= pblk->min_write_pgs_data) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 380 | pblk_write_kick(pblk); |
| 381 | } |
| 382 | |
Javier González | 8bd4002 | 2017-10-13 14:46:44 +0200 | [diff] [blame] | 383 | static void pblk_wait_for_meta(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 384 | { |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 385 | do { |
| 386 | if (!atomic_read(&pblk->inflight_io)) |
| 387 | break; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 388 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 389 | schedule(); |
| 390 | } while (1); |
| 391 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 392 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 393 | static void pblk_flush_writer(struct pblk *pblk) |
| 394 | { |
| 395 | pblk_rb_flush(&pblk->rwb); |
| 396 | do { |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 397 | if (!pblk_rb_sync_count(&pblk->rwb)) |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 398 | break; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 399 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 400 | pblk_write_kick(pblk); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 401 | schedule(); |
| 402 | } while (1); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | struct list_head *pblk_line_gc_list(struct pblk *pblk, struct pblk_line *line) |
| 406 | { |
| 407 | struct pblk_line_meta *lm = &pblk->lm; |
| 408 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 409 | struct list_head *move_list = NULL; |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 410 | int packed_meta = (le32_to_cpu(*line->vsc) / pblk->min_write_pgs_data) |
| 411 | * (pblk->min_write_pgs - pblk->min_write_pgs_data); |
| 412 | int vsc = le32_to_cpu(*line->vsc) + packed_meta; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 413 | |
Javier González | 476118c | 2017-06-26 11:57:26 +0200 | [diff] [blame] | 414 | lockdep_assert_held(&line->lock); |
| 415 | |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 416 | if (line->w_err_gc->has_write_err) { |
| 417 | if (line->gc_group != PBLK_LINEGC_WERR) { |
| 418 | line->gc_group = PBLK_LINEGC_WERR; |
| 419 | move_list = &l_mg->gc_werr_list; |
| 420 | pblk_rl_werr_line_in(&pblk->rl); |
| 421 | } |
| 422 | } else if (!vsc) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 423 | if (line->gc_group != PBLK_LINEGC_FULL) { |
| 424 | line->gc_group = PBLK_LINEGC_FULL; |
| 425 | move_list = &l_mg->gc_full_list; |
| 426 | } |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 427 | } else if (vsc < lm->high_thrs) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 428 | if (line->gc_group != PBLK_LINEGC_HIGH) { |
| 429 | line->gc_group = PBLK_LINEGC_HIGH; |
| 430 | move_list = &l_mg->gc_high_list; |
| 431 | } |
Javier González | b20ba1b | 2017-06-26 11:57:27 +0200 | [diff] [blame] | 432 | } else if (vsc < lm->mid_thrs) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 433 | if (line->gc_group != PBLK_LINEGC_MID) { |
| 434 | line->gc_group = PBLK_LINEGC_MID; |
| 435 | move_list = &l_mg->gc_mid_list; |
| 436 | } |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 437 | } else if (vsc < line->sec_in_line) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 438 | if (line->gc_group != PBLK_LINEGC_LOW) { |
| 439 | line->gc_group = PBLK_LINEGC_LOW; |
| 440 | move_list = &l_mg->gc_low_list; |
| 441 | } |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 442 | } else if (vsc == line->sec_in_line) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 443 | if (line->gc_group != PBLK_LINEGC_EMPTY) { |
| 444 | line->gc_group = PBLK_LINEGC_EMPTY; |
| 445 | move_list = &l_mg->gc_empty_list; |
| 446 | } |
| 447 | } else { |
| 448 | line->state = PBLK_LINESTATE_CORRUPT; |
Hans Holmberg | f293723 | 2018-10-09 13:11:53 +0200 | [diff] [blame] | 449 | trace_pblk_line_state(pblk_disk_name(pblk), line->id, |
| 450 | line->state); |
| 451 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 452 | line->gc_group = PBLK_LINEGC_NONE; |
| 453 | move_list = &l_mg->corrupt_list; |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 454 | pblk_err(pblk, "corrupted vsc for line %d, vsc:%d (%d/%d/%d)\n", |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 455 | line->id, vsc, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 456 | line->sec_in_line, |
| 457 | lm->high_thrs, lm->mid_thrs); |
| 458 | } |
| 459 | |
| 460 | return move_list; |
| 461 | } |
| 462 | |
| 463 | void pblk_discard(struct pblk *pblk, struct bio *bio) |
| 464 | { |
| 465 | sector_t slba = pblk_get_lba(bio); |
| 466 | sector_t nr_secs = pblk_get_secs(bio); |
| 467 | |
| 468 | pblk_invalidate_range(pblk, slba, nr_secs); |
| 469 | } |
| 470 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 471 | void pblk_log_write_err(struct pblk *pblk, struct nvm_rq *rqd) |
| 472 | { |
| 473 | atomic_long_inc(&pblk->write_failed); |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 474 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 475 | pblk_print_failed_rqd(pblk, rqd, rqd->error); |
| 476 | #endif |
| 477 | } |
| 478 | |
| 479 | void pblk_log_read_err(struct pblk *pblk, struct nvm_rq *rqd) |
| 480 | { |
| 481 | /* Empty page read is not necessarily an error (e.g., L2P recovery) */ |
| 482 | if (rqd->error == NVM_RSP_ERR_EMPTYPAGE) { |
| 483 | atomic_long_inc(&pblk->read_empty); |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | switch (rqd->error) { |
| 488 | case NVM_RSP_WARN_HIGHECC: |
| 489 | atomic_long_inc(&pblk->read_high_ecc); |
| 490 | break; |
| 491 | case NVM_RSP_ERR_FAILECC: |
| 492 | case NVM_RSP_ERR_FAILCRC: |
| 493 | atomic_long_inc(&pblk->read_failed); |
| 494 | break; |
| 495 | default: |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 496 | pblk_err(pblk, "unknown read error:%d\n", rqd->error); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 497 | } |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 498 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 499 | pblk_print_failed_rqd(pblk, rqd, rqd->error); |
| 500 | #endif |
| 501 | } |
| 502 | |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 503 | void pblk_set_sec_per_write(struct pblk *pblk, int sec_per_write) |
| 504 | { |
| 505 | pblk->sec_per_write = sec_per_write; |
| 506 | } |
| 507 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 508 | int pblk_submit_io(struct pblk *pblk, struct nvm_rq *rqd) |
| 509 | { |
| 510 | struct nvm_tgt_dev *dev = pblk->dev; |
| 511 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 512 | atomic_inc(&pblk->inflight_io); |
| 513 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 514 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | b6730dd4 | 2018-06-01 15:04:20 +0200 | [diff] [blame] | 515 | if (pblk_check_io(pblk, rqd)) |
| 516 | return NVM_IO_ERR; |
| 517 | #endif |
| 518 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 519 | return nvm_submit_io(dev, rqd); |
| 520 | } |
| 521 | |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 522 | void pblk_check_chunk_state_update(struct pblk *pblk, struct nvm_rq *rqd) |
| 523 | { |
| 524 | struct ppa_addr *ppa_list = nvm_rq_to_ppa_list(rqd); |
| 525 | |
| 526 | int i; |
| 527 | |
| 528 | for (i = 0; i < rqd->nr_ppas; i++) { |
| 529 | struct ppa_addr *ppa = &ppa_list[i]; |
| 530 | struct nvm_chk_meta *chunk = pblk_dev_ppa_to_chunk(pblk, *ppa); |
| 531 | u64 caddr = pblk_dev_ppa_to_chunk_addr(pblk, *ppa); |
| 532 | |
| 533 | if (caddr == 0) |
| 534 | trace_pblk_chunk_state(pblk_disk_name(pblk), |
| 535 | ppa, NVM_CHK_ST_OPEN); |
Hans Holmberg | 96076f7 | 2018-12-11 20:16:09 +0100 | [diff] [blame] | 536 | else if (caddr == (chunk->cnlb - 1)) |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 537 | trace_pblk_chunk_state(pblk_disk_name(pblk), |
| 538 | ppa, NVM_CHK_ST_CLOSED); |
| 539 | } |
| 540 | } |
| 541 | |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 542 | int pblk_submit_io_sync(struct pblk *pblk, struct nvm_rq *rqd) |
| 543 | { |
| 544 | struct nvm_tgt_dev *dev = pblk->dev; |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 545 | int ret; |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 546 | |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 547 | atomic_inc(&pblk->inflight_io); |
| 548 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 549 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | b6730dd4 | 2018-06-01 15:04:20 +0200 | [diff] [blame] | 550 | if (pblk_check_io(pblk, rqd)) |
| 551 | return NVM_IO_ERR; |
| 552 | #endif |
| 553 | |
Hans Holmberg | 4c44abf | 2018-10-09 13:11:52 +0200 | [diff] [blame] | 554 | ret = nvm_submit_io_sync(dev, rqd); |
| 555 | |
| 556 | if (trace_pblk_chunk_state_enabled() && !ret && |
| 557 | rqd->opcode == NVM_OP_PWRITE) |
| 558 | pblk_check_chunk_state_update(pblk, rqd); |
| 559 | |
| 560 | return ret; |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Javier González | 253babc | 2018-10-09 13:12:04 +0200 | [diff] [blame] | 563 | int pblk_submit_io_sync_sem(struct pblk *pblk, struct nvm_rq *rqd) |
| 564 | { |
| 565 | struct ppa_addr *ppa_list; |
| 566 | int ret; |
| 567 | |
| 568 | ppa_list = (rqd->nr_ppas > 1) ? rqd->ppa_list : &rqd->ppa_addr; |
| 569 | |
| 570 | pblk_down_chunk(pblk, ppa_list[0]); |
| 571 | ret = pblk_submit_io_sync(pblk, rqd); |
| 572 | pblk_up_chunk(pblk, ppa_list[0]); |
| 573 | |
| 574 | return ret; |
| 575 | } |
| 576 | |
Javier González | 55e836d | 2017-10-13 14:46:16 +0200 | [diff] [blame] | 577 | static void pblk_bio_map_addr_endio(struct bio *bio) |
| 578 | { |
| 579 | bio_put(bio); |
| 580 | } |
| 581 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 582 | struct bio *pblk_bio_map_addr(struct pblk *pblk, void *data, |
| 583 | unsigned int nr_secs, unsigned int len, |
Javier González | de54e70 | 2017-06-30 17:56:39 +0200 | [diff] [blame] | 584 | int alloc_type, gfp_t gfp_mask) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 585 | { |
| 586 | struct nvm_tgt_dev *dev = pblk->dev; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 587 | void *kaddr = data; |
| 588 | struct page *page; |
| 589 | struct bio *bio; |
| 590 | int i, ret; |
| 591 | |
Javier González | de54e70 | 2017-06-30 17:56:39 +0200 | [diff] [blame] | 592 | if (alloc_type == PBLK_KMALLOC_META) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 593 | return bio_map_kern(dev->q, kaddr, len, gfp_mask); |
| 594 | |
| 595 | bio = bio_kmalloc(gfp_mask, nr_secs); |
| 596 | if (!bio) |
| 597 | return ERR_PTR(-ENOMEM); |
| 598 | |
| 599 | for (i = 0; i < nr_secs; i++) { |
| 600 | page = vmalloc_to_page(kaddr); |
| 601 | if (!page) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 602 | pblk_err(pblk, "could not map vmalloc bio\n"); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 603 | bio_put(bio); |
| 604 | bio = ERR_PTR(-ENOMEM); |
| 605 | goto out; |
| 606 | } |
| 607 | |
| 608 | ret = bio_add_pc_page(dev->q, bio, page, PAGE_SIZE, 0); |
| 609 | if (ret != PAGE_SIZE) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 610 | pblk_err(pblk, "could not add page to bio\n"); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 611 | bio_put(bio); |
| 612 | bio = ERR_PTR(-ENOMEM); |
| 613 | goto out; |
| 614 | } |
| 615 | |
| 616 | kaddr += PAGE_SIZE; |
| 617 | } |
Javier González | 55e836d | 2017-10-13 14:46:16 +0200 | [diff] [blame] | 618 | |
| 619 | bio->bi_end_io = pblk_bio_map_addr_endio; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 620 | out: |
| 621 | return bio; |
| 622 | } |
| 623 | |
| 624 | int pblk_calc_secs(struct pblk *pblk, unsigned long secs_avail, |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 625 | unsigned long secs_to_flush, bool skip_meta) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 626 | { |
Javier González | c2e9f5d | 2017-06-26 11:57:14 +0200 | [diff] [blame] | 627 | int max = pblk->sec_per_write; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 628 | int min = pblk->min_write_pgs; |
| 629 | int secs_to_sync = 0; |
| 630 | |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 631 | if (skip_meta && pblk->min_write_pgs_data != pblk->min_write_pgs) |
| 632 | min = max = pblk->min_write_pgs_data; |
| 633 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 634 | if (secs_avail >= max) |
| 635 | secs_to_sync = max; |
| 636 | else if (secs_avail >= min) |
| 637 | secs_to_sync = min * (secs_avail / min); |
| 638 | else if (secs_to_flush) |
| 639 | secs_to_sync = min; |
| 640 | |
| 641 | return secs_to_sync; |
| 642 | } |
| 643 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 644 | void pblk_dealloc_page(struct pblk *pblk, struct pblk_line *line, int nr_secs) |
| 645 | { |
| 646 | u64 addr; |
| 647 | int i; |
| 648 | |
Rakesh Pandit | e57903f | 2017-10-13 14:45:56 +0200 | [diff] [blame] | 649 | spin_lock(&line->lock); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 650 | addr = find_next_zero_bit(line->map_bitmap, |
| 651 | pblk->lm.sec_per_line, line->cur_sec); |
| 652 | line->cur_sec = addr - nr_secs; |
| 653 | |
| 654 | for (i = 0; i < nr_secs; i++, line->cur_sec--) |
| 655 | WARN_ON(!test_and_clear_bit(line->cur_sec, line->map_bitmap)); |
Rakesh Pandit | e57903f | 2017-10-13 14:45:56 +0200 | [diff] [blame] | 656 | spin_unlock(&line->lock); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | u64 __pblk_alloc_page(struct pblk *pblk, struct pblk_line *line, int nr_secs) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 660 | { |
| 661 | u64 addr; |
| 662 | int i; |
| 663 | |
Javier González | 476118c | 2017-06-26 11:57:26 +0200 | [diff] [blame] | 664 | lockdep_assert_held(&line->lock); |
| 665 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 666 | /* logic error: ppa out-of-bounds. Prevent generating bad address */ |
| 667 | if (line->cur_sec + nr_secs > pblk->lm.sec_per_line) { |
| 668 | WARN(1, "pblk: page allocation out of bounds\n"); |
| 669 | nr_secs = pblk->lm.sec_per_line - line->cur_sec; |
| 670 | } |
| 671 | |
| 672 | line->cur_sec = addr = find_next_zero_bit(line->map_bitmap, |
| 673 | pblk->lm.sec_per_line, line->cur_sec); |
| 674 | for (i = 0; i < nr_secs; i++, line->cur_sec++) |
| 675 | WARN_ON(test_and_set_bit(line->cur_sec, line->map_bitmap)); |
| 676 | |
| 677 | return addr; |
| 678 | } |
| 679 | |
| 680 | u64 pblk_alloc_page(struct pblk *pblk, struct pblk_line *line, int nr_secs) |
| 681 | { |
| 682 | u64 addr; |
| 683 | |
| 684 | /* Lock needed in case a write fails and a recovery needs to remap |
| 685 | * failed write buffer entries |
| 686 | */ |
| 687 | spin_lock(&line->lock); |
| 688 | addr = __pblk_alloc_page(pblk, line, nr_secs); |
| 689 | line->left_msecs -= nr_secs; |
| 690 | WARN(line->left_msecs < 0, "pblk: page allocation out of bounds\n"); |
| 691 | spin_unlock(&line->lock); |
| 692 | |
| 693 | return addr; |
| 694 | } |
| 695 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 696 | u64 pblk_lookup_page(struct pblk *pblk, struct pblk_line *line) |
| 697 | { |
| 698 | u64 paddr; |
| 699 | |
| 700 | spin_lock(&line->lock); |
| 701 | paddr = find_next_zero_bit(line->map_bitmap, |
| 702 | pblk->lm.sec_per_line, line->cur_sec); |
| 703 | spin_unlock(&line->lock); |
| 704 | |
| 705 | return paddr; |
| 706 | } |
| 707 | |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 708 | u64 pblk_line_smeta_start(struct pblk *pblk, struct pblk_line *line) |
| 709 | { |
| 710 | struct nvm_tgt_dev *dev = pblk->dev; |
| 711 | struct nvm_geo *geo = &dev->geo; |
| 712 | struct pblk_line_meta *lm = &pblk->lm; |
| 713 | int bit; |
| 714 | |
| 715 | /* This usually only happens on bad lines */ |
| 716 | bit = find_first_zero_bit(line->blk_bitmap, lm->blk_per_line); |
| 717 | if (bit >= lm->blk_per_line) |
| 718 | return -1; |
| 719 | |
| 720 | return bit * geo->ws_opt; |
| 721 | } |
| 722 | |
| 723 | int pblk_line_smeta_read(struct pblk *pblk, struct pblk_line *line) |
| 724 | { |
| 725 | struct nvm_tgt_dev *dev = pblk->dev; |
| 726 | struct pblk_line_meta *lm = &pblk->lm; |
| 727 | struct bio *bio; |
| 728 | struct nvm_rq rqd; |
| 729 | u64 paddr = pblk_line_smeta_start(pblk, line); |
| 730 | int i, ret; |
| 731 | |
| 732 | memset(&rqd, 0, sizeof(struct nvm_rq)); |
| 733 | |
| 734 | ret = pblk_alloc_rqd_meta(pblk, &rqd); |
| 735 | if (ret) |
| 736 | return ret; |
| 737 | |
| 738 | bio = bio_map_kern(dev->q, line->smeta, lm->smeta_len, GFP_KERNEL); |
| 739 | if (IS_ERR(bio)) { |
| 740 | ret = PTR_ERR(bio); |
| 741 | goto clear_rqd; |
| 742 | } |
| 743 | |
| 744 | bio->bi_iter.bi_sector = 0; /* internal bio */ |
| 745 | bio_set_op_attrs(bio, REQ_OP_READ, 0); |
| 746 | |
| 747 | rqd.bio = bio; |
| 748 | rqd.opcode = NVM_OP_PREAD; |
| 749 | rqd.nr_ppas = lm->smeta_sec; |
| 750 | rqd.is_seq = 1; |
| 751 | |
| 752 | for (i = 0; i < lm->smeta_sec; i++, paddr++) |
| 753 | rqd.ppa_list[i] = addr_to_gen_ppa(pblk, paddr, line->id); |
| 754 | |
| 755 | ret = pblk_submit_io_sync(pblk, &rqd); |
| 756 | if (ret) { |
| 757 | pblk_err(pblk, "smeta I/O submission failed: %d\n", ret); |
| 758 | bio_put(bio); |
| 759 | goto clear_rqd; |
| 760 | } |
| 761 | |
| 762 | atomic_dec(&pblk->inflight_io); |
| 763 | |
| 764 | if (rqd.error) |
| 765 | pblk_log_read_err(pblk, &rqd); |
| 766 | |
| 767 | clear_rqd: |
| 768 | pblk_free_rqd_meta(pblk, &rqd); |
| 769 | return ret; |
| 770 | } |
| 771 | |
| 772 | static int pblk_line_smeta_write(struct pblk *pblk, struct pblk_line *line, |
| 773 | u64 paddr) |
| 774 | { |
| 775 | struct nvm_tgt_dev *dev = pblk->dev; |
| 776 | struct pblk_line_meta *lm = &pblk->lm; |
| 777 | struct bio *bio; |
| 778 | struct nvm_rq rqd; |
| 779 | __le64 *lba_list = emeta_to_lbas(pblk, line->emeta->buf); |
| 780 | __le64 addr_empty = cpu_to_le64(ADDR_EMPTY); |
| 781 | int i, ret; |
| 782 | |
| 783 | memset(&rqd, 0, sizeof(struct nvm_rq)); |
| 784 | |
| 785 | ret = pblk_alloc_rqd_meta(pblk, &rqd); |
| 786 | if (ret) |
| 787 | return ret; |
| 788 | |
| 789 | bio = bio_map_kern(dev->q, line->smeta, lm->smeta_len, GFP_KERNEL); |
| 790 | if (IS_ERR(bio)) { |
| 791 | ret = PTR_ERR(bio); |
| 792 | goto clear_rqd; |
| 793 | } |
| 794 | |
| 795 | bio->bi_iter.bi_sector = 0; /* internal bio */ |
| 796 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); |
| 797 | |
| 798 | rqd.bio = bio; |
| 799 | rqd.opcode = NVM_OP_PWRITE; |
| 800 | rqd.nr_ppas = lm->smeta_sec; |
| 801 | rqd.is_seq = 1; |
| 802 | |
| 803 | for (i = 0; i < lm->smeta_sec; i++, paddr++) { |
Igor Konopko | faa79f2 | 2018-12-11 20:16:23 +0100 | [diff] [blame] | 804 | struct pblk_sec_meta *meta = pblk_get_meta(pblk, |
| 805 | rqd.meta_list, i); |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 806 | |
| 807 | rqd.ppa_list[i] = addr_to_gen_ppa(pblk, paddr, line->id); |
Igor Konopko | faa79f2 | 2018-12-11 20:16:23 +0100 | [diff] [blame] | 808 | meta->lba = lba_list[paddr] = addr_empty; |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 809 | } |
| 810 | |
Javier González | 253babc | 2018-10-09 13:12:04 +0200 | [diff] [blame] | 811 | ret = pblk_submit_io_sync_sem(pblk, &rqd); |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 812 | if (ret) { |
| 813 | pblk_err(pblk, "smeta I/O submission failed: %d\n", ret); |
| 814 | bio_put(bio); |
| 815 | goto clear_rqd; |
| 816 | } |
| 817 | |
| 818 | atomic_dec(&pblk->inflight_io); |
| 819 | |
| 820 | if (rqd.error) { |
| 821 | pblk_log_write_err(pblk, &rqd); |
| 822 | ret = -EIO; |
| 823 | } |
| 824 | |
| 825 | clear_rqd: |
| 826 | pblk_free_rqd_meta(pblk, &rqd); |
| 827 | return ret; |
| 828 | } |
| 829 | |
| 830 | int pblk_line_emeta_read(struct pblk *pblk, struct pblk_line *line, |
| 831 | void *emeta_buf) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 832 | { |
| 833 | struct nvm_tgt_dev *dev = pblk->dev; |
| 834 | struct nvm_geo *geo = &dev->geo; |
Javier González | de54e70 | 2017-06-30 17:56:39 +0200 | [diff] [blame] | 835 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 836 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | 63e3809 | 2017-06-26 11:57:24 +0200 | [diff] [blame] | 837 | void *ppa_list, *meta_list; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 838 | struct bio *bio; |
| 839 | struct nvm_rq rqd; |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 840 | u64 paddr = line->emeta_ssec; |
Javier González | 63e3809 | 2017-06-26 11:57:24 +0200 | [diff] [blame] | 841 | dma_addr_t dma_ppa_list, dma_meta_list; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 842 | int min = pblk->min_write_pgs; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 843 | int left_ppas = lm->emeta_sec[0]; |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 844 | int line_id = line->id; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 845 | int rq_ppas, rq_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 846 | int i, j; |
| 847 | int ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 848 | |
Javier González | 63e3809 | 2017-06-26 11:57:24 +0200 | [diff] [blame] | 849 | meta_list = nvm_dev_dma_alloc(dev->parent, GFP_KERNEL, |
| 850 | &dma_meta_list); |
| 851 | if (!meta_list) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 852 | return -ENOMEM; |
| 853 | |
Igor Konopko | 24828d0 | 2018-12-11 20:16:24 +0100 | [diff] [blame] | 854 | ppa_list = meta_list + pblk_dma_meta_size(pblk); |
| 855 | dma_ppa_list = dma_meta_list + pblk_dma_meta_size(pblk); |
Javier González | 63e3809 | 2017-06-26 11:57:24 +0200 | [diff] [blame] | 856 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 857 | next_rq: |
| 858 | memset(&rqd, 0, sizeof(struct nvm_rq)); |
| 859 | |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 860 | rq_ppas = pblk_calc_secs(pblk, left_ppas, 0, false); |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 861 | rq_len = rq_ppas * geo->csecs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 862 | |
Javier González | de54e70 | 2017-06-30 17:56:39 +0200 | [diff] [blame] | 863 | bio = pblk_bio_map_addr(pblk, emeta_buf, rq_ppas, rq_len, |
| 864 | l_mg->emeta_alloc_type, GFP_KERNEL); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 865 | if (IS_ERR(bio)) { |
| 866 | ret = PTR_ERR(bio); |
| 867 | goto free_rqd_dma; |
| 868 | } |
| 869 | |
| 870 | bio->bi_iter.bi_sector = 0; /* internal bio */ |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 871 | bio_set_op_attrs(bio, REQ_OP_READ, 0); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 872 | |
| 873 | rqd.bio = bio; |
Javier González | 63e3809 | 2017-06-26 11:57:24 +0200 | [diff] [blame] | 874 | rqd.meta_list = meta_list; |
| 875 | rqd.ppa_list = ppa_list; |
| 876 | rqd.dma_meta_list = dma_meta_list; |
| 877 | rqd.dma_ppa_list = dma_ppa_list; |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 878 | rqd.opcode = NVM_OP_PREAD; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 879 | rqd.nr_ppas = rq_ppas; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 880 | |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 881 | for (i = 0; i < rqd.nr_ppas; ) { |
| 882 | struct ppa_addr ppa = addr_to_gen_ppa(pblk, paddr, line_id); |
| 883 | int pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | 63e3809 | 2017-06-26 11:57:24 +0200 | [diff] [blame] | 884 | |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 885 | if (pblk_io_aligned(pblk, rq_ppas)) |
| 886 | rqd.is_seq = 1; |
Javier González | f9c1015 | 2017-06-26 11:57:20 +0200 | [diff] [blame] | 887 | |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 888 | while (test_bit(pos, line->blk_bitmap)) { |
| 889 | paddr += min; |
| 890 | if (pblk_boundary_paddr_checks(pblk, paddr)) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 891 | bio_put(bio); |
| 892 | ret = -EINTR; |
| 893 | goto free_rqd_dma; |
| 894 | } |
| 895 | |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 896 | ppa = addr_to_gen_ppa(pblk, paddr, line_id); |
| 897 | pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 898 | } |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 899 | |
| 900 | if (pblk_boundary_paddr_checks(pblk, paddr + min)) { |
| 901 | bio_put(bio); |
| 902 | ret = -EINTR; |
| 903 | goto free_rqd_dma; |
| 904 | } |
| 905 | |
| 906 | for (j = 0; j < min; j++, i++, paddr++) |
| 907 | rqd.ppa_list[i] = addr_to_gen_ppa(pblk, paddr, line_id); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 908 | } |
| 909 | |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 910 | ret = pblk_submit_io_sync(pblk, &rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 911 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 912 | pblk_err(pblk, "emeta I/O submission failed: %d\n", ret); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 913 | bio_put(bio); |
| 914 | goto free_rqd_dma; |
| 915 | } |
| 916 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 917 | atomic_dec(&pblk->inflight_io); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 918 | |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 919 | if (rqd.error) |
| 920 | pblk_log_read_err(pblk, &rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 921 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 922 | emeta_buf += rq_len; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 923 | left_ppas -= rq_ppas; |
| 924 | if (left_ppas) |
| 925 | goto next_rq; |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 926 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 927 | free_rqd_dma: |
Javier González | 63e3809 | 2017-06-26 11:57:24 +0200 | [diff] [blame] | 928 | nvm_dev_dma_free(dev->parent, rqd.meta_list, rqd.dma_meta_list); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 929 | return ret; |
| 930 | } |
| 931 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 932 | static void pblk_setup_e_rq(struct pblk *pblk, struct nvm_rq *rqd, |
| 933 | struct ppa_addr ppa) |
| 934 | { |
| 935 | rqd->opcode = NVM_OP_ERASE; |
| 936 | rqd->ppa_addr = ppa; |
| 937 | rqd->nr_ppas = 1; |
Matias Bjørling | d7b6801 | 2018-10-09 13:11:32 +0200 | [diff] [blame] | 938 | rqd->is_seq = 1; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 939 | rqd->bio = NULL; |
| 940 | } |
| 941 | |
| 942 | static int pblk_blk_erase_sync(struct pblk *pblk, struct ppa_addr ppa) |
| 943 | { |
Matias Bjørling | 4b5d56e | 2018-10-09 13:11:33 +0200 | [diff] [blame] | 944 | struct nvm_rq rqd = {NULL}; |
| 945 | int ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 946 | |
Hans Holmberg | 4209c31 | 2018-10-09 13:11:55 +0200 | [diff] [blame] | 947 | trace_pblk_chunk_reset(pblk_disk_name(pblk), &ppa, |
| 948 | PBLK_CHUNK_RESET_START); |
| 949 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 950 | pblk_setup_e_rq(pblk, &rqd, ppa); |
| 951 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 952 | /* The write thread schedules erases so that it minimizes disturbances |
| 953 | * with writes. Thus, there is no need to take the LUN semaphore. |
| 954 | */ |
Javier González | 1a94b2d | 2017-10-13 14:46:47 +0200 | [diff] [blame] | 955 | ret = pblk_submit_io_sync(pblk, &rqd); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 956 | rqd.private = pblk; |
| 957 | __pblk_end_io_erase(pblk, &rqd); |
| 958 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 959 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | int pblk_line_erase(struct pblk *pblk, struct pblk_line *line) |
| 963 | { |
| 964 | struct pblk_line_meta *lm = &pblk->lm; |
| 965 | struct ppa_addr ppa; |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 966 | int ret, bit = -1; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 967 | |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 968 | /* Erase only good blocks, one at a time */ |
| 969 | do { |
| 970 | spin_lock(&line->lock); |
| 971 | bit = find_next_zero_bit(line->erase_bitmap, lm->blk_per_line, |
| 972 | bit + 1); |
| 973 | if (bit >= lm->blk_per_line) { |
| 974 | spin_unlock(&line->lock); |
| 975 | break; |
| 976 | } |
| 977 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 978 | ppa = pblk->luns[bit].bppa; /* set ch and lun */ |
Javier González | 6947151 | 2018-03-30 00:05:15 +0200 | [diff] [blame] | 979 | ppa.a.blk = line->id; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 980 | |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 981 | atomic_dec(&line->left_eblks); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 982 | WARN_ON(test_and_set_bit(bit, line->erase_bitmap)); |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 983 | spin_unlock(&line->lock); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 984 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 985 | ret = pblk_blk_erase_sync(pblk, ppa); |
| 986 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 987 | pblk_err(pblk, "failed to erase line %d\n", line->id); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 988 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 989 | } |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 990 | } while (1); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 991 | |
| 992 | return 0; |
| 993 | } |
| 994 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 995 | static void pblk_line_setup_metadata(struct pblk_line *line, |
| 996 | struct pblk_line_mgmt *l_mg, |
| 997 | struct pblk_line_meta *lm) |
| 998 | { |
| 999 | int meta_line; |
| 1000 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1001 | lockdep_assert_held(&l_mg->free_lock); |
| 1002 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1003 | retry_meta: |
| 1004 | meta_line = find_first_zero_bit(&l_mg->meta_bitmap, PBLK_DATA_LINES); |
| 1005 | if (meta_line == PBLK_DATA_LINES) { |
| 1006 | spin_unlock(&l_mg->free_lock); |
| 1007 | io_schedule(); |
| 1008 | spin_lock(&l_mg->free_lock); |
| 1009 | goto retry_meta; |
| 1010 | } |
| 1011 | |
| 1012 | set_bit(meta_line, &l_mg->meta_bitmap); |
| 1013 | line->meta_line = meta_line; |
| 1014 | |
| 1015 | line->smeta = l_mg->sline_meta[meta_line]; |
| 1016 | line->emeta = l_mg->eline_meta[meta_line]; |
| 1017 | |
| 1018 | memset(line->smeta, 0, lm->smeta_len); |
| 1019 | memset(line->emeta->buf, 0, lm->emeta_len[0]); |
| 1020 | |
| 1021 | line->emeta->mem = 0; |
| 1022 | atomic_set(&line->emeta->sync, 0); |
| 1023 | } |
| 1024 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1025 | /* For now lines are always assumed full lines. Thus, smeta former and current |
| 1026 | * lun bitmaps are omitted. |
| 1027 | */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1028 | static int pblk_line_init_metadata(struct pblk *pblk, struct pblk_line *line, |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1029 | struct pblk_line *cur) |
| 1030 | { |
| 1031 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1032 | struct nvm_geo *geo = &dev->geo; |
| 1033 | struct pblk_line_meta *lm = &pblk->lm; |
| 1034 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1035 | struct pblk_emeta *emeta = line->emeta; |
| 1036 | struct line_emeta *emeta_buf = emeta->buf; |
| 1037 | struct line_smeta *smeta_buf = (struct line_smeta *)line->smeta; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1038 | int nr_blk_line; |
| 1039 | |
| 1040 | /* After erasing the line, new bad blocks might appear and we risk |
| 1041 | * having an invalid line |
| 1042 | */ |
| 1043 | nr_blk_line = lm->blk_per_line - |
| 1044 | bitmap_weight(line->blk_bitmap, lm->blk_per_line); |
| 1045 | if (nr_blk_line < lm->min_blk_line) { |
| 1046 | spin_lock(&l_mg->free_lock); |
| 1047 | spin_lock(&line->lock); |
| 1048 | line->state = PBLK_LINESTATE_BAD; |
Hans Holmberg | f293723 | 2018-10-09 13:11:53 +0200 | [diff] [blame] | 1049 | trace_pblk_line_state(pblk_disk_name(pblk), line->id, |
| 1050 | line->state); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1051 | spin_unlock(&line->lock); |
| 1052 | |
| 1053 | list_add_tail(&line->list, &l_mg->bad_list); |
| 1054 | spin_unlock(&l_mg->free_lock); |
| 1055 | |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1056 | pblk_debug(pblk, "line %d is bad\n", line->id); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1057 | |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | /* Run-time metadata */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1062 | line->lun_bitmap = ((void *)(smeta_buf)) + sizeof(struct line_smeta); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1063 | |
| 1064 | /* Mark LUNs allocated in this line (all for now) */ |
| 1065 | bitmap_set(line->lun_bitmap, 0, lm->lun_bitmap_len); |
| 1066 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1067 | smeta_buf->header.identifier = cpu_to_le32(PBLK_MAGIC); |
Andy Shevchenko | 7e0a084 | 2019-02-11 13:25:05 +0100 | [diff] [blame] | 1068 | guid_copy((guid_t *)&smeta_buf->header.uuid, &pblk->instance_uuid); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1069 | smeta_buf->header.id = cpu_to_le32(line->id); |
| 1070 | smeta_buf->header.type = cpu_to_le16(line->type); |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 1071 | smeta_buf->header.version_major = SMETA_VERSION_MAJOR; |
| 1072 | smeta_buf->header.version_minor = SMETA_VERSION_MINOR; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1073 | |
| 1074 | /* Start metadata */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1075 | smeta_buf->seq_nr = cpu_to_le64(line->seq_nr); |
Matias Bjørling | fae7fae | 2018-01-05 14:16:03 +0100 | [diff] [blame] | 1076 | smeta_buf->window_wr_lun = cpu_to_le32(geo->all_luns); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1077 | |
| 1078 | /* Fill metadata among lines */ |
| 1079 | if (cur) { |
| 1080 | memcpy(line->lun_bitmap, cur->lun_bitmap, lm->lun_bitmap_len); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1081 | smeta_buf->prev_id = cpu_to_le32(cur->id); |
| 1082 | cur->emeta->buf->next_id = cpu_to_le32(line->id); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1083 | } else { |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1084 | smeta_buf->prev_id = cpu_to_le32(PBLK_LINE_EMPTY); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | /* All smeta must be set at this point */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1088 | smeta_buf->header.crc = cpu_to_le32( |
| 1089 | pblk_calc_meta_header_crc(pblk, &smeta_buf->header)); |
| 1090 | smeta_buf->crc = cpu_to_le32(pblk_calc_smeta_crc(pblk, smeta_buf)); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1091 | |
| 1092 | /* End metadata */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1093 | memcpy(&emeta_buf->header, &smeta_buf->header, |
| 1094 | sizeof(struct line_header)); |
Hans Holmberg | d0ab0b1 | 2018-03-30 00:04:51 +0200 | [diff] [blame] | 1095 | |
| 1096 | emeta_buf->header.version_major = EMETA_VERSION_MAJOR; |
| 1097 | emeta_buf->header.version_minor = EMETA_VERSION_MINOR; |
| 1098 | emeta_buf->header.crc = cpu_to_le32( |
| 1099 | pblk_calc_meta_header_crc(pblk, &emeta_buf->header)); |
| 1100 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1101 | emeta_buf->seq_nr = cpu_to_le64(line->seq_nr); |
| 1102 | emeta_buf->nr_lbas = cpu_to_le64(line->sec_in_line); |
| 1103 | emeta_buf->nr_valid_lbas = cpu_to_le64(0); |
| 1104 | emeta_buf->next_id = cpu_to_le32(PBLK_LINE_EMPTY); |
| 1105 | emeta_buf->crc = cpu_to_le32(0); |
| 1106 | emeta_buf->prev_id = smeta_buf->prev_id; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1107 | |
| 1108 | return 1; |
| 1109 | } |
| 1110 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1111 | static int pblk_line_alloc_bitmaps(struct pblk *pblk, struct pblk_line *line) |
| 1112 | { |
| 1113 | struct pblk_line_meta *lm = &pblk->lm; |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 1114 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1115 | |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 1116 | line->map_bitmap = mempool_alloc(l_mg->bitmap_pool, GFP_KERNEL); |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1117 | if (!line->map_bitmap) |
| 1118 | return -ENOMEM; |
| 1119 | |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 1120 | memset(line->map_bitmap, 0, lm->sec_bitmap_len); |
| 1121 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1122 | /* will be initialized using bb info from map_bitmap */ |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 1123 | line->invalid_bitmap = mempool_alloc(l_mg->bitmap_pool, GFP_KERNEL); |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1124 | if (!line->invalid_bitmap) { |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 1125 | mempool_free(line->map_bitmap, l_mg->bitmap_pool); |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1126 | line->map_bitmap = NULL; |
| 1127 | return -ENOMEM; |
| 1128 | } |
| 1129 | |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1133 | /* For now lines are always assumed full lines. Thus, smeta former and current |
| 1134 | * lun bitmaps are omitted. |
| 1135 | */ |
| 1136 | static int pblk_line_init_bb(struct pblk *pblk, struct pblk_line *line, |
| 1137 | int init) |
| 1138 | { |
| 1139 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1140 | struct nvm_geo *geo = &dev->geo; |
| 1141 | struct pblk_line_meta *lm = &pblk->lm; |
| 1142 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1143 | u64 off; |
| 1144 | int bit = -1; |
Hans Holmberg | cfe1c9e | 2018-03-30 00:04:50 +0200 | [diff] [blame] | 1145 | int emeta_secs; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1146 | |
| 1147 | line->sec_in_line = lm->sec_per_line; |
| 1148 | |
| 1149 | /* Capture bad block information on line mapping bitmaps */ |
| 1150 | while ((bit = find_next_bit(line->blk_bitmap, lm->blk_per_line, |
| 1151 | bit + 1)) < lm->blk_per_line) { |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 1152 | off = bit * geo->ws_opt; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1153 | bitmap_shift_left(l_mg->bb_aux, l_mg->bb_template, off, |
| 1154 | lm->sec_per_line); |
| 1155 | bitmap_or(line->map_bitmap, line->map_bitmap, l_mg->bb_aux, |
| 1156 | lm->sec_per_line); |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 1157 | line->sec_in_line -= geo->clba; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /* Mark smeta metadata sectors as bad sectors */ |
| 1161 | bit = find_first_zero_bit(line->blk_bitmap, lm->blk_per_line); |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 1162 | off = bit * geo->ws_opt; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1163 | bitmap_set(line->map_bitmap, off, lm->smeta_sec); |
| 1164 | line->sec_in_line -= lm->smeta_sec; |
| 1165 | line->smeta_ssec = off; |
| 1166 | line->cur_sec = off + lm->smeta_sec; |
| 1167 | |
Javier González | af3fac1 | 2018-10-09 13:12:03 +0200 | [diff] [blame] | 1168 | if (init && pblk_line_smeta_write(pblk, line, off)) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1169 | pblk_debug(pblk, "line smeta I/O failed. Retry\n"); |
Hans Holmberg | 6cf17a2 | 2018-06-01 16:41:07 +0200 | [diff] [blame] | 1170 | return 0; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | bitmap_copy(line->invalid_bitmap, line->map_bitmap, lm->sec_per_line); |
| 1174 | |
| 1175 | /* Mark emeta metadata sectors as bad sectors. We need to consider bad |
| 1176 | * blocks to make sure that there are enough sectors to store emeta |
| 1177 | */ |
Hans Holmberg | cfe1c9e | 2018-03-30 00:04:50 +0200 | [diff] [blame] | 1178 | emeta_secs = lm->emeta_sec[0]; |
| 1179 | off = lm->sec_per_line; |
| 1180 | while (emeta_secs) { |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 1181 | off -= geo->ws_opt; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1182 | if (!test_bit(off, line->invalid_bitmap)) { |
Javier González | e46f4e4 | 2018-03-30 00:05:10 +0200 | [diff] [blame] | 1183 | bitmap_set(line->invalid_bitmap, off, geo->ws_opt); |
| 1184 | emeta_secs -= geo->ws_opt; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1188 | line->emeta_ssec = off; |
Hans Holmberg | cfe1c9e | 2018-03-30 00:04:50 +0200 | [diff] [blame] | 1189 | line->sec_in_line -= lm->emeta_sec[0]; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1190 | line->nr_valid_lbas = 0; |
Javier González | 0880a9a | 2017-06-26 11:57:19 +0200 | [diff] [blame] | 1191 | line->left_msecs = line->sec_in_line; |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1192 | *line->vsc = cpu_to_le32(line->sec_in_line); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1193 | |
| 1194 | if (lm->sec_per_line - line->sec_in_line != |
| 1195 | bitmap_weight(line->invalid_bitmap, lm->sec_per_line)) { |
| 1196 | spin_lock(&line->lock); |
| 1197 | line->state = PBLK_LINESTATE_BAD; |
Hans Holmberg | f293723 | 2018-10-09 13:11:53 +0200 | [diff] [blame] | 1198 | trace_pblk_line_state(pblk_disk_name(pblk), line->id, |
| 1199 | line->state); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1200 | spin_unlock(&line->lock); |
| 1201 | |
| 1202 | list_add_tail(&line->list, &l_mg->bad_list); |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1203 | pblk_err(pblk, "unexpected line %d is bad\n", line->id); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | return 1; |
| 1209 | } |
| 1210 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1211 | static int pblk_prepare_new_line(struct pblk *pblk, struct pblk_line *line) |
| 1212 | { |
| 1213 | struct pblk_line_meta *lm = &pblk->lm; |
| 1214 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1215 | struct nvm_geo *geo = &dev->geo; |
| 1216 | int blk_to_erase = atomic_read(&line->blk_in_line); |
| 1217 | int i; |
| 1218 | |
| 1219 | for (i = 0; i < lm->blk_per_line; i++) { |
| 1220 | struct pblk_lun *rlun = &pblk->luns[i]; |
| 1221 | int pos = pblk_ppa_to_pos(geo, rlun->bppa); |
| 1222 | int state = line->chks[pos].state; |
| 1223 | |
| 1224 | /* Free chunks should not be erased */ |
| 1225 | if (state & NVM_CHK_ST_FREE) { |
| 1226 | set_bit(pblk_ppa_to_pos(geo, rlun->bppa), |
| 1227 | line->erase_bitmap); |
| 1228 | blk_to_erase--; |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | return blk_to_erase; |
| 1233 | } |
| 1234 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1235 | static int pblk_line_prepare(struct pblk *pblk, struct pblk_line *line) |
| 1236 | { |
| 1237 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | 1d8b33e | 2018-06-01 15:04:16 +0200 | [diff] [blame] | 1238 | int blk_in_line = atomic_read(&line->blk_in_line); |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1239 | int blk_to_erase; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1240 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1241 | /* Bad blocks do not need to be erased */ |
| 1242 | bitmap_copy(line->erase_bitmap, line->blk_bitmap, lm->blk_per_line); |
| 1243 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1244 | spin_lock(&line->lock); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1245 | |
| 1246 | /* If we have not written to this line, we need to mark up free chunks |
| 1247 | * as already erased |
| 1248 | */ |
| 1249 | if (line->state == PBLK_LINESTATE_NEW) { |
| 1250 | blk_to_erase = pblk_prepare_new_line(pblk, line); |
| 1251 | line->state = PBLK_LINESTATE_FREE; |
Hans Holmberg | f293723 | 2018-10-09 13:11:53 +0200 | [diff] [blame] | 1252 | trace_pblk_line_state(pblk_disk_name(pblk), line->id, |
| 1253 | line->state); |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1254 | } else { |
Javier González | 1d8b33e | 2018-06-01 15:04:16 +0200 | [diff] [blame] | 1255 | blk_to_erase = blk_in_line; |
| 1256 | } |
| 1257 | |
| 1258 | if (blk_in_line < lm->min_blk_line) { |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1259 | spin_unlock(&line->lock); |
| 1260 | return -EAGAIN; |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1261 | } |
| 1262 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1263 | if (line->state != PBLK_LINESTATE_FREE) { |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1264 | WARN(1, "pblk: corrupted line %d, state %d\n", |
| 1265 | line->id, line->state); |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1266 | spin_unlock(&line->lock); |
| 1267 | return -EINTR; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1268 | } |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1269 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1270 | line->state = PBLK_LINESTATE_OPEN; |
Hans Holmberg | f293723 | 2018-10-09 13:11:53 +0200 | [diff] [blame] | 1271 | trace_pblk_line_state(pblk_disk_name(pblk), line->id, |
| 1272 | line->state); |
Javier González | a44f53f | 2017-04-22 01:32:49 +0200 | [diff] [blame] | 1273 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1274 | atomic_set(&line->left_eblks, blk_to_erase); |
| 1275 | atomic_set(&line->left_seblks, blk_to_erase); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1276 | |
| 1277 | line->meta_distance = lm->meta_distance; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1278 | spin_unlock(&line->lock); |
| 1279 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1280 | kref_init(&line->ref); |
Heiner Litz | 0586942 | 2019-02-11 13:25:09 +0100 | [diff] [blame] | 1281 | atomic_set(&line->sec_to_update, 0); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1282 | |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
Javier González | 361d889 | 2018-12-11 20:16:19 +0100 | [diff] [blame] | 1286 | /* Line allocations in the recovery path are always single threaded */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1287 | int pblk_line_recov_alloc(struct pblk *pblk, struct pblk_line *line) |
| 1288 | { |
| 1289 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1290 | int ret; |
| 1291 | |
| 1292 | spin_lock(&l_mg->free_lock); |
| 1293 | l_mg->data_line = line; |
| 1294 | list_del(&line->list); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1295 | |
| 1296 | ret = pblk_line_prepare(pblk, line); |
| 1297 | if (ret) { |
| 1298 | list_add(&line->list, &l_mg->free_list); |
Javier González | 3dc001f | 2017-04-22 01:32:45 +0200 | [diff] [blame] | 1299 | spin_unlock(&l_mg->free_lock); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1300 | return ret; |
| 1301 | } |
Javier González | 3dc001f | 2017-04-22 01:32:45 +0200 | [diff] [blame] | 1302 | spin_unlock(&l_mg->free_lock); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1303 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1304 | ret = pblk_line_alloc_bitmaps(pblk, line); |
| 1305 | if (ret) |
Hua Su | fde201a | 2018-12-11 20:16:18 +0100 | [diff] [blame] | 1306 | goto fail; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1307 | |
| 1308 | if (!pblk_line_init_bb(pblk, line, 0)) { |
Hua Su | fde201a | 2018-12-11 20:16:18 +0100 | [diff] [blame] | 1309 | ret = -EINTR; |
| 1310 | goto fail; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1311 | } |
| 1312 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1313 | pblk_rl_free_lines_dec(&pblk->rl, line, true); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1314 | return 0; |
Hua Su | fde201a | 2018-12-11 20:16:18 +0100 | [diff] [blame] | 1315 | |
| 1316 | fail: |
| 1317 | spin_lock(&l_mg->free_lock); |
| 1318 | list_add(&line->list, &l_mg->free_list); |
| 1319 | spin_unlock(&l_mg->free_lock); |
| 1320 | |
| 1321 | return ret; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | void pblk_line_recov_close(struct pblk *pblk, struct pblk_line *line) |
| 1325 | { |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 1326 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1327 | |
| 1328 | mempool_free(line->map_bitmap, l_mg->bitmap_pool); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1329 | line->map_bitmap = NULL; |
| 1330 | line->smeta = NULL; |
| 1331 | line->emeta = NULL; |
| 1332 | } |
| 1333 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1334 | static void pblk_line_reinit(struct pblk_line *line) |
| 1335 | { |
| 1336 | *line->vsc = cpu_to_le32(EMPTY_ENTRY); |
| 1337 | |
| 1338 | line->map_bitmap = NULL; |
| 1339 | line->invalid_bitmap = NULL; |
| 1340 | line->smeta = NULL; |
| 1341 | line->emeta = NULL; |
| 1342 | } |
| 1343 | |
| 1344 | void pblk_line_free(struct pblk_line *line) |
| 1345 | { |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 1346 | struct pblk *pblk = line->pblk; |
| 1347 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1348 | |
| 1349 | mempool_free(line->map_bitmap, l_mg->bitmap_pool); |
| 1350 | mempool_free(line->invalid_bitmap, l_mg->bitmap_pool); |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1351 | |
| 1352 | pblk_line_reinit(line); |
| 1353 | } |
| 1354 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1355 | struct pblk_line *pblk_line_get(struct pblk *pblk) |
| 1356 | { |
| 1357 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1358 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1359 | struct pblk_line *line; |
| 1360 | int ret, bit; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1361 | |
| 1362 | lockdep_assert_held(&l_mg->free_lock); |
| 1363 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1364 | retry: |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1365 | if (list_empty(&l_mg->free_list)) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1366 | pblk_err(pblk, "no free lines\n"); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1367 | return NULL; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | line = list_first_entry(&l_mg->free_list, struct pblk_line, list); |
| 1371 | list_del(&line->list); |
| 1372 | l_mg->nr_free_lines--; |
| 1373 | |
| 1374 | bit = find_first_zero_bit(line->blk_bitmap, lm->blk_per_line); |
| 1375 | if (unlikely(bit >= lm->blk_per_line)) { |
| 1376 | spin_lock(&line->lock); |
| 1377 | line->state = PBLK_LINESTATE_BAD; |
Hans Holmberg | f293723 | 2018-10-09 13:11:53 +0200 | [diff] [blame] | 1378 | trace_pblk_line_state(pblk_disk_name(pblk), line->id, |
| 1379 | line->state); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1380 | spin_unlock(&line->lock); |
| 1381 | |
| 1382 | list_add_tail(&line->list, &l_mg->bad_list); |
| 1383 | |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1384 | pblk_debug(pblk, "line %d is bad\n", line->id); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1385 | goto retry; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1386 | } |
| 1387 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1388 | ret = pblk_line_prepare(pblk, line); |
| 1389 | if (ret) { |
Javier González | 1d8b33e | 2018-06-01 15:04:16 +0200 | [diff] [blame] | 1390 | switch (ret) { |
| 1391 | case -EAGAIN: |
| 1392 | list_add(&line->list, &l_mg->bad_list); |
| 1393 | goto retry; |
| 1394 | case -EINTR: |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1395 | list_add(&line->list, &l_mg->corrupt_list); |
| 1396 | goto retry; |
Javier González | 1d8b33e | 2018-06-01 15:04:16 +0200 | [diff] [blame] | 1397 | default: |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1398 | pblk_err(pblk, "failed to prepare line %d\n", line->id); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1399 | list_add(&line->list, &l_mg->free_list); |
| 1400 | l_mg->nr_free_lines++; |
| 1401 | return NULL; |
| 1402 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1403 | } |
| 1404 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1405 | return line; |
| 1406 | } |
| 1407 | |
| 1408 | static struct pblk_line *pblk_line_retry(struct pblk *pblk, |
| 1409 | struct pblk_line *line) |
| 1410 | { |
| 1411 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1412 | struct pblk_line *retry_line; |
| 1413 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1414 | retry: |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1415 | spin_lock(&l_mg->free_lock); |
| 1416 | retry_line = pblk_line_get(pblk); |
| 1417 | if (!retry_line) { |
Javier González | be388d9 | 2017-04-22 01:32:48 +0200 | [diff] [blame] | 1418 | l_mg->data_line = NULL; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1419 | spin_unlock(&l_mg->free_lock); |
| 1420 | return NULL; |
| 1421 | } |
| 1422 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1423 | retry_line->map_bitmap = line->map_bitmap; |
| 1424 | retry_line->invalid_bitmap = line->invalid_bitmap; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1425 | retry_line->smeta = line->smeta; |
| 1426 | retry_line->emeta = line->emeta; |
| 1427 | retry_line->meta_line = line->meta_line; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1428 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1429 | pblk_line_reinit(line); |
| 1430 | |
Javier González | 3dc001f | 2017-04-22 01:32:45 +0200 | [diff] [blame] | 1431 | l_mg->data_line = retry_line; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1432 | spin_unlock(&l_mg->free_lock); |
| 1433 | |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 1434 | pblk_rl_free_lines_dec(&pblk->rl, line, false); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1435 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1436 | if (pblk_line_erase(pblk, retry_line)) |
| 1437 | goto retry; |
| 1438 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1439 | return retry_line; |
| 1440 | } |
| 1441 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1442 | static void pblk_set_space_limit(struct pblk *pblk) |
| 1443 | { |
| 1444 | struct pblk_rl *rl = &pblk->rl; |
| 1445 | |
| 1446 | atomic_set(&rl->rb_space, 0); |
| 1447 | } |
| 1448 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1449 | struct pblk_line *pblk_line_get_first_data(struct pblk *pblk) |
| 1450 | { |
| 1451 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1452 | struct pblk_line *line; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1453 | |
| 1454 | spin_lock(&l_mg->free_lock); |
| 1455 | line = pblk_line_get(pblk); |
| 1456 | if (!line) { |
| 1457 | spin_unlock(&l_mg->free_lock); |
| 1458 | return NULL; |
| 1459 | } |
| 1460 | |
| 1461 | line->seq_nr = l_mg->d_seq_nr++; |
| 1462 | line->type = PBLK_LINETYPE_DATA; |
| 1463 | l_mg->data_line = line; |
| 1464 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1465 | pblk_line_setup_metadata(line, l_mg, &pblk->lm); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1466 | |
| 1467 | /* Allocate next line for preparation */ |
| 1468 | l_mg->data_next = pblk_line_get(pblk); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1469 | if (!l_mg->data_next) { |
| 1470 | /* If we cannot get a new line, we need to stop the pipeline. |
| 1471 | * Only allow as many writes in as we can store safely and then |
| 1472 | * fail gracefully |
| 1473 | */ |
| 1474 | pblk_set_space_limit(pblk); |
| 1475 | |
| 1476 | l_mg->data_next = NULL; |
| 1477 | } else { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1478 | l_mg->data_next->seq_nr = l_mg->d_seq_nr++; |
| 1479 | l_mg->data_next->type = PBLK_LINETYPE_DATA; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1480 | } |
| 1481 | spin_unlock(&l_mg->free_lock); |
| 1482 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1483 | if (pblk_line_alloc_bitmaps(pblk, line)) |
| 1484 | return NULL; |
| 1485 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1486 | if (pblk_line_erase(pblk, line)) { |
| 1487 | line = pblk_line_retry(pblk, line); |
| 1488 | if (!line) |
| 1489 | return NULL; |
| 1490 | } |
| 1491 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1492 | retry_setup: |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1493 | if (!pblk_line_init_metadata(pblk, line, NULL)) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1494 | line = pblk_line_retry(pblk, line); |
| 1495 | if (!line) |
| 1496 | return NULL; |
| 1497 | |
| 1498 | goto retry_setup; |
| 1499 | } |
| 1500 | |
| 1501 | if (!pblk_line_init_bb(pblk, line, 1)) { |
| 1502 | line = pblk_line_retry(pblk, line); |
| 1503 | if (!line) |
| 1504 | return NULL; |
| 1505 | |
| 1506 | goto retry_setup; |
| 1507 | } |
| 1508 | |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 1509 | pblk_rl_free_lines_dec(&pblk->rl, line, true); |
| 1510 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1511 | return line; |
| 1512 | } |
| 1513 | |
Matias Bjørling | ae14cc0 | 2018-10-09 13:11:40 +0200 | [diff] [blame] | 1514 | void pblk_ppa_to_line_put(struct pblk *pblk, struct ppa_addr ppa) |
| 1515 | { |
| 1516 | struct pblk_line *line; |
| 1517 | |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 1518 | line = pblk_ppa_to_line(pblk, ppa); |
Matias Bjørling | ae14cc0 | 2018-10-09 13:11:40 +0200 | [diff] [blame] | 1519 | kref_put(&line->ref, pblk_line_put_wq); |
| 1520 | } |
| 1521 | |
| 1522 | void pblk_rq_to_line_put(struct pblk *pblk, struct nvm_rq *rqd) |
| 1523 | { |
| 1524 | struct ppa_addr *ppa_list; |
| 1525 | int i; |
| 1526 | |
| 1527 | ppa_list = (rqd->nr_ppas > 1) ? rqd->ppa_list : &rqd->ppa_addr; |
| 1528 | |
| 1529 | for (i = 0; i < rqd->nr_ppas; i++) |
| 1530 | pblk_ppa_to_line_put(pblk, ppa_list[i]); |
| 1531 | } |
| 1532 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1533 | static void pblk_stop_writes(struct pblk *pblk, struct pblk_line *line) |
| 1534 | { |
| 1535 | lockdep_assert_held(&pblk->l_mg.free_lock); |
| 1536 | |
| 1537 | pblk_set_space_limit(pblk); |
| 1538 | pblk->state = PBLK_STATE_STOPPING; |
Hans Holmberg | 1b0dd0b | 2018-10-09 13:11:54 +0200 | [diff] [blame] | 1539 | trace_pblk_state(pblk_disk_name(pblk), pblk->state); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1540 | } |
| 1541 | |
Javier González | 8bd4002 | 2017-10-13 14:46:44 +0200 | [diff] [blame] | 1542 | static void pblk_line_close_meta_sync(struct pblk *pblk) |
| 1543 | { |
| 1544 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1545 | struct pblk_line_meta *lm = &pblk->lm; |
| 1546 | struct pblk_line *line, *tline; |
| 1547 | LIST_HEAD(list); |
| 1548 | |
| 1549 | spin_lock(&l_mg->close_lock); |
| 1550 | if (list_empty(&l_mg->emeta_list)) { |
| 1551 | spin_unlock(&l_mg->close_lock); |
| 1552 | return; |
| 1553 | } |
| 1554 | |
| 1555 | list_cut_position(&list, &l_mg->emeta_list, l_mg->emeta_list.prev); |
| 1556 | spin_unlock(&l_mg->close_lock); |
| 1557 | |
| 1558 | list_for_each_entry_safe(line, tline, &list, list) { |
| 1559 | struct pblk_emeta *emeta = line->emeta; |
| 1560 | |
| 1561 | while (emeta->mem < lm->emeta_len[0]) { |
| 1562 | int ret; |
| 1563 | |
| 1564 | ret = pblk_submit_meta_io(pblk, line); |
| 1565 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1566 | pblk_err(pblk, "sync meta line %d failed (%d)\n", |
Javier González | 8bd4002 | 2017-10-13 14:46:44 +0200 | [diff] [blame] | 1567 | line->id, ret); |
| 1568 | return; |
| 1569 | } |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | pblk_wait_for_meta(pblk); |
| 1574 | flush_workqueue(pblk->close_wq); |
| 1575 | } |
| 1576 | |
Javier González | a7c9e91 | 2018-06-01 15:04:24 +0200 | [diff] [blame] | 1577 | void __pblk_pipeline_flush(struct pblk *pblk) |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1578 | { |
| 1579 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1580 | int ret; |
| 1581 | |
| 1582 | spin_lock(&l_mg->free_lock); |
| 1583 | if (pblk->state == PBLK_STATE_RECOVERING || |
| 1584 | pblk->state == PBLK_STATE_STOPPED) { |
| 1585 | spin_unlock(&l_mg->free_lock); |
| 1586 | return; |
| 1587 | } |
| 1588 | pblk->state = PBLK_STATE_RECOVERING; |
Hans Holmberg | 1b0dd0b | 2018-10-09 13:11:54 +0200 | [diff] [blame] | 1589 | trace_pblk_state(pblk_disk_name(pblk), pblk->state); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1590 | spin_unlock(&l_mg->free_lock); |
| 1591 | |
| 1592 | pblk_flush_writer(pblk); |
| 1593 | pblk_wait_for_meta(pblk); |
| 1594 | |
| 1595 | ret = pblk_recov_pad(pblk); |
| 1596 | if (ret) { |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1597 | pblk_err(pblk, "could not close data on teardown(%d)\n", ret); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1598 | return; |
| 1599 | } |
| 1600 | |
Javier González | ee8d5c1 | 2017-06-30 17:56:40 +0200 | [diff] [blame] | 1601 | flush_workqueue(pblk->bb_wq); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1602 | pblk_line_close_meta_sync(pblk); |
Javier González | a7c9e91 | 2018-06-01 15:04:24 +0200 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | void __pblk_pipeline_stop(struct pblk *pblk) |
| 1606 | { |
| 1607 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1608 | |
| 1609 | spin_lock(&l_mg->free_lock); |
| 1610 | pblk->state = PBLK_STATE_STOPPED; |
Hans Holmberg | 1b0dd0b | 2018-10-09 13:11:54 +0200 | [diff] [blame] | 1611 | trace_pblk_state(pblk_disk_name(pblk), pblk->state); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1612 | l_mg->data_line = NULL; |
| 1613 | l_mg->data_next = NULL; |
| 1614 | spin_unlock(&l_mg->free_lock); |
| 1615 | } |
| 1616 | |
Javier González | a7c9e91 | 2018-06-01 15:04:24 +0200 | [diff] [blame] | 1617 | void pblk_pipeline_stop(struct pblk *pblk) |
| 1618 | { |
| 1619 | __pblk_pipeline_flush(pblk); |
| 1620 | __pblk_pipeline_stop(pblk); |
| 1621 | } |
| 1622 | |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 1623 | struct pblk_line *pblk_line_replace_data(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1624 | { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1625 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 1626 | struct pblk_line *cur, *new = NULL; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1627 | unsigned int left_seblks; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1628 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1629 | new = l_mg->data_next; |
| 1630 | if (!new) |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 1631 | goto out; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1632 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1633 | spin_lock(&l_mg->free_lock); |
Javier González | 44cdbdc | 2018-10-09 13:12:07 +0200 | [diff] [blame] | 1634 | cur = l_mg->data_line; |
| 1635 | l_mg->data_line = new; |
| 1636 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1637 | pblk_line_setup_metadata(new, l_mg, &pblk->lm); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1638 | spin_unlock(&l_mg->free_lock); |
| 1639 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1640 | retry_erase: |
| 1641 | left_seblks = atomic_read(&new->left_seblks); |
| 1642 | if (left_seblks) { |
| 1643 | /* If line is not fully erased, erase it */ |
| 1644 | if (atomic_read(&new->left_eblks)) { |
| 1645 | if (pblk_line_erase(pblk, new)) |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 1646 | goto out; |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1647 | } else { |
| 1648 | io_schedule(); |
| 1649 | } |
| 1650 | goto retry_erase; |
| 1651 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1652 | |
Javier González | 9cfd5a9 | 2018-06-01 16:41:14 +0200 | [diff] [blame] | 1653 | if (pblk_line_alloc_bitmaps(pblk, new)) |
| 1654 | return NULL; |
| 1655 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1656 | retry_setup: |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1657 | if (!pblk_line_init_metadata(pblk, new, cur)) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1658 | new = pblk_line_retry(pblk, new); |
Javier González | f3236cef | 2017-04-22 01:32:46 +0200 | [diff] [blame] | 1659 | if (!new) |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 1660 | goto out; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1661 | |
| 1662 | goto retry_setup; |
| 1663 | } |
| 1664 | |
| 1665 | if (!pblk_line_init_bb(pblk, new, 1)) { |
| 1666 | new = pblk_line_retry(pblk, new); |
| 1667 | if (!new) |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 1668 | goto out; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1669 | |
| 1670 | goto retry_setup; |
| 1671 | } |
| 1672 | |
Javier González | a768993 | 2018-01-05 14:16:13 +0100 | [diff] [blame] | 1673 | pblk_rl_free_lines_dec(&pblk->rl, new, true); |
| 1674 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1675 | /* Allocate next line for preparation */ |
| 1676 | spin_lock(&l_mg->free_lock); |
| 1677 | l_mg->data_next = pblk_line_get(pblk); |
| 1678 | if (!l_mg->data_next) { |
| 1679 | /* If we cannot get a new line, we need to stop the pipeline. |
| 1680 | * Only allow as many writes in as we can store safely and then |
| 1681 | * fail gracefully |
| 1682 | */ |
| 1683 | pblk_stop_writes(pblk, new); |
| 1684 | l_mg->data_next = NULL; |
| 1685 | } else { |
| 1686 | l_mg->data_next->seq_nr = l_mg->d_seq_nr++; |
| 1687 | l_mg->data_next->type = PBLK_LINETYPE_DATA; |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1688 | } |
| 1689 | spin_unlock(&l_mg->free_lock); |
| 1690 | |
Javier González | 21d2287 | 2017-10-13 14:46:26 +0200 | [diff] [blame] | 1691 | out: |
| 1692 | return new; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1693 | } |
| 1694 | |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 1695 | static void __pblk_line_put(struct pblk *pblk, struct pblk_line *line) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1696 | { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1697 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
Hans Holmberg | d6b992f | 2017-10-13 14:46:41 +0200 | [diff] [blame] | 1698 | struct pblk_gc *gc = &pblk->gc; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1699 | |
| 1700 | spin_lock(&line->lock); |
| 1701 | WARN_ON(line->state != PBLK_LINESTATE_GC); |
| 1702 | line->state = PBLK_LINESTATE_FREE; |
Hans Holmberg | f293723 | 2018-10-09 13:11:53 +0200 | [diff] [blame] | 1703 | trace_pblk_line_state(pblk_disk_name(pblk), line->id, |
| 1704 | line->state); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1705 | line->gc_group = PBLK_LINEGC_NONE; |
Javier González | 8e55c07 | 2018-06-01 15:04:22 +0200 | [diff] [blame] | 1706 | pblk_line_free(line); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1707 | |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 1708 | if (line->w_err_gc->has_write_err) { |
| 1709 | pblk_rl_werr_line_out(&pblk->rl); |
| 1710 | line->w_err_gc->has_write_err = 0; |
| 1711 | } |
| 1712 | |
| 1713 | spin_unlock(&line->lock); |
Hans Holmberg | d6b992f | 2017-10-13 14:46:41 +0200 | [diff] [blame] | 1714 | atomic_dec(&gc->pipeline_gc); |
| 1715 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1716 | spin_lock(&l_mg->free_lock); |
| 1717 | list_add_tail(&line->list, &l_mg->free_list); |
| 1718 | l_mg->nr_free_lines++; |
| 1719 | spin_unlock(&l_mg->free_lock); |
| 1720 | |
| 1721 | pblk_rl_free_lines_inc(&pblk->rl, line); |
| 1722 | } |
| 1723 | |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 1724 | static void pblk_line_put_ws(struct work_struct *work) |
| 1725 | { |
| 1726 | struct pblk_line_ws *line_put_ws = container_of(work, |
| 1727 | struct pblk_line_ws, ws); |
| 1728 | struct pblk *pblk = line_put_ws->pblk; |
| 1729 | struct pblk_line *line = line_put_ws->line; |
| 1730 | |
| 1731 | __pblk_line_put(pblk, line); |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 1732 | mempool_free(line_put_ws, &pblk->gen_ws_pool); |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | void pblk_line_put(struct kref *ref) |
| 1736 | { |
| 1737 | struct pblk_line *line = container_of(ref, struct pblk_line, ref); |
| 1738 | struct pblk *pblk = line->pblk; |
| 1739 | |
| 1740 | __pblk_line_put(pblk, line); |
| 1741 | } |
| 1742 | |
| 1743 | void pblk_line_put_wq(struct kref *ref) |
| 1744 | { |
| 1745 | struct pblk_line *line = container_of(ref, struct pblk_line, ref); |
| 1746 | struct pblk *pblk = line->pblk; |
| 1747 | struct pblk_line_ws *line_put_ws; |
| 1748 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 1749 | line_put_ws = mempool_alloc(&pblk->gen_ws_pool, GFP_ATOMIC); |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 1750 | if (!line_put_ws) |
| 1751 | return; |
| 1752 | |
| 1753 | line_put_ws->pblk = pblk; |
| 1754 | line_put_ws->line = line; |
| 1755 | line_put_ws->priv = NULL; |
| 1756 | |
| 1757 | INIT_WORK(&line_put_ws->ws, pblk_line_put_ws); |
| 1758 | queue_work(pblk->r_end_wq, &line_put_ws->ws); |
| 1759 | } |
| 1760 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1761 | int pblk_blk_erase_async(struct pblk *pblk, struct ppa_addr ppa) |
| 1762 | { |
| 1763 | struct nvm_rq *rqd; |
| 1764 | int err; |
| 1765 | |
Javier González | 67bf26a | 2017-10-13 14:46:20 +0200 | [diff] [blame] | 1766 | rqd = pblk_alloc_rqd(pblk, PBLK_ERASE); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1767 | |
| 1768 | pblk_setup_e_rq(pblk, rqd, ppa); |
| 1769 | |
| 1770 | rqd->end_io = pblk_end_io_erase; |
| 1771 | rqd->private = pblk; |
| 1772 | |
Hans Holmberg | 4209c31 | 2018-10-09 13:11:55 +0200 | [diff] [blame] | 1773 | trace_pblk_chunk_reset(pblk_disk_name(pblk), |
| 1774 | &ppa, PBLK_CHUNK_RESET_START); |
| 1775 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1776 | /* The write thread schedules erases so that it minimizes disturbances |
| 1777 | * with writes. Thus, there is no need to take the LUN semaphore. |
| 1778 | */ |
| 1779 | err = pblk_submit_io(pblk, rqd); |
| 1780 | if (err) { |
| 1781 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1782 | struct nvm_geo *geo = &dev->geo; |
| 1783 | |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1784 | pblk_err(pblk, "could not async erase line:%d,blk:%d\n", |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 1785 | pblk_ppa_to_line_id(ppa), |
Javier González | b1bcfda | 2018-01-05 14:16:06 +0100 | [diff] [blame] | 1786 | pblk_ppa_to_pos(geo, ppa)); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | return err; |
| 1790 | } |
| 1791 | |
| 1792 | struct pblk_line *pblk_line_get_data(struct pblk *pblk) |
| 1793 | { |
| 1794 | return pblk->l_mg.data_line; |
| 1795 | } |
| 1796 | |
Javier González | d624f37 | 2017-06-26 11:57:15 +0200 | [diff] [blame] | 1797 | /* For now, always erase next line */ |
| 1798 | struct pblk_line *pblk_line_get_erase(struct pblk *pblk) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1799 | { |
| 1800 | return pblk->l_mg.data_next; |
| 1801 | } |
| 1802 | |
| 1803 | int pblk_line_is_full(struct pblk_line *line) |
| 1804 | { |
| 1805 | return (line->left_msecs == 0); |
| 1806 | } |
| 1807 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1808 | static void pblk_line_should_sync_meta(struct pblk *pblk) |
| 1809 | { |
| 1810 | if (pblk_rl_is_limit(&pblk->rl)) |
| 1811 | pblk_line_close_meta_sync(pblk); |
| 1812 | } |
| 1813 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1814 | void pblk_line_close(struct pblk *pblk, struct pblk_line *line) |
| 1815 | { |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1816 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1817 | struct nvm_geo *geo = &dev->geo; |
| 1818 | struct pblk_line_meta *lm = &pblk->lm; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1819 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1820 | struct list_head *move_list; |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1821 | int i; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1822 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 1823 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1824 | WARN(!bitmap_full(line->map_bitmap, lm->sec_per_line), |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1825 | "pblk: corrupt closed line %d\n", line->id); |
Javier González | a84ebb8 | 2017-06-30 17:56:43 +0200 | [diff] [blame] | 1826 | #endif |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1827 | |
| 1828 | spin_lock(&l_mg->free_lock); |
| 1829 | WARN_ON(!test_and_clear_bit(line->meta_line, &l_mg->meta_bitmap)); |
| 1830 | spin_unlock(&l_mg->free_lock); |
| 1831 | |
| 1832 | spin_lock(&l_mg->gc_lock); |
| 1833 | spin_lock(&line->lock); |
| 1834 | WARN_ON(line->state != PBLK_LINESTATE_OPEN); |
| 1835 | line->state = PBLK_LINESTATE_CLOSED; |
| 1836 | move_list = pblk_line_gc_list(pblk, line); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1837 | list_add_tail(&line->list, move_list); |
| 1838 | |
Hans Holmberg | 53d82db | 2018-10-09 13:11:47 +0200 | [diff] [blame] | 1839 | mempool_free(line->map_bitmap, l_mg->bitmap_pool); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1840 | line->map_bitmap = NULL; |
| 1841 | line->smeta = NULL; |
| 1842 | line->emeta = NULL; |
| 1843 | |
Javier González | 32ef941 | 2018-03-30 00:05:20 +0200 | [diff] [blame] | 1844 | for (i = 0; i < lm->blk_per_line; i++) { |
| 1845 | struct pblk_lun *rlun = &pblk->luns[i]; |
| 1846 | int pos = pblk_ppa_to_pos(geo, rlun->bppa); |
| 1847 | int state = line->chks[pos].state; |
| 1848 | |
| 1849 | if (!(state & NVM_CHK_ST_OFFLINE)) |
| 1850 | state = NVM_CHK_ST_CLOSED; |
| 1851 | } |
| 1852 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1853 | spin_unlock(&line->lock); |
| 1854 | spin_unlock(&l_mg->gc_lock); |
Hans Holmberg | f293723 | 2018-10-09 13:11:53 +0200 | [diff] [blame] | 1855 | |
| 1856 | trace_pblk_line_state(pblk_disk_name(pblk), line->id, |
| 1857 | line->state); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1858 | } |
| 1859 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1860 | void pblk_line_close_meta(struct pblk *pblk, struct pblk_line *line) |
| 1861 | { |
| 1862 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1863 | struct pblk_line_meta *lm = &pblk->lm; |
| 1864 | struct pblk_emeta *emeta = line->emeta; |
| 1865 | struct line_emeta *emeta_buf = emeta->buf; |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 1866 | struct wa_counters *wa = emeta_to_wa(lm, emeta_buf); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1867 | |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1868 | /* No need for exact vsc value; avoid a big line lock and take aprox. */ |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1869 | memcpy(emeta_to_vsc(pblk, emeta_buf), l_mg->vsc_list, lm->vsc_list_len); |
| 1870 | memcpy(emeta_to_bb(emeta_buf), line->blk_bitmap, lm->blk_bitmap_len); |
| 1871 | |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 1872 | wa->user = cpu_to_le64(atomic64_read(&pblk->user_wa)); |
| 1873 | wa->pad = cpu_to_le64(atomic64_read(&pblk->pad_wa)); |
| 1874 | wa->gc = cpu_to_le64(atomic64_read(&pblk->gc_wa)); |
| 1875 | |
Javier González | 9cc85bc | 2018-10-09 13:11:45 +0200 | [diff] [blame] | 1876 | if (le32_to_cpu(emeta_buf->header.identifier) != PBLK_MAGIC) { |
| 1877 | emeta_buf->header.identifier = cpu_to_le32(PBLK_MAGIC); |
Andy Shevchenko | 7e0a084 | 2019-02-11 13:25:05 +0100 | [diff] [blame] | 1878 | guid_copy((guid_t *)&emeta_buf->header.uuid, |
| 1879 | &pblk->instance_uuid); |
Javier González | 9cc85bc | 2018-10-09 13:11:45 +0200 | [diff] [blame] | 1880 | emeta_buf->header.id = cpu_to_le32(line->id); |
| 1881 | emeta_buf->header.type = cpu_to_le16(line->type); |
| 1882 | emeta_buf->header.version_major = EMETA_VERSION_MAJOR; |
| 1883 | emeta_buf->header.version_minor = EMETA_VERSION_MINOR; |
| 1884 | emeta_buf->header.crc = cpu_to_le32( |
| 1885 | pblk_calc_meta_header_crc(pblk, &emeta_buf->header)); |
| 1886 | } |
| 1887 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1888 | emeta_buf->nr_valid_lbas = cpu_to_le64(line->nr_valid_lbas); |
| 1889 | emeta_buf->crc = cpu_to_le32(pblk_calc_emeta_crc(pblk, emeta_buf)); |
| 1890 | |
| 1891 | spin_lock(&l_mg->close_lock); |
| 1892 | spin_lock(&line->lock); |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 1893 | |
| 1894 | /* Update the in-memory start address for emeta, in case it has |
| 1895 | * shifted due to write errors |
| 1896 | */ |
| 1897 | if (line->emeta_ssec != line->cur_sec) |
| 1898 | line->emeta_ssec = line->cur_sec; |
| 1899 | |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1900 | list_add_tail(&line->list, &l_mg->emeta_list); |
| 1901 | spin_unlock(&line->lock); |
| 1902 | spin_unlock(&l_mg->close_lock); |
Javier González | 588726d3 | 2017-06-26 11:57:29 +0200 | [diff] [blame] | 1903 | |
| 1904 | pblk_line_should_sync_meta(pblk); |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | static void pblk_save_lba_list(struct pblk *pblk, struct pblk_line *line) |
| 1908 | { |
| 1909 | struct pblk_line_meta *lm = &pblk->lm; |
| 1910 | struct pblk_line_mgmt *l_mg = &pblk->l_mg; |
| 1911 | unsigned int lba_list_size = lm->emeta_len[2]; |
| 1912 | struct pblk_w_err_gc *w_err_gc = line->w_err_gc; |
| 1913 | struct pblk_emeta *emeta = line->emeta; |
| 1914 | |
| 1915 | w_err_gc->lba_list = pblk_malloc(lba_list_size, |
| 1916 | l_mg->emeta_alloc_type, GFP_KERNEL); |
| 1917 | memcpy(w_err_gc->lba_list, emeta_to_lbas(pblk, emeta->buf), |
| 1918 | lba_list_size); |
Javier González | dd2a434 | 2017-06-26 11:57:17 +0200 | [diff] [blame] | 1919 | } |
| 1920 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1921 | void pblk_line_close_ws(struct work_struct *work) |
| 1922 | { |
| 1923 | struct pblk_line_ws *line_ws = container_of(work, struct pblk_line_ws, |
| 1924 | ws); |
| 1925 | struct pblk *pblk = line_ws->pblk; |
| 1926 | struct pblk_line *line = line_ws->line; |
Hans Holmberg | 48b8d20 | 2018-06-01 16:41:06 +0200 | [diff] [blame] | 1927 | struct pblk_w_err_gc *w_err_gc = line->w_err_gc; |
| 1928 | |
| 1929 | /* Write errors makes the emeta start address stored in smeta invalid, |
| 1930 | * so keep a copy of the lba list until we've gc'd the line |
| 1931 | */ |
| 1932 | if (w_err_gc->has_write_err) |
| 1933 | pblk_save_lba_list(pblk, line); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1934 | |
| 1935 | pblk_line_close(pblk, line); |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 1936 | mempool_free(line_ws, &pblk->gen_ws_pool); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1937 | } |
| 1938 | |
Javier González | b84ae4a8 | 2017-10-13 14:46:07 +0200 | [diff] [blame] | 1939 | void pblk_gen_run_ws(struct pblk *pblk, struct pblk_line *line, void *priv, |
| 1940 | void (*work)(struct work_struct *), gfp_t gfp_mask, |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 1941 | struct workqueue_struct *wq) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1942 | { |
| 1943 | struct pblk_line_ws *line_ws; |
| 1944 | |
Kent Overstreet | b906bbb | 2018-05-20 18:25:50 -0400 | [diff] [blame] | 1945 | line_ws = mempool_alloc(&pblk->gen_ws_pool, gfp_mask); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1946 | |
| 1947 | line_ws->pblk = pblk; |
| 1948 | line_ws->line = line; |
| 1949 | line_ws->priv = priv; |
| 1950 | |
| 1951 | INIT_WORK(&line_ws->ws, work); |
Javier González | ef57649 | 2017-06-26 11:57:28 +0200 | [diff] [blame] | 1952 | queue_work(wq, &line_ws->ws); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1953 | } |
| 1954 | |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 1955 | static void __pblk_down_chunk(struct pblk *pblk, int pos) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1956 | { |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1957 | struct pblk_lun *rlun = &pblk->luns[pos]; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1958 | int ret; |
| 1959 | |
| 1960 | /* |
| 1961 | * Only send one inflight I/O per LUN. Since we map at a page |
| 1962 | * granurality, all ppas in the I/O will map to the same LUN |
| 1963 | */ |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1964 | |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1965 | ret = down_timeout(&rlun->wr_sem, msecs_to_jiffies(30000)); |
Rakesh Pandit | c549384 | 2017-10-13 14:45:58 +0200 | [diff] [blame] | 1966 | if (ret == -ETIME || ret == -EINTR) |
Matias Bjørling | 4e495a4 | 2018-07-13 10:48:42 +0200 | [diff] [blame] | 1967 | pblk_err(pblk, "taking lun semaphore timed out: err %d\n", |
| 1968 | -ret); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 1969 | } |
| 1970 | |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 1971 | void pblk_down_chunk(struct pblk *pblk, struct ppa_addr ppa) |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1972 | { |
| 1973 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1974 | struct nvm_geo *geo = &dev->geo; |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 1975 | int pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1976 | |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 1977 | __pblk_down_chunk(pblk, pos); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1978 | } |
| 1979 | |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 1980 | void pblk_down_rq(struct pblk *pblk, struct ppa_addr ppa, |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1981 | unsigned long *lun_bitmap) |
| 1982 | { |
| 1983 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1984 | struct nvm_geo *geo = &dev->geo; |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 1985 | int pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1986 | |
| 1987 | /* If the LUN has been locked for this same request, do no attempt to |
| 1988 | * lock it again |
| 1989 | */ |
| 1990 | if (test_and_set_bit(pos, lun_bitmap)) |
| 1991 | return; |
| 1992 | |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 1993 | __pblk_down_chunk(pblk, pos); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1994 | } |
| 1995 | |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 1996 | void pblk_up_chunk(struct pblk *pblk, struct ppa_addr ppa) |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 1997 | { |
| 1998 | struct nvm_tgt_dev *dev = pblk->dev; |
| 1999 | struct nvm_geo *geo = &dev->geo; |
| 2000 | struct pblk_lun *rlun; |
Matias Bjørling | 43241cf | 2018-10-09 13:11:51 +0200 | [diff] [blame] | 2001 | int pos = pblk_ppa_to_pos(geo, ppa); |
Javier González | 3eaa11e | 2017-07-07 21:08:52 +0200 | [diff] [blame] | 2002 | |
| 2003 | rlun = &pblk->luns[pos]; |
| 2004 | up(&rlun->wr_sem); |
| 2005 | } |
| 2006 | |
Hans Holmberg | e99e802 | 2018-10-09 13:11:48 +0200 | [diff] [blame] | 2007 | void pblk_up_rq(struct pblk *pblk, unsigned long *lun_bitmap) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2008 | { |
| 2009 | struct nvm_tgt_dev *dev = pblk->dev; |
| 2010 | struct nvm_geo *geo = &dev->geo; |
| 2011 | struct pblk_lun *rlun; |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 2012 | int num_lun = geo->all_luns; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2013 | int bit = -1; |
| 2014 | |
Javier González | a40afad | 2018-03-30 00:05:14 +0200 | [diff] [blame] | 2015 | while ((bit = find_next_bit(lun_bitmap, num_lun, bit + 1)) < num_lun) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2016 | rlun = &pblk->luns[bit]; |
| 2017 | up(&rlun->wr_sem); |
| 2018 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | void pblk_update_map(struct pblk *pblk, sector_t lba, struct ppa_addr ppa) |
| 2022 | { |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2023 | struct ppa_addr ppa_l2p; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2024 | |
| 2025 | /* logic error: lba out-of-bounds. Ignore update */ |
| 2026 | if (!(lba < pblk->rl.nr_secs)) { |
| 2027 | WARN(1, "pblk: corrupted L2P map request\n"); |
| 2028 | return; |
| 2029 | } |
| 2030 | |
| 2031 | spin_lock(&pblk->trans_lock); |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2032 | ppa_l2p = pblk_trans_map_get(pblk, lba); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2033 | |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2034 | if (!pblk_addr_in_cache(ppa_l2p) && !pblk_ppa_empty(ppa_l2p)) |
| 2035 | pblk_map_invalidate(pblk, ppa_l2p); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2036 | |
| 2037 | pblk_trans_map_set(pblk, lba, ppa); |
| 2038 | spin_unlock(&pblk->trans_lock); |
| 2039 | } |
| 2040 | |
| 2041 | void pblk_update_map_cache(struct pblk *pblk, sector_t lba, struct ppa_addr ppa) |
| 2042 | { |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 2043 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 2044 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2045 | /* Callers must ensure that the ppa points to a cache address */ |
| 2046 | BUG_ON(!pblk_addr_in_cache(ppa)); |
| 2047 | BUG_ON(pblk_rb_pos_oob(&pblk->rwb, pblk_addr_to_cacheline(ppa))); |
| 2048 | #endif |
| 2049 | |
| 2050 | pblk_update_map(pblk, lba, ppa); |
| 2051 | } |
| 2052 | |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2053 | int pblk_update_map_gc(struct pblk *pblk, sector_t lba, struct ppa_addr ppa_new, |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 2054 | struct pblk_line *gc_line, u64 paddr_gc) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2055 | { |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 2056 | struct ppa_addr ppa_l2p, ppa_gc; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2057 | int ret = 1; |
| 2058 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 2059 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2060 | /* Callers must ensure that the ppa points to a cache address */ |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2061 | BUG_ON(!pblk_addr_in_cache(ppa_new)); |
| 2062 | BUG_ON(pblk_rb_pos_oob(&pblk->rwb, pblk_addr_to_cacheline(ppa_new))); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2063 | #endif |
| 2064 | |
| 2065 | /* logic error: lba out-of-bounds. Ignore update */ |
| 2066 | if (!(lba < pblk->rl.nr_secs)) { |
| 2067 | WARN(1, "pblk: corrupted L2P map request\n"); |
| 2068 | return 0; |
| 2069 | } |
| 2070 | |
| 2071 | spin_lock(&pblk->trans_lock); |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2072 | ppa_l2p = pblk_trans_map_get(pblk, lba); |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 2073 | ppa_gc = addr_to_gen_ppa(pblk, paddr_gc, gc_line->id); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2074 | |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 2075 | if (!pblk_ppa_comp(ppa_l2p, ppa_gc)) { |
| 2076 | spin_lock(&gc_line->lock); |
| 2077 | WARN(!test_bit(paddr_gc, gc_line->invalid_bitmap), |
| 2078 | "pblk: corrupted GC update"); |
| 2079 | spin_unlock(&gc_line->lock); |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2080 | |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2081 | ret = 0; |
| 2082 | goto out; |
| 2083 | } |
| 2084 | |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2085 | pblk_trans_map_set(pblk, lba, ppa_new); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2086 | out: |
| 2087 | spin_unlock(&pblk->trans_lock); |
| 2088 | return ret; |
| 2089 | } |
| 2090 | |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2091 | void pblk_update_map_dev(struct pblk *pblk, sector_t lba, |
| 2092 | struct ppa_addr ppa_mapped, struct ppa_addr ppa_cache) |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2093 | { |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2094 | struct ppa_addr ppa_l2p; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2095 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 2096 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2097 | /* Callers must ensure that the ppa points to a device address */ |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2098 | BUG_ON(pblk_addr_in_cache(ppa_mapped)); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2099 | #endif |
| 2100 | /* Invalidate and discard padded entries */ |
| 2101 | if (lba == ADDR_EMPTY) { |
Hans Holmberg | 7675839 | 2018-03-30 00:04:52 +0200 | [diff] [blame] | 2102 | atomic64_inc(&pblk->pad_wa); |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 2103 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2104 | atomic_long_inc(&pblk->padded_wb); |
| 2105 | #endif |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2106 | if (!pblk_ppa_empty(ppa_mapped)) |
| 2107 | pblk_map_invalidate(pblk, ppa_mapped); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2108 | return; |
| 2109 | } |
| 2110 | |
| 2111 | /* logic error: lba out-of-bounds. Ignore update */ |
| 2112 | if (!(lba < pblk->rl.nr_secs)) { |
| 2113 | WARN(1, "pblk: corrupted L2P map request\n"); |
| 2114 | return; |
| 2115 | } |
| 2116 | |
| 2117 | spin_lock(&pblk->trans_lock); |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2118 | ppa_l2p = pblk_trans_map_get(pblk, lba); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2119 | |
| 2120 | /* Do not update L2P if the cacheline has been updated. In this case, |
| 2121 | * the mapped ppa must be invalidated |
| 2122 | */ |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2123 | if (!pblk_ppa_comp(ppa_l2p, ppa_cache)) { |
| 2124 | if (!pblk_ppa_empty(ppa_mapped)) |
| 2125 | pblk_map_invalidate(pblk, ppa_mapped); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2126 | goto out; |
| 2127 | } |
| 2128 | |
Matias Bjørling | 880eda5 | 2018-07-13 10:48:37 +0200 | [diff] [blame] | 2129 | #ifdef CONFIG_NVM_PBLK_DEBUG |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2130 | WARN_ON(!pblk_addr_in_cache(ppa_l2p) && !pblk_ppa_empty(ppa_l2p)); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2131 | #endif |
| 2132 | |
Javier González | 9f6cb13 | 2017-10-13 14:46:12 +0200 | [diff] [blame] | 2133 | pblk_trans_map_set(pblk, lba, ppa_mapped); |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2134 | out: |
| 2135 | spin_unlock(&pblk->trans_lock); |
| 2136 | } |
| 2137 | |
| 2138 | void pblk_lookup_l2p_seq(struct pblk *pblk, struct ppa_addr *ppas, |
| 2139 | sector_t blba, int nr_secs) |
| 2140 | { |
| 2141 | int i; |
| 2142 | |
| 2143 | spin_lock(&pblk->trans_lock); |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 2144 | for (i = 0; i < nr_secs; i++) { |
| 2145 | struct ppa_addr ppa; |
| 2146 | |
| 2147 | ppa = ppas[i] = pblk_trans_map_get(pblk, blba + i); |
| 2148 | |
| 2149 | /* If the L2P entry maps to a line, the reference is valid */ |
| 2150 | if (!pblk_ppa_empty(ppa) && !pblk_addr_in_cache(ppa)) { |
Javier González | cb21665 | 2018-10-09 13:11:42 +0200 | [diff] [blame] | 2151 | struct pblk_line *line = pblk_ppa_to_line(pblk, ppa); |
Javier González | 7bd4d37 | 2017-10-13 14:46:23 +0200 | [diff] [blame] | 2152 | |
| 2153 | kref_get(&line->ref); |
| 2154 | } |
| 2155 | } |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2156 | spin_unlock(&pblk->trans_lock); |
| 2157 | } |
| 2158 | |
| 2159 | void pblk_lookup_l2p_rand(struct pblk *pblk, struct ppa_addr *ppas, |
| 2160 | u64 *lba_list, int nr_secs) |
| 2161 | { |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 2162 | u64 lba; |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2163 | int i; |
| 2164 | |
| 2165 | spin_lock(&pblk->trans_lock); |
| 2166 | for (i = 0; i < nr_secs; i++) { |
| 2167 | lba = lba_list[i]; |
Javier González | d340121 | 2017-10-13 14:46:14 +0200 | [diff] [blame] | 2168 | if (lba != ADDR_EMPTY) { |
Javier González | a4bd217 | 2017-04-15 20:55:50 +0200 | [diff] [blame] | 2169 | /* logic error: lba out-of-bounds. Ignore update */ |
| 2170 | if (!(lba < pblk->rl.nr_secs)) { |
| 2171 | WARN(1, "pblk: corrupted L2P map request\n"); |
| 2172 | continue; |
| 2173 | } |
| 2174 | ppas[i] = pblk_trans_map_get(pblk, lba); |
| 2175 | } |
| 2176 | } |
| 2177 | spin_unlock(&pblk->trans_lock); |
| 2178 | } |
Igor Konopko | 55d8ec3 | 2018-12-11 20:16:26 +0100 | [diff] [blame] | 2179 | |
| 2180 | void *pblk_get_meta_for_writes(struct pblk *pblk, struct nvm_rq *rqd) |
| 2181 | { |
| 2182 | void *buffer; |
| 2183 | |
| 2184 | if (pblk_is_oob_meta_supported(pblk)) { |
| 2185 | /* Just use OOB metadata buffer as always */ |
| 2186 | buffer = rqd->meta_list; |
| 2187 | } else { |
| 2188 | /* We need to reuse last page of request (packed metadata) |
| 2189 | * in similar way as traditional oob metadata |
| 2190 | */ |
| 2191 | buffer = page_to_virt( |
| 2192 | rqd->bio->bi_io_vec[rqd->bio->bi_vcnt - 1].bv_page); |
| 2193 | } |
| 2194 | |
| 2195 | return buffer; |
| 2196 | } |
| 2197 | |
| 2198 | void pblk_get_packed_meta(struct pblk *pblk, struct nvm_rq *rqd) |
| 2199 | { |
| 2200 | void *meta_list = rqd->meta_list; |
| 2201 | void *page; |
| 2202 | int i = 0; |
| 2203 | |
| 2204 | if (pblk_is_oob_meta_supported(pblk)) |
| 2205 | return; |
| 2206 | |
| 2207 | page = page_to_virt(rqd->bio->bi_io_vec[rqd->bio->bi_vcnt - 1].bv_page); |
| 2208 | /* We need to fill oob meta buffer with data from packed metadata */ |
| 2209 | for (; i < rqd->nr_ppas; i++) |
| 2210 | memcpy(pblk_get_meta(pblk, meta_list, i), |
| 2211 | page + (i * sizeof(struct pblk_sec_meta)), |
| 2212 | sizeof(struct pblk_sec_meta)); |
| 2213 | } |