Message ID | 20170516093914.16035-2-anand.jain@oracle.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On Tue, May 16, 2017 at 05:39:13PM +0800, Anand Jain wrote: > blkdev_issue_flush() is a blocking function and returns only after > the flush bio is completed, so a module handling more than one > device can't issue flush for all the devices unless it uses worker > thread. > > This patch adds a new function blkdev_issue_flush_no_wait(), which > uses submit_bio() instead of submit_bio_wait(), and accepts the > completion function and data from the caller. Just open code the damn thing, and drop the various superflous checks while you're at it. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 05/16/2017 07:56 PM, Christoph Hellwig wrote: > On Tue, May 16, 2017 at 05:39:13PM +0800, Anand Jain wrote: >> blkdev_issue_flush() is a blocking function and returns only after >> the flush bio is completed, so a module handling more than one >> device can't issue flush for all the devices unless it uses worker >> thread. >> >> This patch adds a new function blkdev_issue_flush_no_wait(), which >> uses submit_bio() instead of submit_bio_wait(), and accepts the >> completion function and data from the caller. > > Just open code the damn thing, Ok. Thanks for the comments. > and drop the various superflous checks > while you're at it. You mean at btrfs: write_dev_flush() OR block: blkdev_issue_flush() ? Where I find q = bdev_get_queue(bdev); if (!q) return -ENXIO isn't needed as anyway generic_make_request_checks() will check that down below. Not too sure about the other two checks though. Thanks, Anand > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, May 18, 2017 at 05:31:32PM +0800, Anand Jain wrote: > You mean at btrfs: write_dev_flush() > OR > block: blkdev_issue_flush() ? > Where I find > q = bdev_get_queue(bdev); > if (!q) > return -ENXIO > isn't needed as anyway generic_make_request_checks() will > check that down below. > Not too sure about the other two checks though. I was looking at your new function, but indeed it seems like the function is mostly copy & pasted from blkdev_issue_flush. The bdev->bd_disk, !bdev_get_queue and q->make_request_fn checks are all things you don't need, any blkdev_issue_flush should not either, although I'll need to look into the weird loop workaround again, which doesn't make much sense to me. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> The bdev->bd_disk, !bdev_get_queue and q->make_request_fn checks > are all things you don't need, any blkdev_issue_flush should not > either, although I'll need to look into the weird loop workaround > again, which doesn't make much sense to me. I tried to confirm q->make_request_fn and got lost, I am going to try again. Thanks, Anand -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/block/blk-flush.c b/block/blk-flush.c index c4e0880b54bb..16b9c61f4cd3 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -488,6 +488,53 @@ void blk_insert_flush(struct request *rq) blk_flush_complete_seq(rq, fq, REQ_FSEQ_ACTIONS & ~policy, 0); } +/* + * blkdev_issue_flush_no_wait - Issue a flush for the given block device + * @bdev: blockdev to issue flush for + * @gfp_mask: memory allocation flags (for bio_alloc) + * @endio_fn: completion function for the flush bio + * @data: flush bio private data + * + * Description: + * Issue a flush for the block device in question. Caller must provide + * the completion function and the private data, to be called when the + * issued flush bio completes. + */ +int blkdev_issue_flush_no_wait(struct block_device *bdev, gfp_t gfp_mask, + bio_end_io_t *endio_fn, void *data) +{ + struct request_queue *q; + struct bio *bio; + + if (bdev->bd_disk == NULL) + return -ENXIO; + + q = bdev_get_queue(bdev); + if (!q) + return -ENXIO; + + /* + * some block devices may not have their queue correctly set up here + * (e.g. loop device without a backing file) and so issuing a flush + * here will panic. Ensure there is a request function before issuing + * the flush. + */ + if (!q->make_request_fn) + return -ENXIO; + + bio = bio_alloc(gfp_mask, 0); + bio->bi_bdev = bdev; + bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH | REQ_SYNC; + bio->bi_end_io = endio_fn; + bio->bi_private = data; + + init_completion(data); + submit_bio(bio); + + return 0; +} +EXPORT_SYMBOL(blkdev_issue_flush_no_wait); + /** * blkdev_issue_flush - queue a flush * @bdev: blockdev to issue flush for diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index b5d1e27631ee..5d2b62239251 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1322,6 +1322,8 @@ 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_flush_no_wait(struct block_device *bdev, + gfp_t gfp_mask, bio_end_io_t *endio_fn, void *data); extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct page *page); @@ -1994,6 +1996,12 @@ static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask, return 0; } +static inline int blkdev_issue_flush_no_wait(struct block_device *bdev, + gfp_t gfp_mask, bio_end_io_t *endio_fn, void *data) +{ + return 0; +} + #endif /* CONFIG_BLOCK */ #endif
blkdev_issue_flush() is a blocking function and returns only after the flush bio is completed, so a module handling more than one device can't issue flush for all the devices unless it uses worker thread. This patch adds a new function blkdev_issue_flush_no_wait(), which uses submit_bio() instead of submit_bio_wait(), and accepts the completion function and data from the caller. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- block/blk-flush.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 8 ++++++++ 2 files changed, 55 insertions(+)