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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Alexander Nezhinsky <nezhinsky@xxxxxxxxx>

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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux