From 6822baee3fe0383828c7ec16cb14ef5fbff09f9a Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 24 Feb 2015 06:54:18 -0800 Subject: [PATCH] reconnect: we need to reset the in/out iovectors on reconnect This is a bug that has been there a long time. When we reconnect and requeue a PDU we must reset the iovectors for the task. Otherwise, any partially sent/received data when the command is reconnected would end up containing garbage. Signed-off-by: Ronnie Sahlberg --- include/iscsi-private.h | 1 + lib/connect.c | 3 +++ lib/scsi-lowlevel.c | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/include/iscsi-private.h b/include/iscsi-private.h index 17cbce8..afa6ad3 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -324,6 +324,7 @@ void iscsi_set_error(struct iscsi_context *iscsi, const char *error_string, struct scsi_iovector *iscsi_get_scsi_task_iovector_in(struct iscsi_context *iscsi, struct iscsi_in_pdu *in); struct scsi_iovector *iscsi_get_scsi_task_iovector_out(struct iscsi_context *iscsi, struct iscsi_pdu *pdu); +void scsi_task_reset_iov(struct scsi_iovector *iovector); void* iscsi_malloc(struct iscsi_context *iscsi, size_t size); void* iscsi_zmalloc(struct iscsi_context *iscsi, size_t size); diff --git a/lib/connect.c b/lib/connect.c index 6c0ed66..39ca909 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -351,6 +351,9 @@ try_again: continue; } + scsi_task_reset_iov(&pdu->scsi_cbdata.task->iovector_in); + scsi_task_reset_iov(&pdu->scsi_cbdata.task->iovector_out); + /* We pass NULL as 'd' since any databuffer has already * been converted to a task-> iovector first time this * PDU was sent. diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index f8cb71a..c41c95b 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -3817,6 +3817,14 @@ scsi_task_set_iov_in(struct scsi_task *task, struct scsi_iovec *iov, int niov) task->iovector_in.niov = niov; } +void +scsi_task_reset_iov(struct scsi_iovector *iovector) +{ + iovector->nalloc = 0; + iovector->offset = 0; + iovector->consumed = 0; +} + #define IOVECTOR_INITAL_ALLOC (16) static int