conf: domain: Convert virDomainDiskDef's 'tray_status' to virDomainDiskTray

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
This commit is contained in:
Peter Krempa 2021-04-16 10:46:00 +02:00
parent f1c9fed2ca
commit 56be92b473
2 changed files with 4 additions and 11 deletions

View File

@ -9344,7 +9344,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
g_autofree char *bus = NULL;
g_autofree char *serial = NULL;
g_autofree char *startupPolicy = NULL;
g_autofree char *tray = NULL;
g_autofree char *removable = NULL;
g_autofree char *logical_block_size = NULL;
g_autofree char *physical_block_size = NULL;
@ -9415,7 +9414,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
virXMLNodeNameEqual(cur, "target")) {
target = virXMLPropString(cur, "dev");
bus = virXMLPropString(cur, "bus");
tray = virXMLPropString(cur, "tray");
if (virXMLPropEnum(cur, "tray", virDomainDiskTrayTypeFromString,
VIR_XML_PROP_OPTIONAL, &def->tray_status) < 0)
return NULL;
removable = virXMLPropString(cur, "removable");
rotation_rate = virXMLPropString(cur, "rotation_rate");
@ -9634,14 +9635,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
}
}
if (tray) {
if ((def->tray_status = virDomainDiskTrayTypeFromString(tray)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown disk tray status '%s'"), tray);
return NULL;
}
}
if (removable) {
if ((def->removable = virTristateSwitchTypeFromString(removable)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,

View File

@ -537,7 +537,7 @@ struct _virDomainDiskDef {
int device; /* enum virDomainDiskDevice */
int bus; /* enum virDomainDiskBus */
char *dst;
int tray_status; /* enum virDomainDiskTray */
virDomainDiskTray tray_status;
int removable; /* enum virTristateSwitch */
unsigned int rotation_rate;