mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 03:25:20 +00:00
tests: use g_autoptr for virCgroup
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
This commit is contained in:
parent
cfbd7befba
commit
a9932fc292
@ -183,7 +183,7 @@ testCgroupDetectMounts(const void *args)
|
|||||||
const struct _detectMountsData *data = args;
|
const struct _detectMountsData *data = args;
|
||||||
char *parsed = NULL;
|
char *parsed = NULL;
|
||||||
const char *actual;
|
const char *actual;
|
||||||
virCgroupPtr group = NULL;
|
g_autoptr(virCgroup) group = NULL;
|
||||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -217,15 +217,13 @@ testCgroupDetectMounts(const void *args)
|
|||||||
cleanup:
|
cleanup:
|
||||||
g_unsetenv("VIR_CGROUP_MOCK_FILENAME");
|
g_unsetenv("VIR_CGROUP_MOCK_FILENAME");
|
||||||
VIR_FREE(parsed);
|
VIR_FREE(parsed);
|
||||||
virCgroupFree(group);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupNewForSelf(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForSelf(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = "/system",
|
[VIR_CGROUP_CONTROLLER_CPU] = "/system",
|
||||||
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/system",
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/system",
|
||||||
@ -239,14 +237,10 @@ static int testCgroupNewForSelf(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
if (virCgroupNewSelf(&cgroup) < 0) {
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
||||||
fprintf(stderr, "Cannot create cgroup for self\n");
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = validateCgroup(cgroup, "", mountsFull, links, placement, NULL, NULL, 0);
|
return validateCgroup(cgroup, "", mountsFull, links, placement, NULL, NULL, 0);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -256,7 +250,7 @@ static int testCgroupNewForSelf(const void *args G_GNUC_UNUSED)
|
|||||||
virErrorPtr err = virGetLastError(); \
|
virErrorPtr err = virGetLastError(); \
|
||||||
fprintf(stderr, "Did not get " #en " error code: %d:%d\n", \
|
fprintf(stderr, "Did not get " #en " error code: %d:%d\n", \
|
||||||
err ? err->code : 0, err ? err->int1 : 0); \
|
err ? err->code : 0, err ? err->int1 : 0); \
|
||||||
goto cleanup; \
|
return -1; \
|
||||||
} } while (0)
|
} } while (0)
|
||||||
|
|
||||||
/* Asking for impossible combination since CPU is co-mounted */
|
/* Asking for impossible combination since CPU is co-mounted */
|
||||||
@ -264,8 +258,7 @@ static int testCgroupNewForSelf(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
int rv;
|
int rv;
|
||||||
const char *placementSmall[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *placementSmall[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = "/virtualmachines.partition",
|
[VIR_CGROUP_CONTROLLER_CPU] = "/virtualmachines.partition",
|
||||||
@ -290,7 +283,7 @@ static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/virtualmachines", false, -1, &cgroup)) != -1) {
|
if ((rv = virCgroupNewPartition("/virtualmachines", false, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected found /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected found /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ENSURE_ERRNO(ENOENT);
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
@ -299,7 +292,7 @@ static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED)
|
|||||||
(1 << VIR_CGROUP_CONTROLLER_CPU),
|
(1 << VIR_CGROUP_CONTROLLER_CPU),
|
||||||
&cgroup)) != -1) {
|
&cgroup)) != -1) {
|
||||||
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ENSURE_ERRNO(EINVAL);
|
ENSURE_ERRNO(EINVAL);
|
||||||
|
|
||||||
@ -308,7 +301,7 @@ static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED)
|
|||||||
(1 << VIR_CGROUP_CONTROLLER_DEVICES),
|
(1 << VIR_CGROUP_CONTROLLER_DEVICES),
|
||||||
&cgroup)) != -1) {
|
&cgroup)) != -1) {
|
||||||
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ENSURE_ERRNO(ENXIO);
|
ENSURE_ERRNO(ENXIO);
|
||||||
|
|
||||||
@ -319,27 +312,22 @@ static int testCgroupNewForPartition(const void *args G_GNUC_UNUSED)
|
|||||||
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
|
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
|
||||||
&cgroup)) != 0) {
|
&cgroup)) != 0) {
|
||||||
fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
|
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);
|
virCgroupFree(cgroup);
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/virtualmachines", true, -1, &cgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/virtualmachines", true, -1, &cgroup)) != 0) {
|
||||||
fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull, NULL, NULL, 0);
|
return validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull, NULL, NULL, 0);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupNewForPartitionNested(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForPartitionNested(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
int rv;
|
int rv;
|
||||||
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = "/deployment.partition/production.partition",
|
[VIR_CGROUP_CONTROLLER_CPU] = "/deployment.partition/production.partition",
|
||||||
@ -354,42 +342,37 @@ static int testCgroupNewForPartitionNested(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/deployment/production", false, -1, &cgroup)) != -1) {
|
if ((rv = virCgroupNewPartition("/deployment/production", false, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected found /deployment/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected found /deployment/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ENSURE_ERRNO(ENOENT);
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
/* Should not work, since we require /deployment to be pre-created */
|
/* Should not work, since we require /deployment to be pre-created */
|
||||||
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != -1) {
|
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected created /deployment/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected created /deployment/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ENSURE_ERRNO(ENOENT);
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/deployment", true, -1, &cgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/deployment", true, -1, &cgroup)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /deployment cgroup: %d\n", -rv);
|
fprintf(stderr, "Failed to create /deployment cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should now work */
|
/* Should now work */
|
||||||
virCgroupFree(cgroup);
|
virCgroupFree(cgroup);
|
||||||
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /deployment/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Failed to create /deployment/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = validateCgroup(cgroup, "/deployment.partition/production.partition",
|
return validateCgroup(cgroup, "/deployment.partition/production.partition",
|
||||||
mountsFull, links, placementFull, NULL, NULL, 0);
|
mountsFull, links, placementFull, NULL, NULL, 0);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupNewForPartitionNestedDeep(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForPartitionNestedDeep(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
int rv;
|
int rv;
|
||||||
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = "/user/berrange.user/production.partition",
|
[VIR_CGROUP_CONTROLLER_CPU] = "/user/berrange.user/production.partition",
|
||||||
@ -404,50 +387,45 @@ static int testCgroupNewForPartitionNestedDeep(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/user/berrange.user/production", false, -1, &cgroup)) != -1) {
|
if ((rv = virCgroupNewPartition("/user/berrange.user/production", false, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected found /user/berrange.user/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected found /user/berrange.user/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ENSURE_ERRNO(ENOENT);
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
/* Should not work, since we require /user/berrange.user to be pre-created */
|
/* Should not work, since we require /user/berrange.user to be pre-created */
|
||||||
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != -1) {
|
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != -1) {
|
||||||
fprintf(stderr, "Unexpected created /user/berrange.user/production cgroup: %d\n", -rv);
|
fprintf(stderr, "Unexpected created /user/berrange.user/production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ENSURE_ERRNO(ENOENT);
|
ENSURE_ERRNO(ENOENT);
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/user", true, -1, &cgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/user", true, -1, &cgroup)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
|
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virCgroupFree(cgroup);
|
virCgroupFree(cgroup);
|
||||||
if ((rv = virCgroupNewPartition("/user/berrange.user", true, -1, &cgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/user/berrange.user", true, -1, &cgroup)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
|
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should now work */
|
/* Should now work */
|
||||||
virCgroupFree(cgroup);
|
virCgroupFree(cgroup);
|
||||||
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /user/berrange.user/production cgroup: %d\n", -rv);
|
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",
|
return validateCgroup(cgroup, "/user/berrange.user/production.partition",
|
||||||
mountsFull, links, placementFull, NULL, NULL, 0);
|
mountsFull, links, placementFull, NULL, NULL, 0);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupNewForPartitionDomain(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForPartitionDomain(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr partitioncgroup = NULL;
|
g_autoptr(virCgroup) partitioncgroup = NULL;
|
||||||
virCgroupPtr domaincgroup = NULL;
|
g_autoptr(virCgroup) domaincgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
int rv;
|
int rv;
|
||||||
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = "/production.partition/foo.libvirt-lxc",
|
[VIR_CGROUP_CONTROLLER_CPU] = "/production.partition/foo.libvirt-lxc",
|
||||||
@ -462,29 +440,23 @@ static int testCgroupNewForPartitionDomain(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/production", true, -1, &partitioncgroup)) != 0) {
|
if ((rv = virCgroupNewPartition("/production", true, -1, &partitioncgroup)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /production cgroup: %d\n", -rv);
|
fprintf(stderr, "Failed to create /production cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = virCgroupNewDomainPartition(partitioncgroup, "lxc", "foo", true, &domaincgroup)) != 0) {
|
if ((rv = virCgroupNewDomainPartition(partitioncgroup, "lxc", "foo", true, &domaincgroup)) != 0) {
|
||||||
fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv);
|
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);
|
return validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement, NULL, NULL, 0);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(partitioncgroup);
|
|
||||||
virCgroupFree(domaincgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int testCgroupNewForPartitionDomainEscaped(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForPartitionDomainEscaped(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr partitioncgroup1 = NULL;
|
g_autoptr(virCgroup) partitioncgroup1 = NULL;
|
||||||
virCgroupPtr partitioncgroup2 = NULL;
|
g_autoptr(virCgroup) partitioncgroup2 = NULL;
|
||||||
virCgroupPtr partitioncgroup3 = NULL;
|
g_autoptr(virCgroup) partitioncgroup3 = NULL;
|
||||||
virCgroupPtr domaincgroup = NULL;
|
g_autoptr(virCgroup) domaincgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
int rv;
|
int rv;
|
||||||
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc",
|
[VIR_CGROUP_CONTROLLER_CPU] = "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc",
|
||||||
@ -499,42 +471,34 @@ static int testCgroupNewForPartitionDomainEscaped(const void *args G_GNUC_UNUSED
|
|||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/cgroup.evil", true, -1, &partitioncgroup1)) != 0) {
|
if ((rv = virCgroupNewPartition("/cgroup.evil", true, -1, &partitioncgroup1)) != 0) {
|
||||||
fprintf(stderr, "Failed to create /cgroup.evil cgroup: %d\n", -rv);
|
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) {
|
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);
|
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) {
|
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);
|
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) {
|
if ((rv = virCgroupNewDomainPartition(partitioncgroup3, "lxc", "cpu.foo", true, &domaincgroup)) != 0) {
|
||||||
fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv);
|
fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NB we're not expecting 'net_cls.evil' to be escaped,
|
/* NB we're not expecting 'net_cls.evil' to be escaped,
|
||||||
* since our fake /proc/cgroups pretends this controller
|
* since our fake /proc/cgroups pretends this controller
|
||||||
* isn't compiled into the kernel
|
* 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);
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int testCgroupNewForSelfAllInOne(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForSelfAllInOne(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPU] = "/",
|
[VIR_CGROUP_CONTROLLER_CPU] = "/",
|
||||||
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/",
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/",
|
||||||
@ -547,24 +511,19 @@ static int testCgroupNewForSelfAllInOne(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
if (virCgroupNewSelf(&cgroup) < 0) {
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
||||||
fprintf(stderr, "Cannot create cgroup for self\n");
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement, NULL, NULL, 0);
|
return validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement, NULL, NULL, 0);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupNewForSelfLogind(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForSelfLogind(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
|
|
||||||
if (virCgroupNewSelf(&cgroup) >= 0) {
|
if (virCgroupNewSelf(&cgroup) >= 0) {
|
||||||
fprintf(stderr, "Expected to fail, only systemd cgroup available.\n");
|
fprintf(stderr, "Expected to fail, only systemd cgroup available.\n");
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -574,8 +533,7 @@ static int testCgroupNewForSelfLogind(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
static int testCgroupNewForSelfUnified(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForSelfUnified(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
|
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
|
||||||
unsigned int controllers =
|
unsigned int controllers =
|
||||||
(1 << VIR_CGROUP_CONTROLLER_CPU) |
|
(1 << VIR_CGROUP_CONTROLLER_CPU) |
|
||||||
@ -586,21 +544,17 @@ static int testCgroupNewForSelfUnified(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
if (virCgroupNewSelf(&cgroup) < 0) {
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
||||||
fprintf(stderr, "Cannot create cgroup for self\n");
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = validateCgroup(cgroup, "", empty, empty, empty,
|
return validateCgroup(cgroup, "", empty, empty, empty,
|
||||||
"/not/really/sys/fs/cgroup", "/", controllers);
|
"/not/really/sys/fs/cgroup", "/", controllers);
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
|
static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int ret = -1;
|
|
||||||
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
|
const char *empty[VIR_CGROUP_CONTROLLER_LAST] = { 0 };
|
||||||
const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
|
const char *mounts[VIR_CGROUP_CONTROLLER_LAST] = {
|
||||||
[VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
|
||||||
@ -623,15 +577,11 @@ static int testCgroupNewForSelfHybrid(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
if (virCgroupNewSelf(&cgroup) < 0) {
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
||||||
fprintf(stderr, "Cannot create cgroup for self\n");
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = validateCgroup(cgroup, "", mounts, empty, placement,
|
return validateCgroup(cgroup, "", mounts, empty, placement,
|
||||||
"/not/really/sys/fs/cgroup/unified", "/", controllers);
|
"/not/really/sys/fs/cgroup/unified", "/", controllers);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -679,7 +629,7 @@ static int testCgroupControllerAvailable(const void *args G_GNUC_UNUSED)
|
|||||||
|
|
||||||
static int testCgroupGetPercpuStats(const void *args G_GNUC_UNUSED)
|
static int testCgroupGetPercpuStats(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int rv, ret = -1;
|
int rv, ret = -1;
|
||||||
virTypedParameterPtr params = NULL;
|
virTypedParameterPtr params = NULL;
|
||||||
@ -756,50 +706,44 @@ static int testCgroupGetPercpuStats(const void *args G_GNUC_UNUSED)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCgroupFree(cgroup);
|
|
||||||
VIR_FREE(params);
|
VIR_FREE(params);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int testCgroupGetMemoryUsage(const void *args G_GNUC_UNUSED)
|
static int testCgroupGetMemoryUsage(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int rv, ret = -1;
|
int rv;
|
||||||
unsigned long kb;
|
unsigned long kb;
|
||||||
|
|
||||||
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
||||||
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
|
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
|
||||||
&cgroup)) < 0) {
|
&cgroup)) < 0) {
|
||||||
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = virCgroupGetMemoryUsage(cgroup, &kb)) < 0) {
|
if ((rv = virCgroupGetMemoryUsage(cgroup, &kb)) < 0) {
|
||||||
fprintf(stderr, "Could not retrieve GetMemoryUsage for /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Could not retrieve GetMemoryUsage for /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kb != 1421212UL) {
|
if (kb != 1421212UL) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Wrong value from virCgroupGetMemoryUsage (expected %ld)\n",
|
"Wrong value from virCgroupGetMemoryUsage (expected %ld)\n",
|
||||||
1421212UL);
|
1421212UL);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED)
|
testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
int rv;
|
int rv;
|
||||||
int ret = -1;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
const unsigned long long expected_values[] = {
|
const unsigned long long expected_values[] = {
|
||||||
@ -824,7 +768,7 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED)
|
|||||||
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
|
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
|
||||||
&cgroup)) < 0) {
|
&cgroup)) < 0) {
|
||||||
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = virCgroupGetMemoryStat(cgroup, &values[0],
|
if ((rv = virCgroupGetMemoryStat(cgroup, &values[0],
|
||||||
@ -832,7 +776,7 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED)
|
|||||||
&values[3], &values[4],
|
&values[3], &values[4],
|
||||||
&values[5])) < 0) {
|
&values[5])) < 0) {
|
||||||
fprintf(stderr, "Could not retrieve GetMemoryStat for /virtualmachines cgroup: %d\n", -rv);
|
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++) {
|
for (i = 0; i < G_N_ELEMENTS(expected_values); i++) {
|
||||||
@ -842,23 +786,19 @@ testCgroupGetMemoryStat(const void *args G_GNUC_UNUSED)
|
|||||||
"Wrong value (%llu) for %s from virCgroupGetMemoryStat "
|
"Wrong value (%llu) for %s from virCgroupGetMemoryStat "
|
||||||
"(expected %llu)\n",
|
"(expected %llu)\n",
|
||||||
values[i], names[i], (expected_values[i] >> 10));
|
values[i], names[i], (expected_values[i] >> 10));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int testCgroupGetBlkioIoServiced(const void *args G_GNUC_UNUSED)
|
static int testCgroupGetBlkioIoServiced(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int rv, ret = -1;
|
int rv;
|
||||||
|
|
||||||
const long long expected_values[] = {
|
const long long expected_values[] = {
|
||||||
119084214273ULL,
|
119084214273ULL,
|
||||||
@ -878,14 +818,14 @@ static int testCgroupGetBlkioIoServiced(const void *args G_GNUC_UNUSED)
|
|||||||
(1 << VIR_CGROUP_CONTROLLER_BLKIO),
|
(1 << VIR_CGROUP_CONTROLLER_BLKIO),
|
||||||
&cgroup)) < 0) {
|
&cgroup)) < 0) {
|
||||||
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = virCgroupGetBlkioIoServiced(cgroup,
|
if ((rv = virCgroupGetBlkioIoServiced(cgroup,
|
||||||
values, &values[1],
|
values, &values[1],
|
||||||
&values[2], &values[3])) < 0) {
|
&values[2], &values[3])) < 0) {
|
||||||
fprintf(stderr, "Could not retrieve BlkioIoServiced for /virtualmachines cgroup: %d\n", -rv);
|
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++) {
|
for (i = 0; i < G_N_ELEMENTS(expected_values); i++) {
|
||||||
@ -893,22 +833,18 @@ static int testCgroupGetBlkioIoServiced(const void *args G_GNUC_UNUSED)
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Wrong value for %s from virCgroupBlkioIoServiced (expected %lld)\n",
|
"Wrong value for %s from virCgroupBlkioIoServiced (expected %lld)\n",
|
||||||
names[i], expected_values[i]);
|
names[i], expected_values[i]);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
|
static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
g_autoptr(virCgroup) cgroup = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int rv, ret = -1;
|
int rv;
|
||||||
const long long expected_values0[] = {
|
const long long expected_values0[] = {
|
||||||
59542107136ULL,
|
59542107136ULL,
|
||||||
411440480256ULL,
|
411440480256ULL,
|
||||||
@ -933,7 +869,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
|
|||||||
(1 << VIR_CGROUP_CONTROLLER_BLKIO),
|
(1 << VIR_CGROUP_CONTROLLER_BLKIO),
|
||||||
&cgroup)) < 0) {
|
&cgroup)) < 0) {
|
||||||
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((rv = virCgroupGetBlkioIoDeviceServiced(cgroup,
|
if ((rv = virCgroupGetBlkioIoDeviceServiced(cgroup,
|
||||||
@ -941,7 +877,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
|
|||||||
values, &values[1],
|
values, &values[1],
|
||||||
&values[2], &values[3])) < 0) {
|
&values[2], &values[3])) < 0) {
|
||||||
fprintf(stderr, "Could not retrieve BlkioIoDeviceServiced for /virtualmachines cgroup: %d\n", -rv);
|
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++) {
|
for (i = 0; i < G_N_ELEMENTS(expected_values0); i++) {
|
||||||
@ -949,7 +885,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n",
|
"Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n",
|
||||||
names[i], expected_values0[i]);
|
names[i], expected_values0[i]);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -958,7 +894,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
|
|||||||
values, &values[1],
|
values, &values[1],
|
||||||
&values[2], &values[3])) < 0) {
|
&values[2], &values[3])) < 0) {
|
||||||
fprintf(stderr, "Could not retrieve BlkioIoDeviceServiced for /virtualmachines cgroup: %d\n", -rv);
|
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++) {
|
for (i = 0; i < G_N_ELEMENTS(expected_values1); i++) {
|
||||||
@ -966,15 +902,11 @@ static int testCgroupGetBlkioIoDeviceServiced(const void *args G_GNUC_UNUSED)
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n",
|
"Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n",
|
||||||
names[i], expected_values1[i]);
|
names[i], expected_values1[i]);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virCgroupFree(cgroup);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
||||||
|
Loading…
Reference in New Issue
Block a user