Skip to content

Commit 69fe0f2

Browse files
Ming Leisnitm
authored andcommitted
block: add ->poll_bio to block_device_operations
Prepare for supporting IO polling for bio-based driver. Add ->poll_bio callback so that bio-based driver can provide their own logic for polling bio. Also fix ->submit_bio_bio typo in comment block above __submit_bio_noacct. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent 168678d commit 69fe0f2

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

block/blk-core.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ static void __submit_bio(struct bio *bio)
708708
*
709709
* bio_list_on_stack[0] contains bios submitted by the current ->submit_bio.
710710
* bio_list_on_stack[1] contains bios that were submitted before the current
711-
* ->submit_bio_bio, but that haven't been processed yet.
711+
* ->submit_bio, but that haven't been processed yet.
712712
*/
713713
static void __submit_bio_noacct(struct bio *bio)
714714
{
@@ -975,7 +975,7 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
975975
{
976976
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
977977
blk_qc_t cookie = READ_ONCE(bio->bi_cookie);
978-
int ret;
978+
int ret = 0;
979979

980980
if (cookie == BLK_QC_T_NONE ||
981981
!test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
@@ -985,10 +985,14 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags)
985985

986986
if (blk_queue_enter(q, BLK_MQ_REQ_NOWAIT))
987987
return 0;
988-
if (WARN_ON_ONCE(!queue_is_mq(q)))
989-
ret = 0; /* not yet implemented, should not happen */
990-
else
988+
if (queue_is_mq(q)) {
991989
ret = blk_mq_poll(q, cookie, iob, flags);
990+
} else {
991+
struct gendisk *disk = q->disk;
992+
993+
if (disk && disk->fops->poll_bio)
994+
ret = disk->fops->poll_bio(bio, iob, flags);
995+
}
992996
blk_queue_exit(q);
993997
return ret;
994998
}

block/genhd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
410410
struct device *ddev = disk_to_dev(disk);
411411
int ret;
412412

413+
/* Only makes sense for bio-based to set ->poll_bio */
414+
if (queue_is_mq(disk->queue) && disk->fops->poll_bio)
415+
return -EINVAL;
416+
413417
/*
414418
* The disk queue should now be all set with enough information about
415419
* the device for the elevator code to pick an adequate default

include/linux/blkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,8 @@ enum blk_unique_id {
14551455

14561456
struct block_device_operations {
14571457
void (*submit_bio)(struct bio *bio);
1458+
int (*poll_bio)(struct bio *bio, struct io_comp_batch *iob,
1459+
unsigned int flags);
14581460
int (*open) (struct block_device *, fmode_t);
14591461
void (*release) (struct gendisk *, fmode_t);
14601462
int (*rw_page)(struct block_device *, sector_t, struct page *, unsigned int);

0 commit comments

Comments
 (0)