1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-02-24 04:12:20 +00:00

conf: domain: Convert virDomainDiskDef's 'device' to virDomainDiskDevice

Use the appropriate type for the variable and refactor the XML parser to
parse it correctly using virXMLPropEnum.

Changes to other places using switch statements were required.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-04-16 10:46:00 +02:00
parent 0d7f0fe81a
commit 02dfea6693
7 changed files with 24 additions and 8 deletions

@ -208,6 +208,9 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
else
virBufferAsprintf(&device, "-cd,%s", disk_source);
break;
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
case VIR_DOMAIN_DISK_DEVICE_LUN:
case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported disk device"));

@ -9319,7 +9319,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
xmlNodePtr cur;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
bool source = false;
g_autofree char *tmp = NULL;
g_autofree char *target = NULL;
g_autofree char *serial = NULL;
g_autofree char *logical_block_size = NULL;
@ -9342,13 +9341,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
/* defaults */
def->device = VIR_DOMAIN_DISK_DEVICE_DISK;
if ((tmp = virXMLPropString(node, "device")) &&
(def->device = virDomainDiskDeviceTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown disk device '%s'"), tmp);
if (virXMLPropEnum(node, "device", virDomainDiskDeviceTypeFromString,
VIR_XML_PROP_OPTIONAL, &def->device) < 0)
return NULL;
}
VIR_FREE(tmp);
if (virXMLPropEnum(node, "model", virDomainDiskModelTypeFromString,
VIR_XML_PROP_OPTIONAL, &def->model) < 0)

@ -535,7 +535,7 @@ struct _virDomainDiskDef {
virObject *privateData;
int device; /* enum virDomainDiskDevice */
virDomainDiskDevice device;
virDomainDiskBus bus;
char *dst;
virDomainDiskTray tray_status;

@ -886,6 +886,8 @@ hypervDomainAttachStorageVolume(virDomainPtr domain,
return hypervDomainAttachCDROM(domain, disk, controller, hostname);
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
return hypervDomainAttachFloppy(domain, disk, controller, hostname);
case VIR_DOMAIN_DISK_DEVICE_LUN:
case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unsupported disk bus"));
break;

@ -3084,6 +3084,9 @@ libxlDomainAttachDeviceDiskLive(virDomainObj *vm, virDomainDeviceDef *dev)
virDomainDiskBusTypeToString(l_disk->bus));
}
break;
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
case VIR_DOMAIN_DISK_DEVICE_LUN:
case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk device type '%s' cannot be hotplugged"),
@ -3369,6 +3372,10 @@ libxlDomainDetachDeviceDiskLive(virDomainObj *vm, virDomainDeviceDef *dev)
virDomainDiskBusTypeToString(dev->data.disk->bus));
}
break;
case VIR_DOMAIN_DISK_DEVICE_CDROM:
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
case VIR_DOMAIN_DISK_DEVICE_LUN:
case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("device type '%s' cannot hot unplugged"),
@ -4031,6 +4038,10 @@ libxlDomainUpdateDeviceLive(virDomainObj *vm, virDomainDeviceDef *dev)
if (ret == 0)
dev->data.disk = NULL;
break;
case VIR_DOMAIN_DISK_DEVICE_DISK:
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
case VIR_DOMAIN_DISK_DEVICE_LUN:
case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("disk bus '%s' cannot be updated."),

@ -2253,6 +2253,10 @@ qemuBuildDisksCommandLine(virCommand *cmd,
bootindex = bootDisk;
bootDisk = 0;
break;
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
break;
}
}

@ -3474,6 +3474,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOption *xmlopt, virDomainDef
break;
case VIR_DOMAIN_DISK_DEVICE_LAST:
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported disk device type '%s'"),