const struct _detectMountsData *data = args;
char *parsed = NULL;
const char *actual;
- virCgroupPtr group = NULL;
+ g_autoptr(virCgroup) group = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
cleanup:
g_unsetenv("VIR_CGROUP_MOCK_FILENAME");
VIR_FREE(parsed);
- virCgroupFree(group);
return result;
}
static int testCgroupNewForSelf(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/system",
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/system",
if (virCgroupNewSelf(&cgroup) < 0) {
fprintf(stderr, "Cannot create cgroup for self\n");
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(cgroup, "", mountsFull, links, placement, NULL, NULL, 0);
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return validateCgroup(cgroup, "", mountsFull, links, placement, NULL, NULL, 0);
}
virErrorPtr err = virGetLastError(); \
fprintf(stderr, "Did not get " #en " error code: %d:%d\n", \
err ? err->code : 0, err ? err->int1 : 0); \
- goto cleanup; \
+ return -1; \
} } while (0)
/* Asking for impossible combination since CPU is co-mounted */
static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
int rv;
const char *placementSmall[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/virtualmachines.partition",
if ((rv = virCgroupNewPartition("/virtualmachines", false, -1, &cgroup)) != -1) {
fprintf(stderr, "Unexpected found /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
ENSURE_ERRNO(ENOENT);
(1 << VIR_CGROUP_CONTROLLER_CPU),
&cgroup)) != -1) {
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
ENSURE_ERRNO(EINVAL);
(1 << VIR_CGROUP_CONTROLLER_DEVICES),
&cgroup)) != -1) {
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
ENSURE_ERRNO(ENXIO);
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
&cgroup)) != 0) {
fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsSmall, links, placementSmall, NULL, NULL, 0);
+ rv = validateCgroup(cgroup, "/virtualmachines.partition", mountsSmall, links, placementSmall, NULL, NULL, 0);
virCgroupFree(cgroup);
if ((rv = virCgroupNewPartition("/virtualmachines", true, -1, &cgroup)) != 0) {
fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull, NULL, NULL, 0);
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull, NULL, NULL, 0);
}
static int testCgroupNewForPartitionNested(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
int rv;
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/deployment.partition/production.partition",
if ((rv = virCgroupNewPartition("/deployment/production", false, -1, &cgroup)) != -1) {
fprintf(stderr, "Unexpected found /deployment/production cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
ENSURE_ERRNO(ENOENT);
/* Should not work, since we require /deployment to be pre-created */
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != -1) {
fprintf(stderr, "Unexpected created /deployment/production cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
ENSURE_ERRNO(ENOENT);
if ((rv = virCgroupNewPartition("/deployment", true, -1, &cgroup)) != 0) {
fprintf(stderr, "Failed to create /deployment cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
/* Should now work */
virCgroupFree(cgroup);
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != 0) {
fprintf(stderr, "Failed to create /deployment/production cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(cgroup, "/deployment.partition/production.partition",
- mountsFull, links, placementFull, NULL, NULL, 0);
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return validateCgroup(cgroup, "/deployment.partition/production.partition",
+ mountsFull, links, placementFull, NULL, NULL, 0);
}
static int testCgroupNewForPartitionNestedDeep(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
int rv;
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/user/berrange.user/production.partition",
if ((rv = virCgroupNewPartition("/user/berrange.user/production", false, -1, &cgroup)) != -1) {
fprintf(stderr, "Unexpected found /user/berrange.user/production cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
ENSURE_ERRNO(ENOENT);
/* Should not work, since we require /user/berrange.user to be pre-created */
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != -1) {
fprintf(stderr, "Unexpected created /user/berrange.user/production cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
ENSURE_ERRNO(ENOENT);
if ((rv = virCgroupNewPartition("/user", true, -1, &cgroup)) != 0) {
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
virCgroupFree(cgroup);
if ((rv = virCgroupNewPartition("/user/berrange.user", true, -1, &cgroup)) != 0) {
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
/* Should now work */
virCgroupFree(cgroup);
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != 0) {
fprintf(stderr, "Failed to create /user/berrange.user/production cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(cgroup, "/user/berrange.user/production.partition",
- mountsFull, links, placementFull, NULL, NULL, 0);
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return validateCgroup(cgroup, "/user/berrange.user/production.partition",
+ mountsFull, links, placementFull, NULL, NULL, 0);
}
static int testCgroupNewForPartitionDomain(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr partitioncgroup = NULL;
- virCgroupPtr domaincgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) partitioncgroup = NULL;
+ g_autoptr(virCgroup) domaincgroup = NULL;
int rv;
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/production.partition/foo.libvirt-lxc",
if ((rv = virCgroupNewPartition("/production", true, -1, &partitioncgroup)) != 0) {
fprintf(stderr, "Failed to create /production cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if ((rv = virCgroupNewDomainPartition(partitioncgroup, "lxc", "foo", true, &domaincgroup)) != 0) {
fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
-
- cleanup:
- virCgroupFree(partitioncgroup);
- virCgroupFree(domaincgroup);
- return ret;
+ return validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
}
static int testCgroupNewForPartitionDomainEscaped(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr partitioncgroup1 = NULL;
- virCgroupPtr partitioncgroup2 = NULL;
- virCgroupPtr partitioncgroup3 = NULL;
- virCgroupPtr domaincgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) partitioncgroup1 = NULL;
+ g_autoptr(virCgroup) partitioncgroup2 = NULL;
+ g_autoptr(virCgroup) partitioncgroup3 = NULL;
+ g_autoptr(virCgroup) domaincgroup = NULL;
int rv;
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc",
if ((rv = virCgroupNewPartition("/cgroup.evil", true, -1, &partitioncgroup1)) != 0) {
fprintf(stderr, "Failed to create /cgroup.evil cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if ((rv = virCgroupNewPartition("/cgroup.evil/net_cls.evil", true, -1, &partitioncgroup2)) != 0) {
fprintf(stderr, "Failed to create /cgroup.evil/cpu.evil cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if ((rv = virCgroupNewPartition("/cgroup.evil/net_cls.evil/_evil.evil", true, -1, &partitioncgroup3)) != 0) {
fprintf(stderr, "Failed to create /cgroup.evil cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if ((rv = virCgroupNewDomainPartition(partitioncgroup3, "lxc", "cpu.foo", true, &domaincgroup)) != 0) {
fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
/* NB we're not expecting 'net_cls.evil' to be escaped,
* since our fake /proc/cgroups pretends this controller
* isn't compiled into the kernel
*/
- ret = validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
-
- cleanup:
- virCgroupFree(partitioncgroup3);
- virCgroupFree(partitioncgroup2);
- virCgroupFree(partitioncgroup1);
- virCgroupFree(domaincgroup);
- return ret;
+ return validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
}
static int testCgroupNewForSelfAllInOne(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/",
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/",
if (virCgroupNewSelf(&cgroup) < 0) {
fprintf(stderr, "Cannot create cgroup for self\n");
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement, NULL, NULL, 0);
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement, NULL, NULL, 0);
}
static int testCgroupNewForSelfLogind(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
+ g_autoptr(virCgroup) cgroup = NULL;
if (virCgroupNewSelf(&cgroup) >= 0) {
fprintf(stderr, "Expected to fail, only systemd cgroup available.\n");
- virCgroupFree(cgroup);
return -1;
}
static int testCgroupNewForSelfUnified(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
unsigned int controllers =
(1 << VIR_CGROUP_CONTROLLER_CPU) |
if (virCgroupNewSelf(&cgroup) < 0) {
fprintf(stderr, "Cannot create cgroup for self\n");
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(cgroup, "", empty, empty, empty,
- "/not/really/sys/fs/cgroup", "/", controllers);
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return validateCgroup(cgroup, "", empty, empty, empty,
+ "/not/really/sys/fs/cgroup", "/", controllers);
}
static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
- int ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
if (virCgroupNewSelf(&cgroup) < 0) {
fprintf(stderr, "Cannot create cgroup for self\n");
- goto cleanup;
+ return -1;
}
- ret = validateCgroup(cgroup, "", mounts, empty, placement,
- "/not/really/sys/fs/cgroup/unified", "/", controllers);
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return validateCgroup(cgroup, "", mounts, empty, placement,
+ "/not/really/sys/fs/cgroup/unified", "/", controllers);
}
static int testCgroupGetPercpuStats(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
+ g_autoptr(virCgroup) cgroup = NULL;
size_t i;
int rv, ret = -1;
virTypedParameterPtr params = NULL;
ret = 0;
cleanup:
- virCgroupFree(cgroup);
VIR_FREE(params);
return ret;
}
static int testCgroupGetMemoryUsage(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
- int rv, ret = -1;
+ g_autoptr(virCgroup) cgroup = NULL;
+ int rv;
unsigned long kb;
if ((rv = virCgroupNewPartition("/virtualmachines", true,
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
&cgroup)) < 0) {
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if ((rv = virCgroupGetMemoryUsage(cgroup, &kb)) < 0) {
fprintf(stderr, "Could not retrieve GetMemoryUsage for /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if (kb != 1421212UL) {
fprintf(stderr,
"Wrong value from virCgroupGetMemoryUsage (expected %ld)\n",
1421212UL);
- goto cleanup;
+ return -1;
}
- ret = 0;
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return 0;
}
static int
testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
+ g_autoptr(virCgroup) cgroup = NULL;
int rv;
- int ret = -1;
size_t i;
const unsigned long long expected_values[] = {
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
&cgroup)) < 0) {
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if ((rv = virCgroupGetMemoryStat(cgroup, &values[0],
&values[3], &values[4],
&values[5])) < 0) {
fprintf(stderr, "Could not retrieve GetMemoryStat for /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
for (i = 0; i < G_N_ELEMENTS(expected_values); i++) {
"Wrong value (%llu) for %s from virCgroupGetMemoryStat "
"(expected %llu)\n",
values[i], names[i], (expected_values[i] >> 10));
- goto cleanup;
+ return -1;
}
}
- ret = 0;
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return 0;
}
static int testCgroupGetBlkioIoServiced(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
+ g_autoptr(virCgroup) cgroup = NULL;
size_t i;
- int rv, ret = -1;
+ int rv;
const long long expected_values[] = {
119084214273ULL,
(1 << VIR_CGROUP_CONTROLLER_BLKIO),
&cgroup)) < 0) {
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if ((rv = virCgroupGetBlkioIoServiced(cgroup,
values, &values[1],
&values[2], &values[3])) < 0) {
fprintf(stderr, "Could not retrieve BlkioIoServiced for /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
for (i = 0; i < G_N_ELEMENTS(expected_values); i++) {
fprintf(stderr,
"Wrong value for %s from virCgroupBlkioIoServiced (expected %lld)\n",
names[i], expected_values[i]);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return 0;
}
static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
{
- virCgroupPtr cgroup = NULL;
+ g_autoptr(virCgroup) cgroup = NULL;
size_t i;
- int rv, ret = -1;
+ int rv;
const long long expected_values0[] = {
59542107136ULL,
411440480256ULL,
(1 << VIR_CGROUP_CONTROLLER_BLKIO),
&cgroup)) < 0) {
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
if ((rv = virCgroupGetBlkioIoDeviceServiced(cgroup,
values, &values[1],
&values[2], &values[3])) < 0) {
fprintf(stderr, "Could not retrieve BlkioIoDeviceServiced for /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
for (i = 0; i < G_N_ELEMENTS(expected_values0); i++) {
fprintf(stderr,
"Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n",
names[i], expected_values0[i]);
- goto cleanup;
+ return -1;
}
}
values, &values[1],
&values[2], &values[3])) < 0) {
fprintf(stderr, "Could not retrieve BlkioIoDeviceServiced for /virtualmachines cgroup: %d\n", -rv);
- goto cleanup;
+ return -1;
}
for (i = 0; i < G_N_ELEMENTS(expected_values1); i++) {
fprintf(stderr,
"Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n",
names[i], expected_values1[i]);
- goto cleanup;
+ return -1;
}
}
- ret = 0;
-
- cleanup:
- virCgroupFree(cgroup);
- return ret;
+ return 0;
}
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"