Re: [PATCH] esx: Expose host UUID in the capabilities XML

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

 



2010/5/26 Stefan Berger <stefanb@xxxxxxxxxxxxxxxxxx>:
> On Wed, 2010-05-26 at 13:15 +0200, Matthias Bolte wrote:
>> Parse the BIOS UUID. This information may not be available, in that
>> case no host UUID is exposed in the capabilities XML.
>> ---
>>  src/esx/esx_driver.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 files changed, 67 insertions(+), 0 deletions(-)
>>
>> diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
>> index 7c9c50e..b89de72 100644
>> --- a/src/esx/esx_driver.c
>> +++ b/src/esx/esx_driver.c
>> @@ -141,6 +141,69 @@ esxSupportsLongMode(esxPrivate *priv)
>>
>>
>>
>> +static int
>> +esxLookupHostSystemBiosUuid(esxPrivate *priv, unsigned char *uuid)
>> +{
>> +    int result = -1;
>> +    esxVI_String *propertyNameList = NULL;
>> +    esxVI_ObjectContent *hostSystem = NULL;
>> +    esxVI_DynamicProperty *dynamicProperty = NULL;
>> +
>> +    if (esxVI_EnsureSession(priv->host) < 0) {
>> +        return -1;
>> +    }
>> +
>> +    if (esxVI_String_AppendValueToList(&propertyNameList,
>> +                                       "hardware.systemInfo.uuid") < 0 ||
>> +        esxVI_LookupObjectContentByType(priv->host, priv->host->hostFolder,
>> +                                        "HostSystem", propertyNameList,
>> +                                        esxVI_Boolean_True, &hostSystem) < 0) {
>> +        goto cleanup;
>> +    }
>> +
>> +    if (hostSystem == NULL) {
>> +        ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
>> +                  _("Could not retrieve the HostSystem object"));
>> +        goto cleanup;
>> +    }
>> +
>> +    for (dynamicProperty = hostSystem->propSet; dynamicProperty != NULL;
>> +         dynamicProperty = dynamicProperty->_next) {
>> +        if (STREQ(dynamicProperty->name, "hardware.systemInfo.uuid")) {
>> +            if (esxVI_AnyType_ExpectType(dynamicProperty->val,
>> +                                         esxVI_Type_String) < 0) {
>> +                goto cleanup;
>> +            }
>> +
>> +            if (strlen(dynamicProperty->val->string) > 0) {
>> +                if (virUUIDParse(dynamicProperty->val->string, uuid) < 0) {
>
> If the UUID is malformatted it may end up writing a couple of bytes into
> uuid and then terminate. Maybe do the memset below also here?

If virUUIDParse fails then esxLookupHostSystemBiosUuid is going to
fail making esxCapsInit fail too (and esxCapsInit frees the
virCapsPtr). Therefore no memset needed because uuid will not be used
if virUUIDParse fails.

>
>> +                    ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
>> +                              _("Could not parse UUID from string '%s'"),
>> +                              dynamicProperty->val->string);
>> +                    goto cleanup;
>> +                }
>> +            } else {
>> +                /* HostSystem has an empty UUID */
>> +                memset(uuid, 0, VIR_UUID_BUFLEN);

The memset here ensures that the uuid is really all zero, because at
this point esxLookupHostSystemBiosUuid is going to return successfully
and the uuid will be used.

>> +            }
>> +
>> +            break;
>> +        } else {
>> +            VIR_WARN("Unexpected '%s' property", dynamicProperty->name);
>> +        }
>> +    }
>> +
>> +    result = 0;
>> +
>> +  cleanup:
>> +    esxVI_String_Free(&propertyNameList);
>> +    esxVI_ObjectContent_Free(&hostSystem);
>> +
>> +    return result;
>> +}
>> +
>> +
>> +
>>  static virCapsPtr
>>  esxCapsInit(esxPrivate *priv)
>>  {
>> @@ -166,6 +229,10 @@ esxCapsInit(esxPrivate *priv)
>>      virCapabilitiesSetMacPrefix(caps, (unsigned char[]){ 0x00, 0x0c, 0x29 });
>>      virCapabilitiesAddHostMigrateTransport(caps, "esx");
>>
>> +    if (esxLookupHostSystemBiosUuid(priv, caps->host.host_uuid) < 0) {
>> +        goto failure;
>> +    }
>> +
>>      /* i686 */
>>      guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32, NULL, NULL, 0,
>>                                      NULL);
>
>
> Otherwise it looks good to me. ACK.
>
>   Stefan
>

Thanks, pushed.

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]