[PATCH 2/4] conf: domain: Introduce virDomainDeviceInfoIterate flags

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

 



One of the usages of the device iterator is to run config validation.
That's a problem for graphics devices, because they don't have any @info
data (graphics shouldn't have been considered as devices in the first
place), and simply passing NULL would crash a few callbacks invoked from
the iterator. Fix this problem by introducing iterator flags.

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b70dca6c61..11552bff5b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3703,10 +3703,18 @@ virDomainSkipBackcompatConsole(virDomainDefPtr def,
 }
 
 
+typedef enum {
+    DEVICE_INFO_ITERATE_ALL_CONSOLES = 1 << 0, /* Iterate console[0] */
+} virDomainDeviceInfoIterateFlags;
+
+/*
+ * Iterates over domain devices which provide virDomainDeviceInfo data. The
+ * default behaviour can be altered with virDomainDeviceInfoIterateFlags.
+ */
 static int
 virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
                                    virDomainDeviceInfoCallback cb,
-                                   bool all,
+                                   unsigned int iteratorFlags,
                                    void *opaque)
 {
     size_t i;
@@ -3772,6 +3780,8 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
             return rc;
     }
     for (i = 0; i < def->nconsoles; i++) {
+        bool all = iteratorFlags & DEVICE_INFO_ITERATE_ALL_CONSOLES;
+
         if (virDomainSkipBackcompatConsole(def, i, all))
             continue;
         device.data.chr = def->consoles[i];
@@ -3908,7 +3918,7 @@ virDomainDeviceInfoIterate(virDomainDefPtr def,
                            virDomainDeviceInfoCallback cb,
                            void *opaque)
 {
-    return virDomainDeviceInfoIterateInternal(def, cb, false, opaque);
+    return virDomainDeviceInfoIterateInternal(def, cb, 0, opaque);
 }
 
 
@@ -3918,7 +3928,7 @@ virDomainDefHasDeviceAddress(virDomainDefPtr def,
 {
     if (virDomainDeviceInfoIterateInternal(def,
                                            virDomainDefHasDeviceAddressIterator,
-                                           true,
+                                           DEVICE_INFO_ITERATE_ALL_CONSOLES,
                                            info) < 0)
         return true;
 
@@ -5291,7 +5301,7 @@ virDomainDefPostParse(virDomainDefPtr def,
     /* iterate the devices */
     ret = virDomainDeviceInfoIterateInternal(def,
                                              virDomainDefPostParseDeviceIterator,
-                                             true,
+                                             DEVICE_INFO_ITERATE_ALL_CONSOLES,
                                              &data);
 
     if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0)
@@ -5927,7 +5937,8 @@ virDomainDefValidateAliases(const virDomainDef *def,
 
     if (virDomainDeviceInfoIterateInternal((virDomainDefPtr) def,
                                            virDomainDeviceDefValidateAliasesIterator,
-                                           true, &data) < 0)
+                                           DEVICE_INFO_ITERATE_ALL_CONSOLES,
+                                           &data) < 0)
         goto cleanup;
 
     if (aliases) {
@@ -6337,7 +6348,8 @@ virDomainDefValidate(virDomainDefPtr def,
     /* iterate the devices */
     if (virDomainDeviceInfoIterateInternal(def,
                                            virDomainDefValidateDeviceIterator,
-                                           true, &data) < 0)
+                                           DEVICE_INFO_ITERATE_ALL_CONSOLES,
+                                           &data) < 0)
         return -1;
 
     if (virDomainDefValidateInternal(def) < 0)
@@ -29926,7 +29938,8 @@ virDomainDefFindDevice(virDomainDefPtr def,
 
     dev->type = VIR_DOMAIN_DEVICE_NONE;
     virDomainDeviceInfoIterateInternal(def, virDomainDefFindDeviceCallback,
-                                       true, &data);
+                                       DEVICE_INFO_ITERATE_ALL_CONSOLES,
+                                       &data);
 
     if (dev->type == VIR_DOMAIN_DEVICE_NONE) {
         if (reportError) {
-- 
2.19.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]

  Powered by Linux