diff options
Diffstat (limited to 'hw')
-rw-r--r-- | hw/net/virtio-net.c | 15 | ||||
-rw-r--r-- | hw/virtio/virtio.c | 9 |
2 files changed, 22 insertions, 2 deletions
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 365e266b74..826a2a5fca 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -125,10 +125,23 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) return; } if (!n->vhost_started) { - int r; + int r, i; + if (!vhost_net_query(get_vhost_net(nc->peer), vdev)) { return; } + + /* Any packets outstanding? Purge them to avoid touching rings + * when vhost is running. + */ + for (i = 0; i < queues; i++) { + NetClientState *qnc = qemu_get_subqueue(n->nic, i); + + /* Purge both directions: TX and RX. */ + qemu_net_queue_purge(qnc->peer->incoming_queue, qnc); + qemu_net_queue_purge(qnc->incoming_queue, qnc->peer); + } + n->vhost_started = 1; r = vhost_net_start(vdev, n->nic->ncs, queues); if (r < 0) { diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5c981801f3..ac222385d6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1108,7 +1108,10 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state) BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK); - vdev->vm_running = running; + + if (running) { + vdev->vm_running = running; + } if (backend_run) { virtio_set_status(vdev, vdev->status); @@ -1121,6 +1124,10 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state) if (!backend_run) { virtio_set_status(vdev, vdev->status); } + + if (!running) { + vdev->vm_running = running; + } } void virtio_init(VirtIODevice *vdev, const char *name, |