2013-03-28 14:36:52 +00:00
|
|
|
/*
|
2014-02-22 00:21:58 +00:00
|
|
|
* Copyright (C) 2013-2014 Red Hat, Inc.
|
2013-03-28 14:36:52 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
|
|
|
# define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__
|
|
|
|
# include "vircgrouppriv.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
# include "virstring.h"
|
2013-03-28 14:36:52 +00:00
|
|
|
# include "virerror.h"
|
|
|
|
# include "virlog.h"
|
|
|
|
# include "virfile.h"
|
2014-02-14 17:49:05 +00:00
|
|
|
# include "testutilslxc.h"
|
2014-02-14 17:49:08 +00:00
|
|
|
# include "nodeinfo.h"
|
2013-03-28 14:36:52 +00:00
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("tests.cgrouptest");
|
|
|
|
|
2013-03-28 14:36:52 +00:00
|
|
|
static int validateCgroup(virCgroupPtr cgroup,
|
|
|
|
const char *expectPath,
|
|
|
|
const char **expectMountPoint,
|
2013-04-05 10:28:04 +00:00
|
|
|
const char **expectLinkPoint,
|
2013-03-28 14:36:52 +00:00
|
|
|
const char **expectPlacement)
|
|
|
|
{
|
Convert 'int i' to 'size_t i' in tests/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-03-28 14:36:52 +00:00
|
|
|
|
|
|
|
if (STRNEQ(cgroup->path, expectPath)) {
|
|
|
|
fprintf(stderr, "Wrong path '%s', expected '%s'\n",
|
|
|
|
cgroup->path, expectPath);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:53:48 +00:00
|
|
|
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
|
2013-03-28 14:36:52 +00:00
|
|
|
if (STRNEQ_NULLABLE(expectMountPoint[i],
|
|
|
|
cgroup->controllers[i].mountPoint)) {
|
|
|
|
fprintf(stderr, "Wrong mount '%s', expected '%s' for '%s'\n",
|
|
|
|
cgroup->controllers[i].mountPoint,
|
|
|
|
expectMountPoint[i],
|
|
|
|
virCgroupControllerTypeToString(i));
|
|
|
|
return -1;
|
|
|
|
}
|
2013-04-05 10:28:04 +00:00
|
|
|
if (STRNEQ_NULLABLE(expectLinkPoint[i],
|
|
|
|
cgroup->controllers[i].linkPoint)) {
|
|
|
|
fprintf(stderr, "Wrong link '%s', expected '%s' for '%s'\n",
|
|
|
|
cgroup->controllers[i].linkPoint,
|
|
|
|
expectLinkPoint[i],
|
|
|
|
virCgroupControllerTypeToString(i));
|
|
|
|
return -1;
|
|
|
|
}
|
2013-03-28 14:36:52 +00:00
|
|
|
if (STRNEQ_NULLABLE(expectPlacement[i],
|
|
|
|
cgroup->controllers[i].placement)) {
|
|
|
|
fprintf(stderr, "Wrong placement '%s', expected '%s' for '%s'\n",
|
|
|
|
cgroup->controllers[i].placement,
|
|
|
|
expectPlacement[i],
|
|
|
|
virCgroupControllerTypeToString(i));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *mountsSmall[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu,cpuacct",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/not/really/sys/fs/cgroup/cpu,cpuacct",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/not/really/sys/fs/cgroup/memory",
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
2013-03-28 14:36:52 +00:00
|
|
|
};
|
|
|
|
const char *mountsFull[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu,cpuacct",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/not/really/sys/fs/cgroup/cpu,cpuacct",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup/cpuset",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/not/really/sys/fs/cgroup/memory",
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "/not/really/sys/fs/cgroup/freezer",
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup/blkio",
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/not/really/sys/fs/cgroup/systemd",
|
2013-03-28 14:36:52 +00:00
|
|
|
};
|
2013-09-10 13:31:53 +00:00
|
|
|
const char *mountsAllInOne[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/not/really/sys/fs/cgroup",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/not/really/sys/fs/cgroup",
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = "/not/really/sys/fs/cgroup",
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup",
|
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
|
|
|
};
|
2013-09-11 18:15:52 +00:00
|
|
|
const char *mountsLogind[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/not/really/sys/fs/cgroup/systemd",
|
|
|
|
};
|
2013-03-28 14:36:52 +00:00
|
|
|
|
2013-04-05 10:28:04 +00:00
|
|
|
const char *links[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/not/really/sys/fs/cgroup/cpuacct",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
2013-09-10 13:31:53 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *linksAllInOne[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
2013-04-05 10:28:04 +00:00
|
|
|
};
|
|
|
|
|
2013-09-11 18:15:52 +00:00
|
|
|
const char *linksLogind[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
|
|
|
};
|
|
|
|
|
2013-04-05 10:28:04 +00:00
|
|
|
|
2013-03-28 14:36:52 +00:00
|
|
|
static int testCgroupNewForSelf(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/system",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/system",
|
2013-03-22 11:11:34 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/",
|
2013-03-28 14:36:52 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
2013-03-22 11:11:34 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "/",
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/",
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/user/berrange/123",
|
2013-03-28 14:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
|
|
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-05 10:28:04 +00:00
|
|
|
ret = validateCgroup(cgroup, "", mountsFull, links, placement);
|
2013-03-28 14:36:52 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-03-28 14:36:52 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-04 15:49:24 +00:00
|
|
|
# define ENSURE_ERRNO(en) \
|
|
|
|
do { \
|
|
|
|
if (!virLastErrorIsSystemErrno(en)) { \
|
|
|
|
virErrorPtr err = virGetLastError(); \
|
|
|
|
fprintf(stderr, "Did not get " #en " error code: %d:%d\n", \
|
|
|
|
err ? err->code : 0, err ? err->int1 : 0); \
|
|
|
|
goto cleanup; \
|
|
|
|
} } while (0)
|
|
|
|
|
|
|
|
/* Asking for impossible combination since CPU is co-mounted */
|
|
|
|
|
|
|
|
|
2013-03-28 18:08:39 +00:00
|
|
|
static int testCgroupNewForPartition(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
int rv;
|
|
|
|
const char *placementSmall[VIR_CGROUP_CONTROLLER_LAST] = {
|
2013-04-26 09:23:51 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/virtualmachines.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/virtualmachines.partition",
|
2013-03-28 18:08:39 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
2013-04-26 09:23:51 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/virtualmachines.partition",
|
2013-03-28 18:08:39 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
|
2013-03-28 18:08:39 +00:00
|
|
|
};
|
|
|
|
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
|
2013-04-26 09:23:51 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/virtualmachines.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/virtualmachines.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/virtualmachines.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/virtualmachines.partition",
|
2013-03-28 18:08:39 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
2013-04-26 09:23:51 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "/virtualmachines.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/virtualmachines.partition",
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/user/berrange/123",
|
2013-03-28 18:08:39 +00:00
|
|
|
};
|
|
|
|
|
2013-07-04 15:49:24 +00:00
|
|
|
if ((rv = virCgroupNewPartition("/virtualmachines", false, -1, &cgroup)) != -1) {
|
2013-03-28 18:08:39 +00:00
|
|
|
fprintf(stderr, "Unexpected found /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-04 15:49:24 +00:00
|
|
|
ENSURE_ERRNO(ENOENT);
|
2013-03-28 18:08:39 +00:00
|
|
|
|
|
|
|
/* Asking for impossible combination since CPU is co-mounted */
|
|
|
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_CPU),
|
2013-07-04 15:49:24 +00:00
|
|
|
&cgroup)) != -1) {
|
2013-03-28 18:08:39 +00:00
|
|
|
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-04 15:49:24 +00:00
|
|
|
ENSURE_ERRNO(EINVAL);
|
2013-03-28 18:08:39 +00:00
|
|
|
|
|
|
|
/* Asking for impossible combination since devices is not mounted */
|
|
|
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_DEVICES),
|
2013-07-04 15:49:24 +00:00
|
|
|
&cgroup)) != -1) {
|
2013-03-28 18:08:39 +00:00
|
|
|
fprintf(stderr, "Should not have created /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-04 15:49:24 +00:00
|
|
|
ENSURE_ERRNO(ENXIO);
|
2013-03-28 18:08:39 +00:00
|
|
|
|
|
|
|
/* Asking for small combination since devices is not mounted */
|
|
|
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_CPU) |
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_MEMORY),
|
|
|
|
&cgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-04-26 09:23:51 +00:00
|
|
|
ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsSmall, links, placementSmall);
|
2013-03-28 18:08:39 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
|
|
|
|
if ((rv = virCgroupNewPartition("/virtualmachines", true, -1, &cgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-04-26 09:23:51 +00:00
|
|
|
ret = validateCgroup(cgroup, "/virtualmachines.partition", mountsFull, links, placementFull);
|
2013-03-28 18:08:39 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-03-28 18:08:39 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-28 14:36:52 +00:00
|
|
|
|
2013-03-28 18:08:39 +00:00
|
|
|
static int testCgroupNewForPartitionNested(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
int rv;
|
|
|
|
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
|
2013-04-26 09:23:51 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/deployment.partition/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/deployment.partition/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/deployment.partition/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/deployment.partition/production.partition",
|
2013-03-28 18:08:39 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
2013-04-26 09:23:51 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "/deployment.partition/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/deployment.partition/production.partition",
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/user/berrange/123",
|
2013-03-28 18:08:39 +00:00
|
|
|
};
|
2013-03-28 14:36:52 +00:00
|
|
|
|
2013-07-04 15:49:24 +00:00
|
|
|
if ((rv = virCgroupNewPartition("/deployment/production", false, -1, &cgroup)) != -1) {
|
2013-04-26 09:23:51 +00:00
|
|
|
fprintf(stderr, "Unexpected found /deployment/production cgroup: %d\n", -rv);
|
2013-03-28 18:08:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-04 15:49:24 +00:00
|
|
|
ENSURE_ERRNO(ENOENT);
|
2013-03-28 18:08:39 +00:00
|
|
|
|
2013-04-26 09:23:51 +00:00
|
|
|
/* Should not work, since we require /deployment to be pre-created */
|
2013-07-04 15:49:24 +00:00
|
|
|
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != -1) {
|
2013-04-26 09:23:51 +00:00
|
|
|
fprintf(stderr, "Unexpected created /deployment/production cgroup: %d\n", -rv);
|
2013-03-28 18:08:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-04 15:49:24 +00:00
|
|
|
ENSURE_ERRNO(ENOENT);
|
2013-03-28 18:08:39 +00:00
|
|
|
|
2013-04-26 09:23:51 +00:00
|
|
|
if ((rv = virCgroupNewPartition("/deployment", true, -1, &cgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Failed to create /deployment cgroup: %d\n", -rv);
|
2013-03-28 18:08:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Should now work */
|
2013-04-26 09:23:51 +00:00
|
|
|
if ((rv = virCgroupNewPartition("/deployment/production", true, -1, &cgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Failed to create /deployment/production cgroup: %d\n", -rv);
|
2013-03-28 18:08:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-26 09:23:51 +00:00
|
|
|
ret = validateCgroup(cgroup, "/deployment.partition/production.partition",
|
|
|
|
mountsFull, links, placementFull);
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-04-26 09:23:51 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int testCgroupNewForPartitionNestedDeep(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
int rv;
|
|
|
|
const char *placementFull[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/user/berrange.user/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/user/berrange.user/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/user/berrange.user/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/user/berrange.user/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "/user/berrange.user/production.partition",
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/user/berrange.user/production.partition",
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/user/berrange/123",
|
2013-04-26 09:23:51 +00:00
|
|
|
};
|
|
|
|
|
2013-07-04 15:49:24 +00:00
|
|
|
if ((rv = virCgroupNewPartition("/user/berrange.user/production", false, -1, &cgroup)) != -1) {
|
2013-04-26 09:23:51 +00:00
|
|
|
fprintf(stderr, "Unexpected found /user/berrange.user/production cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-04 15:49:24 +00:00
|
|
|
ENSURE_ERRNO(ENOENT);
|
2013-04-26 09:23:51 +00:00
|
|
|
|
|
|
|
/* Should not work, since we require /user/berrange.user to be pre-created */
|
2013-07-04 15:49:24 +00:00
|
|
|
if ((rv = virCgroupNewPartition("/user/berrange.user/production", true, -1, &cgroup)) != -1) {
|
2013-04-26 09:23:51 +00:00
|
|
|
fprintf(stderr, "Unexpected created /user/berrange.user/production cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-07-04 15:49:24 +00:00
|
|
|
ENSURE_ERRNO(ENOENT);
|
2013-04-26 09:23:51 +00:00
|
|
|
|
|
|
|
if ((rv = virCgroupNewPartition("/user", true, -1, &cgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = virCgroupNewPartition("/user/berrange.user", true, -1, &cgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Should now work */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = validateCgroup(cgroup, "/user/berrange.user/production.partition",
|
|
|
|
mountsFull, links, placementFull);
|
2013-03-28 18:08:39 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-03-28 18:08:39 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int testCgroupNewForPartitionDomain(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr partitioncgroup = NULL;
|
|
|
|
virCgroupPtr domaincgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
int rv;
|
|
|
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
2013-04-26 09:23:51 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/production.partition/foo.libvirt-lxc",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/production.partition/foo.libvirt-lxc",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/production.partition/foo.libvirt-lxc",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/production.partition/foo.libvirt-lxc",
|
2013-03-28 18:08:39 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
2013-04-26 09:23:51 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "/production.partition/foo.libvirt-lxc",
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/production.partition/foo.libvirt-lxc",
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/user/berrange/123",
|
2013-03-28 18:08:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if ((rv = virCgroupNewPartition("/production", true, -1, &partitioncgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Failed to create /production cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = virCgroupNewDomainPartition(partitioncgroup, "lxc", "foo", true, &domaincgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-26 09:23:51 +00:00
|
|
|
ret = validateCgroup(domaincgroup, "/production.partition/foo.libvirt-lxc", mountsFull, links, placement);
|
2013-03-28 18:08:39 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-03-28 18:08:39 +00:00
|
|
|
virCgroupFree(&partitioncgroup);
|
|
|
|
virCgroupFree(&domaincgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-26 09:50:24 +00:00
|
|
|
static int testCgroupNewForPartitionDomainEscaped(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr partitioncgroup1 = NULL;
|
|
|
|
virCgroupPtr partitioncgroup2 = NULL;
|
|
|
|
virCgroupPtr partitioncgroup3 = NULL;
|
|
|
|
virCgroupPtr domaincgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
int rv;
|
|
|
|
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_CPUACCT] = "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc",
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc",
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/_cgroup.evil/net_cls.evil/__evil.evil/_cpu.foo.libvirt-lxc",
|
2013-07-25 18:13:44 +00:00
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/user/berrange/123",
|
2013-04-26 09:50:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if ((rv = virCgroupNewPartition("/cgroup.evil", true, -1, &partitioncgroup1)) != 0) {
|
|
|
|
fprintf(stderr, "Failed to create /cgroup.evil cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = virCgroupNewDomainPartition(partitioncgroup3, "lxc", "cpu.foo", true, &domaincgroup)) != 0) {
|
|
|
|
fprintf(stderr, "Cannot create LXC cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-04-26 09:50:24 +00:00
|
|
|
virCgroupFree(&partitioncgroup3);
|
|
|
|
virCgroupFree(&partitioncgroup2);
|
|
|
|
virCgroupFree(&partitioncgroup1);
|
|
|
|
virCgroupFree(&domaincgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-10 13:31:53 +00:00
|
|
|
static int testCgroupNewForSelfAllInOne(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = "/",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = "/",
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = "/",
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = "/",
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = "/",
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = "/",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
|
|
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement);
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-09-10 13:31:53 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-11 18:15:52 +00:00
|
|
|
static int testCgroupNewForSelfLogind(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPU] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
|
|
|
|
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (virCgroupNewSelf(&cgroup) < 0) {
|
|
|
|
fprintf(stderr, "Cannot create cgroup for self\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = validateCgroup(cgroup, "", mountsLogind, linksLogind, placement);
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2013-09-11 18:15:52 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int testCgroupAvailable(const void *args)
|
|
|
|
{
|
|
|
|
bool got = virCgroupAvailable();
|
|
|
|
bool want = args == (void*)0x1;
|
|
|
|
|
|
|
|
if (got != want) {
|
|
|
|
fprintf(stderr, "Expected cgroup %savailable, but state was wrong\n",
|
|
|
|
want ? "" : "not ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-14 17:49:08 +00:00
|
|
|
static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
size_t i;
|
|
|
|
int rv, ret = -1;
|
2015-01-22 10:54:50 +00:00
|
|
|
virTypedParameterPtr params = NULL;
|
|
|
|
# define EXPECTED_NCPUS 160
|
2014-02-14 17:49:08 +00:00
|
|
|
|
2015-01-23 09:30:01 +00:00
|
|
|
unsigned long long expected[EXPECTED_NCPUS] = {
|
2015-01-22 10:54:50 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
7059492996, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
4180532496, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1957541268, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
2065932204, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
18228689414, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
4245525148, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
2911161568, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1407758136, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1836807700, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
1065296618, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
2046213266, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
747889778, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
709566900, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
444777342, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
5683512916, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
635751356, 0, 0, 0, 0, 0, 0, 0,
|
2014-02-14 17:49:08 +00:00
|
|
|
};
|
2015-01-22 10:54:50 +00:00
|
|
|
|
|
|
|
if (VIR_ALLOC_N(params, EXPECTED_NCPUS) < 0)
|
|
|
|
goto cleanup;
|
2014-02-14 17:49:08 +00:00
|
|
|
|
|
|
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_CPU) |
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_CPUACCT),
|
|
|
|
&cgroup)) < 0) {
|
|
|
|
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-01-22 10:54:50 +00:00
|
|
|
if (nodeGetCPUCount() != EXPECTED_NCPUS) {
|
2014-02-14 17:49:08 +00:00
|
|
|
fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount());
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = virCgroupGetPercpuStats(cgroup,
|
|
|
|
params,
|
2015-01-22 10:54:50 +00:00
|
|
|
1, 0, EXPECTED_NCPUS, 0)) < 0) {
|
2014-02-14 17:49:08 +00:00
|
|
|
fprintf(stderr, "Failed call to virCgroupGetPercpuStats for /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-01-22 10:54:50 +00:00
|
|
|
for (i = 0; i < EXPECTED_NCPUS; i++) {
|
2014-02-14 17:49:08 +00:00
|
|
|
if (!STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_CPUTIME)) {
|
|
|
|
fprintf(stderr,
|
2015-01-22 10:54:50 +00:00
|
|
|
"Wrong parameter name value from virCgroupGetPercpuStats at %zu (is: %s)\n",
|
|
|
|
i, params[i].field);
|
2014-02-14 17:49:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params[i].type != VIR_TYPED_PARAM_ULLONG) {
|
|
|
|
fprintf(stderr,
|
2015-01-22 10:54:50 +00:00
|
|
|
"Wrong parameter value type from virCgroupGetPercpuStats at %zu (is: %d)\n",
|
|
|
|
i, params[i].type);
|
2014-02-14 17:49:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params[i].value.ul != expected[i]) {
|
|
|
|
fprintf(stderr,
|
2015-01-22 10:54:50 +00:00
|
|
|
"Wrong value from virCgroupGetMemoryUsage at %zu (expected %llu)\n",
|
|
|
|
i, params[i].value.ul);
|
2014-02-14 17:49:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-02-14 17:49:08 +00:00
|
|
|
virCgroupFree(&cgroup);
|
2015-01-26 09:20:22 +00:00
|
|
|
VIR_FREE(params);
|
2014-02-14 17:49:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-14 17:49:06 +00:00
|
|
|
static int testCgroupGetMemoryUsage(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
int rv, ret = -1;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = virCgroupGetMemoryUsage(cgroup, &kb)) < 0) {
|
|
|
|
fprintf(stderr, "Could not retrieve GetMemoryUsage for /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kb != 1421212UL) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Wrong value from virCgroupGetMemoryUsage (expected %ld)\n",
|
|
|
|
1421212UL);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-02-14 17:49:06 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-14 17:49:05 +00:00
|
|
|
static int testCgroupGetBlkioIoServiced(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
size_t i;
|
|
|
|
int rv, ret = -1;
|
|
|
|
|
|
|
|
const long long expected_values[] = {
|
2014-02-22 00:21:58 +00:00
|
|
|
119084214273ULL,
|
|
|
|
822880960513ULL,
|
2014-02-14 17:49:05 +00:00
|
|
|
9665167,
|
|
|
|
73283807
|
|
|
|
};
|
|
|
|
const char* names[] = {
|
|
|
|
"bytes read",
|
|
|
|
"bytes written",
|
|
|
|
"requests read",
|
|
|
|
"requests written"
|
|
|
|
};
|
|
|
|
long long values[ARRAY_CARDINALITY(expected_values)];
|
|
|
|
|
|
|
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_BLKIO),
|
|
|
|
&cgroup)) < 0) {
|
|
|
|
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(expected_values); i++) {
|
|
|
|
if (expected_values[i] != values[i]) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Wrong value for %s from virCgroupBlkioIoServiced (expected %lld)\n",
|
|
|
|
names[i], expected_values[i]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-02-14 17:49:05 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int testCgroupGetBlkioIoDeviceServiced(const void *args ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
virCgroupPtr cgroup = NULL;
|
|
|
|
size_t i;
|
|
|
|
int rv, ret = -1;
|
|
|
|
const long long expected_values0[] = {
|
2014-02-22 00:21:58 +00:00
|
|
|
59542107136ULL,
|
|
|
|
411440480256ULL,
|
2014-02-14 17:49:05 +00:00
|
|
|
4832583,
|
|
|
|
36641903
|
|
|
|
};
|
|
|
|
const long long expected_values1[] = {
|
2014-02-22 00:21:58 +00:00
|
|
|
59542107137ULL,
|
|
|
|
411440480257ULL,
|
2014-02-14 17:49:05 +00:00
|
|
|
4832584,
|
|
|
|
36641904
|
|
|
|
};
|
|
|
|
const char* names[] = {
|
|
|
|
"bytes read",
|
|
|
|
"bytes written",
|
|
|
|
"requests read",
|
|
|
|
"requests written"
|
|
|
|
};
|
|
|
|
long long values[ARRAY_CARDINALITY(expected_values0)];
|
|
|
|
|
|
|
|
if ((rv = virCgroupNewPartition("/virtualmachines", true,
|
|
|
|
(1 << VIR_CGROUP_CONTROLLER_BLKIO),
|
|
|
|
&cgroup)) < 0) {
|
|
|
|
fprintf(stderr, "Could not create /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = virCgroupGetBlkioIoDeviceServiced(cgroup,
|
|
|
|
FAKEDEVDIR0,
|
|
|
|
values, &values[1],
|
|
|
|
&values[2], &values[3])) < 0) {
|
|
|
|
fprintf(stderr, "Could not retrieve BlkioIoDeviceServiced for /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(expected_values0); i++) {
|
|
|
|
if (expected_values0[i] != values[i]) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n",
|
|
|
|
names[i], expected_values0[i]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = virCgroupGetBlkioIoDeviceServiced(cgroup,
|
|
|
|
FAKEDEVDIR1,
|
|
|
|
values, &values[1],
|
|
|
|
&values[2], &values[3])) < 0) {
|
|
|
|
fprintf(stderr, "Could not retrieve BlkioIoDeviceServiced for /virtualmachines cgroup: %d\n", -rv);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_CARDINALITY(expected_values1); i++) {
|
|
|
|
if (expected_values1[i] != values[i]) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Wrong value for %s from virCgroupGetBlkioIoDeviceServiced (expected %lld)\n",
|
|
|
|
names[i], expected_values1[i]);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-02-14 17:49:05 +00:00
|
|
|
virCgroupFree(&cgroup);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-09-10 13:31:53 +00:00
|
|
|
|
2013-03-28 18:08:39 +00:00
|
|
|
# define FAKESYSFSDIRTEMPLATE abs_builddir "/fakesysfsdir-XXXXXX"
|
2013-03-28 14:36:52 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
char *fakesysfsdir;
|
|
|
|
|
2013-05-03 12:52:21 +00:00
|
|
|
if (VIR_STRDUP_QUIET(fakesysfsdir, FAKESYSFSDIRTEMPLATE) < 0) {
|
2013-03-28 14:36:52 +00:00
|
|
|
fprintf(stderr, "Out of memory\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mkdtemp(fakesysfsdir)) {
|
|
|
|
fprintf(stderr, "Cannot create fakesysfsdir");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
setenv("LIBVIRT_FAKE_SYSFS_DIR", fakesysfsdir, 1);
|
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("New cgroup for self", testCgroupNewForSelf, NULL) < 0)
|
2013-03-28 14:36:52 +00:00
|
|
|
ret = -1;
|
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("New cgroup for partition", testCgroupNewForPartition, NULL) < 0)
|
2013-03-28 14:36:52 +00:00
|
|
|
ret = -1;
|
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("New cgroup for partition nested", testCgroupNewForPartitionNested, NULL) < 0)
|
2013-03-28 18:08:39 +00:00
|
|
|
ret = -1;
|
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("New cgroup for partition nested deeply", testCgroupNewForPartitionNestedDeep, NULL) < 0)
|
2013-04-26 09:23:51 +00:00
|
|
|
ret = -1;
|
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("New cgroup for domain partition", testCgroupNewForPartitionDomain, NULL) < 0)
|
2013-03-28 18:08:39 +00:00
|
|
|
ret = -1;
|
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("New cgroup for domain partition escaped", testCgroupNewForPartitionDomainEscaped, NULL) < 0)
|
2013-04-26 09:50:24 +00:00
|
|
|
ret = -1;
|
2013-03-28 18:08:39 +00:00
|
|
|
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("Cgroup available", testCgroupAvailable, (void*)0x1) < 0)
|
2013-09-11 18:15:52 +00:00
|
|
|
ret = -1;
|
|
|
|
|
2014-02-14 17:49:05 +00:00
|
|
|
if (virtTestRun("virCgroupGetBlkioIoServiced works", testCgroupGetBlkioIoServiced, NULL) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
|
|
|
if (virtTestRun("virCgroupGetBlkioIoDeviceServiced works", testCgroupGetBlkioIoDeviceServiced, NULL) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
2014-02-14 17:49:06 +00:00
|
|
|
if (virtTestRun("virCgroupGetMemoryUsage works", testCgroupGetMemoryUsage, NULL) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
2014-02-14 17:49:08 +00:00
|
|
|
if (virtTestRun("virCgroupGetPercpuStats works", testCgroupGetPercpuStats, NULL) < 0)
|
|
|
|
ret = -1;
|
|
|
|
|
2013-09-10 13:31:53 +00:00
|
|
|
setenv("VIR_CGROUP_MOCK_MODE", "allinone", 1);
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("New cgroup for self (allinone)", testCgroupNewForSelfAllInOne, NULL) < 0)
|
2013-09-10 13:31:53 +00:00
|
|
|
ret = -1;
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("Cgroup available", testCgroupAvailable, (void*)0x1) < 0)
|
2013-09-11 18:15:52 +00:00
|
|
|
ret = -1;
|
|
|
|
unsetenv("VIR_CGROUP_MOCK_MODE");
|
|
|
|
|
|
|
|
setenv("VIR_CGROUP_MOCK_MODE", "logind", 1);
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("New cgroup for self (logind)", testCgroupNewForSelfLogind, NULL) < 0)
|
2013-09-11 18:15:52 +00:00
|
|
|
ret = -1;
|
2013-09-20 18:13:35 +00:00
|
|
|
if (virtTestRun("Cgroup available", testCgroupAvailable, (void*)0x0) < 0)
|
2013-09-11 18:15:52 +00:00
|
|
|
ret = -1;
|
2013-09-10 13:31:53 +00:00
|
|
|
unsetenv("VIR_CGROUP_MOCK_MODE");
|
|
|
|
|
2013-03-28 14:36:52 +00:00
|
|
|
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
|
|
|
virFileDeleteTree(fakesysfsdir);
|
|
|
|
|
|
|
|
VIR_FREE(fakesysfsdir);
|
|
|
|
|
2014-03-17 09:38:38 +00:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2013-03-28 14:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/vircgroupmock.so")
|
|
|
|
|
|
|
|
#else
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
#endif
|