Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: core: Add scsi_{get,put}_internal_cmd() helpers

Add helper functions to allow LLDDs to allocate and free internal commands.

[ bvanassche: changed the 'nowait' argument into a 'flags' argument. See also
https://lore.kernel.org/linux-scsi/20211125151048.103910-3-hare@suse.de/ ]

Reviewed-by: John Garry <john.g.garry@oracle.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://patch.msgid.link/20251031204029.2883185-7-bvanassche@acm.org
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Hannes Reinecke and committed by
Martin K. Petersen
a2ab4e33 11ea1de3

+42
+38
drivers/scsi/scsi_lib.c
··· 2135 2135 } 2136 2136 2137 2137 /** 2138 + * scsi_get_internal_cmd() - Allocate an internal SCSI command. 2139 + * @sdev: SCSI device from which to allocate the command 2140 + * @data_direction: Data direction for the allocated command 2141 + * @flags: request allocation flags, e.g. BLK_MQ_REQ_RESERVED or 2142 + * BLK_MQ_REQ_NOWAIT. 2143 + * 2144 + * Allocates a SCSI command for internal LLDD use. 2145 + */ 2146 + struct scsi_cmnd *scsi_get_internal_cmd(struct scsi_device *sdev, 2147 + enum dma_data_direction data_direction, 2148 + blk_mq_req_flags_t flags) 2149 + { 2150 + enum req_op op = data_direction == DMA_TO_DEVICE ? REQ_OP_DRV_OUT : 2151 + REQ_OP_DRV_IN; 2152 + struct scsi_cmnd *scmd; 2153 + struct request *rq; 2154 + 2155 + rq = scsi_alloc_request(sdev->request_queue, op, flags); 2156 + if (IS_ERR(rq)) 2157 + return NULL; 2158 + scmd = blk_mq_rq_to_pdu(rq); 2159 + scmd->device = sdev; 2160 + 2161 + return scmd; 2162 + } 2163 + EXPORT_SYMBOL_GPL(scsi_get_internal_cmd); 2164 + 2165 + /** 2166 + * scsi_put_internal_cmd() - Free an internal SCSI command. 2167 + * @scmd: SCSI command to be freed 2168 + */ 2169 + void scsi_put_internal_cmd(struct scsi_cmnd *scmd) 2170 + { 2171 + blk_mq_free_request(blk_mq_rq_from_pdu(scmd)); 2172 + } 2173 + EXPORT_SYMBOL_GPL(scsi_put_internal_cmd); 2174 + 2175 + /** 2138 2176 * scsi_device_from_queue - return sdev associated with a request_queue 2139 2177 * @q: The request queue to return the sdev from 2140 2178 *
+4
include/scsi/scsi_device.h
··· 558 558 const struct scsi_exec_args *args); 559 559 void scsi_failures_reset_retries(struct scsi_failures *failures); 560 560 561 + struct scsi_cmnd *scsi_get_internal_cmd(struct scsi_device *sdev, 562 + enum dma_data_direction data_direction, 563 + blk_mq_req_flags_t flags); 564 + void scsi_put_internal_cmd(struct scsi_cmnd *scmd); 561 565 extern void sdev_disable_disk_events(struct scsi_device *sdev); 562 566 extern void sdev_enable_disk_events(struct scsi_device *sdev); 563 567 extern int scsi_vpd_lun_id(struct scsi_device *, char *, size_t);