pid_t pid,
unsigned int flags)
{
- int ret = -1;
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
continue;
if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
virCgroupV1AllowAllDevices(virCgroupPtr group,
int perms)
{
- int ret = -1;
-
if (virCgroupV1AllowDevice(group, 'b', -1, -1, perms) < 0)
- goto cleanup;
+ return -1;
if (virCgroupV1AllowDevice(group, 'c', -1, -1, perms) < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
static int
virExecCommon(virCommandPtr cmd, gid_t *groups, int ngroups)
{
- int ret = -1;
-
if (cmd->uid != (uid_t)-1 || cmd->gid != (gid_t)-1 ||
cmd->capabilities || (cmd->flags & VIR_EXEC_CLEAR_CAPS)) {
VIR_DEBUG("Setting child uid:gid to %d:%d with caps %llx",
if (virSetUIDGIDWithCaps(cmd->uid, cmd->gid, groups, ngroups,
cmd->capabilities,
!!(cmd->flags & VIR_EXEC_CLEAR_CAPS)) < 0)
- goto cleanup;
+ return -1;
}
if (cmd->pwd) {
if (chdir(cmd->pwd) < 0) {
virReportSystemError(errno,
_("Unable to change to %s"), cmd->pwd);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
# ifdef __linux__
va_list args)
{
DBusMessageIter iter;
- int ret = -1;
if (!dbus_message_iter_init(msg, &iter)) {
if (*types != '\0') {
_("No args present for signature %s"),
types);
} else {
- ret = 0;
+ return 0;
}
- goto cleanup;
+ return -1;
}
- ret = virDBusMessageIterDecode(&iter, types, args);
-
- cleanup:
- return ret;
+ return virDBusMessageIterDecode(&iter, types, args);
}
const char *types,
va_list args)
{
- int ret = -1;
-
if (!(*call = dbus_message_new_method_call(destination,
path,
iface,
member))) {
virReportOOMError();
- goto cleanup;
+ return -1;
}
if (virDBusMessageEncodeArgs(*call, types, args) < 0) {
virDBusMessageUnref(*call);
*call = NULL;
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
const char *types,
va_list args)
{
- int ret = -1;
-
if (!(*reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN))) {
virReportOOMError();
- goto cleanup;
+ return -1;
}
if (virDBusMessageEncodeArgs(*reply, types, args) < 0) {
virDBusMessageUnref(*reply);
*reply = NULL;
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
virFileGetHugepageSize(const char *path,
unsigned long long *size)
{
- int ret = -1;
struct statfs fs;
if (statfs(path, &fs) < 0) {
virReportSystemError(errno,
_("cannot determine filesystem for '%s'"),
path);
- goto cleanup;
+ return -1;
}
if (fs.f_type != HUGETLBFS_MAGIC) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("not a hugetlbfs mount: '%s'"),
path);
- goto cleanup;
+ return -1;
}
*size = fs.f_bsize / 1024; /* we are storing size in KiB */
- ret = 0;
- cleanup:
- return ret;
+
+ return 0;
}
# define PROC_MEMINFO "/proc/meminfo"
{
const unsigned long mount_flags = MS_NOSUID;
const char *mount_fs = "tmpfs";
- int ret = -1;
if (virFileMakePath(path) < 0) {
virReportSystemError(errno,
_("Failed to make path %s"), path);
- goto cleanup;
+ return -1;
}
VIR_DEBUG("Mount devfs on %s type=tmpfs flags=0x%lx, opts=%s",
virReportSystemError(errno,
_("Failed to mount devfs on %s type %s (%s)"),
path, mount_fs, mount_options);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
ret = iter(entry->payload, entry->name, data);
if (ret < 0)
- goto cleanup;
+ return ret;
entry = next;
}
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
virNodeCPUStatsPtr params,
int *nparams)
{
- int ret = -1;
char line[1024];
unsigned long long usr, ni, sys, idle, iowait;
unsigned long long irq, softirq, steal, guest, guest_nice;
if ((*nparams) == 0) {
/* Current number of cpu stats supported by linux */
*nparams = LINUX_NB_CPU_STATS;
- ret = 0;
- goto cleanup;
+ return 0;
}
if ((*nparams) != LINUX_NB_CPU_STATS) {
virReportInvalidArg(*nparams,
_("nparams in %s must be equal to %d"),
__FUNCTION__, LINUX_NB_CPU_STATS);
- goto cleanup;
+ return -1;
}
if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) {
if (virHostCPUStatsAssign(¶ms[0], VIR_NODE_CPU_STATS_KERNEL,
(sys + irq + softirq) * TICK_TO_NSEC) < 0)
- goto cleanup;
+ return -1;
if (virHostCPUStatsAssign(¶ms[1], VIR_NODE_CPU_STATS_USER,
(usr + ni) * TICK_TO_NSEC) < 0)
- goto cleanup;
+ return -1;
if (virHostCPUStatsAssign(¶ms[2], VIR_NODE_CPU_STATS_IDLE,
idle * TICK_TO_NSEC) < 0)
- goto cleanup;
+ return -1;
if (virHostCPUStatsAssign(¶ms[3], VIR_NODE_CPU_STATS_IOWAIT,
iowait * TICK_TO_NSEC) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- goto cleanup;
+ return 0;
}
}
_("Invalid cpuNum in %s"),
__FUNCTION__);
- cleanup:
- return ret;
+ return 0;
}
static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *opaque)
{
virPCIDevicePtr actual;
- int ret = -1;
struct virHostdevIsPCINodeDeviceUsedData *helperData = opaque;
actual = virPCIDeviceListFindByIDs(helperData->mgr->activePCIHostdevs,
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is in use"),
virPCIDeviceGetName(actual));
- goto cleanup;
+ return -1;
}
iommu_owner:
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int virHostdevManagerOnceInit(void)
virNodeMemoryStatsPtr params,
int *nparams)
{
- int ret = -1;
size_t i = 0, j = 0, k = 0;
int found = 0;
int nr_param;
if ((*nparams) == 0) {
/* Current number of memory stats supported by linux */
*nparams = nr_param;
- ret = 0;
- goto cleanup;
+ return 0;
}
if ((*nparams) != nr_param) {
virReportInvalidArg(nparams,
_("nparams in %s must be %d"),
__FUNCTION__, nr_param);
- goto cleanup;
+ return -1;
}
while (fgets(line, sizeof(line), meminfo) != NULL) {
if (p == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no prefix found"));
- goto cleanup;
+ return -1;
}
p++;
}
if (virStrcpyStatic(param->field, convp->field) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Field kernel memory too long for destination"));
- goto cleanup;
+ return -1;
}
param->value = val;
found++;
if (found == 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no available memory line found"));
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
#endif
virHostMemGetInfoFake(unsigned long long *mem,
unsigned long long *freeMem)
{
- int ret = -1;
-
if (mem) {
double total = physmem_total();
if (!total) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot determine free memory"));
- goto cleanup;
+ return -1;
}
*mem = (unsigned long long) total;
if (!avail) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Cannot determine free memory"));
- goto cleanup;
+ return -1;
}
*freeMem = (unsigned long long) avail;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
{
unsigned long long mem;
int n, lastCell, numCells;
- int ret = -1;
int maxCell;
if (!virNumaIsAvailable())
virReportError(VIR_ERR_INTERNAL_ERROR,
_("start cell %d out of range (0-%d)"),
startCell, maxCell);
- goto cleanup;
+ return -1;
}
lastCell = startCell + maxCells - 1;
if (lastCell > maxCell)
freeMems[numCells++] = mem;
}
- ret = numCells;
-
- cleanup:
- return ret;
+ return numCells;
}
int
unsigned int cellCount,
unsigned long long *counts)
{
- int ret = -1;
int cell, lastCell;
size_t i, ncounts = 0;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("start cell %d out of range (0-%d)"),
startCell, lastCell);
- goto cleanup;
+ return -1;
}
lastCell = MIN(lastCell, startCell + (int) cellCount - 1);
unsigned long long page_free;
if (virNumaGetPageInfo(cell, page_size, 0, NULL, &page_free) < 0)
- goto cleanup;
+ return -1;
counts[ncounts++] = page_free;
}
if (!ncounts) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no suitable info found"));
- goto cleanup;
+ return -1;
}
- ret = ncounts;
- cleanup:
- return ret;
+ return ncounts;
}
int
unsigned int cellCount,
bool add)
{
- int ret = -1;
int cell, lastCell;
size_t i, ncounts = 0;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("start cell %d out of range (0-%d)"),
startCell, lastCell);
- goto cleanup;
+ return -1;
}
lastCell = MIN(lastCell, startCell + (int) cellCount - 1);
unsigned long long page_count = pageCounts[i];
if (virNumaSetPagePoolSize(cell, page_size, page_count, add) < 0)
- goto cleanup;
+ return -1;
ncounts++;
}
}
- ret = ncounts;
- cleanup:
- return ret;
+ return ncounts;
}
{
char type;
char *key;
- int ret = -1;
int rc;
while ((key = va_arg(args, char *)) != NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' is too short, missing type prefix"),
key);
- goto cleanup;
+ return -1;
}
type = key[0];
virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not have null value"),
key);
- goto cleanup;
+ return -1;
}
rc = virJSONValueObjectAppendString(obj, key, val);
} break;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not be negative"),
key);
- goto cleanup;
+ return -1;
}
if (!val && (type == 'z' || type == 'y'))
virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not be negative"),
key);
- goto cleanup;
+ return -1;
}
if (!val && (type == 'Z' || type == 'Y'))
virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not have null value"),
key);
- goto cleanup;
+ return -1;
}
if ((rc = virJSONValueObjectAppend(obj, key, *val)) == 0)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("argument key '%s' must not have null value"),
key);
- goto cleanup;
+ return -1;
}
if (!(jsonMap = virJSONValueNewArrayFromBitmap(map)))
- goto cleanup;
+ return -1;
if ((rc = virJSONValueObjectAppend(obj, key, jsonMap)) < 0)
virJSONValueFree(jsonMap);
default:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unsupported data type '%c' for arg '%s'"), type, key - 2);
- goto cleanup;
+ return -1;
}
if (rc < 0)
- goto cleanup;
+ return -1;
}
/* verify that we added at least one key-value pair */
- if (virJSONValueObjectKeysNumber(obj) == 0) {
- ret = 0;
- goto cleanup;
- }
-
- ret = 1;
+ if (virJSONValueObjectKeysNumber(obj) == 0)
+ return 0;
- cleanup:
- return ret;
+ return 1;
}
const char *domain,
const char *mac)
{
- int ret = -1;
char **macsList = NULL;
if ((macsList = virHashLookup(mgr->macs, domain)) &&
virStringListHasString((const char**) macsList, mac)) {
- ret = 0;
- goto cleanup;
+ return 0;
}
if (virStringListAdd(&macsList, mac) < 0 ||
virHashUpdateEntry(mgr->macs, domain, macsList) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
const char *ifname,
bool *enable)
{
- int ret = -1;
unsigned long value;
if (virNetDevBridgePortGet(brname, ifname, "learning", &value) < 0)
- goto cleanup;
+ return -1;
*enable = !!value;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
const char *ifname,
bool *enable)
{
- int ret = -1;
unsigned long value;
if (virNetDevBridgePortGet(brname, ifname, "unicast_flood", &value) < 0)
- goto cleanup;
+ return -1;
*enable = !!value;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
virNetDevBridgeGetVlanFiltering(const char *brname,
bool *enable)
{
- int ret = -1;
unsigned long value;
if (virNetDevBridgeGet(brname, "vlan_filtering", &value) < 0)
- goto cleanup;
+ return -1;
*enable = !!value;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
{
nodemask_t mask;
int node = -1;
- int ret = -1;
int bit = 0;
size_t i;
int maxnode = 0;
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("NUMA memory tuning in 'preferred' mode "
"only supports single node"));
- goto cleanup;
+ return -1;
}
numa_set_bind_policy(0);
case VIR_DOMAIN_NUMATUNE_MEM_LAST:
break;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
bool
int **distances,
int *ndistances)
{
- int ret = -1;
int max_node;
size_t i;
}
if ((max_node = virNumaGetMaxNode()) < 0)
- goto cleanup;
+ return -1;
if (VIR_ALLOC_N(*distances, max_node + 1) < 0)
- goto cleanup;
+ return -1;
*ndistances = max_node + 1;
(*distances)[i] = numa_distance(node, i);
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
#else /* !(WITH_NUMACTL && HAVE_NUMA_BITMASK_ISBITSET) */
unsigned long long *page_avail,
unsigned long long *page_free)
{
- int ret = -1;
long system_page_size = virGetSystemPageSize();
/* sysconf() returns page size in bytes,
* account. The problem is huge pages cut off regular memory. */
if (node == -1) {
if (virHostMemGetInfo(&memsize, &memfree) < 0)
- goto cleanup;
+ return -1;
} else {
if (virNumaGetNodeMemory(node, &memsize, &memfree) < 0)
- goto cleanup;
+ return -1;
}
/* see description above */
*page_free = memfree / system_page_size;
} else {
if (virNumaGetHugePageInfo(node, page_size, page_avail, page_free) < 0)
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
virPCIDeviceAddressPtr **iommuGroupDevices,
size_t *nIommuGroupDevices)
{
- int ret = -1;
virPCIDeviceAddressList addrList = { iommuGroupDevices,
nIommuGroupDevices };
if (virPCIDeviceAddressIOMMUGroupIterate(devAddr,
virPCIGetIOMMUGroupAddressesAddOne,
&addrList) < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
{
size_t i;
- int ret = -1;
/* This is in 1/5th seconds since polling is on a 0.2s interval */
unsigned int polldelay = (force ? 200 : 75) + (extradelay*5);
const char *signame = "TERM";
virReportSystemError(errno,
_("Failed to terminate process %lld with SIG%s"),
(long long)pid, signame);
- goto cleanup;
+ return -1;
}
- ret = signum == SIGTERM ? 0 : 1;
- goto cleanup; /* process is dead */
+ return signum == SIGTERM ? 0 : 1;
}
g_usleep(200 * 1000);
_("Failed to terminate process %lld with SIG%s"),
(long long)pid, signame);
- cleanup:
- return ret;
+ return 0;
}
int
virProcessSetupPrivateMountNS(void)
{
- int ret = -1;
-
if (unshare(CLONE_NEWNS) < 0) {
virReportSystemError(errno, "%s",
_("Cannot unshare mount namespace"));
- goto cleanup;
+ return -1;
}
if (mount("", "/", "none", MS_SLAVE|MS_REC, NULL) < 0) {
virReportSystemError(errno, "%s",
_("Failed to switch root mount into slave mode"));
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
#else /* !defined(HAVE_SYS_MOUNT_H) || !defined(HAVE_UNSHARE) */
virResctrlInfoPerLevelPtr i_level = NULL;
virResctrlInfoPerTypePtr i_type = NULL;
size_t i = 0;
- int ret = -1;
if (virResctrlInfoIsEmpty(resctrl))
return 0;
memcpy((*controls)[*ncontrols - 1], &i_type->control, sizeof(i_type->control));
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
error:
while (*ncontrols)
VIR_FREE((*controls)[--*ncontrols]);
VIR_FREE(*controls);
- goto cleanup;
+ return -1;
}
static const char prefix[] = "parentFileNameHint=\"";
char *start, *end;
size_t len;
- int ret = BACKING_STORE_ERROR;
g_autofree char *desc = NULL;
if (VIR_ALLOC_N(desc, VIR_STORAGE_MAX_HEADER) < 0)
- goto cleanup;
+ return BACKING_STORE_ERROR;
*res = NULL;
/*
*/
*format = VIR_STORAGE_FILE_AUTO;
- if (buf_size <= 0x200) {
- ret = BACKING_STORE_INVALID;
- goto cleanup;
- }
+ if (buf_size <= 0x200)
+ return BACKING_STORE_INVALID;
+
len = buf_size - 0x200;
if (len > VIR_STORAGE_MAX_HEADER)
len = VIR_STORAGE_MAX_HEADER;
start = strstr(desc, prefix);
if (start == NULL) {
*format = VIR_STORAGE_FILE_NONE;
- ret = BACKING_STORE_OK;
- goto cleanup;
+ return BACKING_STORE_OK;
}
start += strlen(prefix);
end = strchr(start, '"');
- if (end == NULL) {
- ret = BACKING_STORE_INVALID;
- goto cleanup;
- }
+ if (end == NULL)
+ return BACKING_STORE_INVALID;
+
if (end == start) {
*format = VIR_STORAGE_FILE_NONE;
- ret = BACKING_STORE_OK;
- goto cleanup;
+ return BACKING_STORE_OK;
}
*end = '\0';
*res = g_strdup(start);
- ret = BACKING_STORE_OK;
-
- cleanup:
- return ret;
+ return BACKING_STORE_OK;
}
static int
virStorageSourcePtr old,
bool transferLabels)
{
- int ret = -1;
-
if (transferLabels &&
!newelem->seclabels &&
virStorageSourceSeclabelsCopy(newelem, old) < 0)
- goto cleanup;
+ return -1;
newelem->shared = old->shared;
newelem->readonly = old->readonly;
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
virJSONValuePtr servers = virJSONValueObjectGetArray(json, "server");
size_t nservers;
size_t i;
- int ret = -1;
src->type = VIR_STORAGE_TYPE_NETWORK;
src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD;
nservers = virJSONValueArraySize(servers);
if (VIR_ALLOC_N(src->hosts, nservers) < 0)
- goto cleanup;
+ return -1;
src->nhosts = nservers;
for (i = 0; i < nservers; i++) {
if (virStorageSourceParseBackingJSONInetSocketAddress(src->hosts + i,
virJSONValueArrayGet(servers, i)) < 0)
- goto cleanup;
+ return -1;
}
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
unsigned long long capBits, bool clearExistingCaps)
{
size_t i;
- int capng_ret, ret = -1;
+ int capng_ret;
bool need_setgid = false;
bool need_setuid = false;
bool need_setpcap = false;
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
virReportSystemError(errno, "%s",
_("prctl failed to set KEEPCAPS"));
- goto cleanup;
+ return -1;
}
/* Change to the temp capabilities */
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot apply process capabilities %d"), capng_ret);
- goto cleanup;
+ return -1;
}
}
if (virSetUIDGID(uid, gid, groups, ngroups) < 0)
- goto cleanup;
+ return -1;
/* Tell it we are done keeping capabilities */
if (prctl(PR_SET_KEEPCAPS, 0, 0, 0, 0)) {
virReportSystemError(errno, "%s",
_("prctl failed to reset KEEPCAPS"));
- goto cleanup;
+ return -1;
}
# ifdef PR_CAP_AMBIENT
_("prctl failed to enable '%s' in the "
"AMBIENT set"),
capstr);
- goto cleanup;
+ return -1;
}
}
}
if (((capng_ret = capng_apply(CAPNG_SELECT_CAPS)) < 0)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot apply process capabilities %d"), capng_ret);
- ret = -1;
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
#else