diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index 4f7e2b4120..9666c3b76e 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -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) { diff --git a/lib/iscsi/conn.h b/lib/iscsi/conn.h index ac372339ea..8e7ec6dfcf 100644 --- a/lib/iscsi/conn.h +++ b/lib/iscsi/conn.h @@ -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); diff --git a/test/unit/lib/iscsi/common.c b/test/unit/lib/iscsi/common.c index 6a353f3c66..758dbec205 100644 --- a/test/unit/lib/iscsi/common.c +++ b/test/unit/lib/iscsi/common.c @@ -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) { diff --git a/test/unit/lib/iscsi/conn.c/conn_ut.c b/test/unit/lib/iscsi/conn.c/conn_ut.c index e6ebeae77f..e0468b7e02 100644 --- a/test/unit/lib/iscsi/conn.c/conn_ut.c +++ b/test/unit/lib/iscsi/conn.c/conn_ut.c @@ -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);