Re: [libvirt] [PATCH 20/27] Add API for issuing 'pci_add storage' monitor command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 qemuMonitorAddPCIDisk()
> * src/qemu/qemu_driver.c: Convert over to using the new
>   qemuMonitorAddPCIDisk() method, and remove now obsolete
>   qemudEscape() method
> ---
>  src/qemu/qemu_driver.c       |  130 ++---------------------------------------
>  src/qemu/qemu_monitor_text.c |   55 ++++++++++++++++++
>  src/qemu/qemu_monitor_text.h |   13 ++++
>  3 files changed, 75 insertions(+), 123 deletions(-)
> 
...
> diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
> index 290dcce..765a482 100644
> --- a/src/qemu/qemu_monitor_text.c
> +++ b/src/qemu/qemu_monitor_text.c
> @@ -1437,6 +1437,61 @@ cleanup:
>  }
>  
> 
> +int qemuMonitorAddPCIDisk(const virDomainObjPtr vm,
> +                          const char *path,
> +                          const char *bus,
> +                          unsigned *guestDomain,
> +                          unsigned *guestBus,
> +                          unsigned *guestSlot) {
> +    char *cmd = NULL;
> +    char *reply = NULL;
> +    char *safe_path = NULL;
> +    int tryOldSyntax = 0;
> +    int ret = -1;
> +
> +    safe_path = qemudEscapeMonitorArg(path);
> +    if (!safe_path) {
> +        virReportOOMError(NULL);
> +        return -1;
> +    }
> +
> +try_command:
> +    if (virAsprintf(&cmd, "pci_add %s storage file=%s,if=%s",
> +                    (tryOldSyntax ? "0": "pci_addr=auto"), safe_path, bus) < 0) {
> +        virReportOOMError(NULL);
> +        goto cleanup;
> +    }
> +
> +    if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
> +        qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
> +                         _("cannot attach %s disk %s"), bus, path);
> +        goto cleanup;
> +    }
> +
> +    if (qemuMonitorParsePciAddReply(vm, reply,
> +                                    guestDomain, guestBus, guestSlot) < 0) {
> +        if (!tryOldSyntax && strstr(reply, "invalid char in expression")) {
> +            VIR_FREE(reply);
> +            VIR_FREE(cmd);
> +            tryOldSyntax = 1;
> +            goto try_command;
> +        }
> +
> +        qemudReportError (NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
> +                          _("adding %s disk failed %s: %s"), bus, path, reply);
> +        goto cleanup;
> +    }
> +
> +    ret = 0;
> +
> +cleanup:
> +    VIR_FREE(cmd);
> +    VIR_FREE(reply);
> +    return ret;
> +}

safe_path is leaked

Otherwise ACK

Cheers,
Mark.

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]