[PATCH v4 08/10] qemu: build command line for the TPM Proxy device

Daniel Henrique Barboza posted 10 patches 4 years, 6 months ago
There is a newer version of this series
[PATCH v4 08/10] qemu: build command line for the TPM Proxy device
Posted by Daniel Henrique Barboza 4 years, 6 months ago
This patch wraps it up all the wiring done in previous patches,
enabling a PPC64 guest to launch a guest using a TPM Proxy
device.

Note that device validation is already being done in qemu_validate.c,
qemuValidateDomainDeviceDefTPM(), on domain define time. We don't
need to verify QEMU capabilities for this device again inside
qemu_command.c.

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 src/qemu/qemu_alias.c   |  5 ++++-
 src/qemu/qemu_command.c | 27 ++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 9d72391ddb..522426794d 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -408,7 +408,10 @@ qemuAssignDeviceTPMAlias(virDomainTPMDefPtr tpm,
     if (tpm->info.alias)
         return 0;
 
-    tpm->info.alias = g_strdup_printf("tpm%d", idx);
+    if (tpm->model == VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY)
+        tpm->info.alias = g_strdup_printf("tpmproxy%d", idx);
+    else
+        tpm->info.alias = g_strdup_printf("tpm%d", idx);
     return 0;
 }
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d2ac19a7a8..1eef79b2a0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8979,6 +8979,26 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
 }
 
 
+static int
+qemuBuildTPMProxyCommandLine(virCommandPtr cmd,
+                             virDomainTPMDefPtr tpm)
+{
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    const char *filePath = NULL;
+
+    filePath = tpm->data.passthrough.source.data.file.path;
+
+    virCommandAddArg(cmd, "-device");
+    virBufferAsprintf(&buf, "%s,id=%s,host-path=",
+                      virDomainTPMModelTypeToString(tpm->model),
+                      tpm->info.alias);
+    virQEMUBuildBufferEscapeComma(&buf, filePath);
+    virCommandAddArgBuffer(cmd, &buf);
+
+    return 0;
+}
+
+
 static int
 qemuBuildTPMsCommandLine(virCommandPtr cmd,
                          const virDomainDef *def,
@@ -8987,8 +9007,13 @@ qemuBuildTPMsCommandLine(virCommandPtr cmd,
     size_t i;
 
     for (i = 0; i < def->ntpms; i++) {
-        if (qemuBuildTPMCommandLine(cmd, def, def->tpms[i], qemuCaps) < 0)
+        if (def->tpms[i]->model == VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY) {
+            if (qemuBuildTPMProxyCommandLine(cmd, def->tpms[i]) < 0)
+                return -1;
+        } else if (qemuBuildTPMCommandLine(cmd, def,
+                                           def->tpms[i], qemuCaps) < 0) {
             return -1;
+        }
     }
 
     return 0;
-- 
2.26.2