[RFC PATCH v1 4/6] conf: Add support for profile parameter on TPM emulator in domain XML

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

 



Extend the parser and XML builder with support for the profile
parameter and its remove_disabled attribute.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
---
 src/conf/domain_conf.c     | 32 ++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h     |  2 ++
 src/conf/domain_validate.c |  7 +++++++
 3 files changed, 41 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1c8fffdfa5..8dab1cabea 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3471,6 +3471,7 @@ void virDomainTPMDefFree(virDomainTPMDef *def)
         g_free(def->data.emulator.storagepath);
         g_free(def->data.emulator.logfile);
         virBitmapFree(def->data.emulator.activePcrBanks);
+        g_free(def->data.emulator.profile);
         break;
     case VIR_DOMAIN_TPM_TYPE_EXTERNAL:
         virObjectUnref(def->data.external.source);
@@ -10779,6 +10780,15 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *xmlopt,
  * <tpm model='tpm-tis'>
  *   <backend type='emulator' version='2.0' persistent_state='yes'>
  * </tpm>
+ *
+ * A profile for a TPM 2.0 can be added like this:
+ *
+ * <tpm model='tpm-crb'>
+ *   <backend type='emulator' version='2.0'>
+ *     <profile remove_disabled='check'>{"Name":"custom"}</profile>
+ *   </backend>
+ * </tpm>
+ *
  */
 static virDomainTPMDef *
 virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
@@ -10797,6 +10807,9 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
     g_autofree xmlNodePtr *backends = NULL;
     g_autofree xmlNodePtr *nodes = NULL;
     g_autofree char *type = NULL;
+    g_autofree char *profile = NULL;
+    virDomainTPMProfileRemoveDisabled profile_remove_disabled;
+    xmlNodePtr tmp;
     int bank;
 
     if (!(def = virDomainTPMDefNew(xmlopt)))
@@ -10887,6 +10900,18 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
             }
             virBitmapSetBitExpand(def->data.emulator.activePcrBanks, bank);
         }
+
+        def->data.emulator.profile = virXPathString("string(./backend/profile[1])", ctxt);
+        if ((tmp = virXPathNode("./backend/profile[1]", ctxt))) {
+            if (virXMLPropEnum(tmp, "remove_disabled",
+                               virDomainTPMProfileRemoveDisabledTypeFromString,
+                               VIR_XML_PROP_NONZERO,
+                               &profile_remove_disabled) < 0)
+                goto error;
+            if (profile_remove_disabled != VIR_DOMAIN_TPM_PROFILE_REMOVE_DISABLED_NONE)
+                def->data.emulator.profile_remove_disabled =
+                   virDomainTPMProfileRemoveDisabledTypeToString(profile_remove_disabled);
+        }
         break;
     case VIR_DOMAIN_TPM_TYPE_EXTERNAL:
         if (!(type = virXPathString("string(./backend/source/@type)", ctxt))) {
@@ -25077,6 +25102,13 @@ virDomainTPMDefFormat(virBuffer *buf,
 
             virXMLFormatElement(&backendChildBuf, "active_pcr_banks", NULL, &activePcrBanksBuf);
         }
+        if (def->data.emulator.profile) {
+            virBufferAddLit(&backendChildBuf, "<profile");
+            if (def->data.emulator.profile_remove_disabled)
+               virBufferAsprintf(&backendChildBuf, " remove_disabled='%s'",
+                                 def->data.emulator.profile_remove_disabled);
+            virBufferAsprintf(&backendChildBuf, ">%s</profile>\n", def->data.emulator.profile);
+        }
         break;
     case VIR_DOMAIN_TPM_TYPE_EXTERNAL:
         if (def->data.external.source->type == VIR_DOMAIN_CHR_TYPE_UNIX) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 97972f9909..4a171ee4da 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1493,6 +1493,8 @@ struct _virDomainTPMDef {
             bool hassecretuuid;
             bool persistent_state;
             virBitmap *activePcrBanks;
+            char *profile;
+            const char *profile_remove_disabled;
         } emulator;
         struct {
             virDomainChrSourceDef *source;
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index eddb4a5e74..efab3aa958 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -3025,6 +3025,13 @@ virDomainTPMDevValidate(const virDomainTPMDef *tpm)
                            virDomainTPMVersionTypeToString(VIR_DOMAIN_TPM_VERSION_2_0));
             return -1;
         }
+        if (tpm->data.emulator.profile &&
+            tpm->data.emulator.version != VIR_DOMAIN_TPM_VERSION_2_0) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("<profile/> requires TPM version '%1$s'"),
+                           virDomainTPMVersionTypeToString(VIR_DOMAIN_TPM_VERSION_2_0));
+            return -1;
+        }
         break;
 
     case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
-- 
2.46.0



[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