Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-fne committed Nov 10, 2020
1 parent 9c2ff75 commit 611a8ee
Showing 1 changed file with 41 additions and 42 deletions.
83 changes: 41 additions & 42 deletions src/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static void vhost_create_socket(struct pg_vhost_state *state, uint64_t flags,

path = g_strdup_printf("%s/qemu-%s", sockets_path, state->brick.name);
/* If the socket is CLIENT do NOT destroy the socket. */
if (flags & 1 == 0)
if ((flags & 1) == 0)
g_remove(path);

printf("New vhost-user socket: %s, zero-copy %s\n", path,
Expand Down Expand Up @@ -343,6 +343,46 @@ static void vhost_create_socket(struct pg_vhost_state *state, uint64_t flags,
g_free(path);
}

#define VHOST_NOT_READY \
"vhost not ready, did you called vhost_start after packetgraph_start ?"

static int vhost_init(struct pg_brick *brick, struct pg_brick_config *config,
struct pg_error **errp)
{
struct pg_vhost_state *state;
struct pg_vhost_config *vhost_config;

state = pg_brick_get_state(brick, struct pg_vhost_state);
if (!vhost_start_ok) {
*errp = pg_error_new(VHOST_NOT_READY);
return -1;
}

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);
vhost_create_socket(state, vhost_config->flags, errp);
if (pg_error_is_set(errp))
return -1;

brick->burst = vhost_burst;
brick->poll = vhost_poll;

rte_atomic32_init(&state->allow_queuing);
rte_atomic32_set(&state->allow_queuing, 1);
#ifdef PG_VHOST_FASTER_YET_BROKEN_POLL
state->check_atomic = 1024;
state->check_counter = 0;
#endif /* PG_VHOST_FASTER_YET_BROKEN_POLL */

return 0;
}

#undef VHOST_NOT_READY

static enum pg_side vhost_get_side(struct pg_brick *brick)
{
struct pg_vhost_state *state =
Expand Down Expand Up @@ -453,47 +493,6 @@ static void on_destroy_device(int dev)
pthread_mutex_unlock(&mutex);
}

#define VHOST_NOT_READY \
"vhost not ready, did you called vhost_start after packetgraph_start ?"

static int vhost_init(struct pg_brick *brick, struct pg_brick_config *config,
struct pg_error **errp)
{
struct pg_vhost_state *state;
struct pg_vhost_config *vhost_config;

state = pg_brick_get_state(brick, struct pg_vhost_state);
if (!vhost_start_ok) {
*errp = pg_error_new(VHOST_NOT_READY);
return -1;
}

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);
vhost_create_socket(state, vhost_config->flags, errp);
if (pg_error_is_set(errp))
return -1;

brick->burst = vhost_burst;
brick->poll = vhost_poll;

rte_atomic32_init(&state->allow_queuing);
rte_atomic32_set(&state->allow_queuing, 1);
#ifdef PG_VHOST_FASTER_YET_BROKEN_POLL
state->check_atomic = 1024;
state->check_counter = 0;
#endif /* PG_VHOST_FASTER_YET_BROKEN_POLL */

return 0;
}

#undef VHOST_NOT_READY


/**
* Check that the socket path exists and has the right perm and store it
*
Expand Down

0 comments on commit 611a8ee

Please sign in to comment.