.. | .. |
---|
12 | 12 | |
---|
13 | 13 | #define DM_MSG_PREFIX "core-rq" |
---|
14 | 14 | |
---|
| 15 | +/* |
---|
| 16 | + * One of these is allocated per request. |
---|
| 17 | + */ |
---|
| 18 | +struct dm_rq_target_io { |
---|
| 19 | + struct mapped_device *md; |
---|
| 20 | + struct dm_target *ti; |
---|
| 21 | + struct request *orig, *clone; |
---|
| 22 | + struct kthread_work work; |
---|
| 23 | + blk_status_t error; |
---|
| 24 | + union map_info info; |
---|
| 25 | + struct dm_stats_aux stats_aux; |
---|
| 26 | + unsigned long duration_jiffies; |
---|
| 27 | + unsigned n_sectors; |
---|
| 28 | + unsigned completed; |
---|
| 29 | +}; |
---|
| 30 | + |
---|
15 | 31 | #define DM_MQ_NR_HW_QUEUES 1 |
---|
16 | 32 | #define DM_MQ_QUEUE_DEPTH 2048 |
---|
17 | 33 | static unsigned dm_mq_nr_hw_queues = DM_MQ_NR_HW_QUEUES; |
---|
.. | .. |
---|
22 | 38 | */ |
---|
23 | 39 | #define RESERVED_REQUEST_BASED_IOS 256 |
---|
24 | 40 | static unsigned reserved_rq_based_ios = RESERVED_REQUEST_BASED_IOS; |
---|
25 | | - |
---|
26 | | -static bool use_blk_mq = IS_ENABLED(CONFIG_DM_MQ_DEFAULT); |
---|
27 | | - |
---|
28 | | -bool dm_use_blk_mq_default(void) |
---|
29 | | -{ |
---|
30 | | - return use_blk_mq; |
---|
31 | | -} |
---|
32 | | - |
---|
33 | | -bool dm_use_blk_mq(struct mapped_device *md) |
---|
34 | | -{ |
---|
35 | | - return md->use_blk_mq; |
---|
36 | | -} |
---|
37 | | -EXPORT_SYMBOL_GPL(dm_use_blk_mq); |
---|
38 | 41 | |
---|
39 | 42 | unsigned dm_get_reserved_rq_based_ios(void) |
---|
40 | 43 | { |
---|
.. | .. |
---|
56 | 59 | |
---|
57 | 60 | int dm_request_based(struct mapped_device *md) |
---|
58 | 61 | { |
---|
59 | | - return queue_is_rq_based(md->queue); |
---|
| 62 | + return queue_is_mq(md->queue); |
---|
60 | 63 | } |
---|
61 | 64 | |
---|
62 | | -static void dm_old_start_queue(struct request_queue *q) |
---|
63 | | -{ |
---|
64 | | - unsigned long flags; |
---|
65 | | - |
---|
66 | | - spin_lock_irqsave(q->queue_lock, flags); |
---|
67 | | - if (blk_queue_stopped(q)) |
---|
68 | | - blk_start_queue(q); |
---|
69 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
---|
70 | | -} |
---|
71 | | - |
---|
72 | | -static void dm_mq_start_queue(struct request_queue *q) |
---|
| 65 | +void dm_start_queue(struct request_queue *q) |
---|
73 | 66 | { |
---|
74 | 67 | blk_mq_unquiesce_queue(q); |
---|
75 | 68 | blk_mq_kick_requeue_list(q); |
---|
76 | 69 | } |
---|
77 | 70 | |
---|
78 | | -void dm_start_queue(struct request_queue *q) |
---|
79 | | -{ |
---|
80 | | - if (!q->mq_ops) |
---|
81 | | - dm_old_start_queue(q); |
---|
82 | | - else |
---|
83 | | - dm_mq_start_queue(q); |
---|
84 | | -} |
---|
85 | | - |
---|
86 | | -static void dm_old_stop_queue(struct request_queue *q) |
---|
87 | | -{ |
---|
88 | | - unsigned long flags; |
---|
89 | | - |
---|
90 | | - spin_lock_irqsave(q->queue_lock, flags); |
---|
91 | | - if (!blk_queue_stopped(q)) |
---|
92 | | - blk_stop_queue(q); |
---|
93 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
---|
94 | | -} |
---|
95 | | - |
---|
96 | | -static void dm_mq_stop_queue(struct request_queue *q) |
---|
97 | | -{ |
---|
98 | | - blk_mq_quiesce_queue(q); |
---|
99 | | -} |
---|
100 | | - |
---|
101 | 71 | void dm_stop_queue(struct request_queue *q) |
---|
102 | 72 | { |
---|
103 | | - if (!q->mq_ops) |
---|
104 | | - dm_old_stop_queue(q); |
---|
105 | | - else |
---|
106 | | - dm_mq_stop_queue(q); |
---|
| 73 | + blk_mq_quiesce_queue(q); |
---|
107 | 74 | } |
---|
108 | 75 | |
---|
109 | 76 | /* |
---|
.. | .. |
---|
145 | 112 | |
---|
146 | 113 | /* |
---|
147 | 114 | * Update the original request. |
---|
148 | | - * Do not use blk_end_request() here, because it may complete |
---|
| 115 | + * Do not use blk_mq_end_request() here, because it may complete |
---|
149 | 116 | * the original request before the clone, and break the ordering. |
---|
150 | 117 | */ |
---|
151 | 118 | if (is_last) |
---|
.. | .. |
---|
174 | 141 | * the md may be freed in dm_put() at the end of this function. |
---|
175 | 142 | * Or do dm_get() before calling this function and dm_put() later. |
---|
176 | 143 | */ |
---|
177 | | -static void rq_completed(struct mapped_device *md, int rw, bool run_queue) |
---|
| 144 | +static void rq_completed(struct mapped_device *md) |
---|
178 | 145 | { |
---|
179 | | - struct request_queue *q = md->queue; |
---|
180 | | - unsigned long flags; |
---|
181 | | - |
---|
182 | | - atomic_dec(&md->pending[rw]); |
---|
183 | | - |
---|
184 | | - /* nudge anyone waiting on suspend queue */ |
---|
185 | | - if (!md_in_flight(md)) |
---|
186 | | - wake_up(&md->wait); |
---|
187 | | - |
---|
188 | | - /* |
---|
189 | | - * Run this off this callpath, as drivers could invoke end_io while |
---|
190 | | - * inside their request_fn (and holding the queue lock). Calling |
---|
191 | | - * back into ->request_fn() could deadlock attempting to grab the |
---|
192 | | - * queue lock again. |
---|
193 | | - */ |
---|
194 | | - if (!q->mq_ops && run_queue) { |
---|
195 | | - spin_lock_irqsave(q->queue_lock, flags); |
---|
196 | | - blk_run_queue_async(q); |
---|
197 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
---|
198 | | - } |
---|
199 | | - |
---|
200 | 146 | /* |
---|
201 | 147 | * dm_put() must be at the end of this function. See the comment above |
---|
202 | 148 | */ |
---|
.. | .. |
---|
210 | 156 | */ |
---|
211 | 157 | static void dm_end_request(struct request *clone, blk_status_t error) |
---|
212 | 158 | { |
---|
213 | | - int rw = rq_data_dir(clone); |
---|
214 | 159 | struct dm_rq_target_io *tio = clone->end_io_data; |
---|
215 | 160 | struct mapped_device *md = tio->md; |
---|
216 | 161 | struct request *rq = tio->orig; |
---|
.. | .. |
---|
219 | 164 | tio->ti->type->release_clone_rq(clone, NULL); |
---|
220 | 165 | |
---|
221 | 166 | rq_end_stats(md, rq); |
---|
222 | | - if (!rq->q->mq_ops) |
---|
223 | | - blk_end_request_all(rq, error); |
---|
224 | | - else |
---|
225 | | - blk_mq_end_request(rq, error); |
---|
226 | | - rq_completed(md, rw, true); |
---|
227 | | -} |
---|
228 | | - |
---|
229 | | -/* |
---|
230 | | - * Requeue the original request of a clone. |
---|
231 | | - */ |
---|
232 | | -static void dm_old_requeue_request(struct request *rq, unsigned long delay_ms) |
---|
233 | | -{ |
---|
234 | | - struct request_queue *q = rq->q; |
---|
235 | | - unsigned long flags; |
---|
236 | | - |
---|
237 | | - spin_lock_irqsave(q->queue_lock, flags); |
---|
238 | | - blk_requeue_request(q, rq); |
---|
239 | | - blk_delay_queue(q, delay_ms); |
---|
240 | | - spin_unlock_irqrestore(q->queue_lock, flags); |
---|
| 167 | + blk_mq_end_request(rq, error); |
---|
| 168 | + rq_completed(md); |
---|
241 | 169 | } |
---|
242 | 170 | |
---|
243 | 171 | static void __dm_mq_kick_requeue_list(struct request_queue *q, unsigned long msecs) |
---|
.. | .. |
---|
247 | 175 | |
---|
248 | 176 | void dm_mq_kick_requeue_list(struct mapped_device *md) |
---|
249 | 177 | { |
---|
250 | | - __dm_mq_kick_requeue_list(dm_get_md_queue(md), 0); |
---|
| 178 | + __dm_mq_kick_requeue_list(md->queue, 0); |
---|
251 | 179 | } |
---|
252 | 180 | EXPORT_SYMBOL(dm_mq_kick_requeue_list); |
---|
253 | 181 | |
---|
.. | .. |
---|
261 | 189 | { |
---|
262 | 190 | struct mapped_device *md = tio->md; |
---|
263 | 191 | struct request *rq = tio->orig; |
---|
264 | | - int rw = rq_data_dir(rq); |
---|
265 | 192 | unsigned long delay_ms = delay_requeue ? 100 : 0; |
---|
266 | 193 | |
---|
267 | 194 | rq_end_stats(md, rq); |
---|
.. | .. |
---|
270 | 197 | tio->ti->type->release_clone_rq(tio->clone, NULL); |
---|
271 | 198 | } |
---|
272 | 199 | |
---|
273 | | - if (!rq->q->mq_ops) |
---|
274 | | - dm_old_requeue_request(rq, delay_ms); |
---|
275 | | - else |
---|
276 | | - dm_mq_delay_requeue_request(rq, delay_ms); |
---|
277 | | - |
---|
278 | | - rq_completed(md, rw, false); |
---|
| 200 | + dm_mq_delay_requeue_request(rq, delay_ms); |
---|
| 201 | + rq_completed(md); |
---|
279 | 202 | } |
---|
280 | 203 | |
---|
281 | 204 | static void dm_done(struct request *clone, blk_status_t error, bool mapped) |
---|
.. | .. |
---|
333 | 256 | bool mapped = true; |
---|
334 | 257 | struct dm_rq_target_io *tio = tio_from_request(rq); |
---|
335 | 258 | struct request *clone = tio->clone; |
---|
336 | | - int rw; |
---|
337 | 259 | |
---|
338 | 260 | if (!clone) { |
---|
339 | 261 | struct mapped_device *md = tio->md; |
---|
340 | 262 | |
---|
341 | 263 | rq_end_stats(md, rq); |
---|
342 | | - rw = rq_data_dir(rq); |
---|
343 | | - if (!rq->q->mq_ops) |
---|
344 | | - blk_end_request_all(rq, tio->error); |
---|
345 | | - else |
---|
346 | | - blk_mq_end_request(rq, tio->error); |
---|
347 | | - rq_completed(md, rw, false); |
---|
| 264 | + blk_mq_end_request(rq, tio->error); |
---|
| 265 | + rq_completed(md); |
---|
348 | 266 | return; |
---|
349 | 267 | } |
---|
350 | 268 | |
---|
.. | .. |
---|
363 | 281 | struct dm_rq_target_io *tio = tio_from_request(rq); |
---|
364 | 282 | |
---|
365 | 283 | tio->error = error; |
---|
366 | | - if (!rq->q->mq_ops) |
---|
367 | | - blk_complete_request(rq); |
---|
368 | | - else |
---|
| 284 | + if (likely(!blk_should_fake_timeout(rq->q))) |
---|
369 | 285 | blk_mq_complete_request(rq); |
---|
370 | 286 | } |
---|
371 | 287 | |
---|
.. | .. |
---|
373 | 289 | * Complete the not-mapped clone and the original request with the error status |
---|
374 | 290 | * through softirq context. |
---|
375 | 291 | * Target's rq_end_io() function isn't called. |
---|
376 | | - * This may be used when the target's map_rq() or clone_and_map_rq() functions fail. |
---|
| 292 | + * This may be used when the target's clone_and_map_rq() function fails. |
---|
377 | 293 | */ |
---|
378 | 294 | static void dm_kill_unmapped_request(struct request *rq, blk_status_t error) |
---|
379 | 295 | { |
---|
.. | .. |
---|
381 | 297 | dm_complete_request(rq, error); |
---|
382 | 298 | } |
---|
383 | 299 | |
---|
384 | | -/* |
---|
385 | | - * Called with the clone's queue lock held (in the case of .request_fn) |
---|
386 | | - */ |
---|
387 | 300 | static void end_clone_request(struct request *clone, blk_status_t error) |
---|
388 | 301 | { |
---|
389 | 302 | struct dm_rq_target_io *tio = clone->end_io_data; |
---|
390 | 303 | |
---|
391 | | - /* |
---|
392 | | - * Actual request completion is done in a softirq context which doesn't |
---|
393 | | - * hold the clone's queue lock. Otherwise, deadlock could occur because: |
---|
394 | | - * - another request may be submitted by the upper level driver |
---|
395 | | - * of the stacking during the completion |
---|
396 | | - * - the submission which requires queue lock may be done |
---|
397 | | - * against this clone's queue |
---|
398 | | - */ |
---|
399 | 304 | dm_complete_request(tio->orig, error); |
---|
400 | 305 | } |
---|
401 | 306 | |
---|
.. | .. |
---|
446 | 351 | return 0; |
---|
447 | 352 | } |
---|
448 | 353 | |
---|
449 | | -static void map_tio_request(struct kthread_work *work); |
---|
450 | | - |
---|
451 | 354 | static void init_tio(struct dm_rq_target_io *tio, struct request *rq, |
---|
452 | 355 | struct mapped_device *md) |
---|
453 | 356 | { |
---|
.. | .. |
---|
464 | 367 | */ |
---|
465 | 368 | if (!md->init_tio_pdu) |
---|
466 | 369 | memset(&tio->info, 0, sizeof(tio->info)); |
---|
467 | | - if (md->kworker_task) |
---|
468 | | - kthread_init_work(&tio->work, map_tio_request); |
---|
469 | 370 | } |
---|
470 | 371 | |
---|
471 | 372 | /* |
---|
.. | .. |
---|
484 | 385 | blk_status_t ret; |
---|
485 | 386 | |
---|
486 | 387 | r = ti->type->clone_and_map_rq(ti, rq, &tio->info, &clone); |
---|
487 | | -check_again: |
---|
488 | 388 | switch (r) { |
---|
489 | 389 | case DM_MAPIO_SUBMITTED: |
---|
490 | 390 | /* The target has taken the I/O to submit by itself later */ |
---|
.. | .. |
---|
505 | 405 | blk_mq_cleanup_rq(clone); |
---|
506 | 406 | tio->ti->type->release_clone_rq(clone, &tio->info); |
---|
507 | 407 | tio->clone = NULL; |
---|
508 | | - if (!rq->q->mq_ops) |
---|
509 | | - r = DM_MAPIO_DELAY_REQUEUE; |
---|
510 | | - else |
---|
511 | | - r = DM_MAPIO_REQUEUE; |
---|
512 | | - goto check_again; |
---|
| 408 | + return DM_MAPIO_REQUEUE; |
---|
513 | 409 | } |
---|
514 | 410 | break; |
---|
515 | 411 | case DM_MAPIO_REQUEUE: |
---|
.. | .. |
---|
531 | 427 | return r; |
---|
532 | 428 | } |
---|
533 | 429 | |
---|
| 430 | +/* DEPRECATED: previously used for request-based merge heuristic in dm_request_fn() */ |
---|
| 431 | +ssize_t dm_attr_rq_based_seq_io_merge_deadline_show(struct mapped_device *md, char *buf) |
---|
| 432 | +{ |
---|
| 433 | + return sprintf(buf, "%u\n", 0); |
---|
| 434 | +} |
---|
| 435 | + |
---|
| 436 | +ssize_t dm_attr_rq_based_seq_io_merge_deadline_store(struct mapped_device *md, |
---|
| 437 | + const char *buf, size_t count) |
---|
| 438 | +{ |
---|
| 439 | + return count; |
---|
| 440 | +} |
---|
| 441 | + |
---|
534 | 442 | static void dm_start_request(struct mapped_device *md, struct request *orig) |
---|
535 | 443 | { |
---|
536 | | - if (!orig->q->mq_ops) |
---|
537 | | - blk_start_request(orig); |
---|
538 | | - else |
---|
539 | | - blk_mq_start_request(orig); |
---|
540 | | - atomic_inc(&md->pending[rq_data_dir(orig)]); |
---|
541 | | - |
---|
542 | | - if (md->seq_rq_merge_deadline_usecs) { |
---|
543 | | - md->last_rq_pos = rq_end_sector(orig); |
---|
544 | | - md->last_rq_rw = rq_data_dir(orig); |
---|
545 | | - md->last_rq_start_time = ktime_get(); |
---|
546 | | - } |
---|
| 444 | + blk_mq_start_request(orig); |
---|
547 | 445 | |
---|
548 | 446 | if (unlikely(dm_stats_used(&md->stats))) { |
---|
549 | 447 | struct dm_rq_target_io *tio = tio_from_request(orig); |
---|
.. | .. |
---|
564 | 462 | dm_get(md); |
---|
565 | 463 | } |
---|
566 | 464 | |
---|
567 | | -static int __dm_rq_init_rq(struct mapped_device *md, struct request *rq) |
---|
| 465 | +static int dm_mq_init_request(struct blk_mq_tag_set *set, struct request *rq, |
---|
| 466 | + unsigned int hctx_idx, unsigned int numa_node) |
---|
568 | 467 | { |
---|
| 468 | + struct mapped_device *md = set->driver_data; |
---|
569 | 469 | struct dm_rq_target_io *tio = blk_mq_rq_to_pdu(rq); |
---|
570 | 470 | |
---|
571 | 471 | /* |
---|
.. | .. |
---|
582 | 482 | return 0; |
---|
583 | 483 | } |
---|
584 | 484 | |
---|
585 | | -static int dm_rq_init_rq(struct request_queue *q, struct request *rq, gfp_t gfp) |
---|
586 | | -{ |
---|
587 | | - return __dm_rq_init_rq(q->rq_alloc_data, rq); |
---|
588 | | -} |
---|
589 | | - |
---|
590 | | -static void map_tio_request(struct kthread_work *work) |
---|
591 | | -{ |
---|
592 | | - struct dm_rq_target_io *tio = container_of(work, struct dm_rq_target_io, work); |
---|
593 | | - |
---|
594 | | - if (map_request(tio) == DM_MAPIO_REQUEUE) |
---|
595 | | - dm_requeue_original_request(tio, false); |
---|
596 | | -} |
---|
597 | | - |
---|
598 | | -ssize_t dm_attr_rq_based_seq_io_merge_deadline_show(struct mapped_device *md, char *buf) |
---|
599 | | -{ |
---|
600 | | - return sprintf(buf, "%u\n", md->seq_rq_merge_deadline_usecs); |
---|
601 | | -} |
---|
602 | | - |
---|
603 | | -#define MAX_SEQ_RQ_MERGE_DEADLINE_USECS 100000 |
---|
604 | | - |
---|
605 | | -ssize_t dm_attr_rq_based_seq_io_merge_deadline_store(struct mapped_device *md, |
---|
606 | | - const char *buf, size_t count) |
---|
607 | | -{ |
---|
608 | | - unsigned deadline; |
---|
609 | | - |
---|
610 | | - if (dm_get_md_type(md) != DM_TYPE_REQUEST_BASED) |
---|
611 | | - return count; |
---|
612 | | - |
---|
613 | | - if (kstrtouint(buf, 10, &deadline)) |
---|
614 | | - return -EINVAL; |
---|
615 | | - |
---|
616 | | - if (deadline > MAX_SEQ_RQ_MERGE_DEADLINE_USECS) |
---|
617 | | - deadline = MAX_SEQ_RQ_MERGE_DEADLINE_USECS; |
---|
618 | | - |
---|
619 | | - md->seq_rq_merge_deadline_usecs = deadline; |
---|
620 | | - |
---|
621 | | - return count; |
---|
622 | | -} |
---|
623 | | - |
---|
624 | | -static bool dm_old_request_peeked_before_merge_deadline(struct mapped_device *md) |
---|
625 | | -{ |
---|
626 | | - ktime_t kt_deadline; |
---|
627 | | - |
---|
628 | | - if (!md->seq_rq_merge_deadline_usecs) |
---|
629 | | - return false; |
---|
630 | | - |
---|
631 | | - kt_deadline = ns_to_ktime((u64)md->seq_rq_merge_deadline_usecs * NSEC_PER_USEC); |
---|
632 | | - kt_deadline = ktime_add_safe(md->last_rq_start_time, kt_deadline); |
---|
633 | | - |
---|
634 | | - return !ktime_after(ktime_get(), kt_deadline); |
---|
635 | | -} |
---|
636 | | - |
---|
637 | | -/* |
---|
638 | | - * q->request_fn for old request-based dm. |
---|
639 | | - * Called with the queue lock held. |
---|
640 | | - */ |
---|
641 | | -static void dm_old_request_fn(struct request_queue *q) |
---|
642 | | -{ |
---|
643 | | - struct mapped_device *md = q->queuedata; |
---|
644 | | - struct dm_target *ti = md->immutable_target; |
---|
645 | | - struct request *rq; |
---|
646 | | - struct dm_rq_target_io *tio; |
---|
647 | | - sector_t pos = 0; |
---|
648 | | - |
---|
649 | | - if (unlikely(!ti)) { |
---|
650 | | - int srcu_idx; |
---|
651 | | - struct dm_table *map = dm_get_live_table(md, &srcu_idx); |
---|
652 | | - |
---|
653 | | - if (unlikely(!map)) { |
---|
654 | | - dm_put_live_table(md, srcu_idx); |
---|
655 | | - return; |
---|
656 | | - } |
---|
657 | | - ti = dm_table_find_target(map, pos); |
---|
658 | | - dm_put_live_table(md, srcu_idx); |
---|
659 | | - } |
---|
660 | | - |
---|
661 | | - /* |
---|
662 | | - * For suspend, check blk_queue_stopped() and increment |
---|
663 | | - * ->pending within a single queue_lock not to increment the |
---|
664 | | - * number of in-flight I/Os after the queue is stopped in |
---|
665 | | - * dm_suspend(). |
---|
666 | | - */ |
---|
667 | | - while (!blk_queue_stopped(q)) { |
---|
668 | | - rq = blk_peek_request(q); |
---|
669 | | - if (!rq) |
---|
670 | | - return; |
---|
671 | | - |
---|
672 | | - /* always use block 0 to find the target for flushes for now */ |
---|
673 | | - pos = 0; |
---|
674 | | - if (req_op(rq) != REQ_OP_FLUSH) |
---|
675 | | - pos = blk_rq_pos(rq); |
---|
676 | | - |
---|
677 | | - if ((dm_old_request_peeked_before_merge_deadline(md) && |
---|
678 | | - md_in_flight(md) && rq->bio && !bio_multiple_segments(rq->bio) && |
---|
679 | | - md->last_rq_pos == pos && md->last_rq_rw == rq_data_dir(rq)) || |
---|
680 | | - (ti->type->busy && ti->type->busy(ti))) { |
---|
681 | | - blk_delay_queue(q, 10); |
---|
682 | | - return; |
---|
683 | | - } |
---|
684 | | - |
---|
685 | | - dm_start_request(md, rq); |
---|
686 | | - |
---|
687 | | - tio = tio_from_request(rq); |
---|
688 | | - init_tio(tio, rq, md); |
---|
689 | | - /* Establish tio->ti before queuing work (map_tio_request) */ |
---|
690 | | - tio->ti = ti; |
---|
691 | | - kthread_queue_work(&md->kworker, &tio->work); |
---|
692 | | - BUG_ON(!irqs_disabled()); |
---|
693 | | - } |
---|
694 | | -} |
---|
695 | | - |
---|
696 | | -/* |
---|
697 | | - * Fully initialize a .request_fn request-based queue. |
---|
698 | | - */ |
---|
699 | | -int dm_old_init_request_queue(struct mapped_device *md, struct dm_table *t) |
---|
700 | | -{ |
---|
701 | | - struct dm_target *immutable_tgt; |
---|
702 | | - |
---|
703 | | - /* Fully initialize the queue */ |
---|
704 | | - md->queue->cmd_size = sizeof(struct dm_rq_target_io); |
---|
705 | | - md->queue->rq_alloc_data = md; |
---|
706 | | - md->queue->request_fn = dm_old_request_fn; |
---|
707 | | - md->queue->init_rq_fn = dm_rq_init_rq; |
---|
708 | | - |
---|
709 | | - immutable_tgt = dm_table_get_immutable_target(t); |
---|
710 | | - if (immutable_tgt && immutable_tgt->per_io_data_size) { |
---|
711 | | - /* any target-specific per-io data is immediately after the tio */ |
---|
712 | | - md->queue->cmd_size += immutable_tgt->per_io_data_size; |
---|
713 | | - md->init_tio_pdu = true; |
---|
714 | | - } |
---|
715 | | - if (blk_init_allocated_queue(md->queue) < 0) |
---|
716 | | - return -EINVAL; |
---|
717 | | - |
---|
718 | | - /* disable dm_old_request_fn's merge heuristic by default */ |
---|
719 | | - md->seq_rq_merge_deadline_usecs = 0; |
---|
720 | | - |
---|
721 | | - blk_queue_softirq_done(md->queue, dm_softirq_done); |
---|
722 | | - |
---|
723 | | - /* Initialize the request-based DM worker thread */ |
---|
724 | | - kthread_init_worker(&md->kworker); |
---|
725 | | - md->kworker_task = kthread_run(kthread_worker_fn, &md->kworker, |
---|
726 | | - "kdmwork-%s", dm_device_name(md)); |
---|
727 | | - if (IS_ERR(md->kworker_task)) { |
---|
728 | | - int error = PTR_ERR(md->kworker_task); |
---|
729 | | - md->kworker_task = NULL; |
---|
730 | | - return error; |
---|
731 | | - } |
---|
732 | | - |
---|
733 | | - return 0; |
---|
734 | | -} |
---|
735 | | - |
---|
736 | | -static int dm_mq_init_request(struct blk_mq_tag_set *set, struct request *rq, |
---|
737 | | - unsigned int hctx_idx, unsigned int numa_node) |
---|
738 | | -{ |
---|
739 | | - return __dm_rq_init_rq(set->driver_data, rq); |
---|
740 | | -} |
---|
741 | | - |
---|
742 | 485 | static blk_status_t dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx, |
---|
743 | 486 | const struct blk_mq_queue_data *bd) |
---|
744 | 487 | { |
---|
.. | .. |
---|
749 | 492 | |
---|
750 | 493 | if (unlikely(!ti)) { |
---|
751 | 494 | int srcu_idx; |
---|
752 | | - struct dm_table *map = dm_get_live_table(md, &srcu_idx); |
---|
| 495 | + struct dm_table *map; |
---|
753 | 496 | |
---|
| 497 | + map = dm_get_live_table(md, &srcu_idx); |
---|
| 498 | + if (unlikely(!map)) { |
---|
| 499 | + dm_put_live_table(md, srcu_idx); |
---|
| 500 | + return BLK_STS_RESOURCE; |
---|
| 501 | + } |
---|
754 | 502 | ti = dm_table_find_target(map, 0); |
---|
755 | 503 | dm_put_live_table(md, srcu_idx); |
---|
756 | 504 | } |
---|
.. | .. |
---|
772 | 520 | if (map_request(tio) == DM_MAPIO_REQUEUE) { |
---|
773 | 521 | /* Undo dm_start_request() before requeuing */ |
---|
774 | 522 | rq_end_stats(md, rq); |
---|
775 | | - rq_completed(md, rq_data_dir(rq), false); |
---|
| 523 | + rq_completed(md); |
---|
776 | 524 | return BLK_STS_RESOURCE; |
---|
777 | 525 | } |
---|
778 | 526 | |
---|
.. | .. |
---|
791 | 539 | struct dm_target *immutable_tgt; |
---|
792 | 540 | int err; |
---|
793 | 541 | |
---|
794 | | - if (!dm_table_all_blk_mq_devices(t)) { |
---|
795 | | - DMERR("request-based dm-mq may only be stacked on blk-mq device(s)"); |
---|
796 | | - return -EINVAL; |
---|
797 | | - } |
---|
798 | | - |
---|
799 | 542 | md->tag_set = kzalloc_node(sizeof(struct blk_mq_tag_set), GFP_KERNEL, md->numa_node_id); |
---|
800 | 543 | if (!md->tag_set) |
---|
801 | 544 | return -ENOMEM; |
---|
.. | .. |
---|
803 | 546 | md->tag_set->ops = &dm_mq_ops; |
---|
804 | 547 | md->tag_set->queue_depth = dm_get_blk_mq_queue_depth(); |
---|
805 | 548 | md->tag_set->numa_node = md->numa_node_id; |
---|
806 | | - md->tag_set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE; |
---|
| 549 | + md->tag_set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_STACKING; |
---|
807 | 550 | md->tag_set->nr_hw_queues = dm_get_blk_mq_nr_hw_queues(); |
---|
808 | 551 | md->tag_set->driver_data = md; |
---|
809 | 552 | |
---|
.. | .. |
---|
819 | 562 | if (err) |
---|
820 | 563 | goto out_kfree_tag_set; |
---|
821 | 564 | |
---|
822 | | - q = blk_mq_init_allocated_queue(md->tag_set, md->queue); |
---|
| 565 | + q = blk_mq_init_allocated_queue(md->tag_set, md->queue, true); |
---|
823 | 566 | if (IS_ERR(q)) { |
---|
824 | 567 | err = PTR_ERR(q); |
---|
825 | 568 | goto out_tag_set; |
---|
.. | .. |
---|
848 | 591 | module_param(reserved_rq_based_ios, uint, S_IRUGO | S_IWUSR); |
---|
849 | 592 | MODULE_PARM_DESC(reserved_rq_based_ios, "Reserved IOs in request-based mempools"); |
---|
850 | 593 | |
---|
| 594 | +/* Unused, but preserved for userspace compatibility */ |
---|
| 595 | +static bool use_blk_mq = true; |
---|
851 | 596 | module_param(use_blk_mq, bool, S_IRUGO | S_IWUSR); |
---|
852 | 597 | MODULE_PARM_DESC(use_blk_mq, "Use block multiqueue for request-based DM devices"); |
---|
853 | 598 | |
---|