Re: [PATCH 7/8] Implement basic virDomainGetState in all drivers

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

 



2011/5/4 Jiri Denemark <jdenemar@xxxxxxxxxx>:
> Reason is currently always set to 0 (i.e., *_UNKNOWN).
> ---
> Âsrc/esx/esx_driver.c    |  54 ++++++++++++++++++++++++-
> Âsrc/libxl/libxl_driver.c  |  31 +++++++++++++-
> Âsrc/lxc/lxc_driver.c    |  33 ++++++++++++++-
> Âsrc/openvz/openvz_driver.c | Â 32 ++++++++++++++-
> Âsrc/phyp/phyp_driver.c   |  12 +++++-
> Âsrc/qemu/qemu_driver.c   |  33 ++++++++++++++-
> Âsrc/test/test_driver.c   |  31 +++++++++++++-
> Âsrc/uml/uml_driver.c    |  32 ++++++++++++++-
> Âsrc/vbox/vbox_tmpl.c    |  56 +++++++++++++++++++++++++-
> Âsrc/vmware/vmware_driver.c | Â 31 +++++++++++++-
> Âsrc/xen/xen_driver.c    |  18 ++++++++-
> Âsrc/xen/xen_hypervisor.c  |  34 +++++++++++++++-
> Âsrc/xen/xen_hypervisor.h  |  Â4 ++
> Âsrc/xen/xend_internal.c  Â|  97 ++++++++++++++++++++++++++++++++-----------
> Âsrc/xen/xend_internal.h  Â|  Â1 +
> Âsrc/xen/xm_internal.c   Â|  19 ++++++++-
> Âsrc/xen/xm_internal.h   Â|  Â1 +
> Âsrc/xen/xs_internal.c   Â|  32 ++++++++++++++-
> Âsrc/xen/xs_internal.h   Â|  Â3 +
> Âsrc/xenapi/xenapi_driver.c | Â 45 ++++++++++++++++++++-
> Â20 files changed, 559 insertions(+), 40 deletions(-)
>
> diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
> index 543ebe6..94b0121 100644
> --- a/src/esx/esx_driver.c
> +++ b/src/esx/esx_driver.c
> @@ -2425,6 +2425,58 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
>
>
> Âstatic int
> +esxDomainGetState(virDomainPtr domain, int *state, int *reason)
> +{
> + Â Âint result = -1;
> + Â ÂesxPrivate *priv = domain->conn->privateData;
> + Â ÂesxVI_String *propertyNameList = NULL;
> + Â ÂesxVI_ObjectContent *virtualMachine = NULL;
> + Â ÂesxVI_DynamicProperty *dynamicProperty = NULL;
> + Â ÂesxVI_VirtualMachinePowerState powerState;
> +
> + Â Âif (esxVI_EnsureSession(priv->primary) < 0) {
> + Â Â Â Âreturn -1;
> + Â Â}
> +
> + Â Âif (esxVI_String_AppendValueListToList(&propertyNameList,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "runtime.powerState\0") < 0 ||
> + Â Â Â ÂesxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â propertyNameList, &virtualMachine,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â esxVI_Occurrence_RequiredItem) < 0) {
> + Â Â Â Âgoto cleanup;
> + Â Â}
> +
> + Â Â*state = VIR_DOMAIN_NOSTATE;
> + Â Âif (reason)
> + Â Â Â Â*reason = 0;
> +
> + Â Âfor (dynamicProperty = virtualMachine->propSet; dynamicProperty != NULL;
> + Â Â Â Â dynamicProperty = dynamicProperty->_next) {
> + Â Â Â Âif (STREQ(dynamicProperty->name, "runtime.powerState")) {
> + Â Â Â Â Â Âif (esxVI_VirtualMachinePowerState_CastFromAnyType
> + Â Â Â Â Â Â Â Â Â(dynamicProperty->val, &powerState) < 0) {
> + Â Â Â Â Â Â Â Âgoto cleanup;
> + Â Â Â Â Â Â}
> +
> + Â Â Â Â Â Â*state = esxVI_VirtualMachinePowerState_ConvertToLibvirt
> + Â Â Â Â Â Â Â Â Â Â Â (powerState);
> + Â Â Â Â} else {
> + Â Â Â Â Â ÂVIR_WARN("Unexpected '%s' property", dynamicProperty->name);
> + Â Â Â Â}
> + Â Â}
> +
> + Â Âresult = 0;
> +
> + Âcleanup:
> + Â ÂesxVI_String_Free(&propertyNameList);
> + Â ÂesxVI_ObjectContent_Free(&virtualMachine);
> +
> + Â Âreturn result;
> +}
> +

This can be simplified to:

static int
esxDomainGetState(virDomainPtr domain, int *state, int *reason)
{
    int result = -1;
    esxPrivate *priv = domain->conn->privateData;
    esxVI_String *propertyNameList = NULL;
    esxVI_ObjectContent *virtualMachine = NULL;
    esxVI_VirtualMachinePowerState powerState;

    if (esxVI_EnsureSession(priv->primary) < 0) {
        return -1;
    }

    if (esxVI_String_AppendValueToList(&propertyNameList,
                                       "runtime.powerState") < 0 ||
        esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid,
                                         propertyNameList, &virtualMachine,
                                         esxVI_Occurrence_RequiredItem) < 0 ||
        esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0) {
        goto cleanup;
    }

    *state = esxVI_VirtualMachinePowerState_ConvertToLibvirt(powerState);

    if (reason) {
        *reason = 0;
    }

    result = 0;

  cleanup:
    esxVI_String_Free(&propertyNameList);
    esxVI_ObjectContent_Free(&virtualMachine);

    return result;
}

Matthias

--
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]