[Qemu-devel] [PATCH] monitor: Add force option support to pci_del command
This adds a way to force the removal/unplug of previously added pci devices when ACPI-based hotplug mechanism is not present. Signed-off-by: Marcos Oviedo --- hw/pci-hotplug.c | 16 +--- qemu-monitor.hx |4 ++-- sysemu.h |2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index a8f3df1..1007e5b 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -260,11 +260,12 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict) } #endif -int pci_device_hot_remove(Monitor *mon, const char *pci_addr) +int pci_device_hot_remove(Monitor *mon, const char *pci_addr, const int forced) { PCIDevice *d; int dom, bus; unsigned slot; +int ret = -1; if (pci_read_devaddr(mon, pci_addr, &dom, &bus, &slot)) { return -1; @@ -275,10 +276,19 @@ int pci_device_hot_remove(Monitor *mon, const char *pci_addr) monitor_printf(mon, "slot %d empty\n", slot); return -1; } -return qdev_unplug(&d->qdev); + +if (forced) { +qdev_free(&d->qdev); +ret = 0; +} +else { +ret = qdev_unplug(&d->qdev); +} + +return ret; } void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict) { -pci_device_hot_remove(mon, qdict_get_str(qdict, "pci_addr")); +pci_device_hot_remove(mon, qdict_get_str(qdict, "pci_addr"), qdict_get_int(qdict, "force")); } diff --git a/qemu-monitor.hx b/qemu-monitor.hx index f6a94f2..ce8cddd 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -1140,8 +1140,8 @@ ETEXI #if defined(TARGET_I386) { .name = "pci_del", -.args_type = "pci_addr:s", -.params = "[[:]:]", +.args_type = "pci_addr:s,force:-f", +.params = "[[:]:] [-f]", .help = "hot remove PCI device", .mhandler.cmd = do_pci_device_hot_remove, }, diff --git a/sysemu.h b/sysemu.h index 879446a..22303b3 100644 --- a/sysemu.h +++ b/sysemu.h @@ -202,7 +202,7 @@ DriveInfo *add_init_drive(const char *opts); /* pci-hotplug */ void pci_device_hot_add(Monitor *mon, const QDict *qdict); void drive_hot_add(Monitor *mon, const QDict *qdict); -int pci_device_hot_remove(Monitor *mon, const char *pci_addr); +int pci_device_hot_remove(Monitor *mon, const char *pci_addr, const int forced); void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict); /* serial ports */ -- 1.5.6.5
[Qemu-devel] [Bug 544367] Re: pci_del fails to remove PCI virtio storage device
This bug is still present on latest git. It seems, please double check this, that the commit you tested is related to a different issue. The steps to reproduce the bug are attached on the case. Usually, when there is support for ACPI operations on the guest OS, the pci_del command triggers a general purpose event indicating to the OS ACPI event handlers that the device is going to be removed. The handlers are then in charge of trigger an eject operation (EJx) on the hw device, which causes the removal of the device. The EJx operation is handled on qemu by pciej_write() and ends by calling qdev_free(), which removes the device in question from the system. When there is no support for ACPI (either because the ACPI related drivers are not loaded on the guest OS or the VM is stopped using -s -S), there is no way to remove a previously added PCI device. I've just send a patch that adds the -f (force) option to pci_del in order to be able to remove a PCI device when the ACPI support is not present. Regards, Marcos -- pci_del fails to remove PCI virtio storage device https://bugs.launchpad.net/bugs/544367 You received this bug notification because you are a member of qemu- devel-ml, which is subscribed to QEMU. Status in QEMU: Fix Released Bug description: In qemu monitor, command pci_del silently fails to remove a virtio storage device previously added with pci_add. It doesn't matter whether the guest actually makes use of the virtio device for this failure to happen. = QEMU command line = /usr/local/bin/qemu-system-x86_64 -S -snapshot -enable-kvm -smp 1 -cdrom /pub/gentoo/releases/x86/10.1/livedvd-x86-amd64-32ul-10.1.iso -boot order=d -m 512 -usb -name gentoo_livedvd -ctrl-grab -vga cirrus -chardev pty,id=serial0 -device isa-serial,chardev=serial0 -chardev socket,id=monitor,path=/tmp/gentoo_livedvd.monitor,server,nowait -mon chardev=monitor,mode=readline = Host information = Distribution: Gentoo Linux Portage 2.1.7.16 (default/linux/x86/10.0, gcc-4.3.4, glibc-2.10.1-r1, 2.6.31-gentoo-r6 i686) System uname: linux-2.6.31-gentoo-r6-i686-genuine_intel-r-_cpu_t13...@_1.66ghz-with-gentoo-1.12.13 = Guest information = Gentoo Linux 10.1 x86 LiveDVD
Re: [Qemu-devel] [PATCH] monitor: Add force option support to pci_del command
On Wed, Jun 9, 2010 at 4:38 AM, Gerd Hoffmann wrote: > On 06/09/10 07:37, Marcos Oviedo wrote: > >> This adds a way to force the removal/unplug of previously added pci >> devices when ACPI-based hotplug mechanism is not present. >> > > Point being? > > If your guest can't handle pci hotplug it is pretty useless to plug in > hardware in the first place. > > If your guest supports pci hotplug it will be quite upset if you zap the > hardware without asking via ACPI. > This make sense when you mistakenly add a pci device on a -s -S scenario, like the scenario described on the following bug: https://bugs.launchpad.net/qemu/+bug/544367. When ACPI-based hotplug support is present on the guest and we run pci_del with the force option, the hotplug events will still be generated to the guest and the guest still will trigger the EJx event, which will end by calling pciej_write() on qemu side. This function will do nothing on a -f and pci hotplug support scenario, as the pci device was previously removed by pci_del. Thanks! Marcos > > cheers, > Gerd > >