Skip to content

Commit

Permalink
block: move ->make_request_fn to struct block_device_operations
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jul 1, 2020
1 parent e439ab7 commit c62b37d
Show file tree
Hide file tree
Showing 36 changed files with 153 additions and 140 deletions.
2 changes: 1 addition & 1 deletion Documentation/block/biodoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ Now the generic block layer performs partition-remapping early and thus
provides drivers with a sector number relative to whole device, rather than
having to take partition number into account in order to arrive at the true
sector number. The routine blk_partition_remap() is invoked by
generic_make_request even before invoking the queue specific make_request_fn,
generic_make_request even before invoking the queue specific ->submit_bio,
so the i/o scheduler also gets to operate on whole disk sector numbers. This
should typically not require changes to block drivers, it just never gets
to invoke its own partition sector offset calculations since all bios
Expand Down
2 changes: 1 addition & 1 deletion Documentation/block/writeback_cache_control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ the Forced Unit Access is implemented. The REQ_PREFLUSH and REQ_FUA flags
may both be set on a single bio.


Implementation details for make_request_fn based block drivers
Implementation details for bio based block drivers
--------------------------------------------------------------

These drivers will always see the REQ_PREFLUSH and REQ_FUA bits as they sit
Expand Down
5 changes: 3 additions & 2 deletions arch/m68k/emu/nfblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct nfhd_device {
struct gendisk *disk;
};

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

static const struct block_device_operations nfhd_ops = {
.owner = THIS_MODULE,
.submit_bio = nfhd_submit_bio,
.getgeo = nfhd_getgeo,
};

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

dev->queue = blk_alloc_queue(nfhd_make_request, NUMA_NO_NODE);
dev->queue = blk_alloc_queue(NUMA_NO_NODE);
if (dev->queue == NULL)
goto free_dev;

Expand Down
5 changes: 3 additions & 2 deletions arch/xtensa/platforms/iss/simdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void simdisk_transfer(struct simdisk *dev, unsigned long sector,
spin_unlock(&dev->lock);
}

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

static const struct block_device_operations simdisk_ops = {
.owner = THIS_MODULE,
.submit_bio = simdisk_submit_bio,
.open = simdisk_open,
.release = simdisk_release,
};
Expand Down Expand Up @@ -267,7 +268,7 @@ static int __init simdisk_setup(struct simdisk *dev, int which,
spin_lock_init(&dev->lock);
dev->users = 0;

dev->queue = blk_alloc_queue(simdisk_make_request, NUMA_NO_NODE);
dev->queue = blk_alloc_queue(NUMA_NO_NODE);
if (dev->queue == NULL) {
pr_err("blk_alloc_queue failed\n");
goto out_alloc_queue;
Expand Down
2 changes: 1 addition & 1 deletion block/blk-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ static int blkcg_css_online(struct cgroup_subsys_state *css)
* blkcg_init_queue - initialize blkcg part of request queue
* @q: request_queue to initialize
*
* Called from __blk_alloc_queue(). Responsible for initializing blkcg
* Called from blk_alloc_queue(). Responsible for initializing blkcg
* part of new request_queue @q.
*
* RETURNS:
Expand Down
53 changes: 19 additions & 34 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ EXPORT_SYMBOL(blk_dump_rq_flags);
* A block device may call blk_sync_queue to ensure that any
* such activity is cancelled, thus allowing it to release resources
* that the callbacks might use. The caller must already have made sure
* that its ->make_request_fn will not re-add plugging prior to calling
* that its ->submit_bio will not re-add plugging prior to calling
* this function.
*
* This function does not cancel any asynchronous activity arising
Expand Down Expand Up @@ -510,7 +510,7 @@ static void blk_timeout_work(struct work_struct *work)
{
}

struct request_queue *__blk_alloc_queue(int node_id)
struct request_queue *blk_alloc_queue(int node_id)
{
struct request_queue *q;
int ret;
Expand Down Expand Up @@ -575,6 +575,7 @@ struct request_queue *__blk_alloc_queue(int node_id)

blk_queue_dma_alignment(q, 511);
blk_set_default_limits(&q->limits);
q->nr_requests = BLKDEV_MAX_RQ;

return q;

Expand All @@ -592,21 +593,6 @@ struct request_queue *__blk_alloc_queue(int node_id)
kmem_cache_free(blk_requestq_cachep, q);
return NULL;
}

struct request_queue *blk_alloc_queue(make_request_fn make_request, int node_id)
{
struct request_queue *q;

if (WARN_ON_ONCE(!make_request))
return NULL;

q = __blk_alloc_queue(node_id);
if (!q)
return NULL;
q->make_request_fn = make_request;
q->nr_requests = BLKDEV_MAX_RQ;
return q;
}
EXPORT_SYMBOL(blk_alloc_queue);

/**
Expand Down Expand Up @@ -1088,15 +1074,15 @@ generic_make_request_checks(struct bio *bio)

static blk_qc_t do_make_request(struct bio *bio)
{
struct request_queue *q = bio->bi_disk->queue;
struct gendisk *disk = bio->bi_disk;
blk_qc_t ret = BLK_QC_T_NONE;

if (blk_crypto_bio_prep(&bio)) {
if (!q->make_request_fn)
return blk_mq_make_request(q, bio);
ret = q->make_request_fn(q, bio);
if (!disk->fops->submit_bio)
return blk_mq_submit_bio(bio);
ret = disk->fops->submit_bio(bio);
}
blk_queue_exit(q);
blk_queue_exit(disk->queue);
return ret;
}

Expand All @@ -1113,10 +1099,9 @@ blk_qc_t generic_make_request(struct bio *bio)
{
/*
* bio_list_on_stack[0] contains bios submitted by the current
* make_request_fn.
* bio_list_on_stack[1] contains bios that were submitted before
* the current make_request_fn, but that haven't been processed
* yet.
* ->submit_bio.
* bio_list_on_stack[1] contains bios that were submitted before the
* current ->submit_bio_bio, but that haven't been processed yet.
*/
struct bio_list bio_list_on_stack[2];
blk_qc_t ret = BLK_QC_T_NONE;
Expand All @@ -1125,10 +1110,10 @@ blk_qc_t generic_make_request(struct bio *bio)
goto out;

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

if (WARN_ON_ONCE(q->make_request_fn)) {
if (WARN_ON_ONCE(!disk->queue->mq_ops)) {
bio_io_error(bio);
return BLK_QC_T_NONE;
}
Expand All @@ -1212,10 +1197,10 @@ blk_qc_t direct_make_request(struct bio *bio)
if (unlikely(bio_queue_enter(bio)))
return BLK_QC_T_NONE;
if (!blk_crypto_bio_prep(&bio)) {
blk_queue_exit(q);
blk_queue_exit(disk->queue);
return BLK_QC_T_NONE;
}
return blk_mq_make_request(q, bio);
return blk_mq_submit_bio(bio);
}
EXPORT_SYMBOL_GPL(direct_make_request);

Expand Down
10 changes: 5 additions & 5 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2136,8 +2136,7 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
}

/**
* blk_mq_make_request - Create and send a request to block device.
* @q: Request queue pointer.
* blk_mq_submit_bio - Create and send a request to block device.
* @bio: Bio pointer.
*
* Builds up a request structure from @q and @bio and send to the device. The
Expand All @@ -2151,8 +2150,9 @@ static void blk_add_rq_to_plug(struct blk_plug *plug, struct request *rq)
*
* Returns: Request queue cookie.
*/
blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
blk_qc_t blk_mq_submit_bio(struct bio *bio)
{
struct request_queue *q = bio->bi_disk->queue;
const int is_sync = op_is_sync(bio->bi_opf);
const int is_flush_fua = op_is_flush(bio->bi_opf);
struct blk_mq_alloc_data data = {
Expand Down Expand Up @@ -2277,7 +2277,7 @@ blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
blk_queue_exit(q);
return BLK_QC_T_NONE;
}
EXPORT_SYMBOL_GPL(blk_mq_make_request); /* only for request based dm */
EXPORT_SYMBOL_GPL(blk_mq_submit_bio); /* only for request based dm */

void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
unsigned int hctx_idx)
Expand Down Expand Up @@ -3017,7 +3017,7 @@ struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
{
struct request_queue *uninit_q, *q;

uninit_q = __blk_alloc_queue(set->numa_node);
uninit_q = blk_alloc_queue(set->numa_node);
if (!uninit_q)
return ERR_PTR(-ENOMEM);
uninit_q->queuedata = queuedata;
Expand Down
2 changes: 0 additions & 2 deletions block/blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,6 @@ static inline void part_nr_sects_write(struct hd_struct *part, sector_t size)
#endif
}

struct request_queue *__blk_alloc_queue(int node_id);

int bio_add_hw_page(struct request_queue *q, struct bio *bio,
struct page *page, unsigned int len, unsigned int offset,
unsigned int max_sectors, bool *same_page);
Expand Down
5 changes: 3 additions & 2 deletions drivers/block/brd.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static int brd_do_bvec(struct brd_device *brd, struct page *page,
return err;
}

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

static const struct block_device_operations brd_fops = {
.owner = THIS_MODULE,
.submit_bio = brd_submit_bio,
.rw_page = brd_rw_page,
};

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

brd->brd_queue = blk_alloc_queue(brd_make_request, NUMA_NO_NODE);
brd->brd_queue = blk_alloc_queue(NUMA_NO_NODE);
if (!brd->brd_queue)
goto out_free_dev;

Expand Down
2 changes: 1 addition & 1 deletion drivers/block/drbd/drbd_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ extern void conn_free_crypto(struct drbd_connection *connection);
/* drbd_req */
extern void do_submit(struct work_struct *ws);
extern void __drbd_make_request(struct drbd_device *, struct bio *, unsigned long);
extern blk_qc_t drbd_make_request(struct request_queue *q, struct bio *bio);
extern blk_qc_t drbd_submit_bio(struct bio *bio);
extern int drbd_read_remote(struct drbd_device *device, struct drbd_request *req);
extern int is_valid_ar_handle(struct drbd_request *, sector_t);

Expand Down
9 changes: 5 additions & 4 deletions drivers/block/drbd/drbd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ wait_queue_head_t drbd_pp_wait;
DEFINE_RATELIMIT_STATE(drbd_ratelimit_state, 5 * HZ, 5);

static const struct block_device_operations drbd_ops = {
.owner = THIS_MODULE,
.open = drbd_open,
.release = drbd_release,
.owner = THIS_MODULE,
.submit_bio = drbd_submit_bio,
.open = drbd_open,
.release = drbd_release,
};

struct bio *bio_alloc_drbd(gfp_t gfp_mask)
Expand Down Expand Up @@ -2801,7 +2802,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig

drbd_init_set_defaults(device);

q = blk_alloc_queue(drbd_make_request, NUMA_NO_NODE);
q = blk_alloc_queue(NUMA_NO_NODE);
if (!q)
goto out_no_q;
device->rq_queue = q;
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/drbd/drbd_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ void do_submit(struct work_struct *ws)
}
}

blk_qc_t drbd_make_request(struct request_queue *q, struct bio *bio)
blk_qc_t drbd_submit_bio(struct bio *bio)
{
struct drbd_device *device = bio->bi_disk->private_data;
unsigned long start_jif;
Expand Down
17 changes: 13 additions & 4 deletions drivers/block/null_blk_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ static struct nullb_queue *nullb_to_queue(struct nullb *nullb)
return &nullb->queues[index];
}

static blk_qc_t null_queue_bio(struct request_queue *q, struct bio *bio)
static blk_qc_t null_submit_bio(struct bio *bio)
{
sector_t sector = bio->bi_iter.bi_sector;
sector_t nr_sectors = bio_sectors(bio);
Expand Down Expand Up @@ -1575,7 +1575,13 @@ static void null_config_discard(struct nullb *nullb)
blk_queue_flag_set(QUEUE_FLAG_DISCARD, nullb->q);
}

static const struct block_device_operations null_ops = {
static const struct block_device_operations null_bio_ops = {
.owner = THIS_MODULE,
.submit_bio = null_submit_bio,
.report_zones = null_report_zones,
};

static const struct block_device_operations null_rq_ops = {
.owner = THIS_MODULE,
.report_zones = null_report_zones,
};
Expand Down Expand Up @@ -1647,7 +1653,10 @@ static int null_gendisk_register(struct nullb *nullb)
disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
disk->major = null_major;
disk->first_minor = nullb->index;
disk->fops = &null_ops;
if (queue_is_mq(nullb->q))
disk->fops = &null_rq_ops;
else
disk->fops = &null_bio_ops;
disk->private_data = nullb;
disk->queue = nullb->q;
strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
Expand Down Expand Up @@ -1792,7 +1801,7 @@ static int null_add_dev(struct nullb_device *dev)
goto out_cleanup_tags;
}
} else if (dev->queue_mode == NULL_Q_BIO) {
nullb->q = blk_alloc_queue(null_queue_bio, dev->home_node);
nullb->q = blk_alloc_queue(dev->home_node);
if (!nullb->q) {
rv = -ENOMEM;
goto out_cleanup_queues;
Expand Down
Loading

0 comments on commit c62b37d

Please sign in to comment.