qemu_tpm: Open code qemuSecurityStartTPMEmulator()

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>
This commit is contained in:
Michal Privoznik 2022-12-14 10:33:51 +01:00
parent c0c52a9519
commit 3d2dfec95b

View File

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