Add function to check if a SCSI command originates from the reserved command pool. Signed-off-by: Hannes Reinecke <hare@xxxxxxxx> --- block/blk-mq.c | 13 +++++++++++++ include/linux/blk-mq.h | 2 ++ include/scsi/scsi_tcq.h | 10 +++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index f6711a61ba3b..a2212c117782 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -289,6 +289,19 @@ static inline bool blk_mq_need_time_stamp(struct request *rq) return (rq->rq_flags & RQF_IO_STAT) || rq->q->elevator; } +/** + * blk_mq_rq_is_reserved - Check if a request has a reserved tag + * + * @rq: Request to check + */ +bool blk_mq_rq_is_reserved(struct request *rq) +{ + struct blk_mq_hw_ctx *hctx = rq->mq_hctx; + + return blk_mq_tag_is_reserved(hctx->tags, rq->tag); +} +EXPORT_SYMBOL_GPL(blk_mq_rq_is_reserved); + static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, unsigned int tag, unsigned int op) { diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 15d1aa53d96c..e0e49f1c6f3c 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -348,6 +348,8 @@ static inline void *blk_mq_rq_to_pdu(struct request *rq) return rq + 1; } +bool blk_mq_rq_is_reserved(struct request *rq); + #define queue_for_each_hw_ctx(q, hctx, i) \ for ((i) = 0; (i) < (q)->nr_hw_queues && \ ({ hctx = (q)->queue_hw_ctx[i]; 1; }); (i)++) diff --git a/include/scsi/scsi_tcq.h b/include/scsi/scsi_tcq.h index 227f3bd4e974..0c11e8fbe6d2 100644 --- a/include/scsi/scsi_tcq.h +++ b/include/scsi/scsi_tcq.h @@ -58,7 +58,15 @@ static inline void scsi_put_reserved_cmd(struct scsi_cmnd *scmd) { struct request *rq = blk_mq_rq_from_pdu(scmd); - blk_mq_free_request(rq); + if (blk_mq_rq_is_reserved(rq)) + blk_mq_free_request(rq); +} + +static inline bool scsi_is_reserved_cmd(struct scsi_cmnd *scmd) +{ + struct request *rq = blk_mq_rq_from_pdu(scmd); + + return blk_mq_rq_is_reserved(rq); } #endif /* CONFIG_BLOCK */ -- 2.16.4