Re: [PATCH 2/2] conf: Move generation of NVDIMM UUID into post parse callback

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

 



On Mon, Jan 18, 2021 at 15:15:54 +0100, Michal Privoznik wrote:
> It's better to fill in missing values in post parse callbacks
> than during parsing.
> 
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  src/conf/domain_conf.c | 35 ++++++++++++++++++++++-------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index a2ddfcf947..4f0798de45 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c

[...]

> @@ -5345,6 +5346,19 @@ virDomainMemoryDefPostParse(virDomainMemoryDefPtr mem)
>          break;
>  
>      case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
> +        /* If no NVDIMM UUID was provided in XML, generate one. */
> +        if (ARCH_IS_PPC64(def->os.arch) &&
> +            !mem->uuid) {
> +
> +            mem->uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
> +            if (virUUIDGenerate(mem->uuid) < 0) {
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               "%s", _("Failed to generate UUID"));
> +                return -1;
> +            }
> +        }


You can also reject if an UUID is present but the architecture isn't
PPC64 here, rather than ...

> +        break;
> +
>      case VIR_DOMAIN_MEMORY_MODEL_DIMM:
>      case VIR_DOMAIN_MEMORY_MODEL_NONE:
>      case VIR_DOMAIN_MEMORY_MODEL_LAST:

[...]

> @@ -15526,24 +15540,19 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xmlopt,
>      }
>      VIR_FREE(tmp);
>  
> +    /* Extract NVDIMM UUID. */
>      if (def->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM &&
> -        ARCH_IS_PPC64(dom->os.arch)) {
> -        /* Extract nvdimm uuid or generate a new one */
> -        tmp = virXPathString("string(./uuid[1])", ctxt);
> -
> +        ARCH_IS_PPC64(dom->os.arch) &&

... keeping it in the parser, where it doesn't make much sense.

> +        (tmp = virXPathString("string(./uuid[1])", ctxt))) {
>          def->uuid = g_new0(unsigned char, VIR_UUID_BUFLEN);
> -        if (!tmp) {
> -            if (virUUIDGenerate(def->uuid) < 0) {
> -                virReportError(VIR_ERR_INTERNAL_ERROR,
> -                               "%s", _("Failed to generate UUID"));
> -                goto error;
> -            }
> -        } else if (virUUIDParse(tmp, def->uuid) < 0) {
> +

Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx>




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

  Powered by Linux