mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
qemu: Remove unnecessary variables and labels
This patch removes variables such as 'ret', 'rc' and others which are easily replaced. Therefore, making the code look cleaner and easier to understand. Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
c7edcb320b
commit
fa7023f4eb
@ -52,7 +52,6 @@ virDriverLoadModule(const char *name,
|
||||
bool required)
|
||||
{
|
||||
g_autofree char *modfile = NULL;
|
||||
int ret;
|
||||
|
||||
VIR_DEBUG("Module load %s", name);
|
||||
|
||||
@ -64,8 +63,7 @@ virDriverLoadModule(const char *name,
|
||||
"LIBVIRT_DRIVER_DIR")))
|
||||
return -1;
|
||||
|
||||
ret = virModuleLoad(modfile, regfunc, required);
|
||||
return ret;
|
||||
return virModuleLoad(modfile, regfunc, required);
|
||||
}
|
||||
|
||||
|
||||
|
@ -176,7 +176,6 @@ qemuAgentOpenUnix(const char *socketpath)
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
int agentfd;
|
||||
int ret = -1;
|
||||
|
||||
if ((agentfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||
virReportSystemError(errno,
|
||||
@ -199,8 +198,7 @@ qemuAgentOpenUnix(const char *socketpath)
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = connect(agentfd, (struct sockaddr *)&addr, sizeof(addr));
|
||||
if (ret < 0) {
|
||||
if (connect(agentfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
_("failed to connect to agent socket"));
|
||||
goto error;
|
||||
|
@ -744,16 +744,13 @@ qemuAssignDeviceAliases(virDomainDef *def, virQEMUCaps *qemuCaps)
|
||||
char *
|
||||
qemuAliasDiskDriveFromDisk(const virDomainDiskDef *disk)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (!disk->info.alias) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("disk does not have an alias"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = g_strdup_printf("%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
|
||||
return ret;
|
||||
return g_strdup_printf("%s%s", QEMU_DRIVE_HOST_PREFIX, disk->info.alias);
|
||||
}
|
||||
|
||||
|
||||
@ -780,18 +777,15 @@ qemuAliasDiskDriveSkipPrefix(const char *dev_name)
|
||||
char *
|
||||
qemuAliasFromHostdev(const virDomainHostdevDef *hostdev)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (!hostdev->info->alias) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("hostdev does not have an alias"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = g_strdup_printf("%s-%s",
|
||||
virDomainDeviceAddressTypeToString(hostdev->info->type),
|
||||
hostdev->info->alias);
|
||||
return ret;
|
||||
return g_strdup_printf("%s-%s",
|
||||
virDomainDeviceAddressTypeToString(hostdev->info->type),
|
||||
hostdev->info->alias);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3070,7 +3070,6 @@ virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
|
||||
g_auto(GStrv) list = NULL;
|
||||
size_t i;
|
||||
size_t n;
|
||||
int ret = -1;
|
||||
|
||||
*features = NULL;
|
||||
modelInfo = virQEMUCapsGetCPUModelInfo(qemuCaps, virtType);
|
||||
@ -3091,12 +3090,10 @@ virQEMUCapsGetCPUFeatures(virQEMUCaps *qemuCaps,
|
||||
}
|
||||
|
||||
*features = g_steal_pointer(&list);
|
||||
if (migratable && !modelInfo->migratability)
|
||||
ret = 1;
|
||||
else
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
if (migratable && !modelInfo->migratability)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -5237,15 +5234,13 @@ virQEMUCapsProbeQMPSchemaCapabilities(virQEMUCaps *qemuCaps,
|
||||
virDomainVirtType
|
||||
virQEMUCapsGetVirtType(virQEMUCaps *qemuCaps)
|
||||
{
|
||||
virDomainVirtType type;
|
||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
|
||||
type = VIR_DOMAIN_VIRT_KVM;
|
||||
else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_TCG))
|
||||
type = VIR_DOMAIN_VIRT_QEMU;
|
||||
else
|
||||
type = VIR_DOMAIN_VIRT_NONE;
|
||||
return VIR_DOMAIN_VIRT_KVM;
|
||||
|
||||
return type;
|
||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_TCG))
|
||||
return VIR_DOMAIN_VIRT_QEMU;
|
||||
|
||||
return VIR_DOMAIN_VIRT_NONE;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -336,18 +336,15 @@ static int
|
||||
qemuSetupTPMCgroup(virDomainObj *vm,
|
||||
virDomainTPMDef *dev)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (dev->type) {
|
||||
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
|
||||
ret = qemuSetupChrSourceCgroup(vm, dev->data.passthrough.source);
|
||||
break;
|
||||
return qemuSetupChrSourceCgroup(vm, dev->data.passthrough.source);
|
||||
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
|
||||
case VIR_DOMAIN_TPM_TYPE_LAST:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1915,16 +1915,13 @@ qemuGetBaseHugepagePath(virQEMUDriver *driver,
|
||||
virHugeTLBFS *hugepage)
|
||||
{
|
||||
const char *root = driver->embeddedRoot;
|
||||
char *ret;
|
||||
|
||||
if (root && !STRPREFIX(hugepage->mnt_dir, root)) {
|
||||
g_autofree char * hash = virDomainDriverGenerateRootHash("qemu", root);
|
||||
ret = g_strdup_printf("%s/libvirt/%s", hugepage->mnt_dir, hash);
|
||||
} else {
|
||||
ret = g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir);
|
||||
return g_strdup_printf("%s/libvirt/%s", hugepage->mnt_dir, hash);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir);
|
||||
}
|
||||
|
||||
|
||||
@ -1935,11 +1932,11 @@ qemuGetDomainHugepagePath(virQEMUDriver *driver,
|
||||
{
|
||||
g_autofree char *base = qemuGetBaseHugepagePath(driver, hugepage);
|
||||
g_autofree char *domPath = virDomainDefGetShortName(def);
|
||||
char *ret = NULL;
|
||||
|
||||
if (base && domPath)
|
||||
ret = g_strdup_printf("%s/%s", base, domPath);
|
||||
return ret;
|
||||
if (!base || !domPath)
|
||||
return NULL;
|
||||
|
||||
return g_strdup_printf("%s/%s", base, domPath);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2465,7 +2465,6 @@ static int
|
||||
qemuDomainAddressFindNewTargetIndex(virDomainDef *def)
|
||||
{
|
||||
int targetIndex;
|
||||
int ret = -1;
|
||||
|
||||
/* Try all indexes between 1 and 31 - QEMU only supports 32
|
||||
* PHBs, and 0 is reserved for the default, implicit one */
|
||||
@ -2490,13 +2489,11 @@ qemuDomainAddressFindNewTargetIndex(virDomainDef *def)
|
||||
|
||||
/* If no existing PCI controller uses this index, great,
|
||||
* it means it's free and we can return it to the caller */
|
||||
if (!found) {
|
||||
ret = targetIndex;
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
return targetIndex;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1332,7 +1332,6 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
|
||||
g_autofree char *data = NULL;
|
||||
g_auto(GStrv) lines = NULL;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
double val;
|
||||
|
||||
*cpuWait = 0;
|
||||
@ -1344,21 +1343,19 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
|
||||
else
|
||||
proc = g_strdup_printf("/proc/%d/sched", (int)pid);
|
||||
if (!proc)
|
||||
goto cleanup;
|
||||
ret = -1;
|
||||
return -1;
|
||||
|
||||
/* The file is not guaranteed to exist (needs CONFIG_SCHED_DEBUG) */
|
||||
if (access(proc, R_OK) < 0) {
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (virFileReadAll(proc, (1<<16), &data) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
lines = g_strsplit(data, "\n", 0);
|
||||
if (!lines)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
for (i = 0; lines[i] != NULL; i++) {
|
||||
const char *line = lines[i];
|
||||
@ -1372,7 +1369,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Missing separator in sched info '%s'"),
|
||||
lines[i]);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
line++;
|
||||
while (*line == ' ')
|
||||
@ -1382,7 +1379,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Unable to parse sched info value '%s'"),
|
||||
line);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*cpuWait = (unsigned long long)(val * 1000000);
|
||||
@ -1390,10 +1387,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait,
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -3158,7 +3152,6 @@ doCoreDump(virQEMUDriver *driver,
|
||||
{
|
||||
int fd = -1;
|
||||
int ret = -1;
|
||||
int rc = -1;
|
||||
virFileWrapperFd *wrapperFd = NULL;
|
||||
int directFlag = 0;
|
||||
bool needUnlink = false;
|
||||
@ -3204,8 +3197,9 @@ doCoreDump(virQEMUDriver *driver,
|
||||
if (STREQ(memory_dump_format, "elf"))
|
||||
memory_dump_format = NULL;
|
||||
|
||||
rc = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
|
||||
memory_dump_format);
|
||||
if (qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
|
||||
memory_dump_format) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (dumpformat != VIR_DOMAIN_CORE_DUMP_FORMAT_RAW) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
@ -3217,13 +3211,11 @@ doCoreDump(virQEMUDriver *driver,
|
||||
if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0))
|
||||
goto cleanup;
|
||||
|
||||
rc = qemuMigrationSrcToFile(driver, vm, fd, compressor,
|
||||
QEMU_ASYNC_JOB_DUMP);
|
||||
if (qemuMigrationSrcToFile(driver, vm, fd, compressor,
|
||||
QEMU_ASYNC_JOB_DUMP) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (rc < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (VIR_CLOSE(fd) < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("unable to close file %s"),
|
||||
@ -7205,14 +7197,12 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm,
|
||||
{
|
||||
virQEMUDriver *driver = dom->conn->privateData;
|
||||
virDomainDeviceDef oldDev = { .type = dev->type };
|
||||
int ret = -1;
|
||||
int idx;
|
||||
|
||||
switch ((virDomainDeviceType)dev->type) {
|
||||
case VIR_DOMAIN_DEVICE_DISK:
|
||||
qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL);
|
||||
ret = qemuDomainChangeDiskLive(vm, dev, driver, force);
|
||||
break;
|
||||
return qemuDomainChangeDiskLive(vm, dev, driver, force);
|
||||
|
||||
case VIR_DOMAIN_DEVICE_GRAPHICS:
|
||||
if ((idx = qemuDomainFindGraphicsIndex(vm->def, dev->data.graphics)) >= 0) {
|
||||
@ -7223,8 +7213,7 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm,
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = qemuDomainChangeGraphics(driver, vm, dev->data.graphics);
|
||||
break;
|
||||
return qemuDomainChangeGraphics(driver, vm, dev->data.graphics);
|
||||
|
||||
case VIR_DOMAIN_DEVICE_NET:
|
||||
if ((idx = virDomainNetFindIdx(vm->def, dev->data.net)) >= 0) {
|
||||
@ -7235,12 +7224,10 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm,
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = qemuDomainChangeNet(driver, vm, dev);
|
||||
break;
|
||||
return qemuDomainChangeNet(driver, vm, dev);
|
||||
|
||||
case VIR_DOMAIN_DEVICE_MEMORY:
|
||||
ret = qemuDomainChangeMemoryLive(driver, vm, dev);
|
||||
break;
|
||||
return qemuDomainChangeMemoryLive(driver, vm, dev);
|
||||
|
||||
case VIR_DOMAIN_DEVICE_FS:
|
||||
case VIR_DOMAIN_DEVICE_INPUT:
|
||||
@ -7268,10 +7255,10 @@ qemuDomainUpdateDeviceLive(virDomainObj *vm,
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("live update of device '%s' is not supported"),
|
||||
virDomainDeviceTypeToString(dev->type));
|
||||
break;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -9661,13 +9648,11 @@ qemuGetVcpusBWLive(virDomainObj *vm,
|
||||
{
|
||||
g_autoptr(virCgroup) cgroup_vcpu = NULL;
|
||||
qemuDomainObjPrivate *priv = NULL;
|
||||
int rc;
|
||||
|
||||
priv = vm->privateData;
|
||||
if (!qemuDomainHasVcpuPids(vm)) {
|
||||
/* We do not create sub dir for each vcpu */
|
||||
rc = qemuGetVcpuBWLive(priv->cgroup, period, quota);
|
||||
if (rc < 0)
|
||||
if (qemuGetVcpuBWLive(priv->cgroup, period, quota) < 0)
|
||||
return -1;
|
||||
|
||||
if (*quota > 0)
|
||||
@ -9680,8 +9665,7 @@ qemuGetVcpusBWLive(virDomainObj *vm,
|
||||
false, &cgroup_vcpu) < 0)
|
||||
return -1;
|
||||
|
||||
rc = qemuGetVcpuBWLive(cgroup_vcpu, period, quota);
|
||||
if (rc < 0)
|
||||
if (qemuGetVcpuBWLive(cgroup_vcpu, period, quota) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@ -9711,12 +9695,11 @@ qemuGetIOThreadsBWLive(virDomainObj *vm,
|
||||
{
|
||||
g_autoptr(virCgroup) cgroup_iothread = NULL;
|
||||
qemuDomainObjPrivate *priv = NULL;
|
||||
int rc;
|
||||
|
||||
priv = vm->privateData;
|
||||
if (!vm->def->niothreadids) {
|
||||
/* We do not create sub dir for each iothread */
|
||||
if ((rc = qemuGetVcpuBWLive(priv->cgroup, period, quota)) < 0)
|
||||
if (qemuGetVcpuBWLive(priv->cgroup, period, quota) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
@ -9728,8 +9711,7 @@ qemuGetIOThreadsBWLive(virDomainObj *vm,
|
||||
false, &cgroup_iothread) < 0)
|
||||
return -1;
|
||||
|
||||
rc = qemuGetVcpuBWLive(cgroup_iothread, period, quota);
|
||||
if (rc < 0)
|
||||
if (qemuGetVcpuBWLive(cgroup_iothread, period, quota) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user