xen-platform: Cleanup network infrastructure when emulated NICs are unplugged
PATCH v2 1/1 xen-platform: Cleanup network infrastructure when emulated NICs are unplugged
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.
---
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(+)
hw/i386/xen/xen_platform.c +11 -0
@@ -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 ); }
Signature · 1 line
2.9.4
Quoted 26 lines · Ross Lagerwall
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 <[email protected]>---
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(+)hw/i386/xen/xen_platform.c +4
-0@@ -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;
hw/i386/xen/xen_platform.c static void unplug_nic(PCIBus *b, PCIDevice *d, void *o) · line 118
Quoted 10 lines
hw/i386/xen/xen_platform.c +7
-0+ + 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:
Signature · 1 line
Anthony PERARD