From 2f94f16d02d25e980f8f9038b39ed5e98b697a87 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 22 Mar 2015 08:20:29 -0700 Subject: [PATCH] iovectors: don't reset nalloc when resetting an iovector Don't reset nalloc when resetting an iovector during reconnect. Resetting offset/consumed should be sufficient. Also, don't reset the iovectors when we detect an error condition in iscsi_iovector_readv_writev. If there is a bug feeding an invalid pos into this function, where pos suddently points before the amount of data we have already read/written, then singlan this as an error and return -EINVAL. Previosly we did not reset the iovectors correctly when we re-queued PDUs after a reconnect and thus relied on the iovectors being automatically reset if/when we detected this type of error in readv_writev. Now we do reset the iovectors properly so we do nt need to atuo reset them here anymore and we can change this check to test for and abort the transfer if an error is detected. Signed-off-by: Ronnie Sahlberg --- lib/scsi-lowlevel.c | 1 - lib/socket.c | 13 ++++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index c41c95b..e1ebb20 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -3820,7 +3820,6 @@ scsi_task_set_iov_in(struct scsi_task *task, struct scsi_iovec *iov, int niov) void scsi_task_reset_iov(struct scsi_iovector *iovector) { - iovector->nalloc = 0; iovector->offset = 0; iovector->consumed = 0; } diff --git a/lib/socket.c b/lib/socket.c index 7020c5a..92ed5bf 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -420,9 +420,10 @@ iscsi_iovector_readv_writev(struct iscsi_context *iscsi, struct scsi_iovector *i } if (pos < iovector->offset) { - /* start over in case we are going backwards */ - iovector->offset = 0; - iovector->consumed = 0; + iscsi_set_error(iscsi, "iovector reset. pos is smaller than" + "current offset"); + errno = EINVAL; + return -1; } if (iovector->niov <= iovector->consumed) { @@ -578,7 +579,8 @@ iscsi_read_from_socket(struct iscsi_context *iscsi) return 0; } iscsi_set_error(iscsi, "read from socket failed, " - "errno:%d", errno); + "errno:%d %s", errno, + iscsi_get_error(iscsi)); return -1; } @@ -689,7 +691,8 @@ iscsi_write_to_socket(struct iscsi_context *iscsi) return 0; } iscsi_set_error(iscsi, "Error when writing to " - "socket :%d", errno); + "socket :%d %s", errno, + iscsi_get_error(iscsi)); return -1; }