mirror of https://gitee.com/openkylin/libvirt.git
qemu_tpm, security, tests: change 'switch' clauses for 'if'
This trivial rework is aimed to reduce the amount of line changes made by the next patch, when 'def->tpm' will become a 'def->tpms' array. Instead of using a 'switch' where only the VIR_DOMAIN_TPM_TYPE_EMULATOR label does something, use an 'if' clause instead. Tested-by: Satheesh Rajendran <sathnaga@linux.vnet.ibm.com> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
9c77b617e6
commit
db45fb49e8
|
@ -680,14 +680,9 @@ qemuExtTPMInitPaths(virQEMUDriverPtr driver,
|
|||
{
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
|
||||
switch (def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
|
||||
return qemuTPMEmulatorInitPaths(def->tpm, cfg->swtpmStorageDir,
|
||||
def->uuid);
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -700,8 +695,7 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
|
|||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autofree char *shortName = NULL;
|
||||
|
||||
switch (def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
|
||||
shortName = virDomainDefGetShortName(def);
|
||||
if (!shortName)
|
||||
return -1;
|
||||
|
@ -711,9 +705,6 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
|
|||
cfg->swtpm_group,
|
||||
cfg->swtpmStateDir, cfg->user,
|
||||
shortName);
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -723,15 +714,8 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
|
|||
void
|
||||
qemuExtTPMCleanupHost(virDomainDefPtr def)
|
||||
{
|
||||
switch (def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
|
||||
qemuTPMDeleteEmulatorStorage(def->tpm);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
/* nothing to do */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -825,15 +809,9 @@ qemuExtTPMStart(virQEMUDriverPtr driver,
|
|||
{
|
||||
virDomainTPMDefPtr tpm = vm->def->tpm;
|
||||
|
||||
switch (tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
|
||||
return qemuExtTPMStartEmulator(driver, vm, incomingMigration);
|
||||
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -845,18 +823,13 @@ qemuExtTPMStop(virQEMUDriverPtr driver,
|
|||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autofree char *shortName = NULL;
|
||||
|
||||
switch (vm->def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (vm->def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
|
||||
shortName = virDomainDefGetShortName(vm->def);
|
||||
if (!shortName)
|
||||
return;
|
||||
|
||||
qemuTPMEmulatorStop(cfg->swtpmStateDir, shortName);
|
||||
qemuSecurityCleanupTPMEmulator(driver, vm);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -873,8 +846,7 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver,
|
|||
int rc;
|
||||
pid_t pid;
|
||||
|
||||
switch (def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
|
||||
shortName = virDomainDefGetShortName(def);
|
||||
if (!shortName)
|
||||
return -1;
|
||||
|
@ -886,10 +858,6 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver,
|
|||
}
|
||||
if (virCgroupAddProcess(cgroup, pid) < 0)
|
||||
return -1;
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -3532,10 +3532,7 @@ virSecuritySELinuxSetTPMLabels(virSecurityManagerPtr mgr,
|
|||
if (seclabel == NULL)
|
||||
return 0;
|
||||
|
||||
switch (def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
|
||||
ret = virSecuritySELinuxSetFileLabels(
|
||||
mgr, def->tpm->data.emulator.storagepath,
|
||||
seclabel);
|
||||
|
@ -3543,9 +3540,6 @@ virSecuritySELinuxSetTPMLabels(virSecurityManagerPtr mgr,
|
|||
ret = virSecuritySELinuxSetFileLabels(
|
||||
mgr, def->tpm->data.emulator.logfile,
|
||||
seclabel);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -3558,18 +3552,12 @@ virSecuritySELinuxRestoreTPMLabels(virSecurityManagerPtr mgr,
|
|||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
|
||||
ret = virSecuritySELinuxRestoreFileLabels(
|
||||
mgr, def->tpm->data.emulator.storagepath);
|
||||
if (ret == 0 && def->tpm->data.emulator.logfile)
|
||||
ret = virSecuritySELinuxRestoreFileLabels(
|
||||
mgr, def->tpm->data.emulator.logfile);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -1222,8 +1222,7 @@ get_files(vahControl * ctl)
|
|||
char *shortName = NULL;
|
||||
const char *tpmpath = NULL;
|
||||
|
||||
switch (ctl->def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (ctl->def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
|
||||
shortName = virDomainDefGetShortName(ctl->def);
|
||||
|
||||
switch (ctl->def->tpm->version) {
|
||||
|
@ -1256,10 +1255,6 @@ get_files(vahControl * ctl)
|
|||
RUNSTATEDIR, shortName);
|
||||
|
||||
VIR_FREE(shortName);
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -438,15 +438,10 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv,
|
|||
}
|
||||
|
||||
if (vm->def->tpm) {
|
||||
switch (vm->def->tpm->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
if (vm->def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
|
||||
VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path);
|
||||
vm->def->tpm->data.emulator.source.data.file.path = g_strdup("/dev/test");
|
||||
vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_FILE;
|
||||
break;
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue