提交 72299db6 编写于 作者: S Stefan Berger 提交者: John Ferlan

tpm: Run swtpm_setup with less parameters on incoming migration

In case of an incoming migration we do not need to run swtpm_setup
with all the parameters but only want to get the benefit of it
creating a TPM state file for us that we can then label with an
SELinux label. The actual state will be overwritten by the in-
coming state. So we have to pass an indicator for incomingMigration
all the way to the command line parameter generation for swtpm_setup.
Signed-off-by: NStefan Berger <stefanb@linux.ibm.com>
Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
上级 43686f36
...@@ -128,7 +128,8 @@ qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, ...@@ -128,7 +128,8 @@ qemuExtDevicesCleanupHost(virQEMUDriverPtr driver,
int int
qemuExtDevicesStart(virQEMUDriverPtr driver, qemuExtDevicesStart(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
qemuDomainLogContextPtr logCtxt) qemuDomainLogContextPtr logCtxt,
bool incomingMigration)
{ {
int ret = 0; int ret = 0;
...@@ -136,7 +137,7 @@ qemuExtDevicesStart(virQEMUDriverPtr driver, ...@@ -136,7 +137,7 @@ qemuExtDevicesStart(virQEMUDriverPtr driver,
return -1; return -1;
if (vm->def->tpm) if (vm->def->tpm)
ret = qemuExtTPMStart(driver, vm, logCtxt); ret = qemuExtTPMStart(driver, vm, logCtxt, incomingMigration);
return ret; return ret;
} }
......
...@@ -40,7 +40,8 @@ void qemuExtDevicesCleanupHost(virQEMUDriverPtr driver, ...@@ -40,7 +40,8 @@ void qemuExtDevicesCleanupHost(virQEMUDriverPtr driver,
int qemuExtDevicesStart(virQEMUDriverPtr driver, int qemuExtDevicesStart(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
qemuDomainLogContextPtr logCtxt) qemuDomainLogContextPtr logCtxt,
bool incomingMigration)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_RETURN_CHECK;
......
...@@ -6774,7 +6774,7 @@ qemuProcessLaunch(virConnectPtr conn, ...@@ -6774,7 +6774,7 @@ qemuProcessLaunch(virConnectPtr conn,
if (qemuProcessGenID(vm, flags) < 0) if (qemuProcessGenID(vm, flags) < 0)
goto cleanup; goto cleanup;
if (qemuExtDevicesStart(driver, vm, logCtxt) < 0) if (qemuExtDevicesStart(driver, vm, logCtxt, incoming != NULL) < 0)
goto cleanup; goto cleanup;
VIR_DEBUG("Building emulator command line"); VIR_DEBUG("Building emulator command line");
......
...@@ -453,6 +453,7 @@ qemuTPMSetupEncryption(const unsigned char *secretuuid, ...@@ -453,6 +453,7 @@ qemuTPMSetupEncryption(const unsigned char *secretuuid,
* for the user given by userid or 'tss' * for the user given by userid or 'tss'
* @tpmversion: The version of the TPM, either a TPM 1.2 or TPM 2 * @tpmversion: The version of the TPM, either a TPM 1.2 or TPM 2
* @encryption: pointer to virStorageEncryption holding secret * @encryption: pointer to virStorageEncryption holding secret
* @incomingMigration: whether we have an incoming migration
* *
* Setup the external swtpm by creating endorsement key and * Setup the external swtpm by creating endorsement key and
* certificates for it. * certificates for it.
...@@ -466,7 +467,8 @@ qemuTPMEmulatorRunSetup(const char *storagepath, ...@@ -466,7 +467,8 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
gid_t swtpm_group, gid_t swtpm_group,
const char *logfile, const char *logfile,
const virDomainTPMVersion tpmversion, const virDomainTPMVersion tpmversion,
const unsigned char *secretuuid) const unsigned char *secretuuid,
bool incomingMigration)
{ {
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
int exitstatus; int exitstatus;
...@@ -525,6 +527,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath, ...@@ -525,6 +527,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
pwdfile_fd = -1; pwdfile_fd = -1;
} }
if (!incomingMigration) {
virCommandAddArgList(cmd, virCommandAddArgList(cmd,
"--tpm-state", storagepath, "--tpm-state", storagepath,
"--vmid", vmid, "--vmid", vmid,
...@@ -535,6 +538,12 @@ qemuTPMEmulatorRunSetup(const char *storagepath, ...@@ -535,6 +538,12 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
"--lock-nvram", "--lock-nvram",
"--not-overwrite", "--not-overwrite",
NULL); NULL);
} else {
virCommandAddArgList(cmd,
"--tpm-state", storagepath,
"--overwrite",
NULL);
}
virCommandClearCaps(cmd); virCommandClearCaps(cmd);
...@@ -568,6 +577,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath, ...@@ -568,6 +577,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
* @swtpmStateDir: the directory where swtpm writes the pid file and creates the * @swtpmStateDir: the directory where swtpm writes the pid file and creates the
* Unix socket * Unix socket
* @shortName: the short name of the VM * @shortName: the short name of the VM
* @incomingMigration: whether we have an incoming migration
* *
* Create the virCommand use for starting the emulator * Create the virCommand use for starting the emulator
* Do some initializations on the way, such as creation of storage * Do some initializations on the way, such as creation of storage
...@@ -581,7 +591,8 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm, ...@@ -581,7 +591,8 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm,
uid_t swtpm_user, uid_t swtpm_user,
gid_t swtpm_group, gid_t swtpm_group,
const char *swtpmStateDir, const char *swtpmStateDir,
const char *shortName) const char *shortName,
bool incomingMigration)
{ {
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
bool created = false; bool created = false;
...@@ -605,7 +616,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm, ...@@ -605,7 +616,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDefPtr tpm,
qemuTPMEmulatorRunSetup(tpm->data.emulator.storagepath, vmname, vmuuid, qemuTPMEmulatorRunSetup(tpm->data.emulator.storagepath, vmname, vmuuid,
privileged, swtpm_user, swtpm_group, privileged, swtpm_user, swtpm_group,
tpm->data.emulator.logfile, tpm->version, tpm->data.emulator.logfile, tpm->version,
secretuuid) < 0) secretuuid, incomingMigration) < 0)
goto error; goto error;
unlink(tpm->data.emulator.source.data.nix.path); unlink(tpm->data.emulator.source.data.nix.path);
...@@ -814,6 +825,7 @@ qemuExtTPMCleanupHost(virDomainDefPtr def) ...@@ -814,6 +825,7 @@ qemuExtTPMCleanupHost(virDomainDefPtr def)
* @driver: QEMU driver * @driver: QEMU driver
* @vm: the domain object * @vm: the domain object
* @logCtxt: log context * @logCtxt: log context
* @incomingMigration: whether we have an incoming migration
* *
* Start the external TPM Emulator: * Start the external TPM Emulator:
* - have the command line built * - have the command line built
...@@ -822,7 +834,8 @@ qemuExtTPMCleanupHost(virDomainDefPtr def) ...@@ -822,7 +834,8 @@ qemuExtTPMCleanupHost(virDomainDefPtr def)
static int static int
qemuExtTPMStartEmulator(virQEMUDriverPtr driver, qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
qemuDomainLogContextPtr logCtxt) qemuDomainLogContextPtr logCtxt,
bool incomingMigration)
{ {
int ret = -1; int ret = -1;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
...@@ -846,7 +859,8 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, ...@@ -846,7 +859,8 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
driver->privileged, driver->privileged,
cfg->swtpm_user, cfg->swtpm_user,
cfg->swtpm_group, cfg->swtpm_group,
cfg->swtpmStateDir, shortName))) cfg->swtpmStateDir, shortName,
incomingMigration)))
goto cleanup; goto cleanup;
if (qemuExtDeviceLogCommand(logCtxt, cmd, "TPM Emulator") < 0) if (qemuExtDeviceLogCommand(logCtxt, cmd, "TPM Emulator") < 0)
...@@ -903,14 +917,15 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver, ...@@ -903,14 +917,15 @@ qemuExtTPMStartEmulator(virQEMUDriverPtr driver,
int int
qemuExtTPMStart(virQEMUDriverPtr driver, qemuExtTPMStart(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
qemuDomainLogContextPtr logCtxt) qemuDomainLogContextPtr logCtxt,
bool incomingMigration)
{ {
int ret = 0; int ret = 0;
virDomainTPMDefPtr tpm = vm->def->tpm; virDomainTPMDefPtr tpm = vm->def->tpm;
switch (tpm->type) { switch (tpm->type) {
case VIR_DOMAIN_TPM_TYPE_EMULATOR: case VIR_DOMAIN_TPM_TYPE_EMULATOR:
ret = qemuExtTPMStartEmulator(driver, vm, logCtxt); ret = qemuExtTPMStartEmulator(driver, vm, logCtxt, incomingMigration);
break; break;
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
case VIR_DOMAIN_TPM_TYPE_LAST: case VIR_DOMAIN_TPM_TYPE_LAST:
......
...@@ -37,7 +37,8 @@ void qemuExtTPMCleanupHost(virDomainDefPtr def) ...@@ -37,7 +37,8 @@ void qemuExtTPMCleanupHost(virDomainDefPtr def)
int qemuExtTPMStart(virQEMUDriverPtr driver, int qemuExtTPMStart(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
qemuDomainLogContextPtr logCtxt) qemuDomainLogContextPtr logCtxt,
bool incomingMigration)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_RETURN_CHECK;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册