From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51310 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PrwFT-0006Lk-1H for qemu-devel@nongnu.org; Tue, 22 Feb 2011 12:42:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PrwFC-0006Xz-IF for qemu-devel@nongnu.org; Tue, 22 Feb 2011 12:41:51 -0500 Received: from mail-wy0-f173.google.com ([74.125.82.173]:50817) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PrwFC-0006Xs-3c for qemu-devel@nongnu.org; Tue, 22 Feb 2011 12:41:50 -0500 Received: by wyb29 with SMTP id 29so2767049wyb.4 for ; Tue, 22 Feb 2011 09:41:49 -0800 (PST) From: William Dauchy Date: Tue, 22 Feb 2011 18:36:20 +0100 Message-Id: <1298396180-23734-1-git-send-email-wdauchy@gmail.com> Subject: [Qemu-devel] [PATCH] `qdev_free` when unplug a pci device List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: William Dauchy `qdev_free` when unplug a pci device It resolves a bug when detaching/attaching a network device # virsh detach-interface dom0 network --mac 52:54:00:f6:84:ba Interface detached successfully # virsh attach-interface dom0 network default --mac 52:54:00:f6:84:ba error: Failed to attach interface error: internal error unable to execute QEMU command 'device_add': Duplicate ID 'net0' for device A detached pci device was not freed of the list `qemu_device_opts` --- hw/pci.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 8b76cea..1e9a8f0 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1671,13 +1671,16 @@ static int pci_unplug_device(DeviceState *qdev) { PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev); PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev); + int unplug; if (info->no_hotplug) { qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name); return -1; } - return dev->bus->hotplug(dev->bus->hotplug_qdev, dev, + unplug = dev->bus->hotplug(dev->bus->hotplug_qdev, dev, PCI_HOTPLUG_DISABLED); + qdev_free(qdev); + return unplug; } void pci_qdev_register(PCIDeviceInfo *info) -- William