selftests: cgroup: skip test_cgcore_lesser_ns_open when cgroup2 mounted without nsdelegate
PATCH 1/1 selftests: cgroup: skip test_cgcore_lesser_ns_open when cgroup2 mounted without nsdelegate
The test case test_cgcore_lesser_ns_open only tasks effect when cgroup2 is mounted with "nsdelegate" mount option. If it misses this option, or is remounted without "nsdelegate", the test case will fail. For example, running bpf/test_cgroup_storage first, and then run cgroup/test_core will fail on test_cgcore_lesser_ns_open. Skip it if "nsdelegate" is not detected in cgroup2 mount options.
--- tools/testing/selftests/cgroup/cgroup_util.c | 8 +++++--- tools/testing/selftests/cgroup/cgroup_util.h | 2 +- tools/testing/selftests/cgroup/test_core.c | 7 ++++++- tools/testing/selftests/cgroup/test_cpu.c | 2 +- tools/testing/selftests/cgroup/test_cpuset.c | 2 +- tools/testing/selftests/cgroup/test_freezer.c | 2 +- tools/testing/selftests/cgroup/test_hugetlb_memcg.c | 2 +- tools/testing/selftests/cgroup/test_kill.c | 2 +- tools/testing/selftests/cgroup/test_kmem.c | 2 +- tools/testing/selftests/cgroup/test_memcontrol.c | 2 +- tools/testing/selftests/cgroup/test_zswap.c | 2 +- 11 files changed, 20 insertions(+), 13 deletions(-)
tools/testing/selftests/cgroup/cgroup_util.c +5 -3
@@ -195,10 +195,10 @@ int cg_write_numeric(const char *cgroup, const char *control, long value)return cg_write (cgroup, control, buf); } -int cg_find_unified_root (char *root,size_t len) +int cg_find_unified_root (char *root,size_t len,bool *nsdelegate) {char buf[10 *PAGE_SIZE ]; -char *fs, *mount, *type; +char *fs, *mount, *type, *options;const char delim[] ="\n\t " ;if (read_text ("/proc/self/mounts" , buf,sizeof (buf)) <=0 )
@@ -211,12 +211,14 @@ int cg_find_unified_root(char *root, size_t len)for (fs =strtok (buf, delim); fs; fs =strtok (NULL , delim)) { mount =strtok (NULL , delim); type =strtok (NULL , delim); -strtok (NULL , delim); + options =strtok (NULL , delim);strtok (NULL , delim);strtok (NULL , delim);if (strcmp (type,"cgroup2" ) ==0 ) {strncpy (root, mount, len); +if (nsdelegate) + *nsdelegate = !!strstr (options,"nsdelegate" );return 0 ; } }
tools/testing/selftests/cgroup/cgroup_util.h +1 -1
@@ -21,7 +21,7 @@ static inline int values_close(long a, long b, int err)return abs (a - b) <= (a + b) /100 * err; } -extern int cg_find_unified_root (char *root,size_t len); +extern int cg_find_unified_root (char *root,size_t len,bool *nsdelegate);extern char *cg_name (const char *root,const char *name);extern char *cg_name_indexed (const char *root,const char *name,int index);extern char *cg_control (const char *cgroup,const char *control);
tools/testing/selftests/cgroup/test_core.c +6 -1
@@ -18,6 +18,8 @@#include "../kselftest.h" #include "cgroup_util.h" +static bool nsdelegate; +static int touch_anon (char *buf,size_t size) {int fd;
@@ -775,6 +777,9 @@ static int test_cgcore_lesser_ns_open(const char *root)pid_t pid;int status; +if (!nsdelegate) +return KSFT_SKIP ; + cg_test_a =cg_name (root,"cg_test_a" ); cg_test_b =cg_name (root,"cg_test_b" );
@@ -862,7 +867,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root), &nsdelegate))ksft_exit_skip ("cgroup v2 isn't mounted\n" );if (cg_read_strstr (root,"cgroup.subtree_control" ,"memory" ))
tools/testing/selftests/cgroup/test_cpu.c +1 -1
@@ -700,7 +700,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );if (cg_read_strstr (root,"cgroup.subtree_control" ,"cpu" ))
tools/testing/selftests/cgroup/test_cpuset.c +1 -1
@@ -249,7 +249,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );if (cg_read_strstr (root,"cgroup.subtree_control" ,"cpuset" ))
tools/testing/selftests/cgroup/test_freezer.c +1 -1
@@ -827,7 +827,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );for (i =0 ; i <ARRAY_SIZE (tests); i++) {switch (tests[i].fn (root)) {
tools/testing/selftests/cgroup/test_hugetlb_memcg.c +1 -1
@@ -214,7 +214,7 @@ int main(int argc, char **argv)return ret; } -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );switch (test_hugetlb_memcg (root)) {
tools/testing/selftests/cgroup/test_kill.c +1 -1
@@ -276,7 +276,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );for (i =0 ; i <ARRAY_SIZE (tests); i++) {switch (tests[i].fn (root)) {
tools/testing/selftests/cgroup/test_kmem.c +1 -1
@@ -420,7 +420,7 @@ int main(int argc, char **argv)char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );/*
tools/testing/selftests/cgroup/test_memcontrol.c +1 -1
@@ -1314,7 +1314,7 @@ int main(int argc, char **argv)char root[PATH_MAX ];int i, proc_status, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );/*
tools/testing/selftests/cgroup/test_zswap.c +1 -1
@@ -440,7 +440,7 @@ int main(int argc, char **argv)char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );if (!zswap_configured ())
Signature · 1 line
2.39.3
Quoted 9 lines · Tianchen Ding
The test case
test_cgcore_lesser_ns_openonly tasks effect when cgroup2 is mounted with "nsdelegate" mount option. If it misses this option, or is remounted without "nsdelegate", the test case will fail. For example, running bpf/test_cgroup_storage first, and then run cgroup/test_core will fail ontest_cgcore_lesser_ns_open. Skip it if "nsdelegate" is not detected in cgroup2 mount options.Fixes bf35a7879f1d ("selftests: cgroup: Test open-time cgroup namespace usage for migration checks")Signed-off-by Tianchen Ding <[email protected]>
Quoted 196 lines
--- tools/testing/selftests/cgroup/cgroup_util.c | 8 +++++--- tools/testing/selftests/cgroup/cgroup_util.h | 2 +- tools/testing/selftests/cgroup/test_core.c | 7 ++++++- tools/testing/selftests/cgroup/test_cpu.c | 2 +- tools/testing/selftests/cgroup/test_cpuset.c | 2 +- tools/testing/selftests/cgroup/test_freezer.c | 2 +- tools/testing/selftests/cgroup/test_hugetlb_memcg.c | 2 +- tools/testing/selftests/cgroup/test_kill.c | 2 +- tools/testing/selftests/cgroup/test_kmem.c | 2 +- tools/testing/selftests/cgroup/test_memcontrol.c | 2 +- tools/testing/selftests/cgroup/test_zswap.c | 2 +- 11 files changed, 20 insertions(+), 13 deletions(-)tools/testing/selftests/cgroup/cgroup_util.c +5
-3@@ -195,10 +195,10 @@ int cg_write_numeric(const char *cgroup, const char *control, long value)return cg_write (cgroup, control, buf); } -int cg_find_unified_root (char *root,size_t len) +int cg_find_unified_root (char *root,size_t len,bool *nsdelegate) {char buf[10 *PAGE_SIZE ]; -char *fs, *mount, *type; +char *fs, *mount, *type, *options;const char delim[] ="\n\t " ;if (read_text ("/proc/self/mounts" , buf,sizeof (buf)) <=0 )@@ -211,12 +211,14 @@ int cg_find_unified_root(char *root, size_t len)for (fs =strtok (buf, delim); fs; fs =strtok (NULL , delim)) { mount =strtok (NULL , delim); type =strtok (NULL , delim); -strtok (NULL , delim); + options =strtok (NULL , delim);strtok (NULL , delim);strtok (NULL , delim);if (strcmp (type,"cgroup2" ) ==0 ) {strncpy (root, mount, len); +if (nsdelegate) + *nsdelegate = !!strstr (options,"nsdelegate" );return 0 ; } }tools/testing/selftests/cgroup/cgroup_util.h +1
-1@@ -21,7 +21,7 @@ static inline int values_close(long a, long b, int err)return abs (a - b) <= (a + b) /100 * err; } -extern int cg_find_unified_root (char *root,size_t len); +extern int cg_find_unified_root (char *root,size_t len,bool *nsdelegate);extern char *cg_name (const char *root,const char *name);extern char *cg_name_indexed (const char *root,const char *name,int index);extern char *cg_control (const char *cgroup,const char *control);tools/testing/selftests/cgroup/test_core.c +6
-1@@ -18,6 +18,8 @@#include "../kselftest.h" #include "cgroup_util.h" +static bool nsdelegate; +static int touch_anon (char *buf,size_t size) {int fd;@@ -775,6 +777,9 @@ static int test_cgcore_lesser_ns_open(const char *root)pid_t pid;int status; +if (!nsdelegate) +return KSFT_SKIP ; + cg_test_a =cg_name (root,"cg_test_a" ); cg_test_b =cg_name (root,"cg_test_b" );@@ -862,7 +867,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root), &nsdelegate))ksft_exit_skip ("cgroup v2 isn't mounted\n" );if (cg_read_strstr (root,"cgroup.subtree_control" ,"memory" ))tools/testing/selftests/cgroup/test_cpu.c +1
-1@@ -700,7 +700,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );if (cg_read_strstr (root,"cgroup.subtree_control" ,"cpu" ))tools/testing/selftests/cgroup/test_cpuset.c +1
-1@@ -249,7 +249,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );if (cg_read_strstr (root,"cgroup.subtree_control" ,"cpuset" ))tools/testing/selftests/cgroup/test_freezer.c +1
-1@@ -827,7 +827,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );for (i =0 ; i <ARRAY_SIZE (tests); i++) {switch (tests[i].fn (root)) {tools/testing/selftests/cgroup/test_hugetlb_memcg.c +1
-1@@ -214,7 +214,7 @@ int main(int argc, char **argv)return ret; } -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );switch (test_hugetlb_memcg (root)) {tools/testing/selftests/cgroup/test_kill.c +1
-1@@ -276,7 +276,7 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );for (i =0 ; i <ARRAY_SIZE (tests); i++) {switch (tests[i].fn (root)) {tools/testing/selftests/cgroup/test_kmem.c +1
-1@@ -420,7 +420,7 @@ int main(int argc, char **argv)char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );/* tools/testing/selftests/cgroup/test_memcontrol.c +1
-1@@ -1314,7 +1314,7 @@ int main(int argc, char **argv)char root[PATH_MAX ];int i, proc_status, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );/* tools/testing/selftests/cgroup/test_zswap.c +1
-1@@ -440,7 +440,7 @@ int main(int argc, char **argv)char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root))) +if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );if (!zswap_configured ())
Signature · 2 lines
BR, Muhammad Usama Anjum
Quoted 9 lines · Tianchen Ding
The test case
test_cgcore_lesser_ns_openonly tasks effect when cgroup2 is mounted with "nsdelegate" mount option. If it misses this option, or is remounted without "nsdelegate", the test case will fail. For example, running bpf/test_cgroup_storage first, and then run cgroup/test_core will fail ontest_cgcore_lesser_ns_open. Skip it if "nsdelegate" is not detected in cgroup2 mount options.Fixes bf35a7879f1d ("selftests: cgroup: Test open-time cgroup namespace usage for migration checks")Signed-off-by Tianchen Ding <[email protected]>
Applied to cgroup/for-6.10.
Thanks.
Signature · 1 line
tejun