1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "pblk.h"
19
20int pblk_write_to_cache(struct pblk *pblk, struct bio *bio, unsigned long flags)
21{
22 struct pblk_w_ctx w_ctx;
23 sector_t lba = pblk_get_lba(bio);
24 unsigned int bpos, pos;
25 int nr_entries = pblk_get_secs(bio);
26 int i, ret;
27
28
29
30
31
32retry:
33 ret = pblk_rb_may_write_user(&pblk->rwb, bio, nr_entries, &bpos);
34 switch (ret) {
35 case NVM_IO_REQUEUE:
36 io_schedule();
37 goto retry;
38 case NVM_IO_ERR:
39 pblk_pipeline_stop(pblk);
40 goto out;
41 }
42
43 if (unlikely(!bio_has_data(bio)))
44 goto out;
45
46 w_ctx.flags = flags;
47 pblk_ppa_set_empty(&w_ctx.ppa);
48
49 for (i = 0; i < nr_entries; i++) {
50 void *data = bio_data(bio);
51
52 w_ctx.lba = lba + i;
53
54 pos = pblk_rb_wrap_pos(&pblk->rwb, bpos + i);
55 pblk_rb_write_entry_user(&pblk->rwb, data, w_ctx, pos);
56
57 bio_advance(bio, PBLK_EXPOSED_PAGE_SIZE);
58 }
59
60#ifdef CONFIG_NVM_DEBUG
61 atomic_long_add(nr_entries, &pblk->inflight_writes);
62 atomic_long_add(nr_entries, &pblk->req_writes);
63#endif
64
65 pblk_rl_inserted(&pblk->rl, nr_entries);
66
67out:
68 pblk_write_should_kick(pblk);
69 return ret;
70}
71
72
73
74
75
76int pblk_write_gc_to_cache(struct pblk *pblk, void *data, u64 *lba_list,
77 unsigned int nr_entries, unsigned int nr_rec_entries,
78 struct pblk_line *gc_line, unsigned long flags)
79{
80 struct pblk_w_ctx w_ctx;
81 unsigned int bpos, pos;
82 int i, valid_entries;
83
84
85
86
87
88retry:
89 if (!pblk_rb_may_write_gc(&pblk->rwb, nr_rec_entries, &bpos)) {
90 io_schedule();
91 goto retry;
92 }
93
94 w_ctx.flags = flags;
95 pblk_ppa_set_empty(&w_ctx.ppa);
96
97 for (i = 0, valid_entries = 0; i < nr_entries; i++) {
98 if (lba_list[i] == ADDR_EMPTY)
99 continue;
100
101 w_ctx.lba = lba_list[i];
102
103 pos = pblk_rb_wrap_pos(&pblk->rwb, bpos + valid_entries);
104 pblk_rb_write_entry_gc(&pblk->rwb, data, w_ctx, gc_line, pos);
105
106 data += PBLK_EXPOSED_PAGE_SIZE;
107 valid_entries++;
108 }
109
110 WARN_ONCE(nr_rec_entries != valid_entries,
111 "pblk: inconsistent GC write\n");
112
113#ifdef CONFIG_NVM_DEBUG
114 atomic_long_add(valid_entries, &pblk->inflight_writes);
115 atomic_long_add(valid_entries, &pblk->recov_gc_writes);
116#endif
117
118 pblk_write_should_kick(pblk);
119 return NVM_IO_OK;
120}
121