提交 577ccd07 编写于 作者: P Peter Krempa

qemu: domain: Despaghettify qemuDomainDeviceDefValidate

Move network device validation into a separate function.
上级 8ffdeed4
...@@ -3589,101 +3589,111 @@ qemuDomainWatchdogDefValidate(const virDomainWatchdogDef *dev, ...@@ -3589,101 +3589,111 @@ qemuDomainWatchdogDefValidate(const virDomainWatchdogDef *dev,
static int static int
qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev, qemuDomainDeviceDefValidateNetwork(const virDomainNetDef *net)
const virDomainDef *def,
void *opaque ATTRIBUTE_UNUSED)
{ {
int ret = -1; bool hasIPv4 = false;
bool hasIPv6 = false;
size_t i; size_t i;
if (dev->type == VIR_DOMAIN_DEVICE_NET) { if (net->type == VIR_DOMAIN_NET_TYPE_USER) {
const virDomainNetDef *net = dev->data.net; if (net->guestIP.nroutes) {
bool hasIPv4 = false, hasIPv6 = false; virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid attempt to set network interface "
"guest-side IP route, not supported by QEMU"));
return -1;
}
if (net->type == VIR_DOMAIN_NET_TYPE_USER) { for (i = 0; i < net->guestIP.nips; i++) {
if (net->guestIP.nroutes) { const virNetDevIPAddr *ip = net->guestIP.ips[i];
if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid attempt to set network interface " _("Invalid attempt to set peer IP for guest"));
"guest-side IP route, not supported by QEMU")); return -1;
goto cleanup;
} }
for (i = 0; i < net->guestIP.nips; i++) { if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) {
const virNetDevIPAddr *ip = net->guestIP.ips[i]; if (hasIPv4) {
if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid attempt to set peer IP for guest")); _("Only one IPv4 address per "
goto cleanup; "interface is allowed"));
return -1;
} }
hasIPv4 = true;
if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) { if (ip->prefix > 27) {
if (hasIPv4) { virReportError(VIR_ERR_XML_ERROR, "%s",
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("prefix too long"));
_("Only one IPv4 address per " return -1;
"interface is allowed"));
goto cleanup;
}
hasIPv4 = true;
if (ip->prefix > 27) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("prefix too long"));
goto cleanup;
}
} }
}
if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) { if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET6)) {
if (hasIPv6) { if (hasIPv6) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Only one IPv6 address per " _("Only one IPv6 address per "
"interface is allowed")); "interface is allowed"));
goto cleanup; return -1;
} }
hasIPv6 = true; hasIPv6 = true;
if (ip->prefix > 120) { if (ip->prefix > 120) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("prefix too long")); _("prefix too long"));
goto cleanup; return -1;
}
} }
} }
} else if (net->guestIP.nroutes || net->guestIP.nips) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid attempt to set network interface "
"guest-side IP route and/or address info, "
"not supported by QEMU"));
goto cleanup;
} }
} else if (net->guestIP.nroutes || net->guestIP.nips) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid attempt to set network interface "
"guest-side IP route and/or address info, "
"not supported by QEMU"));
return -1;
}
if (STREQ_NULLABLE(net->model, "virtio")) { if (STREQ_NULLABLE(net->model, "virtio")) {
if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) { if (net->driver.virtio.rx_queue_size & (net->driver.virtio.rx_queue_size - 1)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("rx_queue_size has to be a power of two")); _("rx_queue_size has to be a power of two"));
goto cleanup; return -1;
}
if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queue_size - 1)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("tx_queue_size has to be a power of two"));
goto cleanup;
}
} }
if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queue_size - 1)) {
if (net->mtu && virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
!qemuDomainNetSupportsMTU(net->type)) { _("tx_queue_size has to be a power of two"));
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, return -1;
_("setting MTU on interface type %s is not supported yet"),
virDomainNetTypeToString(net->type));
goto cleanup;
} }
}
if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) { if (net->mtu &&
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, !qemuDomainNetSupportsMTU(net->type)) {
_("coalesce settings on interface type %s are not supported"), virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
virDomainNetTypeToString(net->type)); _("setting MTU on interface type %s is not supported yet"),
virDomainNetTypeToString(net->type));
return -1;
}
if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("coalesce settings on interface type %s are not supported"),
virDomainNetTypeToString(net->type));
return -1;
}
return 0;
}
static int
qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
const virDomainDef *def,
void *opaque ATTRIBUTE_UNUSED)
{
int ret = -1;
if (dev->type == VIR_DOMAIN_DEVICE_NET) {
if (qemuDomainDeviceDefValidateNetwork(dev->data.net) < 0)
goto cleanup; goto cleanup;
}
} else if (dev->type == VIR_DOMAIN_DEVICE_CHR) { } else if (dev->type == VIR_DOMAIN_DEVICE_CHR) {
if (qemuDomainChrDefValidate(dev->data.chr, def) < 0) if (qemuDomainChrDefValidate(dev->data.chr, def) < 0)
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册