These functions can't fail really. Drop checking of their retval then. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_agent.c | 9 +- src/qemu/qemu_alias.c | 114 +++++++++++----------- src/qemu/qemu_block.c | 41 +++----- src/qemu/qemu_blockjob.c | 12 +-- src/qemu/qemu_capabilities.c | 14 +-- src/qemu/qemu_checkpoint.c | 11 +-- src/qemu/qemu_command.c | 104 ++++++++------------ src/qemu/qemu_conf.c | 141 ++++++++++----------------- src/qemu/qemu_conf.h | 4 +- src/qemu/qemu_domain.c | 158 ++++++++++++------------------- src/qemu/qemu_domain.h | 6 +- src/qemu/qemu_driver.c | 6 +- src/qemu/qemu_firmware.c | 3 +- src/qemu/qemu_hotplug.c | 80 ++++++---------- src/qemu/qemu_interface.c | 5 +- src/qemu/qemu_interop_config.c | 9 +- src/qemu/qemu_migration.c | 33 +++---- src/qemu/qemu_migration_cookie.c | 3 +- src/qemu/qemu_monitor.c | 33 +++---- src/qemu/qemu_monitor_json.c | 26 ++--- src/qemu/qemu_monitor_text.c | 15 +-- src/qemu/qemu_process.c | 74 +++++---------- src/qemu/qemu_slirp.c | 18 ++-- src/qemu/qemu_tpm.c | 19 ++-- src/qemu/qemu_vhost_user_gpu.c | 3 +- 25 files changed, 357 insertions(+), 584 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 4b914e6d3b..d1b590d842 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -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; + virAsprintf(&sync_msg.txBuffer, "{\"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; + virAsprintf(&msg.txBuffer, "%s" LINE_ENDING, cmdstr); msg.txLength = strlen(msg.txBuffer); VIR_DEBUG("Send command '%s' for write, seconds = %d", cmdstr, seconds); diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index f11099ce90..60ab5735a4 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -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); + virAsprintf(&chr->info.alias, "%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); + virAsprintf(&controller->info.alias, "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); + virAsprintf(&controller->info.alias, "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); + virAsprintf(&controller->info.alias, "%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; + virAsprintf(&disk->info.alias, "%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; + 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); } } else { int idx = virDiskNameToIndex(disk->dst); - if (virAsprintf(&disk->info.alias, "%s-disk%d", prefix, idx) < 0) - return -1; + virAsprintf(&disk->info.alias, "%s-disk%d", prefix, idx); } } @@ -235,17 +236,15 @@ 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; + virAsprintf(&diskPriv->qomName, + "/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; + virAsprintf(&diskPriv->qomName, + "/machine/peripheral/%s/%s.0/legacy[0]", + disk->info.alias, disk->info.alias); break; case VIR_DOMAIN_DISK_BUS_XEN: @@ -291,8 +290,7 @@ qemuAssignDeviceHostdevAlias(virDomainDefPtr def, } } - if (virAsprintf(alias, "hostdev%d", idx) < 0) - return -1; + virAsprintf(alias, "hostdev%d", idx); return 0; } @@ -327,8 +325,7 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def, } } - if (virAsprintf(&net->info.alias, "net%d", idx) < 0) - return -1; + virAsprintf(&net->info.alias, "net%d", idx); return 0; } @@ -340,7 +337,8 @@ qemuAssignDeviceFSAlias(virDomainFSDefPtr fss, if (fss->info.alias) return 0; - return virAsprintf(&fss->info.alias, "fs%d", idx); + virAsprintf(&fss->info.alias, "fs%d", idx); + return 0; } @@ -351,7 +349,8 @@ qemuAssignDeviceSoundAlias(virDomainSoundDefPtr sound, if (sound->info.alias) return 0; - return virAsprintf(&sound->info.alias, "sound%d", idx); + virAsprintf(&sound->info.alias, "sound%d", idx); + return 0; } @@ -362,7 +361,8 @@ qemuAssignDeviceVideoAlias(virDomainVideoDefPtr video, if (video->info.alias) return 0; - return virAsprintf(&video->info.alias, "video%d", idx); + virAsprintf(&video->info.alias, "video%d", idx); + return 0; } @@ -373,7 +373,8 @@ qemuAssignDeviceHubAlias(virDomainHubDefPtr hub, if (hub->info.alias) return 0; - return virAsprintf(&hub->info.alias, "hub%d", idx); + virAsprintf(&hub->info.alias, "hub%d", idx); + return 0; } @@ -384,7 +385,8 @@ qemuAssignDeviceSmartcardAlias(virDomainSmartcardDefPtr smartcard, if (smartcard->info.alias) return 0; - return virAsprintf(&smartcard->info.alias, "smartcard%d", idx); + virAsprintf(&smartcard->info.alias, "smartcard%d", idx); + return 0; } @@ -395,7 +397,8 @@ qemuAssingDeviceMemballoonAlias(virDomainMemballoonDefPtr memballoon, if (memballoon->info.alias) return 0; - return virAsprintf(&memballoon->info.alias, "balloon%d", idx); + virAsprintf(&memballoon->info.alias, "balloon%d", idx); + return 0; } @@ -406,7 +409,8 @@ qemuAssignDeviceTPMAlias(virDomainTPMDefPtr tpm, if (tpm->info.alias) return 0; - return virAsprintf(&tpm->info.alias, "tpm%d", idx); + virAsprintf(&tpm->info.alias, "tpm%d", idx); + return 0; } @@ -430,8 +434,7 @@ qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, } } - if (virAsprintf(&redirdev->info.alias, "redir%d", idx) < 0) - return -1; + virAsprintf(&redirdev->info.alias, "redir%d", idx); return 0; } @@ -452,8 +455,7 @@ qemuAssignDeviceRNGAlias(virDomainDefPtr def, maxidx = idx + 1; } - if (virAsprintf(&rng->info.alias, "rng%d", maxidx) < 0) - return -1; + virAsprintf(&rng->info.alias, "rng%d", maxidx); return 0; } @@ -498,8 +500,7 @@ qemuAssignDeviceMemoryAlias(virDomainDefPtr def, maxidx = mem->info.addr.dimm.slot; } - if (virAsprintf(&mem->info.alias, "%s%d", prefix, maxidx) < 0) - return -1; + virAsprintf(&mem->info.alias, "%s%d", prefix, maxidx); return 0; } @@ -528,8 +529,7 @@ qemuAssignDeviceShmemAlias(virDomainDefPtr def, } } - if (virAsprintf(&shmem->info.alias, "shmem%d", idx) < 0) - return -1; + virAsprintf(&shmem->info.alias, "shmem%d", idx); return 0; } @@ -565,8 +565,7 @@ qemuAssignDeviceInputAlias(virDomainDefPtr def, } } - if (virAsprintf(&input->info.alias, "input%d", idx) < 0) - return -1; + virAsprintf(&input->info.alias, "input%d", idx); return 0; } @@ -706,9 +705,7 @@ qemuAliasDiskDriveFromDisk(const virDomainDiskDef *disk) return NULL; } - ignore_value(virAsprintf(&ret, "%s%s", QEMU_DRIVE_HOST_PREFIX, - disk->info.alias)); - + virAsprintf(&ret, "%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias); return ret; } @@ -744,9 +741,9 @@ qemuAliasFromHostdev(const virDomainHostdevDef *hostdev) return NULL; } - ignore_value(virAsprintf(&ret, "%s-%s", - virDomainDeviceAddressTypeToString(hostdev->info->type), - hostdev->info->alias)); + virAsprintf(&ret, "%s-%s", + virDomainDeviceAddressTypeToString(hostdev->info->type), + hostdev->info->alias); return ret; } @@ -789,9 +786,9 @@ qemuDomainGetSecretAESAlias(const char *srcalias, } if (isLuks) - ignore_value(virAsprintf(&alias, "%s-luks-secret0", srcalias)); + virAsprintf(&alias, "%s-luks-secret0", srcalias); else - ignore_value(virAsprintf(&alias, "%s-secret0", srcalias)); + virAsprintf(&alias, "%s-secret0", srcalias); return alias; } @@ -807,7 +804,7 @@ qemuAliasTLSObjFromSrcAlias(const char *srcAlias) { char *ret; - ignore_value(virAsprintf(&ret, "obj%s_tls0", srcAlias)); + virAsprintf(&ret, "obj%s_tls0", srcAlias); return ret; } @@ -823,7 +820,7 @@ qemuAliasChardevFromDevAlias(const char *devAlias) { char *ret; - ignore_value(virAsprintf(&ret, "char%s", devAlias)); + virAsprintf(&ret, "char%s", devAlias); return ret; } @@ -841,7 +838,7 @@ qemuDomainGetUnmanagedPRAlias(const char *parentalias) { char *ret; - ignore_value(virAsprintf(&ret, "pr-helper-%s", parentalias)); + virAsprintf(&ret, "pr-helper-%s", parentalias); return ret; } @@ -852,8 +849,7 @@ qemuAliasDBusVMStateFromId(const char *id) char *ret; size_t i; - if (virAsprintf(&ret, "dbus-vms-%s", id) < 0) - return NULL; + virAsprintf(&ret, "dbus-vms-%s", id); for (i = 0; ret[i]; i++) { if (ret[i] == ':') diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 4416bda6d2..f40915fe23 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -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; + virAsprintf(&uri->scheme, "%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; + virAsprintf(&uri->path, "/%s/%s", src->volume, src->path); } else { - if (virAsprintf(&uri->path, "%s%s", - src->path[0] == '/' ? "" : "/", - src->path) < 0) - return NULL; + virAsprintf(&uri->path, "%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; + virAsprintf(&port, "%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; + virAsprintf(&port, "%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; + virAsprintf(&portal, "[%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; + virAsprintf(&portal, "%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; + virAsprintf(&ret, "json:%s", backingJSON); return ret; } @@ -2048,11 +2037,11 @@ qemuBlockStorageSourceCreateGetEncryptionLUKS(virStorageSourcePtr src, return -1; if (src->encryption) { - if (src->encryption->encinfo.cipher_name && + if (src->encryption->encinfo.cipher_name) { virAsprintf(&cipheralg, "%s-%u", src->encryption->encinfo.cipher_name, - src->encryption->encinfo.cipher_size) < 0) - return -1; + src->encryption->encinfo.cipher_size); + } if (virJSONValueObjectAdd(props, "S:cipher-alg", cipheralg, diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 8c418ecf6c..e59cab3478 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -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; + virAsprintf(&jobname, "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; + virAsprintf(&jobname, "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; + virAsprintf(&jobname, "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; + virAsprintf(&jobname, "copy-%s-%s", disk->dst, disk->src->nodeformat); } else { if (!(jobname = qemuAliasDiskDriveFromDisk(disk))) return NULL; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index c78ad56edf..b2ea7ec373 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -734,8 +734,7 @@ virQEMUCapsFindBinary(const char *format, char *ret = NULL; char *binary = NULL; - if (virAsprintf(&binary, format, archstr) < 0) - return NULL; + virAsprintf(&binary, format, archstr); ret = virFindFileInPath(binary); VIR_FREE(binary); @@ -2412,8 +2411,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; + virAsprintf(&type, "%s-machine", canon); if ((nvalues = qemuMonitorGetObjectProps(mon, type, &values)) < 0) return -1; @@ -4849,8 +4847,7 @@ virQEMUCapsCacheNew(const char *libDir, virQEMUCapsCachePrivPtr priv = NULL; struct utsname uts; - if (virAsprintf(&capsCacheDir, "%s/capabilities", cacheDir) < 0) - goto error; + virAsprintf(&capsCacheDir, "%s/capabilities", cacheDir); if (!(cache = virFileCacheNew(capsCacheDir, "xml", &qemuCapsCacheHandlers))) goto error; @@ -4867,9 +4864,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) + virAsprintf(&priv->kernelVersion, "%s %s", uts.release, uts.version); cleanup: VIR_FREE(capsCacheDir); diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index 4a618f5236..4c224d6f40 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -92,16 +92,14 @@ qemuCheckpointWriteMetadata(virDomainObjPtr vm, if (newxml == NULL) return -1; - if (virAsprintf(&chkDir, "%s/%s", checkpointDir, vm->def->name) < 0) - return -1; + virAsprintf(&chkDir, "%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; + virAsprintf(&chkFile, "%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; + virAsprintf(&chkFile, "%s/%s/%s.xml", cfg->checkpointDir, vm->def->name, + chk->def->name); if (!metadata_only) { qemuDomainObjPrivatePtr priv = vm->privateData; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 0160507737..a55a5826a7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -262,7 +262,7 @@ qemuVirCommandGetFDSet(virCommandPtr cmd, int fd) return NULL; } - ignore_value(virAsprintf(&result, "set=%d,fd=%d", idx, fd)); + virAsprintf(&result, "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)); + virAsprintf(&result, "/dev/fdset/%d", idx); return result; } @@ -795,10 +795,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; + virAsprintf(&uri->user, "%s:%s", secinfo->s.plain.username, + secinfo->s.plain.secret); } else { uri->user = g_strdup(secinfo->s.plain.username); } @@ -947,9 +945,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) + virAsprintf(&uri->query, "socket=%s", src->hosts->socket); if (qemuBuildGeneralSecinfoURI(uri, secinfo) < 0) return NULL; @@ -1038,13 +1035,10 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, } if (src->nhosts == 0) { - if (virAsprintf(&ret, "sheepdog:%s", src->path) < 0) - return NULL; + virAsprintf(&ret, "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; + virAsprintf(&ret, "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")); @@ -2375,18 +2369,16 @@ qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd, else driveLetter = 'A'; - if (bootindex && - virAsprintf(&bootindexStr, "bootindex%c=%u", driveLetter, bootindex) < 0) - return -1; + if (bootindex) + virAsprintf(&bootindexStr, "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) + virAsprintf(&backendStr, "drive%c=%s", driveLetter, backendAlias); } if (!explicitfdc) { @@ -3588,8 +3580,7 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, unsigned long long memsize = virDomainNumaGetNodeMemorySize(def->numa, cell); - if (virAsprintf(&alias, "ram-node%zu", cell) < 0) - return -1; + virAsprintf(&alias, "ram-node%zu", cell); mem.size = memsize; mem.targetNode = cell; @@ -3622,8 +3613,7 @@ qemuBuildMemoryDimmBackendStr(virBufferPtr buf, return -1; } - if (virAsprintf(&alias, "mem%s", mem->info.alias) < 0) - return -1; + virAsprintf(&alias, "mem%s", mem->info.alias); if (qemuBuildMemoryBackendProps(&props, alias, cfg, priv, def, mem, true) < 0) @@ -3707,14 +3697,14 @@ 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))); + 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)); return str; } @@ -4708,8 +4698,7 @@ qemuBuildVhostUserChardevStr(const char *alias, return NULL; } - if (virAsprintf(&chardev, "socket,id=chr-vu-%s,fd=%d", alias, *fd) < 0) - return NULL; + virAsprintf(&chardev, "socket,id=chr-vu-%s,fd=%d", alias, *fd); virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); *fd = -1; @@ -5554,10 +5543,7 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd, if (virSCSIVHostOpenVhostSCSI(&vhostfd) < 0) return -1; - if (virAsprintf(&vhostfdName, "%d", vhostfd) < 0) { - VIR_FORCE_CLOSE(vhostfd); - return -1; - } + virAsprintf(&vhostfdName, "%d", vhostfd); virCommandPassFD(cmd, vhostfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); @@ -5791,8 +5777,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; + virAsprintf(&objAlias, "obj%s", rng->info.alias); switch ((virDomainRNGBackend) rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: @@ -8581,8 +8566,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; + virAsprintf(&slirpfdName, "%d", slirpfd); } @@ -8590,16 +8574,14 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, if (qemuSecuritySetTapFDLabel(driver->securityManager, def, tapfd[i]) < 0) goto cleanup; - if (virAsprintf(&tapfdName[i], "%d", tapfd[i]) < 0) - goto cleanup; + virAsprintf(&tapfdName[i], "%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; + virAsprintf(&vhostfdName[i], "%d", vhostfd[i]); virCommandPassFD(cmd, vhostfd[i], VIR_COMMAND_PASS_FD_CLOSE_PARENT); vhostfd[i] = -1; @@ -8975,11 +8957,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; + virAsprintf(&mem_path, "/dev/shm/%s", shmem->name); - if (virAsprintf(&mem_alias, "shmmem-%s", shmem->info.alias) < 0) - return NULL; + virAsprintf(&mem_alias, "shmmem-%s", shmem->info.alias); qemuMonitorCreateObjectProps(&ret, "memory-backend-file", mem_alias, "s:mem-path", mem_path, @@ -9709,9 +9689,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; + virAsprintf(chardev, "socket,id=chrtpm,path=%s", + tpm->data.emulator.source.data.nix.path); break; case VIR_DOMAIN_TPM_TYPE_LAST: @@ -9796,15 +9775,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; + virAsprintf(&path, "%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; + virAsprintf(&path, "%s/session.base64", priv->libDir); virBufferAsprintf(&buf, ",session-file=%s", path); VIR_FREE(path); } @@ -10601,9 +10578,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; + virAsprintf(deviceStr, "isa-parallel,chardev=char%s,id=%s", + chr->info.alias, chr->info.alias); return 0; } @@ -10624,10 +10600,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; + virAsprintf(deviceStr, "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: diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index fae697a2ef..41fd134afc 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -130,49 +130,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; + virAsprintf(&cfg->logDir, "%s/log/libvirt/qemu", LOCALSTATEDIR); - if (virAsprintf(&cfg->swtpmLogDir, - "%s/log/swtpm/libvirt/qemu", LOCALSTATEDIR) < 0) - return NULL; + virAsprintf(&cfg->swtpmLogDir, "%s/log/swtpm/libvirt/qemu", + LOCALSTATEDIR); cfg->configBaseDir = g_strdup(SYSCONFDIR "/libvirt"); - if (virAsprintf(&cfg->stateDir, - "%s/libvirt/qemu", RUNSTATEDIR) < 0) - return NULL; + virAsprintf(&cfg->stateDir, "%s/libvirt/qemu", RUNSTATEDIR); - if (virAsprintf(&cfg->swtpmStateDir, - "%s/libvirt/qemu/swtpm", RUNSTATEDIR) < 0) - return NULL; + virAsprintf(&cfg->swtpmStateDir, "%s/libvirt/qemu/swtpm", RUNSTATEDIR); - if (virAsprintf(&cfg->cacheDir, - "%s/cache/libvirt/qemu", LOCALSTATEDIR) < 0) - return NULL; + virAsprintf(&cfg->cacheDir, "%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; + virAsprintf(&cfg->libDir, "%s/lib/libvirt/qemu", LOCALSTATEDIR); + virAsprintf(&cfg->saveDir, "%s/save", cfg->libDir); + virAsprintf(&cfg->snapshotDir, "%s/snapshot", cfg->libDir); + virAsprintf(&cfg->checkpointDir, "%s/checkpoint", cfg->libDir); + virAsprintf(&cfg->autoDumpPath, "%s/dump", cfg->libDir); + virAsprintf(&cfg->channelTargetDir, "%s/channel/target", cfg->libDir); + virAsprintf(&cfg->nvramDir, "%s/nvram", cfg->libDir); + virAsprintf(&cfg->memoryBackingDir, "%s/ram", cfg->libDir); + virAsprintf(&cfg->swtpmStorageDir, "%s/lib/libvirt/swtpm", + LOCALSTATEDIR); if (!virDoesUserExist("tss") || virGetUserID("tss", &cfg->swtpm_user) < 0) cfg->swtpm_user = 0; /* fall back to root */ @@ -187,55 +167,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; + virAsprintf(&cfg->logDir, "%s/qemu/log", cachedir); + virAsprintf(&cfg->swtpmLogDir, "%s/qemu/log", cachedir); + virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir); rundir = virGetUserRuntimeDirectory(); if (!rundir) return NULL; - if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0) - return NULL; + virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir); - if (virAsprintf(&cfg->swtpmStateDir, "%s/swtpm", cfg->stateDir) < 0) - return NULL; + virAsprintf(&cfg->swtpmStateDir, "%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; + virAsprintf(&cfg->libDir, "%s/qemu/lib", cfg->configBaseDir); + virAsprintf(&cfg->saveDir, "%s/qemu/save", cfg->configBaseDir); + virAsprintf(&cfg->snapshotDir, "%s/qemu/snapshot", cfg->configBaseDir); + virAsprintf(&cfg->checkpointDir, "%s/qemu/checkpoint", + cfg->configBaseDir); + virAsprintf(&cfg->autoDumpPath, "%s/qemu/dump", cfg->configBaseDir); + virAsprintf(&cfg->channelTargetDir, "%s/qemu/channel/target", + cfg->configBaseDir); + virAsprintf(&cfg->nvramDir, "%s/qemu/nvram", cfg->configBaseDir); + virAsprintf(&cfg->memoryBackingDir, "%s/qemu/ram", cfg->configBaseDir); + virAsprintf(&cfg->swtpmStorageDir, "%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; + virAsprintf(&cfg->configDir, "%s/qemu", cfg->configBaseDir); + virAsprintf(&cfg->autostartDir, "%s/qemu/autostart", cfg->configBaseDir); + virAsprintf(&cfg->slirpStateDir, "%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 @@ -1390,12 +1354,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; + virAsprintf(&key, "%d:%d:%s:%s", data.arch, data.virttype, + NULLSTR(data.machine), NULLSTR(data.path)); if (virHashAddEntry(domCapsCache, key, domCaps) < 0) return NULL; @@ -1426,8 +1386,7 @@ qemuGetSharedDeviceKey(const char *device_path) return NULL; } - if (virAsprintf(&key, "%d:%d", maj, min) < 0) - return NULL; + virAsprintf(&key, "%d:%d", maj, min); return key; } @@ -1703,7 +1662,7 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev) scsihostsrc->unit))) return NULL; - ignore_value(virAsprintf(&dev_path, "/dev/%s", dev_name)); + virAsprintf(&dev_path, "/dev/%s", dev_name); return dev_path; } @@ -1880,8 +1839,7 @@ qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage) { char *ret; - if (virAsprintf(&ret, "%s/libvirt/qemu", hugepage->mnt_dir) < 0) - return NULL; + virAsprintf(&ret, "%s/libvirt/qemu", hugepage->mnt_dir); return ret; } @@ -1896,7 +1854,7 @@ qemuGetDomainHugepagePath(const virDomainDef *def, char *ret = NULL; if (base && domPath) - ignore_value(virAsprintf(&ret, "%s/%s", base, domPath)); + virAsprintf(&ret, "%s/%s", base, domPath); return ret; } @@ -1944,11 +1902,11 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, } -int +void qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, char **path) { - return virAsprintf(path, "%s/libvirt/qemu", cfg->memoryBackingDir); + virAsprintf(path, "%s/libvirt/qemu", cfg->memoryBackingDir); } @@ -1960,11 +1918,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); + virAsprintf(path, "%s/%s", base, shortName); + return 0; } @@ -1996,9 +1955,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; + virAsprintf(memPath, "%s/%s", domainPath, alias); return 0; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 7247199d3e..7334a440f8 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -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); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 3e8da13794..25d4a0eb07 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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) + virAsprintf(&priv->libDir, "%s/domain-%s", cfg->libDir, vm->def->name); - if (!priv->channelTargetDir && + if (!priv->channelTargetDir) virAsprintf(&priv->channelTargetDir, "%s/domain-%s", - cfg->channelTargetDir, vm->def->name) < 0) - goto cleanup; + 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) + virAsprintf(&priv->libDir, "%s/domain-%s", cfg->libDir, domname); - if (!priv->channelTargetDir && + if (!priv->channelTargetDir) virAsprintf(&priv->channelTargetDir, "%s/domain-%s", - cfg->channelTargetDir, domname) < 0) - goto cleanup; + cfg->channelTargetDir, domname); ret = 0; cleanup: @@ -3675,8 +3666,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; @@ -4632,8 +4622,7 @@ qemuDomainDefPostParse(virDomainDefPtr def, goto cleanup; } - if (qemuDomainNVRAMPathGenerate(cfg, def) < 0) - goto cleanup; + qemuDomainNVRAMPathGenerate(cfg, def); if (qemuDomainDefAddDefaultDevices(def, qemuCaps) < 0) goto cleanup; @@ -9327,8 +9316,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; + virAsprintf(&ctxt->path, "%s/%s.log", cfg->logDir, vm->def->name); if (cfg->stdioLogD) { ctxt->manager = virLogManagerNew(virQEMUDriverIsPrivileged(driver)); @@ -9508,8 +9496,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; + virAsprintf(&path, "%s/%s.log", cfg->logDir, vm->def->name); if (cfg->stdioLogD) { if (!(manager = virLogManagerNew(virQEMUDriverIsPrivileged(driver)))) @@ -9602,16 +9589,14 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, if (newxml == NULL) return -1; - if (virAsprintf(&snapDir, "%s/%s", snapshotDir, vm->def->name) < 0) - goto cleanup; + virAsprintf(&snapDir, "%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; + virAsprintf(&snapFile, "%s/%s.xml", snapDir, def->parent.name); ret = virXMLSaveFile(snapFile, NULL, "snapshot-edit", newxml); @@ -9744,9 +9729,8 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver, } } - if (virAsprintf(&snapFile, "%s/%s/%s.xml", cfg->snapshotDir, - vm->def->name, snap->def->name) < 0) - goto cleanup; + virAsprintf(&snapFile, "%s/%s/%s.xml", cfg->snapshotDir, vm->def->name, + snap->def->name); if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) { virDomainSnapshotSetCurrent(vm->snapshots, NULL); @@ -9833,23 +9817,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 { + virAsprintf(&snapDir, "%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 { + virAsprintf(&chkDir, "%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); @@ -10195,7 +10177,7 @@ qemuDomainStorageAlias(const char *device, int depth) if (!depth) alias = g_strdup(device); else - ignore_value(virAsprintf(&alias, "%s.%d", device, depth)); + virAsprintf(&alias, "%s.%d", device, depth); return alias; } @@ -11744,9 +11726,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; + virAsprintf(&file, "/sys/bus/pci/devices/%s/of_node/%s", + device, nvlink2Files[i]); if (!virFileExists(file)) return false; @@ -12425,19 +12406,15 @@ 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; + virAsprintf(&channel->source->data.nix.path, "%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; + 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); } return 0; @@ -12620,16 +12597,16 @@ 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); + virAsprintf(&shmem->server.chr.data.nix.path, + "/var/lib/libvirt/shmem-%s-sock", + shmem->name); } @@ -12955,9 +12932,7 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr cfg, if (STREQ(mountpoint, "/dev")) suffix = "dev"; - if (virAsprintf(&path, "%s/%s.%s", - cfg->stateDir, domname, suffix) < 0) - goto cleanup; + virAsprintf(&path, "%s/%s.%s", cfg->stateDir, domname, suffix); /* Now consider that @mountpoint is "/dev/blah/blah2". * @suffix then points to "blah/blah2". However, caller @@ -12973,7 +12948,6 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr cfg, tmp++; } - cleanup: VIR_FREE(domname); return path; } @@ -13138,9 +13112,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; + virAsprintf(&devicePath, "%s/%s", data->path, + device + strlen(QEMU_DEVPREFIX)); if (virFileMakeParentPath(devicePath) < 0) { virReportSystemError(errno, @@ -13194,10 +13167,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; - } + virAsprintf(&tmp, "%s%s", devTmp, target); VIR_FREE(devTmp); VIR_FREE(target); target = g_steal_pointer(&tmp); @@ -13360,9 +13330,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; + virAsprintf(&opts, "mode=755,size=65536%s", mount_options); if (virFileSetupDev(data->path, opts) < 0) goto cleanup; @@ -14171,10 +14139,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver, if ((c = strrchr(fileTmp, '/'))) *(c + 1) = '\0'; - if (virAsprintf(&tmp, "%s%s", fileTmp, target) < 0) { - VIR_FREE(fileTmp); - goto cleanup; - } + virAsprintf(&tmp, "%s%s", fileTmp, target); VIR_FREE(fileTmp); VIR_FREE(target); target = g_steal_pointer(&tmp); @@ -14730,7 +14695,7 @@ qemuDomainDiskBackingStoreGetName(virDomainDiskDefPtr disk, char *ret = NULL; if (idx) - ignore_value(virAsprintf(&ret, "%s[%d]", disk->dst, idx)); + virAsprintf(&ret, "%s[%d]", disk->dst, idx); else ret = g_strdup(disk->dst); @@ -15173,9 +15138,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; + virAsprintf(&src->nodestorage, "libvirt-%u-storage", src->id); + virAsprintf(&src->nodeformat, "libvirt-%u-format", src->id); if (qemuDomainValidateStorageSource(src, priv->qemuCaps) < 0) return -1; @@ -15208,9 +15172,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) + virAsprintf(&diskPriv->nodeCopyOnRead, "libvirt-CoR-%s", disk->dst); for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) { if (qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0) @@ -15363,8 +15326,7 @@ qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv) { char *ret = NULL; - ignore_value(virAsprintf(&ret, "%s/%s.sock", priv->libDir, - qemuDomainGetManagedPRAlias())); + virAsprintf(&ret, "%s/%s.sock", priv->libDir, qemuDomainGetManagedPRAlias()); return ret; } @@ -15451,27 +15413,25 @@ qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk) } -int +void qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg, virDomainDefPtr def, char **path) { - return virAsprintf(path, "%s/%s_VARS.fd", cfg->nvramDir, def->name); + virAsprintf(path, "%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; } diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index b23912ee98..88d1acb64f 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -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); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index af8cbf40f4..0c94261ba8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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, @@ -7756,8 +7755,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); diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 670662fd4b..c6462c723e 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -1058,8 +1058,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, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index fd4bafef0c..1bf0c63eb1 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -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; + virAsprintf(&zpciAlias, "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; + virAsprintf(&slirpfdName, "slirpfd-%s", net->info.alias); } break; @@ -1357,15 +1355,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++) + virAsprintf(&tapfdName[i], "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++) + virAsprintf(&vhostfdName[i], "vhostfd-%s%zu", net->info.alias, i); if (!(netstr = qemuBuildHostNetStr(net, tapfdName, tapfdSize, @@ -1508,19 +1502,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)); - } + virAsprintf(&netdev_name, "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; } @@ -2360,8 +2353,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; + virAsprintf(&objalias, "mem%s", mem->info.alias); if (!(devstr = qemuBuildMemoryDeviceStr(mem, priv))) goto cleanup; @@ -2707,8 +2699,7 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriverPtr driver, if (virSCSIVHostOpenVhostSCSI(&vhostfd) < 0) goto cleanup; - if (virAsprintf(&vhostfdName, "vhostfd-%d", vhostfd) < 0) - goto cleanup; + virAsprintf(&vhostfdName, "vhostfd-%d", vhostfd); if (hostdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) { if (qemuDomainIsS390CCW(vm->def) && @@ -2965,8 +2956,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; @@ -2980,8 +2970,7 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver, goto cleanup; if (shmem->server.enabled) { - if (virAsprintf(&charAlias, "char%s", shmem->info.alias) < 0) - goto cleanup; + virAsprintf(&charAlias, "char%s", shmem->info.alias); } else { if (!(props = qemuBuildShmemBackendMemProps(shmem))) goto cleanup; @@ -3253,8 +3242,7 @@ qemuDomainAttachVsockDevice(virQEMUDriverPtr driver, if (qemuProcessOpenVhostVsock(vsock) < 0) goto cleanup; - if (virAsprintf(&fdname, "%s%u", fdprefix, vsockPriv->vhostfd) < 0) - goto cleanup; + virAsprintf(&fdname, "%s%u", fdprefix, vsockPriv->vhostfd); if (!(devstr = qemuBuildVsockDevStr(vm->def, vsock, priv->qemuCaps, fdprefix))) goto cleanup; @@ -3987,8 +3975,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; + virAsprintf(&validTo, "%lu", (unsigned long)auth->validTo); expire = validTo; } else { expire = "never"; @@ -4343,8 +4330,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; + virAsprintf(&backendAlias, "mem%s", mem->info.alias); qemuDomainObjEnterMonitor(driver, vm); rc = qemuMonitorDelObject(priv->mon, backendAlias); @@ -4562,8 +4548,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))) + virAsprintf(&hostnet_name, "host%s", net->info.alias); + if (!(charDevAlias = qemuAliasChardevFromDevAlias(net->info.alias))) return -1; if (virDomainNetGetActualBandwidth(net) && @@ -4717,8 +4703,7 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver, rng->info.alias, vm, vm->def->name); - if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0) - return -1; + virAsprintf(&objAlias, "obj%s", rng->info.alias); if (!(charAlias = qemuAliasChardevFromDevAlias(rng->info.alias))) return -1; @@ -4777,11 +4762,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; + virAsprintf(&charAlias, "char%s", shmem->info.alias); } else { - if (virAsprintf(&memAlias, "shmmem-%s", shmem->info.alias) < 0) - return -1; + virAsprintf(&memAlias, "shmmem-%s", shmem->info.alias); } qemuDomainObjEnterMonitor(driver, vm); @@ -6022,8 +6005,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver, size_t i; if (newhotplug) { - if (virAsprintf(&vcpupriv->alias, "vcpu%u", vcpu) < 0) - goto cleanup; + virAsprintf(&vcpupriv->alias, "vcpu%u", vcpu); if (!(vcpuprops = qemuBuildHotpluggableCPUProps(vcpuinfo))) goto cleanup; diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 70832e0c9a..8377b4d01d 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -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) + virAsprintf(&errstr, "\nstderr=%s", errbuf); virReportError(VIR_ERR_INTERNAL_ERROR, _("%s: failed to communicate with bridge helper: %s%s"), diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index d05ff56221..00b86fde83 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -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; + virAsprintf(&path, "%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; + virAsprintf(&xdgConfig, "%s/.config", home); } - if (virAsprintf(&homeConfig, "%s/qemu/%s", xdgConfig, name) < 0) - return -1; + virAsprintf(&homeConfig, "%s/qemu/%s", xdgConfig, name); } if (!(files = virHashCreate(10, virHashValueFree))) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 3f90536339..aad2f77cb7 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -818,9 +818,8 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver, copysrc->tlsAlias = g_strdup(tlsAlias); - if (virAsprintf(©src->nodestorage, "migration-%s-storage", disk->dst) < 0 || - virAsprintf(©src->nodeformat, "migration-%s-format", disk->dst) < 0) - return -1; + virAsprintf(©src->nodestorage, "migration-%s-storage", disk->dst); + virAsprintf(©src->nodeformat, "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; + virAsprintf(&nbd_dest, "nbd:[%s]:%d:exportname=%s", host, port, + diskAlias); } else { - if (virAsprintf(&nbd_dest, "nbd:%s:%d:exportname=%s", - host, port, diskAlias) < 0) - return -1; + virAsprintf(&nbd_dest, "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)); + virAsprintf(&uri, "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; + virAsprintf(&migrateFrom, 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; + virAsprintf(&tmp, "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; + virAsprintf(uri_out, 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; + virAsprintf(uri_out, "%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; + virAsprintf(&port, "%d", spec->dest.host.port); spec->destType = MIGRATION_DEST_FD; spec->dest.fd.qemu = -1; diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index f625c7086b..990f2b06d0 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -141,8 +141,7 @@ qemuDomainExtractTLSSubject(const char *certdir) int ret; size_t subjectlen; - if (virAsprintf(&certfile, "%s/server-cert.pem", certdir) < 0) - goto error; + virAsprintf(&certfile, "%s/server-cert.pem", certdir); if (virFileReadAll(certfile, 8192, &pemdata) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index db27b0e796..6495447188 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -961,7 +961,7 @@ qemuMonitorNextCommandID(qemuMonitorPtr mon) { char *id; - ignore_value(virAsprintf(&id, "libvirt-%d", ++mon->nextSerial)); + virAsprintf(&id, "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; - } + virAsprintf(&uri, "%s:[%s]:%d", protocol, hostname, port); + } else virAsprintf(&uri, "%s:%s:%d", protocol, hostname, port); ret = qemuMonitorJSONMigrate(mon, flags, uri); @@ -4249,20 +4246,20 @@ 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)); + 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); 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)); + 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); break; case QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_NONE: case QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_LAST: diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 99f55c420a..697b302a7c 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7120,8 +7120,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; + virAsprintf(&port_str, "%u", server->port); addr = qemuMonitorJSONBuildInetSocketAddress(server->name, port_str); break; case VIR_STORAGE_NET_HOST_TRANS_UNIX: @@ -8052,9 +8051,7 @@ qemuMonitorJSONSetIOThread(qemuMonitorPtr mon, char *path = NULL; qemuMonitorJSONObjectProperty prop; - if (virAsprintf(&path, "/objects/iothread%u", - iothreadInfo->iothread_id) < 0) - goto cleanup; + virAsprintf(&path, "/objects/iothread%u", iothreadInfo->iothread_id); #define VIR_IOTHREAD_SET_PROP(propName, propVal) \ if (iothreadInfo->set_##propVal) { \ @@ -8212,13 +8209,11 @@ qemuMonitorJSONFindObjectPathByAlias(qemuMonitorPtr mon, if (npaths < 0) return -1; - if (virAsprintf(&child, "child<%s>", name) < 0) - goto cleanup; + virAsprintf(&child, "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; + virAsprintf(path, "/machine/peripheral/%s", alias); ret = 0; goto cleanup; @@ -8270,10 +8265,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; - } + virAsprintf(path, "%s/%s", curpath, paths[i]->name); goto cleanup; } @@ -8281,10 +8273,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; - } + virAsprintf(&nextpath, "%s/%s", curpath, paths[i]->name); ret = qemuMonitorJSONFindObjectPathByName(mon, nextpath, name, path); VIR_FREE(nextpath); @@ -8327,8 +8316,7 @@ qemuMonitorJSONFindLinkPath(qemuMonitorPtr mon, return ret; } - if (virAsprintf(&linkname, "link<%s>", name) < 0) - return -1; + virAsprintf(&linkname, "link<%s>", name); ret = qemuMonitorJSONFindObjectPathByName(mon, "/", linkname, path); VIR_FREE(linkname); diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index b1abcacdd0..a5b2d2ccfd 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -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; + virAsprintf(&cmd, "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; + virAsprintf(&cmd, "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; + virAsprintf(&cmd, "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; + virAsprintf(&cmd, "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; + virAsprintf(&cmd, "delvm \"%s\"", name); if (qemuMonitorJSONHumanCommand(mon, cmd, &reply)) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7e0dc26658..925fc44a70 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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; + virAsprintf(&file, "%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; + virAsprintf(&id, "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; + virAsprintf(&id, "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; + virAsprintf(&monConfig->data.nix.path, "%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))); + virAsprintf(&msg, "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; + virAsprintf(&cpuFeature, "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; + virAsprintf(&glisten->socket, "%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; + virAsprintf(&glisten->socket, "%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; + virAsprintf(&vcpupriv->alias, "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: @@ -8503,8 +8480,7 @@ qemuProcessQMPInit(qemuProcessQMPPtr proc) VIR_DEBUG("proc=%p, emulator=%s", proc, proc->binary); - if (virAsprintf(&template, "%s/qmp-XXXXXX", proc->libDir) < 0) - goto cleanup; + virAsprintf(&template, "%s/qmp-XXXXXX", proc->libDir); if (!(proc->uniqDir = mkdtemp(template))) { virReportSystemError(errno, @@ -8517,20 +8493,16 @@ qemuProcessQMPInit(qemuProcessQMPPtr proc) if (qemuProcessQEMULabelUniqPath(proc) < 0) goto cleanup; - if (virAsprintf(&proc->monpath, "%s/%s", proc->uniqDir, - "qmp.monitor") < 0) - goto cleanup; + virAsprintf(&proc->monpath, "%s/%s", proc->uniqDir, "qmp.monitor"); - if (virAsprintf(&proc->monarg, "unix:%s,server,nowait", proc->monpath) < 0) - goto cleanup; + virAsprintf(&proc->monarg, "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; + virAsprintf(&proc->pidfile, "%s/%s", proc->uniqDir, "qmp.pid"); ret = 0; diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c index 0b45315a0b..c08a365548 100644 --- a/src/qemu/qemu_slirp.c +++ b/src/qemu/qemu_slirp.c @@ -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; + virAsprintf(&name, "%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; + virAsprintf(&id, "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; + virAsprintf(&path, "%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; + virAsprintf(&dbus_addr, "unix:path=%s", dbus_path); virCommandAddArgFormat(cmd, "--dbus-id=%s", id); diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index f21dbf9727..d6d418533c 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -78,9 +78,7 @@ qemuTPMCreateEmulatorStoragePath(const char *swtpmStorageDir, return NULL; } - ignore_value(virAsprintf(&path, "%s/%s/%s", swtpmStorageDir, uuidstr, - dir)); - + virAsprintf(&path, "%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)); + virAsprintf(&path, "%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; + virAsprintf(&devicename, "%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) + virAsprintf(&tpm->data.emulator.logfile, "%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; + virAsprintf(&vmid, "%s:%s", vmname, uuid); virCommandSetUID(cmd, swtpm_user); virCommandSetGID(cmd, swtpm_group); diff --git a/src/qemu/qemu_vhost_user_gpu.c b/src/qemu/qemu_vhost_user_gpu.c index 49f48c6d08..7355ae70f8 100644 --- a/src/qemu/qemu_vhost_user_gpu.c +++ b/src/qemu/qemu_vhost_user_gpu.c @@ -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; + virAsprintf(&devicename, "%s-%s-vhost-user-gpu", shortName, alias); return virPidFileBuildPath(stateDir, devicename); } -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list