提交 db45fb49 编写于 作者: D Daniel Henrique Barboza 提交者: Ján Tomko

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: NSatheesh Rajendran <sathnaga@linux.vnet.ibm.com>
Reviewed-by: NStefan Berger <stefanb@linux.ibm.com>
Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
Signed-off-by: NJán Tomko <jtomko@redhat.com>
上级 9c77b617
...@@ -680,14 +680,9 @@ qemuExtTPMInitPaths(virQEMUDriverPtr driver, ...@@ -680,14 +680,9 @@ qemuExtTPMInitPaths(virQEMUDriverPtr driver,
{ {
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
switch (def->tpm->type) { if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
return qemuTPMEmulatorInitPaths(def->tpm, cfg->swtpmStorageDir, return qemuTPMEmulatorInitPaths(def->tpm, cfg->swtpmStorageDir,
def->uuid); def->uuid);
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
}
return 0; return 0;
} }
...@@ -700,8 +695,7 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver, ...@@ -700,8 +695,7 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
g_autofree char *shortName = NULL; g_autofree char *shortName = NULL;
switch (def->tpm->type) { if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
shortName = virDomainDefGetShortName(def); shortName = virDomainDefGetShortName(def);
if (!shortName) if (!shortName)
return -1; return -1;
...@@ -711,9 +705,6 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver, ...@@ -711,9 +705,6 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
cfg->swtpm_group, cfg->swtpm_group,
cfg->swtpmStateDir, cfg->user, cfg->swtpmStateDir, cfg->user,
shortName); shortName);
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
} }
return 0; return 0;
...@@ -723,15 +714,8 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver, ...@@ -723,15 +714,8 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
void void
qemuExtTPMCleanupHost(virDomainDefPtr def) qemuExtTPMCleanupHost(virDomainDefPtr def)
{ {
switch (def->tpm->type) { if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
qemuTPMDeleteEmulatorStorage(def->tpm); 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, ...@@ -825,15 +809,9 @@ qemuExtTPMStart(virQEMUDriverPtr driver,
{ {
virDomainTPMDefPtr tpm = vm->def->tpm; virDomainTPMDefPtr tpm = vm->def->tpm;
switch (tpm->type) { if (tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
return qemuExtTPMStartEmulator(driver, vm, incomingMigration); return qemuExtTPMStartEmulator(driver, vm, incomingMigration);
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
}
return 0; return 0;
} }
...@@ -845,18 +823,13 @@ qemuExtTPMStop(virQEMUDriverPtr driver, ...@@ -845,18 +823,13 @@ qemuExtTPMStop(virQEMUDriverPtr driver,
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
g_autofree char *shortName = NULL; g_autofree char *shortName = NULL;
switch (vm->def->tpm->type) { if (vm->def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
shortName = virDomainDefGetShortName(vm->def); shortName = virDomainDefGetShortName(vm->def);
if (!shortName) if (!shortName)
return; return;
qemuTPMEmulatorStop(cfg->swtpmStateDir, shortName); qemuTPMEmulatorStop(cfg->swtpmStateDir, shortName);
qemuSecurityCleanupTPMEmulator(driver, vm); qemuSecurityCleanupTPMEmulator(driver, vm);
break;
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
} }
return; return;
...@@ -873,8 +846,7 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver, ...@@ -873,8 +846,7 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver,
int rc; int rc;
pid_t pid; pid_t pid;
switch (def->tpm->type) { if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
shortName = virDomainDefGetShortName(def); shortName = virDomainDefGetShortName(def);
if (!shortName) if (!shortName)
return -1; return -1;
...@@ -886,10 +858,6 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver, ...@@ -886,10 +858,6 @@ qemuExtTPMSetupCgroup(virQEMUDriverPtr driver,
} }
if (virCgroupAddProcess(cgroup, pid) < 0) if (virCgroupAddProcess(cgroup, pid) < 0)
return -1; return -1;
break;
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
} }
return 0; return 0;
......
...@@ -3532,10 +3532,7 @@ virSecuritySELinuxSetTPMLabels(virSecurityManagerPtr mgr, ...@@ -3532,10 +3532,7 @@ virSecuritySELinuxSetTPMLabels(virSecurityManagerPtr mgr,
if (seclabel == NULL) if (seclabel == NULL)
return 0; return 0;
switch (def->tpm->type) { if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
break;
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
ret = virSecuritySELinuxSetFileLabels( ret = virSecuritySELinuxSetFileLabels(
mgr, def->tpm->data.emulator.storagepath, mgr, def->tpm->data.emulator.storagepath,
seclabel); seclabel);
...@@ -3543,9 +3540,6 @@ virSecuritySELinuxSetTPMLabels(virSecurityManagerPtr mgr, ...@@ -3543,9 +3540,6 @@ virSecuritySELinuxSetTPMLabels(virSecurityManagerPtr mgr,
ret = virSecuritySELinuxSetFileLabels( ret = virSecuritySELinuxSetFileLabels(
mgr, def->tpm->data.emulator.logfile, mgr, def->tpm->data.emulator.logfile,
seclabel); seclabel);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
} }
return ret; return ret;
...@@ -3558,18 +3552,12 @@ virSecuritySELinuxRestoreTPMLabels(virSecurityManagerPtr mgr, ...@@ -3558,18 +3552,12 @@ virSecuritySELinuxRestoreTPMLabels(virSecurityManagerPtr mgr,
{ {
int ret = 0; int ret = 0;
switch (def->tpm->type) { if (def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
break;
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
ret = virSecuritySELinuxRestoreFileLabels( ret = virSecuritySELinuxRestoreFileLabels(
mgr, def->tpm->data.emulator.storagepath); mgr, def->tpm->data.emulator.storagepath);
if (ret == 0 && def->tpm->data.emulator.logfile) if (ret == 0 && def->tpm->data.emulator.logfile)
ret = virSecuritySELinuxRestoreFileLabels( ret = virSecuritySELinuxRestoreFileLabels(
mgr, def->tpm->data.emulator.logfile); mgr, def->tpm->data.emulator.logfile);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
} }
return ret; return ret;
......
...@@ -1222,8 +1222,7 @@ get_files(vahControl * ctl) ...@@ -1222,8 +1222,7 @@ get_files(vahControl * ctl)
char *shortName = NULL; char *shortName = NULL;
const char *tpmpath = NULL; const char *tpmpath = NULL;
switch (ctl->def->tpm->type) { if (ctl->def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
shortName = virDomainDefGetShortName(ctl->def); shortName = virDomainDefGetShortName(ctl->def);
switch (ctl->def->tpm->version) { switch (ctl->def->tpm->version) {
...@@ -1256,10 +1255,6 @@ get_files(vahControl * ctl) ...@@ -1256,10 +1255,6 @@ get_files(vahControl * ctl)
RUNSTATEDIR, shortName); RUNSTATEDIR, shortName);
VIR_FREE(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, ...@@ -438,15 +438,10 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv,
} }
if (vm->def->tpm) { if (vm->def->tpm) {
switch (vm->def->tpm->type) { if (vm->def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR) {
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
VIR_FREE(vm->def->tpm->data.emulator.source.data.file.path); 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.data.file.path = g_strdup("/dev/test");
vm->def->tpm->data.emulator.source.type = VIR_DOMAIN_CHR_TYPE_FILE; 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;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册