This source file includes following definitions.
- pblk_write_to_cache
- pblk_write_gc_to_cache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "pblk.h"
20
21 void pblk_write_to_cache(struct pblk *pblk, struct bio *bio,
22 unsigned long flags)
23 {
24 struct request_queue *q = pblk->dev->q;
25 struct pblk_w_ctx w_ctx;
26 sector_t lba = pblk_get_lba(bio);
27 unsigned long start_time = jiffies;
28 unsigned int bpos, pos;
29 int nr_entries = pblk_get_secs(bio);
30 int i, ret;
31
32 generic_start_io_acct(q, REQ_OP_WRITE, bio_sectors(bio),
33 &pblk->disk->part0);
34
35
36
37
38
39 retry:
40 ret = pblk_rb_may_write_user(&pblk->rwb, bio, nr_entries, &bpos);
41 switch (ret) {
42 case NVM_IO_REQUEUE:
43 io_schedule();
44 goto retry;
45 case NVM_IO_ERR:
46 pblk_pipeline_stop(pblk);
47 bio_io_error(bio);
48 goto out;
49 }
50
51 pblk_ppa_set_empty(&w_ctx.ppa);
52 w_ctx.flags = flags;
53 if (bio->bi_opf & REQ_PREFLUSH) {
54 w_ctx.flags |= PBLK_FLUSH_ENTRY;
55 pblk_write_kick(pblk);
56 }
57
58 if (unlikely(!bio_has_data(bio)))
59 goto out;
60
61 for (i = 0; i < nr_entries; i++) {
62 void *data = bio_data(bio);
63
64 w_ctx.lba = lba + i;
65
66 pos = pblk_rb_wrap_pos(&pblk->rwb, bpos + i);
67 pblk_rb_write_entry_user(&pblk->rwb, data, w_ctx, pos);
68
69 bio_advance(bio, PBLK_EXPOSED_PAGE_SIZE);
70 }
71
72 atomic64_add(nr_entries, &pblk->user_wa);
73
74 #ifdef CONFIG_NVM_PBLK_DEBUG
75 atomic_long_add(nr_entries, &pblk->inflight_writes);
76 atomic_long_add(nr_entries, &pblk->req_writes);
77 #endif
78
79 pblk_rl_inserted(&pblk->rl, nr_entries);
80
81 out:
82 generic_end_io_acct(q, REQ_OP_WRITE, &pblk->disk->part0, start_time);
83 pblk_write_should_kick(pblk);
84
85 if (ret == NVM_IO_DONE)
86 bio_endio(bio);
87 }
88
89
90
91
92
93 int pblk_write_gc_to_cache(struct pblk *pblk, struct pblk_gc_rq *gc_rq)
94 {
95 struct pblk_w_ctx w_ctx;
96 unsigned int bpos, pos;
97 void *data = gc_rq->data;
98 int i, valid_entries;
99
100
101
102
103
104 retry:
105 if (!pblk_rb_may_write_gc(&pblk->rwb, gc_rq->secs_to_gc, &bpos)) {
106 io_schedule();
107 goto retry;
108 }
109
110 w_ctx.flags = PBLK_IOTYPE_GC;
111 pblk_ppa_set_empty(&w_ctx.ppa);
112
113 for (i = 0, valid_entries = 0; i < gc_rq->nr_secs; i++) {
114 if (gc_rq->lba_list[i] == ADDR_EMPTY)
115 continue;
116
117 w_ctx.lba = gc_rq->lba_list[i];
118
119 pos = pblk_rb_wrap_pos(&pblk->rwb, bpos + valid_entries);
120 pblk_rb_write_entry_gc(&pblk->rwb, data, w_ctx, gc_rq->line,
121 gc_rq->paddr_list[i], pos);
122
123 data += PBLK_EXPOSED_PAGE_SIZE;
124 valid_entries++;
125 }
126
127 WARN_ONCE(gc_rq->secs_to_gc != valid_entries,
128 "pblk: inconsistent GC write\n");
129
130 atomic64_add(valid_entries, &pblk->gc_wa);
131
132 #ifdef CONFIG_NVM_PBLK_DEBUG
133 atomic_long_add(valid_entries, &pblk->inflight_writes);
134 atomic_long_add(valid_entries, &pblk->recov_gc_writes);
135 #endif
136
137 pblk_write_should_kick(pblk);
138 return NVM_IO_OK;
139 }