diff options
Diffstat (limited to 'drivers/block/null_blk.c')
-rw-r--r-- | drivers/block/null_blk.c | 97 |
1 files changed, 33 insertions, 64 deletions
diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c index 3107282a9741..091b9ea14feb 100644 --- a/drivers/block/null_blk.c +++ b/drivers/block/null_blk.c | |||
@@ -60,7 +60,9 @@ enum { | |||
60 | NULL_IRQ_NONE = 0, | 60 | NULL_IRQ_NONE = 0, |
61 | NULL_IRQ_SOFTIRQ = 1, | 61 | NULL_IRQ_SOFTIRQ = 1, |
62 | NULL_IRQ_TIMER = 2, | 62 | NULL_IRQ_TIMER = 2, |
63 | }; | ||
63 | 64 | ||
65 | enum { | ||
64 | NULL_Q_BIO = 0, | 66 | NULL_Q_BIO = 0, |
65 | NULL_Q_RQ = 1, | 67 | NULL_Q_RQ = 1, |
66 | NULL_Q_MQ = 2, | 68 | NULL_Q_MQ = 2, |
@@ -172,18 +174,20 @@ static struct nullb_cmd *alloc_cmd(struct nullb_queue *nq, int can_wait) | |||
172 | 174 | ||
173 | static void end_cmd(struct nullb_cmd *cmd) | 175 | static void end_cmd(struct nullb_cmd *cmd) |
174 | { | 176 | { |
175 | if (cmd->rq) { | 177 | switch (queue_mode) { |
176 | if (queue_mode == NULL_Q_MQ) | 178 | case NULL_Q_MQ: |
177 | blk_mq_end_io(cmd->rq, 0); | 179 | blk_mq_end_io(cmd->rq, 0); |
178 | else { | 180 | return; |
179 | INIT_LIST_HEAD(&cmd->rq->queuelist); | 181 | case NULL_Q_RQ: |
180 | blk_end_request_all(cmd->rq, 0); | 182 | INIT_LIST_HEAD(&cmd->rq->queuelist); |
181 | } | 183 | blk_end_request_all(cmd->rq, 0); |
182 | } else if (cmd->bio) | 184 | break; |
185 | case NULL_Q_BIO: | ||
183 | bio_endio(cmd->bio, 0); | 186 | bio_endio(cmd->bio, 0); |
187 | break; | ||
188 | } | ||
184 | 189 | ||
185 | if (queue_mode != NULL_Q_MQ) | 190 | free_cmd(cmd); |
186 | free_cmd(cmd); | ||
187 | } | 191 | } |
188 | 192 | ||
189 | static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer) | 193 | static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer) |
@@ -195,6 +199,7 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer) | |||
195 | cq = &per_cpu(completion_queues, smp_processor_id()); | 199 | cq = &per_cpu(completion_queues, smp_processor_id()); |
196 | 200 | ||
197 | while ((entry = llist_del_all(&cq->list)) != NULL) { | 201 | while ((entry = llist_del_all(&cq->list)) != NULL) { |
202 | entry = llist_reverse_order(entry); | ||
198 | do { | 203 | do { |
199 | cmd = container_of(entry, struct nullb_cmd, ll_list); | 204 | cmd = container_of(entry, struct nullb_cmd, ll_list); |
200 | end_cmd(cmd); | 205 | end_cmd(cmd); |
@@ -221,61 +226,31 @@ static void null_cmd_end_timer(struct nullb_cmd *cmd) | |||
221 | 226 | ||
222 | static void null_softirq_done_fn(struct request *rq) | 227 | static void null_softirq_done_fn(struct request *rq) |
223 | { | 228 | { |
224 | blk_end_request_all(rq, 0); | 229 | end_cmd(rq->special); |
225 | } | ||
226 | |||
227 | #ifdef CONFIG_SMP | ||
228 | |||
229 | static void null_ipi_cmd_end_io(void *data) | ||
230 | { | ||
231 | struct completion_queue *cq; | ||
232 | struct llist_node *entry, *next; | ||
233 | struct nullb_cmd *cmd; | ||
234 | |||
235 | cq = &per_cpu(completion_queues, smp_processor_id()); | ||
236 | |||
237 | entry = llist_del_all(&cq->list); | ||
238 | |||
239 | while (entry) { | ||
240 | next = entry->next; | ||
241 | cmd = llist_entry(entry, struct nullb_cmd, ll_list); | ||
242 | end_cmd(cmd); | ||
243 | entry = next; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | static void null_cmd_end_ipi(struct nullb_cmd *cmd) | ||
248 | { | ||
249 | struct call_single_data *data = &cmd->csd; | ||
250 | int cpu = get_cpu(); | ||
251 | struct completion_queue *cq = &per_cpu(completion_queues, cpu); | ||
252 | |||
253 | cmd->ll_list.next = NULL; | ||
254 | |||
255 | if (llist_add(&cmd->ll_list, &cq->list)) { | ||
256 | data->func = null_ipi_cmd_end_io; | ||
257 | data->flags = 0; | ||
258 | __smp_call_function_single(cpu, data, 0); | ||
259 | } | ||
260 | |||
261 | put_cpu(); | ||
262 | } | 230 | } |
263 | 231 | ||
264 | #endif /* CONFIG_SMP */ | ||
265 | |||
266 | static inline void null_handle_cmd(struct nullb_cmd *cmd) | 232 | static inline void null_handle_cmd(struct nullb_cmd *cmd) |
267 | { | 233 | { |
268 | /* Complete IO by inline, softirq or timer */ | 234 | /* Complete IO by inline, softirq or timer */ |
269 | switch (irqmode) { | 235 | switch (irqmode) { |
270 | case NULL_IRQ_NONE: | ||
271 | end_cmd(cmd); | ||
272 | break; | ||
273 | case NULL_IRQ_SOFTIRQ: | 236 | case NULL_IRQ_SOFTIRQ: |
274 | #ifdef CONFIG_SMP | 237 | switch (queue_mode) { |
275 | null_cmd_end_ipi(cmd); | 238 | case NULL_Q_MQ: |
276 | #else | 239 | blk_mq_complete_request(cmd->rq); |
240 | break; | ||
241 | case NULL_Q_RQ: | ||
242 | blk_complete_request(cmd->rq); | ||
243 | break; | ||
244 | case NULL_Q_BIO: | ||
245 | /* | ||
246 | * XXX: no proper submitting cpu information available. | ||
247 | */ | ||
248 | end_cmd(cmd); | ||
249 | break; | ||
250 | } | ||
251 | break; | ||
252 | case NULL_IRQ_NONE: | ||
277 | end_cmd(cmd); | 253 | end_cmd(cmd); |
278 | #endif | ||
279 | break; | 254 | break; |
280 | case NULL_IRQ_TIMER: | 255 | case NULL_IRQ_TIMER: |
281 | null_cmd_end_timer(cmd); | 256 | null_cmd_end_timer(cmd); |
@@ -411,6 +386,7 @@ static struct blk_mq_ops null_mq_ops = { | |||
411 | .queue_rq = null_queue_rq, | 386 | .queue_rq = null_queue_rq, |
412 | .map_queue = blk_mq_map_queue, | 387 | .map_queue = blk_mq_map_queue, |
413 | .init_hctx = null_init_hctx, | 388 | .init_hctx = null_init_hctx, |
389 | .complete = null_softirq_done_fn, | ||
414 | }; | 390 | }; |
415 | 391 | ||
416 | static struct blk_mq_reg null_mq_reg = { | 392 | static struct blk_mq_reg null_mq_reg = { |
@@ -609,13 +585,6 @@ static int __init null_init(void) | |||
609 | { | 585 | { |
610 | unsigned int i; | 586 | unsigned int i; |
611 | 587 | ||
612 | #if !defined(CONFIG_SMP) | ||
613 | if (irqmode == NULL_IRQ_SOFTIRQ) { | ||
614 | pr_warn("null_blk: softirq completions not available.\n"); | ||
615 | pr_warn("null_blk: using direct completions.\n"); | ||
616 | irqmode = NULL_IRQ_NONE; | ||
617 | } | ||
618 | #endif | ||
619 | if (bs > PAGE_SIZE) { | 588 | if (bs > PAGE_SIZE) { |
620 | pr_warn("null_blk: invalid block size\n"); | 589 | pr_warn("null_blk: invalid block size\n"); |
621 | pr_warn("null_blk: defaults block size to %lu\n", PAGE_SIZE); | 590 | pr_warn("null_blk: defaults block size to %lu\n", PAGE_SIZE); |