All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] xen-platform: Cleanup network infrastructure when emulated NICs are unplugged
@ 2017-06-30 12:50 Ross Lagerwall
  2017-07-07 15:33 ` Anthony PERARD
  0 siblings, 1 reply; 2+ messages in thread
From: Ross Lagerwall @ 2017-06-30 12:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Ross Lagerwall, Stefano Stabellini, Anthony Perard,
	Michael S. Tsirkin, Paolo Bonzini, Richard Henderson,
	Eduardo Habkost

When the guest unplugs the emulated NICs, cleanup the peer for each NIC
as it is not needed anymore. Most importantly, this allows the tap
interfaces which QEMU holds open to be closed and removed.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---

In v2: Don't call nic_cleanup(), just remove the peer of the NIC which
will cleanup up the tap devices. This means that QEMU doesn't segv
when shutting down.

 hw/i386/xen/xen_platform.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
index 1419fc9..f231558 100644
--- a/hw/i386/xen/xen_platform.c
+++ b/hw/i386/xen/xen_platform.c
@@ -102,8 +102,19 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
     }
 }
 
+/* Remove the peer of the NIC device. Normally, this would be a tap device. */
+static void del_nic_peer(NICState *nic, void *opaque)
+{
+    NetClientState *nc;
+
+    nc = qemu_get_queue(nic);
+    if (nc->peer)
+        qemu_del_net_client(nc->peer);
+}
+
 static void pci_unplug_nics(PCIBus *bus)
 {
+    qemu_foreach_nic(del_nic_peer, NULL);
     pci_for_each_device(bus, 0, unplug_nic, NULL);
 }
 
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH v2] xen-platform: Cleanup network infrastructure when emulated NICs are unplugged
  2017-06-30 12:50 [Qemu-devel] [PATCH v2] xen-platform: Cleanup network infrastructure when emulated NICs are unplugged Ross Lagerwall
@ 2017-07-07 15:33 ` Anthony PERARD
  0 siblings, 0 replies; 2+ messages in thread
From: Anthony PERARD @ 2017-07-07 15:33 UTC (permalink / raw)
  To: Ross Lagerwall
  Cc: qemu-devel, Stefano Stabellini, Michael S. Tsirkin,
	Paolo Bonzini, Richard Henderson, Eduardo Habkost

On Fri, Jun 30, 2017 at 01:50:28PM +0100, Ross Lagerwall wrote:
> When the guest unplugs the emulated NICs, cleanup the peer for each NIC
> as it is not needed anymore. Most importantly, this allows the tap
> interfaces which QEMU holds open to be closed and removed.
> 
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
> ---
> 
> In v2: Don't call nic_cleanup(), just remove the peer of the NIC which
> will cleanup up the tap devices. This means that QEMU doesn't segv
> when shutting down.
> 
>  hw/i386/xen/xen_platform.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
> index 1419fc9..f231558 100644
> --- a/hw/i386/xen/xen_platform.c
> +++ b/hw/i386/xen/xen_platform.c
> @@ -102,8 +102,19 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
>      }
>  }
>  
> +/* Remove the peer of the NIC device. Normally, this would be a tap device. */
> +static void del_nic_peer(NICState *nic, void *opaque)
> +{
> +    NetClientState *nc;
> +
> +    nc = qemu_get_queue(nic);
> +    if (nc->peer)
> +        qemu_del_net_client(nc->peer);
> +}
> +
>  static void pci_unplug_nics(PCIBus *bus)
>  {
> +    qemu_foreach_nic(del_nic_peer, NULL);
>      pci_for_each_device(bus, 0, unplug_nic, NULL);

I don't know if it a good idee to clean every NIC (using
qemu_foreach_nic) vs only clean NIC that have a PCI device (having
unplug_nic cleanup the peer). But I cannot think of a scenario with xen
where a nic is not also a pci device.

Anyway, this patch works:
Acked-by: Anthony PERARD <anthony.perard@citrix.com>

-- 
Anthony PERARD

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-07 15:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-30 12:50 [Qemu-devel] [PATCH v2] xen-platform: Cleanup network infrastructure when emulated NICs are unplugged Ross Lagerwall
2017-07-07 15:33 ` Anthony PERARD

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.