if (obj &&
virNetworkObjLoadAllPorts(obj, stateDir) < 0) {
virNetworkObjEndAPI(&obj);
- goto cleanup;
+ return -1;
}
virNetworkObjEndAPI(&obj);
}
- cleanup:
return ret;
}
g_autoptr(DIR) dh = NULL;
struct dirent *de;
int rc;
- int ret = -1;
if (!(dir = virNetworkObjGetPortStatusDir(net, stateDir)))
- goto cleanup;
+ return -1;
- if ((rc = virDirOpenIfExists(&dh, dir)) <= 0) {
- ret = rc;
- goto cleanup;
- }
+ if ((rc = virDirOpenIfExists(&dh, dir)) <= 0)
+ return rc;
while ((rc = virDirRead(dh, &de, dir)) > 0) {
char *file = NULL;
}
virHashRemoveAll(net->ports);
-
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
g_autofree char *dir = NULL;
g_autoptr(DIR) dh = NULL;
struct dirent *de;
- int ret = -1;
int rc;
char uuidstr[VIR_UUID_STRING_BUFLEN];
g_autoptr(virNetworkPortDef) portdef = NULL;
if (!(dir = virNetworkObjGetPortStatusDir(net, stateDir)))
- goto cleanup;
+ return -1;
- if ((rc = virDirOpenIfExists(&dh, dir)) <= 0) {
- ret = rc;
- goto cleanup;
- }
+ if ((rc = virDirOpenIfExists(&dh, dir)) <= 0)
+ return rc;
while ((rc = virDirRead(dh, &de, dir)) > 0) {
g_autofree char *file = NULL;
virUUIDFormat(portdef->uuid, uuidstr);
if (virHashAddEntry(net->ports, uuidstr, portdef) < 0)
- goto cleanup;
+ return -1;
portdef = NULL;
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
g_autoptr(DIR) dirp = NULL;
struct dirent *ent = NULL;
int rc;
- int ret = -1;
if ((rc = virDirOpenIfExists(&dirp, dir)) < 0)
return -1;
if (stat(path, &sb) < 0) {
virReportSystemError(errno, _("Unable to access %s"), path);
- goto cleanup;
+ return -1;
}
if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
continue;
if (virHashUpdateEntry(files, filename, path) < 0)
- goto cleanup;
+ return -1;
path = NULL;
}
if (rc < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
static int
struct statvfs sb;
struct stat statbuf;
int direrr;
- int ret = -1;
g_autoptr(virStorageVolDef) vol = NULL;
VIR_AUTOCLOSE fd = -1;
g_autoptr(virStorageSource) target = NULL;
if (virDirOpen(&dir, def->target.path) < 0)
- goto cleanup;
+ return -1;
while ((direrr = virDirRead(dir, &ent, def->target.path)) > 0) {
int err;
vol = NULL;
continue;
}
- goto cleanup;
+ return -1;
}
if (virStoragePoolObjAddVol(pool, vol) < 0)
- goto cleanup;
+ return -1;
vol = NULL;
}
if (direrr < 0)
- goto cleanup;
+ return -1;
target = virStorageSourceNew();
virReportSystemError(errno,
_("cannot open path '%s'"),
def->target.path);
- goto cleanup;
+ return -1;
}
if (fstat(fd, &statbuf) < 0) {
virReportSystemError(errno,
_("cannot stat path '%s'"),
def->target.path);
- goto cleanup;
+ return -1;
}
if (virStorageBackendUpdateVolTargetInfoFD(target, fd, &statbuf) < 0)
- goto cleanup;
+ return -1;
/* VolTargetInfoFD doesn't update capacity correctly for the pool case */
if (statvfs(def->target.path, &sb) < 0) {
virReportSystemError(errno,
_("cannot statvfs path '%s'"),
def->target.path);
- goto cleanup;
+ return -1;
}
def->capacity = ((unsigned long long)sb.f_frsize *
VIR_FREE(def->target.perms.label);
def->target.perms.label = g_strdup(target->perms->label);
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
{
g_autoptr(DIR) block_dir = NULL;
struct dirent *block_dirent = NULL;
- int retval = -1;
int direrr;
g_autofree char *block_path = NULL;
VIR_DEBUG("Looking for block device in '%s'", block_path);
if (virDirOpen(&block_dir, block_path) < 0)
- goto cleanup;
+ return -1;
while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
*block_device = g_strdup(block_dirent->d_name);
}
if (direrr < 0)
- goto cleanup;
-
- retval = 0;
+ return -1;
- cleanup:
- return retval;
+ return 0;
}
{
g_autoptr(DIR) lun_dir = NULL;
struct dirent *lun_dirent = NULL;
- int retval = -1;
int direrr;
g_autofree char *lun_path = NULL;
target, lun);
if (virDirOpen(&lun_dir, lun_path) < 0)
- goto cleanup;
+ return -1;
while ((direrr = virDirRead(lun_dir, &lun_dirent, lun_path)) > 0) {
if (STRPREFIX(lun_dirent->d_name, "block")) {
if (getNewStyleBlockDevice(lun_path,
lun_dirent->d_name,
block_device) < 0)
- goto cleanup;
+ return -1;
} else {
if (getOldStyleBlockDevice(lun_path,
lun_dirent->d_name,
block_device) < 0)
- goto cleanup;
+ return -1;
}
break;
}
}
if (direrr < 0)
- goto cleanup;
- if (!*block_device) {
- retval = -2;
- goto cleanup;
- }
+ return -1;
- retval = 0;
+ if (!*block_device)
+ return -2;
- cleanup:
- return retval;
+ return 0;
}
const char *taskFile,
bool dormdir)
{
- int ret = -1;
int rc;
bool killedAny = false;
g_autofree char *keypath = NULL;
if ((rc = virCgroupKillInternal(group, signum, pids,
controller, taskFile)) < 0) {
- goto cleanup;
+ return -1;
}
if (rc == 1)
killedAny = true;
VIR_DEBUG("Iterate over children of %s (killedAny=%d)", keypath, killedAny);
if ((rc = virDirOpenIfExists(&dp, keypath)) < 0)
- goto cleanup;
+ return -1;
if (rc == 0) {
VIR_DEBUG("Path %s does not exist, assuming done", keypath);
VIR_DEBUG("Process subdir %s", ent->d_name);
if (virCgroupNew(-1, ent->d_name, group, -1, &subgroup) < 0)
- goto cleanup;
+ return -1;
if ((rc = virCgroupKillRecursiveInternal(subgroup, signum, pids,
controller, taskFile, true)) < 0)
- goto cleanup;
+ return -1;
if (rc == 1)
killedAny = true;
virCgroupRemove(subgroup);
}
if (direrr < 0)
- goto cleanup;
+ return -1;
done:
- ret = killedAny ? 1 : 0;
-
- cleanup:
- return ret;
+ return killedAny ? 1 : 0;
}
struct dirent *entry;
const char *dirName = "/proc/self/fd";
int rc;
- int ret = -1;
if (virDirOpen(&dp, dirName) < 0)
return -1;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to parse FD: %s"),
entry->d_name);
- goto cleanup;
+ return -1;
}
ignore_value(virBitmapSetBit(fds, fd));
}
if (rc < 0)
- goto cleanup;
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
# else /* !__linux__ */
struct stat sb[2];
g_autoptr(DIR) dh = NULL;
const char *p;
- char *ret = NULL;
/* If a path is NOT provided then assume it's DM name */
p = strrchr(path, '/');
if (stat(tmp, &sb[1]) == 0 &&
sb[0].st_rdev == sb[0].st_rdev) {
- ret = g_steal_pointer(&tmp);
- break;
+ return g_steal_pointer(&tmp);
}
}
- return ret;
+ return NULL;
}
virFileNBDDeviceFindUnused(void)
{
g_autoptr(DIR) dh = NULL;
- char *ret = NULL;
struct dirent *de;
int direrr;
while ((direrr = virDirRead(dh, &de, SYSFS_BLOCK_DIR)) > 0) {
if (STRPREFIX(de->d_name, "nbd")) {
int rv = virFileNBDDeviceIsBusy(de->d_name);
+
if (rv < 0)
- goto cleanup;
- if (rv == 0) {
- ret = g_strdup_printf("/dev/%s", de->d_name);
- goto cleanup;
- }
+ return NULL;
+
+ if (rv == 0)
+ return g_strdup_printf("/dev/%s", de->d_name);
}
}
if (direrr < 0)
- goto cleanup;
- virReportSystemError(EBUSY, "%s",
- _("No free NBD devices"));
+ return NULL;
- cleanup:
- return ret;
+ virReportSystemError(EBUSY, "%s", _("No free NBD devices"));
+ return NULL;
}
static bool
{
g_autoptr(DIR) dh = NULL;
struct dirent *de;
- int ret = -1;
int direrr;
/* Silently return 0 if passed NULL or directory doesn't exist */
if (g_lstat(filepath, &sb) < 0) {
virReportSystemError(errno, _("Cannot access '%s'"),
filepath);
- goto cleanup;
+ return -1;
}
if (S_ISDIR(sb.st_mode)) {
if (virFileDeleteTree(filepath) < 0)
- goto cleanup;
+ return -1;
} else {
if (unlink(filepath) < 0 && errno != ENOENT) {
virReportSystemError(errno,
_("Cannot delete file '%s'"),
filepath);
- goto cleanup;
+ return -1;
}
}
}
if (direrr < 0)
- goto cleanup;
+ return -1;
if (rmdir(dir) < 0 && errno != ENOENT) {
virReportSystemError(errno,
_("Cannot delete directory '%s'"),
dir);
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- return ret;
+ return 0;
}
/* Like read(), but restarts after EINTR. Doesn't play
gid_t gid)
{
struct dirent *ent;
- int ret = -1;
int direrr;
g_autoptr(DIR) dir = NULL;
_("cannot chown '%s' to (%u, %u)"),
ent->d_name, (unsigned int) uid,
(unsigned int) gid);
- goto cleanup;
+ return -1;
}
}
if (direrr < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
#else /* WIN32 */
g_autofree char *eth_res_buf = NULL;
g_autoptr(DIR) dirp = NULL;
struct dirent *dp;
- int ret = -1;
if (!virFileExists(SYSFS_INFINIBAND_DIR))
return 0;
/* If /sys/class/net/<ifname>/device/resource doesn't exist it is not a PCI
* device and therefore it will not have RDMA. */
if (!virFileExists(eth_devpath)) {
- ret = 0;
- goto cleanup;
+ return 0;
}
if (virFileReadAll(eth_devpath, RESOURCE_FILE_LEN, ð_res_buf) < 0)
- goto cleanup;
+ return -1;
while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) {
g_autofree char *ib_res_buf = NULL;
break;
}
}
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
unsigned long long **pages_free,
size_t *npages)
{
- int ret = -1;
g_autoptr(DIR) dir = NULL;
int direrr = 0;
struct dirent *entry;
* slightly different information. So we take the total memory on a node
* and subtract memory taken by the huge pages. */
if (virNumaGetHugePageInfoDir(&path, node) < 0)
- goto cleanup;
+ return -1;
/* It's okay if the @path doesn't exist. Maybe we are running on
* system without huge pages support where the path may not exist. */
if (virDirOpenIfExists(&dir, path) < 0)
- goto cleanup;
+ return -1;
while (dir && (direrr = virDirRead(dir, &entry, path)) > 0) {
const char *page_name = entry->d_name;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unable to parse %s"),
entry->d_name);
- goto cleanup;
+ return -1;
}
if (virNumaGetHugePageInfo(node, page_size,
&page_avail, &page_free) < 0)
- goto cleanup;
+ return -1;
if (VIR_REALLOC_N(tmp_size, ntmp + 1) < 0 ||
VIR_REALLOC_N(tmp_avail, ntmp + 1) < 0 ||
VIR_REALLOC_N(tmp_free, ntmp + 1) < 0)
- goto cleanup;
+ return -1;
tmp_size[ntmp] = page_size;
tmp_avail[ntmp] = page_avail;
}
if (direrr < 0)
- goto cleanup;
+ return -1;
/* Now append the ordinary system pages */
if (VIR_REALLOC_N(tmp_size, ntmp + 1) < 0 ||
VIR_REALLOC_N(tmp_avail, ntmp + 1) < 0 ||
VIR_REALLOC_N(tmp_free, ntmp + 1) < 0)
- goto cleanup;
+ return -1;
if (virNumaGetPageInfo(node, system_page_size, huge_page_sum,
&tmp_avail[ntmp], &tmp_free[ntmp]) < 0)
- goto cleanup;
+ return -1;
tmp_size[ntmp] = system_page_size;
ntmp++;
tmp_free = NULL;
}
*npages = ntmp;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
{
g_autofree char *pcidir = NULL;
g_autoptr(DIR) dir = NULL;
- int ret = -1;
struct dirent *ent;
int direrr;
dev->address.function);
if (virDirOpen(&dir, pcidir) < 0)
- goto cleanup;
+ return -1;
while ((direrr = virDirRead(dir, &ent, pcidir)) > 0) {
g_autofree char *file = NULL;
STREQ(ent->d_name, "reset")) {
file = g_strdup_printf("%s/%s", pcidir, ent->d_name);
if ((actor)(dev, file, opaque) < 0)
- goto cleanup;
+ return -1;
}
}
if (direrr < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
{
g_autofree char *groupPath = NULL;
g_autoptr(DIR) groupDir = NULL;
- int ret = -1;
struct dirent *ent;
int direrr;
if (virDirOpenQuiet(&groupDir, groupPath) < 0) {
/* just process the original device, nothing more */
- ret = (actor)(orig, opaque);
- goto cleanup;
+ return (actor)(orig, opaque);
}
while ((direrr = virDirRead(groupDir, &ent, groupPath)) > 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Found invalid device link '%s' in '%s'"),
ent->d_name, groupPath);
- goto cleanup;
+ return -1;
}
if ((actor)(&newDev, opaque) < 0)
- goto cleanup;
+ return -1;
}
if (direrr < 0)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}
ret = virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info");
if (ret <= 0)
- goto cleanup;
+ return ret;
- ret = virResctrlGetMemoryBandwidthInfo(resctrl);
- if (ret < 0)
- goto cleanup;
+ if ((ret = virResctrlGetMemoryBandwidthInfo(resctrl)) < 0)
+ return -1;
- ret = virResctrlGetCacheInfo(resctrl, dirp);
- if (ret < 0)
- goto cleanup;
+ if ((ret = virResctrlGetCacheInfo(resctrl, dirp)) < 0)
+ return -1;
- ret = virResctrlGetMonitorInfo(resctrl);
- if (ret < 0)
- goto cleanup;
+ if ((ret = virResctrlGetMonitorInfo(resctrl)) < 0)
+ return -1;
- ret = 0;
- cleanup:
- return ret;
+ return 0;
}
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
- char *sg = NULL;
unsigned int adapter_id;
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
bus, target, unit);
if (virDirOpen(&dir, path) < 0)
- goto cleanup;
+ return NULL;
- while (virDirRead(dir, &entry, path) > 0) {
- /* Assume a single directory entry */
- sg = g_strdup(entry->d_name);
- break;
- }
+ /* Assume a single directory entry */
+ if (virDirRead(dir, &entry, path) > 0)
+ return g_strdup(entry->d_name);
- cleanup:
- return sg;
+ return NULL;
}
/* Returns device name (e.g. "sdc") on success, or NULL
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
- char *name = NULL;
unsigned int adapter_id;
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICES;
target, unit);
if (virDirOpen(&dir, path) < 0)
- goto cleanup;
+ return NULL;
- while (virDirRead(dir, &entry, path) > 0) {
- name = g_strdup(entry->d_name);
- break;
- }
+ if (virDirRead(dir, &entry, path) > 0)
+ return g_strdup(entry->d_name);
- cleanup:
- return name;
+ return NULL;
}
virSCSIDevicePtr
{
g_autoptr(DIR) iommuDir = NULL;
struct dirent *iommuGroup = NULL;
- bool ret = false;
int direrr;
if (virDirOpenQuiet(&iommuDir, "/sys/kernel/iommu_groups/") < 0)
- goto cleanup;
+ return false;
while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0)
break;
if (direrr < 0 || !iommuGroup)
- goto cleanup;
-
- ret = true;
+ return false;
- cleanup:
- return ret;
+ return true;
}
char *
virHostGetDRMRenderNode(void)
{
- char *ret = NULL;
g_autoptr(DIR) driDir = NULL;
const char *driPath = "/dev/dri";
struct dirent *ent = NULL;
}
if (dirErr < 0)
- goto cleanup;
+ return NULL;
/* even if /dev/dri exists, there might be no renderDX nodes available */
if (!have_rendernode) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("No DRM render nodes available"));
- goto cleanup;
+ return NULL;
}
- ret = g_strdup_printf("%s/%s", driPath, ent->d_name);
-
- cleanup:
- return ret;
+ return g_strdup_printf("%s/%s", driPath, ent->d_name);
}
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
struct dirent *entry = NULL;
g_autoptr(DIR) dir = NULL;
- char *ret = NULL;
if (virDirOpen(&dir, prefix) < 0)
return NULL;
if ((rc = vhbaReadCompareWWN(prefix, entry->d_name,
"node_name", wwnn)) < 0)
- goto cleanup;
+ return NULL;
if (rc == 0)
continue;
if ((rc = vhbaReadCompareWWN(prefix, entry->d_name,
"port_name", wwpn)) < 0)
- goto cleanup;
+ return NULL;
if (rc == 0)
continue;
- ret = g_strdup(entry->d_name);
- break;
+ return g_strdup(entry->d_name);
}
- cleanup:
- return ret;
+ return NULL;
}
/* virVHBAGetHostByFabricWWN:
unsigned long maxver = 0;
unsigned long ver;
g_autofree char *maxname = NULL;
- char *ret = NULL;
fullsuffix = g_strdup_printf("%s.%s", arch, suffix);
if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0)
- goto cleanup;
+ return NULL;
while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) {
g_autofree char *tmp = NULL;
}
if (rc < 0)
- goto cleanup;
+ return NULL;
if (!maxname) {
VIR_TEST_VERBOSE("failed to find capabilities for '%s' in '%s'",
arch, TEST_QEMU_CAPS_PATH);
- goto cleanup;
+ return NULL;
}
- ret = g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname);
-
- cleanup:
- return ret;
+ return g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname);
}
struct dirent *ent;
g_autoptr(DIR) dir = NULL;
int rc;
- int ret = -1;
bool fail = false;
if (!callback)
/* Validate suffix */
if (!STRPREFIX(suffix, ".")) {
VIR_TEST_VERBOSE("malformed suffix '%s'", suffix);
- goto cleanup;
+ return -1;
}
if (virDirOpen(&dir, TEST_QEMU_CAPS_PATH) < 0)
- goto cleanup;
+ return -1;
while ((rc = virDirRead(dir, &ent, TEST_QEMU_CAPS_PATH)) > 0) {
g_autofree char *tmp = g_strdup(ent->d_name);
/* Strip the leading prefix */
if (!(version = STRSKIP(tmp, "caps_"))) {
VIR_TEST_VERBOSE("malformed file name '%s'", ent->d_name);
- goto cleanup;
+ return -1;
}
/* Find the last dot */
if (!(archName = strrchr(tmp, '.'))) {
VIR_TEST_VERBOSE("malformed file name '%s'", ent->d_name);
- goto cleanup;
+ return -1;
}
/* The version number and the architecture name are separated by
}
if (rc < 0 || fail)
- goto cleanup;
-
- ret = 0;
+ return -1;
- cleanup:
- return ret;
+ return 0;
}