From 2a5d8c802ebaeb75510c286e71f9d0474034aa27 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 9 Dec 2019 20:52:17 -0500 Subject: [PATCH] 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 Change-Id: Ie7ef649e8681efac48adcfb2da1f745660f71782 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/477411 Tested-by: SPDK CI Jenkins Community-CI: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- lib/iscsi/conn.c | 178 +++++++++++++++++++++++------------------------ 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index 59753a5b1b..d23f7826da 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -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)