Re: [PATCH v4 1/2] qemu: formatting XML from domain def choosing the root name

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

 



On Thu, Aug 29, 2019 at 17:55:42 -0300, Maxiwell S. Garcia wrote:
> The function virDomainDefFormatInternal() has the predefined root name
> "domain" to format the XML. But to save both active and inactive domain
> in the snapshot XML, the new root name "inactiveDomain" was created.
> So, the new function virDomainDefFormatInternalSetRootName() allows to
> choose the root name of XML. The former function became a tiny wrapper
> to call the new function setting the correct parameters.
> 
> Signed-off-by: Maxiwell S. Garcia <maxiwell@xxxxxxxxxxxxx>
> ---
>  src/conf/domain_conf.c | 35 ++++++++++++++++++++++++++---------
>  src/conf/domain_conf.h |  6 ++++++
>  2 files changed, 32 insertions(+), 9 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index b7a342bb91..3154c07a86 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -21517,10 +21517,11 @@ virDomainDefParseNode(xmlDocPtr xml,
>      virDomainDefPtr def = NULL;
>      virDomainDefPtr ret = NULL;
>  
> -    if (!virXMLNodeNameEqual(root, "domain")) {
> +    if ((!virXMLNodeNameEqual(root, "domain")) &&
> +        (!virXMLNodeNameEqual(root, "inactiveDomain"))) {
>          virReportError(VIR_ERR_XML_ERROR,
>                         _("unexpected root element <%s>, "
> -                         "expecting <domain>"),
> +                         "expecting <domain> or <inactiveDomain>"),
>                         root->name);
>          goto cleanup;
>      }

The check does not belong to virDomainDefParseNode. It should be moved
to virDomainDefParse, which is the only place we don't select the domain
root element via XPath. Once moved, it must not be changed, since we
don't want to allow <inactiveDomain> to be allowed in a domain
definition XML files.

I've just sent patches moving this code.

> @@ -28277,17 +28278,29 @@ virDomainDefFormatFeatures(virBufferPtr buf,
>      return virXMLFormatElement(buf, "features", NULL, &childBuf);
>  }
>  
> -
> -/* This internal version appends to an existing buffer
> - * (possibly with auto-indent), rather than flattening
> - * to string.
> - * Return -1 on failure.  */
>  int
>  virDomainDefFormatInternal(virDomainDefPtr def,
>                             virCapsPtr caps,
>                             unsigned int flags,
>                             virBufferPtr buf,
>                             virDomainXMLOptionPtr xmlopt)
> +{
> +    return virDomainDefFormatInternalSetRootName(def, caps, flags, buf,
> +                                                 xmlopt, "domain");
> +}
> +
> +
> +/* This internal version appends to an existing buffer
> + * (possibly with auto-indent), rather than flattening
> + * to string.
> + * Return -1 on failure.  */
> +int
> +virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
> +                                      virCapsPtr caps,
> +                                      unsigned int flags,
> +                                      virBufferPtr buf,
> +                                      virDomainXMLOptionPtr xmlopt,
> +                                      const char *rootname)
>  {
>      unsigned char *uuid;
>      char uuidstr[VIR_UUID_STRING_BUFLEN];
> @@ -28312,7 +28325,11 @@ virDomainDefFormatInternal(virDomainDefPtr def,
>      if (def->id == -1)
>          flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
>  
> -    virBufferAsprintf(buf, "<domain type='%s'", type);
> +    if (!rootname || (STRNEQ(rootname, "domain") &&
> +                      STRNEQ(rootname, "inactiveDomain")))
> +        goto error;

This would return an error without setting any error message. But it's
not a big deal since we don't need runtime checks for programmers'
errors and we can just delete this check completely.

> +
> +    virBufferAsprintf(buf, "<%s type='%s'", rootname, type);
>      if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))
>          virBufferAsprintf(buf, " id='%d'", def->id);
>      if (def->namespaceData && def->ns.format)
> @@ -28794,7 +28811,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
>      virDomainSEVDefFormat(buf, def->sev);
>  
>      virBufferAdjustIndent(buf, -2);
> -    virBufferAddLit(buf, "</domain>\n");
> +    virBufferAsprintf(buf, "</%s>\n", rootname);
>  
>      if (virBufferCheckError(buf) < 0)
>          goto error;
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index 33cef5b75c..af1335cc16 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -3073,6 +3073,12 @@ int virDomainDefFormatInternal(virDomainDefPtr def,
>                                 unsigned int flags,
>                                 virBufferPtr buf,
>                                 virDomainXMLOptionPtr xmlopt);
> +int virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
> +                                          virCapsPtr caps,
> +                                          unsigned int flags,
> +                                          virBufferPtr buf,
> +                                          virDomainXMLOptionPtr xmlopt,
> +                                          const char *rootname);
>  
>  int virDomainDiskSourceFormat(virBufferPtr buf,
>                                virStorageSourcePtr src,

With the two problematic hunks removed

Reviewed-by: Jiri Denemark <jdenemar@xxxxxxxxxx>

I'll push this once the patches moving the check for "domain" root
element are acked.

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

  Powered by Linux