1
0

qemu: domain: Despaghettify qemuDomainDeviceDefValidate

Move network device validation into a separate function.
This commit is contained in:
Peter Krempa 2017-11-14 14:33:19 +01:00
parent 8ffdeed455
commit 577ccd07c3

View File

@ -3589,23 +3589,18 @@ 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) {
const virDomainNetDef *net = dev->data.net;
bool hasIPv4 = false, hasIPv6 = false;
if (net->type == VIR_DOMAIN_NET_TYPE_USER) { if (net->type == VIR_DOMAIN_NET_TYPE_USER) {
if (net->guestIP.nroutes) { if (net->guestIP.nroutes) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid attempt to set network interface " _("Invalid attempt to set network interface "
"guest-side IP route, not supported by QEMU")); "guest-side IP route, not supported by QEMU"));
goto cleanup; return -1;
} }
for (i = 0; i < net->guestIP.nips; i++) { for (i = 0; i < net->guestIP.nips; i++) {
@ -3614,7 +3609,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
if (VIR_SOCKET_ADDR_VALID(&net->guestIP.ips[i]->peer)) { 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")); _("Invalid attempt to set peer IP for guest"));
goto cleanup; return -1;
} }
if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) { if (VIR_SOCKET_ADDR_IS_FAMILY(&ip->address, AF_INET)) {
@ -3622,14 +3617,14 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Only one IPv4 address per " _("Only one IPv4 address per "
"interface is allowed")); "interface is allowed"));
goto cleanup; return -1;
} }
hasIPv4 = true; hasIPv4 = true;
if (ip->prefix > 27) { if (ip->prefix > 27) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("prefix too long")); _("prefix too long"));
goto cleanup; return -1;
} }
} }
@ -3638,14 +3633,14 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
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;
} }
} }
} }
@ -3654,19 +3649,19 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
_("Invalid attempt to set network interface " _("Invalid attempt to set network interface "
"guest-side IP route and/or address info, " "guest-side IP route and/or address info, "
"not supported by QEMU")); "not supported by QEMU"));
goto cleanup; 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)) { if (net->driver.virtio.tx_queue_size & (net->driver.virtio.tx_queue_size - 1)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("tx_queue_size has to be a power of two")); _("tx_queue_size has to be a power of two"));
goto cleanup; return -1;
} }
} }
@ -3675,15 +3670,30 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("setting MTU on interface type %s is not supported yet"), _("setting MTU on interface type %s is not supported yet"),
virDomainNetTypeToString(net->type)); virDomainNetTypeToString(net->type));
goto cleanup; return -1;
} }
if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) { if (net->coalesce && !qemuDomainNetSupportsCoalesce(net->type)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("coalesce settings on interface type %s are not supported"), _("coalesce settings on interface type %s are not supported"),
virDomainNetTypeToString(net->type)); virDomainNetTypeToString(net->type));
goto cleanup; 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;
} 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;