Skip to content

Commit

Permalink
lib/vhost: add flag for async connection in client mode
Browse files Browse the repository at this point in the history
This patch introduces a new flag RTE_VHOST_USER_ASYNC_CONNECT,
which in combination with the flag RTE_VHOST_USER_CLIENT makes
rte_vhost_driver_start connect asynchronously to the vhost server.

Signed-off-by: Daniil Ushkov <daniil.ushkov@yandex.ru>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
daniil-ushkov authored and ovsrobot committed May 14, 2024
1 parent 7e06c0d commit 5e96710
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/vhost/rte_vhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern "C" {
#define RTE_VHOST_USER_ASYNC_COPY (1ULL << 7)
#define RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS (1ULL << 8)
#define RTE_VHOST_USER_NET_STATS_ENABLE (1ULL << 9)
#define RTE_VHOST_USER_ASYNC_CONNECT (1ULL << 10)

/* Features. */
#ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
Expand Down
28 changes: 16 additions & 12 deletions lib/vhost/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct vhost_user_socket {
bool async_copy;
bool net_compliant_ol_flags;
bool stats_enabled;
bool async_connect;

/*
* The "supported_features" indicates the feature bits the
Expand Down Expand Up @@ -533,21 +534,23 @@ vhost_user_start_client(struct vhost_user_socket *vsocket)
const char *path = vsocket->path;
struct vhost_user_reconnect *reconn;

ret = vhost_user_connect_nonblock(vsocket->path, fd, (struct sockaddr *)&vsocket->un,
sizeof(vsocket->un));
if (ret == 0) {
vhost_user_add_connection(fd, vsocket);
return 0;
}
if (!vsocket->async_connect || !vsocket->reconnect) {
ret = vhost_user_connect_nonblock(vsocket->path, fd,
(struct sockaddr *)&vsocket->un, sizeof(vsocket->un));
if (ret == 0) {
vhost_user_add_connection(fd, vsocket);
return 0;
}

VHOST_CONFIG_LOG(path, WARNING, "failed to connect: %s", strerror(errno));
VHOST_CONFIG_LOG(path, WARNING, "failed to connect: %s", strerror(errno));

if (ret == -2 || !vsocket->reconnect) {
close(fd);
return -1;
}
if (ret == -2 || !vsocket->reconnect) {
close(fd);
return -1;
}

VHOST_CONFIG_LOG(path, INFO, "reconnecting...");
VHOST_CONFIG_LOG(path, INFO, "reconnecting...");
}
reconn = malloc(sizeof(*reconn));
if (reconn == NULL) {
VHOST_CONFIG_LOG(path, ERR, "failed to allocate memory for reconnect");
Expand Down Expand Up @@ -930,6 +933,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
vsocket->async_copy = flags & RTE_VHOST_USER_ASYNC_COPY;
vsocket->net_compliant_ol_flags = flags & RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS;
vsocket->stats_enabled = flags & RTE_VHOST_USER_NET_STATS_ENABLE;
vsocket->async_connect = flags & RTE_VHOST_USER_ASYNC_CONNECT;
if (vsocket->is_vduse)
vsocket->iommu_support = true;
else
Expand Down

0 comments on commit 5e96710

Please sign in to comment.