From fdd37844053febbb59c54474d266774bfb3e017b Mon Sep 17 00:00:00 2001 From: Mike Snitzer Date: Wed, 23 Sep 2020 16:06:51 -0400 Subject: [PATCH 2278/2944] block: add QUEUE_FLAG_NOWAIT commit 021a24460dc28e7412aecfae89f60e1847e685c0 upstream. Add QUEUE_FLAG_NOWAIT to allow a block device to advertise support for REQ_NOWAIT. Bio-based devices may set QUEUE_FLAG_NOWAIT where applicable. Update QUEUE_FLAG_MQ_DEFAULT to include QUEUE_FLAG_NOWAIT. Also update submit_bio_checks() to verify it is set for REQ_NOWAIT bios. [Backport Notes] There're some issues because of the code base difference. 1. blkdev.h: definition of QUEUE_FLAG_NOWAIT is bit 29 in upstream commit, while it's bit 30 in backport commit. 2. blkdev.h: Single-queue has been merged into the mq framework upon the time of upstream commit, and thus there's only QUEUE_FLAG_MQ_DEFAULT then. However we have both QUEUE_FLAG_MQ_DEFAULT and QUEUE_FLAG_DEFAULT in v4.19, thus QUEUE_FLAG_NOWAIT should be included in both these two default sets. 3. blk-core.c: resolve code base difference. Reported-by: Konstantin Khlebnikov Suggested-by: Christoph Hellwig Signed-off-by: Mike Snitzer Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Jeffle Xu Reviewed-by: Joseph Qi --- block/blk-core.c | 4 ++-- include/linux/blkdev.h | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 483d12e..34c7da4 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2250,9 +2250,9 @@ static inline int blk_partition_remap(struct bio *bio) /* * For a REQ_NOWAIT based request, return -EOPNOTSUPP - * if queue is not a request based queue. + * if queue does not support NOWAIT. */ - if ((bio->bi_opf & REQ_NOWAIT) && !queue_is_rq_based(q)) + if ((bio->bi_opf & REQ_NOWAIT) && !blk_queue_nowait(q)) goto not_supported; if (should_fail_bio(bio)) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9aeffc6..ccb2551 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -729,13 +729,16 @@ struct request_queue { #define QUEUE_FLAG_SCSI_PASSTHROUGH 27 /* queue supports SCSI commands */ #define QUEUE_FLAG_QUIESCED 28 /* queue has been quiesced */ #define QUEUE_FLAG_RQ_ALLOC_TIME 29 /* record rq->alloc_time_ns */ +#define QUEUE_FLAG_NOWAIT 30 /* device supports NOWAIT */ #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_SAME_COMP) | \ - (1 << QUEUE_FLAG_ADD_RANDOM)) + (1 << QUEUE_FLAG_ADD_RANDOM) | \ + (1 << QUEUE_FLAG_NOWAIT)) #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ - (1 << QUEUE_FLAG_SAME_COMP)) + (1 << QUEUE_FLAG_SAME_COMP) | \ + (1 << QUEUE_FLAG_NOWAIT)) void blk_queue_flag_set(unsigned int flag, struct request_queue *q); void blk_queue_flag_clear(unsigned int flag, struct request_queue *q); @@ -773,6 +776,7 @@ struct request_queue { #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) #define blk_queue_pm_only(q) atomic_read(&(q)->pm_only) #define blk_queue_fua(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) +#define blk_queue_nowait(q) test_bit(QUEUE_FLAG_NOWAIT, &(q)->queue_flags) extern void blk_set_pm_only(struct request_queue *q); extern void blk_clear_pm_only(struct request_queue *q); -- 1.8.3.1