From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwVKU-0003UM-VT for qemu-devel@nongnu.org; Wed, 11 Nov 2015 08:20:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwVKR-0007x8-SD for qemu-devel@nongnu.org; Wed, 11 Nov 2015 08:20:50 -0500 Received: from mga11.intel.com ([192.55.52.93]:52749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwVKR-0007wg-MN for qemu-devel@nongnu.org; Wed, 11 Nov 2015 08:20:47 -0500 From: Yuanhan Liu Date: Wed, 11 Nov 2015 21:24:38 +0800 Message-Id: <1447248281-15227-3-git-send-email-yuanhan.liu@linux.intel.com> In-Reply-To: <1447248281-15227-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1447248281-15227-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [Qemu-devel] [PATCH v4 2/5] vhost: reset vhost net when virtio_net_reset happens List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Yuanhan Liu , mst@redhat.com When a virtio net driver is unloaded (unbind), virtio_net_reset happens. For vhost net, we should also send a message (RESET_OWNER) to the backend to do some proper reset settings. Signed-off-by: Yuanhan Liu --- hw/net/vhost_net.c | 20 ++++++++++++++------ hw/net/virtio-net.c | 14 ++++++++++++++ include/net/vhost_net.h | 1 + 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index d91b7b1..387f851 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -292,12 +292,6 @@ static void vhost_net_stop_one(struct vhost_net *net, int r = vhost_ops->vhost_net_set_backend(&net->dev, &file); assert(r >= 0); } - } else if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) { - for (file.index = 0; file.index < net->dev.nvqs; ++file.index) { - const VhostOps *vhost_ops = net->dev.vhost_ops; - int r = vhost_ops->vhost_reset_device(&net->dev); - assert(r >= 0); - } } if (net->nc->info->poll) { net->nc->info->poll(net->nc, true); @@ -382,6 +376,16 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, assert(vhost_net_set_vnet_endian(dev, ncs[0].peer, false) >= 0); } +void vhost_net_reset(VirtIODevice *vdev) +{ + VirtIONet *n = VIRTIO_NET(vdev); + struct vhost_net *net = get_vhost_net(n->nic->ncs[0].peer); + + if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) { + net->dev.vhost_ops->vhost_reset_device(&net->dev); + } +} + void vhost_net_cleanup(struct vhost_net *net) { vhost_dev_cleanup(&net->dev); @@ -469,6 +473,10 @@ void vhost_net_stop(VirtIODevice *dev, { } +void vhost_net_reset(VirtIODevice *vdev) +{ +} + void vhost_net_cleanup(struct vhost_net *net) { } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a877614..75472ba 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -318,10 +318,24 @@ static RxFilterInfo *virtio_net_query_rxfilter(NetClientState *nc) return info; } +static void virtio_net_vhost_reset(VirtIONet *n) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(n); + NetClientState *nc = qemu_get_queue(n->nic); + + if (!get_vhost_net(nc->peer)) { + return; + } + + vhost_net_reset(vdev); +} + static void virtio_net_reset(VirtIODevice *vdev) { VirtIONet *n = VIRTIO_NET(vdev); + virtio_net_vhost_reset(n); + /* Reset back to compatibility mode */ n->promisc = 1; n->allmulti = 0; diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 3389b41..d1c1331 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -18,6 +18,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options); int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int total_queues); void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, int total_queues); +void vhost_net_reset(VirtIODevice *dev); void vhost_net_cleanup(VHostNetState *net); -- 1.9.0