[PATCH 00/20] Misc cleanups (pt. 1)

I had these sitting on a local branch for a while. My initial plan was to use virXMLPropEnum() more and while working on that I found one bug (patch 01/20), one improvement (patch 02/20) and a couple of useless typecats. Michal Prívozník (20): lxc_controller: Access correct union member in virLXCControllerSetupHostdevCaps() src: Access hostdev->source.subsys iff VIR_DOMAIN_HOSTDEV_MODE_SUBSYS qemu_domain_address: Drop needless typecast in qemuDomainDeviceCalculatePCIConnectFlags() qemu: Drop needless typecast to virDomainFSDriverType src: Drop needless typecast to virDomainDeviceType qemu_domain_address: Drop needless typecast to virDomainDiskModel src: Drop needless typecast to virDomainDiskBus virDomainHostdevSubsysSCSI: Convert 'protocol' field to proper enum type virDomainHostdevSubsysSCSIVHost: Convert 'protocol' field to proper enum type virDomainHostdevDef: Convert 'mode' field to proper enum type virDomainHostdevCaps: Convert 'type' field to proper enum type virDomainHostdevSubsys: Convert 'type' field to proper enum type virDomainControllerDef: Convert 'type' field to proper enum type virDomainRNGDef: Convert 'model' field to proper enum type virDomainRNGDef: Convert 'backend' field to proper enum type virDomainWatchdogDef: Convert 'model' field to proper enum type virDomainWatchdogDef: Convert 'action' field to proper enum type virDomainDeviceInfo: Convert 'type' field to proper enum type virStorageNetHostDef: Convert 'transport' field to proper enum type virDomainDiskSourceNVMeParse: Use virXMLPropULongLong() src/ch/ch_domain.c | 2 +- src/conf/device_conf.c | 12 +- src/conf/device_conf.h | 4 +- src/conf/domain_audit.c | 10 +- src/conf/domain_conf.c | 291 ++++++++---------- src/conf/domain_conf.h | 29 +- src/conf/domain_postparse.c | 2 +- src/conf/domain_validate.c | 9 +- src/conf/storage_source_conf.h | 2 +- src/libxl/libxl_driver.c | 12 + src/lxc/lxc_cgroup.c | 3 + src/lxc/lxc_controller.c | 9 +- src/lxc/lxc_driver.c | 16 + src/lxc/lxc_hostdev.c | 7 + src/qemu/qemu_alias.c | 2 +- src/qemu/qemu_backup.c | 2 +- src/qemu/qemu_block.c | 2 +- src/qemu/qemu_command.c | 26 +- src/qemu/qemu_domain.c | 18 +- src/qemu/qemu_domain_address.c | 28 +- src/qemu/qemu_driver.c | 6 +- src/qemu/qemu_hotplug.c | 22 +- src/qemu/qemu_migration.c | 4 +- src/qemu/qemu_monitor.c | 12 + src/qemu/qemu_monitor_json.c | 2 +- src/qemu/qemu_namespace.c | 2 +- src/qemu/qemu_validate.c | 18 +- src/security/security_apparmor.c | 2 +- src/security/security_dac.c | 4 +- src/security/security_selinux.c | 10 +- src/security/virt-aa-helper.c | 7 + .../storage_file_backend_gluster.c | 2 +- .../storage_source_backingstore.c | 15 +- src/vbox/vbox_common.c | 4 +- 34 files changed, 333 insertions(+), 263 deletions(-) -- 2.41.0

The point of virLXCControllerSetupHostdevCaps() is to access .caps union member of given <hostdev/> source. And it does so in the switch, but then, when reporting an error the .subsys member is accessed. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/lxc/lxc_controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index d79b8e1dd6..6c20429998 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1807,7 +1807,7 @@ virLXCControllerSetupHostdevCaps(virDomainDef *vmDef, default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device mode %1$s"), - virDomainHostdevCapsTypeToString(def->source.subsys.type)); + virDomainHostdevCapsTypeToString(def->source.caps.type)); return -1; } } -- 2.41.0

There are few places where a virDomainHostdevDef->source.subsys is accessed without ->mode being checked. Mind you, virDomainHostdevDef can be also in VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES mode. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 3 ++- src/conf/domain_validate.c | 3 ++- src/security/virt-aa-helper.c | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1f14ef6f23..9d819c3dab 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5099,7 +5099,8 @@ virDomainDriveAddressIsUsedByHostdev(const virDomainDef *def, for (i = 0; i < def->nhostdevs; i++) { hostdev = def->hostdevs[i]; - if (hostdev->source.subsys.type != type || + if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS || + hostdev->source.subsys.type != type || hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) continue; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index b050f21edb..53d920b2b3 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1283,7 +1283,8 @@ virDomainDefHostdevValidate(const virDomainDef *def) } } - if (dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV && + if (dev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS && + dev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV && dev->source.subsys.u.mdev.ramfb == VIR_TRISTATE_SWITCH_ON) { if (ramfbEnabled) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index c50629d096..4638451183 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1049,6 +1049,10 @@ get_files(vahControl * ctl) if (ctl->def->hostdevs[i]) { virDomainHostdevDef *dev = ctl->def->hostdevs[i]; virDomainHostdevSubsysUSB *usbsrc = &dev->source.subsys.u.usb; + + if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) + continue; + switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { virUSBDevice *usb = -- 2.41.0

Inside of qemuDomainDeviceCalculatePCIConnectFlags() there's a switch() which typecasts a variable of virDomainHostdevSubsysSCSIVHostModelType type to the very same type. This is useless. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_domain_address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index e26dc38f76..e5f0a9e883 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -864,7 +864,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev, * are the same as virtio-scsi, so they should follow virtio logic */ if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) { - switch ((virDomainHostdevSubsysSCSIVHostModelType) hostdev->source.subsys.u.scsi_host.model) { + switch (hostdev->source.subsys.u.scsi_host.model) { case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_VHOST_MODEL_TYPE_VIRTIO_TRANSITIONAL: /* Transitional devices only work in conventional PCI slots */ return pciFlags; -- 2.41.0

The 'fsdriver' member of _virDomainFSDef is already declared of virDomainFSDriverType type. Hence, there is no need to typecast the variable when passing to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_domain_address.c | 2 +- src/qemu/qemu_validate.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index e84374b4cf..f9e4de9bd7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -831,7 +831,7 @@ qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef *device, break; case VIR_DOMAIN_DEVICE_FS: - switch ((virDomainFSDriverType) device->data.fs->fsdriver) { + switch (device->data.fs->fsdriver) { case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT: case VIR_DOMAIN_FS_DRIVER_TYPE_PATH: case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE: @@ -2434,7 +2434,7 @@ qemuBuildFilesystemCommandLine(virCommand *cmd, size_t i; for (i = 0; i < def->nfss; i++) { - switch ((virDomainFSDriverType) def->fss[i]->fsdriver) { + switch (def->fss[i]->fsdriver) { case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT: case VIR_DOMAIN_FS_DRIVER_TYPE_PATH: case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE: diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index e5f0a9e883..01f44a4991 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -707,7 +707,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev, break; case VIR_DOMAIN_DEVICE_FS: - switch ((virDomainFSDriverType) dev->data.fs->fsdriver) { + switch (dev->data.fs->fsdriver) { case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT: case VIR_DOMAIN_FS_DRIVER_TYPE_PATH: case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE: diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 5bae56b00f..c7deac6251 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4286,7 +4286,7 @@ qemuValidateDomainDeviceDefFS(virDomainFSDef *fs, return -1; } - switch ((virDomainFSDriverType) fs->fsdriver) { + switch (fs->fsdriver) { case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT: case VIR_DOMAIN_FS_DRIVER_TYPE_PATH: break; -- 2.41.0

The 'type' member of _virDomainDeviceDef is already declared of virDomainDeviceType type. Hence, there is no need to typecast the variable when passing to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/ch/ch_domain.c | 2 +- src/conf/domain_conf.c | 8 ++++---- src/conf/domain_postparse.c | 2 +- src/conf/domain_validate.c | 2 +- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 6 +++--- src/qemu/qemu_domain_address.c | 4 ++-- src/qemu/qemu_driver.c | 6 +++--- src/qemu/qemu_hotplug.c | 10 +++++----- src/qemu/qemu_validate.c | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ch/ch_domain.c b/src/ch/ch_domain.c index d6b64b6c59..866f0d899a 100644 --- a/src/ch/ch_domain.c +++ b/src/ch/ch_domain.c @@ -146,7 +146,7 @@ chValidateDomainDeviceDef(const virDomainDeviceDef *dev, void *opaque G_GNUC_UNUSED, void *parseOpaque G_GNUC_UNUSED) { - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: case VIR_DOMAIN_DEVICE_NET: case VIR_DOMAIN_DEVICE_MEMORY: diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d819c3dab..306547e798 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3520,7 +3520,7 @@ void virDomainDeviceDefFree(virDomainDeviceDef *def) if (!def) return; - switch ((virDomainDeviceType) def->type) { + switch (def->type) { case VIR_DOMAIN_DEVICE_DISK: virDomainDiskDefFree(def->data.disk); break; @@ -4468,7 +4468,7 @@ virDomainObjGetOneDef(virDomainObj *vm, virDomainDeviceInfo * virDomainDeviceGetInfo(const virDomainDeviceDef *device) { - switch ((virDomainDeviceType) device->type) { + switch (device->type) { case VIR_DOMAIN_DEVICE_DISK: return &device->data.disk->info; case VIR_DOMAIN_DEVICE_FS: @@ -4541,7 +4541,7 @@ void virDomainDeviceSetData(virDomainDeviceDef *device, void *devicedata) { - switch ((virDomainDeviceType) device->type) { + switch (device->type) { case VIR_DOMAIN_DEVICE_DISK: device->data.disk = devicedata; break; @@ -13777,7 +13777,7 @@ virDomainDeviceDefParse(const char *xmlStr, if (virDomainDeviceDefParseType((const char *)node->name, &dev->type) < 0) return NULL; - switch ((virDomainDeviceType) dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: if (!(dev->data.disk = virDomainDiskDefParseXML(xmlopt, node, ctxt, flags))) diff --git a/src/conf/domain_postparse.c b/src/conf/domain_postparse.c index b76e8dcc5c..e79913b73f 100644 --- a/src/conf/domain_postparse.c +++ b/src/conf/domain_postparse.c @@ -684,7 +684,7 @@ virDomainDeviceDefPostParseCommon(virDomainDeviceDef *dev, { int ret = -1; - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_CHR: ret = virDomainChrDefPostParse(dev->data.chr, def); break; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 53d920b2b3..a8f90af3aa 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2847,7 +2847,7 @@ virDomainDeviceDefValidateInternal(const virDomainDeviceDef *dev, if (virDomainDeviceInfoValidate(dev) < 0) return -1; - switch ((virDomainDeviceType) dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: return virDomainDiskDefValidate(def, dev->data.disk); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f9e4de9bd7..6de0bdf977 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -796,7 +796,7 @@ qemuBuildVirtioDevGetConfigDev(const virDomainDeviceDef *device, bool *has_ntmodel, bool *useBusSuffix) { - switch ((virDomainDeviceType) device->type) { + switch (device->type) { case VIR_DOMAIN_DEVICE_DISK: if (virStorageSourceGetActualType(device->data.disk->src) == VIR_STORAGE_TYPE_VHOST_USER) *baseName = "vhost-user-blk"; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 52ea8f649d..e578df624b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6175,7 +6175,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDef *dev, virQEMUCaps *qemuCaps = parseOpaque; int ret = -1; - switch ((virDomainDeviceType) dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_NET: ret = qemuDomainDeviceNetDefPostParse(dev->data.net, def, qemuCaps); break; @@ -10297,7 +10297,7 @@ qemuDomainPrepareChardevSourceOne(virDomainDeviceDef *dev, struct qemuDomainPrepareChardevSourceData *data = opaque; qemuDomainChrSourcePrivate *charpriv = QEMU_DOMAIN_CHR_SOURCE_PRIVATE(charsrc); - switch ((virDomainDeviceType) dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_CHR: case VIR_DOMAIN_DEVICE_RNG: @@ -12148,7 +12148,7 @@ qemuDomainDeviceBackendChardevForeachOne(virDomainDeviceDef *dev, qemuDomainDeviceBackendChardevForeachCallback cb, void *opaque) { - switch ((virDomainDeviceType) dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: if (virStorageSourceGetActualType(dev->data.disk->src) != VIR_STORAGE_TYPE_VHOST_USER) return 0; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 01f44a4991..38411b4872 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -522,7 +522,7 @@ qemuDomainAssignVirtioMMIOAddresses(virDomainDef *def, static bool qemuDomainDeviceSupportZPCI(virDomainDeviceDef *device) { - switch ((virDomainDeviceType)device->type) { + switch (device->type) { case VIR_DOMAIN_DEVICE_CHR: return false; @@ -604,7 +604,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev, virDomainPCIConnectFlags pciFlags = (VIR_PCI_CONNECT_TYPE_PCI_DEVICE | VIR_PCI_CONNECT_AUTOASSIGN); - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_CONTROLLER: { virDomainControllerDef *cont = dev->data.controller; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0d4da937b0..28ec40e351 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6624,7 +6624,7 @@ qemuDomainAttachDeviceConfig(virDomainDef *vmdef, virDomainRedirdevDef *redirdev; virDomainShmemDef *shmem; - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: disk = dev->data.disk; if (virDomainDiskIndexByName(vmdef, disk->dst, true) >= 0) { @@ -6843,7 +6843,7 @@ qemuDomainDetachDeviceConfig(virDomainDef *vmdef, virDomainMemoryDef *mem; int idx; - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: disk = dev->data.disk; if (!(det_disk = virDomainDiskRemoveByName(vmdef, disk->dst))) { @@ -7041,7 +7041,7 @@ qemuDomainUpdateDeviceConfig(virDomainDef *vmdef, virDomainDeviceDef oldDev = { .type = dev->type }; int pos; - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: newDisk = dev->data.disk; if ((pos = virDomainDiskIndexByName(vmdef, newDisk->dst, false)) < 0) { diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 177ca87d11..0d5f253bb9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3307,7 +3307,7 @@ qemuDomainAttachDeviceLive(virDomainObj *vm, &chardevBackendData) < 0) return -1; - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL); ret = qemuDomainAttachDeviceDiskLive(driver, vm, dev); @@ -5150,7 +5150,7 @@ qemuDomainRemoveAuditDevice(virDomainObj *vm, virDomainDeviceDef *detach, bool success) { - switch ((virDomainDeviceType)detach->type) { + switch (detach->type) { case VIR_DOMAIN_DEVICE_DISK: virDomainAuditDisk(vm, detach->data.disk->src, NULL, "detach", success); break; @@ -5231,7 +5231,7 @@ qemuDomainRemoveDevice(virQEMUDriver *driver, alias = g_strdup(info->alias); info = NULL; - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_CHR: /* We must return directly after calling * qemuDomainRemoveChrDevice because it is called directly @@ -6058,7 +6058,7 @@ qemuDomainDetachDeviceLive(virDomainObj *vm, int ret = -1; int rc; - switch ((virDomainDeviceType)match->type) { + switch (match->type) { /* * lease and chr devices don't follow the standard pattern of * the others, so they must have their own self-contained @@ -7100,7 +7100,7 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm, virDomainDeviceDef oldDev = { .type = dev->type }; int idx; - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_DISK: qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL); return qemuDomainChangeDiskLive(vm, dev, driver, force); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index c7deac6251..3b57fa3c21 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -5068,7 +5068,7 @@ qemuValidateDomainDeviceDef(const virDomainDeviceDef *dev, if (qemuValidateDomainDeviceInfo(dev, def, qemuCaps) < 0) return -1; - switch ((virDomainDeviceType)dev->type) { + switch (dev->type) { case VIR_DOMAIN_DEVICE_NET: return qemuValidateDomainDeviceDefNetwork(dev->data.net, qemuCaps); -- 2.41.0

The 'mode' member of _virDomainDiskDef is already declared of virDomainDiskModel type. Hence, there is no need to typecast the variable when passing to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_domain_address.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 38411b4872..0875ed0401 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -793,7 +793,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev, switch ((virDomainDiskBus) dev->data.disk->bus) { case VIR_DOMAIN_DISK_BUS_VIRTIO: /* only virtio disks use PCI */ - switch ((virDomainDiskModel) dev->data.disk->model) { + switch (dev->data.disk->model) { case VIR_DOMAIN_DISK_MODEL_VIRTIO_TRANSITIONAL: /* Transitional devices only work in conventional PCI slots */ return pciFlags; -- 2.41.0

The 'bus' member of _virDomainDiskDef is already declared of virDomainDiskModel type. Hence, there is no need to typecast the variable when passing to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_alias.c | 2 +- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_domain_address.c | 2 +- src/qemu/qemu_hotplug.c | 4 ++-- src/qemu/qemu_validate.c | 4 ++-- src/vbox/vbox_common.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 161d30cf72..e58c488f8a 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -244,7 +244,7 @@ qemuAssignDeviceDiskAlias(virDomainDef *def, * need the full path into /machine/peripheral as a historical artifact. */ if (!diskPriv->qomName) { - switch ((virDomainDiskBus) disk->bus) { + switch (disk->bus) { case VIR_DOMAIN_DISK_BUS_FDC: case VIR_DOMAIN_DISK_BUS_IDE: case VIR_DOMAIN_DISK_BUS_SATA: diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6de0bdf977..be5814663c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -409,7 +409,7 @@ qemuBuildDeviceAddresDriveProps(virJSONValue *props, virDomainControllerDef *controller = NULL; const char *controllerAlias = NULL; - switch ((virDomainDiskBus) info->addr.drive.diskbus) { + switch (info->addr.drive.diskbus) { case VIR_DOMAIN_DISK_BUS_IDE: /* When domain has builtin IDE controller we don't put it onto cmd * line. Therefore we can't set its alias. In that case, use the @@ -1770,7 +1770,7 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, const char *wpolicy = NULL; const char *rpolicy = NULL; - switch ((virDomainDiskBus) disk->bus) { + switch (disk->bus) { case VIR_DOMAIN_DISK_BUS_IDE: case VIR_DOMAIN_DISK_BUS_SATA: if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 0875ed0401..00742d3c0e 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -790,7 +790,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev, break; case VIR_DOMAIN_DEVICE_DISK: - switch ((virDomainDiskBus) dev->data.disk->bus) { + switch (dev->data.disk->bus) { case VIR_DOMAIN_DISK_BUS_VIRTIO: /* only virtio disks use PCI */ switch (dev->data.disk->model) { diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 0d5f253bb9..d4f01cfd93 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -926,7 +926,7 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver, goto cleanup; } - switch ((virDomainDiskBus) disk->bus) { + switch (disk->bus) { case VIR_DOMAIN_DISK_BUS_USB: if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -5468,7 +5468,7 @@ qemuDomainDetachPrepDisk(virDomainObj *vm, case VIR_DOMAIN_DISK_DEVICE_DISK: case VIR_DOMAIN_DISK_DEVICE_LUN: - switch ((virDomainDiskBus) disk->bus) { + switch (disk->bus) { case VIR_DOMAIN_DISK_BUS_VIRTIO: case VIR_DOMAIN_DISK_BUS_USB: case VIR_DOMAIN_DISK_BUS_SCSI: diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 3b57fa3c21..18d34e7f59 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1371,7 +1371,7 @@ qemuValidateDomainDeviceDefAddressDrive(virDomainDeviceInfo *info, { virDomainControllerDef *controller = NULL; - switch ((virDomainDiskBus) info->addr.drive.diskbus) { + switch (info->addr.drive.diskbus) { case VIR_DOMAIN_DISK_BUS_SCSI: /* Setting bus= attr for SCSI drives, causes a controller * to be created. Yes this is slightly odd. It is not possible @@ -2673,7 +2673,7 @@ static bool qemuValidateDomainDeviceDefDiskIOThreads(const virDomainDef *def, const virDomainDiskDef *disk) { - switch ((virDomainDiskBus)disk->bus) { + switch (disk->bus) { case VIR_DOMAIN_DISK_BUS_VIRTIO: break; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index dba4af1a44..490f337a56 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1206,7 +1206,7 @@ vboxAttachDrives(virDomainDef *def, struct _vboxDriver *data, IMachine *machine) goto cleanup; } - switch ((virDomainDiskBus) disk->bus) { + switch (disk->bus) { case VIR_DOMAIN_DISK_BUS_IDE: VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_IDE_NAME, &storageCtlName); devicePort = def->disks[i]->info.addr.drive.bus; -- 2.41.0

Convert the field and adjust the XML parser to use virXMLPropEnum(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 18 ++++++------------ src/conf/domain_conf.h | 2 +- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_domain.c | 4 ++-- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 306547e798..ef5f02a23b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6065,20 +6065,14 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode, unsigned int flags, virDomainXMLOption *xmlopt) { - g_autofree char *protocol = NULL; - - if ((protocol = virXMLPropString(sourcenode, "protocol"))) { - scsisrc->protocol = - virDomainHostdevSubsysSCSIProtocolTypeFromString(protocol); - if (scsisrc->protocol < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown SCSI subsystem protocol '%1$s'"), - protocol); - return -1; - } + if (virXMLPropEnum(sourcenode, "protocol", + virDomainHostdevSubsysSCSIProtocolTypeFromString, + VIR_XML_PROP_NONE, + &scsisrc->protocol) < 0) { + return -1; } - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { + switch (scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, ctxt, scsisrc, flags, xmlopt); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ca195a52d2..5cce60420f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -273,7 +273,7 @@ typedef enum { } virDomainDeviceSGIO; struct _virDomainHostdevSubsysSCSI { - int protocol; /* enum virDomainHostdevSCSIProtocolType */ + virDomainHostdevSCSIProtocolType protocol; virDomainDeviceSGIO sgio; virTristateBool rawio; union { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index be5814663c..ccbf41a0f7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5033,7 +5033,7 @@ qemuBuildHostdevSCSIDetachPrepare(virDomainHostdevDef *hostdev, virStorageSource *src; qemuDomainStorageSourcePrivate *srcpriv; - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { + switch (scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: src = scsisrc->u.host.src; break; @@ -5068,7 +5068,7 @@ qemuBuildHostdevSCSIAttachPrepare(virDomainHostdevDef *hostdev, g_autoptr(qemuBlockStorageSourceAttachData) ret = g_new0(qemuBlockStorageSourceAttachData, 1); virStorageSource *src = NULL; - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { + switch (scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: src = scsisrc->u.host.src; break; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e578df624b..069f145d26 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6008,7 +6008,7 @@ qemuDomainDeviceHostdevDefPostParseRestoreBackendAlias(virDomainHostdevDef *host hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) return 0; - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { + switch (scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: if (!scsisrc->u.host.src) scsisrc->u.host.src = virStorageSourceNew(); @@ -11373,7 +11373,7 @@ qemuDomainPrepareHostdevSCSI(virDomainHostdevDef *hostdev, virStorageSource *src = NULL; g_autofree char *devstr = NULL; - switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) { + switch (scsisrc->protocol) { case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE: virObjectUnref(scsisrc->u.host.src); scsisrc->u.host.src = virStorageSourceNew(); -- 2.41.0

Convert the field and adjust the XML parser to use virXMLPropEnum(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 17 +++++------------ src/conf/domain_conf.h | 4 ++-- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ef5f02a23b..65b7b44ccb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6095,24 +6095,17 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevDef *def) { virDomainHostdevSubsysSCSIVHost *hostsrc = &def->source.subsys.u.scsi_host; - g_autofree char *protocol = NULL; g_autofree char *wwpn = NULL; - if (!(protocol = virXMLPropString(sourcenode, "protocol"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing scsi_host subsystem protocol")); - return -1; - } - if ((hostsrc->protocol = - virDomainHostdevSubsysSCSIHostProtocolTypeFromString(protocol)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown scsi_host subsystem protocol '%1$s'"), - protocol); + if (virXMLPropEnum(sourcenode, "protocol", + virDomainHostdevSubsysSCSIHostProtocolTypeFromString, + VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO, + &hostsrc->protocol) < 0) { return -1; } - switch ((virDomainHostdevSubsysSCSIHostProtocolType) hostsrc->protocol) { + switch (hostsrc->protocol) { case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST: if (!(wwpn = virXMLPropString(sourcenode, "wwpn"))) { virReportError(VIR_ERR_XML_ERROR, "%s", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5cce60420f..d6d0799f63 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -290,7 +290,7 @@ struct _virDomainHostdevSubsysMediatedDev { }; typedef enum { - VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE, + VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE = 0, VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_VHOST, VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_LAST, @@ -310,7 +310,7 @@ typedef enum { VIR_ENUM_DECL(virDomainHostdevSubsysSCSIVHostModel); struct _virDomainHostdevSubsysSCSIVHost { - int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */ + virDomainHostdevSubsysSCSIHostProtocolType protocol; char *wwpn; virDomainHostdevSubsysSCSIVHostModelType model; }; -- 2.41.0

Convert the field, adjust the XML parser to use virXMLPropEnumDefault() and fill in missing cases to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_audit.c | 2 +- src/conf/domain_conf.c | 23 +++++++++++++---------- src/conf/domain_conf.h | 2 +- src/lxc/lxc_cgroup.c | 1 + src/lxc/lxc_controller.c | 1 + src/lxc/lxc_driver.c | 2 ++ src/lxc/lxc_hostdev.c | 1 + src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_migration.c | 2 +- src/security/security_selinux.c | 2 ++ 10 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index ae875188bd..d4d303a214 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -351,7 +351,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev, return; } - switch ((virDomainHostdevMode) hostdev->mode) { + switch (hostdev->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 65b7b44ccb..c93f89ced6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2648,6 +2648,8 @@ virDomainHostdevDefClear(virDomainHostdevDef *def) break; } break; + case VIR_DOMAIN_HOSTDEV_MODE_LAST: + break; } } @@ -12917,7 +12919,6 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, { virDomainHostdevDef *def; VIR_XPATH_NODE_AUTORESTORE(ctxt) - g_autofree char *mode = virXMLPropString(node, "mode"); g_autofree char *type = virXMLPropString(node, "type"); ctxt->node = node; @@ -12925,15 +12926,11 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, if (!(def = virDomainHostdevDefNew())) goto error; - if (mode) { - if ((def->mode = virDomainHostdevModeTypeFromString(mode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown hostdev mode '%1$s'"), mode); - goto error; - } - } else { - def->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; - } + if (virXMLPropEnumDefault(node, "mode", virDomainHostdevModeTypeFromString, + VIR_XML_PROP_NONE, + &def->mode, + VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) < 0) + goto error; switch (def->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: @@ -12947,6 +12944,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, goto error; break; default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected hostdev mode %1$d"), def->mode); goto error; @@ -14182,6 +14180,8 @@ virDomainHostdevMatch(virDomainHostdevDef *a, return virDomainHostdevMatchSubsys(a, b); case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: return virDomainHostdevMatchCaps(a, b); + case VIR_DOMAIN_HOSTDEV_MODE_LAST: + break; } return 0; } @@ -26087,6 +26087,7 @@ virDomainHostdevDefFormat(virBuffer *buf, } break; default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected hostdev mode %1$d"), def->mode); return -1; @@ -26139,6 +26140,8 @@ virDomainHostdevDefFormat(virBuffer *buf, if (virDomainHostdevDefFormatCaps(buf, def) < 0) return -1; break; + case VIR_DOMAIN_HOSTDEV_MODE_LAST: + break; } virDomainNetTeamingInfoFormat(def->teaming, buf); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index d6d0799f63..1f977ef1c8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -371,7 +371,7 @@ struct _virDomainHostdevDef { */ virDomainNetDef *parentnet; - int mode; /* enum virDomainHostdevMode */ + virDomainHostdevMode mode; virDomainStartupPolicy startupPolicy; bool managed; bool missing; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index bc39b16928..21d9b456e8 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -313,6 +313,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDef *def, break; } default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: break; } } diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 6c20429998..e2d67d504d 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1837,6 +1837,7 @@ virLXCControllerSetupAllHostdevs(virLXCController *ctrl) return -1; break; default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device mode %1$s"), virDomainHostdevModeTypeToString(def->mode)); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index f3d3e4eb50..fb0301b811 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3905,6 +3905,7 @@ lxcDomainAttachDeviceHostdevLive(virLXCDriver *driver, return lxcDomainAttachDeviceHostdevCapsLive(driver, vm, dev); default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device mode %1$s"), virDomainHostdevModeTypeToString(dev->data.hostdev->mode)); @@ -4328,6 +4329,7 @@ lxcDomainDetachDeviceHostdevLive(virLXCDriver *driver, return lxcDomainDetachDeviceHostdevCapsLive(vm, dev); default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device mode %1$s"), virDomainHostdevModeTypeToString(dev->data.hostdev->mode)); diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c index 8fe02a4276..af3ce3e0ac 100644 --- a/src/lxc/lxc_hostdev.c +++ b/src/lxc/lxc_hostdev.c @@ -100,6 +100,7 @@ int virLXCPrepareHostDevices(virLXCDriver *driver, default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported hostdev mode %1$s"), virDomainHostdevModeTypeToString(dev->mode)); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 069f145d26..818e3822d0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10678,7 +10678,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDef *dev, g_autofree char *tmpPath = NULL; int perm = 0; - switch ((virDomainHostdevMode) dev->mode) { + switch (dev->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 801b904a73..9ed5c6e94b 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1280,7 +1280,7 @@ qemuMigrationSrcIsAllowedHostdev(const virDomainDef *def) * forbidden. */ for (i = 0; i < def->nhostdevs; i++) { virDomainHostdevDef *hostdev = def->hostdevs[i]; - switch ((virDomainHostdevMode)hostdev->mode) { + switch (hostdev->mode) { case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot migrate a domain with <hostdev mode='capabilities'>")); diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 7914aba84d..c3c92f3538 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2345,6 +2345,7 @@ virSecuritySELinuxSetHostdevLabel(virSecurityManager *mgr, return virSecuritySELinuxSetHostdevCapsLabel(mgr, def, dev, vroot); default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: return 0; } } @@ -2567,6 +2568,7 @@ virSecuritySELinuxRestoreHostdevLabel(virSecurityManager *mgr, return virSecuritySELinuxRestoreHostdevCapsLabel(mgr, dev, vroot); default: + case VIR_DOMAIN_HOSTDEV_MODE_LAST: return 0; } } -- 2.41.0

Convert the field, adjust the XML parsers to use virXMLPropEnum() and fill in missing cases to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_audit.c | 2 ++ src/conf/domain_conf.c | 29 ++++++++++++++--------------- src/conf/domain_conf.h | 2 +- src/lxc/lxc_cgroup.c | 2 ++ src/lxc/lxc_controller.c | 1 + src/lxc/lxc_driver.c | 4 ++++ src/lxc/lxc_hostdev.c | 1 + src/security/security_selinux.c | 4 ++++ 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index d4d303a214..0bf1768acd 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -428,6 +428,8 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev, virt, reason, vmname, uuidstr, device); break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: VIR_WARN("Unexpected hostdev type while encoding audit message: %d", hostdev->source.caps.type); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c93f89ced6..cf1bd4df74 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2616,7 +2616,7 @@ virDomainHostdevDefClear(virDomainHostdevDef *def) switch (def->mode) { case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: - switch ((virDomainHostdevCapsType) def->source.caps.type) { + switch (def->source.caps.type) { case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: VIR_FREE(def->source.caps.u.storage.block); break; @@ -6502,7 +6502,7 @@ virDomainNetDefCoalesceFormatXML(virBuffer *buf, static int virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED, xmlXPathContextPtr ctxt, - const char *type, + virDomainHostdevCapsType type, virDomainHostdevDef *def) { /* @type is passed in from the caller rather than read from the @@ -6513,18 +6513,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED, * <hostdev>. (the functions we're going to call expect address * type to already be known). */ - if (!type) { - virReportError(VIR_ERR_XML_ERROR, - "%s", _("missing source address type")); - return -1; - } - - if ((def->source.caps.type = virDomainHostdevCapsTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host device source address type '%1$s'"), - type); - return -1; - } + def->source.caps.type = type; if (!virXPathNode("./source", ctxt)) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -6560,6 +6549,7 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node G_GNUC_UNUSED, ctxt, &def->source.caps.u.net.ip) < 0) return -1; break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("address type='%1$s' not supported in hostdev interfaces"), @@ -12920,6 +12910,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, virDomainHostdevDef *def; VIR_XPATH_NODE_AUTORESTORE(ctxt) g_autofree char *type = virXMLPropString(node, "type"); + unsigned int typeU; ctxt->node = node; @@ -12940,7 +12931,12 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, break; case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: /* parse managed/mode/type, and the <source> element */ - if (virDomainHostdevDefParseXMLCaps(node, ctxt, type, def) < 0) + if (virXMLPropEnum(node, "type", + virDomainHostdevCapsTypeFromString, + VIR_XML_PROP_REQUIRED, &typeU) < 0) + goto error; + + if (virDomainHostdevDefParseXMLCaps(node, ctxt, typeU, def) < 0) goto error; break; default: @@ -14163,6 +14159,8 @@ virDomainHostdevMatchCaps(virDomainHostdevDef *a, return virDomainHostdevMatchCapsMisc(a, b); case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: return virDomainHostdevMatchCapsNet(a, b); + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: + break; } return 0; } @@ -23486,6 +23484,7 @@ virDomainHostdevDefFormatCaps(virBuffer *buf, virBufferEscapeString(buf, "<interface>%s</interface>\n", def->source.caps.u.net.ifname); break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected hostdev type %1$d"), diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 1f977ef1c8..0e76ff71ac 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -336,7 +336,7 @@ typedef enum { } virDomainHostdevCapsType; struct _virDomainHostdevCaps { - int type; /* enum virDOmainHostdevCapsType */ + virDomainHostdevCapsType type; union { struct { char *block; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 21d9b456e8..7c889667ba 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -309,6 +309,8 @@ static int virLXCCgroupSetupDeviceACL(virDomainDef *def, VIR_CGROUP_DEVICE_MKNOD, false) < 0) return -1; break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: break; } diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index e2d67d504d..7e486d0f78 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1804,6 +1804,7 @@ virLXCControllerSetupHostdevCaps(virDomainDef *vmDef, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: return 0; /* case is handled in virLXCControllerMoveInterfaces */ + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device mode %1$s"), diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index fb0301b811..a9bdeba36d 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3869,6 +3869,8 @@ lxcDomainAttachDeviceHostdevCapsLive(virLXCDriver *driver, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: return lxcDomainAttachDeviceHostdevMiscLive(driver, vm, dev); + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device type %1$s"), @@ -4299,6 +4301,8 @@ lxcDomainDetachDeviceHostdevCapsLive(virDomainObj *vm, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: return lxcDomainDetachDeviceHostdevMiscLive(vm, dev); + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device type %1$s"), diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c index af3ce3e0ac..2e06b516d4 100644 --- a/src/lxc/lxc_hostdev.c +++ b/src/lxc/lxc_hostdev.c @@ -90,6 +90,7 @@ int virLXCPrepareHostDevices(virLXCDriver *driver, case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: break; + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported hostdev type %1$s"), diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index c3c92f3538..1fa5303495 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2315,6 +2315,8 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityManager *mgr, break; } + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: ret = 0; break; @@ -2538,6 +2540,8 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurityManager *mgr, break; } + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: + case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST: default: ret = 0; break; -- 2.41.0

Convert the field, and fill in missing cases to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_audit.c | 2 +- src/conf/domain_conf.c | 57 +++++++++++++++++++------------- src/conf/domain_conf.h | 2 +- src/conf/domain_validate.c | 2 +- src/libxl/libxl_driver.c | 12 +++++++ src/lxc/lxc_controller.c | 5 +++ src/lxc/lxc_driver.c | 10 ++++++ src/lxc/lxc_hostdev.c | 5 +++ src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 4 +-- src/qemu/qemu_hotplug.c | 4 ++- src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_validate.c | 2 +- src/security/security_apparmor.c | 2 +- src/security/security_dac.c | 4 +-- src/security/security_selinux.c | 4 +-- src/security/virt-aa-helper.c | 3 ++ 17 files changed, 85 insertions(+), 37 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index 0bf1768acd..4294b50c3a 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -353,7 +353,7 @@ virDomainAuditHostdev(virDomainObj *vm, virDomainHostdevDef *hostdev, switch (hostdev->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: - switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { + switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: address = virPCIDeviceAddressAsString(&pcisrc->addr); break; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index cf1bd4df74..35cb14b986 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2632,7 +2632,7 @@ virDomainHostdevDefClear(virDomainHostdevDef *def) } break; case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: - switch ((virDomainHostdevSubsysType) def->source.subsys.type) { + switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: virDomainHostdevSubsysSCSIClear(&def->source.subsys.u.scsi); break; @@ -6168,7 +6168,7 @@ virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDef *def, static int virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, xmlXPathContextPtr ctxt, - const char *type, + virDomainHostdevSubsysType type, virDomainHostdevDef *def, unsigned int flags, virDomainXMLOption *xmlopt) @@ -6202,18 +6202,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, * <hostdev>. (the functions we're going to call expect address * type to already be known). */ - if (!type) { - virReportError(VIR_ERR_XML_ERROR, - "%s", _("missing source address type")); - return -1; - } - - if ((def->source.subsys.type = virDomainHostdevSubsysTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown host device source address type '%1$s'"), - type); - return -1; - } + def->source.subsys.type = type; if (!(sourcenode = virXPathNode("./source", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -6322,6 +6311,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, return -1; break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("address type='%1$s' not supported in hostdev interfaces"), @@ -8868,6 +8858,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, } } else if (actual->type == VIR_DOMAIN_NET_TYPE_HOSTDEV) { virDomainHostdevDef *hostdev = &actual->data.hostdev.def; + int type; hostdev->parentnet = parent; hostdev->info = &parent->info; @@ -8879,8 +8870,16 @@ virDomainActualNetDefParseXML(xmlNodePtr node, /* if not explicitly stated, source/vendor implies usb device */ if (!addrtype && virXPathNode("./source/vendor", ctxt)) addrtype = g_strdup("usb"); + + if ((type = virDomainHostdevSubsysTypeFromString(addrtype)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host device source address type '%1$s'"), + addrtype); + goto error; + } + hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS; - if (virDomainHostdevDefParseXMLSubsys(node, ctxt, addrtype, + if (virDomainHostdevDefParseXMLSubsys(node, ctxt, type, hostdev, flags, xmlopt) < 0) { goto error; } @@ -9544,6 +9543,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, case VIR_DOMAIN_NET_TYPE_HOSTDEV: { g_autofree char *addrtype = virXPathString("string(./source/address/@type)", ctxt); + int type; def->data.hostdev.def.parentnet = def; def->data.hostdev.def.info = &def->info; @@ -9556,7 +9556,15 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, /* The helper function expects type to already be found and * passed in as a string, since it is in a different place in * NetDef vs HostdevDef. */ - if (virDomainHostdevDefParseXMLSubsys(node, ctxt, addrtype, + + if ((type = virDomainHostdevSubsysTypeFromString(addrtype)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown host device source address type '%1$s'"), + addrtype); + return NULL; + } + + if (virDomainHostdevDefParseXMLSubsys(node, ctxt, type, &def->data.hostdev.def, flags, xmlopt) < 0) return NULL; @@ -12909,8 +12917,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, { virDomainHostdevDef *def; VIR_XPATH_NODE_AUTORESTORE(ctxt) - g_autofree char *type = virXMLPropString(node, "type"); - unsigned int typeU; + unsigned int type; ctxt->node = node; @@ -12926,6 +12933,10 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, switch (def->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: /* parse managed/mode/type, and the <source> element */ + if (virXMLPropEnum(node, "type", + virDomainHostdevSubsysTypeFromString, + VIR_XML_PROP_REQUIRED, &type) < 0) + goto error; if (virDomainHostdevDefParseXMLSubsys(node, ctxt, type, def, flags, xmlopt) < 0) goto error; break; @@ -12933,10 +12944,10 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, /* parse managed/mode/type, and the <source> element */ if (virXMLPropEnum(node, "type", virDomainHostdevCapsTypeFromString, - VIR_XML_PROP_REQUIRED, &typeU) < 0) + VIR_XML_PROP_REQUIRED, &type) < 0) goto error; - if (virDomainHostdevDefParseXMLCaps(node, ctxt, typeU, def) < 0) + if (virDomainHostdevDefParseXMLCaps(node, ctxt, type, def) < 0) goto error; break; default: @@ -12953,7 +12964,7 @@ virDomainHostdevDefParseXML(virDomainXMLOption *xmlopt, goto error; } if (def->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { - switch ((virDomainHostdevSubsysType) def->source.subsys.type) { + switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: if (virXPathBoolean("boolean(./readonly)", ctxt)) def->readonly = true; @@ -14087,7 +14098,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDef *a, if (a->source.subsys.type != b->source.subsys.type) return 0; - switch ((virDomainHostdevSubsysType) a->source.subsys.type) { + switch (a->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: return virDomainHostdevMatchSubsysPCI(a, b); case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: @@ -23436,7 +23447,7 @@ virDomainHostdevDefFormatSubsys(virBuffer *buf, bool includeTypeInAddr, virDomainXMLOption *xmlopt) { - switch ((virDomainHostdevSubsysType) def->source.subsys.type) { + switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: virDomainHostdevDefFormatSubsysUSB(buf, def, flags, includeTypeInAddr); return 0; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 0e76ff71ac..fc612f3adb 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -316,7 +316,7 @@ struct _virDomainHostdevSubsysSCSIVHost { }; struct _virDomainHostdevSubsys { - int type; /* enum virDomainHostdevSubsysType */ + virDomainHostdevSubsysType type; union { virDomainHostdevSubsysUSB usb; virDomainHostdevSubsysPCI pci; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index a8f90af3aa..1d25aa32c2 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2149,7 +2149,7 @@ static int virDomainHostdevDefValidate(const virDomainHostdevDef *hostdev) { if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { - switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { + switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_UNASSIGNED && diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index c8ca903050..c98d2d737a 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3271,6 +3271,10 @@ libxlDomainAttachHostDevice(libxlDriverPrivate *driver, return -1; break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("hostdev subsys type '%1$s' not supported"), @@ -3561,6 +3565,10 @@ libxlDomainAttachDeviceConfig(virDomainDef *vmdef, virDomainDeviceDef *dev) case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: return -1; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + break; } if (virDomainHostdevFind(vmdef, hostdev, &found) >= 0) { @@ -3835,6 +3843,10 @@ libxlDomainDetachHostDevice(libxlDriverPrivate *driver, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: return libxlDomainDetachHostUSBDevice(driver, vm, hostdev); + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected hostdev type %1$d"), subsys->type); diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 7e486d0f78..48f5c73fce 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1776,6 +1776,11 @@ virLXCControllerSetupHostdevSubsys(virDomainDef *vmDef, def, securityDriver); + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device mode %1$s"), diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index a9bdeba36d..25cbfc57c9 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3848,6 +3848,11 @@ lxcDomainAttachDeviceHostdevSubsysLive(virLXCDriver *driver, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: return lxcDomainAttachDeviceHostdevSubsysUSBLive(driver, vm, dev); + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device type %1$s"), @@ -4281,6 +4286,11 @@ lxcDomainDetachDeviceHostdevSubsysLive(virLXCDriver *driver, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: return lxcDomainDetachDeviceHostdevUSBLive(driver, vm, dev); + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported host device type %1$s"), diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c index 2e06b516d4..0c4f0b8cac 100644 --- a/src/lxc/lxc_hostdev.c +++ b/src/lxc/lxc_hostdev.c @@ -76,6 +76,11 @@ int virLXCPrepareHostDevices(virLXCDriver *driver, switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported hostdev type %1$s"), diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ccbf41a0f7..701efd46b4 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5141,7 +5141,7 @@ qemuBuildHostdevCommandLine(virCommand *cmd, if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) continue; - switch ((virDomainHostdevSubsysType) subsys->type) { + switch (subsys->type) { /* USB */ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: if (!(devprops = qemuBuildUSBHostdevDevProps(def, hostdev, qemuCaps))) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 818e3822d0..47c3d69bda 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10680,7 +10680,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDef *dev, switch (dev->mode) { case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: - switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { + switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { if (!(tmpPath = virPCIDeviceAddressGetIOMMUGroupDev(&pcisrc->addr))) @@ -11488,7 +11488,7 @@ qemuDomainPrepareHostdev(virDomainHostdevDef *hostdev, if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) return 0; - switch ((virDomainHostdevSubsysType)hostdev->source.subsys.type) { + switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: return qemuDomainPrepareHostdevSCSI(hostdev, priv); case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d4f01cfd93..21154892ae 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2791,6 +2791,7 @@ qemuDomainAttachHostDevice(virQEMUDriver *driver, return -1; break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("hotplug is not supported for hostdev subsys type '%1$s'"), @@ -4680,7 +4681,7 @@ qemuDomainRemoveHostDevice(virQEMUDriver *driver, if (qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0) VIR_WARN("Unable to remove host device from /dev"); - switch ((virDomainHostdevSubsysType)hostdev->source.subsys.type) { + switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: qemuDomainRemovePCIHostDevice(driver, vm, hostdev); /* QEMU might no longer need to lock as much memory, eg. we just @@ -5726,6 +5727,7 @@ qemuDomainDetachPrepHostdev(virDomainObj *vm, break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected hostdev type %1$d"), subsys->type); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 9ed5c6e94b..011482c2b5 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1287,7 +1287,7 @@ qemuMigrationSrcIsAllowedHostdev(const virDomainDef *def) return false; case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: - switch ((virDomainHostdevSubsysType)hostdev->source.subsys.type) { + switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: /* USB devices can be "migrated" */ continue; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 18d34e7f59..315fc676f2 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2448,7 +2448,7 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev, } if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { - switch ((virDomainHostdevSubsysType) hostdev->source.subsys.type) { + switch (hostdev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: if (hostdev->source.subsys.u.usb.guestReset && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_HOST_GUESTS_RESETS_ALL)) { diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 27d64a23bb..bce797de7c 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -846,7 +846,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManager *mgr, ptr->mgr = mgr; ptr->def = def; - switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { + switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { virUSBDevice *usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, vroot); diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4667328b26..c07e488db7 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1230,7 +1230,7 @@ virSecurityDACSetHostdevLabel(virSecurityManager *mgr, if (cbdata.secdef && !cbdata.secdef->relabel) return 0; - switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { + switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { g_autoptr(virUSBDevice) usb = NULL; @@ -1393,7 +1393,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager *mgr, scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) return 0; - switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { + switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { g_autoptr(virUSBDevice) usb = NULL; diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 1fa5303495..07d779a947 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2184,7 +2184,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManager *mgr, scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) return 0; - switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { + switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { g_autoptr(virUSBDevice) usb = NULL; @@ -2420,7 +2420,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManager *mgr, scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) return 0; - switch ((virDomainHostdevSubsysType)dev->source.subsys.type) { + switch (dev->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: { g_autoptr(virUSBDevice) usb = NULL; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 4638451183..0855eb68ca 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1106,6 +1106,9 @@ get_files(vahControl * ctl) break; } + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST: default: rc = 0; break; -- 2.41.0

Convert the field and fill in missing cases to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 26 ++++++++++++++++++-------- src/conf/domain_conf.h | 9 ++++++--- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_domain_address.c | 12 +++++++++++- src/qemu/qemu_hotplug.c | 4 ++-- src/qemu/qemu_validate.c | 2 +- src/vbox/vbox_common.c | 2 +- 8 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 35cb14b986..95a71b204f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2473,7 +2473,7 @@ virDomainControllerDefNew(virDomainControllerType type) def->model = -1; def->idx = -1; - switch ((virDomainControllerType) def->type) { + switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: def->opts.vioserial.ports = -1; def->opts.vioserial.vectors = -1; @@ -8265,7 +8265,7 @@ static int virDomainControllerModelTypeFromString(const virDomainControllerDef *def, const char *model) { - switch ((virDomainControllerType)def->type) { + switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: return virDomainControllerModelSCSITypeFromString(model); case VIR_DOMAIN_CONTROLLER_TYPE_USB: @@ -8293,7 +8293,7 @@ static const char * virDomainControllerModelTypeToString(virDomainControllerDef *def, int model) { - switch ((virDomainControllerType)def->type) { + switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: return virDomainControllerModelSCSITypeToString(model); case VIR_DOMAIN_CONTROLLER_TYPE_USB: @@ -8324,7 +8324,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { g_autoptr(virDomainControllerDef) def = NULL; - virDomainControllerType type = 0; + virDomainControllerType type = VIR_DOMAIN_CONTROLLER_TYPE_IDE; xmlNodePtr driver = NULL; g_autofree xmlNodePtr *targetNodes = NULL; int ntargetNodes = 0; @@ -8539,6 +8539,13 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt, break; } + case VIR_DOMAIN_CONTROLLER_TYPE_IDE: + case VIR_DOMAIN_CONTROLLER_TYPE_FDC: + case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: + case VIR_DOMAIN_CONTROLLER_TYPE_SATA: + case VIR_DOMAIN_CONTROLLER_TYPE_CCID: + case VIR_DOMAIN_CONTROLLER_TYPE_ISA: + case VIR_DOMAIN_CONTROLLER_TYPE_LAST: default: break; } @@ -16031,7 +16038,10 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node) virDomainControllerDef * -virDomainDefAddController(virDomainDef *def, int type, int idx, int model) +virDomainDefAddController(virDomainDef *def, + virDomainControllerType type, + int idx, + int model) { virDomainControllerDef *cont; @@ -16106,7 +16116,7 @@ virDomainDefAddUSBController(virDomainDef *def, int idx, int model) int virDomainDefMaybeAddController(virDomainDef *def, - int type, + virDomainControllerType type, int idx, int model) { @@ -21719,7 +21729,7 @@ virDomainDefCheckABIStability(virDomainDef *src, static int virDomainDefAddDiskControllersForType(virDomainDef *def, - int controllerType, + virDomainControllerType controllerType, int diskBus) { size_t i; @@ -22981,7 +22991,7 @@ virDomainControllerDefFormat(virBuffer *buf, if (model) virBufferEscapeString(&attrBuf, " model='%s'", model); - switch ((virDomainControllerType) def->type) { + switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: if (def->opts.vioserial.ports != -1) { virBufferAsprintf(&attrBuf, " ports='%d'", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index fc612f3adb..9dadda2d1d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -784,7 +784,7 @@ struct _virDomainXenbusControllerOpts { /* Stores the virtual disk controller configuration */ struct _virDomainControllerDef { - int type; + virDomainControllerType type; int idx; int model; /* -1 == undef */ unsigned int queues; @@ -4280,12 +4280,15 @@ VIR_ENUM_DECL(virDomainCpuPlacementMode); VIR_ENUM_DECL(virDomainStartupPolicy); virDomainControllerDef * -virDomainDefAddController(virDomainDef *def, int type, int idx, int model); +virDomainDefAddController(virDomainDef *def, + virDomainControllerType type, + int idx, + int model); int virDomainDefAddUSBController(virDomainDef *def, int idx, int model); int virDomainDefMaybeAddController(virDomainDef *def, - int type, + virDomainControllerType type, int idx, int model); int diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 701efd46b4..17d7bfcfd3 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2802,7 +2802,7 @@ qemuBuildControllerDevProps(const virDomainDef *domainDef, *devprops = NULL; - switch ((virDomainControllerType)def->type) { + switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: if (!(props = qemuBuildControllerSCSIDevProps(def, qemuCaps))) return -1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 47c3d69bda..16a8267726 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5540,7 +5540,7 @@ qemuDomainControllerDefPostParse(virDomainControllerDef *cont, virQEMUCaps *qemuCaps, unsigned int parseFlags) { - switch ((virDomainControllerType)cont->type) { + switch (cont->type) { case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: /* Set the default SCSI controller model if not already set */ if (qemuDomainSetSCSIControllerModel(def, cont, qemuCaps) < 0) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 00742d3c0e..2e58930eec 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -608,7 +608,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev, case VIR_DOMAIN_DEVICE_CONTROLLER: { virDomainControllerDef *cont = dev->data.controller; - switch ((virDomainControllerType)cont->type) { + switch (cont->type) { case VIR_DOMAIN_CONTROLLER_TYPE_PCI: return virDomainPCIControllerModelToConnectType(cont->model); @@ -1984,6 +1984,16 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDef *def, } } break; + + case VIR_DOMAIN_CONTROLLER_TYPE_IDE: + case VIR_DOMAIN_CONTROLLER_TYPE_FDC: + case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: + case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: + case VIR_DOMAIN_CONTROLLER_TYPE_CCID: + case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS: + case VIR_DOMAIN_CONTROLLER_TYPE_ISA: + case VIR_DOMAIN_CONTROLLER_TYPE_LAST: + break; } } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 21154892ae..2fbd46325f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5534,7 +5534,7 @@ qemuDomainDiskControllerIsBusy(virDomainObj *vm, continue; /* check whether the disk uses this type controller */ - switch ((virDomainControllerType) detach->type) { + switch (detach->type) { case VIR_DOMAIN_CONTROLLER_TYPE_IDE: if (disk->bus != VIR_DOMAIN_DISK_BUS_IDE) continue; @@ -5599,7 +5599,7 @@ static bool qemuDomainControllerIsBusy(virDomainObj *vm, virDomainControllerDef *detach) { - switch ((virDomainControllerType) detach->type) { + switch (detach->type) { case VIR_DOMAIN_CONTROLLER_TYPE_IDE: case VIR_DOMAIN_CONTROLLER_TYPE_FDC: case VIR_DOMAIN_CONTROLLER_TYPE_SCSI: diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 315fc676f2..2fcc86bb22 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4036,7 +4036,7 @@ qemuValidateDomainDeviceDefController(const virDomainControllerDef *controller, if (qemuValidateDomainDeviceDefControllerAttributes(controller) < 0) return -1; - switch ((virDomainControllerType)controller->type) { + switch (controller->type) { case VIR_DOMAIN_CONTROLLER_TYPE_IDE: ret = qemuValidateDomainDeviceDefControllerIDE(controller, def); break; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 490f337a56..de3c9989a5 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -467,7 +467,7 @@ vboxSetStorageController(virDomainControllerDef *controller, int ret = -1; /* libvirt controller type => vbox bus type */ - switch ((virDomainControllerType) controller->type) { + switch (controller->type) { case VIR_DOMAIN_CONTROLLER_TYPE_FDC: VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_FLOPPY_NAME, &controllerName); vboxBusType = StorageBus_Floppy; -- 2.41.0

Convert the field and adjust the XML parser to use virXMLPropEnum(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 13 ++++--------- src/conf/domain_conf.h | 2 +- src/qemu/qemu_domain_address.c | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 95a71b204f..3b24d0218d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12116,21 +12116,16 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt, VIR_XPATH_NODE_AUTORESTORE(ctxt) int nbackends; g_autofree xmlNodePtr *backends = NULL; - g_autofree char *model = NULL; g_autofree char *backend = NULL; g_autofree char *type = NULL; def = g_new0(virDomainRNGDef, 1); - if (!(model = virXMLPropString(node, "model"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", _("missing RNG device model")); + if (virXMLPropEnum(node, "model", + virDomainRNGModelTypeFromString, + VIR_XML_PROP_REQUIRED, + &def->model) < 0) goto error; - } - - if ((def->model = virDomainRNGModelTypeFromString(model)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown RNG model '%1$s'"), model); - goto error; - } ctxt->node = node; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 9dadda2d1d..f56c04ce36 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2609,7 +2609,7 @@ typedef enum { } virDomainRNGBackend; struct _virDomainRNGDef { - int model; + virDomainRNGModel model; int backend; unsigned int rate; /* bytes per period */ unsigned int period; /* milliseconds */ diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 2e58930eec..0ed70e5b86 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -912,7 +912,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev, break; case VIR_DOMAIN_DEVICE_RNG: - switch ((virDomainRNGModel) dev->data.rng->model) { + switch (dev->data.rng->model) { case VIR_DOMAIN_RNG_MODEL_VIRTIO_TRANSITIONAL: /* Transitional devices only work in conventional PCI slots */ return pciFlags; -- 2.41.0

Convert the field and adjust the XML parser to use virXMLPropEnum(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_audit.c | 4 ++-- src/conf/domain_conf.c | 22 ++++++++-------------- src/conf/domain_conf.h | 2 +- src/qemu/qemu_command.c | 4 ++-- src/qemu/qemu_namespace.c | 2 +- src/qemu/qemu_validate.c | 2 +- 6 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index 4294b50c3a..7a6bb02203 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -215,7 +215,7 @@ virDomainAuditRNG(virDomainObj *vm, const char *oldsrcpath = NULL; if (newDef) { - switch ((virDomainRNGBackend) newDef->backend) { + switch (newDef->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: newsrcpath = newDef->source.file; break; @@ -231,7 +231,7 @@ virDomainAuditRNG(virDomainObj *vm, } if (oldDef) { - switch ((virDomainRNGBackend) oldDef->backend) { + switch (oldDef->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: oldsrcpath = oldDef->source.file; break; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3b24d0218d..47c4170f29 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12116,7 +12116,6 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt, VIR_XPATH_NODE_AUTORESTORE(ctxt) int nbackends; g_autofree xmlNodePtr *backends = NULL; - g_autofree char *backend = NULL; g_autofree char *type = NULL; def = g_new0(virDomainRNGDef, 1); @@ -12151,19 +12150,14 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt, goto error; } - if (!(backend = virXMLPropString(backends[0], "model"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing RNG device backend model")); + if (virXMLPropEnum(backends[0], "model", + virDomainRNGBackendTypeFromString, + VIR_XML_PROP_REQUIRED, + &def->backend) < 0) { goto error; } - if ((def->backend = virDomainRNGBackendTypeFromString(backend)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown RNG backend model '%1$s'"), backend); - goto error; - } - - switch ((virDomainRNGBackend) def->backend) { + switch (def->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: def->source.file = virXPathString("string(./backend)", ctxt); break; @@ -15197,7 +15191,7 @@ virDomainRNGFind(virDomainDef *def, if (rng->rate != tmp->rate || rng->period != tmp->period) continue; - switch ((virDomainRNGBackend) rng->backend) { + switch (rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: if (STRNEQ_NULLABLE(rng->source.file, tmp->source.file)) continue; @@ -25076,7 +25070,7 @@ virDomainRNGDefFormat(virBuffer *buf, } virBufferAsprintf(buf, "<backend model='%s'", backend); - switch ((virDomainRNGBackend) def->backend) { + switch (def->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: virBufferEscapeString(buf, ">%s</backend>\n", def->source.file); break; @@ -25117,7 +25111,7 @@ virDomainRNGDefFree(virDomainRNGDef *def) if (!def) return; - switch ((virDomainRNGBackend) def->backend) { + switch (def->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: g_free(def->source.file); break; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f56c04ce36..c9b9fbabd3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2610,7 +2610,7 @@ typedef enum { struct _virDomainRNGDef { virDomainRNGModel model; - int backend; + virDomainRNGBackend backend; unsigned int rate; /* bytes per period */ unsigned int period; /* milliseconds */ diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 17d7bfcfd3..11ede25c0b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5361,7 +5361,7 @@ qemuBuildRNGBackendChrdev(virCommand *cmd, { g_autofree char *charAlias = qemuAliasChardevFromDevAlias(rng->info.alias); - switch ((virDomainRNGBackend) rng->backend) { + switch (rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_BUILTIN: case VIR_DOMAIN_RNG_BACKEND_LAST: @@ -5390,7 +5390,7 @@ qemuBuildRNGBackendProps(virDomainRNGDef *rng, objAlias = g_strdup_printf("obj%s", rng->info.alias); - switch ((virDomainRNGBackend) rng->backend) { + switch (rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: if (qemuMonitorCreateObjectProps(props, "rng-random", objAlias, "s:filename", rng->source.file, diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index f245712f9a..915d44310f 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -574,7 +574,7 @@ static int qemuDomainSetupRNG(virDomainRNGDef *rng, GSList **paths) { - switch ((virDomainRNGBackend) rng->backend) { + switch (rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: *paths = g_slist_prepend(*paths, g_strdup(rng->source.file)); break; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 2fcc86bb22..fc61c489e9 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2154,7 +2154,7 @@ qemuValidateDomainRNGDef(const virDomainRNGDef *def, { virDomainCapsDeviceRNG rngCaps = { 0 }; - switch ((virDomainRNGBackend) def->backend) { + switch (def->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", -- 2.41.0

Convert the field and adjust the XML parsers to use virXMLPropEnum(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 15 ++++----------- src/conf/domain_conf.h | 2 +- src/qemu/qemu_domain_address.c | 2 +- src/qemu/qemu_validate.c | 2 +- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 47c4170f29..5c1712cb46 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12065,21 +12065,14 @@ virDomainWatchdogDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { virDomainWatchdogDef *def; - g_autofree char *model = NULL; g_autofree char *action = NULL; def = g_new0(virDomainWatchdogDef, 1); - model = virXMLPropString(node, "model"); - if (model == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("watchdog must contain model name")); - goto error; - } - def->model = virDomainWatchdogModelTypeFromString(model); - if (def->model < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown watchdog model '%1$s'"), model); + if (virXMLPropEnum(node, "model", + virDomainWatchdogModelTypeFromString, + VIR_XML_PROP_REQUIRED, + &def->model) < 0) { goto error; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c9b9fbabd3..e7c663b0e9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1759,7 +1759,7 @@ typedef enum { } virDomainWatchdogAction; struct _virDomainWatchdogDef { - int model; + virDomainWatchdogModel model; int action; virDomainDeviceInfo info; }; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 0ed70e5b86..099778b2a8 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -927,7 +927,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev, case VIR_DOMAIN_DEVICE_WATCHDOG: /* only one model connects using PCI */ - switch ((virDomainWatchdogModel) dev->data.watchdog->model) { + switch (dev->data.watchdog->model) { case VIR_DOMAIN_WATCHDOG_MODEL_I6300ESB: return pciFlags; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index fc61c489e9..27fd5b9a99 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2251,7 +2251,7 @@ qemuValidateDomainWatchdogDef(const virDomainWatchdogDef *dev, return -1; } - switch ((virDomainWatchdogModel) dev->model) { + switch (dev->model) { case VIR_DOMAIN_WATCHDOG_MODEL_I6300ESB: if (dev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && dev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) { -- 2.41.0

Convert the field and adjust the XML parser to use virXMLPropEnumDefault(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 17 ++++++----------- src/conf/domain_conf.h | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5c1712cb46..f48020f893 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12065,7 +12065,6 @@ virDomainWatchdogDefParseXML(virDomainXMLOption *xmlopt, unsigned int flags) { virDomainWatchdogDef *def; - g_autofree char *action = NULL; def = g_new0(virDomainWatchdogDef, 1); @@ -12076,16 +12075,12 @@ virDomainWatchdogDefParseXML(virDomainXMLOption *xmlopt, goto error; } - action = virXMLPropString(node, "action"); - if (action == NULL) { - def->action = VIR_DOMAIN_WATCHDOG_ACTION_RESET; - } else { - def->action = virDomainWatchdogActionTypeFromString(action); - if (def->action < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown watchdog action '%1$s'"), action); - goto error; - } + if (virXMLPropEnumDefault(node, "action", + virDomainWatchdogActionTypeFromString, + VIR_XML_PROP_NONE, + &def->action, + VIR_DOMAIN_WATCHDOG_ACTION_RESET) < 0) { + goto error; } if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info, flags) < 0) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e7c663b0e9..77e5b26957 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1760,7 +1760,7 @@ typedef enum { struct _virDomainWatchdogDef { virDomainWatchdogModel model; - int action; + virDomainWatchdogAction action; virDomainDeviceInfo info; }; -- 2.41.0

Convert the field, adjust the XML parsers to use virXMLPropEnum() and fill in missing cases to switch() statements. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- 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

Convert the field and adjust the XML parsers to use virXMLPropEnumDefault(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 16 ++++++---------- src/conf/storage_source_conf.h | 2 +- src/qemu/qemu_backup.c | 2 +- src/qemu/qemu_block.c | 2 +- src/qemu/qemu_monitor_json.c | 2 +- src/storage_file/storage_file_backend_gluster.c | 2 +- src/storage_file/storage_source_backingstore.c | 15 +++++++++------ 7 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a743a0628c..5f4146b4e3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5834,17 +5834,13 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, g_autofree char *port = NULL; memset(host, 0, sizeof(*host)); - host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; - /* transport can be tcp (default), unix or rdma. */ - if ((transport = virXMLPropString(hostnode, "transport"))) { - host->transport = virStorageNetHostTransportTypeFromString(transport); - if (host->transport < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown protocol transport type '%1$s'"), - transport); - goto cleanup; - } + if (virXMLPropEnumDefault(hostnode, "transport", + virStorageNetHostTransportTypeFromString, + VIR_XML_PROP_NONE, + &host->transport, + VIR_STORAGE_NET_HOST_TRANS_TCP) < 0) { + goto cleanup; } host->socket = virXMLPropString(hostnode, "socket"); diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index f99579bce2..9791fb25ee 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -151,7 +151,7 @@ typedef struct _virStorageNetHostDef virStorageNetHostDef; struct _virStorageNetHostDef { char *name; unsigned int port; - int transport; /* virStorageNetHostTransport */ + virStorageNetHostTransport transport; char *socket; /* path to unix socket */ }; diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c index a94869522d..e4db967e2c 100644 --- a/src/qemu/qemu_backup.c +++ b/src/qemu/qemu_backup.c @@ -68,7 +68,7 @@ qemuBackupPrepare(virDomainBackupDef *def) def->server->name = g_strdup("localhost"); } - switch ((virStorageNetHostTransport) def->server->transport) { + switch (def->server->transport) { case VIR_STORAGE_NET_HOST_TRANS_TCP: /* TODO: Update qemu.conf to provide a port range, * probably starting at 10809, for obtaining automatic diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d31bbde0f4..97f03002fd 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -130,7 +130,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDef *host) g_autoptr(virJSONValue) server = NULL; g_autofree char *port = NULL; - switch ((virStorageNetHostTransport) host->transport) { + switch (host->transport) { case VIR_STORAGE_NET_HOST_TRANS_TCP: port = g_strdup_printf("%u", host->port); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 5b9edadcf7..137cb4e293 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6176,7 +6176,7 @@ qemuMonitorJSONNBDServerStart(qemuMonitor *mon, g_autoptr(virJSONValue) addr = NULL; g_autofree char *port_str = NULL; - switch ((virStorageNetHostTransport)server->transport) { + switch (server->transport) { case VIR_STORAGE_NET_HOST_TRANS_TCP: port_str = g_strdup_printf("%u", server->port); addr = qemuMonitorJSONBuildInetSocketAddress(server->name, port_str); diff --git a/src/storage_file/storage_file_backend_gluster.c b/src/storage_file/storage_file_backend_gluster.c index d018d5422e..950f8e81fe 100644 --- a/src/storage_file/storage_file_backend_gluster.c +++ b/src/storage_file/storage_file_backend_gluster.c @@ -63,7 +63,7 @@ virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPriv *priv, const char *hoststr = NULL; int port = 0; - switch ((virStorageNetHostTransport) host->transport) { + switch (host->transport) { case VIR_STORAGE_NET_HOST_TRANS_RDMA: case VIR_STORAGE_NET_HOST_TRANS_TCP: hoststr = host->name; diff --git a/src/storage_file/storage_source_backingstore.c b/src/storage_file/storage_source_backingstore.c index 00fcfe9fd7..80681924ea 100644 --- a/src/storage_file/storage_source_backingstore.c +++ b/src/storage_file/storage_source_backingstore.c @@ -42,6 +42,7 @@ virStorageSourceParseBackingURI(virStorageSource *src, { g_autoptr(virURI) uri = NULL; const char *path = NULL; + int transport = 0; g_auto(GStrv) scheme = NULL; if (!(uri = virURIParse(uristr))) { @@ -65,12 +66,14 @@ virStorageSourceParseBackingURI(virStorageSource *src, return -1; } - if (scheme[1] && - (src->hosts->transport = virStorageNetHostTransportTypeFromString(scheme[1])) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid protocol transport type '%1$s'"), - scheme[1]); - return -1; + if (scheme[1]) { + if ((transport = virStorageNetHostTransportTypeFromString(scheme[1])) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid protocol transport type '%1$s'"), + scheme[1]); + return -1; + } + src->hosts->transport = transport; } if (uri->query) { -- 2.41.0

Inside of virDomainDiskSourceNVMeParse() we have virXMLPropString() + virStrToLong_ull() combo. Switch to virXMLPropULongLong() which does the same thing. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5f4146b4e3..0efac66f61 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7229,7 +7229,6 @@ virDomainDiskSourceNVMeParse(xmlNodePtr node, { g_autoptr(virStorageSourceNVMeDef) nvme = NULL; g_autofree char *type = NULL; - g_autofree char *namespc = NULL; xmlNodePtr address; nvme = g_new0(virStorageSourceNVMeDef, 1); @@ -7247,16 +7246,9 @@ virDomainDiskSourceNVMeParse(xmlNodePtr node, return -1; } - if (!(namespc = virXMLPropString(node, "namespace"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing 'namespace' attribute to disk source")); - return -1; - } - - if (virStrToLong_ull(namespc, NULL, 10, &nvme->namespc) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("malformed namespace '%1$s'"), - namespc); + if (virXMLPropULongLong(node, "namespace", 10, + VIR_XML_PROP_REQUIRED, + &nvme->namespc) < 0) { return -1; } -- 2.41.0

On a Thursday in 2023, Michal Privoznik wrote:
I had these sitting on a local branch for a while. My initial plan was to use virXMLPropEnum() more and while working on that I found one bug (patch 01/20), one improvement (patch 02/20) and a couple of useless typecats.
Michal Prívozník (20): lxc_controller: Access correct union member in virLXCControllerSetupHostdevCaps() src: Access hostdev->source.subsys iff VIR_DOMAIN_HOSTDEV_MODE_SUBSYS qemu_domain_address: Drop needless typecast in qemuDomainDeviceCalculatePCIConnectFlags() qemu: Drop needless typecast to virDomainFSDriverType src: Drop needless typecast to virDomainDeviceType qemu_domain_address: Drop needless typecast to virDomainDiskModel src: Drop needless typecast to virDomainDiskBus virDomainHostdevSubsysSCSI: Convert 'protocol' field to proper enum type virDomainHostdevSubsysSCSIVHost: Convert 'protocol' field to proper enum type virDomainHostdevDef: Convert 'mode' field to proper enum type virDomainHostdevCaps: Convert 'type' field to proper enum type virDomainHostdevSubsys: Convert 'type' field to proper enum type virDomainControllerDef: Convert 'type' field to proper enum type virDomainRNGDef: Convert 'model' field to proper enum type virDomainRNGDef: Convert 'backend' field to proper enum type virDomainWatchdogDef: Convert 'model' field to proper enum type virDomainWatchdogDef: Convert 'action' field to proper enum type virDomainDeviceInfo: Convert 'type' field to proper enum type virStorageNetHostDef: Convert 'transport' field to proper enum type virDomainDiskSourceNVMeParse: Use virXMLPropULongLong()
src/ch/ch_domain.c | 2 +- src/conf/device_conf.c | 12 +- src/conf/device_conf.h | 4 +- src/conf/domain_audit.c | 10 +- src/conf/domain_conf.c | 291 ++++++++---------- src/conf/domain_conf.h | 29 +- src/conf/domain_postparse.c | 2 +- src/conf/domain_validate.c | 9 +- src/conf/storage_source_conf.h | 2 +- src/libxl/libxl_driver.c | 12 + src/lxc/lxc_cgroup.c | 3 + src/lxc/lxc_controller.c | 9 +- src/lxc/lxc_driver.c | 16 + src/lxc/lxc_hostdev.c | 7 + src/qemu/qemu_alias.c | 2 +- src/qemu/qemu_backup.c | 2 +- src/qemu/qemu_block.c | 2 +- src/qemu/qemu_command.c | 26 +- src/qemu/qemu_domain.c | 18 +- src/qemu/qemu_domain_address.c | 28 +- src/qemu/qemu_driver.c | 6 +- src/qemu/qemu_hotplug.c | 22 +- src/qemu/qemu_migration.c | 4 +- src/qemu/qemu_monitor.c | 12 + src/qemu/qemu_monitor_json.c | 2 +- src/qemu/qemu_namespace.c | 2 +- src/qemu/qemu_validate.c | 18 +- src/security/security_apparmor.c | 2 +- src/security/security_dac.c | 4 +- src/security/security_selinux.c | 10 +- src/security/virt-aa-helper.c | 7 + .../storage_file_backend_gluster.c | 2 +- .../storage_source_backingstore.c | 15 +- src/vbox/vbox_common.c | 4 +- 34 files changed, 333 insertions(+), 263 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On a Thursday in 2023, Michal Privoznik wrote:
I had these sitting on a local branch for a while. My initial plan was to use virXMLPropEnum() more and while working on that I found one bug (patch 01/20), one improvement (patch 02/20) and a couple of useless typecats.
Also: s/typecats/^..^ typecats ^..^/ Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik