Re: [PATCH v3 2/4] conf: Parse virtio-crypto in the domain XML

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

 



On Wed, Jul 05, 2017 at 01:17 PM +0200, "Longpeng(Mike)" <longpeng2@xxxxxxxxxx> wrote:
> This patch parse the domain XML with virtio-crypto
> support, the virtio-crypto XML looks like this:
>
>   <crypto model='virtio'>
>     <backend type='builtin' queues='1'/>
>   </crypto>
>
> Signed-off-by: Longpeng(Mike) <longpeng2@xxxxxxxxxx>
> ---
>  src/conf/domain_conf.c         | 213 ++++++++++++++++++++++++++++++++++++++++-
>  src/conf/domain_conf.h         |  32 +++++++
>  src/libvirt_private.syms       |   4 +
>  src/qemu/qemu_domain_address.c |   1 +
>  src/qemu/qemu_driver.c         |   6 ++
>  src/qemu/qemu_hotplug.c        |   1 +
>  6 files changed, 256 insertions(+), 1 deletion(-)
>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c

(snip)

> +
> +    switch ((virDomainCryptoBackend) def->backend) {
> +    case VIR_DOMAIN_CRYPTO_BACKEND_BUILTIN:
> +        queues = virXMLPropString(backends[0], "queues");
> +        if (queues && virStrToLong_ui(queues, NULL, 10, &def->queues) < 0) {
> +            virReportError(VIR_ERR_XML_ERROR,
> +                            _("Malformed 'queues' value '%s'"), queues);
                              ^^
                              Indentation

> +        break;
> +
> +    case VIR_DOMAIN_CRYPTO_BACKEND_LAST:
> +        break;
> +    }
> +
> +    if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
> +        goto error;
> +
> + cleanup:
> +    VIR_FREE(model);
> +    VIR_FREE(backend);
> +    VIR_FREE(queues);
> +    VIR_FREE(backends);
> +    ctxt->node = save;
> +    return def;
> +
> + error:
> +    virDomainCryptoDefFree(def);
> +    def = NULL;
> +    goto cleanup;
> +}
> +
> +
>  static virDomainMemballoonDefPtr
>  virDomainMemballoonDefParseXML(xmlNodePtr node,
>                                 xmlXPathContextPtr ctxt,
> @@ -14643,6 +14752,10 @@ virDomainDeviceDefParse(const char *xmlStr,
>          if (!(dev->data.iommu = virDomainIOMMUDefParseXML(node, ctxt)))
>              goto error;
>          break;
> +    case VIR_DOMAIN_DEVICE_CRYPTO:
> +        if (!(dev->data.crypto = virDomainCryptoDefParseXML(node, ctxt, flags)))
> +            goto error;
> +        break;
>      case VIR_DOMAIN_DEVICE_NONE:
>      case VIR_DOMAIN_DEVICE_LAST:
>          break;
> @@ -17709,6 +17822,22 @@ virDomainDefParseXML(xmlDocPtr xml,
>      }
>      VIR_FREE(nodes);
>
> +    /* Parse the crypto devices */
> +    if ((n = virXPathNodeSet("./devices/crypto", ctxt, &nodes)) < 0)
> +        goto error;
> +    if (n && VIR_ALLOC_N(def->cryptos, n) < 0)
> +        goto error;
> +    for (i = 0; i < n; i++) {
> +        virDomainCryptoDefPtr crypto = virDomainCryptoDefParseXML(nodes[i],
> +                                                                  ctxt,
> +                                                                  flags);
> +        if (!crypto)
> +            goto error;
> +
> +        def->cryptos[def->ncryptos++] = crypto;
> +    }
> +    VIR_FREE(nodes);
> +
>      if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &def->cpu) < 0)
>          goto error;
>
> @@ -19815,6 +19944,25 @@ virDomainRNGDefCheckABIStability(virDomainRNGDefPtr src,
>
>
>  static bool
> +virDomainCryptoDefCheckABIStability(virDomainCryptoDefPtr src,
> +                                    virDomainCryptoDefPtr dst)
> +{
> +    if (src->model != dst->model) {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                       _("Target Crypto model '%s' does not match source '%s'"),
> +                       virDomainCryptoModelTypeToString(dst->model),
> +                       virDomainCryptoModelTypeToString(src->model));
> +        return false;
> +    }
> +
> +    if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
> +        return false;
> +
> +    return true;
> +}
> +
> +
> +static bool
>  virDomainHubDefCheckABIStability(virDomainHubDefPtr src,
>                                   virDomainHubDefPtr dst)
>  {
> @@ -20718,6 +20866,17 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src,
>          !xmlopt->abi.domain(src, dst))
>          goto error;
>
> +    if (src->ncryptos != dst->ncryptos) {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                       _("Target domain crypto device count %zu "
> +                         "does not match source %zu"), dst->ncryptos, src->ncryptos);
> +        goto error;
> +    }
> +
> +    for (i = 0; i < src->ncryptos; i++)
> +        if (!virDomainCryptoDefCheckABIStability(src->cryptos[i], dst->cryptos[i]))
> +            goto error;
> +
>      /* Coverity is not very happy with this - all dead_error_condition */
>  #if !STATIC_ANALYSIS
>      /* This switch statement is here to trigger compiler warning when adding
> @@ -20751,6 +20910,7 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src,
>      case VIR_DOMAIN_DEVICE_SHMEM:
>      case VIR_DOMAIN_DEVICE_MEMORY:
>      case VIR_DOMAIN_DEVICE_IOMMU:
> +    case VIR_DOMAIN_DEVICE_CRYPTO:
>          break;
>      }
>  #endif
> @@ -23387,6 +23547,49 @@ virDomainRNGDefFree(virDomainRNGDefPtr def)
>
>
>  static int
> +virDomainCryptoDefFormat(virBufferPtr buf,
> +                         virDomainCryptoDefPtr def,
> +                         unsigned int flags)
> +{
> +    const char *model = virDomainCryptoModelTypeToString(def->model);
> +    const char *backend = virDomainCryptoBackendTypeToString(def->backend);
> +
> +    virBufferAsprintf(buf, "<crypto model='%s'>\n", model);
> +    virBufferAdjustIndent(buf, 2);
> +    virBufferAsprintf(buf, "<backend type='%s'", backend);
> +
> +    switch ((virDomainCryptoBackend) def->backend) {
> +    case VIR_DOMAIN_CRYPTO_BACKEND_BUILTIN:
> +        if (def->queues)
> +            virBufferAsprintf(buf, " queues='%u'", def->queues);
> +
> +        virBufferAddLit(buf, "/>\n");
> +        break;
> +
> +    case VIR_DOMAIN_CRYPTO_BACKEND_LAST:
> +        break;
> +    }
> +
> +    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
> +        return -1;
> +
> +    virBufferAdjustIndent(buf, -2);
> +    virBufferAddLit(buf, "</crypto>\n");
> +    return 0;
> +}
> +
> +void
> +virDomainCryptoDefFree(virDomainCryptoDefPtr def)
> +{
> +    if (!def)
> +        return;
> +
> +    virDomainDeviceInfoClear(&def->info);
> +    VIR_FREE(def);
> +}

You should add 'virDomainCryptoDefFree' to libvirt_private.syms.

> +
> +
> +static int
>  virDomainMemorySourceDefFormat(virBufferPtr buf,
>                                 virDomainMemoryDefPtr def)
>  {
> @@ -25418,6 +25621,11 @@ virDomainDefFormatInternal(virDomainDefPtr def,
>              goto error;


Beste Grüße / Kind regards
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


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