conf: Move target index validation

Validation should happen after parsing, so the proper
location for it is virDomainControllerDefValidate()
rather than virDomainControllerDefParseXML().

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Andrea Bolognani 2017-08-17 16:22:14 +02:00
parent 9e318ad713
commit c9d75d655a
1 changed files with 24 additions and 16 deletions

View File

@ -5071,12 +5071,34 @@ static int
virDomainControllerDefValidate(const virDomainControllerDef *controller)
{
if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
const virDomainPCIControllerOpts *opts = &controller->opts.pciopts;
if (controller->idx > 255) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("PCI controller index %d too high, maximum is 255"),
controller->idx);
return -1;
}
/* Only validate the target index if it's been set */
if (opts->targetIndex != -1) {
if (opts->targetIndex < 0 || opts->targetIndex > 31) {
virReportError(VIR_ERR_XML_ERROR,
_("PCI controller target index '%d' out of "
"range - must be 0-31"),
opts->targetIndex);
return -1;
}
if ((controller->idx == 0 && opts->targetIndex != 0) ||
(controller->idx != 0 && opts->targetIndex == 0)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Only the PCI controller with index 0 can "
"have target index 0, and vice versa"));
return -1;
}
}
}
return 0;
}
@ -9398,27 +9420,13 @@ virDomainControllerDefParseXML(xmlNodePtr node,
}
if (targetIndex) {
if (virStrToLong_i(targetIndex, NULL, 0,
&def->opts.pciopts.targetIndex) < 0) {
&def->opts.pciopts.targetIndex) < 0 ||
def->opts.pciopts.targetIndex == -1) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid target index '%s' in PCI controller"),
targetIndex);
goto error;
}
if (def->opts.pciopts.targetIndex < 0 ||
def->opts.pciopts.targetIndex > 31) {
virReportError(VIR_ERR_XML_ERROR,
_("PCI controller target index '%s' out of "
"range - must be 0-31"),
targetIndex);
goto error;
}
if ((def->idx == 0 && def->opts.pciopts.targetIndex != 0) ||
(def->idx != 0 && def->opts.pciopts.targetIndex == 0)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Only the PCI controller with index 0 can "
"have target index 0, and vice versa"));
goto error;
}
}
if (numaNode >= 0) {
if (def->idx == 0) {