[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 14/18] vhost-net: save & restore vhost-user acked fe
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH 14/18] vhost-net: save & restore vhost-user acked features |
Date: |
Fri, 1 Apr 2016 13:16:24 +0200 |
From: Marc-André Lureau <address@hidden>
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 <address@hidden>
---
hw/net/vhost_net.c | 21 ++++++++++++++++++++-
include/net/vhost-user.h | 1 +
include/net/vhost_net.h | 3 +++
net/vhost-user.c | 10 ++++++++++
4 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 6c40c4e..ee39e9c 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -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) {
@@ -148,6 +153,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");
@@ -197,8 +203,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);
diff --git a/include/net/vhost-user.h b/include/net/vhost-user.h
index 85109f6..efae35d 100644
--- a/include/net/vhost-user.h
+++ b/include/net/vhost-user.h
@@ -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_ */
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 3389b41..0bd4877 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -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
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 54849e9..ae63e20 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -23,6 +23,7 @@ typedef struct VhostUserState {
CharDriverState *chr;
VHostNetState *vhost_net;
int watch;
+ uint64_t acked_features;
} VhostUserState;
typedef struct VhostUserChardevProps {
@@ -39,6 +40,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;
@@ -58,6 +66,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;
}
--
2.5.5
- [Qemu-devel] [PATCH 10/18] vhost-user: add slave-fd support, (continued)
[Qemu-devel] [PATCH 12/18] vhost-user: disconnect on start failure, marcandre . lureau, 2016/04/01
[Qemu-devel] [PATCH 15/18] vhost-net: save & restore vring enable state, marcandre . lureau, 2016/04/01
[Qemu-devel] [PATCH 14/18] vhost-net: save & restore vhost-user acked features,
marcandre . lureau <=
[Qemu-devel] [PATCH 13/18] vhost-net: do not crash if backend is not present, marcandre . lureau, 2016/04/01
[Qemu-devel] [PATCH 16/18] test: vubr check vring enable state, marcandre . lureau, 2016/04/01
[Qemu-devel] [PATCH 18/18] test: add shutdown support vubr test, marcandre . lureau, 2016/04/01
[Qemu-devel] [PATCH 17/18] test: start vhost-user reconnect test, marcandre . lureau, 2016/04/01