From 30df192634068a45fe5014236fe421dccb4e1393 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Fri, 30 Nov 2012 18:18:17 +0100 Subject: [PATCH 1/2] DATA-OUT set pdu->cmdsn appropriately set the cmdsn in the pdu struct so we can compare with maxcmdsn when sending to socket even if data-out pdus do not carry a cmdsn on the wire. if we would not set pdu->cmdsn comparsion with iscsi->maxcmdsn would cause a deadlock after maxcmdsn increases to 2^31. Signed-off-by: Peter Lieven --- lib/iscsi-command.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/iscsi-command.c b/lib/iscsi-command.c index ad8c9a5..3c85da7 100644 --- a/lib/iscsi-command.c +++ b/lib/iscsi-command.c @@ -81,7 +81,11 @@ iscsi_send_data_out(struct iscsi_context *iscsi, struct iscsi_pdu *cmd_pdu, return -1; } - pdu->scsi_cbdata.task = cmd_pdu->scsi_cbdata.task; + pdu->scsi_cbdata.task = cmd_pdu->scsi_cbdata.task; + /* set the cmdsn in the pdu struct so we can compare with + * maxcmdsn when sending to socket even if data-out pdus + * do not carry a cmdsn on the wire */ + pdu->cmdsn = cmd_pdu->cmdsn; if (tot_len == len) { flags = ISCSI_PDU_SCSI_FINAL; From 92114f5d7aedb853b73fc5dc2dca9d83e1a34301 Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Fri, 30 Nov 2012 21:06:39 +0100 Subject: [PATCH 2/2] ISCSI fix broken send logic in iscsi_scsi_async_command [v2] This fixes the IMMEDIATE_DATA_YES case if the paylaod did not fit into the first PDU and fixes no unsolicited data sent out iff IMMEDIATE_DATA_NO and INITIAL_R2T_NO. Signed-off-by: Peter Lieven --- lib/iscsi-command.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/iscsi-command.c b/lib/iscsi-command.c index 3c85da7..a97dc46 100644 --- a/lib/iscsi-command.c +++ b/lib/iscsi-command.c @@ -207,6 +207,7 @@ iscsi_scsi_command_async(struct iscsi_context *iscsi, int lun, if (len > iscsi->first_burst_length) { len = iscsi->first_burst_length; + flags &= ~ISCSI_PDU_SCSI_FINAL; } pdu->out_offset = 0; @@ -253,8 +254,11 @@ iscsi_scsi_command_async(struct iscsi_context *iscsi, int lun, } /* Can we send some unsolicited data ? */ - if (pdu->out_len != 0 && iscsi->use_initial_r2t == ISCSI_INITIAL_R2T_NO && iscsi->use_immediate_data == ISCSI_IMMEDIATE_DATA_NO) { - uint32_t len = task->expxferlen - pdu->out_len; + if (task->xfer_dir == SCSI_XFER_WRITE + && iscsi->use_initial_r2t == ISCSI_INITIAL_R2T_NO + && iscsi->use_immediate_data == ISCSI_IMMEDIATE_DATA_NO) { + + uint32_t len = task->expxferlen; if (len > iscsi->first_burst_length) { len = iscsi->first_burst_length;