[virt-tools-list] [virt-manager PATCH 3/5] tpm: add TPM emulator backend

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Thu May 24 10:39:15 UTC 2018


From: Marc-André Lureau <marcandre.lureau at redhat.com>

Support is being added to libvirt. An emulated backend doesn't require
any path, since libvirt will take care of finding the emulator and
managing the storage. However, the version to emulate can be specified.

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 .../virt-install-singleton-config-2.xml       |  6 +++++
 tests/clitest.py                              |  1 +
 virtinst/cli.py                               |  1 +
 virtinst/devices/tpm.py                       | 26 +++++++++++++++++--
 4 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml b/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml
index 8cd92544..674eebe4 100644
--- a/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml
+++ b/tests/cli-test-xml/compare/virt-install-singleton-config-2.xml
@@ -148,6 +148,9 @@
         <device path="/dev/tpm0"/>
       </backend>
     </tpm>
+    <tpm model="tpm-crb">
+      <backend type="emulator" version="2"/>
+    </tpm>
     <graphics type="vnc" port="-1"/>
     <watchdog model="ib700" action="pause"/>
     <memballoon model="virtio"/>
@@ -322,6 +325,9 @@
         <device path="/dev/tpm0"/>
       </backend>
     </tpm>
+    <tpm model="tpm-crb">
+      <backend type="emulator" version="2"/>
+    </tpm>
     <graphics type="vnc" port="-1"/>
     <watchdog model="ib700" action="pause"/>
     <memballoon model="virtio"/>
diff --git a/tests/clitest.py b/tests/clitest.py
index 5271935f..d323aace 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -450,6 +450,7 @@ cache.mode=emulate,cache.level=3 \
 --watchdog ib700,action=pause \
 --tpm passthrough,model=tpm-tis,path=/dev/tpm0 \
 --tpm passthrough,model=tpm-crb,path=/dev/tpm0 \
+--tpm emulator,model=tpm-crb,version=2 \
 --rng egd,backend_host=127.0.0.1,backend_service=8000,backend_type=udp,backend_mode=bind,backend_connect_host=foo,backend_connect_service=708 \
 --panic iobase=0x506 \
 """, "singleton-config-2")
diff --git a/virtinst/cli.py b/virtinst/cli.py
index a2624e66..a20cdb23 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -2440,6 +2440,7 @@ _register_virt_parser(ParserTPM)
 _add_device_address_args(ParserTPM)
 ParserTPM.add_arg("type", "type")
 ParserTPM.add_arg("model", "model")
+ParserTPM.add_arg("version", "version")
 ParserTPM.add_arg("device_path", "path")
 
 
diff --git a/virtinst/devices/tpm.py b/virtinst/devices/tpm.py
index ab7492ed..54cd3517 100644
--- a/virtinst/devices/tpm.py
+++ b/virtinst/devices/tpm.py
@@ -16,9 +16,15 @@ from ..xmlbuilder import XMLProperty
 class DeviceTpm(Device):
     XML_NAME = "tpm"
 
+    VERSION_1_2 = "1.2"
+    VERSION_2 = "2"
+    VERSION_DEFAULT = "default"
+    VERSIONS = [VERSION_1_2, VERSION_2]
+
     TYPE_PASSTHROUGH = "passthrough"
+    TYPE_EMULATOR = "emulator"
     TYPE_DEFAULT = "default"
-    TYPES = [TYPE_PASSTHROUGH]
+    TYPES = [TYPE_PASSTHROUGH, TYPE_EMULATOR]
 
     MODEL_TIS = "tpm-tis"
     MODEL_CRB = "tpm-crb"
@@ -29,6 +35,8 @@ class DeviceTpm(Device):
     def get_pretty_type(tpm_type):
         if tpm_type == DeviceTpm.TYPE_PASSTHROUGH:
             return _("Passthrough device")
+        if tpm_type == DeviceTpm.TYPE_EMULATOR:
+            return _("Emulated device")
         return tpm_type
 
     @staticmethod
@@ -45,6 +53,7 @@ class DeviceTpm(Device):
         """
         users = {
             "device_path": [self.TYPE_PASSTHROUGH],
+            "version": [self.TYPE_EMULATOR],
         }
 
         if users.get(propname):
@@ -54,7 +63,20 @@ class DeviceTpm(Device):
 
     type = XMLProperty("./backend/@type",
                        default_cb=lambda s: s.TYPE_PASSTHROUGH)
+
+    def _get_default_version(self):
+        if not self.supports_property("version"):
+            return None
+        return self.VERSION_1_2
+    version = XMLProperty("./backend/@version",
+                          default_cb=_get_default_version)
     model = XMLProperty("./@model",
                        default_cb=lambda s: s.MODEL_TIS)
+
+
+    def _get_default_device_path(self):
+        if not self.supports_property("device_path"):
+            return None
+        return "/dev/tpm0"
     device_path = XMLProperty("./backend/device/@path",
-                              default_cb=lambda s: "/dev/tpm0")
+                              default_cb=_get_default_device_path)
-- 
2.17.0.253.g3dd125b46d




More information about the virt-tools-list mailing list