Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log necessary message on internal reconnect #403

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,20 +516,22 @@ iscsi_out_queue_length(struct iscsi_context *iscsi)
ssize_t
iscsi_iovector_readv_writev(struct iscsi_context *iscsi, struct scsi_iovector *iovector, uint32_t pos, ssize_t count, int do_write)
{
struct scsi_iovec *iov, *iov2;
int niov;
uint32_t len2;
size_t _len2;
ssize_t n;

if (iovector->iov == NULL) {
struct scsi_iovec *iov, *iov2;
int niov;
uint32_t len2;
size_t _len2;
ssize_t n;
const char *rw = do_write ? "write" : "read";

if (iovector->iov == NULL) {
iscsi_set_error(iscsi, "%s: iovector empty buffer", rw);
errno = EINVAL;
return -1;
}

if (pos < iovector->offset) {
iscsi_set_error(iscsi, "iovector reset. pos is smaller than"
"current offset");
iscsi_set_error(iscsi, "%s: iovector reset. pos(%d) is smaller than"
"current offset(%ld)", rw, pos, iovector->offset);
errno = EINVAL;
return -1;
}
Expand All @@ -538,6 +540,8 @@ iscsi_iovector_readv_writev(struct iscsi_context *iscsi, struct scsi_iovector *i
/* someone issued a read/write but did not provide enough user buffers for all the data.
* maybe someone tried to read just 512 bytes off a MMC device?
*/
iscsi_set_error(iscsi, "%s: iovector consumed(%d) exceeds niov(%d)",
rw, iovector->consumed, iovector->niov);
errno = EINVAL;
return -1;
}
Expand All @@ -552,6 +556,8 @@ iscsi_iovector_readv_writev(struct iscsi_context *iscsi, struct scsi_iovector *i
iovector->consumed++;
pos -= iov->iov_len;
if (iovector->niov <= iovector->consumed) {
iscsi_set_error(iscsi, "%s: iovector consumed(%d) exceeds niov(%d) on head",
rw, iovector->consumed, iovector->niov);
errno = EINVAL;
return -1;
}
Expand All @@ -567,6 +573,9 @@ iscsi_iovector_readv_writev(struct iscsi_context *iscsi, struct scsi_iovector *i
while (len2 > iov2->iov_len) {
niov++;
if (iovector->niov < iovector->consumed + niov) {
iscsi_set_error(iscsi, "%s: iovector consumed(%d) + niov(%d)"
" exceeds niov(%d) on tail",
rw, iovector->consumed, niov, iovector->niov);
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -599,6 +608,9 @@ iscsi_iovector_readv_writev(struct iscsi_context *iscsi, struct scsi_iovector *i
errno = EINVAL;
return -1;
}
if ((n <= 0) && (errno != EAGAIN) && (errno == EINTR)) {
iscsi_set_error(iscsi, "%s: socket failed, errno:%d", rw, errno);
}
return n;
}

Expand Down Expand Up @@ -692,9 +704,6 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
if (errno == EINTR || errno == EAGAIN) {
break;
}
iscsi_set_error(iscsi, "read from socket failed, "
"errno:%d %s", errno,
iscsi_get_error(iscsi));
return -1;
}
in->data_pos += count;
Expand Down Expand Up @@ -844,9 +853,6 @@ iscsi_write_to_socket(struct iscsi_context *iscsi)
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return 0;
}
iscsi_set_error(iscsi, "Error when writing to "
"socket :%d %s", errno,
iscsi_get_error(iscsi));
return -1;
}

Expand Down Expand Up @@ -993,11 +999,13 @@ iscsi_tcp_service(struct iscsi_context *iscsi, int revents)

if (revents & POLLIN) {
if (iscsi_read_from_socket(iscsi) != 0) {
ISCSI_LOG(iscsi, 1, "%s", iscsi_get_error(iscsi));
return iscsi_service_reconnect_if_loggedin(iscsi);
}
}
if (revents & POLLOUT) {
if (iscsi_write_to_socket(iscsi) != 0) {
ISCSI_LOG(iscsi, 1, "%s", iscsi_get_error(iscsi));
return iscsi_service_reconnect_if_loggedin(iscsi);
}
}
Expand Down