|
|
c1c534 |
From 2d801f20547584950c0b312e5d6fbc975d65868e Mon Sep 17 00:00:00 2001
|
|
|
c1c534 |
Message-Id: <2d801f20547584950c0b312e5d6fbc975d65868e@dist-git>
|
|
|
c1c534 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
c1c534 |
Date: Thu, 23 Nov 2017 19:02:17 +0100
|
|
|
c1c534 |
Subject: [PATCH] qemu: domain: Refactor domain device validation function
|
|
|
c1c534 |
|
|
|
c1c534 |
Use a style that will discourage from adding inline checks.
|
|
|
c1c534 |
|
|
|
c1c534 |
(cherry picked from commit 85b0e2f1260bb169298db5b44859be48426821f0)
|
|
|
c1c534 |
|
|
|
c1c534 |
https://bugzilla.redhat.com/show_bug.cgi?id=1511480
|
|
|
c1c534 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
c1c534 |
---
|
|
|
c1c534 |
src/qemu/qemu_domain.c | 79 +++++++++++++++++++++++++++++++++-----------------
|
|
|
c1c534 |
1 file changed, 52 insertions(+), 27 deletions(-)
|
|
|
c1c534 |
|
|
|
c1c534 |
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
|
|
|
c1c534 |
index 1b72d95d7e..1159be9980 100644
|
|
|
c1c534 |
--- a/src/qemu/qemu_domain.c
|
|
|
c1c534 |
+++ b/src/qemu/qemu_domain.c
|
|
|
c1c534 |
@@ -3694,36 +3694,61 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
|
|
c1c534 |
const virDomainDef *def,
|
|
|
c1c534 |
void *opaque ATTRIBUTE_UNUSED)
|
|
|
c1c534 |
{
|
|
|
c1c534 |
- int ret = -1;
|
|
|
c1c534 |
+ int ret = 0;
|
|
|
c1c534 |
|
|
|
c1c534 |
- if (dev->type == VIR_DOMAIN_DEVICE_NET) {
|
|
|
c1c534 |
- if (qemuDomainDeviceDefValidateNetwork(dev->data.net) < 0)
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- } else if (dev->type == VIR_DOMAIN_DEVICE_CHR) {
|
|
|
c1c534 |
- if (qemuDomainChrDefValidate(dev->data.chr, def) < 0)
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- } else if (dev->type == VIR_DOMAIN_DEVICE_SMARTCARD) {
|
|
|
c1c534 |
- if (qemuDomainSmartcardDefValidate(dev->data.smartcard) < 0)
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- } else if (dev->type == VIR_DOMAIN_DEVICE_RNG) {
|
|
|
c1c534 |
- if (qemuDomainRNGDefValidate(dev->data.rng) < 0)
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- } else if (dev->type == VIR_DOMAIN_DEVICE_REDIRDEV) {
|
|
|
c1c534 |
- if (qemuDomainRedirdevDefValidate(dev->data.redirdev) < 0)
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- } else if (dev->type == VIR_DOMAIN_DEVICE_WATCHDOG) {
|
|
|
c1c534 |
- if (qemuDomainWatchdogDefValidate(dev->data.watchdog, def) < 0)
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
|
|
|
c1c534 |
- if (qemuDomainDeviceDefValidateHostdev(dev->data.hostdev, def) < 0)
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
- } else if (dev->type == VIR_DOMAIN_DEVICE_VIDEO) {
|
|
|
c1c534 |
- if (qemuDomainDeviceDefValidateVideo(dev->data.video) < 0)
|
|
|
c1c534 |
- goto cleanup;
|
|
|
c1c534 |
+ switch ((virDomainDeviceType) dev->type) {
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_NET:
|
|
|
c1c534 |
+ ret = qemuDomainDeviceDefValidateNetwork(dev->data.net);
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_CHR:
|
|
|
c1c534 |
+ ret = qemuDomainChrDefValidate(dev->data.chr, def);
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_SMARTCARD:
|
|
|
c1c534 |
+ ret = qemuDomainSmartcardDefValidate(dev->data.smartcard);
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_RNG:
|
|
|
c1c534 |
+ ret = qemuDomainRNGDefValidate(dev->data.rng);
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_REDIRDEV:
|
|
|
c1c534 |
+ ret = qemuDomainRedirdevDefValidate(dev->data.redirdev);
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_WATCHDOG:
|
|
|
c1c534 |
+ ret = qemuDomainWatchdogDefValidate(dev->data.watchdog, def);
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_HOSTDEV:
|
|
|
c1c534 |
+ ret = qemuDomainDeviceDefValidateHostdev(dev->data.hostdev, def);
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_VIDEO:
|
|
|
c1c534 |
+ ret = qemuDomainDeviceDefValidateVideo(dev->data.video);
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
+
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_DISK:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_LEASE:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_FS:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_INPUT:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_SOUND:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_CONTROLLER:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_GRAPHICS:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_HUB:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_MEMBALLOON:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_NVRAM:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_SHMEM:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_TPM:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_PANIC:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_MEMORY:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_IOMMU:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_NONE:
|
|
|
c1c534 |
+ case VIR_DOMAIN_DEVICE_LAST:
|
|
|
c1c534 |
+ break;
|
|
|
c1c534 |
}
|
|
|
c1c534 |
|
|
|
c1c534 |
- ret = 0;
|
|
|
c1c534 |
- cleanup:
|
|
|
c1c534 |
return ret;
|
|
|
c1c534 |
}
|
|
|
c1c534 |
|
|
|
c1c534 |
--
|
|
|
c1c534 |
2.15.0
|
|
|
c1c534 |
|