Skip to content

Commit 973da9f

Browse files
coolgwpevik
authored andcommitted
tst_cgroup.c: Add a cgroup base controller
For new test case such as kill01.c no need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" base controller. Reviewed-by: Li Wang <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Wei Gao <[email protected]>
1 parent ddf65fd commit 973da9f

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

lib/tst_cgroup.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {
9494
CTRL_MISC,
9595
CTRL_PERFEVENT,
9696
CTRL_DEBUG,
97-
CTRL_RDMA
97+
CTRL_RDMA,
98+
CTRL_BASE
9899
};
99-
#define CTRLS_MAX CTRL_RDMA
100+
#define CTRLS_MAX CTRL_BASE
100101

101102
/* At most we can have one cgroup V1 tree for each controller and one
102103
* (empty) v2 tree.
@@ -258,6 +259,10 @@ static const struct cgroup_file rdma_ctrl_files[] = {
258259
{ }
259260
};
260261

262+
static const struct cgroup_file base_ctrl_files[] = {
263+
{ }
264+
};
265+
261266
#define CTRL_NAME_MAX 31
262267
#define CGROUP_CTRL_MEMBER(x, y)[y] = { .ctrl_name = #x, .files = \
263268
x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
@@ -281,6 +286,7 @@ static struct cgroup_ctrl controllers[] = {
281286
CGROUP_CTRL_MEMBER(perf_event, CTRL_PERFEVENT),
282287
CGROUP_CTRL_MEMBER(debug, CTRL_DEBUG),
283288
CGROUP_CTRL_MEMBER(rdma, CTRL_RDMA),
289+
CGROUP_CTRL_MEMBER(base, CTRL_BASE),
284290
{ }
285291
};
286292

@@ -797,6 +803,10 @@ void tst_cg_require(const char *const ctrl_name,
797803
const char *const cgsc = "cgroup.subtree_control";
798804
struct cgroup_ctrl *const ctrl = cgroup_find_ctrl(ctrl_name);
799805
struct cgroup_root *root;
806+
int base = !strcmp(ctrl->ctrl_name, "base");
807+
808+
if (base && options->needs_ver != TST_CG_V2)
809+
tst_brk(TCONF, "Base control only support needs_ver TST_CG_V2!");
800810

801811
if (!ctrl) {
802812
tst_brk(TBROK, "'%s' controller is unknown to LTP", ctrl_name);
@@ -826,6 +836,9 @@ void tst_cg_require(const char *const ctrl_name,
826836
if (options->needs_ver != TST_CG_V2)
827837
cgroup_mount_v1(ctrl);
828838

839+
if (base)
840+
ctrl->ctrl_root = roots;
841+
829842
if (!ctrl->ctrl_root) {
830843
tst_brk(TCONF,
831844
"'%s' controller required, but not available",
@@ -848,7 +861,7 @@ void tst_cg_require(const char *const ctrl_name,
848861
ctrl->ctrl_name);
849862
}
850863

851-
if (cgroup_ctrl_on_v2(ctrl)) {
864+
if (cgroup_ctrl_on_v2(ctrl) && !base) {
852865
if (root->we_mounted_it) {
853866
SAFE_FILE_PRINTFAT(root->mnt_dir.dir_fd,
854867
cgsc, "+%s", ctrl->ctrl_name);
@@ -863,15 +876,17 @@ void tst_cg_require(const char *const ctrl_name,
863876
else
864877
root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field;
865878

866-
if (cgroup_ctrl_on_v2(ctrl)) {
867-
SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd,
868-
cgsc, "+%s", ctrl->ctrl_name);
869-
} else {
870-
SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd,
871-
"cgroup.clone_children", "%d", 1);
879+
if (!base) {
880+
if (cgroup_ctrl_on_v2(ctrl)) {
881+
SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd,
882+
cgsc, "+%s", ctrl->ctrl_name);
883+
} else {
884+
SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd,
885+
"cgroup.clone_children", "%d", 1);
872886

873-
if (ctrl->ctrl_indx == CTRL_CPUSET)
874-
cgroup_copy_cpuset(root);
887+
if (ctrl->ctrl_indx == CTRL_CPUSET)
888+
cgroup_copy_cpuset(root);
889+
}
875890
}
876891

877892
cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
@@ -996,7 +1011,8 @@ void tst_cg_cleanup(void)
9961011
}
9971012

9981013
for_each_ctrl(ctrl) {
999-
if (!cgroup_ctrl_on_v2(ctrl) || !ctrl->ctrl_root->we_mounted_it)
1014+
if (!cgroup_ctrl_on_v2(ctrl) || !ctrl->ctrl_root->we_mounted_it
1015+
|| !strcmp(ctrl->ctrl_name, "base"))
10001016
continue;
10011017

10021018
SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd,
@@ -1049,8 +1065,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,
10491065
if (!parent || dir->dir_root->ver == TST_CG_V1)
10501066
continue;
10511067

1052-
SAFE_CG_PRINTF(parent, "cgroup.subtree_control",
1053-
"+%s", ctrl->ctrl_name);
1068+
if (strcmp(ctrl->ctrl_name, "base")) {
1069+
SAFE_CG_PRINTF(parent, "cgroup.subtree_control",
1070+
"+%s", ctrl->ctrl_name);
1071+
}
10541072
}
10551073

10561074
for (i = 0; cg->dirs[i]; i++)

0 commit comments

Comments
 (0)