Skip to content

Commit

Permalink
blk-mq: add the blk_mq_alloc_disk APIs
Browse files Browse the repository at this point in the history
Add a new API to allocate a gendisk including the request_queue for use
with blk-mq based drivers.  This is to avoid boilerplate code in drivers.

Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Chaitanya Kulkarni <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jun 11, 2021
1 parent 26a9750 commit b461dfc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -3137,6 +3137,25 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
}
EXPORT_SYMBOL(blk_mq_init_queue);

struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata)
{
struct request_queue *q;
struct gendisk *disk;

q = blk_mq_init_queue_data(set, queuedata);
if (IS_ERR(q))
return ERR_CAST(q);

disk = __alloc_disk_node(0, set->numa_node);
if (!disk) {
blk_cleanup_queue(q);
return ERR_PTR(-ENOMEM);
}
disk->queue = q;
return disk;
}
EXPORT_SYMBOL(__blk_mq_alloc_disk);

/*
* Helper for setting up a queue with mq ops, given queue depth, and
* the passed in mq ops flags.
Expand Down
12 changes: 12 additions & 0 deletions include/linux/blk-mq.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@ enum {
((policy & ((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1)) \
<< BLK_MQ_F_ALLOC_POLICY_START_BIT)

#define blk_mq_alloc_disk(set, queuedata) \
({ \
static struct lock_class_key __key; \
struct gendisk *__disk = __blk_mq_alloc_disk(set, queuedata); \
\
if (__disk) \
lockdep_init_map(&__disk->lockdep_map, \
"(bio completion)", &__key, 0); \
__disk; \
})
struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set,
void *queuedata);
struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *);
struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
void *queuedata);
Expand Down

0 comments on commit b461dfc

Please sign in to comment.