virDomainControllerDefParseXML: Use virXMLProp*

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-04-23 16:39:15 +02:00 committed by Ján Tomko
parent f953e37846
commit 020dd80ecb

View File

@ -9500,7 +9500,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
unsigned int flags) unsigned int flags)
{ {
g_autoptr(virDomainControllerDef) def = NULL; g_autoptr(virDomainControllerDef) def = NULL;
int type = 0; virDomainControllerType type = 0;
xmlNodePtr cur = NULL; xmlNodePtr cur = NULL;
bool processedModel = false; bool processedModel = false;
bool processedTarget = false; bool processedTarget = false;
@ -9508,33 +9508,14 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
int ports = -1; int ports = -1;
VIR_XPATH_NODE_AUTORESTORE(ctxt) VIR_XPATH_NODE_AUTORESTORE(ctxt)
int rc; int rc;
g_autofree char *typeStr = NULL;
g_autofree char *idx = NULL; g_autofree char *idx = NULL;
g_autofree char *model = NULL; g_autofree char *model = NULL;
g_autofree char *queues = NULL;
g_autofree char *cmd_per_lun = NULL;
g_autofree char *max_sectors = NULL;
g_autofree char *modelName = NULL;
g_autofree char *chassisNr = NULL;
g_autofree char *chassis = NULL;
g_autofree char *port = NULL;
g_autofree char *busNr = NULL;
g_autofree char *targetIndex = NULL;
g_autofree char *hotplug = NULL;
g_autofree char *ioeventfd = NULL;
g_autofree char *portsStr = NULL;
g_autofree char *iothread = NULL;
ctxt->node = node; ctxt->node = node;
typeStr = virXMLPropString(node, "type"); if (virXMLPropEnum(node, "type", virDomainControllerTypeFromString,
if (typeStr) { VIR_XML_PROP_NONE, &type) < 0)
if ((type = virDomainControllerTypeFromString(typeStr)) < 0) { return NULL;
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown controller type '%s'"), typeStr);
return NULL;
}
}
if (!(def = virDomainControllerDefNew(type))) if (!(def = virDomainControllerDefNew(type)))
return NULL; return NULL;
@ -9564,11 +9545,26 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
while (cur != NULL) { while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) { if (cur->type == XML_ELEMENT_NODE) {
if (virXMLNodeNameEqual(cur, "driver")) { if (virXMLNodeNameEqual(cur, "driver")) {
queues = virXMLPropString(cur, "queues"); if (virXMLPropUInt(cur, "queues", 10, VIR_XML_PROP_NONE,
cmd_per_lun = virXMLPropString(cur, "cmd_per_lun"); &def->queues) < 0)
max_sectors = virXMLPropString(cur, "max_sectors"); return NULL;
ioeventfd = virXMLPropString(cur, "ioeventfd");
iothread = virXMLPropString(cur, "iothread"); if (virXMLPropUInt(cur, "cmd_per_lun", 10, VIR_XML_PROP_NONE,
&def->cmd_per_lun) < 0)
return NULL;
if (virXMLPropUInt(cur, "max_sectors", 10, VIR_XML_PROP_NONE,
&def->max_sectors) < 0)
return NULL;
if (virXMLPropTristateSwitch(cur, "ioeventfd",
VIR_XML_PROP_NONE,
&def->ioeventfd) < 0)
return NULL;
if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONE,
&def->iothread) < 0)
return NULL;
if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
return NULL; return NULL;
@ -9579,7 +9575,15 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
"controller definition not allowed")); "controller definition not allowed"));
return NULL; return NULL;
} }
modelName = virXMLPropString(cur, "name");
if (def->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
if (virXMLPropEnum(cur, "name",
virDomainControllerPCIModelNameTypeFromString,
VIR_XML_PROP_NONE,
&def->opts.pciopts.modelName) < 0)
return NULL;
}
processedModel = true; processedModel = true;
} else if (virXMLNodeNameEqual(cur, "target")) { } else if (virXMLNodeNameEqual(cur, "target")) {
if (processedTarget) { if (processedTarget) {
@ -9588,12 +9592,39 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
"controller definition not allowed")); "controller definition not allowed"));
return NULL; return NULL;
} }
chassisNr = virXMLPropString(cur, "chassisNr"); if (def->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
chassis = virXMLPropString(cur, "chassis"); if (virXMLPropInt(cur, "chassisNr", 0, VIR_XML_PROP_NONE,
port = virXMLPropString(cur, "port"); &def->opts.pciopts.chassisNr) < 0)
busNr = virXMLPropString(cur, "busNr"); return NULL;
hotplug = virXMLPropString(cur, "hotplug");
targetIndex = virXMLPropString(cur, "index"); if (virXMLPropInt(cur, "chassis", 0, VIR_XML_PROP_NONE,
&def->opts.pciopts.chassis) < 0)
return NULL;
if (virXMLPropInt(cur, "port", 0, VIR_XML_PROP_NONE,
&def->opts.pciopts.port) < 0)
return NULL;
if (virXMLPropInt(cur, "busNr", 0, VIR_XML_PROP_NONE,
&def->opts.pciopts.busNr) < 0)
return NULL;
if (virXMLPropTristateSwitch(cur, "hotplug",
VIR_XML_PROP_NONE,
&def->opts.pciopts.hotplug) < 0)
return NULL;
if ((rc = virXMLPropInt(cur, "index", 0, VIR_XML_PROP_NONE,
&def->opts.pciopts.targetIndex)) < 0)
return NULL;
if ((rc == 1) && def->opts.pciopts.targetIndex == -1) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid target index '%i' in PCI controller"),
def->opts.pciopts.targetIndex);
}
}
processedTarget = true; processedTarget = true;
} }
} }
@ -9610,42 +9641,6 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
return NULL; return NULL;
} }
if (queues && virStrToLong_ui(queues, NULL, 10, &def->queues) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Malformed 'queues' value '%s'"), queues);
return NULL;
}
if (cmd_per_lun && virStrToLong_ui(cmd_per_lun, NULL, 10, &def->cmd_per_lun) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Malformed 'cmd_per_lun' value '%s'"), cmd_per_lun);
return NULL;
}
if (max_sectors && virStrToLong_ui(max_sectors, NULL, 10, &def->max_sectors) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Malformed 'max_sectors' value %s"), max_sectors);
return NULL;
}
if (ioeventfd) {
int value;
if ((value = virTristateSwitchTypeFromString(ioeventfd)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Malformed 'ioeventfd' value %s"), ioeventfd);
return NULL;
}
def->ioeventfd = value;
}
if (iothread) {
if (virStrToLong_uip(iothread, NULL, 10, &def->iothread) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid 'iothread' value '%s'"), iothread);
return NULL;
}
}
if (def->type == VIR_DOMAIN_CONTROLLER_TYPE_USB && if (def->type == VIR_DOMAIN_CONTROLLER_TYPE_USB &&
def->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { def->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
VIR_DEBUG("Ignoring device address for none model usb controller"); VIR_DEBUG("Ignoring device address for none model usb controller");
@ -9654,30 +9649,28 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
return NULL; return NULL;
} }
portsStr = virXMLPropString(node, "ports"); if ((rc = virXMLPropInt(node, "ports", 10, VIR_XML_PROP_NONE, &ports)) < 0)
if (portsStr) { return NULL;
int r = virStrToLong_i(portsStr, NULL, 10, &ports); if ((rc == 1) && ports < 0) {
if (r != 0 || ports < 0) { virReportError(VIR_ERR_INTERNAL_ERROR,
virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid ports: %i"), ports);
_("Invalid ports: %s"), portsStr); return NULL;
return NULL;
}
} }
switch (def->type) { switch (def->type) {
case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: {
g_autofree char *vectors = virXMLPropString(node, "vectors"); if ((rc = virXMLPropInt(node, "vectors", 10, VIR_XML_PROP_NONE,
&def->opts.vioserial.vectors)) < 0)
return NULL;
if ((rc == 1) && def->opts.vioserial.vectors < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid vectors: %i"),
def->opts.vioserial.vectors);
return NULL;
}
def->opts.vioserial.ports = ports; def->opts.vioserial.ports = ports;
if (vectors) {
int r = virStrToLong_i(vectors, NULL, 10,
&def->opts.vioserial.vectors);
if (r != 0 || def->opts.vioserial.vectors < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid vectors: %s"), vectors);
return NULL;
}
}
break; break;
} }
case VIR_DOMAIN_CONTROLLER_TYPE_USB: { case VIR_DOMAIN_CONTROLLER_TYPE_USB: {
@ -9731,98 +9724,32 @@ virDomainControllerDefParseXML(virDomainXMLOption *xmlopt,
/* Other controller models don't require extra checks */ /* Other controller models don't require extra checks */
break; break;
} }
if (modelName) {
int value;
if ((value = virDomainControllerPCIModelNameTypeFromString(modelName)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown PCI controller model name '%s'"),
modelName);
return NULL;
}
def->opts.pciopts.modelName = value;
}
if (chassisNr) {
if (virStrToLong_i(chassisNr, NULL, 0,
&def->opts.pciopts.chassisNr) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid chassisNr '%s' in PCI controller"),
chassisNr);
return NULL;
}
}
if (chassis) {
if (virStrToLong_i(chassis, NULL, 0,
&def->opts.pciopts.chassis) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid chassis '%s' in PCI controller"),
chassis);
return NULL;
}
}
if (port) {
if (virStrToLong_i(port, NULL, 0,
&def->opts.pciopts.port) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid port '%s' in PCI controller"),
port);
return NULL;
}
}
if (busNr) {
if (virStrToLong_i(busNr, NULL, 0,
&def->opts.pciopts.busNr) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid busNr '%s' in PCI controller"),
busNr);
return NULL;
}
}
if (targetIndex) {
if (virStrToLong_i(targetIndex, NULL, 0,
&def->opts.pciopts.targetIndex) < 0 ||
def->opts.pciopts.targetIndex == -1) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid target index '%s' in PCI controller"),
targetIndex);
return NULL;
}
}
if (numaNode >= 0) if (numaNode >= 0)
def->opts.pciopts.numaNode = numaNode; def->opts.pciopts.numaNode = numaNode;
if (hotplug) {
int val = virTristateSwitchTypeFromString(hotplug);
if (val <= 0) {
virReportError(VIR_ERR_XML_ERROR,
_("PCI controller unrecognized hotplug setting '%s'"),
hotplug);
return NULL;
}
def->opts.pciopts.hotplug = val;
}
break; break;
case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS: { case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS: {
g_autofree char *gntframes = virXMLPropString(node, "maxGrantFrames"); if ((rc = virXMLPropInt(node, "maxGrantFrames", 10, VIR_XML_PROP_NONE,
g_autofree char *eventchannels = virXMLPropString(node, "maxEventChannels"); &def->opts.xenbusopts.maxGrantFrames)) < 0)
return NULL;
if (gntframes) { if ((rc == 1) && def->opts.xenbusopts.maxGrantFrames < 0) {
int r = virStrToLong_i(gntframes, NULL, 10, virReportError(VIR_ERR_INTERNAL_ERROR,
&def->opts.xenbusopts.maxGrantFrames); _("Invalid maxGrantFrames: %i"),
if (r != 0 || def->opts.xenbusopts.maxGrantFrames < 0) { def->opts.xenbusopts.maxGrantFrames);
virReportError(VIR_ERR_INTERNAL_ERROR, return NULL;
_("Invalid maxGrantFrames: %s"), gntframes);
return NULL;
}
} }
if (eventchannels) {
int r = virStrToLong_i(eventchannels, NULL, 10, if ((rc = virXMLPropInt(node, "maxEventChannels", 10, VIR_XML_PROP_NONE,
&def->opts.xenbusopts.maxEventChannels); &def->opts.xenbusopts.maxEventChannels)) < 0)
if (r != 0 || def->opts.xenbusopts.maxEventChannels < 0) { return NULL;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Invalid maxEventChannels: %s"), eventchannels); if ((rc == 1) && def->opts.xenbusopts.maxEventChannels < 0) {
return NULL; virReportError(VIR_ERR_INTERNAL_ERROR,
} _("Invalid maxEventChannels: %i"),
def->opts.xenbusopts.maxEventChannels);
return NULL;
} }
break; break;
} }