[PATCH 18/20] virDomainDeviceInfo: Convert 'type' field to proper enum type

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

 



Convert the field, adjust the XML parsers to use virXMLPropEnum()
and fill in missing cases to switch() statements.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/device_conf.c     | 12 +++++++++++-
 src/conf/device_conf.h     |  4 ++--
 src/conf/domain_conf.c     | 21 +++++++--------------
 src/conf/domain_validate.c |  2 +-
 src/qemu/qemu_command.c    |  4 ++--
 src/qemu/qemu_monitor.c    | 12 ++++++++++++
 src/qemu/qemu_validate.c   |  2 +-
 7 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index aa0cc8945c..f3d977f2b7 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -98,7 +98,7 @@ virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
     if (a->type != b->type)
         return false;
 
-    switch ((virDomainDeviceAddressType) a->type) {
+    switch (a->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
     /* address types below don't have any specific data */
@@ -427,6 +427,16 @@ virDomainDeviceAddressIsValid(virDomainDeviceInfo *info,
 
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
         return true;
+
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
+        break;
     }
 
     return false;
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index f2907dc596..a83377417a 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -32,7 +32,7 @@
 #include "virenum.h"
 
 typedef enum {
-    VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
+    VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE = 0,
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI,
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE,
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL,
@@ -116,7 +116,7 @@ struct _virDomainDeviceDimmAddress {
 typedef struct _virDomainDeviceInfo virDomainDeviceInfo;
 struct _virDomainDeviceInfo {
     char *alias;
-    int type; /* virDomainDeviceAddressType */
+    virDomainDeviceAddressType type;
     union {
         virPCIDeviceAddress pci;
         virDomainDeviceDriveAddress drive;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f48020f893..a743a0628c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5366,7 +5366,7 @@ virDomainDeviceInfoFormat(virBuffer *buf,
     virBufferAsprintf(&attrBuf, " type='%s'",
                       virDomainDeviceAddressTypeToString(info->type));
 
-    switch ((virDomainDeviceAddressType) info->type) {
+    switch (info->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
         if (!virPCIDeviceAddressIsEmpty(&info->addr.pci)) {
             virBufferAsprintf(&attrBuf, " domain='0x%04x' bus='0x%02x' "
@@ -5539,21 +5539,14 @@ static int
 virDomainDeviceAddressParseXML(xmlNodePtr address,
                                virDomainDeviceInfo *info)
 {
-    g_autofree char *type = virXMLPropString(address, "type");
-
-    if (!type) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("No type specified for device address"));
-        return -1;
-    }
-
-    if ((info->type = virDomainDeviceAddressTypeFromString(type)) <= 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown address type '%1$s'"), type);
+    if (virXMLPropEnum(address, "type",
+                       virDomainDeviceAddressTypeFromString,
+                       VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+                       &info->type) < 0) {
         return -1;
     }
 
-    switch ((virDomainDeviceAddressType) info->type) {
+    switch (info->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
         if (virPCIDeviceAddressParseXML(address, &info->addr.pci) < 0)
             return -1;
@@ -19625,7 +19618,7 @@ virDomainDeviceInfoCheckABIStability(virDomainDeviceInfo *src,
         return false;
     }
 
-    switch ((virDomainDeviceAddressType) src->type) {
+    switch (src->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
         if (src->addr.pci.domain != dst->addr.pci.domain ||
             src->addr.pci.bus != dst->addr.pci.bus ||
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 1d25aa32c2..e70841c1d6 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2806,7 +2806,7 @@ virDomainDeviceInfoValidate(const virDomainDeviceDef *dev)
     if (!(info = virDomainDeviceGetInfo(dev)))
         return 0;
 
-    switch ((virDomainDeviceAddressType) info->type) {
+    switch (info->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 11ede25c0b..8a7b80719f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -541,7 +541,7 @@ qemuBuildDeviceAddressProps(virJSONValue *props,
                             const virDomainDef *domainDef,
                             const virDomainDeviceInfo *info)
 {
-    switch ((virDomainDeviceAddressType) info->type) {
+    switch (info->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: {
         g_autofree char *pciaddr = NULL;
         g_autofree char *bus = qemuBuildDeviceAddressPCIGetBus(domainDef, info);
@@ -981,7 +981,7 @@ qemuBuildVirtioDevGetConfig(const virDomainDeviceDef *device,
 
     virBufferAdd(&buf, baseName, -1);
 
-    switch ((virDomainDeviceAddressType) info->type) {
+    switch (info->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
         implName = "pci";
         break;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7053539c7d..320729f067 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -954,6 +954,18 @@ qemuMonitorInitBalloonObjectPath(qemuMonitor *mon,
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
         name = "virtio-balloon-ccw";
         break;
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED:
+    case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
     default:
         return;
     }
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 27fd5b9a99..36c7941fe9 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1479,7 +1479,7 @@ qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev,
                                    const virDomainDef *def,
                                    virQEMUCaps *qemuCaps)
 {
-    switch ((virDomainDeviceAddressType) info->type) {
+    switch (info->type) {
     case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
         if (qemuValidateDomainDeviceDefZPCIAddress(info, qemuCaps) < 0)
             return -1;
-- 
2.41.0




[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