diff options
author | Bui Quang Minh <minhquangbui99@gmail.com> | 2022-09-04 11:05:10 +0300 |
---|---|---|
committer | Andrei Vagin <avagin@gmail.com> | 2022-11-02 07:35:04 +0300 |
commit | a8328c72a01ac825cebc974f2beb7d9e06cfdebb (patch) | |
tree | 16fefe0cf7e88103a9002e8f63f9c8b208c10ff4 | |
parent | 1304415e5f159d9c059c48a17f3b7f0468fcb14e (diff) |
zdtm: Add test to check global properties of cgroup-v2 are preserved
Check that CRIU can checkpoint/restore global properties in cgroup-v2 properly.
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
-rw-r--r-- | test/zdtm/static/Makefile | 1 | ||||
-rw-r--r-- | test/zdtm/static/cgroupv2_00.c | 86 | ||||
-rwxr-xr-x | test/zdtm/static/cgroupv2_00.checkskip | 11 | ||||
-rw-r--r-- | test/zdtm/static/cgroupv2_00.desc | 1 | ||||
-rwxr-xr-x | test/zdtm/static/cgroupv2_00.hook | 16 |
5 files changed, 115 insertions, 0 deletions
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile index 0ac22731b..915e565bd 100644 --- a/test/zdtm/static/Makefile +++ b/test/zdtm/static/Makefile @@ -386,6 +386,7 @@ TST_DIR = \ cgroup02 \ cgroup03 \ cgroup04 \ + cgroupv2_00 \ cgroup_ifpriomap \ cgroup_ignore \ cgroup_stray \ diff --git a/test/zdtm/static/cgroupv2_00.c b/test/zdtm/static/cgroupv2_00.c new file mode 100644 index 000000000..2c6780e0c --- /dev/null +++ b/test/zdtm/static/cgroupv2_00.c @@ -0,0 +1,86 @@ +#include <sys/mount.h> +#include <sys/stat.h> + +#include "zdtmtst.h" + +const char *test_doc = "Check that some cgroup-v2 properties in kernel controllers are preserved"; +const char *test_author = "Bui Quang Minh <minhquangbui99@gmail.com>"; + +char *dirname; +TEST_OPTION(dirname, string, "cgroup-v2 directory name", 1); +const char *cgname = "subcg00"; + +int main(int argc, char **argv) +{ + char path[1024], aux[1024]; + int ret = -1; + + test_init(argc, argv); + + if (mkdir(dirname, 0700) < 0 && errno != EEXIST) { + pr_perror("Can't make dir"); + return -1; + } + + if (mount("cgroup2", dirname, "cgroup2", 0, NULL)) { + pr_perror("Can't mount cgroup-v2"); + return -1; + } + + sprintf(path, "%s/%s", dirname, cgname); + if (mkdir(path, 0700) < 0 && errno != EEXIST) { + pr_perror("Can't make dir"); + goto out; + } + + /* Make cpuset controllers available in children directory */ + sprintf(path, "%s/%s", dirname, "cgroup.subtree_control"); + sprintf(aux, "%s", "+cpuset"); + if (write_value(path, aux)) + goto out; + + sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.subtree_control"); + sprintf(aux, "%s", "+cpuset"); + if (write_value(path, aux)) + goto out; + + sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.type"); + sprintf(aux, "%s", "threaded"); + if (write_value(path, aux)) + goto out; + + sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.procs"); + sprintf(aux, "%d", getpid()); + if (write_value(path, aux)) + goto out; + + test_daemon(); + test_waitsig(); + + sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.subtree_control"); + if (read_value(path, aux, sizeof(aux))) + goto out; + + if (strcmp(aux, "cpuset\n")) { + fail("cgroup.subtree_control mismatches"); + goto out; + } + + sprintf(path, "%s/%s/%s", dirname, cgname, "cgroup.type"); + if (read_value(path, aux, sizeof(aux))) + goto out; + + if (strcmp(aux, "threaded\n")) { + fail("cgroup.type mismatches"); + goto out; + } + + pass(); + + ret = 0; + +out: + sprintf(path, "%s", dirname); + umount(path); + return ret; +} diff --git a/test/zdtm/static/cgroupv2_00.checkskip b/test/zdtm/static/cgroupv2_00.checkskip new file mode 100755 index 000000000..375ed3564 --- /dev/null +++ b/test/zdtm/static/cgroupv2_00.checkskip @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ -f /sys/fs/cgroup/cgroup.controllers ]; then + grep -q "cpuset" /sys/fs/cgroup/cgroup.controllers && exit 0 +fi + +if [ -d /sys/fs/cgroup/unified ]; then + grep -q "cpuset" /sys/fs/cgroup/unified/cgroup.controllers && exit 0 +fi + +exit 1 diff --git a/test/zdtm/static/cgroupv2_00.desc b/test/zdtm/static/cgroupv2_00.desc new file mode 100644 index 000000000..4bfd4b265 --- /dev/null +++ b/test/zdtm/static/cgroupv2_00.desc @@ -0,0 +1 @@ +{'flavor': 'h ns', 'flags': 'suid', 'opts': '--manage-cgroups=full'} diff --git a/test/zdtm/static/cgroupv2_00.hook b/test/zdtm/static/cgroupv2_00.hook new file mode 100755 index 000000000..1002b1ec5 --- /dev/null +++ b/test/zdtm/static/cgroupv2_00.hook @@ -0,0 +1,16 @@ +#!/bin/bash + +[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0 + +set -e +cgname="subcg00" +tname=$(mktemp -d cgclean.XXXXXX) +mount -t cgroup2 cgroup2 $tname + +echo "Cleaning $tname" +echo "-cpuset" > "$tname/$cgname/cgroup.subtree_control" + +set +e +rmdir "$tname/$cgname" +umount "$tname" +rmdir "$tname" |