提交 f5a60ebd 编写于 作者: M Michal Privoznik

Adapt to VIR_ALLOC and virAsprintf in src/parallels/*

上级 4079aca0
......@@ -1486,8 +1486,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
cpus[id].core_id = c;
if (!(cpus[id].siblings = virBitmapNew(ncpus)))
goto error;
if (virBitmapSetBit(cpus[id].siblings, id) < 0)
goto error;
ignore_value(virBitmapSetBit(cpus[id].siblings, id));
id++;
}
}
......
......@@ -118,35 +118,34 @@ parallelsBuildCapabilities(void)
if ((caps = virCapabilitiesNew(virArchFromHost(),
0, 0)) == NULL)
goto no_memory;
return NULL;
if (nodeCapsInitNUMA(caps) < 0)
goto no_memory;
goto error;
if ((guest = virCapabilitiesAddGuest(caps, "hvm",
VIR_ARCH_X86_64,
"parallels",
NULL, 0, NULL)) == NULL)
goto no_memory;
goto error;
if (virCapabilitiesAddGuestDomain(guest,
"parallels", NULL, NULL, 0, NULL) == NULL)
goto no_memory;
goto error;
if ((guest = virCapabilitiesAddGuest(caps, "exe",
VIR_ARCH_X86_64,
"parallels",
NULL, 0, NULL)) == NULL)
goto no_memory;
goto error;
if (virCapabilitiesAddGuestDomain(guest,
"parallels", NULL, NULL, 0, NULL) == NULL)
goto no_memory;
goto error;
return caps;
no_memory:
virReportOOMError();
error:
virObjectUnref(caps);
return NULL;
}
......@@ -227,20 +226,18 @@ parallelsAddSerialInfo(virDomainChrDefPtr **serials, size_t *nserials,
virDomainChrDefPtr chr = NULL;
if (!(chr = virDomainChrDefNew()))
goto no_memory;
goto cleanup;
if (parallelsGetSerialInfo(chr, key, value))
goto cleanup;
if (VIR_REALLOC_N(*serials, *nserials + 1) < 0)
goto no_memory;
goto cleanup;
(*serials)[(*nserials)++] = chr;
return 0;
no_memory:
virReportOOMError();
cleanup:
virDomainChrDefFree(chr);
return -1;
......@@ -271,13 +268,13 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value)
}
if (VIR_ALLOC(video) < 0)
goto no_memory;
goto error;
if (VIR_ALLOC(accel) < 0)
goto no_memory;
goto error;
if (VIR_REALLOC_N(def->videos, def->nvideos + 1) < 0)
goto no_memory;
goto error;
def->videos[def->nvideos++] = video;
......@@ -288,11 +285,9 @@ parallelsAddVideoInfo(virDomainDefPtr def, virJSONValuePtr value)
return 0;
no_memory:
virReportOOMError();
error:
VIR_FREE(accel);
virDomainVideoDefFree(video);
error:
return -1;
}
......@@ -386,20 +381,18 @@ parallelsAddHddInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value)
virDomainDiskDefPtr disk = NULL;
if (VIR_ALLOC(disk) < 0)
goto no_memory;
goto error;
if (parallelsGetHddInfo(def, disk, key, value))
goto error;
if (VIR_REALLOC_N(def->disks, def->ndisks + 1) < 0)
goto no_memory;
goto error;
def->disks[def->ndisks++] = disk;
return 0;
no_memory:
virReportOOMError();
error:
virDomainDiskDefFree(disk);
return -1;
......@@ -508,20 +501,18 @@ parallelsAddNetInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value)
virDomainNetDefPtr net = NULL;
if (VIR_ALLOC(net) < 0)
goto no_memory;
goto error;
if (parallelsGetNetInfo(net, key, value))
goto error;
if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
goto no_memory;
goto error;
def->nets[def->nnets - 1] = net;
return 0;
no_memory:
virReportOOMError();
error:
virDomainNetDefFree(net);
return -1;
......@@ -597,7 +588,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root)
}
if (VIR_ALLOC(gr) < 0)
goto no_memory;
goto cleanup;
if (STREQ(tmp, "auto")) {
if (virJSONValueObjectGetNumberUint(jobj, "port", &port) < 0)
......@@ -625,7 +616,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root)
}
if (VIR_ALLOC(gr->listens) < 0)
goto no_memory;
goto cleanup;
gr->nListens = 1;
......@@ -635,13 +626,11 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root)
gr->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
if (VIR_REALLOC_N(def->graphics, def->ngraphics + 1) < 0)
goto no_memory;
goto cleanup;
def->graphics[def->ngraphics++] = gr;
return 0;
no_memory:
virReportOOMError();
cleanup:
virDomainGraphicsDefFree(gr);
return ret;
......@@ -665,7 +654,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
const char *state;
if (VIR_ALLOC(def) < 0)
goto no_memory;
goto cleanup;
def->virtType = VIR_DOMAIN_VIRT_PARALLELS;
def->id = -1;
......@@ -771,7 +760,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
def->os.arch = VIR_ARCH_X86_64;
if (VIR_ALLOC(pdom) < 0)
goto no_memory;
goto cleanup;
if (virJSONValueObjectGetNumberUint(jobj, "EnvID", &x) < 0)
goto cleanup;
......@@ -833,8 +822,6 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
return dom;
no_memory:
virReportOOMError();
cleanup:
virDomainDefFree(def);
parallelsDomObjFreePrivate(pdom);
......@@ -899,10 +886,8 @@ parallelsOpenDefault(virConnectPtr conn)
{
parallelsConnPtr privconn;
if (VIR_ALLOC(privconn) < 0) {
virReportOOMError();
if (VIR_ALLOC(privconn) < 0)
return VIR_DRV_OPEN_ERROR;
}
if (virMutexInit(&privconn->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize mutex"));
......@@ -1800,10 +1785,8 @@ static int parallelsApplyIfaceParams(parallelsDomObjPtr pdom,
if (!oldnet) {
create = true;
if (VIR_ALLOC(oldnet) < 0) {
virReportOOMError();
if (VIR_ALLOC(oldnet) < 0)
return -1;
}
}
if (!create && oldnet->type != newnet->type) {
......
......@@ -57,10 +57,8 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj
}
if (virAsprintf(&bridgeLink, "%s/%s/brport/bridge",
SYSFS_NET_DIR, ifname) < 0) {
virReportOOMError();
SYSFS_NET_DIR, ifname) < 0)
goto cleanup;
}
if (virFileResolveLink(bridgeLink, &bridgePath) < 0) {
virReportSystemError(errno, _("cannot read link '%s'"), bridgeLink);
......@@ -71,10 +69,8 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj
goto cleanup;
if (virAsprintf(&bridgeAddressPath, "%s/%s/brport/bridge/address",
SYSFS_NET_DIR, ifname) < 0) {
virReportOOMError();
SYSFS_NET_DIR, ifname) < 0)
goto cleanup;
}
if ((len = virFileReadAll(bridgeAddressPath, 18, &bridgeAddress)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -112,10 +108,8 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name)
virJSONValuePtr jobj = NULL, jobj2;
int ret = -1;
if (VIR_EXPAND_N(def->ips, def->nips, 1) < 0) {
virReportOOMError();
if (VIR_EXPAND_N(def->ips, def->nips, 1) < 0)
goto cleanup;
}
jobj = parallelsParseOutput("prlsrvctl", "net", "info", "-j", name, NULL);
......@@ -157,10 +151,8 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name)
goto cleanup;
}
if (VIR_EXPAND_N(def->ips[0].ranges, def->ips[0].nranges, 1) < 0) {
virReportOOMError();
if (VIR_EXPAND_N(def->ips[0].ranges, def->ips[0].nranges, 1) < 0)
goto cleanup;
}
if (!(tmp = virJSONValueObjectGetString(jobj2, "IP scope start address"))) {
parallelsParseError();
......@@ -198,7 +190,7 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj)
unsigned char md5[MD5_DIGEST_SIZE];
if (VIR_ALLOC(def) < 0)
goto no_memory;
goto cleanup;
if (!(tmp = virJSONValueObjectGetString(jobj, "Network ID"))) {
parallelsParseError();
......@@ -244,8 +236,6 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj)
virNetworkObjUnlock(net);
return net;
no_memory:
virReportOOMError();
cleanup:
virNetworkDefFree(def);
return NULL;
......@@ -258,7 +248,7 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn)
virNetworkDefPtr def;
if (VIR_ALLOC(def) < 0)
goto no_memory;
goto cleanup;
def->forward.type = VIR_NETWORK_FORWARD_ROUTE;
......@@ -283,8 +273,6 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn)
return net;
no_memory:
virReportOOMError();
cleanup:
virNetworkDefFree(def);
return NULL;
......
......@@ -106,10 +106,8 @@ parallelsFindVolumes(virStoragePoolObjPtr pool)
continue;
if (!(path = virFileBuildPath(pool->def->target.path,
ent->d_name, NULL))) {
virReportOOMError();
ent->d_name, NULL)))
goto cleanup;
}
if (!parallelsStorageVolDefineXML(pool, NULL, path, false))
goto cleanup;
......@@ -170,13 +168,13 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path)
virStoragePoolObjPtr pool = NULL;
if (VIR_ALLOC(def) < 0)
goto no_memory;
goto error;
if (!(def->name = parallelsMakePoolName(conn, path)))
goto error;
if (VIR_ALLOC_N(def->uuid, VIR_UUID_BUFLEN))
goto no_memory;
goto error;
if (virUUIDGenerate(def->uuid)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
......@@ -199,8 +197,6 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path)
virStoragePoolObjUnlock(pool);
return pool;
no_memory:
virReportOOMError();
error:
virStoragePoolDefFree(def);
if (pool)
......@@ -302,10 +298,10 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool,
virStorageVolDefPtr def = NULL;
if (VIR_ALLOC(def))
goto no_memory;
goto error;
if (virAsprintf(&def->name, "%s-%s", dom->def->name, diskName) < 0)
goto no_memory;
goto error;
def->type = VIR_STORAGE_VOL_FILE;
......@@ -319,7 +315,7 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool,
goto error;
if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0)
goto no_memory;
goto error;
pool->volumes.objs[pool->volumes.count++] = def;
......@@ -352,10 +348,8 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
VIR_FREE(diskPath);
VIR_FREE(diskDescPath);
if (!(diskPath = virFileBuildPath(pdom->home, ent->d_name, NULL))) {
virReportOOMError();
if (!(diskPath = virFileBuildPath(pdom->home, ent->d_name, NULL)))
goto cleanup;
}
if (lstat(diskPath, &sb) < 0) {
virReportSystemError(errno,
......@@ -368,10 +362,8 @@ static int parallelsFindVmVolumes(virStoragePoolObjPtr pool,
continue;
if (!(diskDescPath = virFileBuildPath(diskPath,
"DiskDescriptor", ".xml"))) {
virReportOOMError();
"DiskDescriptor", ".xml")))
goto cleanup;
}
if (access(diskDescPath, F_OK))
continue;
......@@ -422,11 +414,11 @@ static int parallelsLoadPools(virConnectPtr conn)
/* Configuration path is /etc/libvirt/parallels-storage/... . */
if (virAsprintf(&storageState->configDir,
"%s/parallels-storage", base) == -1)
goto out_of_memory;
goto error;
if (virAsprintf(&storageState->autostartDir,
"%s/parallels-storage/autostart", base) == -1)
goto out_of_memory;
goto error;
VIR_FREE(base);
......@@ -459,8 +451,6 @@ static int parallelsLoadPools(virConnectPtr conn)
return 0;
out_of_memory:
virReportOOMError();
error:
VIR_FREE(base);
return -1;
......@@ -477,10 +467,8 @@ parallelsStorageOpen(virConnectPtr conn,
if (STRNEQ(conn->driver->name, "Parallels"))
return VIR_DRV_OPEN_DECLINED;
if (VIR_ALLOC(storageState) < 0) {
virReportOOMError();
if (VIR_ALLOC(storageState) < 0)
return VIR_DRV_OPEN_ERROR;
}
if (virMutexInit(&storageState->lock) < 0) {
VIR_FREE(storageState);
......@@ -1244,16 +1232,12 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool,
}
}
if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0) {
virReportOOMError();
if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0)
goto cleanup;
}
if (virAsprintf(&privvol->target.path, "%s/%s",
pool->def->target.path, privvol->name) < 0) {
virReportOOMError();
pool->def->target.path, privvol->name) < 0)
goto cleanup;
}
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup;
......@@ -1382,16 +1366,12 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool,
privpool->def->allocation);
if (VIR_REALLOC_N(privpool->volumes.objs,
privpool->volumes.count + 1) < 0) {
virReportOOMError();
privpool->volumes.count + 1) < 0)
goto cleanup;
}
if (virAsprintf(&privvol->target.path, "%s/%s",
privpool->def->target.path, privvol->name) == -1) {
virReportOOMError();
privpool->def->target.path, privvol->name) == -1)
goto cleanup;
}
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0)
goto cleanup;
......
......@@ -130,10 +130,8 @@ parallelsAddFileExt(const char *path, const char *ext)
char *new_path = NULL;
size_t len = strlen(path) + strlen(ext) + 1;
if (VIR_ALLOC_N(new_path, len) < 0) {
virReportOOMError();
if (VIR_ALLOC_N(new_path, len) < 0)
return NULL;
}
if (!virStrcpy(new_path, path, len)) {
VIR_FREE(new_path);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册