[stgt] [PATCH v2 2/2] Create tx pdu by explicit scsi cmd dir (none, rd, wr, bidir)

nezhinsky at gmail.com nezhinsky at gmail.com
Tue Jun 4 14:06:23 CEST 2013


From: Alexander Nezhinsky <nezhinsky at gmail.com>

Differentiating between various possible cases for tx pdus
(r2t, data-in and scsi_response) has been made using a set of
predicates, some of which are relevant only for a specific
cmd direction types.
Although possibly correct when all counters and flags used
are up-to-date, this may be dangerous and hard to debug.
Explicit check of cmd type allows discriminating only between
the choices feasible for each cmd type.
---
 usr/iscsi/iscsid.c |   33 ++++++++++++++++++++++++++++-----
 1 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index e1180fb..260989f 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -1785,14 +1785,37 @@ static int iscsi_task_rx_start(struct iscsi_connection *conn)
 
 static int iscsi_scsi_cmd_tx_start(struct iscsi_task *task)
 {
+	enum data_direction data_dir = scsi_get_data_dir(&task->scmd);
 	int err = 0;
 
-	if (task->r2t_count)
-		err = iscsi_r2t_build(task);
-	else if (task->offset < scsi_get_in_transfer_len(&task->scmd))
-		err = iscsi_data_rsp_build(task);
-	else
+	switch (data_dir) {
+	case DATA_NONE:
 		err = iscsi_cmd_rsp_build(task);
+		break;
+	case DATA_READ:
+		if (task->offset < scsi_get_in_transfer_len(&task->scmd))
+			err = iscsi_data_rsp_build(task);
+		else
+			err = iscsi_cmd_rsp_build(task);
+		break;
+	case DATA_WRITE:
+		if (task->r2t_count)
+			err = iscsi_r2t_build(task);
+		else
+			err = iscsi_cmd_rsp_build(task);
+		break;
+	case DATA_BIDIRECTIONAL:
+		if (task->r2t_count)
+			err = iscsi_r2t_build(task);
+		else if (task->offset < scsi_get_in_transfer_len(&task->scmd))
+			err = iscsi_data_rsp_build(task);
+		else
+			err = iscsi_cmd_rsp_build(task);
+		break;
+	default:
+		eprintf("Unexpected data_dir %d task %p\n", data_dir, task);
+		exit(-1);
+	}
 
 	return err;
 }
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list