From: Hannes Reinecke <hare@xxxxxxx> Some drivers use a single tag space for requests submitted by the block layer and driver-internal requests. Driver-internal requests will never pass through the block layer but require a valid tag. This patch adds a new request flag REQ_INTERNAL to mark such requests and a terminates any such commands in blk_execute_rq_nowait() with a WARN_ON_ONCE() to signal such an invalid usage. Cc: Jens Axboe <axboe@xxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Ming Lei <ming.lei@xxxxxxxxxx> Cc: John Garry <john.garry@xxxxxxxxxx> Signed-off-by: Hannes Reinecke <hare@xxxxxxx> [ bvanassche: modified patch description ] Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx> --- block/blk-exec.c | 5 +++++ include/linux/blk-mq.h | 5 +++++ include/linux/blk_types.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/block/blk-exec.c b/block/blk-exec.c index 1b8b47f6e79b..27d2e3779c13 100644 --- a/block/blk-exec.c +++ b/block/blk-exec.c @@ -53,6 +53,11 @@ void blk_execute_rq_nowait(struct gendisk *bd_disk, struct request *rq, rq->rq_disk = bd_disk; rq->end_io = done; + if (WARN_ON_ONCE(blk_rq_is_internal(rq))) { + blk_mq_end_request(rq, BLK_STS_NOTSUPP); + return; + } + blk_account_io_start(rq); /* diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 2949d9ac7484..3b42fcdf0c15 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -208,6 +208,11 @@ static inline bool blk_rq_is_passthrough(struct request *rq) return blk_op_is_passthrough(req_op(rq)); } +static inline bool blk_rq_is_internal(struct request *rq) +{ + return rq->cmd_flags & REQ_INTERNAL; +} + static inline unsigned short req_get_ioprio(struct request *req) { return req->ioprio; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index fe065c394fff..1ae2365e02d1 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -411,6 +411,7 @@ enum req_flag_bits { /* for driver use */ __REQ_DRV, __REQ_SWAP, /* swapping request. */ + __REQ_INTERNAL, /* driver-internal command */ __REQ_NR_BITS, /* stops here */ }; @@ -435,6 +436,7 @@ enum req_flag_bits { #define REQ_DRV (1ULL << __REQ_DRV) #define REQ_SWAP (1ULL << __REQ_SWAP) +#define REQ_INTERNAL (1ULL << __REQ_INTERNAL) #define REQ_FAILFAST_MASK \ (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)