Validation should happen after parsing, so the proper location for it is virDomainControllerDefValidate() rather than virDomainControllerDefParseXML(). Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- src/conf/domain_conf.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3db56ffb7..86afeaa3f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -4995,12 +4995,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; } @@ -9322,27 +9344,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) { -- 2.13.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list