[libvirt] [PATCH v3] Add host UUID (to libvirt capabilities)

Eric Blake eblake at redhat.com
Tue May 25 15:08:15 UTC 2010


On 05/25/2010 08:26 AM, Daniel P. Berrange wrote:
> +
> +# UUID of the host:
> +# Provide the UUID of the host here in case the command
> +# 'dmidecode -s system-uuid' does not provide a valid uuid. In case
> +# 'dmidecode' does not provide a valid UUID and none is provided here, a
> +# temporary UUID will be generated.
> +# Keep the format of the example UUID below. UUID must not have all digits
> +# be the same.
> +
> +#host_uuid = "8510b1a1-1afa-4da6-8111-785fae202c1e"

What's the likelihood that people just uncomment this line, and this
becomes a very common "uuid" that is no longer unique?
http://www.snopes.com/business/taxes/woolworth.asp

The sample is worthwhile, to show the locations where - must appear, but
is it any better to write the sample as a known-invalid string, with all
digits the same?

> +
> +/**
> + * virUUIDIsValid
> + *
> + * @uuid: The UUID to test
> + *
> + * Do some basic tests to check whether the given UUID is
> + * valid as a host UUID.
> + * Basic tests:
> + *  - Not all of the digits may be equal
> + */
> +int
> +virUUIDIsValid(unsigned char *uuid)
> +{
> +    unsigned int i, ctr = 1;
> +    unsigned char c;
> +
> +    if (!uuid)
> +        return 0;
> +
> +    c = uuid[0];
> +
> +    for (i = 1; i < VIR_UUID_BUFLEN; i++)
> +        if (uuid[i] == c)
> +            ctr++;
> +
> +    return (ctr != VIR_UUID_BUFLEN);

Is it worth the micro-optimization of breaking out of the loop on the
first uuid[i] != c, rather than parsing the entire string?  That way,
you would only need two or three comparisons on the common case, rather
than a full 32.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100525/d662832a/attachment-0001.sig>


More information about the libvir-list mailing list