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 <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Michal Privoznik 2018-11-13 15:14:43 +01:00
parent 0f464afde1
commit 592ed505e1
7 changed files with 36 additions and 36 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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,

View File

@ -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:

View File

@ -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,