[PATCH v7 04/10] qemu_tpm, security, tests: change 'switch' clauses for 'if'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxx>
Reviewed-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_tpm.c             | 44 +++++----------------------------
 src/security/security_selinux.c | 16 ++----------
 src/security/virt-aa-helper.c   |  7 +-----
 tests/qemuxml2argvtest.c        |  7 +-----
 4 files changed, 10 insertions(+), 64 deletions(-)

diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index fe567f440c..afec0e5328 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -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;
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index e6819af26c..554bdd4f80 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -3549,10 +3549,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);
@@ -3560,9 +3557,6 @@ virSecuritySELinuxSetTPMLabels(virSecurityManagerPtr mgr,
             ret = virSecuritySELinuxSetFileLabels(
                 mgr, def->tpm->data.emulator.logfile,
                 seclabel);
-        break;
-    case VIR_DOMAIN_TPM_TYPE_LAST:
-        break;
     }
 
     return ret;
@@ -3575,18 +3569,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;
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 34c281100e..7e8f0a84be 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -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;
         }
     }
 
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 02f8846e57..f57d2a21b3 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -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;
        }
     }
 
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux