diff mbox

[RFC,09/13] usb f_tcm: remove transport_send_check_condition_and_sense use

Message ID 1496263970-7632-10-git-send-email-mchristi@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mike Christie May 31, 2017, 8:52 p.m. UTC
The usb submission failure path seems like it is broken because:

1. transport_send_check_condition_and_sense is called with from_transport=1
so the scsi sense value passed to it is not set. We just call queue_status
and it looks like we will return a successful status.

2. It looks like if the cmd is not supported in get_cmd_dir we wanted
to return a unsupported opcode error, but that error does not make
sense for target_submit_cmd failures.

To try and fail/cleanup the failed command, it relies on target_submit_cmd
calling at least transport_init_se_cmd which seems like too much info
for a fabric driver to have.

This syncs f_tcm's submission failure handling with other fabric
drivers. Instead of faking setup or assuming it is partially setup
on failure, this patch just has f_tcm setup the sense, send it
and release what it has allocated.

It also fixes the sense code used for targe t_submit_cmd failures since
the TCM_UNSUPPORTED_SCSI_OPCODE was only supposed to be for when when
get_cmd_dir failed.

Signed-off-by: Mike Christie <mchristi@redhat.com>
---
 drivers/usb/gadget/function/f_tcm.c | 38 +++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)
diff mbox

Patch

diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
index a82e2bd..b3dc7e8 100644
--- a/drivers/usb/gadget/function/f_tcm.c
+++ b/drivers/usb/gadget/function/f_tcm.c
@@ -1033,10 +1033,13 @@  static int usbg_send_read_response(struct se_cmd *se_cmd)
 		return uasp_send_read_response(cmd);
 }
 
+static void usbg_release_cmd(struct se_cmd *);
+
 static void usbg_cmd_work(struct work_struct *work)
 {
 	struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work);
 	struct se_cmd *se_cmd;
+	sense_reason_t failure_reason;
 	struct tcm_usbg_nexus *tv_nexus;
 	struct usbg_tpg *tpg;
 	int dir, flags = (TARGET_SCF_UNKNOWN_SIZE | TARGET_SCF_ACK_KREF);
@@ -1046,24 +1049,24 @@  static void usbg_cmd_work(struct work_struct *work)
 	tv_nexus = tpg->tpg_nexus;
 	dir = get_cmd_dir(cmd->cmd_buf);
 	if (dir < 0) {
-		transport_init_se_cmd(se_cmd,
-				tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo,
-				tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE,
-				cmd->prio_attr, cmd->sense_iu.sense);
+		failure_reason = TCM_UNSUPPORTED_SCSI_OPCODE;
 		goto out;
 	}
 
 	if (target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, cmd->cmd_buf,
 			      cmd->sense_iu.sense, cmd->unpacked_lun, 0,
-			      cmd->prio_attr, dir, flags) < 0)
+			      cmd->prio_attr, dir, flags) < 0) {
+		failure_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 		goto out;
+	}
 
 	return;
 
 out:
-	transport_send_check_condition_and_sense(se_cmd,
-			TCM_UNSUPPORTED_SCSI_OPCODE, 1);
-	transport_generic_free_cmd(&cmd->se_cmd, 0);
+	se_cmd->sense_buffer = cmd->sense_iu.sense;
+	transport_setup_sense(se_cmd, failure_reason);
+	usbg_send_status_response(&cmd->se_cmd);
+	usbg_release_cmd(&cmd->se_cmd);
 }
 
 static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu,
@@ -1086,8 +1089,6 @@  static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu,
 	return cmd;
 }
 
-static void usbg_release_cmd(struct se_cmd *);
-
 static int usbg_submit_command(struct f_uas *fu,
 		void *cmdbuf, unsigned int len)
 {
@@ -1165,6 +1166,7 @@  static void bot_cmd_work(struct work_struct *work)
 {
 	struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work);
 	struct se_cmd *se_cmd;
+	sense_reason_t failure_reason;
 	struct tcm_usbg_nexus *tv_nexus;
 	struct usbg_tpg *tpg;
 	int dir;
@@ -1174,24 +1176,24 @@  static void bot_cmd_work(struct work_struct *work)
 	tv_nexus = tpg->tpg_nexus;
 	dir = get_cmd_dir(cmd->cmd_buf);
 	if (dir < 0) {
-		transport_init_se_cmd(se_cmd,
-				tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo,
-				tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE,
-				cmd->prio_attr, cmd->sense_iu.sense);
+		failure_reason = TCM_UNSUPPORTED_SCSI_OPCODE;
 		goto out;
 	}
 
 	if (target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess,
 			cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun,
-			cmd->data_len, cmd->prio_attr, dir, 0) < 0)
+			cmd->data_len, cmd->prio_attr, dir, 0) < 0) {
+		failure_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 		goto out;
+	}
 
 	return;
 
 out:
-	transport_send_check_condition_and_sense(se_cmd,
-				TCM_UNSUPPORTED_SCSI_OPCODE, 1);
-	transport_generic_free_cmd(&cmd->se_cmd, 0);
+	se_cmd->sense_buffer = cmd->sense_iu.sense;
+	transport_setup_sense(se_cmd, failure_reason);
+	usbg_send_status_response(&cmd->se_cmd);
+	usbg_release_cmd(&cmd->se_cmd);
 }
 
 static int bot_submit_command(struct f_uas *fu,