Commit 1ee8deae authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Changpeng Liu
Browse files

sock: Add spdk_sock_readv(sock, iov, iovcnt)



Add an new API spdk_sock_readv(sock, iov, iovcnt) to the sock
library. This will be used in SPDK iSCSI target first.

Implementation was done based on vcom_socket_readv in VPP.

Change-Id: I88a8f2af4856b1035165b78d76b4a4f4587b265d
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446343


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent e80efe8f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -126,6 +126,17 @@ ssize_t spdk_sock_recv(struct spdk_sock *sock, void *buf, size_t len);
 */
ssize_t spdk_sock_writev(struct spdk_sock *sock, struct iovec *iov, int iovcnt);

/**
 * Read message from the given socket to the I/O vector array.
 *
 * \param sock Socket to receive message.
 * \param iov I/O vector.
 * \param iovcnt Number of I/O vectors in the array.
 *
 * \return the length of the received message on success, -1 on failure.
 */
ssize_t spdk_sock_readv(struct spdk_sock *sock, struct iovec *iov, int iovcnt);

/**
 * Set the value used to specify the low water mark (in bytes) for this socket.
 *
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ struct spdk_net_impl {
	struct spdk_sock *(*accept)(struct spdk_sock *sock);
	int (*close)(struct spdk_sock *sock);
	ssize_t (*recv)(struct spdk_sock *sock, void *buf, size_t len);
	ssize_t (*readv)(struct spdk_sock *sock, struct iovec *iov, int iovcnt);
	ssize_t (*writev)(struct spdk_sock *sock, struct iovec *iov, int iovcnt);

	int (*set_recvlowat)(struct spdk_sock *sock, int nbytes);
+9 −0
Original line number Diff line number Diff line
@@ -372,6 +372,14 @@ spdk_posix_sock_recv(struct spdk_sock *_sock, void *buf, size_t len)
	return recv(sock->fd, buf, len, MSG_DONTWAIT);
}

static ssize_t
spdk_posix_sock_readv(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
{
	struct spdk_posix_sock *sock = __posix_sock(_sock);

	return readv(sock->fd, iov, iovcnt);
}

static ssize_t
spdk_posix_sock_writev(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
{
@@ -588,6 +596,7 @@ static struct spdk_net_impl g_posix_net_impl = {
	.accept		= spdk_posix_sock_accept,
	.close		= spdk_posix_sock_close,
	.recv		= spdk_posix_sock_recv,
	.readv		= spdk_posix_sock_readv,
	.writev		= spdk_posix_sock_writev,
	.set_recvlowat	= spdk_posix_sock_set_recvlowat,
	.set_recvbuf	= spdk_posix_sock_set_recvbuf,
+11 −1
Original line number Diff line number Diff line
@@ -129,6 +129,17 @@ spdk_sock_recv(struct spdk_sock *sock, void *buf, size_t len)
	return sock->net_impl->recv(sock, buf, len);
}

ssize_t
spdk_sock_readv(struct spdk_sock *sock, struct iovec *iov, int iovcnt)
{
	if (sock == NULL) {
		errno = EBADF;
		return -1;
	}

	return sock->net_impl->readv(sock, iov, iovcnt);
}

ssize_t
spdk_sock_writev(struct spdk_sock *sock, struct iovec *iov, int iovcnt)
{
@@ -140,7 +151,6 @@ spdk_sock_writev(struct spdk_sock *sock, struct iovec *iov, int iovcnt)
	return sock->net_impl->writev(sock, iov, iovcnt);
}


int
spdk_sock_set_recvlowat(struct spdk_sock *sock, int nbytes)
{
+31 −1
Original line number Diff line number Diff line
@@ -385,6 +385,36 @@ spdk_vpp_sock_recv(struct spdk_sock *_sock, void *buf, size_t len)
	return rc;
}

static ssize_t
spdk_vpp_sock_readv(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
{
	struct spdk_vpp_sock *sock = __vpp_sock(_sock);
	ssize_t total = 0;
	int i, rc;

	assert(sock != NULL);
	assert(g_vpp_initialized);

	for (i = 0; i < iovcnt; ++i) {
		rc = vppcom_session_read(sock->fd, iov[i].iov_base, iov[i].iov_len);
		if (rc < 0) {
			if (total > 0) {
				break;
			} else {
				errno = -rc;
				return -1;
			}
		} else {
			total += rc;
			if (rc < iov[i].iov_len) {
				/* Read less than buffer provided, no point to continue. */
				break;
			}
		}
	}
	return total;
}

static ssize_t
spdk_vpp_sock_writev(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
{
@@ -411,7 +441,6 @@ spdk_vpp_sock_writev(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
	return total;
}


/*
 * TODO: Check if there are similar parameters to configure in VPP
 * to three below.
@@ -609,6 +638,7 @@ static struct spdk_net_impl g_vpp_net_impl = {
	.accept		= spdk_vpp_sock_accept,
	.close		= spdk_vpp_sock_close,
	.recv		= spdk_vpp_sock_recv,
	.readv		= spdk_vpp_sock_readv,
	.writev		= spdk_vpp_sock_writev,
	.set_recvlowat	= spdk_vpp_sock_set_recvlowat,
	.set_recvbuf	= spdk_vpp_sock_set_recvbuf,
Loading