Skip to contentSkip to conversation

: Add proper STGT LUN backstore passthrough support

PATCH In review Nicholas A. Bellinger 2 participants 2 messages Jun 1, 2010 – Jun 4, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 : Add proper STGT LUN backstore passthrough support

From: Nicholas Bellinger <[email protected]>

This patch adds two new queueing and completion function pointers to struct scsi_lu called ->cmd_perform() and ->cmd_done() for handling existing internal STGT port emulation and the struct scsi_cmd passthrough with bs_sg.c. It retains the struct device_type_template->cmd_passthrough() from the original patches, which still appears to be necessary for a device type to perform passthrough. Also as before we modify the struct device_type_template sbc_template->cmd_passthrough() for sbc.c / TYPE_DISK that we want to use passthrough for bs_sg LUNs.

For the setup path, we update tgt_device_create() to check if lu->cmd_perform() and lu->cmd_done() have been set by struct backingstore_template->bs_init(). We expect bs_sg to setup these pointers for us using the new target_cmd_perform_passthrough() and __cmd_done_passthrough() (see below). Otherwise we setup the pointers following existing logic with target_cmd_perform() (also below) and __cmd_done() for the non bs_sg case.

For the queue path and struct scsi_lu->cmd_perform() it made sense to split up target_cmd_queue() into two functions, the original code at the tail of target_cmd_queue() now becomes target_cmd_perform() and calls existing STGT port emulation code via cmd_enabled() -> scsi_cmd_perform(). A new function for passthrough has been added called target_cmd_perform_passthrough() that will do struct scsi_lu->dev_type_template.cmd_passthrough() into the device type for bs_sg LUNs.

For the completion path and struct scsi_lu->cmd_done(), a new __cmd_done_passthrough() has been added minus the original cmd_hlist_remove() and SCSI TASK attr checking in __cmd_done(). __cmd_done() is used for the existing port emulation case, and modify the two original users target_cmd_lookup() and abort_cmd() to call cmd->dev->cmd_done() instead.

This patch has been tested with STGT/iSCSI and TCM_Loop SPC-4 iSCSI Target Port emulation.

---
 usr/sbc.c    |    1 +
 usr/target.c |   92 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 usr/tgtd.h   |   15 +++++++++
 3 files changed, 100 insertions(+), 8 deletions(-)
usr/sbc.c +1 -0
index a048d53..d53f7f9 100644
@@ -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/target.c +84 -8

153 lines not on this page · raw message

usr/tgtd.h +15 -0
index 3323a9b..ff3c5da 100644
@@ -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];
 
@@ -178,6 +179,17 @@ struct scsi_lu {
 	 * Currently used by ssc, smc and mmc modules.
 	 */
 	void *xxc_p;
+	/*
+	 * Used internally for usr/target.c:target_cmd_perform() and with
+	 * passthrough CMD processing with
+	 * struct device_type_template->cmd_passthrough().
+	 */
+	int (*cmd_perform)(int, struct scsi_cmd *);
+	/*
+	 * Used internally for usr/target.c:__cmd_done() and with
+	 * passthrough CMD processing with __cmd_done_passthrough()
+	 */
+	void (*cmd_done)(struct target *, struct scsi_cmd *);
 };
 
 struct mgmt_req {
@@ -250,7 +262,10 @@ extern void tgt_remove_sched_event(struct event_data *evt);
 
 extern int tgt_event_modify(int fd, int events);
 extern int target_cmd_queue(int tid, struct scsi_cmd *cmd);
+extern int target_cmd_perform(int tid, struct scsi_cmd *cmd);
+extern int target_cmd_perform_passthrough(int tid, struct scsi_cmd *cmd);
 extern void target_cmd_done(struct scsi_cmd *cmd);
+extern void __cmd_done_passthrough(struct target *target, struct scsi_cmd *cmd);
 struct scsi_cmd *target_cmd_lookup(int tid, uint64_t itn_id, uint64_t tag);
 
 extern enum mgmt_req_result target_mgmt_request(int tid, uint64_t itn_id,
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 3 lines · On Tue, 1 Jun 2010 01:50:45 -0700 "Nicholas A. Bellinger"…

This patch adds two new queueing and completion function pointers to struct scsi_lu called ->cmd_perform() and ->cmd_done() for handling existing internal STGT port emulation and the struct scsi_cmd

Using new function pointers look fine. However, have you tried the existing non passthrough code? This patch seems to break it. I've not looked at the details though.

I don't think you need to touch to sbc.c. we should not need to know the type of underlying devices with passthough. Can you add a new device type such as struct device_type_template sg_template?

__cmd_done_passthrough() doesn't need to call post_cmd_done(), I think because post_cmd_done() checks the pending commands. With passthrough, there is no pending commands.

Thanks,