Use the appropriate type for the variable and refactor the XML parser to
parse it correctly using virXMLPropEnum.
Changes to other places using switch statements were required.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/bhyve/bhyve_command.c | 3 +++
src/conf/domain_conf.c | 9 ++-------
src/conf/domain_conf.h | 2 +-
src/hyperv/hyperv_driver.c | 2 ++
src/libxl/libxl_driver.c | 11 +++++++++++
src/qemu/qemu_command.c | 4 ++++
src/vmx/vmx.c | 1 +
7 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 9731fee22f..f8e0ce5123 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -208,6 +208,9 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
else
virBufferAsprintf(&device, "-cd,%s", disk_source);
break;
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported disk device"));
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9afb548ea7..242839d60f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9319,7 +9319,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
xmlNodePtr cur;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
bool source = false;
- g_autofree char *tmp = NULL;
g_autofree char *target = NULL;
g_autofree char *serial = NULL;
g_autofree char *logical_block_size = NULL;
@@ -9342,13 +9341,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
/* defaults */
def->device = VIR_DOMAIN_DISK_DEVICE_DISK;
- if ((tmp = virXMLPropString(node, "device")) &&
- (def->device = virDomainDiskDeviceTypeFromString(tmp)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown disk device '%s'"), tmp);
+ if (virXMLPropEnum(node, "device", virDomainDiskDeviceTypeFromString,
+ VIR_XML_PROP_OPTIONAL, &def->device) < 0)
return NULL;
- }
- VIR_FREE(tmp);
if (virXMLPropEnum(node, "model", virDomainDiskModelTypeFromString,
VIR_XML_PROP_OPTIONAL, &def->model) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 29866927c7..a17f241c53 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -535,7 +535,7 @@ struct _virDomainDiskDef {
virObject *privateData;
- int device; /* enum virDomainDiskDevice */
+ virDomainDiskDevice device;
virDomainDiskBus bus;
char *dst;
virDomainDiskTray tray_status;
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 3a0eeb5178..ff20d5548b 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -886,6 +886,8 @@ hypervDomainAttachStorageVolume(virDomainPtr domain,
return hypervDomainAttachCDROM(domain, disk, controller, hostname);
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
return hypervDomainAttachFloppy(domain, disk, controller, hostname);
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unsupported disk
bus"));
break;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index d924e033d9..cf3ee4db3d 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -3084,6 +3084,9 @@ libxlDomainAttachDeviceDiskLive(virDomainObj *vm, virDomainDeviceDef
*dev)
virDomainDiskBusTypeToString(l_disk->bus));
}
break;
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk device type '%s' cannot be
hotplugged"),
@@ -3369,6 +3372,10 @@ libxlDomainDetachDeviceDiskLive(virDomainObj *vm,
virDomainDeviceDef *dev)
virDomainDiskBusTypeToString(dev->data.disk->bus));
}
break;
+ case VIR_DOMAIN_DISK_DEVICE_CDROM:
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("device type '%s' cannot hot unplugged"),
@@ -4031,6 +4038,10 @@ libxlDomainUpdateDeviceLive(virDomainObj *vm, virDomainDeviceDef
*dev)
if (ret == 0)
dev->data.disk = NULL;
break;
+ case VIR_DOMAIN_DISK_DEVICE_DISK:
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk bus '%s' cannot be
updated."),
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6ac36da1bb..e55858bb79 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2252,6 +2252,10 @@ qemuBuildDisksCommandLine(virCommand *cmd,
bootindex = bootDisk;
bootDisk = 0;
break;
+ case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
+ default:
+ break;
}
}
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 65d2850f2c..1cd5a82227 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -3474,6 +3474,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt,
virDomainDef
break;
+ case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported disk device type '%s'"),
--
2.30.2