>From 44c0b07191629e4d9b1cefb43cc9f84e5491bb81 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 28 Jun 2018 10:44:35 -0700 Subject: [PATCH 1/2] block: Add blkdev_submit_write_same() Add an asynchronous version of blkdev_issue_write_same(). Signed-off-by: Bart Van Assche --- block/blk-lib.c | 37 ++++++++++++++++++++++++++++++++++++- include/linux/blkdev.h | 3 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 8faa70f26fcd..680e2dadb2b8 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -212,7 +212,8 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector, * @page: page containing data * * Description: - * Issue a write same request for the sectors in question. + * Issue a write same request for the sectors in question and wait until it + * has finished. */ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, @@ -234,6 +235,40 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, } EXPORT_SYMBOL(blkdev_issue_write_same); +/** + * blkdev_submit_write_same - queue a write same operation + * @bdev: target blockdev + * @sector: start sector + * @nr_sects: number of sectors to write + * @gfp_mask: memory allocation flags (for bio_alloc) + * @page: page containing data + * @bi_end_io: will be called upon completion + * @bi_private: will be stored in the bio->bi_private field of the bio passed + * to @bi_end_io. + * + * Description: + * Submit a write same request asynchronously for the sectors in question. + * @bi_end_io will be called upon request completion. + */ +int blkdev_submit_write_same(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, + struct page *page, bio_end_io_t bi_end_io, + void *bi_private) +{ + struct bio *bio = NULL; + int ret; + + ret = __blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask, page, + &bio); + if (ret) + return ret; + bio->bi_end_io = bi_end_io; + bio->bi_private = bi_private; + submit_bio(bio); + return 0; +} +EXPORT_SYMBOL(blkdev_submit_write_same); + static int __blkdev_issue_write_zeroes(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, unsigned flags) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9154570edf29..771d37c347ea 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1388,6 +1388,9 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *); extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct page *page); +extern int blkdev_submit_write_same(struct block_device *bdev, sector_t sector, + sector_t nr_sects, gfp_t gfp_mask, struct page *page, + bio_end_io_t bi_end_io, void *bi_private); #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */ -- 2.17.1