Improve reporting of connection problems in iscsid(8).

Obtained from:	Mellanox Technologies
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Edward Tomasz Napierala 2016-01-27 18:12:42 +00:00
parent 4644fda3f7
commit 7aebc1bce2

View File

@ -34,7 +34,9 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/uio.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "iscsid.h"
@ -177,18 +179,23 @@ pdu_padding(const struct pdu *pdu)
}
static void
pdu_read(int fd, char *data, size_t len)
pdu_read(const struct connection *conn, char *data, size_t len)
{
ssize_t ret;
while (len > 0) {
ret = read(fd, data, len);
ret = read(conn->conn_socket, data, len);
if (ret < 0) {
if (timed_out())
if (timed_out()) {
fail(conn, "Login Phase timeout");
log_errx(1, "exiting due to timeout");
}
fail(conn, strerror(errno));
log_err(1, "read");
} else if (ret == 0)
} else if (ret == 0) {
fail(conn, "connection lost");
log_errx(1, "read: connection lost");
}
len -= ret;
data += ret;
}
@ -207,7 +214,7 @@ pdu_receive(struct pdu *pdu)
assert(pdu->pdu_connection->conn_conf.isc_iser == 0);
pdu_read(pdu->pdu_connection->conn_socket,
pdu_read(pdu->pdu_connection,
(char *)pdu->pdu_bhs, sizeof(*pdu->pdu_bhs));
len = pdu_ahs_length(pdu);
@ -227,13 +234,13 @@ pdu_receive(struct pdu *pdu)
if (pdu->pdu_data == NULL)
log_err(1, "malloc");
pdu_read(pdu->pdu_connection->conn_socket,
pdu_read(pdu->pdu_connection,
(char *)pdu->pdu_data, pdu->pdu_data_len);
padding = pdu_padding(pdu);
if (padding != 0) {
assert(padding < sizeof(dummy));
pdu_read(pdu->pdu_connection->conn_socket,
pdu_read(pdu->pdu_connection,
(char *)dummy, padding);
}
}