From: Marc-André Lureau <marcandre.lur...@redhat.com> vhost backend may want to stop the device, for example if it wants to restart itself (translates to a link down for vhost-net).
Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> --- hw/net/vhost_net.c | 13 +++++++++++++ include/hw/virtio/vhost.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index ea15220..f977e2d 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -134,6 +134,18 @@ static int vhost_net_get_fd(NetClientState *backend) } } +static void vhost_net_backend_stop(struct vhost_dev *dev) +{ + struct vhost_net *net = container_of(dev, struct vhost_net, dev); + NetClientState *nc = net->nc; + NetClientState *peer = nc->peer; + + peer->link_down = 1; + if (peer->info->link_status_changed) { + peer->info->link_status_changed(peer); + } +} + struct vhost_net *vhost_net_init(VhostNetOptions *options) { int r; @@ -163,6 +175,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options) net->dev.nvqs = 2; net->dev.vqs = net->vqs; + net->dev.stop = vhost_net_backend_stop; r = vhost_dev_init(&net->dev, options->opaque, options->backend_type); diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index ab1dcac..48efd87 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -35,6 +35,8 @@ struct vhost_log { vhost_log_chunk_t *log; }; +typedef void (*vhost_stop)(struct vhost_dev *dev); + struct vhost_memory; struct vhost_dev { MemoryListener memory_listener; @@ -59,6 +61,8 @@ struct vhost_dev { const VhostOps *vhost_ops; void *opaque; struct vhost_log *log; + /* backend request to stop */ + vhost_stop stop; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque, -- 2.4.3