]> xenbits.xensource.com Git - libvirt.git/commitdiff
src/xenxs: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 7 Mar 2014 08:33:31 +0000 (09:33 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Mar 2014 12:45:11 +0000 (13:45 +0100)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/xenxs/xen_sxpr.c
src/xenxs/xen_xm.c

index d366b1bf49c7e7e2340ed6aacea2adb5384d7a98..1319c740a47d5010162528ec20c97b7548940043 100644 (file)
@@ -601,10 +601,9 @@ xenParseSxprNets(virDomainDefPtr def,
                 VIR_STRDUP(net->model, "netfront") < 0)
                 goto cleanup;
 
-            if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0)
+            if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0)
                 goto cleanup;
 
-            def->nets[def->nnets++] = net;
             vif_index++;
         }
     }
@@ -685,12 +684,11 @@ xenParseSxprSound(virDomainDefPtr def,
                 goto error;
             }
 
-            if (VIR_REALLOC_N(def->sounds, def->nsounds+1) < 0) {
+            if (VIR_APPEND_ELEMENT(def->sounds, def->nsounds, sound) < 0) {
                 virDomainSoundDefFree(sound);
                 goto error;
             }
 
-            def->sounds[def->nsounds++] = sound;
             offset = offset2 ? offset2 + 1 : NULL;
         } while (offset);
     }
@@ -1057,10 +1055,8 @@ xenParseSxprPCI(virDomainDefPtr def,
         dev->source.subsys.u.pci.addr.slot = slotID;
         dev->source.subsys.u.pci.addr.function = funcID;
 
-        if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0)
+        if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, dev) < 0)
             goto error;
-
-        def->hostdevs[def->nhostdevs++] = dev;
     }
 
     return 0;
@@ -1326,11 +1322,10 @@ xenParseSxpr(const struct sexpr *root,
             disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
             disk->readonly = true;
 
-            if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
+            if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) {
                 virDomainDiskDefFree(disk);
                 goto error;
             }
-            def->disks[def->ndisks++] = disk;
         }
     }
 
@@ -1361,11 +1356,10 @@ xenParseSxpr(const struct sexpr *root,
                 }
                 disk->bus = VIR_DOMAIN_DISK_BUS_FDC;
 
-                if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
+                if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) {
                     virDomainDiskDefFree(disk);
                     goto error;
                 }
-                def->disks[def->ndisks++] = disk;
             }
         }
     }
@@ -1395,13 +1389,12 @@ xenParseSxpr(const struct sexpr *root,
                         virDomainChrDefPtr chr;
                         if ((chr = xenParseSxprChar(tmp, tty)) == NULL)
                             goto error;
-                        if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) {
+                        chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
+                        chr->target.port = def->nserials + ports_skipped;
+                        if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) {
                             virDomainChrDefFree(chr);
                             goto error;
                         }
-                        chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
-                        chr->target.port = def->nserials + ports_skipped;
-                        def->serials[def->nserials++] = chr;
                     }
                     else
                         ports_skipped++;
@@ -1417,13 +1410,12 @@ xenParseSxpr(const struct sexpr *root,
                 virDomainChrDefPtr chr;
                 if ((chr = xenParseSxprChar(tmp, tty)) == NULL)
                     goto error;
-                if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) {
+                chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
+                chr->target.port = 0;
+                if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) {
                     virDomainChrDefFree(chr);
                     goto error;
                 }
-                chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
-                chr->target.port = 0;
-                def->serials[def->nserials++] = chr;
             }
         }
 
@@ -1433,13 +1425,12 @@ xenParseSxpr(const struct sexpr *root,
             /* XXX does XenD stuff parallel port tty info into xenstore somewhere ? */
             if ((chr = xenParseSxprChar(tmp, NULL)) == NULL)
                 goto error;
-            if (VIR_REALLOC_N(def->parallels, def->nparallels+1) < 0) {
+            chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
+            chr->target.port = 0;
+            if (VIR_APPEND_ELEMENT(def->parallels, def->nparallels, chr) < 0) {
                 virDomainChrDefFree(chr);
                 goto error;
             }
-            chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
-            chr->target.port = 0;
-            def->parallels[def->nparallels++] = chr;
         }
     } else if (def->id != 0) {
         if (VIR_ALLOC_N(def->consoles, 1) < 0)
index 3a57547d92a98e23460138a7bd24bd702fdfe40c..a70c5e3972566f3ba643a8212f54b9f8b9214a75 100644 (file)
@@ -608,10 +608,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
                 disk->shared = true;
 
             /* Maintain list in sorted order according to target device name */
-            if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
+            if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
                 goto cleanup;
-            def->disks[def->ndisks++] = disk;
-            disk = NULL;
 
             skipdisk:
             list = list->next;
@@ -637,10 +635,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
             disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
             disk->readonly = true;
 
-            if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
+            if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
                 goto cleanup;
-            def->disks[def->ndisks++] = disk;
-            disk = NULL;
         }
     }
 
@@ -778,10 +774,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
                 VIR_STRDUP(net->ifname, vifname) < 0)
                 goto cleanup;
 
-            if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0)
+            if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0)
                 goto cleanup;
-            def->nets[def->nnets++] = net;
-            net = NULL;
 
         skipnic:
             list = list->next;
@@ -869,12 +863,10 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
             hostdev->source.subsys.u.pci.addr.slot = slotID;
             hostdev->source.subsys.u.pci.addr.function = funcID;
 
-            if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) {
+            if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) {
                 virDomainHostdevDefFree(hostdev);
                 goto cleanup;
             }
-            def->hostdevs[def->nhostdevs++] = hostdev;
-            hostdev = NULL;
 
         skippci:
             list = list->next;
@@ -1084,16 +1076,13 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
                 if (!(chr = xenParseSxprChar(port, NULL)))
                     goto cleanup;
 
-                if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) {
-                    virDomainChrDefFree(chr);
-                    goto cleanup;
-                }
-
                 chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
                 chr->target.port = portnum;
 
-                def->serials[def->nserials++] = chr;
-                chr = NULL;
+                if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) {
+                    virDomainChrDefFree(chr);
+                    goto cleanup;
+                }
 
                 list = list->next;
             }