Re: [PATCH v5 02/11] conf: Rework SEV XML parse and format methods

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

 



On Fri, Jul 16, 2021 at 11:44:26AM +0200, Boris Fiuczynski wrote:
> Make use of virDomainLaunchSecurity enum.
> 
> Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
> Reviewed-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
> ---
>  src/conf/domain_conf.c | 108 ++++++++++++++++++++++++-----------------
>  1 file changed, 64 insertions(+), 44 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index f1d4ef021c..74254d505b 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -14732,40 +14732,50 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode,
>                         &def->sectype) < 0)
>          return NULL;
>  
> -    if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) {
> -        virReportError(VIR_ERR_XML_ERROR, "%s",
> -                       _("failed to get launch security policy"));
> -        return NULL;
> -    }
> +    switch ((virDomainLaunchSecurity) def->sectype) {
> +    case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
> +        if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) {
> +            virReportError(VIR_ERR_XML_ERROR, "%s",
> +                           _("failed to get launch security policy"));
> +            return NULL;
> +        }
>  
> -    /* the following attributes are platform dependent and if missing, we can
> -     * autofill them from domain capabilities later
> -     */
> -    rc = virXPathUInt("string(./cbitpos)", ctxt, &def->cbitpos);
> -    if (rc == 0) {
> -        def->haveCbitpos = true;
> -    } else if (rc == -2) {
> -        virReportError(VIR_ERR_XML_ERROR, "%s",
> -                       _("Invalid format for launch security cbitpos"));
> -        return NULL;
> -    }
> +        /* the following attributes are platform dependent and if missing, we can
> +         * autofill them from domain capabilities later
> +        */
> +        rc = virXPathUInt("string(./cbitpos)", ctxt, &def->cbitpos);
> +        if (rc == 0) {
> +            def->haveCbitpos = true;
> +        } else if (rc == -2) {
> +            virReportError(VIR_ERR_XML_ERROR, "%s",
> +                           _("Invalid format for launch security cbitpos"));
> +            return NULL;
> +        }
>  
> -    rc = virXPathUInt("string(./reducedPhysBits)", ctxt,
> -                      &def->reduced_phys_bits);
> -    if (rc == 0) {
> -        def->haveReducedPhysBits = true;
> -    } else if (rc == -2) {
> -        virReportError(VIR_ERR_XML_ERROR, "%s",
> -                       _("Invalid format for launch security "
> -                         "reduced-phys-bits"));
> -        return NULL;
> -    }
> +        rc = virXPathUInt("string(./reducedPhysBits)", ctxt,
> +                          &def->reduced_phys_bits);
> +        if (rc == 0) {
> +            def->haveReducedPhysBits = true;
> +        } else if (rc == -2) {
> +            virReportError(VIR_ERR_XML_ERROR, "%s",
> +                           _("Invalid format for launch security "
> +                             "reduced-phys-bits"));
> +            return NULL;
> +        }
>  
> -    def->policy = policy;
> -    def->dh_cert = virXPathString("string(./dhCert)", ctxt);
> -    def->session = virXPathString("string(./session)", ctxt);
> +        def->policy = policy;
> +        def->dh_cert = virXPathString("string(./dhCert)", ctxt);
> +        def->session = virXPathString("string(./session)", ctxt);
>  
> -    return g_steal_pointer(&def);
> +        return g_steal_pointer(&def);
> +    case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
> +    case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
> +    default:
> +        virReportError(VIR_ERR_XML_ERROR,
> +                       _("unsupported launch security type '%s'"),
> +                       virDomainLaunchSecurityTypeToString(def->sectype));
> +        return NULL;
> +    }
>  }
>  
>  
> @@ -26856,28 +26866,38 @@ virDomainKeyWrapDefFormat(virBuffer *buf, virDomainKeyWrapDef *keywrap)
>  static void
>  virDomainSEVDefFormat(virBuffer *buf, virDomainSEVDef *sev)
>  {
> +    g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
> +    g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
> +
>      if (!sev)
>          return;
>  
> -    virBufferAsprintf(buf, "<launchSecurity type='%s'>\n",
> +    virBufferAsprintf(&attrBuf, " type='%s'",
>                        virDomainLaunchSecurityTypeToString(sev->sectype));
> -    virBufferAdjustIndent(buf, 2);
>  
> -    if (sev->haveCbitpos)
> -        virBufferAsprintf(buf, "<cbitpos>%d</cbitpos>\n", sev->cbitpos);
> +    switch ((virDomainLaunchSecurity) sev->sectype) {
> +    case VIR_DOMAIN_LAUNCH_SECURITY_SEV: {

No need for the braces, I'll drop it before pushing.

Pavel

Attachment: signature.asc
Description: PGP signature


[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