On 2020-04-30 9:18 a.m., Hannes Reinecke wrote:
Add helper functions to retrieve SCSI commands from the reserved
tag pool.
Signed-off-by: Hannes Reinecke <hare@xxxxxxxx>
---
drivers/scsi/scsi_lib.c | 35 +++++++++++++++++++++++++++++++++++
include/scsi/scsi_device.h | 3 +++
2 files changed, 38 insertions(+)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 5358f553f526..d0972744ea7f 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1901,6 +1901,41 @@ void scsi_mq_destroy_tags(struct Scsi_Host *shost)
blk_mq_free_tag_set(&shost->tag_set);
}
+/**
+ * scsi_get_reserved_cmd - allocate a SCSI command from reserved tags
+ * @sdev: SCSI device from which to allocate the command
+ * @data_direction: Data direction for the allocated command
+ */
+struct scsi_cmnd *scsi_get_reserved_cmd(struct scsi_device *sdev,
+ int data_direction)
+{
+ struct request *rq;
+ struct scsi_cmnd *scmd;
+
+ rq = blk_mq_alloc_request(sdev->request_queue,
+ data_direction == DMA_TO_DEVICE ?
+ REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN | REQ_NOWAIT,
after consulting: https://en.cppreference.com/w/c/language/operator_precedence
I think that the above expression can be written as:
(data_direction == DMA_TO_DEVICE) ? REQ_OP_SCSI_OUT : (REQ_OP_SCSI_IN | REQ_NOWAIT),
So is REQ_NOWAIT not needed with REQ_OP_SCSI_OUT ?
Please note that scripts/checkpatch.pl does _not_ complain when parentheses
are used around bitwise operators in complex expressions. And I reckon this
expression qualifies as complex.
Doug Gilbert
Note: in that reference the terniary operator gets this note: "The expression
in the middle of the conditional operator (between ? and :) is parsed as if
parenthesized: its precedence relative to ?: is ignored". Who knew?