: Add support for SG_IO CDB passthrough in scsi_cmd_perform()
PATCH 2/2 : Add support for SG_IO CDB passthrough in scsi_cmd_perform()
From: Nicholas Bellinger <[email protected]>
This patch changes usr/scsi.c:scsi_cmd_perform() to first check to see if the struct backingstore_template->bs_passthrough=1 for SG_IO, then check for a valid struct device_type_template->cmd_passthrough() function pointer to determine if the device supports SG_IO.
This patch then updates the device_type in usr/sb.c to enable the functionality for TYPE_DISK.
--- usr/sbc.c | 1 + usr/scsi.c | 11 +++++++++++ usr/tgtd.h | 1 + 3 files changed, 13 insertions(+), 0 deletions(-)
usr/sbc.c +1 -0
@@ -269,6 +269,7 @@ static struct device_type_template sbc_template = { .lu_online = spc_lu_online, .lu_offline = spc_lu_offline, .lu_exit = spc_lu_exit, + .cmd_passthrough = sbc_rw, .ops = { {spc_test_unit,}, {spc_illegal_op,},
usr/scsi.c +11 -0
@@ -242,6 +242,17 @@ int scsi_cmd_perform(int host_no, struct scsi_cmd *cmd)if (spc_access_check (cmd))return SAM_STAT_RESERVATION_CONFLICT ; +/* +* Use dev_type_template->cmd_passthrough() for usr/bs_sg.c devices +*/ +if (cmd->dev->bst->bs_passthrough) { +if (!(cmd->dev->dev_type_template.cmd_passthrough)) { +eprintf ("cmd->dev->dev_type_template.cmd_passthrough()" +" is NULL!\n" ); +return SAM_STAT_CHECK_CONDITION ; + } +return cmd->dev->dev_type_template.cmd_passthrough (host_no, cmd); + }return cmd->dev->dev_type_template.ops[op].cmd_perform (host_no, cmd); }
usr/tgtd.h +1 -0
@@ -108,6 +108,7 @@ struct device_type_template {int (*lu_config)(struct scsi_lu *lu,char *args);int (*lu_online)(struct scsi_lu *lu);int (*lu_offline)(struct scsi_lu *lu); +int (*cmd_passthrough)(int ,struct scsi_cmd *);struct device_type_operations ops[256 ];
Signature · 1 line
1.5.6.5
Quoted 39 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
This patch changes usr/scsi.c:scsi_cmd_perform() to first check to see if the struct backingstore_template->bs_passthrough=1 for
SG_IO, then check for a valid structdevice_type_template->cmd_passthrough()function pointer to determine if the device supportsSG_IO.This patch then updates the
device_typeinusr/sb.cto enable the functionality forTYPE_DISK.Signed-off-by Nicholas A. Bellinger <[email protected]>--- usr/sbc.c | 1 + usr/scsi.c | 11 +++++++++++ usr/tgtd.h | 1 + 3 files changed, 13 insertions(+), 0 deletions(-)usr/sbc.c +1
-0@@ -269,6 +269,7 @@ static struct device_type_template sbc_template = { .lu_online = spc_lu_online, .lu_offline = spc_lu_offline, .lu_exit = spc_lu_exit, + .cmd_passthrough = sbc_rw, .ops = { {spc_test_unit,}, {spc_illegal_op,},usr/scsi.c +2
-0@@ -242,6 +242,17 @@ int scsi_cmd_perform(int host_no, struct scsi_cmd *cmd)if (spc_access_check (cmd))return SAM_STAT_RESERVATION_CONFLICT ; +/* +* Use dev_type_template->cmd_passthrough() for usr/bs_sg.c devices
usr/scsi.c int scsi_cmd_perform(int host_no, struct scsi_cmd *cmd) · line 256
Quoted 10 lines
usr/scsi.c +9
-0+*/ +if (cmd->dev->bst->bs_passthrough) { +if (!(cmd->dev->dev_type_template.cmd_passthrough)) { +eprintf ("cmd->dev->dev_type_template.cmd_passthrough()" +" is NULL!\n" ); +return SAM_STAT_CHECK_CONDITION ; + } +return cmd->dev->dev_type_template.cmd_passthrough (host_no, cmd); + }
Can't you just perform this check once somewhere and set cmd_perform to the new cmd_passthrough? why check for every command?
This is not accepted it is the hot path.
usr/tgtd.h struct device_type_template { · line 112
Quoted 12 lines
usr/scsi.c +0
-0return cmd->dev->dev_type_template.ops[op].cmd_perform (host_no, cmd); }usr/tgtd.h +1
-0@@ -108,6 +108,7 @@ struct device_type_template {int (*lu_config)(struct scsi_lu *lu,char *args);int (*lu_online)(struct scsi_lu *lu);int (*lu_offline)(struct scsi_lu *lu); +int (*cmd_passthrough)(int ,struct scsi_cmd *);
Actually you can do more:
If you leave the checking and decisions to the target driver then you don't need to touch this file. Just let the device_type decide which vector to set once it knows what target is used.
(Like start with a vector that check and sets the vector to
the passthrough or the regular path, on first IO)
usr/tgtd.h struct device_type_template { · line 114
Quoted 2 lines
usr/tgtd.h +0
-0struct device_type_operations ops[256 ];
Boaz
Quoted 54 lines · Boaz Harrosh
Quoted 39 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
This patch changes usr/scsi.c:scsi_cmd_perform() to first check to see if the struct backingstore_template->bs_passthrough=1 for
SG_IO, then check for a valid structdevice_type_template->cmd_passthrough()function pointer to determine if the device supportsSG_IO.This patch then updates the
device_typeinusr/sb.cto enable the functionality forTYPE_DISK.Signed-off-by Nicholas A. Bellinger <[email protected]>--- usr/sbc.c | 1 + usr/scsi.c | 11 +++++++++++ usr/tgtd.h | 1 + 3 files changed, 13 insertions(+), 0 deletions(-)usr/sbc.c +1
-0@@ -269,6 +269,7 @@ static struct device_type_template sbc_template = { .lu_online = spc_lu_online, .lu_offline = spc_lu_offline, .lu_exit = spc_lu_exit, + .cmd_passthrough = sbc_rw, .ops = { {spc_test_unit,}, {spc_illegal_op,},usr/scsi.c +2
-0@@ -242,6 +242,17 @@ int scsi_cmd_perform(int host_no, struct scsi_cmd *cmd)if (spc_access_check (cmd))return SAM_STAT_RESERVATION_CONFLICT ; +/* +* Use dev_type_template->cmd_passthrough() for usr/bs_sg.c devices usr/scsi.c int scsi_cmd_perform(int host_no, struct scsi_cmd *cmd) · line 256
Quoted 10 lines
usr/scsi.c +9
-0+*/ +if (cmd->dev->bst->bs_passthrough) { +if (!(cmd->dev->dev_type_template.cmd_passthrough)) { +eprintf ("cmd->dev->dev_type_template.cmd_passthrough()" +" is NULL!\n" ); +return SAM_STAT_CHECK_CONDITION ; + } +return cmd->dev->dev_type_template.cmd_passthrough (host_no, cmd); + }Can't you just perform this check once somewhere and set
cmd_performto the newcmd_passthrough? why check for every command?
Quoted 1 line
This is not accepted it is the hot path.
Good point..
Quoted 19 lines
usr/tgtd.h struct device_type_template { · line 112
Quoted 13 lines
usr/scsi.c +0
-0return cmd->dev->dev_type_template.ops[op].cmd_perform (host_no, cmd); }usr/tgtd.h +1
-0@@ -108,6 +108,7 @@ struct device_type_template {int (*lu_config)(struct scsi_lu *lu,char *args);int (*lu_online)(struct scsi_lu *lu);int (*lu_offline)(struct scsi_lu *lu); +int (*cmd_passthrough)(int ,struct scsi_cmd *);Actually you can do more:
If you leave the checking and decisions to the target driver then you don't need to touch this file. Just let thedevice_typedecide which vector to set once it knows what target is used.
Quoted 3 lines
(Like start with a vector that check and sets the vector to
the passthrough or the regular path, on first IO)
Ok, this makes alot more sense for a STGT backstore passthrough. I will respin the patch to let device_type decide to setup which flavour of ->cmd_perform() it would like to use and drop the scsi_cmd_perform() passthrough check, et al. for the fast path.
Thanks for your comments Boaz!
--nab