Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup and better flags forwarding to dpdk in vhost. #524

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 34 additions & 55 deletions src/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct pg_vhost_state {
struct pg_vhost_socket *socket;
rte_atomic32_t allow_queuing;
int vid;
uint64_t flags;
struct rte_mbuf *in[PG_MAX_PKTS_BURST];
struct rte_mbuf *out[PG_MAX_PKTS_BURST];
PG_PKTS_COUNT_TYPE tx_bytes; /* TX: [vhost] --> VM */
Expand All @@ -94,20 +95,18 @@ struct pg_vhost_state {
#endif
};

static int new_vm(int dev);
static void destroy_vm(int dev);
static int on_new_device(int dev);
static void on_destroy_device(int dev);

static const struct vhost_device_ops virtio_net_device_ops = {
.new_device = new_vm,
.destroy_device = destroy_vm,
.new_device = on_new_device,
.destroy_device = on_destroy_device,
};

/* head of the socket list */
static LIST_HEAD(socket_list, pg_vhost_socket) sockets;
static char *sockets_path;
static int vhost_start_ok;
static int disable_freacture_mask;
static int enable_freacture_mask;

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

Expand Down Expand Up @@ -181,6 +180,17 @@ static int vhost_burst(struct pg_brick *brick, enum pg_side from,
#define TCP_PROTOCOL_NUMBER 6
#define UDP_PROTOCOL_NUMBER 17

/* To know if a vhost brick is server or not. */
static int pg_vhost_is_server(struct pg_brick *brick)
{
struct pg_vhost_state *state =
pg_brick_get_state(brick, struct pg_vhost_state);

if(state->flags & RTE_VHOST_USER_CLIENT)
return 0;
return 1;
}

#ifdef PG_VHOST_FASTER_YET_BROKEN_POLL

void pg_vhost_request_remove(struct pg_brick *brick)
Expand Down Expand Up @@ -284,11 +294,15 @@ static void vhost_create_socket(struct pg_vhost_state *state, uint64_t flags,
int ret;

path = g_strdup_printf("%s/qemu-%s", sockets_path, state->brick.name);
g_remove(path);

printf("New vhost-user socket: %s, zero-copy %s\n", path,
printf("New vhost-user socket: %s, zero-copy %s, client: %s\n", path,
(flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY) ?
"enable" : "disable");
"enable" : "disable",
(flags & RTE_VHOST_USER_CLIENT) ?
"true" : "false");

/* If the socket is CLIENT do NOT destroy the socket. */
if((flags & RTE_VHOST_USER_CLIENT) == 0)
g_remove(path);

flags = flags & (RTE_VHOST_USER_CLIENT | RTE_VHOST_USER_NO_RECONNECT |
RTE_VHOST_USER_DEQUEUE_ZERO_COPY);
Expand Down Expand Up @@ -350,11 +364,9 @@ static int vhost_init(struct pg_brick *brick, struct pg_brick_config *config,
vhost_config = (struct pg_vhost_config *) config->brick_config;
state->output = vhost_config->output;
state->vid = -1;
state->flags = vhost_config->flags;
PG_PKTS_COUNT_SET(state->rx_bytes, 0);
PG_PKTS_COUNT_SET(state->tx_bytes, 0);
pg_vhost_enable(brick, enable_freacture_mask);
pg_vhost_disable(brick, disable_freacture_mask);
outscale-fne marked this conversation as resolved.
Show resolved Hide resolved

vhost_create_socket(state, vhost_config->flags, errp);
if (pg_error_is_set(errp))
return -1;
Expand Down Expand Up @@ -392,20 +404,19 @@ struct pg_brick *pg_vhost_new(const char *name, uint64_t flags,
return ret;
}


static void vhost_destroy(struct pg_brick *brick, struct pg_error **errp)
{
struct pg_vhost_state *state;

state = pg_brick_get_state(brick, struct pg_vhost_state);
rte_vhost_driver_unregister(state->socket->path);
struct pg_vhost_state *state =
pg_brick_get_state(brick, struct pg_vhost_state);

pthread_mutex_lock(&mutex);
g_remove(state->socket->path);
LIST_REMOVE(state->socket, socket_list);
rte_vhost_driver_unregister(state->socket->path);
g_free(state->socket->path);
g_free(state->socket);

LIST_REMOVE(state->socket, socket_list);
/* If the socket is client, do NOT destroy the existing socket. */
if(pg_vhost_is_server(brick))
g_remove(state->socket->path);
pthread_mutex_unlock(&mutex);
}

Expand All @@ -431,7 +442,7 @@ static uint64_t tx_bytes(struct pg_brick *brick)
pg_brick_get_state(brick, struct pg_vhost_state)->tx_bytes);
}

static int new_vm(int dev)
static int on_new_device(int dev)
{
struct pg_vhost_socket *s = NULL;
char buf[256];
Expand All @@ -454,7 +465,7 @@ static int new_vm(int dev)
return 0;
}

static void destroy_vm(int dev)
static void on_destroy_device(int dev)
{
struct pg_vhost_socket *s = NULL;
char buf[256];
Expand Down Expand Up @@ -548,38 +559,6 @@ int pg_vhost_start(const char *base_dir, struct pg_error **errp)
return 0;
}

int pg_vhost_global_enable(uint64_t feature_mask)
{
enable_freacture_mask |= feature_mask;
return 0;
}

int pg_vhost_global_disable(uint64_t feature_mask)
{
disable_freacture_mask |= feature_mask;
return 0;
}

int pg_vhost_enable(struct pg_brick *brick, uint64_t feature_mask)
{
const char *path = pg_vhost_socket_path(brick);

if (unlikely(!path))
return -1;
return rte_vhost_driver_enable_features(path,
feature_mask) ? -1 : 0;
}

int pg_vhost_disable(struct pg_brick *brick, uint64_t feature_mask)
{
const char *path = pg_vhost_socket_path(brick);

if (unlikely(!path))
return -1;
return rte_vhost_driver_disable_features(path,
feature_mask) ? -1 : 0;
}

static void vhost_link(struct pg_brick *brick, enum pg_side side, int edge)
{
struct pg_vhost_state *state =
Expand Down