[libvirt] [PATCH 3/9] conf: Add compile time check that devices were checked for ABI stability

Peter Krempa pkrempa at redhat.com
Tue Oct 14 07:29:07 UTC 2014


As in the device info iterator add a switch that will force the compiler
to check that new device types are added to the ABI stability checker.
---
 src/conf/domain_conf.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5e3c389..0634116 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -15449,6 +15449,39 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
             goto error;
     }

+    /* Coverity is not very happy with this - all dead_error_condition */
+#if !STATIC_ANALYSIS
+    /* This switch statement is here to trigger compiler warning when adding
+     * a new device type. When you are adding a new field to the switch you
+     * also have to add an check above. Otherwise the switch statement has no
+     * real function here and should be optimized out by the compiler. */
+    i = VIR_DOMAIN_DEVICE_LAST;
+    switch ((virDomainDeviceType) i) {
+    case VIR_DOMAIN_DEVICE_DISK:
+    case VIR_DOMAIN_DEVICE_LEASE:
+    case VIR_DOMAIN_DEVICE_FS:
+    case VIR_DOMAIN_DEVICE_NET:
+    case VIR_DOMAIN_DEVICE_INPUT:
+    case VIR_DOMAIN_DEVICE_SOUND:
+    case VIR_DOMAIN_DEVICE_VIDEO:
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+    case VIR_DOMAIN_DEVICE_HUB:
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_CHR:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_NVRAM:
+    case VIR_DOMAIN_DEVICE_LAST:
+    case VIR_DOMAIN_DEVICE_RNG:
+    case VIR_DOMAIN_DEVICE_SHMEM:
+        break;
+    }
+#endif
+
     return true;

  error:
-- 
2.1.0




More information about the libvir-list mailing list