[PATCH 6/6] conf: Add validation infrastructure for device hot/cold plug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Similarly to domain definition it would be possible to introduce
invalid config via device coldplug. Add a similar infrastructure to do
the checking.
---
 src/conf/domain_conf.c   | 52 +++++++++++++++++++++++++++++++++++++++++++++---
 src/conf/domain_conf.h   |  3 +++
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_domain.c   | 11 ++++++++++
 src/qemu/qemu_domain.h   |  3 +++
 src/qemu/qemu_driver.c   |  3 +++
 6 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2beb825..3a809d4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -24366,9 +24366,54 @@ virDomainDiskDefValidate(const virDomainDiskDef *disk)
 }


-#define VIR_DOMAIN_DEF_VALIDATE_DEVICES(dev, func)                             \
+/**
+ * virDomainDeviceDefValidate:
+ * @def: domain definition
+ * @dev: device definition
+ *
+ */
+int
+virDomainDeviceDefValidate(const virDomainDef *def ATTRIBUTE_UNUSED,
+                           const virDomainDeviceDef *dev)
+{
+    switch ((virDomainDeviceType) dev->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        return virDomainDiskDefValidate(dev->data.disk);
+    case VIR_DOMAIN_DEVICE_LEASE:
+    case VIR_DOMAIN_DEVICE_FS:
+    case VIR_DOMAIN_DEVICE_NET:
+    case VIR_DOMAIN_DEVICE_INPUT:
+    case VIR_DOMAIN_DEVICE_SOUND:
+    case VIR_DOMAIN_DEVICE_VIDEO:
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+    case VIR_DOMAIN_DEVICE_HUB:
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_CHR:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_NVRAM:
+    case VIR_DOMAIN_DEVICE_RNG:
+    case VIR_DOMAIN_DEVICE_SHMEM:
+    case VIR_DOMAIN_DEVICE_TPM:
+    case VIR_DOMAIN_DEVICE_PANIC:
+    case VIR_DOMAIN_DEVICE_MEMORY:
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_LAST:
+        break;
+    }
+
+    return 0;
+}
+
+
+#define VIR_DOMAIN_DEF_VALIDATE_DEVICES(dev, devtype)                          \
+    device.type = devtype;                                                     \
     for (i = 0; i < def->n ## dev ## s; i++) {                                 \
-        if (func(def->dev ## s[i]) < 0)                                        \
+        device.data.dev = def->dev ## s[i];                                    \
+        if (virDomainDeviceDefValidate(def, &device) < 0)                      \
             return -1;                                                         \
     }

@@ -24388,9 +24433,10 @@ int
 virDomainDefValidate(const virDomainDef *def)
 {
     size_t i;
+    virDomainDeviceDef device;

     /* check configuration of individual devices */
-    VIR_DOMAIN_DEF_VALIDATE_DEVICES(disk, virDomainDiskDefValidate);
+    VIR_DOMAIN_DEF_VALIDATE_DEVICES(disk, VIR_DOMAIN_DEVICE_DISK);

     if (virDomainDefCheckDuplicateDiskInfo(def) < 0)
         return -1;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3c219ea..8f40feb 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3176,6 +3176,9 @@ bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1);

 char *virDomainObjGetShortName(virDomainObjPtr vm);

+int virDomainDeviceDefValidate(const virDomainDef *def,
+                               const virDomainDeviceDef *dev);
+
 int virDomainDefValidate(const virDomainDef *def);

 #endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 99975ed..08d8f54 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -249,6 +249,7 @@ virDomainDeviceAddressTypeToString;
 virDomainDeviceDefCopy;
 virDomainDeviceDefFree;
 virDomainDeviceDefParse;
+virDomainDeviceDefValidate;
 virDomainDeviceFindControllerModel;
 virDomainDeviceGetInfo;
 virDomainDeviceInfoCopy;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f172d6f..58bd412 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5345,6 +5345,17 @@ qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
 }


+int
+qemuDomainDeviceDefValidate(const virDomainDef *def,
+                            const virDomainDeviceDef *dev)
+{
+    if (virDomainDeviceDefValidate(def, dev) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 /**
  * qemuDomainDefValidate:
  * @def: domain definition
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index baf8bd8..aee38c6 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -667,6 +667,9 @@ void qemuDomainSecretDestroy(virDomainObjPtr vm)
 int qemuDomainSecretPrepare(virConnectPtr conn, virDomainObjPtr vm)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

+int qemuDomainDeviceDefValidate(const virDomainDef *def,
+                                const virDomainDeviceDef *dev);
+
 int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
     ATTRIBUTE_NONNULL(1);

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e6d22ec..fd2c0be 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8248,6 +8248,9 @@ qemuDomainAttachDeviceFlags(virDomainPtr dom,
     if (dev == NULL)
         goto endjob;

+    if (qemuDomainDeviceDefValidate(vm->def, dev) < 0)
+        goto endjob;
+
     if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
         flags & VIR_DOMAIN_AFFECT_LIVE) {
         /* If we are affecting both CONFIG and LIVE
-- 
2.8.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]