@@ -2081,11 +2081,23 @@ static int scsi_init_request(void *data, struct request *rq,
unsigned int numa_node)
{
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
+ struct Scsi_Host *shost = data;
cmd->sense_buffer = kzalloc_node(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL,
numa_node);
if (!cmd->sense_buffer)
return -ENOMEM;
+
+ if (shost->hostt->init_command) {
+ int ret;
+
+ ret = shost->hostt->init_command(shost, cmd, request_idx);
+ if (ret) {
+ kfree(cmd->sense_buffer);
+ return ret;
+ }
+ }
+
return 0;
}
@@ -2093,8 +2105,12 @@ static void scsi_exit_request(void *data, struct request *rq,
unsigned int hctx_idx, unsigned int request_idx)
{
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
+ struct Scsi_Host *shost = data;
kfree(cmd->sense_buffer);
+
+ if (shost->hostt->exit_command)
+ shost->hostt->exit_command(shost, cmd);
}
static u64 scsi_calculate_bounce_limit(struct Scsi_Host *shost)
@@ -496,10 +496,14 @@ struct scsi_host_template {
u64 vendor_id;
/*
- * Additional per-command data allocated for the driver.
+ * Additional per-command data allocated for the driver, along
+ * with init/exit helper hooks.
*/
unsigned int cmd_size;
struct scsi_host_cmd_pool *cmd_pool;
+ int (*init_command)(struct Scsi_Host *, struct scsi_cmnd *,
+ unsigned int);
+ void (*exit_command)(struct Scsi_Host *, struct scsi_cmnd *);
/* temporary flag to disable blk-mq I/O path */
bool disable_blk_mq;
If a LLD has hardware commands in the request pdu, then we need some helper hooks to help the driver initialize state at load time, and potentially to tear down state at rmmod time. Add a host template ->init_command() and ->exit_command() hook to help with that. Signed-off-by: Jens Axboe <axboe@fb.com> --- drivers/scsi/scsi_lib.c | 16 ++++++++++++++++ include/scsi/scsi_host.h | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-)