/* XXX Only support one extended partition */
switch (virStorageBackendDiskPartTypeToCreate(pool)) {
case VIR_STORAGE_VOL_DISK_TYPE_PRIMARY:
- if (virAsprintf(partFormat, "primary %s", partedFormat) < 0)
- return -1;
+ *partFormat = g_strdup_printf("primary %s", partedFormat);
break;
case VIR_STORAGE_VOL_DISK_TYPE_LOGICAL:
/* make sure we have an extended partition */
if (virStoragePoolObjSearchVolume(pool,
virStorageVolPartFindExtended,
NULL)) {
- if (virAsprintf(partFormat, "logical %s",
- partedFormat) < 0)
- return -1;
+ *partFormat = g_strdup_printf("logical %s", partedFormat);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no extended partition found and no "
return NULL;
ret->volname = g_strdup(name);
- if (virAsprintf(&ret->dir, "%s%s", dir ? dir : "/",
- trailing_slash ? "" : "/") < 0)
- goto error;
+ 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 */
goto error;
ret->uri->scheme = g_strdup("gluster");
ret->uri->server = g_strdup(def->source.hosts[0].name);
- if (virAsprintf(&ret->uri->path, "/%s%s", ret->volname, ret->dir) < 0)
- goto error;
+ ret->uri->path = g_strdup_printf("/%s%s", ret->volname, ret->dir);
ret->uri->port = def->source.hosts[0].port;
/* Actually connect to glfs */
vol->name = g_strdup(name);
}
- if (virAsprintf(&path, "%s%s%s", state->volname, state->dir,
- vol->name) < 0)
- return -1;
+ path = g_strdup_printf("%s%s%s", state->volname, state->dir, vol->name);
tmp = state->uri->path;
- if (virAsprintf(&state->uri->path, "/%s", path) < 0) {
- state->uri->path = tmp;
- return -1;
- }
+ state->uri->path = g_strdup_printf("/%s", path);
if (!(vol->target.path = virURIFormat(state->uri))) {
VIR_FREE(state->uri->path);
state->uri->path = tmp;
source->hosts[0].port = ISCSI_DEFAULT_TARGET_PORT;
if (strchr(source->hosts[0].name, ':')) {
- ignore_value(virAsprintf(&portal, "[%s]:%d,1",
+ portal = g_strdup_printf("[%s]:%d,1",
source->hosts[0].name,
- source->hosts[0].port));
+ source->hosts[0].port);
} else {
- ignore_value(virAsprintf(&portal, "%s:%d,1",
+ portal = g_strdup_printf("%s:%d,1",
source->hosts[0].name,
- source->hosts[0].port));
+ source->hosts[0].port);
}
return portal;
uint32_t host;
g_autofree char *sysfs_path = NULL;
- if (virAsprintf(&sysfs_path,
- "/sys/class/iscsi_session/session%s/device", session) < 0)
- return -1;
+ sysfs_path = g_strdup_printf("/sys/class/iscsi_session/session%s/device",
+ session);
if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0)
return -1;
return NULL;
}
if (source->hosts[0].port == 0) {
- ignore_value(virAsprintf(&portal, "%s:%d",
+ portal = g_strdup_printf("%s:%d",
source->hosts[0].name,
- ISCSI_DEFAULT_TARGET_PORT));
+ ISCSI_DEFAULT_TARGET_PORT);
} else if (strchr(source->hosts[0].name, ':')) {
- ignore_value(virAsprintf(&portal, "[%s]:%d",
+ portal = g_strdup_printf("[%s]:%d",
source->hosts[0].name,
- source->hosts[0].port));
+ source->hosts[0].port);
} else {
- ignore_value(virAsprintf(&portal, "%s:%d",
+ portal = g_strdup_printf("%s:%d",
source->hosts[0].name,
- source->hosts[0].port));
+ source->hosts[0].port);
}
return portal;
}
{
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
- if (virAsprintf(&vol->name, "%s%u", VOL_NAME_PREFIX, lun) < 0)
- return -1;
- if (virAsprintf(&vol->key, "ip-%s-iscsi-%s-lun-%u", portal,
- def->source.devices[0].path, lun) < 0)
- return -1;
- if (virAsprintf(&vol->target.path, "ip-%s-iscsi-%s-lun-%u", portal,
- def->source.devices[0].path, lun) < 0)
- return -1;
+ vol->name = g_strdup_printf("%s%u", VOL_NAME_PREFIX, lun);
+ vol->key = g_strdup_printf("ip-%s-iscsi-%s-lun-%u", portal,
+ def->source.devices[0].path, lun);
+ vol->target.path = g_strdup_printf("ip-%s-iscsi-%s-lun-%u", portal,
+ def->source.devices[0].path, lun);
return 0;
}
}
- if (vol->target.path == NULL) {
- if (virAsprintf(&vol->target.path, "%s/%s",
- def->target.path, vol->name) < 0)
- goto cleanup;
- }
+ if (vol->target.path == NULL)
+ vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
/* Mark the (s) sparse/snapshot lv, e.g. the lv created using
* the --virtualsize/-V option. We've already ignored the (t)hin
if (!(vol->target.backingStore = virStorageSourceNew()))
goto cleanup;
- if (virAsprintf(&vol->target.backingStore->path, "%s/%s",
- def->target.path, groups[1]) < 0)
- goto cleanup;
+ vol->target.backingStore->path = g_strdup_printf("%s/%s",
+ def->target.path, groups[1]);
vol->target.backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2;
vol->target.backingStore->type = VIR_STORAGE_TYPE_BLOCK;
vol->type = VIR_STORAGE_VOL_BLOCK;
VIR_FREE(vol->target.path);
- if (virAsprintf(&vol->target.path, "%s/%s",
- def->target.path, vol->name) < 0)
- return -1;
+ vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
if (virStorageBackendLogicalLVCreate(vol, def) < 0)
return -1;
vol->type = VIR_STORAGE_VOL_BLOCK;
- if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0)
- return -1;
+ (vol->name) = g_strdup_printf("dm-%u", devnum);
- if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0)
- return -1;
+ vol->target.path = g_strdup_printf("/dev/%s", dev);
if (virStorageBackendUpdateVolInfo(vol, true,
VIR_STORAGE_VOL_OPEN_DEFAULT, 0) < 0) {
if (is_mpath == 1) {
- if (virAsprintf(&map_device, "mapper/%s", names->name) < 0)
- return -1;
+ map_device = g_strdup_printf("mapper/%s", names->name);
if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
vol->target.allocation, info.obj_size, info.num_objs);
VIR_FREE(vol->target.path);
- if (virAsprintf(&vol->target.path, "%s/%s",
- def->source.name, vol->name) < 0)
- goto cleanup;
+ vol->target.path = g_strdup_printf("%s/%s", def->source.name, vol->name);
VIR_FREE(vol->key);
- if (virAsprintf(&vol->key, "%s/%s",
- def->source.name, vol->name) < 0)
- goto cleanup;
+ vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
ret = 0;
}
VIR_FREE(vol->target.path);
- if (virAsprintf(&vol->target.path, "%s/%s",
- def->source.name, vol->name) < 0)
- return -1;
+ vol->target.path = g_strdup_printf("%s/%s", def->source.name, vol->name);
VIR_FREE(vol->key);
- if (virAsprintf(&vol->key, "%s/%s",
- def->source.name, vol->name) < 0)
- return -1;
+ vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
return 0;
}
VIR_DEBUG("Triggering rescan of host %d", host);
- if (virAsprintf(&path, "%s/host%u/scan",
- LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0)
- return -1;
+ path = g_strdup_printf("%s/host%u/scan", LINUX_SYSFS_SCSI_HOST_PREFIX, host);
VIR_DEBUG("Scan trigger path is '%s'", path);
goto cleanup;
}
- if (virAsprintf(&scsi_host_name, "scsi_%s", name) < 0)
- goto cleanup;
+ scsi_host_name = g_strdup_printf("scsi_%s", name);
if (!(vhba_parent = virNodeDeviceGetParentName(conn, scsi_host_name)))
goto cleanup;
if (virSCSIHostGetNumber(name, &host) < 0)
return -1;
- if (virAsprintf(&path, "%s/host%d",
- LINUX_SYSFS_SCSI_HOST_PREFIX, host) < 0)
- return -1;
+ path = g_strdup_printf("%s/host%d", LINUX_SYSFS_SCSI_HOST_PREFIX, host);
*isActive = virFileExists(path);
vol->type = VIR_STORAGE_VOL_NETWORK;
VIR_FREE(vol->key);
- if (virAsprintf(&vol->key, "%s/%s",
- def->source.name, vol->name) < 0)
- return -1;
+ vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
VIR_FREE(vol->target.path);
vol->target.path = g_strdup(vol->name);
vol->type = VIR_STORAGE_VOL_NETWORK;
VIR_FREE(vol->key);
- if (virAsprintf(&vol->key, "%s/%s", def->source.name, vol->name) < 0)
- return -1;
+ vol->key = g_strdup_printf("%s/%s", def->source.name, vol->name);
VIR_FREE(vol->target.path);
vol->target.path = g_strdup(vol->name);
if (!(usr_name = virGetUserName(def->target.perms.uid)))
return -1;
- if (virAsprintf(&mode, "%o", def->target.perms.mode) < 0)
- return -1;
+ mode = g_strdup_printf("%o", def->target.perms.mode);
cmd = virCommandNewArgList(VSTORAGE_MOUNT,
"-c", def->source.name,
char buf[1024];
g_autofree char *cluster = NULL;
- if (virAsprintf(&cluster, "vstorage://%s", def->source.name) < 0)
- return -1;
+ cluster = g_strdup_printf("vstorage://%s", def->source.name);
if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
virReportSystemError(errno,
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
g_autofree char *devpath = NULL;
- if (virAsprintf(&devpath, "/dev/zvol/%s",
- def->source.name) < 0)
- return -1;
+ devpath = g_strdup_printf("/dev/zvol/%s", def->source.name);
*isActive = virFileIsDir(devpath);
return 0;
volume->key = g_strdup(tokens[0]);
if (volume->target.path == NULL) {
- if (virAsprintf(&volume->target.path, "%s/%s",
- def->target.path, volume->name) < 0)
- goto cleanup;
+ volume->target.path = g_strdup_printf("%s/%s", def->target.path,
+ volume->name);
}
if (virStrToLong_ull(tokens[1], NULL, 10, &volume->target.capacity) < 0) {
vol->type = VIR_STORAGE_VOL_BLOCK;
VIR_FREE(vol->target.path);
- if (virAsprintf(&vol->target.path, "%s/%s",
- def->target.path, vol->name) < 0)
- return -1;
+ vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
vol->key = g_strdup(vol->target.path);
if (!(configdir && rundir))
goto error;
- if ((virAsprintf(&driver->configDir,
- "%s/storage", configdir) < 0) ||
- (virAsprintf(&driver->autostartDir,
- "%s/storage/autostart", configdir) < 0) ||
- (virAsprintf(&driver->stateDir,
- "%s/storage/run", rundir) < 0))
- goto error;
+ driver->configDir = g_strdup_printf("%s/storage", configdir);
+ driver->autostartDir = g_strdup_printf("%s/storage/autostart", configdir);
+ driver->stateDir = g_strdup_printf("%s/storage/run", rundir);
}
driver->privileged = privileged;
g_autofree char *refresh_tool = NULL;
g_autofree char *desc = NULL;
- if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0)
- return -1;
+ desc = g_strdup_printf("%s/DiskDescriptor.xml", path);
if (virFileRemove(desc, 0, 0) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
char *tmp = NULL;
- ignore_value(virAsprintf(&tmp, "%s/%s.%s.secret.XXXXXX",
- driver->stateDir, def->name, voldef->name));
+ tmp = g_strdup_printf("%s/%s.%s.secret.XXXXXX",
+ driver->stateDir, def->name, voldef->name);
return tmp;
}
priv)))
return NULL;
- ignore_value(virAsprintf(&priv->canonpath, "gluster://%s:%u/%s/%s",
- src->hosts->name,
- src->hosts->port,
- src->volume,
- filePath));
+ priv->canonpath = g_strdup_printf("gluster://%s:%u/%s/%s",
+ src->hosts->name,
+ src->hosts->port,
+ src->volume,
+ filePath);
return priv->canonpath;
}
/* Convert relative backing store paths to absolute paths for access
* validation.
*/
- if ('/' != *(info->backingPath) &&
- virAsprintf(&absolutePath, "%s/%s", def->target.path,
- info->backingPath) < 0)
- return -1;
+ if (*(info->backingPath) != '/')
+ absolutePath = g_strdup_printf("%s/%s", def->target.path, info->backingPath);
accessRetCode = access(absolutePath ? absolutePath :
info->backingPath, R_OK);
if (accessRetCode != 0) {
_("path to secret data file is required"));
goto error;
}
- if (virAsprintf(&info.secretAlias, "%s_encrypt0", vol->name) < 0)
- goto error;
+ info.secretAlias = g_strdup_printf("%s_encrypt0", vol->name);
if (storageBackendCreateQemuImgSecretObject(cmd, secretPath,
info.secretAlias) < 0)
goto error;
_("path to inputvol secret data file is required"));
goto error;
}
- if (virAsprintf(&inputSecretAlias, "%s_encrypt0",
- inputvol->name) < 0)
- goto error;
+ inputSecretAlias = g_strdup_printf("%s_encrypt0", inputvol->name);
if (storageBackendCreateQemuImgSecretObject(cmd, inputSecretPath,
inputSecretAlias) < 0)
goto error;
g_autofree char *root = NULL;
g_autofree char *desc = NULL;
- if (virAsprintf(&root, "%s/root.hds", path) < 0)
- return false;
+ root = g_strdup_printf("%s/root.hds", path);
if (!virFileExists(root))
return false;
- if (virAsprintf(&desc, "%s/DiskDescriptor.xml", path) < 0)
- return false;
+ desc = g_strdup_printf("%s/DiskDescriptor.xml", path);
if (!virFileExists(desc))
return false;
{
g_autofree char *path = NULL;
- if (virAsprintf(&path, "%s/root.hds", target->path) < 0)
- return -1;
+ path = g_strdup_printf("%s/root.hds", target->path);
VIR_FORCE_CLOSE(*fd);
if ((*fd = virStorageBackendVolOpen(path, sb, flags)) < 0)
return -1;
*/
retry:
while ((direrr = virDirRead(dh, &dent, NULL)) > 0) {
- if (virAsprintf(&stablepath, "%s/%s",
- def->target.path, dent->d_name) < 0) {
- VIR_DIR_CLOSE(dh);
- return NULL;
- }
+ stablepath = g_strdup_printf("%s/%s", def->target.path, dent->d_name);
if (virFileLinkPointsTo(stablepath, devpath)) {
VIR_DIR_CLOSE(dh);
}
VIR_FREE(vol->target.path);
- if (virAsprintf(&vol->target.path, "%s/%s",
- def->target.path, vol->name) < 0)
- return -1;
+ vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
if (virFileExists(vol->target.path)) {
virReportError(VIR_ERR_OPERATION_INVALID,
storageBackendCreateQemuImgSecretPath(pool, vol)))
goto cleanup;
- if (virAsprintf(&secretAlias, "%s_encrypt0", vol->name) < 0)
- goto cleanup;
+ secretAlias = g_strdup_printf("%s_encrypt0", vol->name);
}
/* Round capacity as qemu-img resize errors out on sizes which are not
return -1;
}
- if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0)
- return -1;
+ path = g_strdup_printf("%s/root.hds", vol->target.path);
target_path = path;
}
" will be lost"));
return -1;
}
- if (virAsprintf(&path, "%s/root.hds", vol->target.path) < 0)
- return -1;
+ path = g_strdup_printf("%s/root.hds", vol->target.path);
target_path = path;
}
return -1;
}
- if (virAsprintf(&target_path, "%s/root.hds", vol->target.path) < 0)
- return -1;
+ target_path = g_strdup_printf("%s/root.hds", vol->target.path);
- if (virAsprintf(&disk_desc, "%s/DiskDescriptor.xml", vol->target.path) < 0)
- return -1;
+ disk_desc = g_strdup_printf("%s/DiskDescriptor.xml", vol->target.path);
if (storageBackendVolWipeLocalFile(target_path, algorithm,
vol->target.allocation, false) < 0)
vol->name = g_strdup(ent->d_name);
vol->type = VIR_STORAGE_VOL_FILE;
- if (virAsprintf(&vol->target.path, "%s/%s",
- def->target.path, vol->name) < 0)
- goto cleanup;
+ vol->target.path = g_strdup_printf("%s/%s", def->target.path, vol->name);
vol->key = g_strdup(vol->target.path);
* in the volume name. We only need uniqueness per-pool, so
* just leave 'host' out
*/
- if (virAsprintf(&(vol->name), "unit:%u:%u:%u", bus, target, lun) < 0)
- return -1;
+ vol->name = g_strdup_printf("unit:%u:%u:%u", bus, target, lun);
- if (virAsprintf(&devpath, "/dev/%s", dev) < 0)
- return -1;
+ devpath = g_strdup_printf("/dev/%s", dev);
VIR_DEBUG("Trying to create volume for '%s'", devpath);
int direrr;
g_autofree char *block_path = NULL;
- if (virAsprintf(&block_path, "%s/block", lun_path) < 0)
- goto cleanup;
+ block_path = g_strdup_printf("%s/block", lun_path);
VIR_DEBUG("Looking for block device in '%s'", block_path);
*block_device = NULL;
- if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u",
- host, bus, target, lun) < 0)
- goto cleanup;
+ lun_path = g_strdup_printf("/sys/bus/scsi/devices/%u:%u:%u:%u", host, bus,
+ target, lun);
if (virDirOpen(&lun_dir, lun_path) < 0)
goto cleanup;
FILE *typefile;
g_autofree char *type_path = NULL;
- if (virAsprintf(&type_path, "/sys/bus/scsi/devices/%u:%u:%u:%u/type",
- host, bus, target, lun) < 0)
- return -1;
+ type_path = g_strdup_printf("/sys/bus/scsi/devices/%u:%u:%u:%u/type", host,
+ bus, target, lun);
typefile = fopen(type_path, "r");
if (typefile == NULL) {
if (def->type == VIR_STORAGE_POOL_NETFS) {
if (def->source.format == VIR_STORAGE_POOL_NETFS_CIFS) {
- if (virAsprintf(&src, "//%s/%s",
- def->source.hosts[0].name,
- def->source.dir) < 0)
- return NULL;
+ src = g_strdup_printf("//%s/%s", def->source.hosts[0].name,
+ def->source.dir);
} else {
- if (virAsprintf(&src, "%s:%s",
- def->source.hosts[0].name,
- def->source.dir) < 0)
- return NULL;
+ src = g_strdup_printf("%s:%s", def->source.hosts[0].name,
+ def->source.dir);
}
} else {
src = g_strdup(def->source.devices[0].path);
virCommandPtr cmd = NULL;
g_autofree char *nfsVers = NULL;
- if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer > 0 &&
- virAsprintf(&nfsVers, "nfsvers=%u", def->source.protocolVer) < 0)
- return NULL;
+ if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer > 0)
+ nfsVers = g_strdup_printf("nfsvers=%u", def->source.protocolVer);
cmd = virCommandNew(cmdstr);
if (netauto)