From: Marc-André Lureau <marcandre.lureau(a)redhat.com>
Learn to parse a directory for the TPM state.
Signed-off-by: Marc-André Lureau <marcandre.lureau(a)redhat.com>
---
docs/formatdomain.rst | 3 +++
src/conf/domain_conf.c | 13 ++++++++++---
src/conf/domain_conf.h | 1 +
src/conf/schemas/domaincommon.rng | 15 ++++++++++++---
tests/qemuxmlconfdata/tpm-emulator-tpm2-enc.xml | 1 +
5 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index 4818113bc2..24dcc6daaa 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -8183,6 +8183,9 @@ Example: usage of the TPM Emulator
This attribute requires that swtpm v0.7 or later is installed.
+ ``dir``
+ The path to the TPM state storage directory.
+
:since:`Since v10.8.0`
``persistent_state``
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 18c58d16dc..d1e9e4a50c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10865,13 +10865,16 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
source_node = virXPathNode("./backend/source", ctxt);
if (source_node) {
- path = virXMLPropString(source_node, "file");
+ if ((path = virXMLPropString(source_node, "file"))) {
+ def->data.emulator.storage_type = VIR_DOMAIN_TPM_STORAGE_FILE;
+ } else if ((path = virXMLPropString(source_node, "dir"))) {
+ def->data.emulator.storage_type = VIR_DOMAIN_TPM_STORAGE_DIR;
+ }
if (!path) {
virReportError(VIR_ERR_XML_ERROR, "%s",
- _("missing TPM file source"));
+ _("missing TPM file or directory source"));
goto error;
}
- def->data.emulator.storage_type = VIR_DOMAIN_TPM_STORAGE_FILE;
def->data.emulator.storagepath = g_steal_pointer(&path);
}
@@ -25084,6 +25087,10 @@ virDomainTPMDefFormat(virBuffer *buf,
virBufferAsprintf(&backendChildBuf, "<source
file='%s'/>\n",
def->data.emulator.storagepath);
break;
+ case VIR_DOMAIN_TPM_STORAGE_DIR:
+ virBufferAsprintf(&backendChildBuf, "<source
dir='%s'/>\n",
+ def->data.emulator.storagepath);
+ break;
case VIR_DOMAIN_TPM_STORAGE_DEFAULT:
break;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 371e6ecf6c..4e4ae2e048 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1465,6 +1465,7 @@ typedef enum {
typedef enum {
VIR_DOMAIN_TPM_STORAGE_DEFAULT,
+ VIR_DOMAIN_TPM_STORAGE_DIR,
VIR_DOMAIN_TPM_STORAGE_FILE,
} virDomainTPMStorage;
diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng
index 62d3f0e6fe..f6b47ae97e 100644
--- a/src/conf/schemas/domaincommon.rng
+++ b/src/conf/schemas/domaincommon.rng
@@ -5985,9 +5985,18 @@
<define name="tpm-backend-emulator-source">
<optional>
<element name="source">
- <attribute name="file">
- <ref name="filePath"/>
- </attribute>
+ <choice>
+ <group>
+ <attribute name="dir">
+ <ref name="absDirPath"/>
+ </attribute>
+ </group>
+ <group>
+ <attribute name="file">
+ <ref name="filePath"/>
+ </attribute>
+ </group>
+ </choice>
</element>
</optional>
</define>
diff --git a/tests/qemuxmlconfdata/tpm-emulator-tpm2-enc.xml
b/tests/qemuxmlconfdata/tpm-emulator-tpm2-enc.xml
index 9c2279b28b..016c68296c 100644
--- a/tests/qemuxmlconfdata/tpm-emulator-tpm2-enc.xml
+++ b/tests/qemuxmlconfdata/tpm-emulator-tpm2-enc.xml
@@ -30,6 +30,7 @@
<tpm model='tpm-tis'>
<backend type='emulator' version='2.0'>
<encryption secret='32ee7e76-2178-47a1-ab7b-269e6e348015'/>
+ <source dir='/some/dir'/>
</backend>
</tpm>
<audio id='1' type='none'/>
--
2.45.2.827.g557ae147e6