Skip to content

Commit c62b37d

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: move ->make_request_fn to struct block_device_operations
The make_request_fn is a little weird in that it sits directly in struct request_queue instead of an operation vector. Replace it with a block_device_operations method called submit_bio (which describes much better what it does). Also remove the request_queue argument to it, as the queue can be derived pretty trivially from the bio. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e439ab7 commit c62b37d

36 files changed

Lines changed: 153 additions & 140 deletions

File tree

‎Documentation/block/biodoc.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ Now the generic block layer performs partition-remapping early and thus
10361036
provides drivers with a sector number relative to whole device, rather than
10371037
having to take partition number into account in order to arrive at the true
10381038
sector number. The routine blk_partition_remap() is invoked by
1039-
generic_make_request even before invoking the queue specific make_request_fn,
1039+
generic_make_request even before invoking the queue specific ->submit_bio,
10401040
so the i/o scheduler also gets to operate on whole disk sector numbers. This
10411041
should typically not require changes to block drivers, it just never gets
10421042
to invoke its own partition sector offset calculations since all bios

‎Documentation/block/writeback_cache_control.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ the Forced Unit Access is implemented. The REQ_PREFLUSH and REQ_FUA flags
4747
may both be set on a single bio.
4848

4949

50-
Implementation details for make_request_fn based block drivers
50+
Implementation details for bio based block drivers
5151
--------------------------------------------------------------
5252

5353
These drivers will always see the REQ_PREFLUSH and REQ_FUA bits as they sit

‎arch/m68k/emu/nfblock.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct nfhd_device {
5959
struct gendisk *disk;
6060
};
6161

62-
static blk_qc_t nfhd_make_request(struct request_queue *queue, struct bio *bio)
62+
static blk_qc_t nfhd_submit_bio(struct bio *bio)
6363
{
6464
struct nfhd_device *dev = bio->bi_disk->private_data;
6565
struct bio_vec bvec;
@@ -93,6 +93,7 @@ static int nfhd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
9393

9494
static const struct block_device_operations nfhd_ops = {
9595
.owner = THIS_MODULE,
96+
.submit_bio = nfhd_submit_bio,
9697
.getgeo = nfhd_getgeo,
9798
};
9899

@@ -118,7 +119,7 @@ static int __init nfhd_init_one(int id, u32 blocks, u32 bsize)
118119
dev->bsize = bsize;
119120
dev->bshift = ffs(bsize) - 10;
120121

121-
dev->queue = blk_alloc_queue(nfhd_make_request, NUMA_NO_NODE);
122+
dev->queue = blk_alloc_queue(NUMA_NO_NODE);
122123
if (dev->queue == NULL)
123124
goto free_dev;
124125

‎arch/xtensa/platforms/iss/simdisk.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void simdisk_transfer(struct simdisk *dev, unsigned long sector,
101101
spin_unlock(&dev->lock);
102102
}
103103

104-
static blk_qc_t simdisk_make_request(struct request_queue *q, struct bio *bio)
104+
static blk_qc_t simdisk_submit_bio(struct bio *bio)
105105
{
106106
struct simdisk *dev = bio->bi_disk->private_data;
107107
struct bio_vec bvec;
@@ -144,6 +144,7 @@ static void simdisk_release(struct gendisk *disk, fmode_t mode)
144144

145145
static const struct block_device_operations simdisk_ops = {
146146
.owner = THIS_MODULE,
147+
.submit_bio = simdisk_submit_bio,
147148
.open = simdisk_open,
148149
.release = simdisk_release,
149150
};
@@ -267,7 +268,7 @@ static int __init simdisk_setup(struct simdisk *dev, int which,
267268
spin_lock_init(&dev->lock);
268269
dev->users = 0;
269270

270-
dev->queue = blk_alloc_queue(simdisk_make_request, NUMA_NO_NODE);
271+
dev->queue = blk_alloc_queue(NUMA_NO_NODE);
271272
if (dev->queue == NULL) {
272273
pr_err("blk_alloc_queue failed\n");
273274
goto out_alloc_queue;

‎block/blk-cgroup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ static int blkcg_css_online(struct cgroup_subsys_state *css)
10121012
* blkcg_init_queue - initialize blkcg part of request queue
10131013
* @q: request_queue to initialize
10141014
*
1015-
* Called from __blk_alloc_queue(). Responsible for initializing blkcg
1015+
* Called from blk_alloc_queue(). Responsible for initializing blkcg
10161016
* part of new request_queue @q.
10171017
*
10181018
* RETURNS:

‎block/blk-core.c‎

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ EXPORT_SYMBOL(blk_dump_rq_flags);
283283
* A block device may call blk_sync_queue to ensure that any
284284
* such activity is cancelled, thus allowing it to release resources
285285
* that the callbacks might use. The caller must already have made sure
286-
* that its ->make_request_fn will not re-add plugging prior to calling
286+
* that its ->submit_bio will not re-add plugging prior to calling
287287
* this function.
288288
*
289289
* This function does not cancel any asynchronous activity arising
@@ -510,7 +510,7 @@ static void blk_timeout_work(struct work_struct *work)
510510
{
511511
}
512512

513-
struct request_queue *__blk_alloc_queue(int node_id)
513+
struct request_queue *blk_alloc_queue(int node_id)
514514
{
515515
struct request_queue *q;
516516
int ret;
@@ -575,6 +575,7 @@ struct request_queue *__blk_alloc_queue(int node_id)
575575

576576
blk_queue_dma_alignment(q, 511);
577577
blk_set_default_limits(&q->limits);
578+
q->nr_requests = BLKDEV_MAX_RQ;
578579

579580
return q;
580581

@@ -592,21 +593,6 @@ struct request_queue *__blk_alloc_queue(int node_id)
592593
kmem_cache_free(blk_requestq_cachep, q);
593594
return NULL;
594595
}
595-
596-
struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
597-
{
598-
struct request_queue *q;
599-
600-
if (WARN_ON_ONCE(!make_request))
601-
return NULL;
602-
603-
q = __blk_alloc_queue(node_id);
604-
if (!q)
605-
return NULL;
606-
q->make_request_fn = make_request;
607-
q->nr_requests = BLKDEV_MAX_RQ;
608-
return q;
609-
}
610596
EXPORT_SYMBOL(blk_alloc_queue);
611597

612598
/**
@@ -1088,15 +1074,15 @@ generic_make_request_checks(struct bio *bio)
10881074

10891075
static blk_qc_t do_make_request(struct bio *bio)
10901076
{
1091-
struct request_queue *q = bio->bi_disk->queue;
1077+
struct gendisk *disk = bio->bi_disk;
10921078
blk_qc_t ret = BLK_QC_T_NONE;
10931079

10941080
if (blk_crypto_bio_prep(&bio)) {
1095-
if (!q->make_request_fn)
1096-
return blk_mq_make_request(q, bio);
1097-
ret = q->make_request_fn(q, bio);
1081+
if (!disk->fops->submit_bio)
1082+
return blk_mq_submit_bio(bio);
1083+
ret = disk->fops->submit_bio(bio);
10981084
}
1099-
blk_queue_exit(q);
1085+
blk_queue_exit(disk->queue);
11001086
return ret;
11011087
}
11021088

@@ -1113,10 +1099,9 @@ blk_qc_t generic_make_request(struct bio *bio)
11131099
{
11141100
/*
11151101
* bio_list_on_stack[0] contains bios submitted by the current
1116-
* make_request_fn.
1117-
* bio_list_on_stack[1] contains bios that were submitted before
1118-
* the current make_request_fn, but that haven't been processed
1119-
* yet.
1102+
* ->submit_bio.
1103+
* bio_list_on_stack[1] contains bios that were submitted before the
1104+
* current ->submit_bio_bio, but that haven't been processed yet.
11201105
*/
11211106
struct bio_list bio_list_on_stack[2];
11221107
blk_qc_t ret = BLK_QC_T_NONE;
@@ -1125,10 +1110,10 @@ blk_qc_t generic_make_request(struct bio *bio)
11251110
goto out;
11261111

11271112
/*
1128-
* We only want one ->make_request_fn to be active at a time, else
1113+
* We only want one ->submit_bio to be active at a time, else
11291114
* stack usage with stacked devices could be a problem. So use
11301115
* current->bio_list to keep a list of requests submited by a
1131-
* make_request_fn function. current->bio_list is also used as a
1116+
* ->submit_bio method. current->bio_list is also used as a
11321117
* flag to say if generic_make_request is currently active in this
11331118
* task or not. If it is NULL, then no make_request is active. If
11341119
* it is non-NULL, then a make_request is active, and new requests
@@ -1146,12 +1131,12 @@ blk_qc_t generic_make_request(struct bio *bio)
11461131
* We pretend that we have just taken it off a longer list, so
11471132
* we assign bio_list to a pointer to the bio_list_on_stack,
11481133
* thus initialising the bio_list of new bios to be
1149-
* added. ->make_request() may indeed add some more bios
1134+
* added. ->submit_bio() may indeed add some more bios
11501135
* through a recursive call to generic_make_request. If it
11511136
* did, we find a non-NULL value in bio_list and re-enter the loop
11521137
* from the top. In this case we really did just take the bio
11531138
* of the top of the list (no pretending) and so remove it from
1154-
* bio_list, and call into ->make_request() again.
1139+
* bio_list, and call into ->submit_bio() again.
11551140
*/
11561141
BUG_ON(bio->bi_next);
11571142
bio_list_init(&bio_list_on_stack[0]);
@@ -1201,9 +1186,9 @@ EXPORT_SYMBOL(generic_make_request);
12011186
*/
12021187
blk_qc_t direct_make_request(struct bio *bio)
12031188
{
1204-
struct request_queue *q = bio->bi_disk->queue;
1189+
struct gendisk *disk = bio->bi_disk;
12051190

1206-
if (WARN_ON_ONCE(q->make_request_fn)) {
1191+
if (WARN_ON_ONCE(!disk->queue->mq_ops)) {
12071192
bio_io_error(bio);
12081193
return BLK_QC_T_NONE;
12091194
}
@@ -1212,10 +1197,10 @@ blk_qc_t direct_make_request(struct bio *bio)
12121197
if (unlikely(bio_queue_enter(bio)))
12131198
return BLK_QC_T_NONE;
12141199
if (!blk_crypto_bio_prep(&bio)) {
1215-
blk_queue_exit(q);
1200+
blk_queue_exit(disk->queue);
12161201
return BLK_QC_T_NONE;
12171202
}
1218-
return blk_mq_make_request(q, bio);
1203+
return blk_mq_submit_bio(bio);
12191204
}
12201205
EXPORT_SYMBOL_GPL(direct_make_request);
12211206

‎block/blk-mq.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,8 +2136,7 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
21362136
}
21372137

21382138
/**
2139-
* blk_mq_make_request - Create and send a request to block device.
2140-
* @q: Request queue pointer.
2139+
* blk_mq_submit_bio - Create and send a request to block device.
21412140
* @bio: Bio pointer.
21422141
*
21432142
* Builds up a request structure from @q and @bio and send to the device. The
@@ -2151,8 +2150,9 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
21512150
*
21522151
* Returns: Request queue cookie.
21532152
*/
2154-
blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
2153+
blk_qc_t blk_mq_submit_bio(struct bio *bio)
21552154
{
2155+
struct request_queue *q = bio->bi_disk->queue;
21562156
const int is_sync = op_is_sync(bio->bi_opf);
21572157
const int is_flush_fua = op_is_flush(bio->bi_opf);
21582158
struct blk_mq_alloc_data data = {
@@ -2277,7 +2277,7 @@ blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
22772277
blk_queue_exit(q);
22782278
return BLK_QC_T_NONE;
22792279
}
2280-
EXPORT_SYMBOL_GPL(blk_mq_make_request); /* only for request based dm */
2280+
EXPORT_SYMBOL_GPL(blk_mq_submit_bio); /* only for request based dm */
22812281

22822282
void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
22832283
unsigned int hctx_idx)
@@ -3017,7 +3017,7 @@ struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
30173017
{
30183018
struct request_queue *uninit_q, *q;
30193019

3020-
uninit_q = __blk_alloc_queue(set->numa_node);
3020+
uninit_q = blk_alloc_queue(set->numa_node);
30213021
if (!uninit_q)
30223022
return ERR_PTR(-ENOMEM);
30233023
uninit_q->queuedata = queuedata;

‎block/blk.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,6 @@ static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
419419
#endif
420420
}
421421

422-
struct request_queue *__blk_alloc_queue(int node_id);
423-
424422
int bio_add_hw_page(struct request_queue *q, struct bio *bio,
425423
struct page *page, unsigned int len, unsigned int offset,
426424
unsigned int max_sectors, bool *same_page);

‎drivers/block/brd.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static int brd_do_bvec(struct brd_device *brd, struct page *page,
282282
return err;
283283
}
284284

285-
static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
285+
static blk_qc_t brd_submit_bio(struct bio *bio)
286286
{
287287
struct brd_device *brd = bio->bi_disk->private_data;
288288
struct bio_vec bvec;
@@ -330,6 +330,7 @@ static int brd_rw_page(struct block_device *bdev, sector_t sector,
330330

331331
static const struct block_device_operations brd_fops = {
332332
.owner = THIS_MODULE,
333+
.submit_bio = brd_submit_bio,
333334
.rw_page = brd_rw_page,
334335
};
335336

@@ -381,7 +382,7 @@ static struct brd_device *brd_alloc(int i)
381382
spin_lock_init(&brd->brd_lock);
382383
INIT_RADIX_TREE(&brd->brd_pages, GFP_ATOMIC);
383384

384-
brd->brd_queue = blk_alloc_queue(brd_make_request, NUMA_NO_NODE);
385+
brd->brd_queue = blk_alloc_queue(NUMA_NO_NODE);
385386
if (!brd->brd_queue)
386387
goto out_free_dev;
387388

‎drivers/block/drbd/drbd_int.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ extern void conn_free_crypto(struct drbd_connection *connection);
14511451
/* drbd_req */
14521452
extern void do_submit(struct work_struct *ws);
14531453
extern void __drbd_make_request(struct drbd_device *, struct bio *, unsigned long);
1454-
extern blk_qc_t drbd_make_request(struct request_queue *q, struct bio *bio);
1454+
extern blk_qc_t drbd_submit_bio(struct bio *bio);
14551455
extern int drbd_read_remote(struct drbd_device *device, struct drbd_request *req);
14561456
extern int is_valid_ar_handle(struct drbd_request *, sector_t);
14571457

0 commit comments

Comments
 (0)