mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf: Rework SEV XML parse and format methods
Make use of virDomainLaunchSecurity enum. Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
001b482e30
commit
f7bc6febd0
@ -14732,6 +14732,8 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode,
|
|||||||
&def->sectype) < 0)
|
&def->sectype) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
switch ((virDomainLaunchSecurity) def->sectype) {
|
||||||
|
case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
|
||||||
if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) {
|
if (virXPathULongHex("string(./policy)", ctxt, &policy) < 0) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("failed to get launch security policy"));
|
_("failed to get launch security policy"));
|
||||||
@ -14766,6 +14768,14 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode,
|
|||||||
def->session = virXPathString("string(./session)", 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,37 @@ virDomainKeyWrapDefFormat(virBuffer *buf, virDomainKeyWrapDef *keywrap)
|
|||||||
static void
|
static void
|
||||||
virDomainSEVDefFormat(virBuffer *buf, virDomainSEVDef *sev)
|
virDomainSEVDefFormat(virBuffer *buf, virDomainSEVDef *sev)
|
||||||
{
|
{
|
||||||
|
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||||
|
|
||||||
if (!sev)
|
if (!sev)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<launchSecurity type='%s'>\n",
|
virBufferAsprintf(&attrBuf, " type='%s'",
|
||||||
virDomainLaunchSecurityTypeToString(sev->sectype));
|
virDomainLaunchSecurityTypeToString(sev->sectype));
|
||||||
virBufferAdjustIndent(buf, 2);
|
|
||||||
|
|
||||||
|
switch ((virDomainLaunchSecurity) sev->sectype) {
|
||||||
|
case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
|
||||||
if (sev->haveCbitpos)
|
if (sev->haveCbitpos)
|
||||||
virBufferAsprintf(buf, "<cbitpos>%d</cbitpos>\n", sev->cbitpos);
|
virBufferAsprintf(&childBuf, "<cbitpos>%d</cbitpos>\n", sev->cbitpos);
|
||||||
|
|
||||||
if (sev->haveReducedPhysBits)
|
if (sev->haveReducedPhysBits)
|
||||||
virBufferAsprintf(buf, "<reducedPhysBits>%d</reducedPhysBits>\n",
|
virBufferAsprintf(&childBuf, "<reducedPhysBits>%d</reducedPhysBits>\n",
|
||||||
sev->reduced_phys_bits);
|
sev->reduced_phys_bits);
|
||||||
virBufferAsprintf(buf, "<policy>0x%04x</policy>\n", sev->policy);
|
virBufferAsprintf(&childBuf, "<policy>0x%04x</policy>\n", sev->policy);
|
||||||
if (sev->dh_cert)
|
if (sev->dh_cert)
|
||||||
virBufferEscapeString(buf, "<dhCert>%s</dhCert>\n", sev->dh_cert);
|
virBufferEscapeString(&childBuf, "<dhCert>%s</dhCert>\n", sev->dh_cert);
|
||||||
|
|
||||||
if (sev->session)
|
if (sev->session)
|
||||||
virBufferEscapeString(buf, "<session>%s</session>\n", sev->session);
|
virBufferEscapeString(&childBuf, "<session>%s</session>\n", sev->session);
|
||||||
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
break;
|
||||||
virBufferAddLit(buf, "</launchSecurity>\n");
|
case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
|
||||||
|
case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
virXMLFormatElement(buf, "launchSecurity", &attrBuf, &childBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user