Adapt to VIR_ALLOC and virAsprintf in src/parallels/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:13:24 +02:00
parent 4079aca089
commit f5a60ebdc3
5 changed files with 47 additions and 99 deletions

View File

@ -1486,8 +1486,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
cpus[id].core_id = c; cpus[id].core_id = c;
if (!(cpus[id].siblings = virBitmapNew(ncpus))) if (!(cpus[id].siblings = virBitmapNew(ncpus)))
goto error; goto error;
if (virBitmapSetBit(cpus[id].siblings, id) < 0) ignore_value(virBitmapSetBit(cpus[id].siblings, id));
goto error;
id++; id++;
} }
} }

View File

@ -118,35 +118,34 @@ parallelsBuildCapabilities(void)
if ((caps = virCapabilitiesNew(virArchFromHost(), if ((caps = virCapabilitiesNew(virArchFromHost(),
0, 0)) == NULL) 0, 0)) == NULL)
goto no_memory; return NULL;
if (nodeCapsInitNUMA(caps) < 0) if (nodeCapsInitNUMA(caps) < 0)
goto no_memory; goto error;
if ((guest = virCapabilitiesAddGuest(caps, "hvm", if ((guest = virCapabilitiesAddGuest(caps, "hvm",
VIR_ARCH_X86_64, VIR_ARCH_X86_64,
"parallels", "parallels",
NULL, 0, NULL)) == NULL) NULL, 0, NULL)) == NULL)
goto no_memory; goto error;
if (virCapabilitiesAddGuestDomain(guest, if (virCapabilitiesAddGuestDomain(guest,
"parallels", NULL, NULL, 0, NULL) == NULL) "parallels", NULL, NULL, 0, NULL) == NULL)
goto no_memory; goto error;
if ((guest = virCapabilitiesAddGuest(caps, "exe", if ((guest = virCapabilitiesAddGuest(caps, "exe",
VIR_ARCH_X86_64, VIR_ARCH_X86_64,
"parallels", "parallels",
NULL, 0, NULL)) == NULL) NULL, 0, NULL)) == NULL)
goto no_memory; goto error;
if (virCapabilitiesAddGuestDomain(guest, if (virCapabilitiesAddGuestDomain(guest,
"parallels", NULL, NULL, 0, NULL) == NULL) "parallels", NULL, NULL, 0, NULL) == NULL)
goto no_memory; goto error;
return caps; return caps;
no_memory: error:
virReportOOMError();
virObjectUnref(caps); virObjectUnref(caps);
return NULL; return NULL;
} }
@ -227,20 +226,18 @@ parallelsAddSerialInfo(virDomainChrDefPtr **serials, size_t *nserials,
virDomainChrDefPtr chr = NULL; virDomainChrDefPtr chr = NULL;
if (!(chr = virDomainChrDefNew())) if (!(chr = virDomainChrDefNew()))
goto no_memory; goto cleanup;
if (parallelsGetSerialInfo(chr, key, value)) if (parallelsGetSerialInfo(chr, key, value))
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(*serials, *nserials + 1) < 0) if (VIR_REALLOC_N(*serials, *nserials + 1) < 0)
goto no_memory; goto cleanup;
(*serials)[(*nserials)++] = chr; (*serials)[(*nserials)++] = chr;
return 0; return 0;
no_memory:
virReportOOMError();
cleanup: cleanup:
virDomainChrDefFree(chr); virDomainChrDefFree(chr);
return -1; return -1;
@ -271,13 +268,13 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value)
} }
if (VIR_ALLOC(video) < 0) if (VIR_ALLOC(video) < 0)
goto no_memory; goto error;
if (VIR_ALLOC(accel) < 0) if (VIR_ALLOC(accel) < 0)
goto no_memory; goto error;
if (VIR_REALLOC_N(def->videos, def->nvideos + 1) < 0) if (VIR_REALLOC_N(def->videos, def->nvideos + 1) < 0)
goto no_memory; goto error;
def->videos[def->nvideos++] = video; def->videos[def->nvideos++] = video;
@ -288,11 +285,9 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value)
return 0; return 0;
no_memory: error:
virReportOOMError();
VIR_FREE(accel); VIR_FREE(accel);
virDomainVideoDefFree(video); virDomainVideoDefFree(video);
error:
return -1; return -1;
} }
@ -386,20 +381,18 @@ parallelsAddHddInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value)
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
if (VIR_ALLOC(disk) < 0) if (VIR_ALLOC(disk) < 0)
goto no_memory; goto error;
if (parallelsGetHddInfo(def, disk, key, value)) if (parallelsGetHddInfo(def, disk, key, value))
goto error; goto error;
if (VIR_REALLOC_N(def->disks, def->ndisks + 1) < 0) if (VIR_REALLOC_N(def->disks, def->ndisks + 1) < 0)
goto no_memory; goto error;
def->disks[def->ndisks++] = disk; def->disks[def->ndisks++] = disk;
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virDomainDiskDefFree(disk); virDomainDiskDefFree(disk);
return -1; return -1;
@ -508,20 +501,18 @@ parallelsAddNetInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value)
virDomainNetDefPtr net = NULL; virDomainNetDefPtr net = NULL;
if (VIR_ALLOC(net) < 0) if (VIR_ALLOC(net) < 0)
goto no_memory; goto error;
if (parallelsGetNetInfo(net, key, value)) if (parallelsGetNetInfo(net, key, value))
goto error; goto error;
if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0) if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
goto no_memory; goto error;
def->nets[def->nnets - 1] = net; def->nets[def->nnets - 1] = net;
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virDomainNetDefFree(net); virDomainNetDefFree(net);
return -1; return -1;
@ -597,7 +588,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root)
} }
if (VIR_ALLOC(gr) < 0) if (VIR_ALLOC(gr) < 0)
goto no_memory; goto cleanup;
if (STREQ(tmp, "auto")) { if (STREQ(tmp, "auto")) {
if (virJSONValueObjectGetNumberUint(jobj, "port", &port) < 0) if (virJSONValueObjectGetNumberUint(jobj, "port", &port) < 0)
@ -625,7 +616,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root)
} }
if (VIR_ALLOC(gr->listens) < 0) if (VIR_ALLOC(gr->listens) < 0)
goto no_memory; goto cleanup;
gr->nListens = 1; gr->nListens = 1;
@ -635,13 +626,11 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root)
gr->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; gr->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
if (VIR_REALLOC_N(def->graphics, def->ngraphics + 1) < 0) if (VIR_REALLOC_N(def->graphics, def->ngraphics + 1) < 0)
goto no_memory; goto cleanup;
def->graphics[def->ngraphics++] = gr; def->graphics[def->ngraphics++] = gr;
return 0; return 0;
no_memory:
virReportOOMError();
cleanup: cleanup:
virDomainGraphicsDefFree(gr); virDomainGraphicsDefFree(gr);
return ret; return ret;
@ -665,7 +654,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
const char *state; const char *state;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
goto no_memory; goto cleanup;
def->virtType = VIR_DOMAIN_VIRT_PARALLELS; def->virtType = VIR_DOMAIN_VIRT_PARALLELS;
def->id = -1; def->id = -1;
@ -771,7 +760,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
def->os.arch = VIR_ARCH_X86_64; def->os.arch = VIR_ARCH_X86_64;
if (VIR_ALLOC(pdom) < 0) if (VIR_ALLOC(pdom) < 0)
goto no_memory; goto cleanup;
if (virJSONValueObjectGetNumberUint(jobj, "EnvID", &x) < 0) if (virJSONValueObjectGetNumberUint(jobj, "EnvID", &x) < 0)
goto cleanup; goto cleanup;
@ -833,8 +822,6 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
return dom; return dom;
no_memory:
virReportOOMError();
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
parallelsDomObjFreePrivate(pdom); parallelsDomObjFreePrivate(pdom);
@ -899,10 +886,8 @@ parallelsOpenDefault(virConnectPtr conn)
{ {
parallelsConnPtr privconn; parallelsConnPtr privconn;
if (VIR_ALLOC(privconn) < 0) { if (VIR_ALLOC(privconn) < 0)
virReportOOMError();
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
}
if (virMutexInit(&privconn->lock) < 0) { if (virMutexInit(&privconn->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize mutex")); _("cannot initialize mutex"));
@ -1800,10 +1785,8 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom,
if (!oldnet) { if (!oldnet) {
create = true; create = true;
if (VIR_ALLOC(oldnet) < 0) { if (VIR_ALLOC(oldnet) < 0)
virReportOOMError();
return -1; return -1;
}
} }
if (!create && oldnet->type != newnet->type) { if (!create && oldnet->type != newnet->type) {

View File

@ -57,10 +57,8 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj
} }
if (virAsprintf(&bridgeLink, "%s/%s/brport/bridge", if (virAsprintf(&bridgeLink, "%s/%s/brport/bridge",
SYSFS_NET_DIR, ifname) < 0) { SYSFS_NET_DIR, ifname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virFileResolveLink(bridgeLink, &bridgePath) < 0) { if (virFileResolveLink(bridgeLink, &bridgePath) < 0) {
virReportSystemError(errno, _("cannot read link '%s'"), bridgeLink); virReportSystemError(errno, _("cannot read link '%s'"), bridgeLink);
@ -71,10 +69,8 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj
goto cleanup; goto cleanup;
if (virAsprintf(&bridgeAddressPath, "%s/%s/brport/bridge/address", if (virAsprintf(&bridgeAddressPath, "%s/%s/brport/bridge/address",
SYSFS_NET_DIR, ifname) < 0) { SYSFS_NET_DIR, ifname) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if ((len = virFileReadAll(bridgeAddressPath, 18, &bridgeAddress)) < 0) { if ((len = virFileReadAll(bridgeAddressPath, 18, &bridgeAddress)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -112,10 +108,8 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name)
virJSONValuePtr jobj = NULL, jobj2; virJSONValuePtr jobj = NULL, jobj2;
int ret = -1; int ret = -1;
if (VIR_EXPAND_N(def->ips, def->nips, 1) < 0) { if (VIR_EXPAND_N(def->ips, def->nips, 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
jobj = parallelsParseOutput("prlsrvctl", "net", "info", "-j", name, NULL); jobj = parallelsParseOutput("prlsrvctl", "net", "info", "-j", name, NULL);
@ -157,10 +151,8 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name)
goto cleanup; goto cleanup;
} }
if (VIR_EXPAND_N(def->ips[0].ranges, def->ips[0].nranges, 1) < 0) { if (VIR_EXPAND_N(def->ips[0].ranges, def->ips[0].nranges, 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (!(tmp = virJSONValueObjectGetString(jobj2, "IP scope start address"))) { if (!(tmp = virJSONValueObjectGetString(jobj2, "IP scope start address"))) {
parallelsParseError(); parallelsParseError();
@ -198,7 +190,7 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj)
unsigned char md5[MD5_DIGEST_SIZE]; unsigned char md5[MD5_DIGEST_SIZE];
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
goto no_memory; goto cleanup;
if (!(tmp = virJSONValueObjectGetString(jobj, "Network ID"))) { if (!(tmp = virJSONValueObjectGetString(jobj, "Network ID"))) {
parallelsParseError(); parallelsParseError();
@ -244,8 +236,6 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj)
virNetworkObjUnlock(net); virNetworkObjUnlock(net);
return net; return net;
no_memory:
virReportOOMError();
cleanup: cleanup:
virNetworkDefFree(def); virNetworkDefFree(def);
return NULL; return NULL;
@ -258,7 +248,7 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn)
virNetworkDefPtr def; virNetworkDefPtr def;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
goto no_memory; goto cleanup;
def->forward.type = VIR_NETWORK_FORWARD_ROUTE; def->forward.type = VIR_NETWORK_FORWARD_ROUTE;
@ -283,8 +273,6 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn)
return net; return net;
no_memory:
virReportOOMError();
cleanup: cleanup:
virNetworkDefFree(def); virNetworkDefFree(def);
return NULL; return NULL;

View File

@ -106,10 +106,8 @@ parallelsFindVolumes(virStoragePoolObjPtr pool)
continue; continue;
if (!(path = virFileBuildPath(pool->def->target.path, if (!(path = virFileBuildPath(pool->def->target.path,
ent->d_name, NULL))) { ent->d_name, NULL)))
virReportOOMError();
goto cleanup; goto cleanup;
}
if (!parallelsStorageVolDefineXML(pool, NULL, path, false)) if (!parallelsStorageVolDefineXML(pool, NULL, path, false))
goto cleanup; goto cleanup;
@ -170,13 +168,13 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path)
virStoragePoolObjPtr pool = NULL; virStoragePoolObjPtr pool = NULL;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
goto no_memory; goto error;
if (!(def->name = parallelsMakePoolName(conn, path))) if (!(def->name = parallelsMakePoolName(conn, path)))
goto error; goto error;
if (VIR_ALLOC_N(def->uuid, VIR_UUID_BUFLEN)) if (VIR_ALLOC_N(def->uuid, VIR_UUID_BUFLEN))
goto no_memory; goto error;
if (virUUIDGenerate(def->uuid)) { if (virUUIDGenerate(def->uuid)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -199,8 +197,6 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path)
virStoragePoolObjUnlock(pool); virStoragePoolObjUnlock(pool);
return pool; return pool;
no_memory:
virReportOOMError();
error: error:
virStoragePoolDefFree(def); virStoragePoolDefFree(def);
if (pool) if (pool)
@ -302,10 +298,10 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool,
virStorageVolDefPtr def = NULL; virStorageVolDefPtr def = NULL;
if (VIR_ALLOC(def)) if (VIR_ALLOC(def))
goto no_memory; goto error;
if (virAsprintf(&def->name, "%s-%s", dom->def->name, diskName) < 0) if (virAsprintf(&def->name, "%s-%s", dom->def->name, diskName) < 0)
goto no_memory; goto error;
def->type = VIR_STORAGE_VOL_FILE; def->type = VIR_STORAGE_VOL_FILE;
@ -319,7 +315,7 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool,
goto error; goto error;
if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0)
goto no_memory; goto error;
pool->volumes.objs[pool->volumes.count++] = def; pool->volumes.objs[pool->volumes.count++] = def;
@ -352,10 +348,8 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
VIR_FREE(diskPath); VIR_FREE(diskPath);
VIR_FREE(diskDescPath); VIR_FREE(diskDescPath);
if (!(diskPath = virFileBuildPath(pdom->home, ent->d_name, NULL))) { if (!(diskPath = virFileBuildPath(pdom->home, ent->d_name, NULL)))
virReportOOMError();
goto cleanup; goto cleanup;
}
if (lstat(diskPath, &sb) < 0) { if (lstat(diskPath, &sb) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
@ -368,10 +362,8 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
continue; continue;
if (!(diskDescPath = virFileBuildPath(diskPath, if (!(diskDescPath = virFileBuildPath(diskPath,
"DiskDescriptor", ".xml"))) { "DiskDescriptor", ".xml")))
virReportOOMError();
goto cleanup; goto cleanup;
}
if (access(diskDescPath, F_OK)) if (access(diskDescPath, F_OK))
continue; continue;
@ -422,11 +414,11 @@ static int parallelsLoadPools(virConnectPtr conn)
/* Configuration path is /etc/libvirt/parallels-storage/... . */ /* Configuration path is /etc/libvirt/parallels-storage/... . */
if (virAsprintf(&storageState->configDir, if (virAsprintf(&storageState->configDir,
"%s/parallels-storage", base) == -1) "%s/parallels-storage", base) == -1)
goto out_of_memory; goto error;
if (virAsprintf(&storageState->autostartDir, if (virAsprintf(&storageState->autostartDir,
"%s/parallels-storage/autostart", base) == -1) "%s/parallels-storage/autostart", base) == -1)
goto out_of_memory; goto error;
VIR_FREE(base); VIR_FREE(base);
@ -459,8 +451,6 @@ static int parallelsLoadPools(virConnectPtr conn)
return 0; return 0;
out_of_memory:
virReportOOMError();
error: error:
VIR_FREE(base); VIR_FREE(base);
return -1; return -1;
@ -477,10 +467,8 @@ parallelsStorageOpen(virConnectPtr conn,
if (STRNEQ(conn->driver->name, "Parallels")) if (STRNEQ(conn->driver->name, "Parallels"))
return VIR_DRV_OPEN_DECLINED; return VIR_DRV_OPEN_DECLINED;
if (VIR_ALLOC(storageState) < 0) { if (VIR_ALLOC(storageState) < 0)
virReportOOMError();
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
}
if (virMutexInit(&storageState->lock) < 0) { if (virMutexInit(&storageState->lock) < 0) {
VIR_FREE(storageState); VIR_FREE(storageState);
@ -1244,16 +1232,12 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool,
} }
} }
if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) { if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virAsprintf(&privvol->target.path, "%s/%s", if (virAsprintf(&privvol->target.path, "%s/%s",
pool->def->target.path, privvol->name) < 0) { pool->def->target.path, privvol->name) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup; goto cleanup;
@ -1382,16 +1366,12 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool,
privpool->def->allocation); privpool->def->allocation);
if (VIR_REALLOC_N(privpool->volumes.objs, if (VIR_REALLOC_N(privpool->volumes.objs,
privpool->volumes.count + 1) < 0) { privpool->volumes.count + 1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (virAsprintf(&privvol->target.path, "%s/%s", if (virAsprintf(&privvol->target.path, "%s/%s",
privpool->def->target.path, privvol->name) == -1) { privpool->def->target.path, privvol->name) == -1)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup; goto cleanup;

View File

@ -130,10 +130,8 @@ parallelsAddFileExt(const char *path, const char *ext)
char *new_path = NULL; char *new_path = NULL;
size_t len = strlen(path) + strlen(ext) + 1; size_t len = strlen(path) + strlen(ext) + 1;
if (VIR_ALLOC_N(new_path, len) < 0) { if (VIR_ALLOC_N(new_path, len) < 0)
virReportOOMError();
return NULL; return NULL;
}
if (!virStrcpy(new_path, path, len)) { if (!virStrcpy(new_path, path, len)) {
VIR_FREE(new_path); VIR_FREE(new_path);