VPP: change sockets from FIONBIO to O_NONBLOCK type
There are two ways to set stockets to nonblocking type: - ioctl with FIONBIO - fcntl with O_NONBLOCK Those two should be equivalent for sockets used in SPDK. During testing it was shown that VPP interprets only the second type, so this patch changes all occurences of it. When here, more descriptive error logs were set in case of failure. Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: Ifa5b30e3a4fa04fe23f41fa2ae9dab4b01dd7d3c Reviewed-on: https://review.gerrithub.io/388816 Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
962fdadfb8
commit
161a300275
@ -40,7 +40,7 @@ spdk_jsonrpc_server_listen(int domain, int protocol,
|
||||
spdk_jsonrpc_handle_request_fn handle_request)
|
||||
{
|
||||
struct spdk_jsonrpc_server *server;
|
||||
int rc, val;
|
||||
int rc, val, flag;
|
||||
char buf[64];
|
||||
|
||||
server = calloc(1, sizeof(struct spdk_jsonrpc_server));
|
||||
@ -63,10 +63,10 @@ spdk_jsonrpc_server_listen(int domain, int protocol,
|
||||
setsockopt(server->sockfd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
|
||||
}
|
||||
|
||||
val = 1;
|
||||
rc = ioctl(server->sockfd, FIONBIO, &val);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("ioctl(FIONBIO) failed\n");
|
||||
flag = fcntl(server->sockfd, F_GETFL);
|
||||
if (fcntl(server->sockfd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", server->sockfd, buf);
|
||||
close(server->sockfd);
|
||||
free(server);
|
||||
return NULL;
|
||||
@ -136,7 +136,8 @@ static int
|
||||
spdk_jsonrpc_server_accept(struct spdk_jsonrpc_server *server)
|
||||
{
|
||||
struct spdk_jsonrpc_server_conn *conn;
|
||||
int rc, conn_idx, nonblock;
|
||||
int rc, conn_idx, flag;
|
||||
char buf[64];
|
||||
|
||||
rc = accept(server->sockfd, NULL, NULL);
|
||||
if (rc >= 0) {
|
||||
@ -156,10 +157,10 @@ spdk_jsonrpc_server_accept(struct spdk_jsonrpc_server *server)
|
||||
return -1;
|
||||
}
|
||||
|
||||
nonblock = 1;
|
||||
rc = ioctl(conn->sockfd, FIONBIO, &nonblock);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("ioctl(FIONBIO) failed\n");
|
||||
flag = fcntl(conn->sockfd, F_GETFL);
|
||||
if (fcntl(conn->sockfd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", conn->sockfd, buf);
|
||||
close(conn->sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -390,6 +390,7 @@ spdk_nbd_start(struct spdk_bdev *bdev, const char *nbd_path)
|
||||
int rc;
|
||||
int sp[2];
|
||||
char buf[64];
|
||||
int flag;
|
||||
|
||||
nbd = calloc(1, sizeof(*nbd));
|
||||
if (nbd == NULL) {
|
||||
@ -462,7 +463,12 @@ spdk_nbd_start(struct spdk_bdev *bdev, const char *nbd_path)
|
||||
goto err;
|
||||
}
|
||||
|
||||
fcntl(nbd->spdk_sp_fd, F_SETFL, O_NONBLOCK);
|
||||
flag = fcntl(nbd->spdk_sp_fd, F_GETFL);
|
||||
if (fcntl(nbd->spdk_sp_fd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", nbd->spdk_sp_fd, buf);
|
||||
goto err;
|
||||
}
|
||||
|
||||
to_be32(&nbd->io.resp.magic, NBD_REPLY_MAGIC);
|
||||
nbd->io.req_in_progress = true;
|
||||
|
@ -128,7 +128,7 @@ spdk_sock_create(const char *ip, int port, enum spdk_sock_create_type type)
|
||||
char portnum[PORTNUMLEN];
|
||||
char *p;
|
||||
struct addrinfo hints, *res, *res0;
|
||||
int sock, nonblock;
|
||||
int sock, flag;
|
||||
int val = 1;
|
||||
int rc;
|
||||
|
||||
@ -218,10 +218,9 @@ retry:
|
||||
}
|
||||
}
|
||||
|
||||
nonblock = 1;
|
||||
rc = ioctl(sock, FIONBIO, &nonblock);
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("ioctl(FIONBIO) failed\n");
|
||||
flag = fcntl(sock, F_GETFL);
|
||||
if (fcntl(sock, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%d)\n", sock, errno);
|
||||
close(sock);
|
||||
sock = -1;
|
||||
break;
|
||||
|
@ -49,10 +49,10 @@ int
|
||||
spdk_uevent_connect(void)
|
||||
{
|
||||
struct sockaddr_nl addr;
|
||||
int ret;
|
||||
int netlink_fd;
|
||||
int size = 64 * 1024;
|
||||
int nonblock = 1;
|
||||
char buf[64];
|
||||
int flag;
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.nl_family = AF_NETLINK;
|
||||
@ -65,9 +65,10 @@ spdk_uevent_connect(void)
|
||||
|
||||
setsockopt(netlink_fd, SOL_SOCKET, SO_RCVBUFFORCE, &size, sizeof(size));
|
||||
|
||||
ret = ioctl(netlink_fd, FIONBIO, &nonblock);
|
||||
if (ret != 0) {
|
||||
SPDK_ERRLOG("ioctl(FIONBIO) failed\n");
|
||||
flag = fcntl(netlink_fd, F_GETFL);
|
||||
if (fcntl(netlink_fd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n", netlink_fd, buf);
|
||||
close(netlink_fd);
|
||||
return -1;
|
||||
}
|
||||
|
@ -1145,6 +1145,7 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_tgt *tgt)
|
||||
struct ibv_context **contexts;
|
||||
uint32_t i;
|
||||
char buf[64];
|
||||
int flag;
|
||||
|
||||
rtransport = calloc(1, sizeof(*rtransport));
|
||||
if (!rtransport) {
|
||||
@ -1172,9 +1173,11 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_tgt *tgt)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = fcntl(rtransport->event_channel->fd, F_SETFL, O_NONBLOCK);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("fcntl to set fd to non-blocking failed\n");
|
||||
flag = fcntl(rtransport->event_channel->fd, F_GETFL);
|
||||
if (fcntl(rtransport->event_channel->fd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||
spdk_strerror_r(errno, buf, sizeof(buf));
|
||||
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n",
|
||||
rtransport->event_channel->fd, buf);
|
||||
free(rtransport);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user