* we're discovering the existing partitions for the pool
*/
addVol = true;
- if (VIR_ALLOC(vol) < 0)
- return -1;
+ vol = g_new0(virStorageVolDef, 1);
vol->name = g_strdup(partname);
}
}
if (vol->source.extents == NULL) {
- if (VIR_ALLOC(vol->source.extents) < 0)
- goto error;
+ vol->source.extents = g_new0(virStorageVolSourceExtent, 1);
vol->source.nextent = 1;
if (virStrToLong_ull(groups[3], NULL, 10,
if (!(src = virStoragePoolSourceListNewSource(&state->list)))
return -1;
- if (VIR_ALLOC_N(src->hosts, 1) < 0)
- return -1;
+ src->hosts = g_new0(virStoragePoolSourceHost, 1);
src->nhost = 1;
src->hosts[0].name = g_strdup(state->host);
if (nnodes == 0)
return 0;
- if (VIR_ALLOC(cmdopts) < 0 ||
- VIR_ALLOC_N(cmdopts->options, nnodes) < 0)
- goto cleanup;
+ cmdopts = g_new0(virStoragePoolFSMountOptionsDef, 1);
+ cmdopts->options = g_new0(char *, nnodes);
for (i = 0; i < nnodes; i++) {
if (!(cmdopts->options[cmdopts->noptions] =
trailing_slash = false;
}
- if (VIR_ALLOC(ret) < 0)
- return NULL;
+ ret = g_new0(virStorageBackendGlusterState, 1);
ret->volname = g_strdup(name);
ret->dir = g_strdup_printf("%s%s", dir ? dir : "/", trailing_slash ? "" : "/");
/* FIXME: Currently hard-coded to tcp transport; XML needs to be
* extended to allow alternate transport */
- if (VIR_ALLOC(ret->uri) < 0)
- goto error;
+ ret->uri = g_new0(virURI, 1);
ret->uri->scheme = g_strdup("gluster");
ret->uri->server = g_strdup(def->source.hosts[0].name);
ret->uri->path = g_strdup_printf("/%s%s", ret->volname, ret->dir);
char *s;
size_t nread = 0;
- if (VIR_ALLOC_N(*buf, len) < 0)
- return -1;
+ *buf = g_new0(char, len);
s = *buf;
while (len) {
return ret;
}
- if (VIR_ALLOC(vol) < 0)
- goto cleanup;
+ vol = g_new0(virStorageVolDef, 1);
if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st) < 0)
goto cleanup;
&ntargets, &targets) < 0)
goto cleanup;
- if (VIR_ALLOC_N(list.sources, ntargets) < 0)
- goto cleanup;
+ list.sources = g_new0(virStoragePoolSource, ntargets);
for (i = 0; i < ntargets; i++) {
- if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0 ||
- VIR_ALLOC_N(list.sources[i].hosts, 1) < 0)
- goto cleanup;
+ list.sources[i].devices = g_new0(virStoragePoolSourceDevice, 1);
+ list.sources[i].hosts = g_new0(virStoragePoolSourceHost, 1);
list.sources[i].nhost = 1;
list.sources[i].hosts[0] = source->hosts[0];
list.sources[i].initiator = source->initiator;
if (virISCSIDirectTestUnitReady(iscsi, lun) < 0)
return -1;
- if (VIR_ALLOC(vol) < 0)
- return -1;
+ vol = g_new0(virStorageVolDef, 1);
vol->type = VIR_STORAGE_VOL_NETWORK;
if (virISCSIDirectScanTargets(source->initiator.iqn, portal, &ntargets, &targets) < 0)
goto cleanup;
- if (VIR_ALLOC_N(list.sources, ntargets) < 0)
- goto cleanup;
+ list.sources = g_new0(virStoragePoolSource, ntargets);
for (i = 0; i < ntargets; i++) {
- if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0 ||
- VIR_ALLOC_N(list.sources[i].hosts, 1) < 0)
- goto cleanup;
+ list.sources[i].devices = g_new0(virStoragePoolSourceDevice, 1);
+ list.sources[i].hosts = g_new0(virStoragePoolSourceHost, 1);
list.sources[i].nhost = 1;
list.sources[i].hosts[0] = source->hosts[0];
list.sources[i].initiator = source->initiator;
return ret;
if (virISCSIDirectGetVolumeCapacity(iscsi, lun, &block_size, &nb_block))
return ret;
- if (VIR_ALLOC_N(data, block_size * BLOCK_PER_PACKET))
+ data = g_new0(unsigned char, block_size * BLOCK_PER_PACKET);
return ret;
while (lba < nb_block) {
}
/* Allocate space for 'nextents' regex_unit strings plus a comma for each */
- if (VIR_ALLOC_N(regex, nextents * (strlen(regex_unit) + 1) + 1) < 0)
- goto cleanup;
+ regex = g_new0(char, nextents * (strlen(regex_unit) + 1) + 1);
strcat(regex, regex_unit);
for (i = 1; i < nextents; i++) {
/* "," is the separator of "devices" field */
/* Or a completely new volume */
if (vol == NULL) {
- if (VIR_ALLOC(vol) < 0)
- return -1;
+ vol = g_new0(virStorageVolDef, 1);
is_new_vol = true;
vol->type = VIR_STORAGE_VOL_BLOCK;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
g_autoptr(virStorageVolDef) vol = NULL;
- if (VIR_ALLOC(vol) < 0)
- return -1;
+ vol = g_new0(virStorageVolDef, 1);
vol->type = VIR_STORAGE_VOL_BLOCK;
if (nnodes == 0)
return 0;
- if (VIR_ALLOC(cmdopts) < 0)
- goto cleanup;
+ cmdopts = g_new0(virStoragePoolRBDConfigOptionsDef, 1);
- if (VIR_ALLOC_N(cmdopts->names, nnodes) < 0 ||
- VIR_ALLOC_N(cmdopts->values, nnodes) < 0)
- goto cleanup;
+ cmdopts->names = g_new0(char *, nnodes);
+ cmdopts->values = g_new0(char *, nnodes);
for (i = 0; i < nnodes; i++) {
if (!(cmdopts->names[cmdopts->noptions] =
virStorageBackendRBDStatePtr ptr;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
- if (VIR_ALLOC(ptr) < 0)
- return NULL;
+ ptr = g_new0(virStorageBackendRBDState, 1);
if (virStorageBackendRBDOpenRADOSConn(ptr, def) < 0)
goto error;
}
}
- if (VIR_ALLOC_N(names, nimages + 1) < 0)
- goto error;
+ names = g_new0(char *, nimages + 1);
nnames = nimages;
for (i = 0; i < nimages; i++)
const char *name;
while (true) {
- if (VIR_ALLOC_N(namebuf, max_size) < 0)
- goto error;
+ namebuf = g_new0(char, max_size);
rc = rbd_list(ptr->ioctx, namebuf, &max_size);
if (rc >= 0)
for (i = 0; names[i] != NULL; i++) {
g_autoptr(virStorageVolDef) vol = NULL;
- if (VIR_ALLOC(vol) < 0)
- goto cleanup;
+ vol = g_new0(virStorageVolDef, 1);
vol->name = g_steal_pointer(&names[i]);
}
do {
- if (VIR_ALLOC_N(snaps, max_snaps))
- goto cleanup;
+ snaps = g_new0(rbd_snap_info_t, max_snaps);
snap_count = rbd_snap_list(image, snaps, &max_snaps);
if (snap_count <= 0)
}
do {
- if (VIR_ALLOC_N(snaps, max_snaps))
- goto cleanup;
+ snaps = g_new0(rbd_snap_info_t, max_snaps);
snap_count = rbd_snap_list(image, snaps, &max_snaps);
if (snap_count <= 0)
unsigned long long length;
g_autofree char *writebuf = NULL;
- if (VIR_ALLOC_N(writebuf, info->obj_size * stripe_count) < 0)
- return -1;
+ writebuf = g_new0(char, info->obj_size * stripe_count);
while (offset < info->size) {
length = MIN((info->size - offset), (info->obj_size * stripe_count));
* retry logic set to true. If the thread isn't created, then no big
* deal since it's still possible to refresh the pool later.
*/
- if (VIR_ALLOC(cbdata) < 0)
- return -1;
-
+ cbdata = g_new0(virStoragePoolFCRefreshInfo, 1);
memcpy(cbdata->pool_uuid, def->uuid, VIR_UUID_BUFLEN);
cbdata->fchost_name = g_steal_pointer(&name);
return -1;
}
- if (VIR_ALLOC(vol) < 0)
- return -1;
+ vol = g_new0(virStorageVolDef, 1);
vol->name = g_strdup(diskInfo);
volume = vol;
if (volume == NULL) {
- if (VIR_ALLOC(volume) < 0)
- goto cleanup;
+ volume = g_new0(virStorageVolDef, 1);
is_new_vol = true;
volume->type = VIR_STORAGE_VOL_BLOCK;
return -1;
}
- if (VIR_ALLOC(driver) < 0)
- return VIR_DRV_STATE_INIT_ERROR;
+ driver = g_new0(virStorageDriverState, 1);
driver->lockFD = -1;
if (virMutexInit(&driver->lock) < 0) {
int buildret;
virStorageVolDefPtr buildvoldef = NULL;
- if (VIR_ALLOC(buildvoldef) < 0) {
- voldef = NULL;
- goto cleanup;
- }
+ buildvoldef = g_new0(virStorageVolDef, 1);
/* Make a shallow copy of the 'defined' volume definition, since the
* original allocation value will change as the user polls 'info',
* original allocation value will change as the user polls 'info',
* but we only need the initial requested values
*/
- if (VIR_ALLOC(shadowvol) < 0)
- goto cleanup;
+ shadowvol = g_new0(virStorageVolDef, 1);
memcpy(shadowvol, voldef, sizeof(*voldef));
* interaction and we can just lookup the backend in the callback
* routine in order to call the refresh API.
*/
- if (VIR_ALLOC(cbdata) < 0)
- goto cleanup;
+ cbdata = g_new0(virStorageVolStreamInfo, 1);
cbdata->pool_name = g_strdup(def->name);
if (voldef->type == VIR_STORAGE_VOL_PLOOP)
cbdata->vol_path = g_strdup(voldef->target.path);
src->path,
(unsigned int)src->drv->uid, (unsigned int)src->drv->gid);
- if (VIR_ALLOC(priv) < 0)
- return -1;
+ priv = g_new0(virStorageFileBackendFsPriv, 1);
src->drv->priv = priv;
return -1;
}
- if (VIR_ALLOC(priv) < 0)
- return -1;
+ priv = g_new0(virStorageFileBackendGlusterPriv, 1);
VIR_DEBUG("initializing gluster storage file %p "
"(priv='%p' volume='%s' path='%s') as [%u:%u]",
}
- if (VIR_ALLOC_N(*buf, len) < 0)
- return -1;
+ *buf = g_new0(char, len);
s = *buf;
while (len) {
if (wbytes < WRITE_BLOCK_SIZE_DEFAULT)
wbytes = WRITE_BLOCK_SIZE_DEFAULT;
- if (VIR_ALLOC_N(zerobuf, wbytes) < 0)
- return -errno;
+ zerobuf = g_new0(char, wbytes);
- if (VIR_ALLOC_N(buf, rbytes) < 0)
- return -errno;
+ buf = g_new0(char, rbytes);
if (reflink_copy) {
if (reflinkCloneFile(fd, inputfd) < 0) {
if (virStorageSourceUpdateBackingSizes(target, fd, sb) < 0)
return -1;
- if (!target->perms && VIR_ALLOC(target->perms) < 0)
- return -1;
+ if (!target->perms)
+ target->perms = g_new0(virStoragePerms, 1);
target->perms->mode = sb->st_mode & S_IRWXUGO;
target->perms->uid = sb->st_uid;
target->perms->gid = sb->st_gid;
- if (!target->timestamps && VIR_ALLOC(target->timestamps) < 0)
- return -1;
+ if (!target->timestamps)
+ target->timestamps = g_new0(virStorageTimestamps, 1);
#ifdef __APPLE__
target->timestamps->atime = sb->st_atimespec;
if (!sec)
return 0;
- if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
- VIR_ALLOC(encsec) < 0) {
- VIR_FREE(vol->target.encryption->secrets);
- virObjectUnref(sec);
- return -1;
- }
+ vol->target.encryption->secrets = g_new0(virStorageEncryptionSecretPtr, 1);
+ encsec = g_new0(virStorageEncryptionSecret, 1);
vol->target.encryption->nsecrets = 1;
vol->target.encryption->secrets[0] = encsec;
off_t size;
g_autofree char *writebuf = NULL;
- if (VIR_ALLOC_N(writebuf, writebuf_length) < 0)
- return -1;
+ writebuf = g_new0(char, writebuf_length);
if (!zero_end) {
if ((size = lseek(fd, 0, SEEK_SET)) < 0) {
goto cleanup;
}
- if (VIR_ALLOC_N(src->hosts, 1) < 0)
- goto cleanup;
+ src->hosts = g_new0(virStoragePoolSourceHost, 1);
src->nhost = 1;
src->hosts[0].name = g_strdup(host);
continue;
}
- if (VIR_ALLOC(vol) < 0)
- goto cleanup;
+ vol = g_new0(virStorageVolDef, 1);
vol->name = g_strdup(ent->d_name);
return -1;
}
- if (VIR_ALLOC(vol) < 0)
- return -1;
+ vol = g_new0(virStorageVolDef, 1);
vol->type = VIR_STORAGE_VOL_BLOCK;