lib/iscsi: Move down spdk_iscsi_conn_read/readv_data() in a file

Move spdk_iscsi_conn_read/readv_data() down closer to the functions
which calls spdk_sock_writev().

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ie7ef649e8681efac48adcfb2da1f745660f71782
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477411
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-12-09 20:52:17 -05:00 committed by Tomasz Zawadzki
parent 18609b025f
commit 2a5d8c802e

View File

@ -930,95 +930,6 @@ spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn, const char *conn_match,
return 0;
}
/**
* \brief Reads data for the specified iSCSI connection from its TCP socket.
*
* The TCP socket is marked as non-blocking, so this function may not read
* all data requested.
*
* Returns SPDK_ISCSI_CONNECTION_FATAL if the recv() operation indicates a fatal
* error with the TCP connection (including if the TCP connection was closed
* unexpectedly.
*
* Otherwise returns the number of bytes successfully read.
*/
int
spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
void *buf)
{
int ret;
if (bytes == 0) {
return 0;
}
ret = spdk_sock_recv(conn->sock, buf, bytes);
if (ret > 0) {
spdk_trace_record(TRACE_ISCSI_READ_FROM_SOCKET_DONE, conn->id, ret, 0, 0);
return ret;
}
if (ret < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return 0;
}
/* For connect reset issue, do not output error log */
if (errno == ECONNRESET) {
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_sock_recv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
} else {
SPDK_ERRLOG("spdk_sock_recv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
}
}
/* connection closed */
return SPDK_ISCSI_CONNECTION_FATAL;
}
int
spdk_iscsi_conn_readv_data(struct spdk_iscsi_conn *conn,
struct iovec *iov, int iovcnt)
{
int ret;
if (iov == NULL || iovcnt == 0) {
return 0;
}
if (iovcnt == 1) {
return spdk_iscsi_conn_read_data(conn, iov[0].iov_len,
iov[0].iov_base);
}
ret = spdk_sock_readv(conn->sock, iov, iovcnt);
if (ret > 0) {
spdk_trace_record(TRACE_ISCSI_READ_FROM_SOCKET_DONE, conn->id, ret, 0, 0);
return ret;
}
if (ret < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return 0;
}
/* For connect reset issue, do not output error log */
if (errno == ECONNRESET) {
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_sock_readv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
} else {
SPDK_ERRLOG("spdk_sock_readv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
}
}
/* connection closed */
return SPDK_ISCSI_CONNECTION_FATAL;
}
void
spdk_iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task)
{
@ -1266,6 +1177,95 @@ spdk_iscsi_conn_handle_nop(struct spdk_iscsi_conn *conn)
}
}
/**
* \brief Reads data for the specified iSCSI connection from its TCP socket.
*
* The TCP socket is marked as non-blocking, so this function may not read
* all data requested.
*
* Returns SPDK_ISCSI_CONNECTION_FATAL if the recv() operation indicates a fatal
* error with the TCP connection (including if the TCP connection was closed
* unexpectedly.
*
* Otherwise returns the number of bytes successfully read.
*/
int
spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
void *buf)
{
int ret;
if (bytes == 0) {
return 0;
}
ret = spdk_sock_recv(conn->sock, buf, bytes);
if (ret > 0) {
spdk_trace_record(TRACE_ISCSI_READ_FROM_SOCKET_DONE, conn->id, ret, 0, 0);
return ret;
}
if (ret < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return 0;
}
/* For connect reset issue, do not output error log */
if (errno == ECONNRESET) {
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_sock_recv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
} else {
SPDK_ERRLOG("spdk_sock_recv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
}
}
/* connection closed */
return SPDK_ISCSI_CONNECTION_FATAL;
}
int
spdk_iscsi_conn_readv_data(struct spdk_iscsi_conn *conn,
struct iovec *iov, int iovcnt)
{
int ret;
if (iov == NULL || iovcnt == 0) {
return 0;
}
if (iovcnt == 1) {
return spdk_iscsi_conn_read_data(conn, iov[0].iov_len,
iov[0].iov_base);
}
ret = spdk_sock_readv(conn->sock, iov, iovcnt);
if (ret > 0) {
spdk_trace_record(TRACE_ISCSI_READ_FROM_SOCKET_DONE, conn->id, ret, 0, 0);
return ret;
}
if (ret < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return 0;
}
/* For connect reset issue, do not output error log */
if (errno == ECONNRESET) {
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_sock_readv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
} else {
SPDK_ERRLOG("spdk_sock_readv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
}
}
/* connection closed */
return SPDK_ISCSI_CONNECTION_FATAL;
}
static int
iscsi_get_pdu_length(struct spdk_iscsi_pdu *pdu, int header_digest,
int data_digest)