提交 c9d75d65 编写于 作者: A Andrea Bolognani

conf: Move target index validation

Validation should happen after parsing, so the proper
location for it is virDomainControllerDefValidate()
rather than virDomainControllerDefParseXML().
Signed-off-by: NAndrea Bolognani <abologna@redhat.com>
上级 9e318ad7
...@@ -5071,12 +5071,34 @@ static int ...@@ -5071,12 +5071,34 @@ static int
virDomainControllerDefValidate(const virDomainControllerDef *controller) virDomainControllerDefValidate(const virDomainControllerDef *controller)
{ {
if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) { if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
const virDomainPCIControllerOpts *opts = &controller->opts.pciopts;
if (controller->idx > 255) { if (controller->idx > 255) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("PCI controller index %d too high, maximum is 255"), _("PCI controller index %d too high, maximum is 255"),
controller->idx); controller->idx);
return -1; 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; return 0;
} }
...@@ -9398,27 +9420,13 @@ virDomainControllerDefParseXML(xmlNodePtr node, ...@@ -9398,27 +9420,13 @@ virDomainControllerDefParseXML(xmlNodePtr node,
} }
if (targetIndex) { if (targetIndex) {
if (virStrToLong_i(targetIndex, NULL, 0, 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, virReportError(VIR_ERR_XML_ERROR,
_("Invalid target index '%s' in PCI controller"), _("Invalid target index '%s' in PCI controller"),
targetIndex); targetIndex);
goto error; 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 (numaNode >= 0) {
if (def->idx == 0) { if (def->idx == 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册