From: Arun Menon <[email protected]>

Update logic for both creation and parsing the 2 new attributes backup
and fsync introduced in swtpm.

Signed-off-by: Arun Menon <[email protected]>
---
 src/conf/domain_conf.c | 31 +++++++++++++++++++++++++++++++
 src/conf/domain_conf.h |  2 ++
 2 files changed, 33 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 34d3b00079..0326ad7c58 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11449,6 +11449,11 @@ virDomainSmartcardDefParseXML(virDomainXMLOption 
*xmlopt,
  *   </backend>
  * </tpm>
  *
+ * Emulator state backup and fsync is supported with the following:
+ * <tpm model='tpm-crb'>
+ *   <backend type='emulator' version='2.0' backup='yes' fsync='yes'>
+ * </tpm>
+ *
  */
 static virDomainTPMDef *
 virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
@@ -11465,6 +11470,8 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
     g_autofree char *path = NULL;
     g_autofree char *secretuuid = NULL;
     g_autofree char *persistent_state = NULL;
+    g_autofree char *backup = NULL;
+    g_autofree char *fsync = NULL;
     g_autofree xmlNodePtr *backends = NULL;
     g_autofree xmlNodePtr *nodes = NULL;
     g_autofree char *type = NULL;
@@ -11562,6 +11569,26 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
             }
         }
 
+        backup = virXMLPropString(backends[0], "backup");
+        if (backup) {
+            if (virStringParseYesNo(backup,
+                                    &def->data.emulator.backup) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("Invalid backup value, either 'yes' or 
'no'"));
+                goto error;
+            }
+        }
+
+        fsync = virXMLPropString(backends[0], "fsync");
+        if (fsync) {
+            if (virStringParseYesNo(fsync,
+                                    &def->data.emulator.fsync) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("Invalid fsync value, either 'yes' or 'no'"));
+                goto error;
+            }
+        }
+
         if ((nnodes = virXPathNodeSet("./backend/active_pcr_banks/*", ctxt, 
&nodes)) < 0)
             break;
         if (nnodes > 0)
@@ -26662,6 +26689,10 @@ virDomainTPMDefFormat(virBuffer *buf,
         }
         if (def->data.emulator.persistent_state)
             virBufferAddLit(&backendAttrBuf, " persistent_state='yes'");
+        if (def->data.emulator.backup)
+            virBufferAddLit(&backendAttrBuf, " backup='yes'");
+        if (def->data.emulator.fsync)
+            virBufferAddLit(&backendAttrBuf, " fsync='yes'");
         if (def->data.emulator.debug != 0)
             virBufferAsprintf(&backendAttrBuf, " debug='%u'",
                               def->data.emulator.debug);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3732525af4..0d93487689 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1546,6 +1546,8 @@ struct _virDomainTPMEmulatorDef {
         char *name;   /* name read from active profile */
         virDomainTPMProfileRemoveDisabled removeDisabled;
     } profile;
+    bool backup;
+    bool fsync;
 };
 
 struct _virDomainTPMDef {
-- 
2.54.0

Reply via email to