]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_tpm: Open code qemuSecurityStartTPMEmulator()
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 14 Dec 2022 09:33:51 +0000 (10:33 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 3 Jan 2023 16:19:22 +0000 (17:19 +0100)
When starting swtpm binary, the qemuSecurityStartTPMEmulator() is
called which sets seclabel on the TPM state and then uses
qemuSecurityCommandRun() to execute the swtpm binary with proper
seclabel. Well, the aim is to ditch
qemuSecurityStartTPMEmulator() because it entangles two distinct
operations. Just call functions for them separately.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_tpm.c

index 03055002cb69b0609bc0a52278f2194d514bc3c4..b2748eb6a4080ffc084bb96af2fd51709bf35b8c 100644 (file)
@@ -927,7 +927,6 @@ qemuTPMEmulatorStart(virQEMUDriver *driver,
     virTimeBackOffVar timebackoff;
     const unsigned long long timeout = 1000; /* ms */
     bool setTPMStateLabel = true;
-    bool teardownlabel = false;
     int cmdret = 0;
     pid_t pid = -1;
 
@@ -960,18 +959,18 @@ qemuTPMEmulatorStart(virQEMUDriver *driver,
         setTPMStateLabel = false;
     }
 
-    if (qemuSecurityStartTPMEmulator(driver, vm, cmd,
-                                     cfg->swtpm_user, cfg->swtpm_group,
-                                     setTPMStateLabel, NULL, &cmdret) < 0) {
+    if (qemuSecuritySetTPMLabels(driver, vm, setTPMStateLabel) < 0)
+        return -1;
+
+    if (qemuSecurityCommandRun(driver, vm, cmd, cfg->swtpm_user,
+                               cfg->swtpm_group, NULL, &cmdret) < 0)
         goto error;
-    }
 
     if (cmdret < 0) {
-        /* virCommandRun() hidden in qemuSecurityStartTPMEmulator()
+        /* virCommandRun() hidden in qemuSecurityCommandRun()
          * already reported error. */
         goto error;
     }
-    teardownlabel = true;
 
     if (virPidFileReadPath(pidfile, &pid) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -1014,8 +1013,7 @@ qemuTPMEmulatorStart(virQEMUDriver *driver,
         virProcessKillPainfully(pid, true);
     if (pidfile)
         unlink(pidfile);
-    if (teardownlabel)
-        qemuSecurityRestoreTPMLabels(driver, vm, setTPMStateLabel);
+    qemuSecurityRestoreTPMLabels(driver, vm, setTPMStateLabel);
     return -1;
 }