Skip to content

Commit 4793cb5

Browse files
dtcccchtejun
authored andcommitted
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: bf35a78 ("selftests: cgroup: Test open-time cgroup namespace usage for migration checks") Signed-off-by: Tianchen Ding <[email protected]> Reviewed-by: Muhammad Usama Anjum <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 20d4628 commit 4793cb5

File tree

11 files changed

+20
-13
lines changed

11 files changed

+20
-13
lines changed

tools/testing/selftests/cgroup/cgroup_util.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ int cg_write_numeric(const char *cgroup, const char *control, long value)
195195
return cg_write(cgroup, control, buf);
196196
}
197197

198-
int cg_find_unified_root(char *root, size_t len)
198+
int cg_find_unified_root(char *root, size_t len, bool *nsdelegate)
199199
{
200200
char buf[10 * PAGE_SIZE];
201-
char *fs, *mount, *type;
201+
char *fs, *mount, *type, *options;
202202
const char delim[] = "\n\t ";
203203

204204
if (read_text("/proc/self/mounts", buf, sizeof(buf)) <= 0)
@@ -211,12 +211,14 @@ int cg_find_unified_root(char *root, size_t len)
211211
for (fs = strtok(buf, delim); fs; fs = strtok(NULL, delim)) {
212212
mount = strtok(NULL, delim);
213213
type = strtok(NULL, delim);
214-
strtok(NULL, delim);
214+
options = strtok(NULL, delim);
215215
strtok(NULL, delim);
216216
strtok(NULL, delim);
217217

218218
if (strcmp(type, "cgroup2") == 0) {
219219
strncpy(root, mount, len);
220+
if (nsdelegate)
221+
*nsdelegate = !!strstr(options, "nsdelegate");
220222
return 0;
221223
}
222224
}

tools/testing/selftests/cgroup/cgroup_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static inline int values_close(long a, long b, int err)
2121
return abs(a - b) <= (a + b) / 100 * err;
2222
}
2323

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);
2525
extern char *cg_name(const char *root, const char *name);
2626
extern char *cg_name_indexed(const char *root, const char *name, int index);
2727
extern char *cg_control(const char *cgroup, const char *control);

tools/testing/selftests/cgroup/test_core.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "../kselftest.h"
1919
#include "cgroup_util.h"
2020

21+
static bool nsdelegate;
22+
2123
static int touch_anon(char *buf, size_t size)
2224
{
2325
int fd;
@@ -775,6 +777,9 @@ static int test_cgcore_lesser_ns_open(const char *root)
775777
pid_t pid;
776778
int status;
777779

780+
if (!nsdelegate)
781+
return KSFT_SKIP;
782+
778783
cg_test_a = cg_name(root, "cg_test_a");
779784
cg_test_b = cg_name(root, "cg_test_b");
780785

@@ -862,7 +867,7 @@ int main(int argc, char *argv[])
862867
char root[PATH_MAX];
863868
int i, ret = EXIT_SUCCESS;
864869

865-
if (cg_find_unified_root(root, sizeof(root)))
870+
if (cg_find_unified_root(root, sizeof(root), &nsdelegate))
866871
ksft_exit_skip("cgroup v2 isn't mounted\n");
867872

868873
if (cg_read_strstr(root, "cgroup.subtree_control", "memory"))

tools/testing/selftests/cgroup/test_cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ int main(int argc, char *argv[])
700700
char root[PATH_MAX];
701701
int i, ret = EXIT_SUCCESS;
702702

703-
if (cg_find_unified_root(root, sizeof(root)))
703+
if (cg_find_unified_root(root, sizeof(root), NULL))
704704
ksft_exit_skip("cgroup v2 isn't mounted\n");
705705

706706
if (cg_read_strstr(root, "cgroup.subtree_control", "cpu"))

tools/testing/selftests/cgroup/test_cpuset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ int main(int argc, char *argv[])
249249
char root[PATH_MAX];
250250
int i, ret = EXIT_SUCCESS;
251251

252-
if (cg_find_unified_root(root, sizeof(root)))
252+
if (cg_find_unified_root(root, sizeof(root), NULL))
253253
ksft_exit_skip("cgroup v2 isn't mounted\n");
254254

255255
if (cg_read_strstr(root, "cgroup.subtree_control", "cpuset"))

tools/testing/selftests/cgroup/test_freezer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ int main(int argc, char *argv[])
827827
char root[PATH_MAX];
828828
int i, ret = EXIT_SUCCESS;
829829

830-
if (cg_find_unified_root(root, sizeof(root)))
830+
if (cg_find_unified_root(root, sizeof(root), NULL))
831831
ksft_exit_skip("cgroup v2 isn't mounted\n");
832832
for (i = 0; i < ARRAY_SIZE(tests); i++) {
833833
switch (tests[i].fn(root)) {

tools/testing/selftests/cgroup/test_hugetlb_memcg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ int main(int argc, char **argv)
214214
return ret;
215215
}
216216

217-
if (cg_find_unified_root(root, sizeof(root)))
217+
if (cg_find_unified_root(root, sizeof(root), NULL))
218218
ksft_exit_skip("cgroup v2 isn't mounted\n");
219219

220220
switch (test_hugetlb_memcg(root)) {

tools/testing/selftests/cgroup/test_kill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ int main(int argc, char *argv[])
276276
char root[PATH_MAX];
277277
int i, ret = EXIT_SUCCESS;
278278

279-
if (cg_find_unified_root(root, sizeof(root)))
279+
if (cg_find_unified_root(root, sizeof(root), NULL))
280280
ksft_exit_skip("cgroup v2 isn't mounted\n");
281281
for (i = 0; i < ARRAY_SIZE(tests); i++) {
282282
switch (tests[i].fn(root)) {

tools/testing/selftests/cgroup/test_kmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ int main(int argc, char **argv)
420420
char root[PATH_MAX];
421421
int i, ret = EXIT_SUCCESS;
422422

423-
if (cg_find_unified_root(root, sizeof(root)))
423+
if (cg_find_unified_root(root, sizeof(root), NULL))
424424
ksft_exit_skip("cgroup v2 isn't mounted\n");
425425

426426
/*

tools/testing/selftests/cgroup/test_memcontrol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ int main(int argc, char **argv)
13141314
char root[PATH_MAX];
13151315
int i, proc_status, ret = EXIT_SUCCESS;
13161316

1317-
if (cg_find_unified_root(root, sizeof(root)))
1317+
if (cg_find_unified_root(root, sizeof(root), NULL))
13181318
ksft_exit_skip("cgroup v2 isn't mounted\n");
13191319

13201320
/*

0 commit comments

Comments
 (0)