]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
selftests: cgroup: skip test_cgcore_lesser_ns_open when cgroup2 mounted without nsdel...
authorTianchen Ding <dtcccc@linux.alibaba.com>
Wed, 27 Mar 2024 02:44:37 +0000 (10:44 +0800)
committerTejun Heo <tj@kernel.org>
Wed, 3 Apr 2024 19:42:13 +0000 (09:42 -1000)
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>
tools/testing/selftests/cgroup/cgroup_util.c
tools/testing/selftests/cgroup/cgroup_util.h
tools/testing/selftests/cgroup/test_core.c
tools/testing/selftests/cgroup/test_cpu.c
tools/testing/selftests/cgroup/test_cpuset.c
tools/testing/selftests/cgroup/test_freezer.c
tools/testing/selftests/cgroup/test_hugetlb_memcg.c
tools/testing/selftests/cgroup/test_kill.c
tools/testing/selftests/cgroup/test_kmem.c
tools/testing/selftests/cgroup/test_memcontrol.c
tools/testing/selftests/cgroup/test_zswap.c

index 0340d4ca8f51cbfed84512362f3aa02c106712f2..432db923bced0c522138e8423c19297a2317ad5c 100644 (file)
@@ -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;
                }
        }
index 1df7f202214afcb6bb73e55d04163d02974371d9..89e8519fb2719c53d27f2b99b111809ebe929022 100644 (file)
@@ -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);
index 80aa6b2373b9660a2d5407cf1bf112f2ea3e92f5..a5672a91d273ced50a1582297e9711ac0012fa2f 100644 (file)
@@ -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"))
index 24020a2c68dcdd9fff0e8d0f4af279d6840bbe77..186bf96f6a284651b9953d75a1f91806db118821 100644 (file)
@@ -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"))
index b061ed1e05b4d08f63b3c7ea4541133c7ad7f16a..4034d14ba69ac03b119d9718beca6e66332d90cf 100644 (file)
@@ -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"))
index 8845353aca53bb90e7781afc8bb3e86b94bc35b1..8730645d363a73a03f297a06ba4ae6acf7eb9d55 100644 (file)
@@ -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)) {
index f0fefeb4cc24c4c130674e13dd40138332ca023e..856f9508ea562e08bb6dc9d1ca6cb6f3be717e31 100644 (file)
@@ -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)) {
index 6153690319c9c888e0e53047898ee0469f577d3a..0e5bb6c7307a504ffb76653a1241e6beb8c12e3b 100644 (file)
@@ -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)) {
index c82f974b85c94d0ae82b54ec5b560449480fb48f..137506db03127fb3eed6554e684bd41f7112e77f 100644 (file)
@@ -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");
 
        /*
index c7c9572003a8c9efa29a179e4121a243112c63be..b462416b380612b4d22f4757379e13cd006aa8a1 100644 (file)
@@ -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");
 
        /*
index f0e488ed90d8959dc5edb83da057741ad6608384..ef7f39545317387b9b7c824531aa143ec86d9c24 100644 (file)
@@ -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())