Commit 4b100294 authored by Jim Harris's avatar Jim Harris
Browse files

net, iscsi: add struct spdk_sock abstraction



This provides an abstraction layer around TCP
sockets.  Previously we just used fd integers, but
we don't want to be tied to integers for alternative
userspace TCP stacks.

Future patches will do more work to enable multiple
implementations of this abstraction.  For now, just
get the abstraction in place for POSIX sockets and
make all of the iSCSI changes associated with it.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I9a825e9e02eb6927c8702d205665c626f57b3771

Reviewed-on: https://review.gerrithub.io/398861


Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatar <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarZiye Yang <optimistyzy@gmail.com>
parent a1e1b9a5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -46,12 +46,14 @@
extern "C" {
#endif

struct spdk_sock;

int spdk_interface_init(void);
void spdk_interface_destroy(void);

const char *spdk_net_framework_get_name(void);
int spdk_net_framework_start(void);
void spdk_net_framework_clear_socket_association(int sock);
void spdk_net_framework_clear_socket_association(struct spdk_sock *sock);
void spdk_net_framework_fini(void);

#define SPDK_IFNAMSIZE		32
+14 −12
Original line number Diff line number Diff line
@@ -44,20 +44,22 @@
extern "C" {
#endif

int spdk_sock_getaddr(int sock, char *saddr, int slen, char *caddr, int clen);
int spdk_sock_connect(const char *ip, int port);
int spdk_sock_listen(const char *ip, int port);
int spdk_sock_accept(int sock);
int spdk_sock_close(int sock);
ssize_t spdk_sock_recv(int sock, void *buf, size_t len);
ssize_t spdk_sock_writev(int sock, struct iovec *iov, int iovcnt);
struct spdk_sock;

int spdk_sock_set_recvlowat(int sock, int nbytes);
int spdk_sock_set_recvbuf(int sock, int sz);
int spdk_sock_set_sendbuf(int sock, int sz);
int spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, char *caddr, int clen);
struct spdk_sock *spdk_sock_connect(const char *ip, int port);
struct spdk_sock *spdk_sock_listen(const char *ip, int port);
struct spdk_sock *spdk_sock_accept(struct spdk_sock *sock);
int spdk_sock_close(struct spdk_sock **sock);
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);

bool spdk_sock_is_ipv6(int sock);
bool spdk_sock_is_ipv4(int sock);
int spdk_sock_set_recvlowat(struct spdk_sock *sock, int nbytes);
int spdk_sock_set_recvbuf(struct spdk_sock *sock, int sz);
int spdk_sock_set_sendbuf(struct spdk_sock *sock, int sz);

bool spdk_sock_is_ipv6(struct spdk_sock *sock);
bool spdk_sock_is_ipv4(struct spdk_sock *sock);

#ifdef __cplusplus
}
+6 −6
Original line number Diff line number Diff line
@@ -49,19 +49,19 @@ static void
spdk_iscsi_portal_accept(void *arg)
{
	struct spdk_iscsi_portal	*portal = arg;
	int				rc, sock;
	struct spdk_sock		*sock;
	int				rc;

	if (portal->sock < 0) {
	if (portal->sock == NULL) {
		return;
	}

	while (1) {
		rc = spdk_sock_accept(portal->sock);
		if (rc >= 0) {
			sock = rc;
		sock = spdk_sock_accept(portal->sock);
		if (sock != NULL) {
			rc = spdk_iscsi_conn_construct(portal, sock);
			if (rc < 0) {
				spdk_sock_close(sock);
				spdk_sock_close(&sock);
				SPDK_ERRLOG("spdk_iscsi_connection_construct() failed\n");
				break;
			}
+6 −6
Original line number Diff line number Diff line
@@ -391,7 +391,7 @@ int spdk_initialize_iscsi_conns(void)
 */
int
spdk_iscsi_conn_construct(struct spdk_iscsi_portal *portal,
			  int sock)
			  struct spdk_sock *sock)
{
	struct spdk_iscsi_conn *conn;
	int bufsize, i, rc;
@@ -692,7 +692,7 @@ void spdk_iscsi_conn_destruct(struct spdk_iscsi_conn *conn)
	}

	spdk_clear_all_transfer_task(conn, NULL);
	spdk_sock_close(conn->sock);
	spdk_sock_close(&conn->sock);
	spdk_poller_unregister(&conn->logout_timer);
	spdk_poller_unregister(&conn->flush_poller);

@@ -895,8 +895,8 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
		if (errno == EAGAIN || errno == EWOULDBLOCK) {
			return 0;
		} else {
			SPDK_ERRLOG("spdk_sock_recv() failed (fd=%d), errno %d: %s\n",
				    conn->sock, errno, spdk_strerror(errno));
			SPDK_ERRLOG("spdk_sock_recv() failed, errno %d: %s\n",
				    errno, spdk_strerror(errno));
		}
		return SPDK_ISCSI_CONNECTION_FATAL;
	}
@@ -1152,8 +1152,8 @@ spdk_iscsi_conn_flush_pdus_internal(struct spdk_iscsi_conn *conn)
		if (errno == EWOULDBLOCK || errno == EAGAIN) {
			return 1;
		} else {
			SPDK_ERRLOG("spdk_sock_writev() failed (fd=%d), errno %d: %s\n",
				    conn->sock, errno, spdk_strerror(errno));
			SPDK_ERRLOG("spdk_sock_writev() failed, errno %d: %s\n",
				    errno, spdk_strerror(errno));
			return -1;
		}
	}
+2 −2
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ struct spdk_iscsi_conn {
	char				*portal_port;
	struct spdk_cpuset		*portal_cpumask;
	uint32_t			lcore;
	int				sock;
	struct spdk_sock		*sock;
	struct spdk_iscsi_sess		*sess;

	enum iscsi_connection_state	state;
@@ -171,7 +171,7 @@ extern struct spdk_iscsi_conn *g_conns_array;
int spdk_initialize_iscsi_conns(void);
void spdk_shutdown_iscsi_conns(void);

int spdk_iscsi_conn_construct(struct spdk_iscsi_portal *portal, int sock);
int spdk_iscsi_conn_construct(struct spdk_iscsi_portal *portal, struct spdk_sock *sock);
void spdk_iscsi_conn_destruct(struct spdk_iscsi_conn *conn);
void spdk_iscsi_conn_logout(struct spdk_iscsi_conn *conn);
int spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn,
Loading