lightnvm: pblk: move lba list to partial read context
[linux-2.6-microblaze.git] / drivers / lightnvm / pblk-read.c
1 // SPDX-License-Identifier: GPL-2.0
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-read.c - pblk's read path
17  */
18
19 #include "pblk.h"
20
21 /*
22  * There is no guarantee that the value read from cache has not been updated and
23  * resides at another location in the cache. We guarantee though that if the
24  * value is read from the cache, it belongs to the mapped lba. In order to
25  * guarantee and order between writes and reads are ordered, a flush must be
26  * issued.
27  */
28 static int pblk_read_from_cache(struct pblk *pblk, struct bio *bio,
29                                 sector_t lba, struct ppa_addr ppa,
30                                 int bio_iter, bool advanced_bio)
31 {
32 #ifdef CONFIG_NVM_PBLK_DEBUG
33         /* Callers must ensure that the ppa points to a cache address */
34         BUG_ON(pblk_ppa_empty(ppa));
35         BUG_ON(!pblk_addr_in_cache(ppa));
36 #endif
37
38         return pblk_rb_copy_to_bio(&pblk->rwb, bio, lba, ppa,
39                                                 bio_iter, advanced_bio);
40 }
41
42 static void pblk_read_ppalist_rq(struct pblk *pblk, struct nvm_rq *rqd,
43                                  struct bio *bio, sector_t blba,
44                                  unsigned long *read_bitmap)
45 {
46         struct pblk_sec_meta *meta_list = rqd->meta_list;
47         struct ppa_addr ppas[NVM_MAX_VLBA];
48         int nr_secs = rqd->nr_ppas;
49         bool advanced_bio = false;
50         int i, j = 0;
51
52         pblk_lookup_l2p_seq(pblk, ppas, blba, nr_secs);
53
54         for (i = 0; i < nr_secs; i++) {
55                 struct ppa_addr p = ppas[i];
56                 sector_t lba = blba + i;
57
58 retry:
59                 if (pblk_ppa_empty(p)) {
60                         WARN_ON(test_and_set_bit(i, read_bitmap));
61                         meta_list[i].lba = cpu_to_le64(ADDR_EMPTY);
62
63                         if (unlikely(!advanced_bio)) {
64                                 bio_advance(bio, (i) * PBLK_EXPOSED_PAGE_SIZE);
65                                 advanced_bio = true;
66                         }
67
68                         goto next;
69                 }
70
71                 /* Try to read from write buffer. The address is later checked
72                  * on the write buffer to prevent retrieving overwritten data.
73                  */
74                 if (pblk_addr_in_cache(p)) {
75                         if (!pblk_read_from_cache(pblk, bio, lba, p, i,
76                                                                 advanced_bio)) {
77                                 pblk_lookup_l2p_seq(pblk, &p, lba, 1);
78                                 goto retry;
79                         }
80                         WARN_ON(test_and_set_bit(i, read_bitmap));
81                         meta_list[i].lba = cpu_to_le64(lba);
82                         advanced_bio = true;
83 #ifdef CONFIG_NVM_PBLK_DEBUG
84                         atomic_long_inc(&pblk->cache_reads);
85 #endif
86                 } else {
87                         /* Read from media non-cached sectors */
88                         rqd->ppa_list[j++] = p;
89                 }
90
91 next:
92                 if (advanced_bio)
93                         bio_advance(bio, PBLK_EXPOSED_PAGE_SIZE);
94         }
95
96         if (pblk_io_aligned(pblk, nr_secs))
97                 rqd->is_seq = 1;
98
99 #ifdef CONFIG_NVM_PBLK_DEBUG
100         atomic_long_add(nr_secs, &pblk->inflight_reads);
101 #endif
102 }
103
104
105 static void pblk_read_check_seq(struct pblk *pblk, struct nvm_rq *rqd,
106                                 sector_t blba)
107 {
108         struct pblk_sec_meta *meta_lba_list = rqd->meta_list;
109         int nr_lbas = rqd->nr_ppas;
110         int i;
111
112         for (i = 0; i < nr_lbas; i++) {
113                 u64 lba = le64_to_cpu(meta_lba_list[i].lba);
114
115                 if (lba == ADDR_EMPTY)
116                         continue;
117
118                 if (lba != blba + i) {
119 #ifdef CONFIG_NVM_PBLK_DEBUG
120                         struct ppa_addr *ppa_list = nvm_rq_to_ppa_list(rqd);
121
122                         print_ppa(pblk, &ppa_list[i], "seq", i);
123 #endif
124                         pblk_err(pblk, "corrupted read LBA (%llu/%llu)\n",
125                                                         lba, (u64)blba + i);
126                         WARN_ON(1);
127                 }
128         }
129 }
130
131 /*
132  * There can be holes in the lba list.
133  */
134 static void pblk_read_check_rand(struct pblk *pblk, struct nvm_rq *rqd,
135                                  u64 *lba_list, int nr_lbas)
136 {
137         struct pblk_sec_meta *meta_lba_list = rqd->meta_list;
138         int i, j;
139
140         for (i = 0, j = 0; i < nr_lbas; i++) {
141                 u64 lba = lba_list[i];
142                 u64 meta_lba;
143
144                 if (lba == ADDR_EMPTY)
145                         continue;
146
147                 meta_lba = le64_to_cpu(meta_lba_list[j].lba);
148
149                 if (lba != meta_lba) {
150 #ifdef CONFIG_NVM_PBLK_DEBUG
151                         struct ppa_addr *ppa_list = nvm_rq_to_ppa_list(rqd);
152
153                         print_ppa(pblk, &ppa_list[j], "rnd", j);
154 #endif
155                         pblk_err(pblk, "corrupted read LBA (%llu/%llu)\n",
156                                                         meta_lba, lba);
157                         WARN_ON(1);
158                 }
159
160                 j++;
161         }
162
163         WARN_ONCE(j != rqd->nr_ppas, "pblk: corrupted random request\n");
164 }
165
166 static void pblk_end_user_read(struct bio *bio)
167 {
168 #ifdef CONFIG_NVM_PBLK_DEBUG
169         WARN_ONCE(bio->bi_status, "pblk: corrupted read bio\n");
170 #endif
171         bio_endio(bio);
172 }
173
174 static void __pblk_end_io_read(struct pblk *pblk, struct nvm_rq *rqd,
175                                bool put_line)
176 {
177         struct nvm_tgt_dev *dev = pblk->dev;
178         struct pblk_g_ctx *r_ctx = nvm_rq_to_pdu(rqd);
179         struct bio *int_bio = rqd->bio;
180         unsigned long start_time = r_ctx->start_time;
181
182         generic_end_io_acct(dev->q, REQ_OP_READ, &pblk->disk->part0, start_time);
183
184         if (rqd->error)
185                 pblk_log_read_err(pblk, rqd);
186
187         pblk_read_check_seq(pblk, rqd, r_ctx->lba);
188
189         if (int_bio)
190                 bio_put(int_bio);
191
192         if (put_line)
193                 pblk_rq_to_line_put(pblk, rqd);
194
195 #ifdef CONFIG_NVM_PBLK_DEBUG
196         atomic_long_add(rqd->nr_ppas, &pblk->sync_reads);
197         atomic_long_sub(rqd->nr_ppas, &pblk->inflight_reads);
198 #endif
199
200         pblk_free_rqd(pblk, rqd, PBLK_READ);
201         atomic_dec(&pblk->inflight_io);
202 }
203
204 static void pblk_end_io_read(struct nvm_rq *rqd)
205 {
206         struct pblk *pblk = rqd->private;
207         struct pblk_g_ctx *r_ctx = nvm_rq_to_pdu(rqd);
208         struct bio *bio = (struct bio *)r_ctx->private;
209
210         pblk_end_user_read(bio);
211         __pblk_end_io_read(pblk, rqd, true);
212 }
213
214 static void pblk_end_partial_read(struct nvm_rq *rqd)
215 {
216         struct pblk *pblk = rqd->private;
217         struct pblk_g_ctx *r_ctx = nvm_rq_to_pdu(rqd);
218         struct pblk_pr_ctx *pr_ctx = r_ctx->private;
219         struct bio *new_bio = rqd->bio;
220         struct bio *bio = pr_ctx->orig_bio;
221         struct bio_vec src_bv, dst_bv;
222         struct pblk_sec_meta *meta_list = rqd->meta_list;
223         int bio_init_idx = pr_ctx->bio_init_idx;
224         unsigned long *read_bitmap = pr_ctx->bitmap;
225         int nr_secs = pr_ctx->orig_nr_secs;
226         int nr_holes = nr_secs - bitmap_weight(read_bitmap, nr_secs);
227         void *src_p, *dst_p;
228         int hole, i;
229
230         if (unlikely(nr_holes == 1)) {
231                 struct ppa_addr ppa;
232
233                 ppa = rqd->ppa_addr;
234                 rqd->ppa_list = pr_ctx->ppa_ptr;
235                 rqd->dma_ppa_list = pr_ctx->dma_ppa_list;
236                 rqd->ppa_list[0] = ppa;
237         }
238
239         for (i = 0; i < nr_secs; i++) {
240                 pr_ctx->lba_list_media[i] = meta_list[i].lba;
241                 meta_list[i].lba = pr_ctx->lba_list_mem[i];
242         }
243
244         /* Fill the holes in the original bio */
245         i = 0;
246         hole = find_first_zero_bit(read_bitmap, nr_secs);
247         do {
248                 struct pblk_line *line;
249
250                 line = pblk_ppa_to_line(pblk, rqd->ppa_list[i]);
251                 kref_put(&line->ref, pblk_line_put);
252
253                 meta_list[hole].lba = pr_ctx->lba_list_media[i];
254
255                 src_bv = new_bio->bi_io_vec[i++];
256                 dst_bv = bio->bi_io_vec[bio_init_idx + hole];
257
258                 src_p = kmap_atomic(src_bv.bv_page);
259                 dst_p = kmap_atomic(dst_bv.bv_page);
260
261                 memcpy(dst_p + dst_bv.bv_offset,
262                         src_p + src_bv.bv_offset,
263                         PBLK_EXPOSED_PAGE_SIZE);
264
265                 kunmap_atomic(src_p);
266                 kunmap_atomic(dst_p);
267
268                 mempool_free(src_bv.bv_page, &pblk->page_bio_pool);
269
270                 hole = find_next_zero_bit(read_bitmap, nr_secs, hole + 1);
271         } while (hole < nr_secs);
272
273         bio_put(new_bio);
274         kfree(pr_ctx);
275
276         /* restore original request */
277         rqd->bio = NULL;
278         rqd->nr_ppas = nr_secs;
279
280         bio_endio(bio);
281         __pblk_end_io_read(pblk, rqd, false);
282 }
283
284 static int pblk_setup_partial_read(struct pblk *pblk, struct nvm_rq *rqd,
285                             unsigned int bio_init_idx,
286                             unsigned long *read_bitmap,
287                             int nr_holes)
288 {
289         struct pblk_sec_meta *meta_list = rqd->meta_list;
290         struct pblk_g_ctx *r_ctx = nvm_rq_to_pdu(rqd);
291         struct pblk_pr_ctx *pr_ctx;
292         struct bio *new_bio, *bio = r_ctx->private;
293         int nr_secs = rqd->nr_ppas;
294         int i;
295
296         new_bio = bio_alloc(GFP_KERNEL, nr_holes);
297
298         if (pblk_bio_add_pages(pblk, new_bio, GFP_KERNEL, nr_holes))
299                 goto fail_bio_put;
300
301         if (nr_holes != new_bio->bi_vcnt) {
302                 WARN_ONCE(1, "pblk: malformed bio\n");
303                 goto fail_free_pages;
304         }
305
306         pr_ctx = kzalloc(sizeof(struct pblk_pr_ctx), GFP_KERNEL);
307         if (!pr_ctx)
308                 goto fail_free_pages;
309
310         for (i = 0; i < nr_secs; i++)
311                 pr_ctx->lba_list_mem[i] = meta_list[i].lba;
312
313         new_bio->bi_iter.bi_sector = 0; /* internal bio */
314         bio_set_op_attrs(new_bio, REQ_OP_READ, 0);
315
316         rqd->bio = new_bio;
317         rqd->nr_ppas = nr_holes;
318
319         pr_ctx->orig_bio = bio;
320         bitmap_copy(pr_ctx->bitmap, read_bitmap, NVM_MAX_VLBA);
321         pr_ctx->bio_init_idx = bio_init_idx;
322         pr_ctx->orig_nr_secs = nr_secs;
323         r_ctx->private = pr_ctx;
324
325         if (unlikely(nr_holes == 1)) {
326                 pr_ctx->ppa_ptr = rqd->ppa_list;
327                 pr_ctx->dma_ppa_list = rqd->dma_ppa_list;
328                 rqd->ppa_addr = rqd->ppa_list[0];
329         }
330         return 0;
331
332 fail_free_pages:
333         pblk_bio_free_pages(pblk, new_bio, 0, new_bio->bi_vcnt);
334 fail_bio_put:
335         bio_put(new_bio);
336
337         return -ENOMEM;
338 }
339
340 static int pblk_partial_read_bio(struct pblk *pblk, struct nvm_rq *rqd,
341                                  unsigned int bio_init_idx,
342                                  unsigned long *read_bitmap, int nr_secs)
343 {
344         int nr_holes;
345         int ret;
346
347         nr_holes = nr_secs - bitmap_weight(read_bitmap, nr_secs);
348
349         if (pblk_setup_partial_read(pblk, rqd, bio_init_idx, read_bitmap,
350                                     nr_holes))
351                 return NVM_IO_ERR;
352
353         rqd->end_io = pblk_end_partial_read;
354
355         ret = pblk_submit_io(pblk, rqd);
356         if (ret) {
357                 bio_put(rqd->bio);
358                 pblk_err(pblk, "partial read IO submission failed\n");
359                 goto err;
360         }
361
362         return NVM_IO_OK;
363
364 err:
365         pblk_err(pblk, "failed to perform partial read\n");
366
367         /* Free allocated pages in new bio */
368         pblk_bio_free_pages(pblk, rqd->bio, 0, rqd->bio->bi_vcnt);
369         __pblk_end_io_read(pblk, rqd, false);
370         return NVM_IO_ERR;
371 }
372
373 static void pblk_read_rq(struct pblk *pblk, struct nvm_rq *rqd, struct bio *bio,
374                          sector_t lba, unsigned long *read_bitmap)
375 {
376         struct pblk_sec_meta *meta_list = rqd->meta_list;
377         struct ppa_addr ppa;
378
379         pblk_lookup_l2p_seq(pblk, &ppa, lba, 1);
380
381 #ifdef CONFIG_NVM_PBLK_DEBUG
382         atomic_long_inc(&pblk->inflight_reads);
383 #endif
384
385 retry:
386         if (pblk_ppa_empty(ppa)) {
387                 WARN_ON(test_and_set_bit(0, read_bitmap));
388                 meta_list[0].lba = cpu_to_le64(ADDR_EMPTY);
389                 return;
390         }
391
392         /* Try to read from write buffer. The address is later checked on the
393          * write buffer to prevent retrieving overwritten data.
394          */
395         if (pblk_addr_in_cache(ppa)) {
396                 if (!pblk_read_from_cache(pblk, bio, lba, ppa, 0, 1)) {
397                         pblk_lookup_l2p_seq(pblk, &ppa, lba, 1);
398                         goto retry;
399                 }
400
401                 WARN_ON(test_and_set_bit(0, read_bitmap));
402                 meta_list[0].lba = cpu_to_le64(lba);
403
404 #ifdef CONFIG_NVM_PBLK_DEBUG
405                 atomic_long_inc(&pblk->cache_reads);
406 #endif
407         } else {
408                 rqd->ppa_addr = ppa;
409         }
410 }
411
412 int pblk_submit_read(struct pblk *pblk, struct bio *bio)
413 {
414         struct nvm_tgt_dev *dev = pblk->dev;
415         struct request_queue *q = dev->q;
416         sector_t blba = pblk_get_lba(bio);
417         unsigned int nr_secs = pblk_get_secs(bio);
418         struct pblk_g_ctx *r_ctx;
419         struct nvm_rq *rqd;
420         unsigned int bio_init_idx;
421         DECLARE_BITMAP(read_bitmap, NVM_MAX_VLBA);
422         int ret = NVM_IO_ERR;
423
424         generic_start_io_acct(q, REQ_OP_READ, bio_sectors(bio),
425                               &pblk->disk->part0);
426
427         bitmap_zero(read_bitmap, nr_secs);
428
429         rqd = pblk_alloc_rqd(pblk, PBLK_READ);
430
431         rqd->opcode = NVM_OP_PREAD;
432         rqd->nr_ppas = nr_secs;
433         rqd->bio = NULL; /* cloned bio if needed */
434         rqd->private = pblk;
435         rqd->end_io = pblk_end_io_read;
436
437         r_ctx = nvm_rq_to_pdu(rqd);
438         r_ctx->start_time = jiffies;
439         r_ctx->lba = blba;
440         r_ctx->private = bio; /* original bio */
441
442         /* Save the index for this bio's start. This is needed in case
443          * we need to fill a partial read.
444          */
445         bio_init_idx = pblk_get_bi_idx(bio);
446
447         if (pblk_alloc_rqd_meta(pblk, rqd))
448                 goto fail_rqd_free;
449
450         if (nr_secs > 1)
451                 pblk_read_ppalist_rq(pblk, rqd, bio, blba, read_bitmap);
452         else
453                 pblk_read_rq(pblk, rqd, bio, blba, read_bitmap);
454
455         if (bitmap_full(read_bitmap, nr_secs)) {
456                 atomic_inc(&pblk->inflight_io);
457                 __pblk_end_io_read(pblk, rqd, false);
458                 return NVM_IO_DONE;
459         }
460
461         /* All sectors are to be read from the device */
462         if (bitmap_empty(read_bitmap, rqd->nr_ppas)) {
463                 struct bio *int_bio = NULL;
464
465                 /* Clone read bio to deal with read errors internally */
466                 int_bio = bio_clone_fast(bio, GFP_KERNEL, &pblk_bio_set);
467                 if (!int_bio) {
468                         pblk_err(pblk, "could not clone read bio\n");
469                         goto fail_end_io;
470                 }
471
472                 rqd->bio = int_bio;
473
474                 if (pblk_submit_io(pblk, rqd)) {
475                         pblk_err(pblk, "read IO submission failed\n");
476                         ret = NVM_IO_ERR;
477                         goto fail_end_io;
478                 }
479
480                 return NVM_IO_OK;
481         }
482
483         /* The read bio request could be partially filled by the write buffer,
484          * but there are some holes that need to be read from the drive.
485          */
486         ret = pblk_partial_read_bio(pblk, rqd, bio_init_idx, read_bitmap,
487                                     nr_secs);
488         if (ret)
489                 goto fail_meta_free;
490
491         return NVM_IO_OK;
492
493 fail_meta_free:
494         nvm_dev_dma_free(dev->parent, rqd->meta_list, rqd->dma_meta_list);
495 fail_rqd_free:
496         pblk_free_rqd(pblk, rqd, PBLK_READ);
497         return ret;
498 fail_end_io:
499         __pblk_end_io_read(pblk, rqd, false);
500         return ret;
501 }
502
503 static int read_ppalist_rq_gc(struct pblk *pblk, struct nvm_rq *rqd,
504                               struct pblk_line *line, u64 *lba_list,
505                               u64 *paddr_list_gc, unsigned int nr_secs)
506 {
507         struct ppa_addr ppa_list_l2p[NVM_MAX_VLBA];
508         struct ppa_addr ppa_gc;
509         int valid_secs = 0;
510         int i;
511
512         pblk_lookup_l2p_rand(pblk, ppa_list_l2p, lba_list, nr_secs);
513
514         for (i = 0; i < nr_secs; i++) {
515                 if (lba_list[i] == ADDR_EMPTY)
516                         continue;
517
518                 ppa_gc = addr_to_gen_ppa(pblk, paddr_list_gc[i], line->id);
519                 if (!pblk_ppa_comp(ppa_list_l2p[i], ppa_gc)) {
520                         paddr_list_gc[i] = lba_list[i] = ADDR_EMPTY;
521                         continue;
522                 }
523
524                 rqd->ppa_list[valid_secs++] = ppa_list_l2p[i];
525         }
526
527 #ifdef CONFIG_NVM_PBLK_DEBUG
528         atomic_long_add(valid_secs, &pblk->inflight_reads);
529 #endif
530
531         return valid_secs;
532 }
533
534 static int read_rq_gc(struct pblk *pblk, struct nvm_rq *rqd,
535                       struct pblk_line *line, sector_t lba,
536                       u64 paddr_gc)
537 {
538         struct ppa_addr ppa_l2p, ppa_gc;
539         int valid_secs = 0;
540
541         if (lba == ADDR_EMPTY)
542                 goto out;
543
544         /* logic error: lba out-of-bounds */
545         if (lba >= pblk->rl.nr_secs) {
546                 WARN(1, "pblk: read lba out of bounds\n");
547                 goto out;
548         }
549
550         spin_lock(&pblk->trans_lock);
551         ppa_l2p = pblk_trans_map_get(pblk, lba);
552         spin_unlock(&pblk->trans_lock);
553
554         ppa_gc = addr_to_gen_ppa(pblk, paddr_gc, line->id);
555         if (!pblk_ppa_comp(ppa_l2p, ppa_gc))
556                 goto out;
557
558         rqd->ppa_addr = ppa_l2p;
559         valid_secs = 1;
560
561 #ifdef CONFIG_NVM_PBLK_DEBUG
562         atomic_long_inc(&pblk->inflight_reads);
563 #endif
564
565 out:
566         return valid_secs;
567 }
568
569 int pblk_submit_read_gc(struct pblk *pblk, struct pblk_gc_rq *gc_rq)
570 {
571         struct nvm_tgt_dev *dev = pblk->dev;
572         struct nvm_geo *geo = &dev->geo;
573         struct bio *bio;
574         struct nvm_rq rqd;
575         int data_len;
576         int ret = NVM_IO_OK;
577
578         memset(&rqd, 0, sizeof(struct nvm_rq));
579
580         ret = pblk_alloc_rqd_meta(pblk, &rqd);
581         if (ret)
582                 return ret;
583
584         if (gc_rq->nr_secs > 1) {
585                 gc_rq->secs_to_gc = read_ppalist_rq_gc(pblk, &rqd, gc_rq->line,
586                                                         gc_rq->lba_list,
587                                                         gc_rq->paddr_list,
588                                                         gc_rq->nr_secs);
589                 if (gc_rq->secs_to_gc == 1)
590                         rqd.ppa_addr = rqd.ppa_list[0];
591         } else {
592                 gc_rq->secs_to_gc = read_rq_gc(pblk, &rqd, gc_rq->line,
593                                                         gc_rq->lba_list[0],
594                                                         gc_rq->paddr_list[0]);
595         }
596
597         if (!(gc_rq->secs_to_gc))
598                 goto out;
599
600         data_len = (gc_rq->secs_to_gc) * geo->csecs;
601         bio = pblk_bio_map_addr(pblk, gc_rq->data, gc_rq->secs_to_gc, data_len,
602                                                 PBLK_VMALLOC_META, GFP_KERNEL);
603         if (IS_ERR(bio)) {
604                 pblk_err(pblk, "could not allocate GC bio (%lu)\n",
605                                                                 PTR_ERR(bio));
606                 ret = PTR_ERR(bio);
607                 goto err_free_dma;
608         }
609
610         bio->bi_iter.bi_sector = 0; /* internal bio */
611         bio_set_op_attrs(bio, REQ_OP_READ, 0);
612
613         rqd.opcode = NVM_OP_PREAD;
614         rqd.nr_ppas = gc_rq->secs_to_gc;
615         rqd.bio = bio;
616
617         if (pblk_submit_io_sync(pblk, &rqd)) {
618                 ret = -EIO;
619                 pblk_err(pblk, "GC read request failed\n");
620                 goto err_free_bio;
621         }
622
623         pblk_read_check_rand(pblk, &rqd, gc_rq->lba_list, gc_rq->nr_secs);
624
625         atomic_dec(&pblk->inflight_io);
626
627         if (rqd.error) {
628                 atomic_long_inc(&pblk->read_failed_gc);
629 #ifdef CONFIG_NVM_PBLK_DEBUG
630                 pblk_print_failed_rqd(pblk, &rqd, rqd.error);
631 #endif
632         }
633
634 #ifdef CONFIG_NVM_PBLK_DEBUG
635         atomic_long_add(gc_rq->secs_to_gc, &pblk->sync_reads);
636         atomic_long_add(gc_rq->secs_to_gc, &pblk->recov_gc_reads);
637         atomic_long_sub(gc_rq->secs_to_gc, &pblk->inflight_reads);
638 #endif
639
640 out:
641         pblk_free_rqd_meta(pblk, &rqd);
642         return ret;
643
644 err_free_bio:
645         bio_put(bio);
646 err_free_dma:
647         pblk_free_rqd_meta(pblk, &rqd);
648         return ret;
649 }