On Wed, Jul 16, 2025 at 02:17:46PM +0100, Mark Cave-Ayland wrote:
> The hardware UUID (hwuuid) element provides a mechanism to supply an external
> UUID to the guest, as opposed to the libvirt domain UUID. This is to allow
> for the scenario whereby a domain can be stopped, cloned and then started as
> a new domain without altering the guest-visible UUID.
> 
> Add the element, documentation and core code for the hwuuid feature along
> with an implementation for the QEMU driver.
> 
> Signed-off-by: Mark Cave-Ayland <mark.caveayl...@nutanix.com>
> ---
>  docs/formatdomain.rst             |  7 ++++++
>  src/conf/domain_conf.c            | 38 ++++++++++++++++++++++++++++---
>  src/conf/domain_conf.h            |  1 +
>  src/conf/schemas/domaincommon.rng |  5 ++++
>  src/qemu/qemu_command.c           |  6 ++++-
>  5 files changed, 53 insertions(+), 4 deletions(-)
> 
> diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
> index 9a2f065590..7b10dfa3da 100644
> --- a/docs/formatdomain.rst
> +++ b/docs/formatdomain.rst
> @@ -54,6 +54,13 @@ General metadata
>  
>     :since:`Since 0.8.7`, it is also possible to provide the UUID via a
>     `SMBIOS System Information`_ specification.
> +``hwuuid``
> +   The optional ``hwuuid`` element can be used to supply an alternative UUID 
> for
> +   identifying the virtual machine from the domain ``uuid`` above. The 
> difference
> +   between using the ``hwuuid`` element and simply providing an alternative 
> UUID
> +   via a `SMBIOS System Information`_ specification is that the ``hwuuid`` 
> affects
> +   all devices that expose the UUID to the guest.
> +   :since:`Since 11.6.0 QEMU/KVM only`
>  ``genid``
>     :since:`Since 4.4.0`, the ``genid`` element can be used to add a Virtual
>     Machine Generation ID which exposes a 128-bit, cryptographically random,
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index bfc62b6270..63603ca527 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -13098,6 +13098,7 @@ static int
>  virSysinfoSystemParseXML(xmlNodePtr node,
>                           xmlXPathContextPtr ctxt,
>                           virSysinfoSystemDef **sysdef,
> +                         unsigned char *hwUUID,
>                           unsigned char *domUUID,
>                           bool uuid_generated)
>  {
> @@ -13122,11 +13123,18 @@ virSysinfoSystemParseXML(xmlNodePtr node,
>          }
>          if (uuid_generated) {
>              memcpy(domUUID, uuidbuf, VIR_UUID_BUFLEN);
> -        } else if (memcmp(domUUID, uuidbuf, VIR_UUID_BUFLEN) != 0) {
> +        } else if (!virUUIDIsValid(hwUUID) &&
> +                   memcmp(domUUID, uuidbuf, VIR_UUID_BUFLEN) != 0) {
>              virReportError(VIR_ERR_XML_DETAIL, "%s",
>                             _("UUID mismatch between <uuid> and <sysinfo>"));
>              return -1;
>          }
> +        if (virUUIDIsValid(hwUUID) &&
> +            memcmp(hwUUID, uuidbuf, VIR_UUID_BUFLEN) != 0) {
> +                virReportError(VIR_ERR_XML_DETAIL, "%s",
> +                    _("UUID mismatch between <hwuuid> and <sysinfo>"));
> +                return -1;
> +        }

I think it'd be slightly clearer to re-arrange the order
and nesting here 

   if (uuid_generated) {
      ...
   } else if (virUUIDIsValid(hwUUID)) {
      if (memcmp(....)) {
       ...err
      }
   } else {
      if (memcmp(....)) {
       ...err
      }
   }


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Reply via email to