[libvirt] [PATCH 19/27] Add API for issuing 'pci_del' monitor command
Mark McLoughlin
markmc at redhat.com
Mon Sep 28 13:23:03 UTC 2009
On Thu, 2009-09-24 at 16:00 +0100, Daniel P. Berrange wrote:
> * src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Add new API
> qemuMonitorRemovePCIDevice() for removing PCI device
> * src/qemu/qemu_driver.c: Convert all places removing PCI devices
> over to new qemuMonitorRemovePCIDevice() API
> ---
> src/qemu/qemu_driver.c | 120 ++++-------------------------------------
> src/qemu/qemu_monitor_text.c | 60 +++++++++++++++++++++
> src/qemu/qemu_monitor_text.h | 6 ++
> 3 files changed, 78 insertions(+), 108 deletions(-)
>
...
> diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
> index ca84fc6..290dcce 100644
> --- a/src/qemu/qemu_monitor_text.c
> +++ b/src/qemu/qemu_monitor_text.c
> @@ -1436,3 +1436,63 @@ cleanup:
> return ret;
> }
>
> +
> +int qemuMonitorRemovePCIDevice(const virDomainObjPtr vm,
> + unsigned guestDomain,
> + unsigned guestBus,
> + unsigned guestSlot)
> +{
> + char *cmd = NULL;
> + char *reply = NULL;
> + int tryOldSyntax = 0;
> + int ret = -1;
> +
> +try_command:
> + if (tryOldSyntax) {
> + if (virAsprintf(&cmd, "pci_del 0 %.2x", guestSlot) < 0) {
> + virReportOOMError(NULL);
> + goto cleanup;
> + }
> + } else {
> + if (virAsprintf(&cmd, "pci_del pci_addr=%.4x:%.2x:%.2x",
> + guestDomain, guestBus, guestSlot) < 0) {
> + virReportOOMError(NULL);
> + goto cleanup;
> + }
> + }
> +
> + if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
> + qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
> + "%s", _("failed to remove PCI device"));
> + goto cleanup;
> + }
> +
> + DEBUG ("%s: pci_del reply: %s",vm->def->name, reply);
> +
> + /* Syntax changed when KVM merged PCI hotplug upstream to QEMU,
> + * so check for an error message from old KVM indicating the
> + * need to try the old syntax */
> + if (!tryOldSyntax &&
> + strstr(reply, "extraneous characters")) {
> + tryOldSyntax = 1;
> + VIR_FREE(reply);
> + VIR_FREE(cmd);
> + goto try_command;
This fixes a leak in the old code, would have been nice to have as a
separate patch
ACK
Cheers,
Mark.
More information about the libvir-list
mailing list