Skip to content

Commit

Permalink
vhost-net: save & restore vhost-user acked features
Browse files Browse the repository at this point in the history
The initial vhost-user connection sets the features to be negotiated
with the driver. Renegotiation isn't possible without device reset.

To handle reconnection of vhost-user backend, ensure the same set of
features are provided, and reuse already acked features.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Victor Kaplansky <victork@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
  • Loading branch information
elmarco authored and mstsirkin committed Jun 17, 2016
1 parent 72b65f9 commit a463215
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
27 changes: 26 additions & 1 deletion hw/net/vhost_net.c
Expand Up @@ -120,6 +120,11 @@ uint64_t vhost_net_get_max_queues(VHostNetState *net)
return net->dev.max_queues;
}

uint64_t vhost_net_get_acked_features(VHostNetState *net)
{
return net->dev.acked_features;
}

static int vhost_net_get_fd(NetClientState *backend)
{
switch (backend->info->type) {
Expand All @@ -136,6 +141,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
int r;
bool backend_kernel = options->backend_type == VHOST_BACKEND_TYPE_KERNEL;
struct vhost_net *net = g_malloc(sizeof *net);
uint64_t features = 0;

if (!options->net_backend) {
fprintf(stderr, "vhost-net requires net backend to be setup\n");
Expand Down Expand Up @@ -183,8 +189,21 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
goto fail;
}
}

/* Set sane init value. Override when guest acks. */
vhost_net_ack_features(net, 0);
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
features = vhost_user_get_acked_features(net->nc);
if (~net->dev.features & features) {
fprintf(stderr, "vhost lacks feature mask %" PRIu64
" for backend\n",
(uint64_t)(~net->dev.features & features));
vhost_dev_cleanup(&net->dev);
goto fail;
}
}

vhost_net_ack_features(net, features);

return net;
fail:
g_free(net);
Expand Down Expand Up @@ -447,10 +466,16 @@ uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features)
{
return features;
}

void vhost_net_ack_features(struct vhost_net *net, uint64_t features)
{
}

uint64_t vhost_net_get_acked_features(VHostNetState *net)
{
return 0;
}

bool vhost_net_virtqueue_pending(VHostNetState *net, int idx)
{
return false;
Expand Down
1 change: 1 addition & 0 deletions include/net/vhost-user.h
Expand Up @@ -13,5 +13,6 @@

struct vhost_net;
struct vhost_net *vhost_user_get_vhost_net(NetClientState *nc);
uint64_t vhost_user_get_acked_features(NetClientState *nc);

#endif /* VHOST_USER_H_ */
3 changes: 3 additions & 0 deletions include/net/vhost_net.h
Expand Up @@ -31,4 +31,7 @@ int vhost_net_notify_migration_done(VHostNetState *net, char* mac_addr);
VHostNetState *get_vhost_net(NetClientState *nc);

int vhost_set_vring_enable(NetClientState * nc, int enable);

uint64_t vhost_net_get_acked_features(VHostNetState *net);

#endif
10 changes: 10 additions & 0 deletions net/vhost-user.c
Expand Up @@ -23,6 +23,7 @@ typedef struct VhostUserState {
CharDriverState *chr;
VHostNetState *vhost_net;
int watch;
uint64_t acked_features;
} VhostUserState;

typedef struct VhostUserChardevProps {
Expand All @@ -37,6 +38,13 @@ VHostNetState *vhost_user_get_vhost_net(NetClientState *nc)
return s->vhost_net;
}

uint64_t vhost_user_get_acked_features(NetClientState *nc)
{
VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
return s->acked_features;
}

static int vhost_user_running(VhostUserState *s)
{
return (s->vhost_net) ? 1 : 0;
Expand All @@ -56,6 +64,8 @@ static void vhost_user_stop(int queues, NetClientState *ncs[])
}

if (s->vhost_net) {
/* save acked features */
s->acked_features = vhost_net_get_acked_features(s->vhost_net);
vhost_net_cleanup(s->vhost_net);
s->vhost_net = NULL;
}
Expand Down

0 comments on commit a463215

Please sign in to comment.