From 592ed505e1ae7f57015980e06e338822521ef901 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 13 Nov 2018 15:14:43 +0100 Subject: [PATCH] qemu_tpm: Pass virDomainObjPtr instead of virDomainDefPtr The TPM code currently accepts pointer to a domain definition. This is okay for now, but in near future the security driver APIs it calls will require domain object. Therefore, change the TPM code to accept the domain object pointer. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_extdevice.c | 16 ++++++++-------- src/qemu/qemu_extdevice.h | 4 ++-- src/qemu/qemu_process.c | 6 +++--- src/qemu/qemu_security.c | 14 +++++++------- src/qemu/qemu_security.h | 4 ++-- src/qemu/qemu_tpm.c | 24 ++++++++++++------------ src/qemu/qemu_tpm.h | 4 ++-- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c index d982922470..27cf118c14 100644 --- a/src/qemu/qemu_extdevice.c +++ b/src/qemu/qemu_extdevice.c @@ -129,16 +129,16 @@ qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, int qemuExtDevicesStart(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) { int ret = 0; - if (qemuExtDevicesInitPaths(driver, def) < 0) + if (qemuExtDevicesInitPaths(driver, vm->def) < 0) return -1; - if (def->tpm) - ret = qemuExtTPMStart(driver, def, logCtxt); + if (vm->def->tpm) + ret = qemuExtTPMStart(driver, vm, logCtxt); return ret; } @@ -146,13 +146,13 @@ qemuExtDevicesStart(virQEMUDriverPtr driver, void qemuExtDevicesStop(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) { - if (qemuExtDevicesInitPaths(driver, def) < 0) + if (qemuExtDevicesInitPaths(driver, vm->def) < 0) return; - if (def->tpm) - qemuExtTPMStop(driver, def); + if (vm->def->tpm) + qemuExtTPMStop(driver, vm); } diff --git a/src/qemu/qemu_extdevice.h b/src/qemu/qemu_extdevice.h index c557778ddb..c26cdd50b2 100644 --- a/src/qemu/qemu_extdevice.h +++ b/src/qemu/qemu_extdevice.h @@ -41,13 +41,13 @@ void qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int qemuExtDevicesStart(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; void qemuExtDevicesStop(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); bool qemuExtDevicesHasDevice(virDomainDefPtr def); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 622341b8a4..36164a3183 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6374,7 +6374,7 @@ qemuProcessLaunch(virConnectPtr conn, if (qemuProcessGenID(vm, flags) < 0) goto cleanup; - if (qemuExtDevicesStart(driver, vm->def, logCtxt) < 0) + if (qemuExtDevicesStart(driver, vm, logCtxt) < 0) goto cleanup; VIR_DEBUG("Building emulator command line"); @@ -6630,7 +6630,7 @@ qemuProcessLaunch(virConnectPtr conn, cleanup: if (ret < 0) - qemuExtDevicesStop(driver, vm->def); + qemuExtDevicesStop(driver, vm); qemuDomainSecretDestroy(vm); virCommandFree(cmd); virObjectUnref(logCtxt); @@ -7061,7 +7061,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, qemuDomainCleanupRun(driver, vm); - qemuExtDevicesStop(driver, vm->def); + qemuExtDevicesStop(driver, vm); /* Stop autodestroy in case guest is restarted */ qemuProcessAutoDestroyRemove(driver, vm); diff --git a/src/qemu/qemu_security.c b/src/qemu/qemu_security.c index 34921b4046..bf45abf93a 100644 --- a/src/qemu/qemu_security.c +++ b/src/qemu/qemu_security.c @@ -453,7 +453,7 @@ qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driver, * qemuSecurityStartTPMEmulator: * * @driver: the QEMU driver - * @def: the domain definition + * @vm: the domain object * @cmd: the command to run * @uid: the uid to run the emulator * @gid: the gid to run the emulator @@ -469,7 +469,7 @@ qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driver, */ int qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, virCommandPtr cmd, uid_t uid, gid_t gid, @@ -484,7 +484,7 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, transactionStarted = true; if (virSecurityManagerSetTPMLabels(driver->securityManager, - def) < 0) { + vm->def) < 0) { virSecurityManagerTransactionAbort(driver->securityManager); return -1; } @@ -494,7 +494,7 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, transactionStarted = false; if (virSecurityManagerSetChildProcessLabel(driver->securityManager, - def, cmd) < 0) + vm->def, cmd) < 0) goto cleanup; if (virSecurityManagerPreFork(driver->securityManager) < 0) @@ -519,7 +519,7 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, virSecurityManagerTransactionStart(driver->securityManager) >= 0) transactionStarted = true; - virSecurityManagerRestoreTPMLabels(driver->securityManager, def); + virSecurityManagerRestoreTPMLabels(driver->securityManager, vm->def); if (transactionStarted && virSecurityManagerTransactionCommit(driver->securityManager, -1) < 0) @@ -532,14 +532,14 @@ qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, void qemuSecurityCleanupTPMEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) { bool transactionStarted = false; if (virSecurityManagerTransactionStart(driver->securityManager) >= 0) transactionStarted = true; - virSecurityManagerRestoreTPMLabels(driver->securityManager, def); + virSecurityManagerRestoreTPMLabels(driver->securityManager, vm->def); if (transactionStarted && virSecurityManagerTransactionCommit(driver->securityManager, -1) < 0) diff --git a/src/qemu/qemu_security.h b/src/qemu/qemu_security.h index 13fc05152c..45d26a0dbf 100644 --- a/src/qemu/qemu_security.h +++ b/src/qemu/qemu_security.h @@ -84,7 +84,7 @@ int qemuSecurityRestoreChardevLabel(virQEMUDriverPtr driver, virDomainChrDefPtr chr); int qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, virCommandPtr cmd, uid_t uid, gid_t gid, @@ -92,7 +92,7 @@ int qemuSecurityStartTPMEmulator(virQEMUDriverPtr driver, int *cmdret); void qemuSecurityCleanupTPMEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def); + virDomainObjPtr vm); int qemuSecurityDomainSetPathLabel(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index c64114feac..af85f7b25f 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -756,7 +756,7 @@ qemuExtTPMCleanupHost(virDomainDefPtr def) */ static int qemuExtTPMStartEmulator(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) { int ret = -1; @@ -764,8 +764,8 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, int exitstatus = 0; char *errbuf = NULL; virQEMUDriverConfigPtr cfg; - virDomainTPMDefPtr tpm = def->tpm; - char *shortName = virDomainDefGetShortName(def); + virDomainTPMDefPtr tpm = vm->def->tpm; + char *shortName = virDomainDefGetShortName(vm->def); int cmdret = 0, timeout, rc; pid_t pid; @@ -777,7 +777,7 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, /* stop any left-over TPM emulator for this VM */ qemuTPMEmulatorStop(cfg->swtpmStateDir, shortName); - if (!(cmd = qemuTPMEmulatorBuildCommand(tpm, def->name, def->uuid, + if (!(cmd = qemuTPMEmulatorBuildCommand(tpm, vm->def->name, vm->def->uuid, driver->privileged, cfg->swtpm_user, cfg->swtpm_group, @@ -789,7 +789,7 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, virCommandSetErrorBuffer(cmd, &errbuf); - if (qemuSecurityStartTPMEmulator(driver, def, cmd, + if (qemuSecurityStartTPMEmulator(driver, vm, cmd, cfg->swtpm_user, cfg->swtpm_group, &exitstatus, &cmdret) < 0) goto cleanup; @@ -837,15 +837,15 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, int qemuExtTPMStart(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) { int ret = 0; - virDomainTPMDefPtr tpm = def->tpm; + virDomainTPMDefPtr tpm = vm->def->tpm; switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: - ret = qemuExtTPMStartEmulator(driver, def, logCtxt); + ret = qemuExtTPMStartEmulator(driver, vm, logCtxt); break; case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: case VIR_DOMAIN_TPM_TYPE_LAST: @@ -858,19 +858,19 @@ qemuExtTPMStart(virQEMUDriverPtr driver, void qemuExtTPMStop(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); char *shortName = NULL; - switch (def->tpm->type) { + switch (vm->def->tpm->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: - shortName = virDomainDefGetShortName(def); + shortName = virDomainDefGetShortName(vm->def); if (!shortName) goto cleanup; qemuTPMEmulatorStop(cfg->swtpmStateDir, shortName); - qemuSecurityCleanupTPMEmulator(driver, def); + qemuSecurityCleanupTPMEmulator(driver, vm); break; case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: case VIR_DOMAIN_TPM_TYPE_LAST: diff --git a/src/qemu/qemu_tpm.h b/src/qemu/qemu_tpm.h index 6eb1294da0..c7eeaafeb9 100644 --- a/src/qemu/qemu_tpm.h +++ b/src/qemu/qemu_tpm.h @@ -38,13 +38,13 @@ void qemuExtTPMCleanupHost(virDomainDefPtr def) ATTRIBUTE_NONNULL(1); int qemuExtTPMStart(virQEMUDriverPtr driver, - virDomainDefPtr def, + virDomainObjPtr vm, qemuDomainLogContextPtr logCtxt) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; void qemuExtTPMStop(virQEMUDriverPtr driver, - virDomainDefPtr def) + virDomainObjPtr vm) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); int qemuExtTPMSetupCgroup(virQEMUDriverPtr driver,