Adapt to VIR_ALLOC and virAsprintf in src/libxl/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:10:38 +02:00
parent d89f8056a8
commit 23b861f52e
2 changed files with 17 additions and 50 deletions

View File

@ -278,12 +278,11 @@ libxlMakeCapabilitiesInternal(virArch hostarch,
host_pae, host_pae,
guest_archs, guest_archs,
nr_guest_archs)) == NULL) nr_guest_archs)) == NULL)
goto no_memory; goto error;
return caps; return caps;
no_memory: error:
virReportOOMError();
virObjectUnref(caps); virObjectUnref(caps);
return NULL; return NULL;
} }
@ -576,10 +575,8 @@ libxlMakeDiskList(virDomainDefPtr def, libxl_domain_config *d_config)
libxl_device_disk *x_disks; libxl_device_disk *x_disks;
int i; int i;
if (VIR_ALLOC_N(x_disks, ndisks) < 0) { if (VIR_ALLOC_N(x_disks, ndisks) < 0)
virReportOOMError();
return -1; return -1;
}
for (i = 0; i < ndisks; i++) { for (i = 0; i < ndisks; i++) {
if (libxlMakeDisk(l_disks[i], &x_disks[i]) < 0) if (libxlMakeDisk(l_disks[i], &x_disks[i]) < 0)
@ -648,10 +645,8 @@ libxlMakeNicList(virDomainDefPtr def, libxl_domain_config *d_config)
libxl_device_nic *x_nics; libxl_device_nic *x_nics;
int i; int i;
if (VIR_ALLOC_N(x_nics, nnics) < 0) { if (VIR_ALLOC_N(x_nics, nnics) < 0)
virReportOOMError();
return -1; return -1;
}
for (i = 0; i < nnics; i++) { for (i = 0; i < nnics; i++) {
if (libxlMakeNic(l_nics[i], &x_nics[i])) if (libxlMakeNic(l_nics[i], &x_nics[i]))
@ -734,12 +729,9 @@ libxlMakeVfbList(libxlDriverPrivatePtr driver,
if (nvfbs == 0) if (nvfbs == 0)
return 0; return 0;
if (VIR_ALLOC_N(x_vfbs, nvfbs) < 0) { if (VIR_ALLOC_N(x_vfbs, nvfbs) < 0)
virReportOOMError();
return -1; return -1;
}
if (VIR_ALLOC_N(x_vkbs, nvfbs) < 0) { if (VIR_ALLOC_N(x_vkbs, nvfbs) < 0) {
virReportOOMError();
VIR_FREE(x_vfbs); VIR_FREE(x_vfbs);
return -1; return -1;
} }

View File

@ -183,10 +183,8 @@ libxlFDRegisterEventHook(void *priv, int fd, void **hndp,
int vir_events = VIR_EVENT_HANDLE_ERROR; int vir_events = VIR_EVENT_HANDLE_ERROR;
libxlEventHookInfoPtr info; libxlEventHookInfoPtr info;
if (VIR_ALLOC(info) < 0) { if (VIR_ALLOC(info) < 0)
virReportOOMError();
return -1; return -1;
}
info->priv = priv; info->priv = priv;
/* /*
@ -287,10 +285,8 @@ libxlTimeoutRegisterEventHook(void *priv,
static struct timeval zero; static struct timeval zero;
int timeout; int timeout;
if (VIR_ALLOC(info) < 0) { if (VIR_ALLOC(info) < 0)
virReportOOMError();
return -1; return -1;
}
info->priv = priv; info->priv = priv;
/* /*
@ -548,11 +544,7 @@ static char *
libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm) { libxlDomainManagedSavePath(libxlDriverPrivatePtr driver, virDomainObjPtr vm) {
char *ret; char *ret;
if (virAsprintf(&ret, "%s/%s.save", driver->saveDir, vm->def->name) < 0) { ignore_value(virAsprintf(&ret, "%s/%s.save", driver->saveDir, vm->def->name));
virReportOOMError();
return NULL;
}
return ret; return ret;
} }
@ -597,10 +589,8 @@ libxlSaveImageOpen(libxlDriverPrivatePtr driver, const char *from,
goto error; goto error;
} }
if (VIR_ALLOC_N(xml, hdr.xmlLen) < 0) { if (VIR_ALLOC_N(xml, hdr.xmlLen) < 0)
virReportOOMError();
goto error; goto error;
}
if (saferead(fd, xml, hdr.xmlLen) != hdr.xmlLen) { if (saferead(fd, xml, hdr.xmlLen) != hdr.xmlLen) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read XML")); virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to read XML"));
@ -845,10 +835,8 @@ libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
if (vcpu != def->cputune.vcpupin[vcpu]->vcpuid) if (vcpu != def->cputune.vcpupin[vcpu]->vcpuid)
continue; continue;
if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) { if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
cpumask = (uint8_t*) def->cputune.vcpupin[vcpu]->cpumask; cpumask = (uint8_t*) def->cputune.vcpupin[vcpu]->cpumask;
@ -1273,9 +1261,8 @@ libxlStateInitialize(bool privileged,
goto error; goto error;
} }
if (virAsprintf(&log_file, "%s/libxl.log", libxl_driver->logDir) < 0) { if (virAsprintf(&log_file, "%s/libxl.log", libxl_driver->logDir) < 0)
goto out_of_memory; goto error;
}
if ((libxl_driver->logger_file = fopen(log_file, "a")) == NULL) { if ((libxl_driver->logger_file = fopen(log_file, "a")) == NULL) {
virReportSystemError(errno, virReportSystemError(errno,
@ -1369,8 +1356,6 @@ libxlStateInitialize(bool privileged,
return 0; return 0;
out_of_memory:
virReportOOMError();
error: error:
ret = -1; ret = -1;
fail: fail:
@ -2803,10 +2788,8 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
goto cleanup; goto cleanup;
maplen = VIR_CPU_MAPLEN(nvcpus); maplen = VIR_CPU_MAPLEN(nvcpus);
if (VIR_ALLOC_N(bitmask, maplen) < 0) { if (VIR_ALLOC_N(bitmask, maplen) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
for (i = 0; i < nvcpus; ++i) { for (i = 0; i < nvcpus; ++i) {
pos = i / 8; pos = i / 8;
@ -2967,10 +2950,8 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
} }
if (!vm->def->cputune.vcpupin) { if (!vm->def->cputune.vcpupin) {
if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0) { if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
vm->def->cputune.nvcpupin = 0; vm->def->cputune.nvcpupin = 0;
} }
if (virDomainVcpuPinAdd(&vm->def->cputune.vcpupin, if (virDomainVcpuPinAdd(&vm->def->cputune.vcpupin,
@ -3176,10 +3157,8 @@ libxlConnectDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major))) if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major)))
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);
@ -3492,10 +3471,8 @@ libxlDomainAttachDeviceDiskLive(libxlDomainObjPrivatePtr priv,
goto cleanup; goto cleanup;
} }
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0) { if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
if (libxlMakeDisk(l_disk, &x_disk) < 0) if (libxlMakeDisk(l_disk, &x_disk) < 0)
goto cleanup; goto cleanup;
@ -3617,10 +3594,8 @@ libxlDomainAttachDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
_("target %s already exists."), disk->dst); _("target %s already exists."), disk->dst);
return -1; return -1;
} }
if (virDomainDiskInsert(vmdef, disk)) { if (virDomainDiskInsert(vmdef, disk))
virReportOOMError();
return -1; return -1;
}
/* vmdef has the pointer. Generic codes for vmdef will do all jobs */ /* vmdef has the pointer. Generic codes for vmdef will do all jobs */
dev->data.disk = NULL; dev->data.disk = NULL;
break; break;