Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Fixes: bf35a7879f1d ("selftests: cgroup: Test open-time cgroup namespace usage for migration checks")
Signed-off-by: Tianchen Ding <dtcccc@linux.alibaba.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Tianchen Ding and committed by
Tejun Heo
4793cb59 20d46283

+20 -13
+5 -3
tools/testing/selftests/cgroup/cgroup_util.c
··· 195 195 return cg_write(cgroup, control, buf); 196 196 } 197 197 198 - int cg_find_unified_root(char *root, size_t len) 198 + int cg_find_unified_root(char *root, size_t len, bool *nsdelegate) 199 199 { 200 200 char buf[10 * PAGE_SIZE]; 201 - char *fs, *mount, *type; 201 + char *fs, *mount, *type, *options; 202 202 const char delim[] = "\n\t "; 203 203 204 204 if (read_text("/proc/self/mounts", buf, sizeof(buf)) <= 0) ··· 211 211 for (fs = strtok(buf, delim); fs; fs = strtok(NULL, delim)) { 212 212 mount = strtok(NULL, delim); 213 213 type = strtok(NULL, delim); 214 - strtok(NULL, delim); 214 + options = strtok(NULL, delim); 215 215 strtok(NULL, delim); 216 216 strtok(NULL, delim); 217 217 218 218 if (strcmp(type, "cgroup2") == 0) { 219 219 strncpy(root, mount, len); 220 + if (nsdelegate) 221 + *nsdelegate = !!strstr(options, "nsdelegate"); 220 222 return 0; 221 223 } 222 224 }
+1 -1
tools/testing/selftests/cgroup/cgroup_util.h
··· 21 21 return abs(a - b) <= (a + b) / 100 * err; 22 22 } 23 23 24 - extern int cg_find_unified_root(char *root, size_t len); 24 + extern int cg_find_unified_root(char *root, size_t len, bool *nsdelegate); 25 25 extern char *cg_name(const char *root, const char *name); 26 26 extern char *cg_name_indexed(const char *root, const char *name, int index); 27 27 extern char *cg_control(const char *cgroup, const char *control);
+6 -1
tools/testing/selftests/cgroup/test_core.c
··· 18 18 #include "../kselftest.h" 19 19 #include "cgroup_util.h" 20 20 21 + static bool nsdelegate; 22 + 21 23 static int touch_anon(char *buf, size_t size) 22 24 { 23 25 int fd; ··· 777 775 pid_t pid; 778 776 int status; 779 777 778 + if (!nsdelegate) 779 + return KSFT_SKIP; 780 + 780 781 cg_test_a = cg_name(root, "cg_test_a"); 781 782 cg_test_b = cg_name(root, "cg_test_b"); 782 783 ··· 867 862 char root[PATH_MAX]; 868 863 int i, ret = EXIT_SUCCESS; 869 864 870 - if (cg_find_unified_root(root, sizeof(root))) 865 + if (cg_find_unified_root(root, sizeof(root), &nsdelegate)) 871 866 ksft_exit_skip("cgroup v2 isn't mounted\n"); 872 867 873 868 if (cg_read_strstr(root, "cgroup.subtree_control", "memory"))
+1 -1
tools/testing/selftests/cgroup/test_cpu.c
··· 700 700 char root[PATH_MAX]; 701 701 int i, ret = EXIT_SUCCESS; 702 702 703 - if (cg_find_unified_root(root, sizeof(root))) 703 + if (cg_find_unified_root(root, sizeof(root), NULL)) 704 704 ksft_exit_skip("cgroup v2 isn't mounted\n"); 705 705 706 706 if (cg_read_strstr(root, "cgroup.subtree_control", "cpu"))
+1 -1
tools/testing/selftests/cgroup/test_cpuset.c
··· 249 249 char root[PATH_MAX]; 250 250 int i, ret = EXIT_SUCCESS; 251 251 252 - if (cg_find_unified_root(root, sizeof(root))) 252 + if (cg_find_unified_root(root, sizeof(root), NULL)) 253 253 ksft_exit_skip("cgroup v2 isn't mounted\n"); 254 254 255 255 if (cg_read_strstr(root, "cgroup.subtree_control", "cpuset"))
+1 -1
tools/testing/selftests/cgroup/test_freezer.c
··· 827 827 char root[PATH_MAX]; 828 828 int i, ret = EXIT_SUCCESS; 829 829 830 - if (cg_find_unified_root(root, sizeof(root))) 830 + if (cg_find_unified_root(root, sizeof(root), NULL)) 831 831 ksft_exit_skip("cgroup v2 isn't mounted\n"); 832 832 for (i = 0; i < ARRAY_SIZE(tests); i++) { 833 833 switch (tests[i].fn(root)) {
+1 -1
tools/testing/selftests/cgroup/test_hugetlb_memcg.c
··· 214 214 return ret; 215 215 } 216 216 217 - if (cg_find_unified_root(root, sizeof(root))) 217 + if (cg_find_unified_root(root, sizeof(root), NULL)) 218 218 ksft_exit_skip("cgroup v2 isn't mounted\n"); 219 219 220 220 switch (test_hugetlb_memcg(root)) {
+1 -1
tools/testing/selftests/cgroup/test_kill.c
··· 276 276 char root[PATH_MAX]; 277 277 int i, ret = EXIT_SUCCESS; 278 278 279 - if (cg_find_unified_root(root, sizeof(root))) 279 + if (cg_find_unified_root(root, sizeof(root), NULL)) 280 280 ksft_exit_skip("cgroup v2 isn't mounted\n"); 281 281 for (i = 0; i < ARRAY_SIZE(tests); i++) { 282 282 switch (tests[i].fn(root)) {
+1 -1
tools/testing/selftests/cgroup/test_kmem.c
··· 420 420 char root[PATH_MAX]; 421 421 int i, ret = EXIT_SUCCESS; 422 422 423 - if (cg_find_unified_root(root, sizeof(root))) 423 + if (cg_find_unified_root(root, sizeof(root), NULL)) 424 424 ksft_exit_skip("cgroup v2 isn't mounted\n"); 425 425 426 426 /*
+1 -1
tools/testing/selftests/cgroup/test_memcontrol.c
··· 1314 1314 char root[PATH_MAX]; 1315 1315 int i, proc_status, ret = EXIT_SUCCESS; 1316 1316 1317 - if (cg_find_unified_root(root, sizeof(root))) 1317 + if (cg_find_unified_root(root, sizeof(root), NULL)) 1318 1318 ksft_exit_skip("cgroup v2 isn't mounted\n"); 1319 1319 1320 1320 /*
+1 -1
tools/testing/selftests/cgroup/test_zswap.c
··· 440 440 char root[PATH_MAX]; 441 441 int i, ret = EXIT_SUCCESS; 442 442 443 - if (cg_find_unified_root(root, sizeof(root))) 443 + if (cg_find_unified_root(root, sizeof(root), NULL)) 444 444 ksft_exit_skip("cgroup v2 isn't mounted\n"); 445 445 446 446 if (!zswap_configured())