In a few instances there is a plain if() check for
_virDomainSecDef::sectype. While this works perfectly for now,
soon there'll be another type and we can utilize compiler to
identify all the places that need adaptation. Switch those if()
statements to switch().
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_cgroup.c | 18 ++++++++++++++----
src/qemu/qemu_driver.c | 16 ++++++++++++++--
src/qemu/qemu_process.c | 17 +++++++++++++----
src/security/security_dac.c | 32 +++++++++++++++++++++++++-------
4 files changed, 66 insertions(+), 17 deletions(-)
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 5a5ba763a0..9e559c7c4f 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -845,10 +845,20 @@ qemuSetupDevicesCgroup(virDomainObj *vm)
return -1;
}
- if (vm->def->sec &&
- vm->def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV &&
- qemuSetupSEVCgroup(vm) < 0)
- return -1;
+ if (vm->def->sec) {
+ switch (vm->def->sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ if (qemuSetupSEVCgroup(vm) < 0)
+ return -1;
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_PV:
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity,
vm->def->sec->sectype);
+ return -1;
+ }
+ }
return 0;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3fd401fd3b..eb1612b9d7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19111,10 +19111,22 @@ qemuDomainGetLaunchSecurityInfo(virDomainPtr domain,
if (virDomainGetLaunchSecurityInfoEnsureACL(domain->conn, vm->def) < 0)
goto cleanup;
- if (vm->def->sec &&
- vm->def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
+ if (!vm->def->sec) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ switch (vm->def->sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
if (qemuDomainGetSEVInfo(vm, params, nparams, flags) < 0)
goto cleanup;
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_PV:
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity,
vm->def->sec->sectype);
+ return -1;
}
ret = 0;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f730cd1828..d14975180a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6741,11 +6741,20 @@ qemuProcessPrepareDomain(virQEMUDriver *driver,
for (i = 0; i < vm->def->nshmems; i++)
qemuDomainPrepareShmemChardev(vm->def->shmems[i]);
- if (vm->def->sec &&
- vm->def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
- VIR_DEBUG("Updating SEV platform info");
- if (qemuProcessUpdateSEVInfo(vm) < 0)
+ if (vm->def->sec) {
+ switch (vm->def->sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ VIR_DEBUG("Updating SEV platform info");
+ if (qemuProcessUpdateSEVInfo(vm) < 0)
+ return -1;
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_PV:
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity,
vm->def->sec->sectype);
return -1;
+ }
}
return 0;
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 669b90125c..d0864313c1 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -1951,10 +1951,19 @@ virSecurityDACRestoreAllLabel(virSecurityManager *mgr,
rc = -1;
}
- if (def->sec &&
- def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
- if (virSecurityDACRestoreSEVLabel(mgr, def) < 0)
- rc = -1;
+ if (def->sec) {
+ switch (def->sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ if (virSecurityDACRestoreSEVLabel(mgr, def) < 0)
+ rc = -1;
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_PV:
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity, def->sec->sectype);
+ return -1;
+ }
}
for (i = 0; i < def->nsysinfo; i++) {
@@ -2175,10 +2184,19 @@ virSecurityDACSetAllLabel(virSecurityManager *mgr,
return -1;
}
- if (def->sec &&
- def->sec->sectype == VIR_DOMAIN_LAUNCH_SECURITY_SEV) {
- if (virSecurityDACSetSEVLabel(mgr, def) < 0)
+ if (def->sec) {
+ switch (def->sec->sectype) {
+ case VIR_DOMAIN_LAUNCH_SECURITY_SEV:
+ if (virSecurityDACSetSEVLabel(mgr, def) < 0)
+ return -1;
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_PV:
+ break;
+ case VIR_DOMAIN_LAUNCH_SECURITY_NONE:
+ case VIR_DOMAIN_LAUNCH_SECURITY_LAST:
+ virReportEnumRangeError(virDomainLaunchSecurity, def->sec->sectype);
return -1;
+ }
}
if (virSecurityDACGetImageIds(secdef, priv, &user, &group))
--
2.44.2