[PATCH v1 4/8] domain_conf.c: XML parsing for VIR_DOMAIN_DEVICE_TPMPROXY

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

 



Add virDomainTPMProxyDefParseXML() and virDomainTPMProxyDefFormat()
to handle the creating of the TPM Proxy device via its XML
description.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/conf/domain_conf.c | 94 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4c731b9f36..4f43dcddee 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13779,6 +13779,50 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt,
     return NULL;
 }
 
+static virDomainTPMProxyDefPtr
+virDomainTPMProxyDefParseXML(virDomainXMLOptionPtr xmlopt,
+                             xmlNodePtr node,
+                             xmlXPathContextPtr ctxt,
+                             unsigned int flags)
+{
+    virDomainTPMProxyDefPtr def;
+    VIR_XPATH_NODE_AUTORESTORE(ctxt);
+    g_autofree char *path = NULL;
+    g_autofree char *model = NULL;
+
+    if (VIR_ALLOC(def) < 0)
+        return NULL;
+
+    def->model = VIR_DOMAIN_TPMPROXY_MODEL_DEFAULT;
+
+    model = virXMLPropString(node, "model");
+    if (model != NULL &&
+        (def->model = virDomainTPMProxyModelTypeFromString(model)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Unknown TPM Proxy frontend model '%s'"), model);
+        goto error;
+    }
+
+    ctxt->node = node;
+
+    path = virXPathString("string(./device/@path)", ctxt);
+    if (!path) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing TPM Proxy device path"));
+        goto error;
+    }
+    def->path = g_steal_pointer(&path);
+
+    if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info, flags) < 0)
+        goto error;
+
+    return def;
+
+ error:
+    virDomainTPMProxyDefFree(def);
+    return NULL;
+}
+
 static virDomainPanicDefPtr
 virDomainPanicDefParseXML(virDomainXMLOptionPtr xmlopt,
                           xmlNodePtr node,
@@ -17076,6 +17120,10 @@ virDomainDeviceDefParse(const char *xmlStr,
             return NULL;
         break;
     case VIR_DOMAIN_DEVICE_TPMPROXY:
+        if (!(dev->data.tpmproxy = virDomainTPMProxyDefParseXML(xmlopt, node,
+                                                                ctxt, flags)))
+            return NULL;
+        break;
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_LAST:
         break;
@@ -22024,6 +22072,23 @@ virDomainDefParseXML(xmlDocPtr xml,
     }
     VIR_FREE(nodes);
 
+    /* Parse TPM Proxy device */
+    if ((n = virXPathNodeSet("./devices/tpmproxy", ctxt, &nodes)) < 0)
+        goto error;
+
+    if (n > 1) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("only a single TPM Proxy device is supported"));
+        goto error;
+    }
+
+    if (n > 0) {
+        if (!(def->tpmproxy = virDomainTPMProxyDefParseXML(xmlopt, nodes[0],
+                                                           ctxt, flags)))
+            goto error;
+    }
+    VIR_FREE(nodes);
+
     if ((n = virXPathNodeSet("./devices/nvram", ctxt, &nodes)) < 0)
         goto error;
 
@@ -27166,6 +27231,26 @@ virDomainTPMDefFormat(virBufferPtr buf,
 }
 
 
+static int
+virDomainTPMProxyDefFormat(virBufferPtr buf,
+                           virDomainTPMProxyDefPtr def,
+                           unsigned int flags)
+{
+    virBufferAsprintf(buf, "<tpmproxy model='%s'>\n",
+                      virDomainTPMProxyModelTypeToString(def->model));
+    virBufferAdjustIndent(buf, 2);
+    virBufferEscapeString(buf, "<device path='%s'/>\n", def->path);
+
+    if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
+        return -1;
+
+    virBufferAdjustIndent(buf, -2);
+    virBufferAddLit(buf, "</tpmproxy>\n");
+
+    return 0;
+}
+
+
 static int
 virDomainSoundDefFormat(virBufferPtr buf,
                         virDomainSoundDefPtr def,
@@ -29853,6 +29938,11 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
             goto error;
     }
 
+    if (def->tpmproxy) {
+        if (virDomainTPMProxyDefFormat(buf, def->tpmproxy, flags) < 0)
+            goto error;
+    }
+
     for (n = 0; n < def->ngraphics; n++) {
         if (virDomainGraphicsDefFormat(buf, def->graphics[n], flags) < 0)
             goto error;
@@ -31038,13 +31128,15 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
     case VIR_DOMAIN_DEVICE_VSOCK:
         rc = virDomainVsockDefFormat(&buf, src->data.vsock);
         break;
+    case VIR_DOMAIN_DEVICE_TPMPROXY:
+        rc = virDomainTPMProxyDefFormat(&buf, src->data.tpmproxy, flags);
+        break;
 
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_SMARTCARD:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
     case VIR_DOMAIN_DEVICE_NVRAM:
     case VIR_DOMAIN_DEVICE_IOMMU:
-    case VIR_DOMAIN_DEVICE_TPMPROXY:
     case VIR_DOMAIN_DEVICE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Copying definition of '%d' type "
-- 
2.26.2






[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