qemu: Use g_strdup_printf() instead of virAsprintf()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Michal Privoznik 2019-10-22 15:26:14 +02:00
parent 183a60aa75
commit d4e5b98330
25 changed files with 357 additions and 588 deletions

View File

@ -916,10 +916,8 @@ qemuAgentGuestSync(qemuAgentPtr mon)
if (virTimeMillisNow(&id) < 0)
return -1;
if (virAsprintf(&sync_msg.txBuffer,
"{\"execute\":\"guest-sync\", "
"\"arguments\":{\"id\":%llu}}\n", id) < 0)
return -1;
sync_msg.txBuffer = g_strdup_printf("{\"execute\":\"guest-sync\", "
"\"arguments\":{\"id\":%llu}}\n", id);
sync_msg.txLength = strlen(sync_msg.txBuffer);
sync_msg.sync = true;
@ -1120,8 +1118,7 @@ qemuAgentCommand(qemuAgentPtr mon,
if (!(cmdstr = virJSONValueToString(cmd, false)))
goto cleanup;
if (virAsprintf(&msg.txBuffer, "%s" LINE_ENDING, cmdstr) < 0)
goto cleanup;
msg.txBuffer = g_strdup_printf("%s" LINE_ENDING, cmdstr);
msg.txLength = strlen(msg.txBuffer);
VIR_DEBUG("Send command '%s' for write, seconds = %d", cmdstr, seconds);

View File

@ -114,7 +114,8 @@ qemuAssignDeviceChrAlias(virDomainDefPtr def,
if (idx == -1 && (idx = qemuGetNextChrDevIndex(def, chr, prefix)) < 0)
return -1;
return virAsprintf(&chr->info.alias, "%s%zd", prefix, idx);
chr->info.alias = g_strdup_printf("%s%zd", prefix, idx);
return 0;
}
@ -141,13 +142,15 @@ qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
* different naming convention ("pcie.0"), because it is
* hardcoded that way in qemu.
*/
return virAsprintf(&controller->info.alias, "pcie.%d", controller->idx);
controller->info.alias = g_strdup_printf("pcie.%d", controller->idx);
return 0;
}
/* All other PCI controllers use the consistent "pci.%u"
* (including the hardcoded pci-root controller on
* multibus-capable qemus).
*/
return virAsprintf(&controller->info.alias, "pci.%d", controller->idx);
controller->info.alias = g_strdup_printf("pci.%d", controller->idx);
return 0;
} else if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE) {
/* for any machine based on e.g. I440FX or G3Beige, the
* first (and currently only) IDE controller is an integrated
@ -176,7 +179,8 @@ qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
/* all other controllers use the default ${type}${index} naming
* scheme for alias/id.
*/
return virAsprintf(&controller->info.alias, "%s%d", prefix, controller->idx);
controller->info.alias = g_strdup_printf("%s%d", prefix, controller->idx);
return 0;
}
@ -200,23 +204,20 @@ qemuAssignDeviceDiskAlias(virDomainDefPtr def,
if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI ||
controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
if (virAsprintf(&disk->info.alias, "%s%d-%d-%d", prefix,
disk->info.addr.drive.controller,
disk->info.addr.drive.bus,
disk->info.addr.drive.unit) < 0)
return -1;
disk->info.alias = g_strdup_printf("%s%d-%d-%d", prefix,
disk->info.addr.drive.controller,
disk->info.addr.drive.bus,
disk->info.addr.drive.unit);
} else {
if (virAsprintf(&disk->info.alias, "%s%d-%d-%d-%d", prefix,
disk->info.addr.drive.controller,
disk->info.addr.drive.bus,
disk->info.addr.drive.target,
disk->info.addr.drive.unit) < 0)
return -1;
disk->info.alias = g_strdup_printf("%s%d-%d-%d-%d", prefix,
disk->info.addr.drive.controller,
disk->info.addr.drive.bus,
disk->info.addr.drive.target,
disk->info.addr.drive.unit);
}
} else {
int idx = virDiskNameToIndex(disk->dst);
if (virAsprintf(&disk->info.alias, "%s-disk%d", prefix, idx) < 0)
return -1;
disk->info.alias = g_strdup_printf("%s-disk%d", prefix, idx);
}
}
@ -235,17 +236,13 @@ qemuAssignDeviceDiskAlias(virDomainDefPtr def,
break;
case VIR_DOMAIN_DISK_BUS_VIRTIO:
if (virAsprintf(&diskPriv->qomName,
"/machine/peripheral/%s/virtio-backend",
disk->info.alias) < 0)
return -1;
diskPriv->qomName = g_strdup_printf("/machine/peripheral/%s/virtio-backend",
disk->info.alias);
break;
case VIR_DOMAIN_DISK_BUS_USB:
if (virAsprintf(&diskPriv->qomName,
"/machine/peripheral/%s/%s.0/legacy[0]",
disk->info.alias, disk->info.alias) < 0)
return -1;
diskPriv->qomName = g_strdup_printf("/machine/peripheral/%s/%s.0/legacy[0]",
disk->info.alias, disk->info.alias);
break;
case VIR_DOMAIN_DISK_BUS_XEN:
@ -291,8 +288,7 @@ qemuAssignDeviceHostdevAlias(virDomainDefPtr def,
}
}
if (virAsprintf(alias, "hostdev%d", idx) < 0)
return -1;
*alias = g_strdup_printf("hostdev%d", idx);
return 0;
}
@ -327,8 +323,7 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def,
}
}
if (virAsprintf(&net->info.alias, "net%d", idx) < 0)
return -1;
net->info.alias = g_strdup_printf("net%d", idx);
return 0;
}
@ -340,7 +335,8 @@ qemuAssignDeviceFSAlias(virDomainFSDefPtr fss,
if (fss->info.alias)
return 0;
return virAsprintf(&fss->info.alias, "fs%d", idx);
fss->info.alias = g_strdup_printf("fs%d", idx);
return 0;
}
@ -351,7 +347,8 @@ qemuAssignDeviceSoundAlias(virDomainSoundDefPtr sound,
if (sound->info.alias)
return 0;
return virAsprintf(&sound->info.alias, "sound%d", idx);
sound->info.alias = g_strdup_printf("sound%d", idx);
return 0;
}
@ -362,7 +359,8 @@ qemuAssignDeviceVideoAlias(virDomainVideoDefPtr video,
if (video->info.alias)
return 0;
return virAsprintf(&video->info.alias, "video%d", idx);
video->info.alias = g_strdup_printf("video%d", idx);
return 0;
}
@ -373,7 +371,8 @@ qemuAssignDeviceHubAlias(virDomainHubDefPtr hub,
if (hub->info.alias)
return 0;
return virAsprintf(&hub->info.alias, "hub%d", idx);
hub->info.alias = g_strdup_printf("hub%d", idx);
return 0;
}
@ -384,7 +383,8 @@ qemuAssignDeviceSmartcardAlias(virDomainSmartcardDefPtr smartcard,
if (smartcard->info.alias)
return 0;
return virAsprintf(&smartcard->info.alias, "smartcard%d", idx);
smartcard->info.alias = g_strdup_printf("smartcard%d", idx);
return 0;
}
@ -395,7 +395,8 @@ qemuAssingDeviceMemballoonAlias(virDomainMemballoonDefPtr memballoon,
if (memballoon->info.alias)
return 0;
return virAsprintf(&memballoon->info.alias, "balloon%d", idx);
memballoon->info.alias = g_strdup_printf("balloon%d", idx);
return 0;
}
@ -406,7 +407,8 @@ qemuAssignDeviceTPMAlias(virDomainTPMDefPtr tpm,
if (tpm->info.alias)
return 0;
return virAsprintf(&tpm->info.alias, "tpm%d", idx);
tpm->info.alias = g_strdup_printf("tpm%d", idx);
return 0;
}
@ -430,8 +432,7 @@ qemuAssignDeviceRedirdevAlias(virDomainDefPtr def,
}
}
if (virAsprintf(&redirdev->info.alias, "redir%d", idx) < 0)
return -1;
redirdev->info.alias = g_strdup_printf("redir%d", idx);
return 0;
}
@ -452,8 +453,7 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def,
maxidx = idx + 1;
}
if (virAsprintf(&rng->info.alias, "rng%d", maxidx) < 0)
return -1;
rng->info.alias = g_strdup_printf("rng%d", maxidx);
return 0;
}
@ -498,8 +498,7 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def,
maxidx = mem->info.addr.dimm.slot;
}
if (virAsprintf(&mem->info.alias, "%s%d", prefix, maxidx) < 0)
return -1;
mem->info.alias = g_strdup_printf("%s%d", prefix, maxidx);
return 0;
}
@ -528,8 +527,7 @@ qemuAssignDeviceShmemAlias(virDomainDefPtr def,
}
}
if (virAsprintf(&shmem->info.alias, "shmem%d", idx) < 0)
return -1;
shmem->info.alias = g_strdup_printf("shmem%d", idx);
return 0;
}
@ -565,8 +563,7 @@ qemuAssignDeviceInputAlias(virDomainDefPtr def,
}
}
if (virAsprintf(&input->info.alias, "input%d", idx) < 0)
return -1;
input->info.alias = g_strdup_printf("input%d", idx);
return 0;
}
@ -706,9 +703,7 @@ qemuAliasDiskDriveFromDisk(const virDomainDiskDef *disk)
return NULL;
}
ignore_value(virAsprintf(&ret, "%s%s", QEMU_DRIVE_HOST_PREFIX,
disk->info.alias));
ret = g_strdup_printf("%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
return ret;
}
@ -744,9 +739,9 @@ qemuAliasFromHostdev(const virDomainHostdevDef *hostdev)
return NULL;
}
ignore_value(virAsprintf(&ret, "%s-%s",
virDomainDeviceAddressTypeToString(hostdev->info->type),
hostdev->info->alias));
ret = g_strdup_printf("%s-%s",
virDomainDeviceAddressTypeToString(hostdev->info->type),
hostdev->info->alias);
return ret;
}
@ -789,9 +784,9 @@ qemuDomainGetSecretAESAlias(const char *srcalias,
}
if (isLuks)
ignore_value(virAsprintf(&alias, "%s-luks-secret0", srcalias));
alias = g_strdup_printf("%s-luks-secret0", srcalias);
else
ignore_value(virAsprintf(&alias, "%s-secret0", srcalias));
alias = g_strdup_printf("%s-secret0", srcalias);
return alias;
}
@ -807,7 +802,7 @@ qemuAliasTLSObjFromSrcAlias(const char *srcAlias)
{
char *ret;
ignore_value(virAsprintf(&ret, "obj%s_tls0", srcAlias));
ret = g_strdup_printf("obj%s_tls0", srcAlias);
return ret;
}
@ -823,7 +818,7 @@ qemuAliasChardevFromDevAlias(const char *devAlias)
{
char *ret;
ignore_value(virAsprintf(&ret, "char%s", devAlias));
ret = g_strdup_printf("char%s", devAlias);
return ret;
}
@ -841,7 +836,7 @@ qemuDomainGetUnmanagedPRAlias(const char *parentalias)
{
char *ret;
ignore_value(virAsprintf(&ret, "pr-helper-%s", parentalias));
ret = g_strdup_printf("pr-helper-%s", parentalias);
return ret;
}
@ -852,8 +847,7 @@ qemuAliasDBusVMStateFromId(const char *id)
char *ret;
size_t i;
if (virAsprintf(&ret, "dbus-vms-%s", id) < 0)
return NULL;
ret = g_strdup_printf("dbus-vms-%s", id);
for (i = 0; ret[i]; i++) {
if (ret[i] == ':')

View File

@ -423,22 +423,17 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src)
uri->scheme = g_strdup(virStorageNetProtocolTypeToString(src->protocol));
} else {
if (virAsprintf(&uri->scheme, "%s+%s",
virStorageNetProtocolTypeToString(src->protocol),
virStorageNetHostTransportTypeToString(src->hosts->transport)) < 0)
return NULL;
uri->scheme = g_strdup_printf("%s+%s",
virStorageNetProtocolTypeToString(src->protocol),
virStorageNetHostTransportTypeToString(src->hosts->transport));
}
if (src->path) {
if (src->volume) {
if (virAsprintf(&uri->path, "/%s/%s",
src->volume, src->path) < 0)
return NULL;
uri->path = g_strdup_printf("/%s/%s", src->volume, src->path);
} else {
if (virAsprintf(&uri->path, "%s%s",
src->path[0] == '/' ? "" : "/",
src->path) < 0)
return NULL;
uri->path = g_strdup_printf("%s%s", src->path[0] == '/' ? "" : "/",
src->path);
}
}
@ -477,8 +472,7 @@ qemuBlockStorageSourceBuildJSONSocketAddress(virStorageNetHostDefPtr host,
else
transport = "inet";
if (virAsprintf(&port, "%u", host->port) < 0)
return NULL;
port = g_strdup_printf("%u", host->port);
if (virJSONValueObjectCreate(&server,
"s:type", transport,
@ -570,8 +564,7 @@ qemuBlockStorageSourceBuildJSONInetSocketAddress(virStorageNetHostDefPtr host)
return NULL;
}
if (virAsprintf(&port, "%u", host->port) < 0)
return NULL;
port = g_strdup_printf("%u", host->port);
ignore_value(virJSONValueObjectCreate(&ret,
"s:host", host->name,
@ -767,13 +760,10 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src,
/* combine host and port into portal */
if (virSocketAddrNumericFamily(src->hosts[0].name) == AF_INET6) {
if (virAsprintf(&portal, "[%s]:%u",
src->hosts[0].name, src->hosts[0].port) < 0)
return NULL;
portal = g_strdup_printf("[%s]:%u", src->hosts[0].name,
src->hosts[0].port);
} else {
if (virAsprintf(&portal, "%s:%u",
src->hosts[0].name, src->hosts[0].port) < 0)
return NULL;
portal = g_strdup_printf("%s:%u", src->hosts[0].name, src->hosts[0].port);
}
if (!onlytarget && src->auth) {
@ -1965,8 +1955,7 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
if (!(backingJSON = virJSONValueToString(backingProps, false)))
return NULL;
if (virAsprintf(&ret, "json:%s", backingJSON) < 0)
return NULL;
ret = g_strdup_printf("json:%s", backingJSON);
return ret;
}
@ -2048,11 +2037,11 @@ qemuBlockStorageSourceCreateGetEncryptionLUKS(virStorageSourcePtr src,
return -1;
if (src->encryption) {
if (src->encryption->encinfo.cipher_name &&
virAsprintf(&cipheralg, "%s-%u",
src->encryption->encinfo.cipher_name,
src->encryption->encinfo.cipher_size) < 0)
return -1;
if (src->encryption->encinfo.cipher_name) {
cipheralg = g_strdup_printf("%s-%u",
src->encryption->encinfo.cipher_name,
src->encryption->encinfo.cipher_size);
}
if (virJSONValueObjectAdd(props,
"S:cipher-alg", cipheralg,

View File

@ -227,8 +227,7 @@ qemuBlockJobDiskNewPull(virDomainObjPtr vm,
g_autofree char *jobname = NULL;
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
if (virAsprintf(&jobname, "pull-%s-%s", disk->dst, disk->src->nodeformat) < 0)
return NULL;
jobname = g_strdup_printf("pull-%s-%s", disk->dst, disk->src->nodeformat);
} else {
if (!(jobname = qemuAliasDiskDriveFromDisk(disk)))
return NULL;
@ -262,8 +261,7 @@ qemuBlockJobDiskNewCommit(virDomainObjPtr vm,
jobtype = QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT;
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
if (virAsprintf(&jobname, "commit-%s-%s", disk->dst, top->nodeformat) < 0)
return NULL;
jobname = g_strdup_printf("commit-%s-%s", disk->dst, top->nodeformat);
} else {
if (!(jobname = qemuAliasDiskDriveFromDisk(disk)))
return NULL;
@ -296,8 +294,7 @@ qemuBlockJobNewCreate(virDomainObjPtr vm,
if (storage)
nodename = src->nodestorage;
if (virAsprintf(&jobname, "create-%s", nodename) < 0)
return NULL;
jobname = g_strdup_printf("create-%s", nodename);
if (!(job = qemuBlockJobDataNew(QEMU_BLOCKJOB_TYPE_CREATE, jobname)))
return NULL;
@ -326,8 +323,7 @@ qemuBlockJobDiskNewCopy(virDomainObjPtr vm,
g_autofree char *jobname = NULL;
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
if (virAsprintf(&jobname, "copy-%s-%s", disk->dst, disk->src->nodeformat) < 0)
return NULL;
jobname = g_strdup_printf("copy-%s-%s", disk->dst, disk->src->nodeformat);
} else {
if (!(jobname = qemuAliasDiskDriveFromDisk(disk)))
return NULL;

View File

@ -737,8 +737,7 @@ virQEMUCapsFindBinary(const char *format,
char *ret = NULL;
char *binary = NULL;
if (virAsprintf(&binary, format, archstr) < 0)
return NULL;
binary = g_strdup_printf(format, archstr);
ret = virFindFileInPath(binary);
VIR_FREE(binary);
@ -2419,8 +2418,7 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
/* The QOM type for machine types is the machine type name
* followed by the -machine suffix */
if (virAsprintf(&type, "%s-machine", canon) < 0)
return -1;
type = g_strdup_printf("%s-machine", canon);
if ((nvalues = qemuMonitorGetObjectProps(mon, type, &values)) < 0)
return -1;
@ -4858,8 +4856,7 @@ virQEMUCapsCacheNew(const char *libDir,
virQEMUCapsCachePrivPtr priv = NULL;
struct utsname uts;
if (virAsprintf(&capsCacheDir, "%s/capabilities", cacheDir) < 0)
goto error;
capsCacheDir = g_strdup_printf("%s/capabilities", cacheDir);
if (!(cache = virFileCacheNew(capsCacheDir, "xml", &qemuCapsCacheHandlers)))
goto error;
@ -4876,9 +4873,8 @@ virQEMUCapsCacheNew(const char *libDir,
priv->runGid = runGid;
priv->kvmUsable = VIR_TRISTATE_BOOL_ABSENT;
if (uname(&uts) == 0 &&
virAsprintf(&priv->kernelVersion, "%s %s", uts.release, uts.version) < 0)
goto error;
if (uname(&uts) == 0)
priv->kernelVersion = g_strdup_printf("%s %s", uts.release, uts.version);
cleanup:
VIR_FREE(capsCacheDir);

View File

@ -92,16 +92,14 @@ qemuCheckpointWriteMetadata(virDomainObjPtr vm,
if (newxml == NULL)
return -1;
if (virAsprintf(&chkDir, "%s/%s", checkpointDir, vm->def->name) < 0)
return -1;
chkDir = g_strdup_printf("%s/%s", checkpointDir, vm->def->name);
if (virFileMakePath(chkDir) < 0) {
virReportSystemError(errno, _("cannot create checkpoint directory '%s'"),
chkDir);
return -1;
}
if (virAsprintf(&chkFile, "%s/%s.xml", chkDir, def->parent.name) < 0)
return -1;
chkFile = g_strdup_printf("%s/%s.xml", chkDir, def->parent.name);
return virXMLSaveFile(chkFile, NULL, "checkpoint-edit", newxml);
}
@ -127,9 +125,8 @@ qemuCheckpointDiscard(virQEMUDriverPtr driver,
return -1;
}
if (virAsprintf(&chkFile, "%s/%s/%s.xml", cfg->checkpointDir,
vm->def->name, chk->def->name) < 0)
return -1;
chkFile = g_strdup_printf("%s/%s/%s.xml", cfg->checkpointDir, vm->def->name,
chk->def->name);
if (!metadata_only) {
qemuDomainObjPrivatePtr priv = vm->privateData;

View File

@ -262,7 +262,7 @@ qemuVirCommandGetFDSet(virCommandPtr cmd, int fd)
return NULL;
}
ignore_value(virAsprintf(&result, "set=%d,fd=%d", idx, fd));
result = g_strdup_printf("set=%d,fd=%d", idx, fd);
return result;
}
@ -289,7 +289,7 @@ qemuVirCommandGetDevSet(virCommandPtr cmd, int fd)
return NULL;
}
ignore_value(virAsprintf(&result, "/dev/fdset/%d", idx));
result = g_strdup_printf("/dev/fdset/%d", idx);
return result;
}
@ -791,10 +791,8 @@ qemuBuildGeneralSecinfoURI(virURIPtr uri,
_("found non printable characters in secret"));
return -1;
}
if (virAsprintf(&uri->user, "%s:%s",
secinfo->s.plain.username,
secinfo->s.plain.secret) < 0)
return -1;
uri->user = g_strdup_printf("%s:%s", secinfo->s.plain.username,
secinfo->s.plain.secret);
} else {
uri->user = g_strdup(secinfo->s.plain.username);
}
@ -943,9 +941,8 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src,
if (!(uri = qemuBlockStorageSourceGetURI(src)))
return NULL;
if (src->hosts->socket &&
virAsprintf(&uri->query, "socket=%s", src->hosts->socket) < 0)
return NULL;
if (src->hosts->socket)
uri->query = g_strdup_printf("socket=%s", src->hosts->socket);
if (qemuBuildGeneralSecinfoURI(uri, secinfo) < 0)
return NULL;
@ -1031,13 +1028,10 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
}
if (src->nhosts == 0) {
if (virAsprintf(&ret, "sheepdog:%s", src->path) < 0)
return NULL;
ret = g_strdup_printf("sheepdog:%s", src->path);
} else if (src->nhosts == 1) {
if (virAsprintf(&ret, "sheepdog:%s:%u:%s",
src->hosts->name, src->hosts->port,
src->path) < 0)
return NULL;
ret = g_strdup_printf("sheepdog:%s:%u:%s", src->hosts->name,
src->hosts->port, src->path);
} else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("protocol 'sheepdog' accepts up to one host"));
@ -2356,18 +2350,16 @@ qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
else
driveLetter = 'A';
if (bootindex &&
virAsprintf(&bootindexStr, "bootindex%c=%u", driveLetter, bootindex) < 0)
return -1;
if (bootindex)
bootindexStr = g_strdup_printf("bootindex%c=%u", driveLetter, bootindex);
/* with -blockdev we setup the floppy device and it's backend with -device */
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
if (qemuDomainDiskGetBackendAlias(disk, qemuCaps, &backendAlias) < 0)
return -1;
if (backendAlias &&
virAsprintf(&backendStr, "drive%c=%s", driveLetter, backendAlias) < 0)
return -1;
if (backendAlias)
backendStr = g_strdup_printf("drive%c=%s", driveLetter, backendAlias);
}
if (!explicitfdc) {
@ -3560,8 +3552,7 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def,
unsigned long long memsize = virDomainNumaGetNodeMemorySize(def->numa,
cell);
if (virAsprintf(&alias, "ram-node%zu", cell) < 0)
return -1;
alias = g_strdup_printf("ram-node%zu", cell);
mem.size = memsize;
mem.targetNode = cell;
@ -3594,8 +3585,7 @@ qemuBuildMemoryDimmBackendStr(virBufferPtr buf,
return -1;
}
if (virAsprintf(&alias, "mem%s", mem->info.alias) < 0)
return -1;
alias = g_strdup_printf("mem%s", mem->info.alias);
if (qemuBuildMemoryBackendProps(&props, alias, cfg,
priv, def, mem, true) < 0)
@ -3676,14 +3666,13 @@ qemuBuildLegacyNicStr(virDomainNetDefPtr net)
char macaddr[VIR_MAC_STRING_BUFLEN];
const char *netmodel = virDomainNetGetModelString(net);
ignore_value(virAsprintf(&str,
"nic,macaddr=%s,netdev=host%s%s%s%s%s",
virMacAddrFormat(&net->mac, macaddr),
net->info.alias,
netmodel ? ",model=" : "",
NULLSTR_EMPTY(netmodel),
(net->info.alias ? ",id=" : ""),
NULLSTR_EMPTY(net->info.alias)));
str = g_strdup_printf("nic,macaddr=%s,netdev=host%s%s%s%s%s",
virMacAddrFormat(&net->mac, macaddr),
net->info.alias,
netmodel ? ",model=" : "",
NULLSTR_EMPTY(netmodel),
(net->info.alias ? ",id=" : ""),
NULLSTR_EMPTY(net->info.alias));
return str;
}
@ -4654,8 +4643,7 @@ qemuBuildVhostUserChardevStr(const char *alias,
return NULL;
}
if (virAsprintf(&chardev, "socket,id=chr-vu-%s,fd=%d", alias, *fd) < 0)
return NULL;
chardev = g_strdup_printf("socket,id=chr-vu-%s,fd=%d", alias, *fd);
virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
*fd = -1;
@ -5473,10 +5461,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
if (virSCSIVHostOpenVhostSCSI(&vhostfd) < 0)
return -1;
if (virAsprintf(&vhostfdName, "%d", vhostfd) < 0) {
VIR_FORCE_CLOSE(vhostfd);
return -1;
}
vhostfdName = g_strdup_printf("%d", vhostfd);
virCommandPassFD(cmd, vhostfd,
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
@ -5706,8 +5691,7 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
g_autofree char *objAlias = NULL;
g_autofree char *charBackendAlias = NULL;
if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0)
return -1;
objAlias = g_strdup_printf("obj%s", rng->info.alias);
switch ((virDomainRNGBackend) rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
@ -8469,8 +8453,7 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
int slirpfd = qemuSlirpGetFD(slirp);
virCommandPassFD(cmd, slirpfd,
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
if (virAsprintf(&slirpfdName, "%d", slirpfd) < 0)
goto cleanup;
slirpfdName = g_strdup_printf("%d", slirpfd);
}
@ -8478,16 +8461,14 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
if (qemuSecuritySetTapFDLabel(driver->securityManager,
def, tapfd[i]) < 0)
goto cleanup;
if (virAsprintf(&tapfdName[i], "%d", tapfd[i]) < 0)
goto cleanup;
tapfdName[i] = g_strdup_printf("%d", tapfd[i]);
virCommandPassFD(cmd, tapfd[i],
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
tapfd[i] = -1;
}
for (i = 0; i < vhostfdSize; i++) {
if (virAsprintf(&vhostfdName[i], "%d", vhostfd[i]) < 0)
goto cleanup;
vhostfdName[i] = g_strdup_printf("%d", vhostfd[i]);
virCommandPassFD(cmd, vhostfd[i],
VIR_COMMAND_PASS_FD_CLOSE_PARENT);
vhostfd[i] = -1;
@ -8857,11 +8838,9 @@ qemuBuildShmemBackendMemProps(virDomainShmemDefPtr shmem)
g_autofree char *mem_path = NULL;
virJSONValuePtr ret = NULL;
if (virAsprintf(&mem_path, "/dev/shm/%s", shmem->name) < 0)
return NULL;
mem_path = g_strdup_printf("/dev/shm/%s", shmem->name);
if (virAsprintf(&mem_alias, "shmmem-%s", shmem->info.alias) < 0)
return NULL;
mem_alias = g_strdup_printf("shmmem-%s", shmem->info.alias);
qemuMonitorCreateObjectProps(&ret, "memory-backend-file", mem_alias,
"s:mem-path", mem_path,
@ -9585,9 +9564,8 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
virBufferAddLit(&buf, ",chardev=chrtpm");
if (virAsprintf(chardev, "socket,id=chrtpm,path=%s",
tpm->data.emulator.source.data.nix.path) < 0)
return NULL;
*chardev = g_strdup_printf("socket,id=chrtpm,path=%s",
tpm->data.emulator.source.data.nix.path);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
@ -9669,15 +9647,13 @@ qemuBuildSEVCommandLine(virDomainObjPtr vm, virCommandPtr cmd,
virBufferAsprintf(&buf, ",policy=0x%x", sev->policy);
if (sev->dh_cert) {
if (virAsprintf(&path, "%s/dh_cert.base64", priv->libDir) < 0)
return -1;
path = g_strdup_printf("%s/dh_cert.base64", priv->libDir);
virBufferAsprintf(&buf, ",dh-cert-file=%s", path);
VIR_FREE(path);
}
if (sev->session) {
if (virAsprintf(&path, "%s/session.base64", priv->libDir) < 0)
return -1;
path = g_strdup_printf("%s/session.base64", priv->libDir);
virBufferAsprintf(&buf, ",session-file=%s", path);
VIR_FREE(path);
}
@ -10468,9 +10444,8 @@ static int
qemuBuildParallelChrDeviceStr(char **deviceStr,
virDomainChrDefPtr chr)
{
if (virAsprintf(deviceStr, "isa-parallel,chardev=char%s,id=%s",
chr->info.alias, chr->info.alias) < 0)
return -1;
*deviceStr = g_strdup_printf("isa-parallel,chardev=char%s,id=%s",
chr->info.alias, chr->info.alias);
return 0;
}
@ -10491,10 +10466,8 @@ qemuBuildChannelChrDeviceStr(char **deviceStr,
return ret;
port = virSocketAddrGetPort(chr->target.addr);
if (virAsprintf(deviceStr,
"user,guestfwd=tcp:%s:%i-chardev:char%s,id=%s",
addr, port, chr->info.alias, chr->info.alias) < 0)
return -1;
*deviceStr = g_strdup_printf("user,guestfwd=tcp:%s:%i-chardev:char%s,id=%s",
addr, port, chr->info.alias, chr->info.alias);
break;
case VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO:

View File

@ -131,49 +131,29 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
cfg->cgroupControllers = -1; /* -1 == auto-detect */
if (privileged) {
if (virAsprintf(&cfg->logDir,
"%s/log/libvirt/qemu", LOCALSTATEDIR) < 0)
return NULL;
cfg->logDir = g_strdup_printf("%s/log/libvirt/qemu", LOCALSTATEDIR);
if (virAsprintf(&cfg->swtpmLogDir,
"%s/log/swtpm/libvirt/qemu", LOCALSTATEDIR) < 0)
return NULL;
cfg->swtpmLogDir = g_strdup_printf("%s/log/swtpm/libvirt/qemu",
LOCALSTATEDIR);
cfg->configBaseDir = g_strdup(SYSCONFDIR "/libvirt");
if (virAsprintf(&cfg->stateDir,
"%s/libvirt/qemu", RUNSTATEDIR) < 0)
return NULL;
cfg->stateDir = g_strdup_printf("%s/libvirt/qemu", RUNSTATEDIR);
if (virAsprintf(&cfg->swtpmStateDir,
"%s/libvirt/qemu/swtpm", RUNSTATEDIR) < 0)
return NULL;
cfg->swtpmStateDir = g_strdup_printf("%s/libvirt/qemu/swtpm", RUNSTATEDIR);
if (virAsprintf(&cfg->cacheDir,
"%s/cache/libvirt/qemu", LOCALSTATEDIR) < 0)
return NULL;
cfg->cacheDir = g_strdup_printf("%s/cache/libvirt/qemu", LOCALSTATEDIR);
if (virAsprintf(&cfg->libDir,
"%s/lib/libvirt/qemu", LOCALSTATEDIR) < 0)
return NULL;
if (virAsprintf(&cfg->saveDir, "%s/save", cfg->libDir) < 0)
return NULL;
if (virAsprintf(&cfg->snapshotDir, "%s/snapshot", cfg->libDir) < 0)
return NULL;
if (virAsprintf(&cfg->checkpointDir, "%s/checkpoint", cfg->libDir) < 0)
return NULL;
if (virAsprintf(&cfg->autoDumpPath, "%s/dump", cfg->libDir) < 0)
return NULL;
if (virAsprintf(&cfg->channelTargetDir,
"%s/channel/target", cfg->libDir) < 0)
return NULL;
if (virAsprintf(&cfg->nvramDir, "%s/nvram", cfg->libDir) < 0)
return NULL;
if (virAsprintf(&cfg->memoryBackingDir, "%s/ram", cfg->libDir) < 0)
return NULL;
if (virAsprintf(&cfg->swtpmStorageDir, "%s/lib/libvirt/swtpm",
LOCALSTATEDIR) < 0)
return NULL;
cfg->libDir = g_strdup_printf("%s/lib/libvirt/qemu", LOCALSTATEDIR);
cfg->saveDir = g_strdup_printf("%s/save", cfg->libDir);
cfg->snapshotDir = g_strdup_printf("%s/snapshot", cfg->libDir);
cfg->checkpointDir = g_strdup_printf("%s/checkpoint", cfg->libDir);
cfg->autoDumpPath = g_strdup_printf("%s/dump", cfg->libDir);
cfg->channelTargetDir = g_strdup_printf("%s/channel/target", cfg->libDir);
cfg->nvramDir = g_strdup_printf("%s/nvram", cfg->libDir);
cfg->memoryBackingDir = g_strdup_printf("%s/ram", cfg->libDir);
cfg->swtpmStorageDir = g_strdup_printf("%s/lib/libvirt/swtpm",
LOCALSTATEDIR);
if (!virDoesUserExist("tss") ||
virGetUserID("tss", &cfg->swtpm_user) < 0)
cfg->swtpm_user = 0; /* fall back to root */
@ -188,55 +168,39 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
if (!cachedir)
return NULL;
if (virAsprintf(&cfg->logDir, "%s/qemu/log", cachedir) < 0)
return NULL;
if (virAsprintf(&cfg->swtpmLogDir, "%s/qemu/log", cachedir) < 0)
return NULL;
if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) < 0)
return NULL;
cfg->logDir = g_strdup_printf("%s/qemu/log", cachedir);
cfg->swtpmLogDir = g_strdup_printf("%s/qemu/log", cachedir);
cfg->cacheDir = g_strdup_printf("%s/qemu/cache", cachedir);
rundir = virGetUserRuntimeDirectory();
if (!rundir)
return NULL;
if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0)
return NULL;
cfg->stateDir = g_strdup_printf("%s/qemu/run", rundir);
if (virAsprintf(&cfg->swtpmStateDir, "%s/swtpm", cfg->stateDir) < 0)
return NULL;
cfg->swtpmStateDir = g_strdup_printf("%s/swtpm", cfg->stateDir);
if (!(cfg->configBaseDir = virGetUserConfigDirectory()))
return NULL;
if (virAsprintf(&cfg->libDir, "%s/qemu/lib", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->saveDir, "%s/qemu/save", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->snapshotDir, "%s/qemu/snapshot", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->checkpointDir, "%s/qemu/checkpoint", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->autoDumpPath, "%s/qemu/dump", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->channelTargetDir,
"%s/qemu/channel/target", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->nvramDir,
"%s/qemu/nvram", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->memoryBackingDir, "%s/qemu/ram", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->swtpmStorageDir, "%s/qemu/swtpm", cfg->configBaseDir) < 0)
return NULL;
cfg->libDir = g_strdup_printf("%s/qemu/lib", cfg->configBaseDir);
cfg->saveDir = g_strdup_printf("%s/qemu/save", cfg->configBaseDir);
cfg->snapshotDir = g_strdup_printf("%s/qemu/snapshot", cfg->configBaseDir);
cfg->checkpointDir = g_strdup_printf("%s/qemu/checkpoint",
cfg->configBaseDir);
cfg->autoDumpPath = g_strdup_printf("%s/qemu/dump", cfg->configBaseDir);
cfg->channelTargetDir = g_strdup_printf("%s/qemu/channel/target",
cfg->configBaseDir);
cfg->nvramDir = g_strdup_printf("%s/qemu/nvram", cfg->configBaseDir);
cfg->memoryBackingDir = g_strdup_printf("%s/qemu/ram", cfg->configBaseDir);
cfg->swtpmStorageDir = g_strdup_printf("%s/qemu/swtpm",
cfg->configBaseDir);
cfg->swtpm_user = (uid_t)-1;
cfg->swtpm_group = (gid_t)-1;
}
if (virAsprintf(&cfg->configDir, "%s/qemu", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->autostartDir, "%s/qemu/autostart", cfg->configBaseDir) < 0)
return NULL;
if (virAsprintf(&cfg->slirpStateDir, "%s/slirp", cfg->stateDir) < 0)
return NULL;
cfg->configDir = g_strdup_printf("%s/qemu", cfg->configBaseDir);
cfg->autostartDir = g_strdup_printf("%s/qemu/autostart", cfg->configBaseDir);
cfg->slirpStateDir = g_strdup_printf("%s/slirp", cfg->stateDir);
/* Set the default directory to find TLS X.509 certificates.
* This will then be used as a fallback if the service specific
@ -1405,12 +1369,8 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
cfg->firmwares, cfg->nfirmwares) < 0)
return NULL;
if (virAsprintf(&key, "%d:%d:%s:%s",
data.arch,
data.virttype,
NULLSTR(data.machine),
NULLSTR(data.path)) < 0)
return NULL;
key = g_strdup_printf("%d:%d:%s:%s", data.arch, data.virttype,
NULLSTR(data.machine), NULLSTR(data.path));
if (virHashAddEntry(domCapsCache, key, domCaps) < 0)
return NULL;
@ -1441,8 +1401,7 @@ qemuGetSharedDeviceKey(const char *device_path)
return NULL;
}
if (virAsprintf(&key, "%d:%d", maj, min) < 0)
return NULL;
key = g_strdup_printf("%d:%d", maj, min);
return key;
}
@ -1718,7 +1677,7 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev)
scsihostsrc->unit)))
return NULL;
ignore_value(virAsprintf(&dev_path, "/dev/%s", dev_name));
dev_path = g_strdup_printf("/dev/%s", dev_name);
return dev_path;
}
@ -1895,8 +1854,7 @@ qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage)
{
char *ret;
if (virAsprintf(&ret, "%s/libvirt/qemu", hugepage->mnt_dir) < 0)
return NULL;
ret = g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir);
return ret;
}
@ -1911,7 +1869,7 @@ qemuGetDomainHugepagePath(const virDomainDef *def,
char *ret = NULL;
if (base && domPath)
ignore_value(virAsprintf(&ret, "%s/%s", base, domPath));
ret = g_strdup_printf("%s/%s", base, domPath);
return ret;
}
@ -1959,11 +1917,11 @@ qemuGetDomainHupageMemPath(const virDomainDef *def,
}
int
void
qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
char **path)
{
return virAsprintf(path, "%s/libvirt/qemu", cfg->memoryBackingDir);
*path = g_strdup_printf("%s/libvirt/qemu", cfg->memoryBackingDir);
}
@ -1975,11 +1933,12 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *def,
g_autofree char *shortName = NULL;
g_autofree char *base = NULL;
if (!(shortName = virDomainDefGetShortName(def)) ||
qemuGetMemoryBackingBasePath(cfg, &base) < 0 ||
virAsprintf(path, "%s/%s", base, shortName) < 0)
if (!(shortName = virDomainDefGetShortName(def)))
return -1;
qemuGetMemoryBackingBasePath(cfg, &base);
*path = g_strdup_printf("%s/%s", base, shortName);
return 0;
}
@ -2011,9 +1970,9 @@ qemuGetMemoryBackingPath(const virDomainDef *def,
return -1;
}
if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0 ||
virAsprintf(memPath, "%s/%s", domainPath, alias) < 0)
if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0)
return -1;
*memPath = g_strdup_printf("%s/%s", domainPath, alias);
return 0;
}

View File

@ -376,8 +376,8 @@ int qemuGetDomainHupageMemPath(const virDomainDef *def,
unsigned long long pagesize,
char **memPath);
int qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
char **path);
void qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
char **path);
int qemuGetMemoryBackingDomainPath(const virDomainDef *def,
virQEMUDriverConfigPtr cfg,
char **path);

View File

@ -2017,28 +2017,21 @@ qemuDomainSecretPrepare(virQEMUDriverPtr driver,
/* This is the old way of setting up per-domain directories */
static int
static void
qemuDomainSetPrivatePathsOld(virQEMUDriverPtr driver,
virDomainObjPtr vm)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int ret = -1;
if (!priv->libDir &&
virAsprintf(&priv->libDir, "%s/domain-%s",
cfg->libDir, vm->def->name) < 0)
goto cleanup;
if (!priv->libDir)
priv->libDir = g_strdup_printf("%s/domain-%s", cfg->libDir, vm->def->name);
if (!priv->channelTargetDir &&
virAsprintf(&priv->channelTargetDir, "%s/domain-%s",
cfg->channelTargetDir, vm->def->name) < 0)
goto cleanup;
if (!priv->channelTargetDir)
priv->channelTargetDir = g_strdup_printf("%s/domain-%s",
cfg->channelTargetDir, vm->def->name);
ret = 0;
cleanup:
virObjectUnref(cfg);
return ret;
}
@ -2054,14 +2047,12 @@ qemuDomainSetPrivatePaths(virQEMUDriverPtr driver,
if (!domname)
goto cleanup;
if (!priv->libDir &&
virAsprintf(&priv->libDir, "%s/domain-%s", cfg->libDir, domname) < 0)
goto cleanup;
if (!priv->libDir)
priv->libDir = g_strdup_printf("%s/domain-%s", cfg->libDir, domname);
if (!priv->channelTargetDir &&
virAsprintf(&priv->channelTargetDir, "%s/domain-%s",
cfg->channelTargetDir, domname) < 0)
goto cleanup;
if (!priv->channelTargetDir)
priv->channelTargetDir = g_strdup_printf("%s/domain-%s",
cfg->channelTargetDir, domname);
ret = 0;
cleanup:
@ -3671,8 +3662,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
priv->channelTargetDir = tmp;
tmp = NULL;
if (qemuDomainSetPrivatePathsOld(driver, vm) < 0)
goto error;
qemuDomainSetPrivatePathsOld(driver, vm);
if (virCPUDefParseXML(ctxt, "./cpu", VIR_CPU_TYPE_GUEST, &priv->origCPU) < 0)
goto error;
@ -4665,8 +4655,7 @@ qemuDomainDefPostParse(virDomainDefPtr def,
goto cleanup;
}
if (qemuDomainNVRAMPathGenerate(cfg, def) < 0)
goto cleanup;
qemuDomainNVRAMPathGenerate(cfg, def);
if (qemuDomainDefAddDefaultDevices(def, qemuCaps) < 0)
goto cleanup;
@ -9361,8 +9350,7 @@ qemuDomainLogContextPtr qemuDomainLogContextNew(virQEMUDriverPtr driver,
ctxt->writefd = -1;
ctxt->readfd = -1;
if (virAsprintf(&ctxt->path, "%s/%s.log", cfg->logDir, vm->def->name) < 0)
goto error;
ctxt->path = g_strdup_printf("%s/%s.log", cfg->logDir, vm->def->name);
if (cfg->stdioLogD) {
ctxt->manager = virLogManagerNew(virQEMUDriverIsPrivileged(driver));
@ -9542,8 +9530,7 @@ qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
VIR_DEBUG("Append log message (vm='%s' message='%s) stdioLogD=%d",
vm->def->name, message, cfg->stdioLogD);
if (virAsprintf(&path, "%s/%s.log", cfg->logDir, vm->def->name) < 0)
goto cleanup;
path = g_strdup_printf("%s/%s.log", cfg->logDir, vm->def->name);
if (cfg->stdioLogD) {
if (!(manager = virLogManagerNew(virQEMUDriverIsPrivileged(driver))))
@ -9636,16 +9623,14 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
if (newxml == NULL)
return -1;
if (virAsprintf(&snapDir, "%s/%s", snapshotDir, vm->def->name) < 0)
goto cleanup;
snapDir = g_strdup_printf("%s/%s", snapshotDir, vm->def->name);
if (virFileMakePath(snapDir) < 0) {
virReportSystemError(errno, _("cannot create snapshot directory '%s'"),
snapDir);
goto cleanup;
}
if (virAsprintf(&snapFile, "%s/%s.xml", snapDir, def->parent.name) < 0)
goto cleanup;
snapFile = g_strdup_printf("%s/%s.xml", snapDir, def->parent.name);
ret = virXMLSaveFile(snapFile, NULL, "snapshot-edit", newxml);
@ -9778,9 +9763,8 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
}
}
if (virAsprintf(&snapFile, "%s/%s/%s.xml", cfg->snapshotDir,
vm->def->name, snap->def->name) < 0)
goto cleanup;
snapFile = g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def->name,
snap->def->name);
if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) {
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
@ -9867,23 +9851,21 @@ qemuDomainRemoveInactiveCommon(virQEMUDriverPtr driver,
if (qemuDomainSnapshotDiscardAllMetadata(driver, vm) < 0) {
VIR_WARN("unable to remove all snapshots for domain %s",
vm->def->name);
} else if (virAsprintf(&snapDir, "%s/%s", cfg->snapshotDir,
vm->def->name) < 0) {
VIR_WARN("unable to remove snapshot directory %s/%s",
cfg->snapshotDir, vm->def->name);
} else if (rmdir(snapDir) < 0 && errno != ENOENT) {
VIR_WARN("unable to remove snapshot directory %s", snapDir);
} else {
snapDir = g_strdup_printf("%s/%s", cfg->snapshotDir, vm->def->name);
if (rmdir(snapDir) < 0 && errno != ENOENT)
VIR_WARN("unable to remove snapshot directory %s", snapDir);
}
/* Remove any checkpoint metadata prior to removing the domain */
if (qemuCheckpointDiscardAllMetadata(driver, vm) < 0) {
VIR_WARN("unable to remove all checkpoints for domain %s",
vm->def->name);
} else if (virAsprintf(&chkDir, "%s/%s", cfg->checkpointDir,
vm->def->name) < 0) {
VIR_WARN("unable to remove checkpoint directory %s/%s",
cfg->checkpointDir, vm->def->name);
} else if (rmdir(chkDir) < 0 && errno != ENOENT) {
VIR_WARN("unable to remove checkpoint directory %s", chkDir);
} else {
chkDir = g_strdup_printf("%s/%s", cfg->checkpointDir,
vm->def->name);
if (rmdir(chkDir) < 0 && errno != ENOENT)
VIR_WARN("unable to remove checkpoint directory %s", chkDir);
}
qemuExtDevicesCleanupHost(driver, vm->def);
@ -10229,7 +10211,7 @@ qemuDomainStorageAlias(const char *device, int depth)
if (!depth)
alias = g_strdup(device);
else
ignore_value(virAsprintf(&alias, "%s.%d", device, depth));
alias = g_strdup_printf("%s.%d", device, depth);
return alias;
}
@ -11778,9 +11760,8 @@ ppc64VFIODeviceIsNV2Bridge(const char *device)
for (i = 0; i < G_N_ELEMENTS(nvlink2Files); i++) {
g_autofree char *file = NULL;
if ((virAsprintf(&file, "/sys/bus/pci/devices/%s/of_node/%s",
device, nvlink2Files[i])) < 0)
return false;
file = g_strdup_printf("/sys/bus/pci/devices/%s/of_node/%s",
device, nvlink2Files[i]);
if (!virFileExists(file))
return false;
@ -12459,19 +12440,16 @@ qemuDomainPrepareChannel(virDomainChrDefPtr channel,
return 0;
if (channel->target.name) {
if (virAsprintf(&channel->source->data.nix.path,
"%s/%s", domainChannelTargetDir,
channel->target.name) < 0)
return -1;
channel->source->data.nix.path = g_strdup_printf("%s/%s",
domainChannelTargetDir,
channel->target.name);
} else {
/* Generate a unique name */
if (virAsprintf(&channel->source->data.nix.path,
"%s/vioser-%02d-%02d-%02d.sock",
domainChannelTargetDir,
channel->info.addr.vioserial.controller,
channel->info.addr.vioserial.bus,
channel->info.addr.vioserial.port) < 0)
return -1;
channel->source->data.nix.path = g_strdup_printf("%s/vioser-%02d-%02d-%02d.sock",
domainChannelTargetDir,
channel->info.addr.vioserial.controller,
channel->info.addr.vioserial.bus,
channel->info.addr.vioserial.port);
}
return 0;
@ -12654,16 +12632,15 @@ qemuDomainPrepareStorageSourceTLS(virStorageSourcePtr src,
}
int
void
qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
{
if (!shmem->server.enabled ||
shmem->server.chr.data.nix.path)
return 0;
return;
return virAsprintf(&shmem->server.chr.data.nix.path,
"/var/lib/libvirt/shmem-%s-sock",
shmem->name);
shmem->server.chr.data.nix.path = g_strdup_printf("/var/lib/libvirt/shmem-%s-sock",
shmem->name);
}
@ -12989,9 +12966,7 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr cfg,
if (STREQ(mountpoint, "/dev"))
suffix = "dev";
if (virAsprintf(&path, "%s/%s.%s",
cfg->stateDir, domname, suffix) < 0)
goto cleanup;
path = g_strdup_printf("%s/%s.%s", cfg->stateDir, domname, suffix);
/* Now consider that @mountpoint is "/dev/blah/blah2".
* @suffix then points to "blah/blah2". However, caller
@ -13007,7 +12982,6 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr cfg,
tmp++;
}
cleanup:
VIR_FREE(domname);
return path;
}
@ -13172,9 +13146,8 @@ qemuDomainCreateDeviceRecursive(const char *device,
if (i == data->ndevMountsPath) {
/* Okay, @device is in /dev but not in any mount point under /dev.
* Create it. */
if (virAsprintf(&devicePath, "%s/%s",
data->path, device + strlen(QEMU_DEVPREFIX)) < 0)
goto cleanup;
devicePath = g_strdup_printf("%s/%s", data->path,
device + strlen(QEMU_DEVPREFIX));
if (virFileMakeParentPath(devicePath) < 0) {
virReportSystemError(errno,
@ -13228,10 +13201,7 @@ qemuDomainCreateDeviceRecursive(const char *device,
if ((c = strrchr(devTmp, '/')))
*(c + 1) = '\0';
if (virAsprintf(&tmp, "%s%s", devTmp, target) < 0) {
VIR_FREE(devTmp);
goto cleanup;
}
tmp = g_strdup_printf("%s%s", devTmp, target);
VIR_FREE(devTmp);
VIR_FREE(target);
target = g_steal_pointer(&tmp);
@ -13394,9 +13364,7 @@ qemuDomainSetupDev(virQEMUDriverConfigPtr cfg,
* tmpfs is limited to 64kb, since we only have device nodes in there
* and don't want to DOS the entire OS RAM usage
*/
if (virAsprintf(&opts,
"mode=755,size=65536%s", mount_options) < 0)
goto cleanup;
opts = g_strdup_printf("mode=755,size=65536%s", mount_options);
if (virFileSetupDev(data->path, opts) < 0)
goto cleanup;
@ -14205,10 +14173,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
if ((c = strrchr(fileTmp, '/')))
*(c + 1) = '\0';
if (virAsprintf(&tmp, "%s%s", fileTmp, target) < 0) {
VIR_FREE(fileTmp);
goto cleanup;
}
tmp = g_strdup_printf("%s%s", fileTmp, target);
VIR_FREE(fileTmp);
VIR_FREE(target);
target = g_steal_pointer(&tmp);
@ -14764,7 +14729,7 @@ qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk,
char *ret = NULL;
if (idx)
ignore_value(virAsprintf(&ret, "%s[%d]", disk->dst, idx));
ret = g_strdup_printf("%s[%d]", disk->dst, idx);
else
ret = g_strdup(disk->dst);
@ -15207,9 +15172,8 @@ qemuDomainPrepareStorageSourceBlockdev(virDomainDiskDefPtr disk,
{
src->id = qemuDomainStorageIdNew(priv);
if (virAsprintf(&src->nodestorage, "libvirt-%u-storage", src->id) < 0 ||
virAsprintf(&src->nodeformat, "libvirt-%u-format", src->id) < 0)
return -1;
src->nodestorage = g_strdup_printf("libvirt-%u-storage", src->id);
src->nodeformat = g_strdup_printf("libvirt-%u-format", src->id);
if (qemuDomainValidateStorageSource(src, priv->qemuCaps) < 0)
return -1;
@ -15242,9 +15206,8 @@ qemuDomainPrepareDiskSourceBlockdev(virDomainDiskDefPtr disk,
virStorageSourcePtr n;
if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON &&
!diskPriv->nodeCopyOnRead &&
virAsprintf(&diskPriv->nodeCopyOnRead, "libvirt-CoR-%s", disk->dst) < 0)
return -1;
!diskPriv->nodeCopyOnRead)
diskPriv->nodeCopyOnRead = g_strdup_printf("libvirt-CoR-%s", disk->dst);
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
if (qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0)
@ -15397,8 +15360,7 @@ qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv)
{
char *ret = NULL;
ignore_value(virAsprintf(&ret, "%s/%s.sock", priv->libDir,
qemuDomainGetManagedPRAlias()));
ret = g_strdup_printf("%s/%s.sock", priv->libDir, qemuDomainGetManagedPRAlias());
return ret;
}
@ -15485,27 +15447,25 @@ qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk)
}
int
void
qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
virDomainDefPtr def,
char **path)
{
return virAsprintf(path, "%s/%s_VARS.fd", cfg->nvramDir, def->name);
*path = g_strdup_printf("%s/%s_VARS.fd", cfg->nvramDir, def->name);
}
int
void
qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
virDomainDefPtr def)
{
if (def->os.loader &&
def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_PFLASH &&
def->os.loader->readonly == VIR_TRISTATE_BOOL_YES &&
!def->os.loader->nvram) {
return qemuDomainNVRAMPathFormat(cfg, def, &def->os.loader->nvram);
}
!def->os.loader->nvram)
qemuDomainNVRAMPathFormat(cfg, def, &def->os.loader->nvram);
return 0;
}

View File

@ -1054,7 +1054,7 @@ void qemuDomainPrepareChardevSource(virDomainDefPtr def,
virQEMUDriverConfigPtr cfg)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
void qemuDomainPrepareShmemChardev(virDomainShmemDefPtr shmem)
ATTRIBUTE_NONNULL(1);
bool qemuDomainVcpuHotplugIsInOrder(virDomainDefPtr def)
@ -1206,12 +1206,12 @@ qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr priv);
bool
qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk);
int
void
qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
virDomainDefPtr def,
char **path);
int
void
qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
virDomainDefPtr def);

View File

@ -942,8 +942,7 @@ qemuStateInitialize(bool privileged,
goto error;
}
if (qemuGetMemoryBackingBasePath(cfg, &memoryBackingPath) < 0)
goto error;
qemuGetMemoryBackingBasePath(cfg, &memoryBackingPath);
if (virFileMakePath(memoryBackingPath) < 0) {
virReportSystemError(errno,
@ -7745,8 +7744,7 @@ qemuDomainUndefineFlags(virDomainPtr dom,
}
if (vm->def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
if (qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path) < 0)
goto endjob;
qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path);
} else {
if (vm->def->os.loader)
nvram_path = g_strdup(vm->def->os.loader->nvram);

View File

@ -1056,8 +1056,7 @@ qemuFirmwareEnableFeatures(virQEMUDriverPtr driver,
VIR_FREE(def->os.loader->templt);
def->os.loader->templt = g_strdup(flash->nvram_template.filename);
if (qemuDomainNVRAMPathGenerate(cfg, def) < 0)
return -1;
qemuDomainNVRAMPathGenerate(cfg, def);
VIR_DEBUG("decided on firmware '%s' varstore template '%s'",
def->os.loader->path,

View File

@ -154,8 +154,7 @@ qemuDomainDetachZPCIDevice(qemuMonitorPtr mon,
{
g_autofree char *zpciAlias = NULL;
if (virAsprintf(&zpciAlias, "zpci%d", info->addr.pci.zpci.uid) < 0)
return -1;
zpciAlias = g_strdup_printf("zpci%d", info->addr.pci.zpci.uid);
if (qemuMonitorDelDevice(mon, zpciAlias) < 0)
return -1;
@ -1308,8 +1307,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
}
slirpfd = qemuSlirpGetFD(slirp);
if (virAsprintf(&slirpfdName, "slirpfd-%s", net->info.alias) < 0)
goto cleanup;
slirpfdName = g_strdup_printf("slirpfd-%s", net->info.alias);
}
break;
@ -1361,15 +1359,11 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
VIR_ALLOC_N(vhostfdName, vhostfdSize) < 0)
goto cleanup;
for (i = 0; i < tapfdSize; i++) {
if (virAsprintf(&tapfdName[i], "fd-%s%zu", net->info.alias, i) < 0)
goto cleanup;
}
for (i = 0; i < tapfdSize; i++)
tapfdName[i] = g_strdup_printf("fd-%s%zu", net->info.alias, i);
for (i = 0; i < vhostfdSize; i++) {
if (virAsprintf(&vhostfdName[i], "vhostfd-%s%zu", net->info.alias, i) < 0)
goto cleanup;
}
for (i = 0; i < vhostfdSize; i++)
vhostfdName[i] = g_strdup_printf("vhostfd-%s%zu", net->info.alias, i);
if (!(netstr = qemuBuildHostNetStr(net,
tapfdName, tapfdSize,
@ -1512,19 +1506,18 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
goto cleanup;
virErrorPreserveLast(&originalError);
if (virAsprintf(&netdev_name, "host%s", net->info.alias) >= 0) {
if (QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp)
qemuSlirpStop(QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp, vm, driver, net, true);
qemuDomainObjEnterMonitor(driver, vm);
if (charDevPlugged &&
qemuMonitorDetachCharDev(priv->mon, charDevAlias) < 0)
VIR_WARN("Failed to remove associated chardev %s", charDevAlias);
if (netdevPlugged &&
qemuMonitorRemoveNetdev(priv->mon, netdev_name) < 0)
VIR_WARN("Failed to remove network backend for netdev %s",
netdev_name);
ignore_value(qemuDomainObjExitMonitor(driver, vm));
}
netdev_name = g_strdup_printf("host%s", net->info.alias);
if (QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp)
qemuSlirpStop(QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp, vm, driver, net, true);
qemuDomainObjEnterMonitor(driver, vm);
if (charDevPlugged &&
qemuMonitorDetachCharDev(priv->mon, charDevAlias) < 0)
VIR_WARN("Failed to remove associated chardev %s", charDevAlias);
if (netdevPlugged &&
qemuMonitorRemoveNetdev(priv->mon, netdev_name) < 0)
VIR_WARN("Failed to remove network backend for netdev %s",
netdev_name);
ignore_value(qemuDomainObjExitMonitor(driver, vm));
virErrorRestore(&originalError);
goto cleanup;
}
@ -2364,8 +2357,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
if (qemuAssignDeviceMemoryAlias(vm->def, mem, priv->memAliasOrderMismatch) < 0)
goto cleanup;
if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0)
goto cleanup;
objalias = g_strdup_printf("mem%s", mem->info.alias);
if (!(devstr = qemuBuildMemoryDeviceStr(mem, priv)))
goto cleanup;
@ -2711,8 +2703,7 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriverPtr driver,
if (virSCSIVHostOpenVhostSCSI(&vhostfd) < 0)
goto cleanup;
if (virAsprintf(&vhostfdName, "vhostfd-%d", vhostfd) < 0)
goto cleanup;
vhostfdName = g_strdup_printf("vhostfd-%d", vhostfd);
if (hostdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
if (qemuDomainIsS390CCW(vm->def) &&
@ -2969,8 +2960,7 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
if (qemuAssignDeviceShmemAlias(vm->def, shmem, -1) < 0)
return -1;
if (qemuDomainPrepareShmemChardev(shmem) < 0)
return -1;
qemuDomainPrepareShmemChardev(shmem);
if (VIR_REALLOC_N(vm->def->shmems, vm->def->nshmems + 1) < 0)
return -1;
@ -2984,8 +2974,7 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
goto cleanup;
if (shmem->server.enabled) {
if (virAsprintf(&charAlias, "char%s", shmem->info.alias) < 0)
goto cleanup;
charAlias = g_strdup_printf("char%s", shmem->info.alias);
} else {
if (!(props = qemuBuildShmemBackendMemProps(shmem)))
goto cleanup;
@ -3257,8 +3246,7 @@ qemuDomainAttachVsockDevice(virQEMUDriverPtr driver,
if (qemuProcessOpenVhostVsock(vsock) < 0)
goto cleanup;
if (virAsprintf(&fdname, "%s%u", fdprefix, vsockPriv->vhostfd) < 0)
goto cleanup;
fdname = g_strdup_printf("%s%u", fdprefix, vsockPriv->vhostfd);
if (!(devstr = qemuBuildVsockDevStr(vm->def, vsock, priv->qemuCaps, fdprefix)))
goto cleanup;
@ -3991,8 +3979,7 @@ qemuDomainChangeGraphicsPasswords(virQEMUDriverPtr driver,
(auth->expires && auth->validTo <= now)) {
expire = "now";
} else if (auth->expires) {
if (virAsprintf(&validTo, "%lu", (unsigned long)auth->validTo) < 0)
goto end_job;
validTo = g_strdup_printf("%lu", (unsigned long)auth->validTo);
expire = validTo;
} else {
expire = "never";
@ -4347,8 +4334,7 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
VIR_DEBUG("Removing memory device %s from domain %p %s",
mem->info.alias, vm, vm->def->name);
if (virAsprintf(&backendAlias, "mem%s", mem->info.alias) < 0)
return -1;
backendAlias = g_strdup_printf("mem%s", mem->info.alias);
qemuDomainObjEnterMonitor(driver, vm);
rc = qemuMonitorDelObject(priv->mon, backendAlias);
@ -4566,8 +4552,8 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
VIR_DEBUG("Removing network interface %s from domain %p %s",
net->info.alias, vm, vm->def->name);
if (virAsprintf(&hostnet_name, "host%s", net->info.alias) < 0 ||
!(charDevAlias = qemuAliasChardevFromDevAlias(net->info.alias)))
hostnet_name = g_strdup_printf("host%s", net->info.alias);
if (!(charDevAlias = qemuAliasChardevFromDevAlias(net->info.alias)))
return -1;
if (virDomainNetGetActualBandwidth(net) &&
@ -4721,8 +4707,7 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
rng->info.alias, vm, vm->def->name);
if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0)
return -1;
objAlias = g_strdup_printf("obj%s", rng->info.alias);
if (!(charAlias = qemuAliasChardevFromDevAlias(rng->info.alias)))
return -1;
@ -4781,11 +4766,9 @@ qemuDomainRemoveShmemDevice(virQEMUDriverPtr driver,
shmem->info.alias, vm, vm->def->name);
if (shmem->server.enabled) {
if (virAsprintf(&charAlias, "char%s", shmem->info.alias) < 0)
return -1;
charAlias = g_strdup_printf("char%s", shmem->info.alias);
} else {
if (virAsprintf(&memAlias, "shmmem-%s", shmem->info.alias) < 0)
return -1;
memAlias = g_strdup_printf("shmmem-%s", shmem->info.alias);
}
qemuDomainObjEnterMonitor(driver, vm);
@ -6026,8 +6009,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
size_t i;
if (newhotplug) {
if (virAsprintf(&vcpupriv->alias, "vcpu%u", vcpu) < 0)
goto cleanup;
vcpupriv->alias = g_strdup_printf("vcpu%u", vcpu);
if (!(vcpuprops = qemuBuildHotpluggableCPUProps(vcpuinfo)))
goto cleanup;

View File

@ -364,9 +364,8 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
goto cleanup;
virCommandAbort(cmd);
if (errbuf && *errbuf &&
virAsprintf(&errstr, "\nstderr=%s", errbuf) < 0)
goto cleanup;
if (errbuf && *errbuf)
errstr = g_strdup_printf("\nstderr=%s", errbuf);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("%s: failed to communicate with bridge helper: %s%s"),

View File

@ -57,8 +57,7 @@ qemuBuildFileList(virHashTablePtr files, const char *dir)
filename = g_strdup(ent->d_name);
if (virAsprintf(&path, "%s/%s", dir, filename) < 0)
goto cleanup;
path = g_strdup_printf("%s/%s", dir, filename);
if (stat(path, &sb) < 0) {
virReportSystemError(errno, _("Unable to access %s"), path);
@ -122,12 +121,10 @@ qemuInteropFetchConfigs(const char *name,
if (!home)
return -1;
if (virAsprintf(&xdgConfig, "%s/.config", home) < 0)
return -1;
xdgConfig = g_strdup_printf("%s/.config", home);
}
if (virAsprintf(&homeConfig, "%s/qemu/%s", xdgConfig, name) < 0)
return -1;
homeConfig = g_strdup_printf("%s/qemu/%s", xdgConfig, name);
}
if (!(files = virHashCreate(10, virHashValueFree)))

View File

@ -818,9 +818,8 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver,
copysrc->tlsAlias = g_strdup(tlsAlias);
if (virAsprintf(&copysrc->nodestorage, "migration-%s-storage", disk->dst) < 0 ||
virAsprintf(&copysrc->nodeformat, "migration-%s-format", disk->dst) < 0)
return -1;
copysrc->nodestorage = g_strdup_printf("migration-%s-storage", disk->dst);
copysrc->nodeformat = g_strdup_printf("migration-%s-format", disk->dst);
/* Migration via blockdev-mirror was supported sooner than the auto-read-only
* feature was added to qemu */
@ -865,13 +864,11 @@ qemuMigrationSrcNBDStorageCopyDriveMirror(virQEMUDriverPtr driver,
int mon_ret;
if (strchr(host, ':')) {
if (virAsprintf(&nbd_dest, "nbd:[%s]:%d:exportname=%s",
host, port, diskAlias) < 0)
return -1;
nbd_dest = g_strdup_printf("nbd:[%s]:%d:exportname=%s", host, port,
diskAlias);
} else {
if (virAsprintf(&nbd_dest, "nbd:%s:%d:exportname=%s",
host, port, diskAlias) < 0)
return -1;
nbd_dest = g_strdup_printf("nbd:%s:%d:exportname=%s", host, port,
diskAlias);
}
if (qemuDomainObjEnterMonitorAsync(driver, vm,
@ -1834,7 +1831,7 @@ qemuMigrationDstGetURI(const char *migrateFrom,
char *uri = NULL;
if (STREQ(migrateFrom, "stdio"))
ignore_value(virAsprintf(&uri, "fd:%d", migrateFd));
uri = g_strdup_printf("fd:%d", migrateFd);
else
uri = g_strdup(migrateFrom);
@ -2258,9 +2255,7 @@ qemuMigrationDstPrepare(virDomainObjPtr vm,
incFormat = "%s:[%s]:%d";
else
incFormat = "%s:%s:%d";
if (virAsprintf(&migrateFrom, incFormat,
protocol, listenAddress, port) < 0)
goto cleanup;
migrateFrom = g_strdup_printf(incFormat, protocol, listenAddress, port);
}
inc = qemuProcessIncomingDefNew(priv->qemuCaps, listenAddress,
@ -2700,8 +2695,7 @@ qemuMigrationAnyParseURI(const char *uri, bool *wellFormed)
/* For compatibility reasons tcp://... URIs are sent as tcp:...
* We need to transform them to a well-formed URI before parsing. */
if (STRPREFIX(uri, "tcp:") && !STRPREFIX(uri + 4, "//")) {
if (virAsprintf(&tmp, "tcp://%s", uri + 4) < 0)
return NULL;
tmp = g_strdup_printf("tcp://%s", uri + 4);
uri = tmp;
}
@ -2796,8 +2790,7 @@ qemuMigrationDstPrepareDirect(virQEMUDriverPtr driver,
else
incFormat = "%s:%s:%d";
if (virAsprintf(uri_out, incFormat, "tcp", hostname, port) < 0)
goto cleanup;
*uri_out = g_strdup_printf(incFormat, "tcp", hostname, port);
} else {
bool well_formed_uri;
@ -2835,8 +2828,7 @@ qemuMigrationDstPrepareDirect(virQEMUDriverPtr driver,
if (!(*uri_out = virURIFormat(uri)))
goto cleanup;
} else {
if (virAsprintf(uri_out, "%s:%d", uri_in, port) < 0)
goto cleanup;
*uri_out = g_strdup_printf("%s:%d", uri_in, port);
}
} else {
port = uri->port;
@ -3302,8 +3294,7 @@ qemuMigrationSrcConnect(virQEMUDriverPtr driver,
int ret = -1;
host = spec->dest.host.name;
if (virAsprintf(&port, "%d", spec->dest.host.port) < 0)
return -1;
port = g_strdup_printf("%d", spec->dest.host.port);
spec->destType = MIGRATION_DEST_FD;
spec->dest.fd.qemu = -1;

View File

@ -141,8 +141,7 @@ qemuDomainExtractTLSSubject(const char *certdir)
int ret;
size_t subjectlen;
if (virAsprintf(&certfile, "%s/server-cert.pem", certdir) < 0)
goto error;
certfile = g_strdup_printf("%s/server-cert.pem", certdir);
if (virFileReadAll(certfile, 8192, &pemdata) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,

View File

@ -961,7 +961,7 @@ qemuMonitorNextCommandID(qemuMonitorPtr mon)
{
char *id;
ignore_value(virAsprintf(&id, "libvirt-%d", ++mon->nextSerial));
id = g_strdup_printf("libvirt-%d", ++mon->nextSerial);
return id;
}
@ -2560,11 +2560,8 @@ qemuMonitorMigrateToHost(qemuMonitorPtr mon,
QEMU_CHECK_MONITOR(mon);
if (strchr(hostname, ':')) {
if (virAsprintf(&uri, "%s:[%s]:%d", protocol, hostname, port) < 0)
return -1;
} else if (virAsprintf(&uri, "%s:%s:%d", protocol, hostname, port) < 0) {
return -1;
}
uri = g_strdup_printf("%s:[%s]:%d", protocol, hostname, port);
} else uri = g_strdup_printf("%s:%s:%d", protocol, hostname, port);
ret = qemuMonitorJSONMigrate(mon, flags, uri);
@ -4249,20 +4246,19 @@ qemuMonitorGuestPanicEventInfoFormatMsg(qemuMonitorEventPanicInfoPtr info)
switch (info->type) {
case QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_HYPERV:
ignore_value(virAsprintf(&ret,
"hyper-v: arg1='0x%llx', arg2='0x%llx', "
"arg3='0x%llx', arg4='0x%llx', arg5='0x%llx'",
info->data.hyperv.arg1, info->data.hyperv.arg2,
info->data.hyperv.arg3, info->data.hyperv.arg4,
info->data.hyperv.arg5));
ret = g_strdup_printf("hyper-v: arg1='0x%llx', arg2='0x%llx', "
"arg3='0x%llx', arg4='0x%llx', arg5='0x%llx'",
info->data.hyperv.arg1, info->data.hyperv.arg2,
info->data.hyperv.arg3, info->data.hyperv.arg4,
info->data.hyperv.arg5);
break;
case QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_S390:
ignore_value(virAsprintf(&ret, "s390: core='%d' psw-mask='0x%016llx' "
"psw-addr='0x%016llx' reason='%s'",
info->data.s390.core,
info->data.s390.psw_mask,
info->data.s390.psw_addr,
info->data.s390.reason));
ret = g_strdup_printf("s390: core='%d' psw-mask='0x%016llx' "
"psw-addr='0x%016llx' reason='%s'",
info->data.s390.core,
info->data.s390.psw_mask,
info->data.s390.psw_addr,
info->data.s390.reason);
break;
case QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_NONE:
case QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_LAST:

View File

@ -7117,8 +7117,7 @@ qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
switch ((virStorageNetHostTransport)server->transport) {
case VIR_STORAGE_NET_HOST_TRANS_TCP:
if (virAsprintf(&port_str, "%u", server->port) < 0)
return ret;
port_str = g_strdup_printf("%u", server->port);
addr = qemuMonitorJSONBuildInetSocketAddress(server->name, port_str);
break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX:
@ -8049,9 +8048,7 @@ qemuMonitorJSONSetIOThread(qemuMonitorPtr mon,
char *path = NULL;
qemuMonitorJSONObjectProperty prop;
if (virAsprintf(&path, "/objects/iothread%u",
iothreadInfo->iothread_id) < 0)
goto cleanup;
path = g_strdup_printf("/objects/iothread%u", iothreadInfo->iothread_id);
#define VIR_IOTHREAD_SET_PROP(propName, propVal) \
if (iothreadInfo->set_##propVal) { \
@ -8209,13 +8206,11 @@ qemuMonitorJSONFindObjectPathByAlias(qemuMonitorPtr mon,
if (npaths < 0)
return -1;
if (virAsprintf(&child, "child<%s>", name) < 0)
goto cleanup;
child = g_strdup_printf("child<%s>", name);
for (i = 0; i < npaths; i++) {
if (STREQ(paths[i]->name, alias) && STREQ(paths[i]->type, child)) {
if (virAsprintf(path, "/machine/peripheral/%s", alias) < 0)
goto cleanup;
*path = g_strdup_printf("/machine/peripheral/%s", alias);
ret = 0;
goto cleanup;
@ -8267,10 +8262,7 @@ qemuMonitorJSONFindObjectPathByName(qemuMonitorPtr mon,
if (STREQ_NULLABLE(paths[i]->type, name)) {
VIR_DEBUG("Path to '%s' is '%s/%s'", name, curpath, paths[i]->name);
ret = 0;
if (virAsprintf(path, "%s/%s", curpath, paths[i]->name) < 0) {
*path = NULL;
ret = -1;
}
*path = g_strdup_printf("%s/%s", curpath, paths[i]->name);
goto cleanup;
}
@ -8278,10 +8270,7 @@ qemuMonitorJSONFindObjectPathByName(qemuMonitorPtr mon,
* traversed looking for more entries
*/
if (paths[i]->type && STRPREFIX(paths[i]->type, "child<")) {
if (virAsprintf(&nextpath, "%s/%s", curpath, paths[i]->name) < 0) {
ret = -1;
goto cleanup;
}
nextpath = g_strdup_printf("%s/%s", curpath, paths[i]->name);
ret = qemuMonitorJSONFindObjectPathByName(mon, nextpath, name, path);
VIR_FREE(nextpath);
@ -8324,8 +8313,7 @@ qemuMonitorJSONFindLinkPath(qemuMonitorPtr mon,
return ret;
}
if (virAsprintf(&linkname, "link<%s>", name) < 0)
return -1;
linkname = g_strdup_printf("link<%s>", name);
ret = qemuMonitorJSONFindObjectPathByName(mon, "/", linkname, path);
VIR_FREE(linkname);

View File

@ -42,8 +42,7 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon,
/* 'dummy' here is just a placeholder since there is no PCI
* address required when attaching drives to a controller */
if (virAsprintf(&cmd, "drive_add dummy %s", drivestr) < 0)
goto cleanup;
cmd = g_strdup_printf("drive_add dummy %s", drivestr);
if (qemuMonitorJSONHumanCommand(mon, cmd, &reply) < 0)
goto cleanup;
@ -92,8 +91,7 @@ int qemuMonitorTextDriveDel(qemuMonitorPtr mon,
char *reply = NULL;
int ret = -1;
if (virAsprintf(&cmd, "drive_del %s", drivestr) < 0)
goto cleanup;
cmd = g_strdup_printf("drive_del %s", drivestr);
if (qemuMonitorJSONHumanCommand(mon, cmd, &reply) < 0)
goto cleanup;
@ -131,8 +129,7 @@ qemuMonitorTextCreateSnapshot(qemuMonitorPtr mon,
char *reply = NULL;
int ret = -1;
if (virAsprintf(&cmd, "savevm \"%s\"", name) < 0)
goto cleanup;
cmd = g_strdup_printf("savevm \"%s\"", name);
if (qemuMonitorJSONHumanCommand(mon, cmd, &reply))
goto cleanup;
@ -166,8 +163,7 @@ int qemuMonitorTextLoadSnapshot(qemuMonitorPtr mon, const char *name)
int ret = -1;
char *safename;
if (virAsprintf(&cmd, "loadvm \"%s\"", name) < 0)
goto cleanup;
cmd = g_strdup_printf("loadvm \"%s\"", name);
if (qemuMonitorJSONHumanCommand(mon, cmd, &reply))
goto cleanup;
@ -210,8 +206,7 @@ int qemuMonitorTextDeleteSnapshot(qemuMonitorPtr mon, const char *name)
char *reply = NULL;
int ret = -1;
if (virAsprintf(&cmd, "delvm \"%s\"", name) < 0)
goto cleanup;
cmd = g_strdup_printf("delvm \"%s\"", name);
if (qemuMonitorJSONHumanCommand(mon, cmd, &reply))
goto cleanup;

View File

@ -98,10 +98,8 @@ VIR_LOG_INIT("qemu.qemu_process");
* qemuProcessRemoveDomainStatus
*
* remove all state files of a domain from statedir
*
* Returns 0 on success
*/
static int
static void
qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
virDomainObjPtr vm)
{
@ -109,10 +107,8 @@ qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
char *file = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int ret = -1;
if (virAsprintf(&file, "%s/%s.xml", cfg->stateDir, vm->def->name) < 0)
goto cleanup;
file = g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name);
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
VIR_WARN("Failed to remove domain XML for %s: %s",
@ -125,10 +121,7 @@ qemuProcessRemoveDomainStatus(virQEMUDriverPtr driver,
VIR_WARN("Failed to remove PID file for %s: %s",
vm->def->name, virStrerror(errno, ebuf, sizeof(ebuf)));
ret = 0;
cleanup:
virObjectUnref(cfg);
return ret;
}
@ -2105,8 +2098,7 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices,
qemuMonitorChardevInfoPtr entry;
VIR_FREE(id);
if (virAsprintf(&id, "char%s", chr->info.alias) < 0)
return -1;
id = g_strdup_printf("char%s", chr->info.alias);
entry = virHashLookup(info, id);
if (!entry || !entry->ptyPath) {
@ -2175,7 +2167,7 @@ qemuProcessFindCharDevicePTYsMonitor(virDomainObjPtr vm,
}
static int
static void
qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virHashTablePtr info,
@ -2186,7 +2178,6 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
qemuMonitorChardevInfoPtr entry;
virObjectEventPtr event = NULL;
char *id = NULL;
int ret = -1;
if (booted)
agentReason = VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED;
@ -2196,8 +2187,7 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
if (chr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO) {
VIR_FREE(id);
if (virAsprintf(&id, "char%s", chr->info.alias) < 0)
goto cleanup;
id = g_strdup_printf("char%s", chr->info.alias);
/* port state not reported */
if (!(entry = virHashLookup(info, id)) ||
@ -2214,10 +2204,7 @@ qemuProcessRefreshChannelVirtioState(virQEMUDriverPtr driver,
}
}
ret = 0;
cleanup:
VIR_FREE(id);
return ret;
}
@ -2240,7 +2227,8 @@ qemuRefreshVirtioChannelState(virQEMUDriverPtr driver,
if (ret < 0)
goto cleanup;
ret = qemuProcessRefreshChannelVirtioState(driver, vm, info, false);
qemuProcessRefreshChannelVirtioState(driver, vm, info, false);
ret = 0;
cleanup:
virHashFree(info);
@ -2405,9 +2393,7 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
if ((ret = qemuProcessFindCharDevicePTYsMonitor(vm, info)) < 0)
goto cleanup;
if ((ret = qemuProcessRefreshChannelVirtioState(driver, vm, info,
true)) < 0)
goto cleanup;
qemuProcessRefreshChannelVirtioState(driver, vm, info, true);
}
cleanup:
@ -3208,9 +3194,7 @@ qemuProcessPrepareMonitorChr(virDomainChrSourceDefPtr monConfig,
monConfig->type = VIR_DOMAIN_CHR_TYPE_UNIX;
monConfig->data.nix.listen = true;
if (virAsprintf(&monConfig->data.nix.path, "%s/monitor.sock",
domainDir) < 0)
return -1;
monConfig->data.nix.path = g_strdup_printf("%s/monitor.sock", domainDir);
return 0;
}
@ -3416,8 +3400,8 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, virDomainObjPtr vm)
} else {
newState = VIR_DOMAIN_PAUSED;
newReason = reason;
ignore_value(virAsprintf(&msg, "was paused (%s)",
virDomainPausedReasonTypeToString(reason)));
msg = g_strdup_printf("was paused (%s)",
virDomainPausedReasonTypeToString(reason));
}
}
@ -4082,9 +4066,7 @@ qemuProcessVerifyHypervFeatures(virDomainDefPtr def,
if (def->hyperv_features[i] != VIR_TRISTATE_SWITCH_ON)
continue;
if (virAsprintf(&cpuFeature, "hv-%s",
virDomainHypervTypeToString(i)) < 0)
return -1;
cpuFeature = g_strdup_printf("hv-%s", virDomainHypervTypeToString(i));
rc = virCPUDataCheckFeature(cpu, cpuFeature);
VIR_FREE(cpuFeature);
@ -4916,9 +4898,8 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
* default instead of tcp listen. */
if (useSocket) {
memset(glisten, 0, sizeof(virDomainGraphicsListenDef));
if (virAsprintf(&glisten->socket, "%s/%s.sock",
priv->libDir, type) < 0)
goto cleanup;
glisten->socket = g_strdup_printf("%s/%s.sock", priv->libDir,
type);
glisten->fromConfig = true;
glisten->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET;
} else if (listenAddr) {
@ -4939,9 +4920,8 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver,
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
if (!glisten->socket) {
if (virAsprintf(&glisten->socket, "%s/%s.sock",
priv->libDir, type) < 0)
goto cleanup;
glisten->socket = g_strdup_printf("%s/%s.sock", priv->libDir,
type);
glisten->autoGenerated = true;
}
break;
@ -6018,8 +5998,7 @@ qemuProcessSetupHotpluggableVcpus(virQEMUDriverPtr driver,
if (vcpu->hotpluggable == VIR_TRISTATE_BOOL_YES && vcpu->online &&
vcpupriv->vcpus != 0) {
if (virAsprintf(&vcpupriv->alias, "vcpu%zu", i) < 0)
goto cleanup;
vcpupriv->alias = g_strdup_printf("vcpu%zu", i);
if (VIR_APPEND_ELEMENT(bootHotplug, nbootHotplug, vcpu) < 0)
goto cleanup;
@ -6370,10 +6349,8 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
if (qemuProcessUpdateGuestCPU(vm->def, priv->qemuCaps, caps, flags) < 0)
goto cleanup;
for (i = 0; i < vm->def->nshmems; i++) {
if (qemuDomainPrepareShmemChardev(vm->def->shmems[i]) < 0)
goto cleanup;
}
for (i = 0; i < vm->def->nshmems; i++)
qemuDomainPrepareShmemChardev(vm->def->shmems[i]);
ret = 0;
cleanup:
@ -8497,8 +8474,7 @@ qemuProcessQMPInit(qemuProcessQMPPtr proc)
VIR_DEBUG("proc=%p, emulator=%s", proc, proc->binary);
if (virAsprintf(&template, "%s/qmp-XXXXXX", proc->libDir) < 0)
goto cleanup;
template = g_strdup_printf("%s/qmp-XXXXXX", proc->libDir);
if (!(proc->uniqDir = mkdtemp(template))) {
virReportSystemError(errno,
@ -8511,20 +8487,16 @@ qemuProcessQMPInit(qemuProcessQMPPtr proc)
if (qemuProcessQEMULabelUniqPath(proc) < 0)
goto cleanup;
if (virAsprintf(&proc->monpath, "%s/%s", proc->uniqDir,
"qmp.monitor") < 0)
goto cleanup;
proc->monpath = g_strdup_printf("%s/%s", proc->uniqDir, "qmp.monitor");
if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath) < 0)
goto cleanup;
proc->monarg = g_strdup_printf("unix:%s,server,nowait", proc->monpath);
/*
* Normally we'd use runDir for pid files, but because we're using
* -daemonize we need QEMU to be allowed to create them, rather
* than libvirtd. So we're using libDir which QEMU can write to
*/
if (virAsprintf(&proc->pidfile, "%s/%s", proc->uniqDir, "qmp.pid") < 0)
goto cleanup;
proc->pidfile = g_strdup_printf("%s/%s", proc->uniqDir, "qmp.pid");
ret = 0;

View File

@ -153,10 +153,11 @@ qemuSlirpCreatePidFilename(virQEMUDriverConfigPtr cfg,
g_autofree char *shortName = NULL;
g_autofree char *name = NULL;
if (!(shortName = virDomainDefGetShortName(def)) ||
virAsprintf(&name, "%s-%s-slirp", shortName, alias) < 0)
if (!(shortName = virDomainDefGetShortName(def)))
return NULL;
name = g_strdup_printf("%s-%s-slirp", shortName, alias);
return virPidFileBuildPath(cfg->slirpStateDir, name);
}
@ -209,8 +210,7 @@ qemuSlirpGetDBusVMStateId(virDomainNetDefPtr net)
char *id = NULL;
/* can't use alias, because it's not stable across restarts */
if (virAsprintf(&id, "slirp-%s", virMacAddrFormat(&net->mac, macstr)) < 0)
return NULL;
id = g_strdup_printf("slirp-%s", virMacAddrFormat(&net->mac, macstr));
return id;
}
@ -224,11 +224,12 @@ qemuSlirpGetDBusPath(virQEMUDriverConfigPtr cfg,
g_autofree char *shortName = NULL;
char *path = NULL;
if (!(shortName = virDomainDefGetShortName(def)) ||
virAsprintf(&path, "%s/%s-%s-slirp",
cfg->slirpStateDir, shortName, alias) < 0)
if (!(shortName = virDomainDefGetShortName(def)))
return NULL;
path = g_strdup_printf("%s/%s-%s-slirp",
cfg->slirpStateDir, shortName, alias);
return path;
}
@ -379,8 +380,7 @@ qemuSlirpStart(qemuSlirpPtr slirp,
return -1;
}
if (virAsprintf(&dbus_addr, "unix:path=%s", dbus_path) < 0)
return -1;
dbus_addr = g_strdup_printf("unix:path=%s", dbus_path);
virCommandAddArgFormat(cmd, "--dbus-id=%s", id);

View File

@ -78,9 +78,7 @@ qemuTPMCreateEmulatorStoragePath(const char *swtpmStorageDir,
return NULL;
}
ignore_value(virAsprintf(&path, "%s/%s/%s", swtpmStorageDir, uuidstr,
dir));
path = g_strdup_printf("%s/%s/%s", swtpmStorageDir, uuidstr, dir);
return path;
}
@ -208,8 +206,7 @@ qemuTPMCreateEmulatorSocket(const char *swtpmStateDir,
{
char *path = NULL;
ignore_value(virAsprintf(&path, "%s/%s-swtpm.sock", swtpmStateDir,
shortName));
path = g_strdup_printf("%s/%s-swtpm.sock", swtpmStateDir, shortName);
return path;
}
@ -252,8 +249,7 @@ qemuTPMEmulatorCreatePidFilename(const char *swtpmStateDir,
char *pidfile = NULL;
char *devicename = NULL;
if (virAsprintf(&devicename, "%s-swtpm", shortName) < 0)
return NULL;
devicename = g_strdup_printf("%s-swtpm", shortName);
pidfile = virPidFileBuildPath(swtpmStateDir, devicename);
@ -335,10 +331,8 @@ qemuTPMEmulatorPrepareHost(virDomainTPMDefPtr tpm,
goto cleanup;
/* create logfile name ... */
if (!tpm->data.emulator.logfile &&
virAsprintf(&tpm->data.emulator.logfile, "%s/%s-swtpm.log",
logDir, vmname) < 0)
goto cleanup;
if (!tpm->data.emulator.logfile)
tpm->data.emulator.logfile = g_strdup_printf("%s/%s-swtpm.log", logDir, vmname);
if (!virFileExists(tpm->data.emulator.logfile) &&
virFileTouch(tpm->data.emulator.logfile, 0644) < 0) {
@ -492,8 +486,7 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
goto cleanup;
virUUIDFormat(vmuuid, uuid);
if (virAsprintf(&vmid, "%s:%s", vmname, uuid) < 0)
goto cleanup;
vmid = g_strdup_printf("%s:%s", vmname, uuid);
virCommandSetUID(cmd, swtpm_user);
virCommandSetGID(cmd, swtpm_group);

View File

@ -47,8 +47,7 @@ qemuVhostUserGPUCreatePidFilename(const char *stateDir,
{
g_autofree char *devicename = NULL;
if (virAsprintf(&devicename, "%s-%s-vhost-user-gpu", shortName, alias) < 0)
return NULL;
devicename = g_strdup_printf("%s-%s-vhost-user-gpu", shortName, alias);
return virPidFileBuildPath(stateDir, devicename);
}