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

[libvirt] [PATCH v2 07/11] conf: add model attribute to virDomainDefMaybeAddController



---
 src/conf/domain_conf.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 548368e..cf0f1c4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9747,21 +9747,18 @@ virDomainLookupVcpuPin(virDomainDefPtr def,
 
 static int virDomainDefMaybeAddController(virDomainDefPtr def,
                                           int type,
-                                          int idx)
+                                          int idx,
+                                          int model)
 {
-    int found = 0;
     int i;
     virDomainControllerDefPtr cont;
 
-    for (i = 0 ; (i < def->ncontrollers) && !found; i++) {
+    for (i = 0; i < def->ncontrollers; i++) {
         if (def->controllers[i]->type == type &&
             def->controllers[i]->idx == idx)
-            found = 1;
+            return 0;
     }
 
-    if (found)
-        return 0;
-
     if (VIR_ALLOC(cont) < 0) {
         virReportOOMError();
         return -1;
@@ -9769,21 +9766,17 @@ static int virDomainDefMaybeAddController(virDomainDefPtr def,
 
     cont->type = type;
     cont->idx = idx;
-    cont->model = -1;
+    cont->model = model;
 
     if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL) {
         cont->opts.vioserial.ports = -1;
         cont->opts.vioserial.vectors = -1;
     }
 
-
-    if (VIR_REALLOC_N(def->controllers, def->ncontrollers+1) < 0) {
+    if (VIR_APPEND_ELEMENT(def->controllers, def->ncontrollers, cont) < 0) {
         VIR_FREE(cont);
-        virReportOOMError();
         return -1;
     }
-    def->controllers[def->ncontrollers] = cont;
-    def->ncontrollers++;
 
     return 0;
 }
@@ -10839,7 +10832,7 @@ virDomainDefParseXML(xmlDocPtr xml,
     if (def->virtType == VIR_DOMAIN_VIRT_QEMU ||
         def->virtType == VIR_DOMAIN_VIRT_KQEMU ||
         def->virtType == VIR_DOMAIN_VIRT_KVM)
-        if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_USB, 0) < 0)
+        if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_USB, 0, -1) < 0)
             goto error;
 
     /* analysis of the resource leases */
@@ -12718,7 +12711,7 @@ virDomainDefAddDiskControllersForType(virDomainDefPtr def,
     }
 
     for (i = 0 ; i <= maxController ; i++) {
-        if (virDomainDefMaybeAddController(def, controllerType, i) < 0)
+        if (virDomainDefMaybeAddController(def, controllerType, i, -1) < 0)
             return -1;
     }
 
@@ -12741,7 +12734,7 @@ virDomainDefMaybeAddVirtioSerialController(virDomainDefPtr def)
                 idx = channel->info.addr.vioserial.controller;
 
             if (virDomainDefMaybeAddController(def,
-                VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, idx) < 0)
+                VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, idx, -1) < 0)
                 return -1;
         }
     }
@@ -12756,7 +12749,7 @@ virDomainDefMaybeAddVirtioSerialController(virDomainDefPtr def)
                 idx = console->info.addr.vioserial.controller;
 
             if (virDomainDefMaybeAddController(def,
-                VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, idx) < 0)
+                VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL, idx, -1) < 0)
                 return -1;
         }
     }
@@ -12796,7 +12789,7 @@ virDomainDefMaybeAddSmartcardController(virDomainDefPtr def)
 
         if (virDomainDefMaybeAddController(def,
                                            VIR_DOMAIN_CONTROLLER_TYPE_CCID,
-                                           idx) < 0)
+                                           idx, -1) < 0)
             return -1;
     }
 
-- 
1.8.1.5


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