Skip to content

Commit 4ee5eaf

Browse files
Kiyoshi UedaJens Axboe
authored andcommitted
block: add a queue flag for request stacking support
This patch adds a queue flag to indicate the block device can be used for request stacking. Request stacking drivers need to stack their devices on top of only devices of which q->request_fn is functional. Since bio stacking drivers (e.g. md, loop) basically initialize their queue using blk_alloc_queue() and don't set q->request_fn, the check of (q->request_fn == NULL) looks enough for that purpose. However, dm will become both types of stacking driver (bio-based and request-based). And dm will always set q->request_fn even if the dm device is bio-based of which q->request_fn is not functional actually. So we need something else to distinguish the type of the device. Adding a queue flag is a solution for that. The reason why dm always sets q->request_fn is to keep the compatibility of dm user-space tools. Currently, all dm user-space tools are using bio-based dm without specifying the type of the dm device they use. To use request-based dm without changing such tools, the kernel must decide the type of the dm device automatically. The automatic type decision can't be done at the device creation time and needs to be deferred until such tools load a mapping table, since the actual type is decided by dm target type included in the mapping table. So a dm device has to be initialized using blk_init_queue() so that we can load either type of table. Then, all queue stuffs are set (e.g. q->request_fn) and we have no element to distinguish that it is bio-based or request-based, even after a table is loaded and the type of the device is decided. By the way, some stuffs of the queue (e.g. request_list, elevator) are needless when the dm device is used as bio-based. But the memory size is not so large (about 20[KB] per queue on ia64), so I hope the memory loss can be acceptable for bio-based dm users. Signed-off-by: Kiyoshi Ueda <[email protected]> Signed-off-by: Jun'ichi Nomura <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 82124d6 commit 4ee5eaf

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

block/blk-core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ blk_init_queue_node(request_fn_proc *rfn, spinlock_t *lock, int node_id)
574574
q->request_fn = rfn;
575575
q->prep_rq_fn = NULL;
576576
q->unplug_fn = generic_unplug_device;
577-
q->queue_flags = (1 << QUEUE_FLAG_CLUSTER);
577+
q->queue_flags = (1 << QUEUE_FLAG_CLUSTER |
578+
1 << QUEUE_FLAG_STACKABLE);
578579
q->queue_lock = lock;
579580

580581
blk_queue_segment_boundary(q, 0xffffffff);

include/linux/blkdev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ struct request_queue
441441
#define QUEUE_FLAG_NOMERGES 10 /* disable merge attempts */
442442
#define QUEUE_FLAG_SAME_COMP 11 /* force complete on same CPU */
443443
#define QUEUE_FLAG_FAIL_IO 12 /* fake timeout */
444+
#define QUEUE_FLAG_STACKABLE 13 /* supports request stacking */
444445

445446
static inline int queue_is_locked(struct request_queue *q)
446447
{
@@ -547,6 +548,8 @@ enum {
547548
#define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
548549
#define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
549550
#define blk_queue_flushing(q) ((q)->ordseq)
551+
#define blk_queue_stackable(q) \
552+
test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)
550553

551554
#define blk_fs_request(rq) ((rq)->cmd_type == REQ_TYPE_FS)
552555
#define blk_pc_request(rq) ((rq)->cmd_type == REQ_TYPE_BLOCK_PC)

0 commit comments

Comments
 (0)