iscsi: Add a function to read PDU data from socket by spdk_sock_readv

This patch adds spdk_iscsi_conn_readv_data() to read PDU data
from network socket by using spdk_sock_readv().

Additionally, this patch changes the existing spdk_iscsi_conn_read_data()
to call spdk_iscsi_conn_readv_data() by creating a single struct
iovec.

Change-Id: Ied487bb71bd4261ad53c9f3744ae272e65f98d7a
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446377
Tested-by: 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-02-27 11:06:25 +09:00 committed by Changpeng Liu
parent 1ee8deae9c
commit af85c0ff68
4 changed files with 27 additions and 8 deletions

View File

@ -875,16 +875,16 @@ spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn, const char *conn_match,
* Otherwise returns the number of bytes successfully read.
*/
int
spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
void *buf)
spdk_iscsi_conn_readv_data(struct spdk_iscsi_conn *conn,
struct iovec *iov, int iovcnt)
{
int ret;
if (bytes == 0) {
if (iov == NULL || iovcnt == 0) {
return 0;
}
ret = spdk_sock_recv(conn->sock, buf, bytes);
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);
@ -898,10 +898,10 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
/* 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",
SPDK_DEBUGLOG(SPDK_LOG_ISCSI, "spdk_sock_readv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
} else {
SPDK_ERRLOG("spdk_sock_recv() failed, errno %d: %s\n",
SPDK_ERRLOG("spdk_sock_readv() failed, errno %d: %s\n",
errno, spdk_strerror(errno));
}
}
@ -910,6 +910,18 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
return SPDK_ISCSI_CONNECTION_FATAL;
}
int
spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
void *buf)
{
struct iovec iov;
iov.iov_base = buf;
iov.iov_len = bytes;
return spdk_iscsi_conn_readv_data(conn, &iov, 1);
}
void
spdk_iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task)
{

View File

@ -183,8 +183,9 @@ int spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn,
void spdk_iscsi_conn_set_min_per_core(int count);
int spdk_iscsi_conn_get_min_per_core(void);
int spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int len,
void *buf);
int spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int len, void *buf);
int spdk_iscsi_conn_readv_data(struct spdk_iscsi_conn *conn,
struct iovec *iov, int iovcnt);
void spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu);
void spdk_iscsi_conn_free_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu);

View File

@ -191,6 +191,9 @@ DEFINE_STUB_V(spdk_iscsi_task_mgmt_cpl, (struct spdk_scsi_task *scsi_task));
DEFINE_STUB(spdk_iscsi_conn_read_data, int,
(struct spdk_iscsi_conn *conn, int bytes, void *buf), 0);
DEFINE_STUB(spdk_iscsi_conn_readv_data, int,
(struct spdk_iscsi_conn *conn, struct iovec *iov, int iovcnt), 0);
void
spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
{

View File

@ -78,6 +78,9 @@ spdk_sock_close(struct spdk_sock **sock)
DEFINE_STUB(spdk_sock_recv, ssize_t,
(struct spdk_sock *sock, void *buf, size_t len), 0);
DEFINE_STUB(spdk_sock_readv, ssize_t,
(struct spdk_sock *sock, struct iovec *iov, int iovcnt), 0);
DEFINE_STUB(spdk_sock_writev, ssize_t,
(struct spdk_sock *sock, struct iovec *iov, int iovcnt), 0);