src/xenxs: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2014-03-07 09:33:31 +01:00
parent ce17ddacca
commit 17d6a91854
2 changed files with 22 additions and 42 deletions

View File

@ -601,10 +601,9 @@ xenParseSxprNets(virDomainDefPtr def,
VIR_STRDUP(net->model, "netfront") < 0) VIR_STRDUP(net->model, "netfront") < 0)
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0)
goto cleanup; goto cleanup;
def->nets[def->nnets++] = net;
vif_index++; vif_index++;
} }
} }
@ -685,12 +684,11 @@ xenParseSxprSound(virDomainDefPtr def,
goto error; goto error;
} }
if (VIR_REALLOC_N(def->sounds, def->nsounds+1) < 0) { if (VIR_APPEND_ELEMENT(def->sounds, def->nsounds, sound) < 0) {
virDomainSoundDefFree(sound); virDomainSoundDefFree(sound);
goto error; goto error;
} }
def->sounds[def->nsounds++] = sound;
offset = offset2 ? offset2 + 1 : NULL; offset = offset2 ? offset2 + 1 : NULL;
} while (offset); } while (offset);
} }
@ -1057,10 +1055,8 @@ xenParseSxprPCI(virDomainDefPtr def,
dev->source.subsys.u.pci.addr.slot = slotID; dev->source.subsys.u.pci.addr.slot = slotID;
dev->source.subsys.u.pci.addr.function = funcID; 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; goto error;
def->hostdevs[def->nhostdevs++] = dev;
} }
return 0; return 0;
@ -1326,11 +1322,10 @@ xenParseSxpr(const struct sexpr *root,
disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
disk->readonly = true; 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); virDomainDiskDefFree(disk);
goto error; goto error;
} }
def->disks[def->ndisks++] = disk;
} }
} }
@ -1361,11 +1356,10 @@ xenParseSxpr(const struct sexpr *root,
} }
disk->bus = VIR_DOMAIN_DISK_BUS_FDC; 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); virDomainDiskDefFree(disk);
goto error; goto error;
} }
def->disks[def->ndisks++] = disk;
} }
} }
} }
@ -1395,13 +1389,12 @@ xenParseSxpr(const struct sexpr *root,
virDomainChrDefPtr chr; virDomainChrDefPtr chr;
if ((chr = xenParseSxprChar(tmp, tty)) == NULL) if ((chr = xenParseSxprChar(tmp, tty)) == NULL)
goto error; 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); virDomainChrDefFree(chr);
goto error; goto error;
} }
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
chr->target.port = def->nserials + ports_skipped;
def->serials[def->nserials++] = chr;
} }
else else
ports_skipped++; ports_skipped++;
@ -1417,13 +1410,12 @@ xenParseSxpr(const struct sexpr *root,
virDomainChrDefPtr chr; virDomainChrDefPtr chr;
if ((chr = xenParseSxprChar(tmp, tty)) == NULL) if ((chr = xenParseSxprChar(tmp, tty)) == NULL)
goto error; 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); virDomainChrDefFree(chr);
goto error; 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 ? */ /* XXX does XenD stuff parallel port tty info into xenstore somewhere ? */
if ((chr = xenParseSxprChar(tmp, NULL)) == NULL) if ((chr = xenParseSxprChar(tmp, NULL)) == NULL)
goto error; 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); virDomainChrDefFree(chr);
goto error; goto error;
} }
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
chr->target.port = 0;
def->parallels[def->nparallels++] = chr;
} }
} else if (def->id != 0) { } else if (def->id != 0) {
if (VIR_ALLOC_N(def->consoles, 1) < 0) if (VIR_ALLOC_N(def->consoles, 1) < 0)

View File

@ -608,10 +608,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
disk->shared = true; disk->shared = true;
/* Maintain list in sorted order according to target device name */ /* 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; goto cleanup;
def->disks[def->ndisks++] = disk;
disk = NULL;
skipdisk: skipdisk:
list = list->next; list = list->next;
@ -637,10 +635,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
disk->readonly = true; 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; goto cleanup;
def->disks[def->ndisks++] = disk;
disk = NULL;
} }
} }
@ -778,10 +774,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
VIR_STRDUP(net->ifname, vifname) < 0) VIR_STRDUP(net->ifname, vifname) < 0)
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0)
goto cleanup; goto cleanup;
def->nets[def->nnets++] = net;
net = NULL;
skipnic: skipnic:
list = list->next; 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.slot = slotID;
hostdev->source.subsys.u.pci.addr.function = funcID; 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); virDomainHostdevDefFree(hostdev);
goto cleanup; goto cleanup;
} }
def->hostdevs[def->nhostdevs++] = hostdev;
hostdev = NULL;
skippci: skippci:
list = list->next; list = list->next;
@ -1084,16 +1076,13 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (!(chr = xenParseSxprChar(port, NULL))) if (!(chr = xenParseSxprChar(port, NULL)))
goto cleanup; 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->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
chr->target.port = portnum; chr->target.port = portnum;
def->serials[def->nserials++] = chr; if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) {
chr = NULL; virDomainChrDefFree(chr);
goto cleanup;
}
list = list->next; list = list->next;
} }