Skip to content

Commit fcd3497

Browse files
xuyang0410wangli5665
authored andcommitted
lib/tst_cgroup: Reset cgroup.clone_children value
When running cgroup test cases(like cpuset01 or oom05) about cpuset subsystem firstly, then cpuset_inherit case will fail because the value of cgroup.clone_children has been changed into 1 on cgroup-v1. Reset this value when calling tst_cgroupN_umount. Signed-off-by: Yang Xu <[email protected]> Acked-by: Li Wang <[email protected]>
1 parent 4d8373f commit fcd3497

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/tst_cgroup.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <stdio.h>
1010
#include <stdlib.h>
1111
#include <sys/mount.h>
12+
#include <fcntl.h>
13+
#include <unistd.h>
1214

1315
#include "tst_test.h"
1416
#include "tst_safe_macros.h"
@@ -17,6 +19,7 @@
1719
#include "tst_device.h"
1820

1921
static enum tst_cgroup_ver tst_cg_ver;
22+
static int clone_children;
2023

2124
static int tst_cgroup_check(const char *cgroup)
2225
{
@@ -88,6 +91,7 @@ static void tst_cgroup1_mount(const char *name, const char *option,
8891
*/
8992
if (strcmp(option, "cpuset") == 0) {
9093
sprintf(knob_path, "%s/cgroup.clone_children", mnt_path);
94+
SAFE_FILE_SCANF(knob_path, "%d", &clone_children);
9195
SAFE_FILE_PRINTF(knob_path, "%d", 1);
9296
}
9397
out:
@@ -123,6 +127,7 @@ static void tst_cgroupN_umount(const char *mnt_path, const char *new_path)
123127
FILE *fp;
124128
int fd;
125129
char s_new[BUFSIZ], s[BUFSIZ], value[BUFSIZ];
130+
char knob_path[PATH_MAX];
126131

127132
if (!tst_is_mounted(mnt_path))
128133
return;
@@ -151,6 +156,13 @@ static void tst_cgroupN_umount(const char *mnt_path, const char *new_path)
151156
!= (ssize_t)strlen(value) - 1)
152157
tst_res(TWARN | TERRNO, "write %s", s);
153158
}
159+
if (tst_cg_ver & TST_CGROUP_V1) {
160+
sprintf(knob_path, "%s/cpuset.cpus", mnt_path);
161+
if (!access(knob_path, F_OK)) {
162+
sprintf(knob_path, "%s/cgroup.clone_children", mnt_path);
163+
SAFE_FILE_PRINTF(knob_path, "%d", clone_children);
164+
}
165+
}
154166
if (fd != -1)
155167
close(fd);
156168
if (fp != NULL)

0 commit comments

Comments
 (0)