Adapt to VIR_ALLOC and virAsprintf in src/xen/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:18:49 +02:00
parent ed11a1a43e
commit d582618e11
7 changed files with 42 additions and 116 deletions

View File

@ -114,10 +114,8 @@ read_bd_stat(int device, int domid, const char *str)
int64_t r; int64_t r;
for (i = 0; i < ARRAY_CARDINALITY(paths); ++i) { for (i = 0; i < ARRAY_CARDINALITY(paths); ++i) {
if (virAsprintf(&path, paths[i], domid, device, str) < 0) { if (virAsprintf(&path, paths[i], domid, device, str) < 0)
virReportOOMError();
return -1; return -1;
}
r = read_stat(path); r = read_stat(path);
@ -296,10 +294,8 @@ xenLinuxDomainDeviceID(int domid, const char *path)
if (VIR_STRDUP(mod_path, path) < 0) if (VIR_STRDUP(mod_path, path) < 0)
return -1; return -1;
} else { } else {
if (virAsprintf(&mod_path, "/dev/%s", path) < 0) { if (virAsprintf(&mod_path, "/dev/%s", path) < 0)
virReportOOMError();
return -1; return -1;
}
} }
retval = -1; retval = -1;

View File

@ -208,20 +208,14 @@ xenDomainUsedCpus(virDomainPtr dom)
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0) if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
return NULL; return NULL;
if (!(cpulist = virBitmapNew(priv->nbNodeCpus))) { if (!(cpulist = virBitmapNew(priv->nbNodeCpus)))
virReportOOMError();
goto done; goto done;
} if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0)
if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0) {
virReportOOMError();
goto done; goto done;
}
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo)); cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
if (xalloc_oversized(nb_vcpu, cpumaplen) || if (xalloc_oversized(nb_vcpu, cpumaplen) ||
VIR_ALLOC_N(cpumap, nb_vcpu * cpumaplen) < 0) { VIR_ALLOC_N(cpumap, nb_vcpu * cpumaplen) < 0)
virReportOOMError();
goto done; goto done;
}
if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu, if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu,
cpumap, cpumaplen)) >= 0) { cpumap, cpumaplen)) >= 0) {
@ -415,10 +409,8 @@ xenUnifiedConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int f
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
/* Allocate per-connection private data. */ /* Allocate per-connection private data. */
if (VIR_ALLOC(priv) < 0) { if (VIR_ALLOC(priv) < 0)
virReportOOMError();
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
}
if (virMutexInit(&priv->lock) < 0) { if (virMutexInit(&priv->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot initialize mutex")); "%s", _("cannot initialize mutex"));
@ -856,10 +848,8 @@ xenUnifiedDomainIsPersistent(virDomainPtr dom)
/* If its running there's no official way to tell, so we /* If its running there's no official way to tell, so we
* go behind xend's back & look at the config dir */ * go behind xend's back & look at the config dir */
virUUIDFormat(dom->uuid, uuidstr); virUUIDFormat(dom->uuid, uuidstr);
if (virAsprintf(&path, "%s/%s", XEND_DOMAINS_DIR, uuidstr) < 0) { if (virAsprintf(&path, "%s/%s", XEND_DOMAINS_DIR, uuidstr) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (access(path, R_OK) == 0) if (access(path, R_OK) == 0)
ret = 1; ret = 1;
else if (errno == ENOENT) else if (errno == ENOENT)
@ -1202,10 +1192,8 @@ xenUnifiedDomainManagedSavePath(xenUnifiedPrivatePtr priv,
{ {
char *ret; char *ret;
if (virAsprintf(&ret, "%s/%s.save", priv->saveDir, def->name) < 0) { if (virAsprintf(&ret, "%s/%s.save", priv->saveDir, def->name) < 0)
virReportOOMError();
return NULL; return NULL;
}
VIR_DEBUG("managed save image: %s", ret); VIR_DEBUG("managed save image: %s", ret);
return ret; return ret;
@ -1617,10 +1605,8 @@ xenUnifiedConnectDomainXMLToNative(virConnectPtr conn,
if (!conf) if (!conf)
goto cleanup; goto cleanup;
if (VIR_ALLOC_N(ret, len) < 0) { if (VIR_ALLOC_N(ret, len) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virConfWriteMem(ret, &len, conf) < 0) { if (virConfWriteMem(ret, &len, conf) < 0) {
VIR_FREE(ret); VIR_FREE(ret);
@ -2473,10 +2459,8 @@ xenUnifiedNodeDeviceAssignedDomainId(virNodeDevicePtr dev)
return ret; return ret;
} }
if (numdomains > 0){ if (numdomains > 0){
if (VIR_ALLOC_N(ids, numdomains) < 0) { if (VIR_ALLOC_N(ids, numdomains) < 0)
virReportOOMError();
goto out; goto out;
}
if ((numdomains = xenUnifiedConnectListDomains(conn, &ids[0], numdomains)) < 0) { if ((numdomains = xenUnifiedConnectListDomains(conn, &ids[0], numdomains)) < 0) {
goto out; goto out;
} }
@ -2487,10 +2471,8 @@ xenUnifiedNodeDeviceAssignedDomainId(virNodeDevicePtr dev)
goto out; goto out;
if (virAsprintf(&bdf, "%04x:%02x:%02x.%0x", if (virAsprintf(&bdf, "%04x:%02x:%02x.%0x",
domain, bus, slot, function) < 0) { domain, bus, slot, function) < 0)
virReportOOMError();
goto out; goto out;
}
xenUnifiedLock(priv); xenUnifiedLock(priv);
/* Check if bdf is assigned to one of active domains */ /* Check if bdf is assigned to one of active domains */
@ -2824,7 +2806,7 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list,
} }
if (VIR_ALLOC(info) < 0) if (VIR_ALLOC(info) < 0)
goto memory_error; goto error;
if (VIR_STRDUP(info->name, name) < 0) if (VIR_STRDUP(info->name, name) < 0)
goto error; goto error;
@ -2834,14 +2816,12 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list,
/* Make space on list */ /* Make space on list */
n = list->count; n = list->count;
if (VIR_REALLOC_N(list->doms, n + 1) < 0) { if (VIR_REALLOC_N(list->doms, n + 1) < 0) {
goto memory_error; goto error;
} }
list->doms[n] = info; list->doms[n] = info;
list->count++; list->count++;
return 0; return 0;
memory_error:
virReportOOMError();
error: error:
if (info) if (info)
VIR_FREE(info->name); VIR_FREE(info->name);

View File

@ -1509,10 +1509,8 @@ virXen_setvcpumap(int handle,
/* The allocated memory to cpumap must be 'sizeof(uint64_t)' byte * /* The allocated memory to cpumap must be 'sizeof(uint64_t)' byte *
* for Xen, and also nr_cpus must be 'sizeof(uint64_t) * 8' */ * for Xen, and also nr_cpus must be 'sizeof(uint64_t) * 8' */
if (maplen < 8) { if (maplen < 8) {
if (VIR_ALLOC_N(new, sizeof(uint64_t)) < 0) { if (VIR_ALLOC_N(new, sizeof(uint64_t)) < 0)
virReportOOMError();
return -1; return -1;
}
memcpy(new, cpumap, maplen); memcpy(new, cpumap, maplen);
bitmap = new; bitmap = new;
nr_cpus = sizeof(uint64_t) * 8; nr_cpus = sizeof(uint64_t) * 8;
@ -1829,10 +1827,8 @@ xenHypervisorInit(struct xenHypervisorVersions *override_versions)
*/ */
hv_versions.hypervisor = 2; hv_versions.hypervisor = 2;
if (VIR_ALLOC(ipt) < 0) { if (VIR_ALLOC(ipt) < 0)
virReportOOMError();
return -1; return -1;
}
/* Currently consider RHEL5.0 Fedora7, xen-3.1, and xen-unstable */ /* Currently consider RHEL5.0 Fedora7, xen-3.1, and xen-unstable */
hv_versions.sys_interface = 2; /* XEN_SYSCTL_INTERFACE_VERSION */ hv_versions.sys_interface = 2; /* XEN_SYSCTL_INTERFACE_VERSION */
if (virXen_getdomaininfo(fd, 0, &info) == 1) { if (virXen_getdomaininfo(fd, 0, &info) == 1) {
@ -2265,11 +2261,10 @@ xenHypervisorMakeCapabilitiesSunOS(virConnectPtr conn)
} }
} }
if ((caps = xenHypervisorBuildCapabilities(conn, caps = xenHypervisorBuildCapabilities(conn,
virArchFromHost(), virArchFromHost(),
pae, hvm, pae, hvm,
guest_arches, i)) == NULL) guest_arches, i);
virReportOOMError();
return caps; return caps;
} }
@ -2428,7 +2423,6 @@ xenHypervisorMakeCapabilitiesInternal(virConnectPtr conn,
return caps; return caps;
no_memory: no_memory:
virReportOOMError();
virObjectUnref(caps); virObjectUnref(caps);
return NULL; return NULL;
} }

View File

@ -360,10 +360,8 @@ xenInotifyOpen(virConnectPtr conn,
priv->configDir = XEND_DOMAINS_DIR; priv->configDir = XEND_DOMAINS_DIR;
priv->useXenConfigCache = 0; priv->useXenConfigCache = 0;
if (VIR_ALLOC(priv->configInfoList) < 0) { if (VIR_ALLOC(priv->configInfoList) < 0)
virReportOOMError();
return -1; return -1;
}
/* populate initial list */ /* populate initial list */
if (!(dh = opendir(priv->configDir))) { if (!(dh = opendir(priv->configDir))) {

View File

@ -283,10 +283,8 @@ xend_req(int fd, char **content)
int content_length = 0; int content_length = 0;
int retcode = 0; int retcode = 0;
if (VIR_ALLOC_N(buffer, buffer_size) < 0) { if (VIR_ALLOC_N(buffer, buffer_size) < 0)
virReportOOMError();
return -1; return -1;
}
while (sreads(fd, buffer, buffer_size) > 0) { while (sreads(fd, buffer, buffer_size) > 0) {
if (STREQ(buffer, "\r\n")) if (STREQ(buffer, "\r\n"))
@ -315,10 +313,8 @@ xend_req(int fd, char **content)
/* Allocate one byte beyond the end of the largest buffer we will read. /* Allocate one byte beyond the end of the largest buffer we will read.
Combined with the fact that VIR_ALLOC_N zeros the returned buffer, Combined with the fact that VIR_ALLOC_N zeros the returned buffer,
this guarantees that "content" will always be NUL-terminated. */ this guarantees that "content" will always be NUL-terminated. */
if (VIR_ALLOC_N(*content, content_length + 1) < 0) { if (VIR_ALLOC_N(*content, content_length + 1) < 0)
virReportOOMError();
return -1; return -1;
}
ret = sread(fd, *content, content_length); ret = sread(fd, *content, content_length);
if (ret < 0) if (ret < 0)
@ -762,10 +758,8 @@ xenDaemonListDomainsOld(virConnectPtr xend)
count++; count++;
} }
if (VIR_ALLOC_N(ret, count + 1) < 0) { if (VIR_ALLOC_N(ret, count + 1) < 0)
virReportOOMError();
goto error; goto error;
}
i = 0; i = 0;
for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS; for (_for_i = root, node = root->u.s.car; _for_i->kind == SEXPR_CONS;
@ -1073,7 +1067,7 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps)
if (STRPREFIX(cur, "no cpus")) { if (STRPREFIX(cur, "no cpus")) {
nb_cpus = 0; nb_cpus = 0;
if (!(cpuset = virBitmapNew(numCpus))) if (!(cpuset = virBitmapNew(numCpus)))
goto memory_error; goto error;
} else { } else {
nb_cpus = virBitmapParse(cur, 'n', &cpuset, numCpus); nb_cpus = virBitmapParse(cur, 'n', &cpuset, numCpus);
if (nb_cpus < 0) if (nb_cpus < 0)
@ -1082,7 +1076,7 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps)
if (VIR_ALLOC_N(cpuInfo, numCpus) < 0) { if (VIR_ALLOC_N(cpuInfo, numCpus) < 0) {
virBitmapFree(cpuset); virBitmapFree(cpuset);
goto memory_error; goto error;
} }
for (n = 0, cpu = 0; cpu < numCpus; cpu++) { for (n = 0, cpu = 0; cpu < numCpus; cpu++) {
@ -1095,7 +1089,7 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps)
virBitmapFree(cpuset); virBitmapFree(cpuset);
if (virCapabilitiesAddHostNUMACell(caps, cell, nb_cpus, 0, cpuInfo) < 0) if (virCapabilitiesAddHostNUMACell(caps, cell, nb_cpus, 0, cpuInfo) < 0)
goto memory_error; goto error;
cpuInfo = NULL; cpuInfo = NULL;
} }
@ -1107,10 +1101,6 @@ sexpr_to_xend_topology(const struct sexpr *root, virCapsPtr caps)
virCapabilitiesClearHostNUMACellCPUTopology(cpuInfo, nb_cpus); virCapabilitiesClearHostNUMACellCPUTopology(cpuInfo, nb_cpus);
VIR_FREE(cpuInfo); VIR_FREE(cpuInfo);
return -1; return -1;
memory_error:
virReportOOMError();
goto error;
} }
@ -1219,10 +1209,8 @@ xenDaemonOpen(virConnectPtr conn,
goto failed; goto failed;
} else if (STRCASEEQ(conn->uri->scheme, "http")) { } else if (STRCASEEQ(conn->uri->scheme, "http")) {
if (conn->uri->port && if (conn->uri->port &&
virAsprintf(&port, "%d", conn->uri->port) == -1) { virAsprintf(&port, "%d", conn->uri->port) == -1)
virReportOOMError();
goto failed; goto failed;
}
if (xenDaemonOpen_tcp(conn, if (xenDaemonOpen_tcp(conn,
conn->uri->server ? conn->uri->server : "localhost", conn->uri->server ? conn->uri->server : "localhost",
@ -1895,10 +1883,8 @@ xenDaemonDomainPinVcpu(virConnectPtr conn,
if (ret == 0) { if (ret == 0) {
if (!def->cputune.vcpupin) { if (!def->cputune.vcpupin) {
if (VIR_ALLOC(def->cputune.vcpupin) < 0) { if (VIR_ALLOC(def->cputune.vcpupin) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
def->cputune.nvcpupin = 0; def->cputune.nvcpupin = 0;
} }
if (virDomainVcpuPinAdd(&def->cputune.vcpupin, if (virDomainVcpuPinAdd(&def->cputune.vcpupin,
@ -2302,10 +2288,8 @@ xenDaemonAttachDeviceFlags(virConnectPtr conn,
PCIAddr = dev->data.hostdev->source.subsys.u.pci.addr; PCIAddr = dev->data.hostdev->source.subsys.u.pci.addr;
if (virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x", if (virAsprintf(&target, "PCI device: %.4x:%.2x:%.2x",
PCIAddr.domain, PCIAddr.bus, PCIAddr.slot) < 0) { PCIAddr.domain, PCIAddr.bus, PCIAddr.slot) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} else { } else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported device type")); _("unsupported device type"));
@ -3393,10 +3377,8 @@ virDomainXMLDevID(virConnectPtr conn,
hostdef->source.subsys.u.pci.addr.domain, hostdef->source.subsys.u.pci.addr.domain,
hostdef->source.subsys.u.pci.addr.bus, hostdef->source.subsys.u.pci.addr.bus,
hostdef->source.subsys.u.pci.addr.slot, hostdef->source.subsys.u.pci.addr.slot,
hostdef->source.subsys.u.pci.addr.function) < 0) { hostdef->source.subsys.u.pci.addr.function) < 0)
virReportOOMError();
return -1; return -1;
}
strcpy(class, "pci"); strcpy(class, "pci");

View File

@ -237,10 +237,8 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
entry->def = NULL; entry->def = NULL;
} else { /* Completely new entry */ } else { /* Completely new entry */
newborn = 1; newborn = 1;
if (VIR_ALLOC(entry) < 0) { if (VIR_ALLOC(entry) < 0)
virReportOOMError();
return -1; return -1;
}
if (VIR_STRDUP(entry->filename, filename) < 0) { if (VIR_STRDUP(entry->filename, filename) < 0) {
VIR_FREE(entry); VIR_FREE(entry);
return -1; return -1;
@ -1030,10 +1028,8 @@ xenXMDomainDefineXML(virConnectPtr conn, virDomainDefPtr def)
if (virConfWriteFile(filename, conf) < 0) if (virConfWriteFile(filename, conf) < 0)
goto error; goto error;
if (VIR_ALLOC(entry) < 0) { if (VIR_ALLOC(entry) < 0)
virReportOOMError();
goto error; goto error;
}
if ((entry->refreshedAt = time(NULL)) == ((time_t)-1)) { if ((entry->refreshedAt = time(NULL)) == ((time_t)-1)) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -1257,20 +1253,16 @@ xenXMDomainAttachDeviceFlags(virConnectPtr conn,
switch (dev->type) { switch (dev->type) {
case VIR_DOMAIN_DEVICE_DISK: case VIR_DOMAIN_DEVICE_DISK:
{ {
if (virDomainDiskInsert(def, dev->data.disk) < 0) { if (virDomainDiskInsert(def, dev->data.disk) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
dev->data.disk = NULL; dev->data.disk = NULL;
} }
break; break;
case VIR_DOMAIN_DEVICE_NET: case VIR_DOMAIN_DEVICE_NET:
{ {
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) { if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
def->nets[def->nnets++] = dev->data.net; def->nets[def->nnets++] = dev->data.net;
dev->data.net = NULL; dev->data.net = NULL;
break; break;
@ -1444,10 +1436,8 @@ xenXMDomainGetAutostart(virDomainDefPtr def,
char *config = xenXMDomainConfigName(def); char *config = xenXMDomainConfigName(def);
int ret = -1; int ret = -1;
if (!linkname || !config) { if (!linkname || !config)
virReportOOMError();
goto cleanup; goto cleanup;
}
*autostart = virFileLinkPointsTo(linkname, config); *autostart = virFileLinkPointsTo(linkname, config);
if (*autostart < 0) { if (*autostart < 0) {
@ -1474,10 +1464,8 @@ xenXMDomainSetAutostart(virDomainDefPtr def,
char *config = xenXMDomainConfigName(def); char *config = xenXMDomainConfigName(def);
int ret = -1; int ret = -1;
if (!linkname || !config) { if (!linkname || !config)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (autostart) { if (autostart) {
if (symlink(config, linkname) < 0 && if (symlink(config, linkname) < 0 &&

View File

@ -132,18 +132,14 @@ xenStoreOpen(virConnectPtr conn,
} }
/* Init activeDomainList */ /* Init activeDomainList */
if (VIR_ALLOC(priv->activeDomainList) < 0) { if (VIR_ALLOC(priv->activeDomainList) < 0)
virReportOOMError();
return -1; return -1;
}
/* Init watch list before filling in domInfoList, /* Init watch list before filling in domInfoList,
so we can know if it is the first time through so we can know if it is the first time through
when the callback fires */ when the callback fires */
if (VIR_ALLOC(priv->xsWatchList) < 0) { if (VIR_ALLOC(priv->xsWatchList) < 0)
virReportOOMError();
return -1; return -1;
}
/* This will get called once at start */ /* This will get called once at start */
if (xenStoreAddWatch(conn, "@releaseDomain", if (xenStoreAddWatch(conn, "@releaseDomain",
@ -656,10 +652,8 @@ xenStoreAddWatch(virConnectPtr conn,
} }
} }
if (VIR_ALLOC(watch) < 0) { if (VIR_ALLOC(watch) < 0)
virReportOOMError();
goto error; goto error;
}
watch->cb = cb; watch->cb = cb;
watch->opaque = opaque; watch->opaque = opaque;
@ -669,10 +663,8 @@ xenStoreAddWatch(virConnectPtr conn,
/* Make space on list */ /* Make space on list */
n = list->count; n = list->count;
if (VIR_REALLOC_N(list->watches, n + 1) < 0) { if (VIR_REALLOC_N(list->watches, n + 1) < 0)
virReportOOMError();
goto error; goto error;
}
list->watches[n] = watch; list->watches[n] = watch;
list->count++; list->count++;
@ -817,10 +809,8 @@ retry:
if (new_domain_cnt < 0) if (new_domain_cnt < 0)
return -1; return -1;
if (VIR_ALLOC_N(new_domids,new_domain_cnt) < 0) { if (VIR_ALLOC_N(new_domids,new_domain_cnt) < 0)
virReportOOMError();
return -1; return -1;
}
nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt); nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt);
if (nread != new_domain_cnt) { if (nread != new_domain_cnt) {
/* mismatch. retry this read */ /* mismatch. retry this read */
@ -901,10 +891,8 @@ retry:
if (new_domain_cnt < 0) if (new_domain_cnt < 0)
return -1; return -1;
if (VIR_ALLOC_N(new_domids,new_domain_cnt) < 0) { if (VIR_ALLOC_N(new_domids,new_domain_cnt) < 0)
virReportOOMError();
return -1; return -1;
}
nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt); nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt);
if (nread != new_domain_cnt) { if (nread != new_domain_cnt) {
/* mismatch. retry this read */ /* mismatch. retry this read */