2 * Copyright (C) 2016 Red Hat, Inc. All rights reserved.
4 * This file is released under the GPL.
10 #include <linux/elevator.h> /* for rq_end_sector() */
11 #include <linux/blk-mq.h>
13 #define DM_MSG_PREFIX "core-rq"
15 #define DM_MQ_NR_HW_QUEUES 1
16 #define DM_MQ_QUEUE_DEPTH 2048
17 static unsigned dm_mq_nr_hw_queues
= DM_MQ_NR_HW_QUEUES
;
18 static unsigned dm_mq_queue_depth
= DM_MQ_QUEUE_DEPTH
;
21 * Request-based DM's mempools' reserved IOs set by the user.
23 #define RESERVED_REQUEST_BASED_IOS 256
24 static unsigned reserved_rq_based_ios
= RESERVED_REQUEST_BASED_IOS
;
26 static bool use_blk_mq
= IS_ENABLED(CONFIG_DM_MQ_DEFAULT
);
28 bool dm_use_blk_mq_default(void)
33 bool dm_use_blk_mq(struct mapped_device
*md
)
35 return md
->use_blk_mq
;
37 EXPORT_SYMBOL_GPL(dm_use_blk_mq
);
39 unsigned dm_get_reserved_rq_based_ios(void)
41 return __dm_get_module_param(&reserved_rq_based_ios
,
42 RESERVED_REQUEST_BASED_IOS
, DM_RESERVED_MAX_IOS
);
44 EXPORT_SYMBOL_GPL(dm_get_reserved_rq_based_ios
);
46 static unsigned dm_get_blk_mq_nr_hw_queues(void)
48 return __dm_get_module_param(&dm_mq_nr_hw_queues
, 1, 32);
51 static unsigned dm_get_blk_mq_queue_depth(void)
53 return __dm_get_module_param(&dm_mq_queue_depth
,
54 DM_MQ_QUEUE_DEPTH
, BLK_MQ_MAX_DEPTH
);
57 int dm_request_based(struct mapped_device
*md
)
59 return queue_is_rq_based(md
->queue
);
62 static void dm_old_start_queue(struct request_queue
*q
)
66 spin_lock_irqsave(q
->queue_lock
, flags
);
67 if (blk_queue_stopped(q
))
69 spin_unlock_irqrestore(q
->queue_lock
, flags
);
72 static void dm_mq_start_queue(struct request_queue
*q
)
74 blk_mq_unquiesce_queue(q
);
75 blk_mq_kick_requeue_list(q
);
78 void dm_start_queue(struct request_queue
*q
)
81 dm_old_start_queue(q
);
86 static void dm_old_stop_queue(struct request_queue
*q
)
90 spin_lock_irqsave(q
->queue_lock
, flags
);
91 if (!blk_queue_stopped(q
))
93 spin_unlock_irqrestore(q
->queue_lock
, flags
);
96 static void dm_mq_stop_queue(struct request_queue
*q
)
98 if (blk_mq_queue_stopped(q
))
101 blk_mq_quiesce_queue(q
);
104 void dm_stop_queue(struct request_queue
*q
)
107 dm_old_stop_queue(q
);
113 * Partial completion handling for request-based dm
115 static void end_clone_bio(struct bio
*clone
)
117 struct dm_rq_clone_bio_info
*info
=
118 container_of(clone
, struct dm_rq_clone_bio_info
, clone
);
119 struct dm_rq_target_io
*tio
= info
->tio
;
120 unsigned int nr_bytes
= info
->orig
->bi_iter
.bi_size
;
121 blk_status_t error
= clone
->bi_status
;
122 bool is_last
= !clone
->bi_next
;
128 * An error has already been detected on the request.
129 * Once error occurred, just let clone->end_io() handle
135 * Don't notice the error to the upper layer yet.
136 * The error handling decision is made by the target driver,
137 * when the request is completed.
144 * I/O for the bio successfully completed.
145 * Notice the data completion to the upper layer.
147 tio
->completed
+= nr_bytes
;
150 * Update the original request.
151 * Do not use blk_end_request() here, because it may complete
152 * the original request before the clone, and break the ordering.
156 blk_update_request(tio
->orig
, BLK_STS_OK
, tio
->completed
);
159 static struct dm_rq_target_io
*tio_from_request(struct request
*rq
)
161 return blk_mq_rq_to_pdu(rq
);
164 static void rq_end_stats(struct mapped_device
*md
, struct request
*orig
)
166 if (unlikely(dm_stats_used(&md
->stats
))) {
167 struct dm_rq_target_io
*tio
= tio_from_request(orig
);
168 tio
->duration_jiffies
= jiffies
- tio
->duration_jiffies
;
169 dm_stats_account_io(&md
->stats
, rq_data_dir(orig
),
170 blk_rq_pos(orig
), tio
->n_sectors
, true,
171 tio
->duration_jiffies
, &tio
->stats_aux
);
176 * Don't touch any member of the md after calling this function because
177 * the md may be freed in dm_put() at the end of this function.
178 * Or do dm_get() before calling this function and dm_put() later.
180 static void rq_completed(struct mapped_device
*md
, int rw
, bool run_queue
)
182 struct request_queue
*q
= md
->queue
;
185 atomic_dec(&md
->pending
[rw
]);
187 /* nudge anyone waiting on suspend queue */
188 if (!md_in_flight(md
))
192 * Run this off this callpath, as drivers could invoke end_io while
193 * inside their request_fn (and holding the queue lock). Calling
194 * back into ->request_fn() could deadlock attempting to grab the
197 if (!q
->mq_ops
&& run_queue
) {
198 spin_lock_irqsave(q
->queue_lock
, flags
);
199 blk_run_queue_async(q
);
200 spin_unlock_irqrestore(q
->queue_lock
, flags
);
204 * dm_put() must be at the end of this function. See the comment above
210 * Complete the clone and the original request.
211 * Must be called without clone's queue lock held,
212 * see end_clone_request() for more details.
214 static void dm_end_request(struct request
*clone
, blk_status_t error
)
216 int rw
= rq_data_dir(clone
);
217 struct dm_rq_target_io
*tio
= clone
->end_io_data
;
218 struct mapped_device
*md
= tio
->md
;
219 struct request
*rq
= tio
->orig
;
221 blk_rq_unprep_clone(clone
);
222 tio
->ti
->type
->release_clone_rq(clone
, NULL
);
224 rq_end_stats(md
, rq
);
226 blk_end_request_all(rq
, error
);
228 blk_mq_end_request(rq
, error
);
229 rq_completed(md
, rw
, true);
233 * Requeue the original request of a clone.
235 static void dm_old_requeue_request(struct request
*rq
, unsigned long delay_ms
)
237 struct request_queue
*q
= rq
->q
;
240 spin_lock_irqsave(q
->queue_lock
, flags
);
241 blk_requeue_request(q
, rq
);
242 blk_delay_queue(q
, delay_ms
);
243 spin_unlock_irqrestore(q
->queue_lock
, flags
);
246 static void __dm_mq_kick_requeue_list(struct request_queue
*q
, unsigned long msecs
)
248 blk_mq_delay_kick_requeue_list(q
, msecs
);
251 void dm_mq_kick_requeue_list(struct mapped_device
*md
)
253 __dm_mq_kick_requeue_list(dm_get_md_queue(md
), 0);
255 EXPORT_SYMBOL(dm_mq_kick_requeue_list
);
257 static void dm_mq_delay_requeue_request(struct request
*rq
, unsigned long msecs
)
259 blk_mq_requeue_request(rq
, false);
260 __dm_mq_kick_requeue_list(rq
->q
, msecs
);
263 static void dm_requeue_original_request(struct dm_rq_target_io
*tio
, bool delay_requeue
)
265 struct mapped_device
*md
= tio
->md
;
266 struct request
*rq
= tio
->orig
;
267 int rw
= rq_data_dir(rq
);
268 unsigned long delay_ms
= delay_requeue
? 100 : 0;
270 rq_end_stats(md
, rq
);
272 blk_rq_unprep_clone(tio
->clone
);
273 tio
->ti
->type
->release_clone_rq(tio
->clone
, NULL
);
277 dm_old_requeue_request(rq
, delay_ms
);
279 dm_mq_delay_requeue_request(rq
, delay_ms
);
281 rq_completed(md
, rw
, false);
284 static void dm_done(struct request
*clone
, blk_status_t error
, bool mapped
)
286 int r
= DM_ENDIO_DONE
;
287 struct dm_rq_target_io
*tio
= clone
->end_io_data
;
288 dm_request_endio_fn rq_end_io
= NULL
;
291 rq_end_io
= tio
->ti
->type
->rq_end_io
;
293 if (mapped
&& rq_end_io
)
294 r
= rq_end_io(tio
->ti
, clone
, error
, &tio
->info
);
297 if (unlikely(error
== BLK_STS_TARGET
)) {
298 if (req_op(clone
) == REQ_OP_DISCARD
&&
299 !clone
->q
->limits
.max_discard_sectors
)
300 disable_discard(tio
->md
);
301 else if (req_op(clone
) == REQ_OP_WRITE_SAME
&&
302 !clone
->q
->limits
.max_write_same_sectors
)
303 disable_write_same(tio
->md
);
304 else if (req_op(clone
) == REQ_OP_WRITE_ZEROES
&&
305 !clone
->q
->limits
.max_write_zeroes_sectors
)
306 disable_write_zeroes(tio
->md
);
311 /* The target wants to complete the I/O */
312 dm_end_request(clone
, error
);
314 case DM_ENDIO_INCOMPLETE
:
315 /* The target will handle the I/O */
317 case DM_ENDIO_REQUEUE
:
318 /* The target wants to requeue the I/O */
319 dm_requeue_original_request(tio
, false);
321 case DM_ENDIO_DELAY_REQUEUE
:
322 /* The target wants to requeue the I/O after a delay */
323 dm_requeue_original_request(tio
, true);
326 DMWARN("unimplemented target endio return value: %d", r
);
332 * Request completion handler for request-based dm
334 static void dm_softirq_done(struct request
*rq
)
337 struct dm_rq_target_io
*tio
= tio_from_request(rq
);
338 struct request
*clone
= tio
->clone
;
342 struct mapped_device
*md
= tio
->md
;
344 rq_end_stats(md
, rq
);
345 rw
= rq_data_dir(rq
);
347 blk_end_request_all(rq
, tio
->error
);
349 blk_mq_end_request(rq
, tio
->error
);
350 rq_completed(md
, rw
, false);
354 if (rq
->rq_flags
& RQF_FAILED
)
357 dm_done(clone
, tio
->error
, mapped
);
361 * Complete the clone and the original request with the error status
362 * through softirq context.
364 static void dm_complete_request(struct request
*rq
, blk_status_t error
)
366 struct dm_rq_target_io
*tio
= tio_from_request(rq
);
370 blk_complete_request(rq
);
372 blk_mq_complete_request(rq
);
376 * Complete the not-mapped clone and the original request with the error status
377 * through softirq context.
378 * Target's rq_end_io() function isn't called.
379 * This may be used when the target's map_rq() or clone_and_map_rq() functions fail.
381 static void dm_kill_unmapped_request(struct request
*rq
, blk_status_t error
)
383 rq
->rq_flags
|= RQF_FAILED
;
384 dm_complete_request(rq
, error
);
388 * Called with the clone's queue lock held (in the case of .request_fn)
390 static void end_clone_request(struct request
*clone
, blk_status_t error
)
392 struct dm_rq_target_io
*tio
= clone
->end_io_data
;
395 * Actual request completion is done in a softirq context which doesn't
396 * hold the clone's queue lock. Otherwise, deadlock could occur because:
397 * - another request may be submitted by the upper level driver
398 * of the stacking during the completion
399 * - the submission which requires queue lock may be done
400 * against this clone's queue
402 dm_complete_request(tio
->orig
, error
);
405 static blk_status_t
dm_dispatch_clone_request(struct request
*clone
, struct request
*rq
)
409 if (blk_queue_io_stat(clone
->q
))
410 clone
->rq_flags
|= RQF_IO_STAT
;
412 clone
->start_time_ns
= ktime_get_ns();
413 r
= blk_insert_cloned_request(clone
->q
, clone
);
414 if (r
!= BLK_STS_OK
&& r
!= BLK_STS_RESOURCE
&& r
!= BLK_STS_DEV_RESOURCE
)
415 /* must complete clone in terms of original request */
416 dm_complete_request(rq
, r
);
420 static int dm_rq_bio_constructor(struct bio
*bio
, struct bio
*bio_orig
,
423 struct dm_rq_target_io
*tio
= data
;
424 struct dm_rq_clone_bio_info
*info
=
425 container_of(bio
, struct dm_rq_clone_bio_info
, clone
);
427 info
->orig
= bio_orig
;
429 bio
->bi_end_io
= end_clone_bio
;
434 static int setup_clone(struct request
*clone
, struct request
*rq
,
435 struct dm_rq_target_io
*tio
, gfp_t gfp_mask
)
439 r
= blk_rq_prep_clone(clone
, rq
, &tio
->md
->bs
, gfp_mask
,
440 dm_rq_bio_constructor
, tio
);
444 clone
->end_io
= end_clone_request
;
445 clone
->end_io_data
= tio
;
452 static void map_tio_request(struct kthread_work
*work
);
454 static void init_tio(struct dm_rq_target_io
*tio
, struct request
*rq
,
455 struct mapped_device
*md
)
464 * Avoid initializing info for blk-mq; it passes
465 * target-specific data through info.ptr
466 * (see: dm_mq_init_request)
468 if (!md
->init_tio_pdu
)
469 memset(&tio
->info
, 0, sizeof(tio
->info
));
470 if (md
->kworker_task
)
471 kthread_init_work(&tio
->work
, map_tio_request
);
476 * DM_MAPIO_* : the request has been processed as indicated
477 * DM_MAPIO_REQUEUE : the original request needs to be immediately requeued
478 * < 0 : the request was completed due to failure
480 static int map_request(struct dm_rq_target_io
*tio
)
483 struct dm_target
*ti
= tio
->ti
;
484 struct mapped_device
*md
= tio
->md
;
485 struct request
*rq
= tio
->orig
;
486 struct request
*clone
= NULL
;
489 r
= ti
->type
->clone_and_map_rq(ti
, rq
, &tio
->info
, &clone
);
492 case DM_MAPIO_SUBMITTED
:
493 /* The target has taken the I/O to submit by itself later */
495 case DM_MAPIO_REMAPPED
:
496 if (setup_clone(clone
, rq
, tio
, GFP_ATOMIC
)) {
498 ti
->type
->release_clone_rq(clone
, &tio
->info
);
499 return DM_MAPIO_REQUEUE
;
502 /* The target has remapped the I/O so dispatch it */
503 trace_block_rq_remap(clone
->q
, clone
, disk_devt(dm_disk(md
)),
505 ret
= dm_dispatch_clone_request(clone
, rq
);
506 if (ret
== BLK_STS_RESOURCE
|| ret
== BLK_STS_DEV_RESOURCE
) {
507 blk_rq_unprep_clone(clone
);
508 blk_mq_cleanup_rq(clone
);
509 tio
->ti
->type
->release_clone_rq(clone
, &tio
->info
);
512 r
= DM_MAPIO_DELAY_REQUEUE
;
514 r
= DM_MAPIO_REQUEUE
;
518 case DM_MAPIO_REQUEUE
:
519 /* The target wants to requeue the I/O */
521 case DM_MAPIO_DELAY_REQUEUE
:
522 /* The target wants to requeue the I/O after a delay */
523 dm_requeue_original_request(tio
, true);
526 /* The target wants to complete the I/O */
527 dm_kill_unmapped_request(rq
, BLK_STS_IOERR
);
530 DMWARN("unimplemented target map return value: %d", r
);
537 static void dm_start_request(struct mapped_device
*md
, struct request
*orig
)
539 if (!orig
->q
->mq_ops
)
540 blk_start_request(orig
);
542 blk_mq_start_request(orig
);
543 atomic_inc(&md
->pending
[rq_data_dir(orig
)]);
545 if (md
->seq_rq_merge_deadline_usecs
) {
546 md
->last_rq_pos
= rq_end_sector(orig
);
547 md
->last_rq_rw
= rq_data_dir(orig
);
548 md
->last_rq_start_time
= ktime_get();
551 if (unlikely(dm_stats_used(&md
->stats
))) {
552 struct dm_rq_target_io
*tio
= tio_from_request(orig
);
553 tio
->duration_jiffies
= jiffies
;
554 tio
->n_sectors
= blk_rq_sectors(orig
);
555 dm_stats_account_io(&md
->stats
, rq_data_dir(orig
),
556 blk_rq_pos(orig
), tio
->n_sectors
, false, 0,
561 * Hold the md reference here for the in-flight I/O.
562 * We can't rely on the reference count by device opener,
563 * because the device may be closed during the request completion
564 * when all bios are completed.
565 * See the comment in rq_completed() too.
570 static int __dm_rq_init_rq(struct mapped_device
*md
, struct request
*rq
)
572 struct dm_rq_target_io
*tio
= blk_mq_rq_to_pdu(rq
);
575 * Must initialize md member of tio, otherwise it won't
576 * be available in dm_mq_queue_rq.
580 if (md
->init_tio_pdu
) {
581 /* target-specific per-io data is immediately after the tio */
582 tio
->info
.ptr
= tio
+ 1;
588 static int dm_rq_init_rq(struct request_queue
*q
, struct request
*rq
, gfp_t gfp
)
590 return __dm_rq_init_rq(q
->rq_alloc_data
, rq
);
593 static void map_tio_request(struct kthread_work
*work
)
595 struct dm_rq_target_io
*tio
= container_of(work
, struct dm_rq_target_io
, work
);
597 if (map_request(tio
) == DM_MAPIO_REQUEUE
)
598 dm_requeue_original_request(tio
, false);
601 ssize_t
dm_attr_rq_based_seq_io_merge_deadline_show(struct mapped_device
*md
, char *buf
)
603 return sprintf(buf
, "%u\n", md
->seq_rq_merge_deadline_usecs
);
606 #define MAX_SEQ_RQ_MERGE_DEADLINE_USECS 100000
608 ssize_t
dm_attr_rq_based_seq_io_merge_deadline_store(struct mapped_device
*md
,
609 const char *buf
, size_t count
)
613 if (dm_get_md_type(md
) != DM_TYPE_REQUEST_BASED
)
616 if (kstrtouint(buf
, 10, &deadline
))
619 if (deadline
> MAX_SEQ_RQ_MERGE_DEADLINE_USECS
)
620 deadline
= MAX_SEQ_RQ_MERGE_DEADLINE_USECS
;
622 md
->seq_rq_merge_deadline_usecs
= deadline
;
627 static bool dm_old_request_peeked_before_merge_deadline(struct mapped_device
*md
)
631 if (!md
->seq_rq_merge_deadline_usecs
)
634 kt_deadline
= ns_to_ktime((u64
)md
->seq_rq_merge_deadline_usecs
* NSEC_PER_USEC
);
635 kt_deadline
= ktime_add_safe(md
->last_rq_start_time
, kt_deadline
);
637 return !ktime_after(ktime_get(), kt_deadline
);
641 * q->request_fn for old request-based dm.
642 * Called with the queue lock held.
644 static void dm_old_request_fn(struct request_queue
*q
)
646 struct mapped_device
*md
= q
->queuedata
;
647 struct dm_target
*ti
= md
->immutable_target
;
649 struct dm_rq_target_io
*tio
;
654 struct dm_table
*map
= dm_get_live_table(md
, &srcu_idx
);
656 if (unlikely(!map
)) {
657 dm_put_live_table(md
, srcu_idx
);
660 ti
= dm_table_find_target(map
, pos
);
661 dm_put_live_table(md
, srcu_idx
);
665 * For suspend, check blk_queue_stopped() and increment
666 * ->pending within a single queue_lock not to increment the
667 * number of in-flight I/Os after the queue is stopped in
670 while (!blk_queue_stopped(q
)) {
671 rq
= blk_peek_request(q
);
675 /* always use block 0 to find the target for flushes for now */
677 if (req_op(rq
) != REQ_OP_FLUSH
)
678 pos
= blk_rq_pos(rq
);
680 if ((dm_old_request_peeked_before_merge_deadline(md
) &&
681 md_in_flight(md
) && rq
->bio
&& !bio_multiple_segments(rq
->bio
) &&
682 md
->last_rq_pos
== pos
&& md
->last_rq_rw
== rq_data_dir(rq
)) ||
683 (ti
->type
->busy
&& ti
->type
->busy(ti
))) {
684 blk_delay_queue(q
, 10);
688 dm_start_request(md
, rq
);
690 tio
= tio_from_request(rq
);
691 init_tio(tio
, rq
, md
);
692 /* Establish tio->ti before queuing work (map_tio_request) */
694 kthread_queue_work(&md
->kworker
, &tio
->work
);
695 BUG_ON(!irqs_disabled());
700 * Fully initialize a .request_fn request-based queue.
702 int dm_old_init_request_queue(struct mapped_device
*md
, struct dm_table
*t
)
704 struct dm_target
*immutable_tgt
;
706 /* Fully initialize the queue */
707 md
->queue
->cmd_size
= sizeof(struct dm_rq_target_io
);
708 md
->queue
->rq_alloc_data
= md
;
709 md
->queue
->request_fn
= dm_old_request_fn
;
710 md
->queue
->init_rq_fn
= dm_rq_init_rq
;
712 immutable_tgt
= dm_table_get_immutable_target(t
);
713 if (immutable_tgt
&& immutable_tgt
->per_io_data_size
) {
714 /* any target-specific per-io data is immediately after the tio */
715 md
->queue
->cmd_size
+= immutable_tgt
->per_io_data_size
;
716 md
->init_tio_pdu
= true;
718 if (blk_init_allocated_queue(md
->queue
) < 0)
721 /* disable dm_old_request_fn's merge heuristic by default */
722 md
->seq_rq_merge_deadline_usecs
= 0;
724 blk_queue_softirq_done(md
->queue
, dm_softirq_done
);
726 /* Initialize the request-based DM worker thread */
727 kthread_init_worker(&md
->kworker
);
728 md
->kworker_task
= kthread_run(kthread_worker_fn
, &md
->kworker
,
729 "kdmwork-%s", dm_device_name(md
));
730 if (IS_ERR(md
->kworker_task
)) {
731 int error
= PTR_ERR(md
->kworker_task
);
732 md
->kworker_task
= NULL
;
739 static int dm_mq_init_request(struct blk_mq_tag_set
*set
, struct request
*rq
,
740 unsigned int hctx_idx
, unsigned int numa_node
)
742 return __dm_rq_init_rq(set
->driver_data
, rq
);
745 static blk_status_t
dm_mq_queue_rq(struct blk_mq_hw_ctx
*hctx
,
746 const struct blk_mq_queue_data
*bd
)
748 struct request
*rq
= bd
->rq
;
749 struct dm_rq_target_io
*tio
= blk_mq_rq_to_pdu(rq
);
750 struct mapped_device
*md
= tio
->md
;
751 struct dm_target
*ti
= md
->immutable_target
;
755 struct dm_table
*map
= dm_get_live_table(md
, &srcu_idx
);
757 ti
= dm_table_find_target(map
, 0);
758 dm_put_live_table(md
, srcu_idx
);
761 if (ti
->type
->busy
&& ti
->type
->busy(ti
))
762 return BLK_STS_RESOURCE
;
764 dm_start_request(md
, rq
);
766 /* Init tio using md established in .init_request */
767 init_tio(tio
, rq
, md
);
770 * Establish tio->ti before calling map_request().
774 /* Direct call is fine since .queue_rq allows allocations */
775 if (map_request(tio
) == DM_MAPIO_REQUEUE
) {
776 /* Undo dm_start_request() before requeuing */
777 rq_end_stats(md
, rq
);
778 rq_completed(md
, rq_data_dir(rq
), false);
779 return BLK_STS_RESOURCE
;
785 static const struct blk_mq_ops dm_mq_ops
= {
786 .queue_rq
= dm_mq_queue_rq
,
787 .complete
= dm_softirq_done
,
788 .init_request
= dm_mq_init_request
,
791 int dm_mq_init_request_queue(struct mapped_device
*md
, struct dm_table
*t
)
793 struct request_queue
*q
;
794 struct dm_target
*immutable_tgt
;
797 if (!dm_table_all_blk_mq_devices(t
)) {
798 DMERR("request-based dm-mq may only be stacked on blk-mq device(s)");
802 md
->tag_set
= kzalloc_node(sizeof(struct blk_mq_tag_set
), GFP_KERNEL
, md
->numa_node_id
);
806 md
->tag_set
->ops
= &dm_mq_ops
;
807 md
->tag_set
->queue_depth
= dm_get_blk_mq_queue_depth();
808 md
->tag_set
->numa_node
= md
->numa_node_id
;
809 md
->tag_set
->flags
= BLK_MQ_F_SHOULD_MERGE
| BLK_MQ_F_SG_MERGE
;
810 md
->tag_set
->nr_hw_queues
= dm_get_blk_mq_nr_hw_queues();
811 md
->tag_set
->driver_data
= md
;
813 md
->tag_set
->cmd_size
= sizeof(struct dm_rq_target_io
);
814 immutable_tgt
= dm_table_get_immutable_target(t
);
815 if (immutable_tgt
&& immutable_tgt
->per_io_data_size
) {
816 /* any target-specific per-io data is immediately after the tio */
817 md
->tag_set
->cmd_size
+= immutable_tgt
->per_io_data_size
;
818 md
->init_tio_pdu
= true;
821 err
= blk_mq_alloc_tag_set(md
->tag_set
);
823 goto out_kfree_tag_set
;
825 q
= blk_mq_init_allocated_queue(md
->tag_set
, md
->queue
);
834 blk_mq_free_tag_set(md
->tag_set
);
841 void dm_mq_cleanup_mapped_device(struct mapped_device
*md
)
844 blk_mq_free_tag_set(md
->tag_set
);
849 module_param(reserved_rq_based_ios
, uint
, S_IRUGO
| S_IWUSR
);
850 MODULE_PARM_DESC(reserved_rq_based_ios
, "Reserved IOs in request-based mempools");
852 module_param(use_blk_mq
, bool, S_IRUGO
| S_IWUSR
);
853 MODULE_PARM_DESC(use_blk_mq
, "Use block multiqueue for request-based DM devices");
855 module_param(dm_mq_nr_hw_queues
, uint
, S_IRUGO
| S_IWUSR
);
856 MODULE_PARM_DESC(dm_mq_nr_hw_queues
, "Number of hardware queues for request-based dm-mq devices");
858 module_param(dm_mq_queue_depth
, uint
, S_IRUGO
| S_IWUSR
);
859 MODULE_PARM_DESC(dm_mq_queue_depth
, "Queue depth for request-based dm-mq devices");