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 | 9 +++++++++
src/bhyve/bhyve_domain.c | 12 ++++++++++++
src/conf/domain_conf.c | 26 ++++++++++++++++----------
src/conf/domain_conf.h | 2 +-
src/hyperv/hyperv_driver.c | 16 ++++++++++++++++
src/qemu/qemu_validate.c | 3 +++
src/vz/vz_sdk.c | 22 +++++++++++++++++++---
src/vz/vz_utils.c | 8 ++++++++
8 files changed, 84 insertions(+), 14 deletions(-)
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index b1558132e1..9731fee22f 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -309,6 +309,15 @@ bhyveBuildDiskArgStr(const virDomainDef *def,
if (bhyveBuildVirtIODiskArgStr(def, disk, cmd) < 0)
return -1;
break;
+ case VIR_DOMAIN_DISK_BUS_SCSI:
+ case VIR_DOMAIN_DISK_BUS_IDE:
+ case VIR_DOMAIN_DISK_BUS_FDC:
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported disk device"));
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index 0213878f26..33e74e2e25 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -133,6 +133,18 @@ bhyveDomainDiskDefAssignAddress(struct _bhyveConn *driver,
def->info.addr.drive.bus = 0;
break;
+ case VIR_DOMAIN_DISK_BUS_SCSI:
+ case VIR_DOMAIN_DISK_BUS_IDE:
+ case VIR_DOMAIN_DISK_BUS_FDC:
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
+ default:
+ break;
}
return 0;
}
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6f7948da0a..9afb548ea7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7874,6 +7874,13 @@ virDomainDiskDefAssignAddress(virDomainXMLOption *xmlopt,
def->info.addr.drive.unit = idx % 2;
break;
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
default:
/* Other disk bus's aren't controller based */
break;
@@ -9314,7 +9321,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
bool source = false;
g_autofree char *tmp = NULL;
g_autofree char *target = NULL;
- g_autofree char *bus = NULL;
g_autofree char *serial = NULL;
g_autofree char *logical_block_size = NULL;
g_autofree char *physical_block_size = NULL;
@@ -9375,7 +9381,11 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
} else if (!target &&
virXMLNodeNameEqual(cur, "target")) {
target = virXMLPropString(cur, "dev");
- bus = virXMLPropString(cur, "bus");
+ if (virXMLPropEnum(cur, "bus",
+ virDomainDiskBusTypeFromString,
+ VIR_XML_PROP_OPTIONAL | VIR_XML_PROP_NONZERO,
+ &def->bus) < 0)
+ return NULL;
if (virXMLPropEnum(cur, "tray", virDomainDiskTrayTypeFromString,
VIR_XML_PROP_OPTIONAL, &def->tray_status) < 0)
return NULL;
@@ -9462,14 +9472,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
}
}
- if (bus) {
- if ((def->bus = virDomainDiskBusTypeFromString(bus)) <= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown disk bus type '%s'"), bus);
- return NULL;
- }
- }
-
if (rotation_rate &&
virStrToLong_ui(rotation_rate, NULL, 10, &def->rotation_rate) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -30042,6 +30044,10 @@ virDiskNameToBusDeviceIndex(virDomainDiskDef *disk,
case VIR_DOMAIN_DISK_BUS_VIRTIO:
case VIR_DOMAIN_DISK_BUS_XEN:
case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_SATA:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_LAST:
default:
*busIdx = 0;
*devIdx = idx;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 17d830a822..29866927c7 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -536,7 +536,7 @@ struct _virDomainDiskDef {
virObject *privateData;
int device; /* enum virDomainDiskDevice */
- int bus; /* enum virDomainDiskBus */
+ virDomainDiskBus bus;
char *dst;
virDomainDiskTray tray_status;
virTristateSwitch removable;
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 0ac4f93d13..3a0eeb5178 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -961,6 +961,14 @@ hypervDomainAttachStorage(virDomainPtr domain, virDomainDef *def,
const char *ho
if (hypervDomainAttachFloppy(domain, def->disks[i], floppySettings,
hostname) < 0)
return -1;
break;
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SATA:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
default:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unsupported
controller type"));
return -1;
@@ -3108,6 +3116,14 @@ hypervDomainAttachDeviceFlags(virDomainPtr domain, const char *xml,
unsigned int
if (!entry)
return -1;
break;
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SATA:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
default:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid disk
bus in definition"));
return -1;
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 18c851d693..44d20088bf 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2755,6 +2755,9 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef
*disk,
case VIR_DOMAIN_DISK_BUS_XEN:
case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_LAST:
break;
}
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 048d4adacd..e09950812d 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -595,7 +595,7 @@ prlsdkAddDomainVideoInfoVm(PRL_HANDLE sdkdom, virDomainDef *def)
}
static int
-prlsdkGetDiskId(PRL_HANDLE disk, int *bus, char **dst)
+prlsdkGetDiskId(PRL_HANDLE disk, virDomainDiskBus *bus, char **dst)
{
PRL_RESULT pret;
PRL_UINT32 pos, ifType;
@@ -1624,7 +1624,7 @@ prlsdkBootOrderCheck(PRL_HANDLE sdkdom, PRL_DEVICE_TYPE sdkType, int
sdkIndex,
PRL_HANDLE dev = PRL_INVALID_HANDLE;
virDomainDiskDef *disk;
virDomainDiskDevice device;
- int bus;
+ virDomainDiskBus bus;
char *dst = NULL;
int ret = -1;
@@ -3462,6 +3462,14 @@ static int prlsdkConfigureDisk(struct _vzDriver *driver,
sdkbus = PMS_SATA_DEVICE;
idx = drive->unit;
break;
+ case VIR_DOMAIN_DISK_BUS_FDC:
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Specified disk bus is not "
@@ -3500,7 +3508,7 @@ prlsdkGetDisk(PRL_HANDLE sdkdom, virDomainDiskDef *disk)
PRL_UINT32 num;
size_t i;
PRL_HANDLE sdkdisk = PRL_INVALID_HANDLE;
- int bus;
+ virDomainDiskBus bus;
char *dst = NULL;
PRL_DEVICE_TYPE devType;
@@ -4339,6 +4347,14 @@ prlsdkGetBlockStats(PRL_HANDLE sdkstats,
prefix = "scsi";
idx = address->unit;
break;
+ case VIR_DOMAIN_DISK_BUS_FDC:
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unknown disk bus: %X"), disk->bus);
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index a07754d5ec..8fed875281 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -237,6 +237,14 @@ vzCheckDiskAddressDriveUnsupportedParams(virDomainDiskDef *disk)
return -1;
}
break;
+ case VIR_DOMAIN_DISK_BUS_FDC:
+ case VIR_DOMAIN_DISK_BUS_NONE:
+ case VIR_DOMAIN_DISK_BUS_VIRTIO:
+ case VIR_DOMAIN_DISK_BUS_XEN:
+ case VIR_DOMAIN_DISK_BUS_USB:
+ case VIR_DOMAIN_DISK_BUS_UML:
+ case VIR_DOMAIN_DISK_BUS_SD:
+ case VIR_DOMAIN_DISK_BUS_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Specified disk bus is not supported by vz
driver."));
--
2.30.2