• Home
  • Raw
  • Download

Lines Matching +full:test +full:- +full:cgroups

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (c) 2020-2021 SUSE LLC <rpalethorpe@suse.com>
27 * This is actually a single-linked list not a tree. We only need to
39 * this field. So it may be different from root->css_field.
61 /* CGroup hierarchy: mnt -> ltp -> {drain, test -> ??? } We
62 * keep a flat reference to ltp, drain and test for
68 /* LTP CGroup directory, contains drain and test dirs */
72 /* CGroup for current test. Which may have children. */
80 /* Controller sub-systems */
153 * populated with the test's CGroup.
164 /* procs exists on V1, however it was read-only until kernel v3.0. */
299 for ((r) = first_root; (r)->ver; (r)++)
301 for ((r) = roots + 1; (r)->ver; (r)++)
303 for ((ctrl) = controllers; (ctrl)->ctrl_name; (ctrl)++)
313 for ((t) = (ctrl) ? (cg)->dirs_by_ctrl + (ctrl) : (cg)->dirs; \
315 (t) = (ctrl) ? (cg)->dirs + ROOTS_MAX : (t) + 1)
321 return !!(ctrl_field & (1 << ctrl->ctrl_indx)); in has_ctrl()
328 *ctrl_field |= 1 << ctrl->ctrl_indx; in add_ctrl()
349 return ctrl->ctrl_root && ctrl->ctrl_root->ver == TST_CG_V2; in cgroup_ctrl_on_v2()
359 new->dir_root = parent->dir_root; in cgroup_dir_mk()
360 new->dir_name = dir_name; in cgroup_dir_mk()
361 new->dir_parent = parent; in cgroup_dir_mk()
362 new->ctrl_field = parent->ctrl_field; in cgroup_dir_mk()
363 new->we_created_it = 0; in cgroup_dir_mk()
365 if (!mkdirat(parent->dir_fd, dir_name, 0777)) { in cgroup_dir_mk()
366 new->we_created_it = 1; in cgroup_dir_mk()
373 dpath = tst_decode_fd(parent->dir_fd); in cgroup_dir_mk()
382 parent->dir_fd, dpath, dir_name); in cgroup_dir_mk()
386 new->dir_fd = SAFE_OPENAT(parent->dir_fd, dir_name, in cgroup_dir_mk()
406 struct cgroup_root *root = ctrl->ctrl_root; in tst_cg_print_config()
412 ctrl->ctrl_name, in tst_cg_print_config()
413 root->ver, in tst_cg_print_config()
414 ctrl->we_require_it, in tst_cg_print_config()
415 root->mnt_path, in tst_cg_print_config()
416 root->we_mounted_it, in tst_cg_print_config()
417 root->ltp_dir.we_created_it, in tst_cg_print_config()
418 root->test_dir.dir_name ? root->test_dir.dir_name : "NULL"); in tst_cg_print_config()
428 if (!strcmp(ctrl_name, ctrl->ctrl_name)) in cgroup_find_ctrl()
440 if (!strcmp(root->mnt_path, mnt_path)) in cgroup_find_root()
465 ctrl->we_require_it = we_require_it; in cgroup_parse_config_line()
472 root->we_mounted_it = 1; in cgroup_parse_config_line()
474 if (!root->ltp_dir.dir_name) { in cgroup_parse_config_line()
475 cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir); in cgroup_parse_config_line()
476 cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir); in cgroup_parse_config_line()
478 root->ltp_dir.we_created_it = 1; in cgroup_parse_config_line()
479 root->drain_dir.we_created_it = 1; in cgroup_parse_config_line()
483 if (!root->test_dir.dir_name && strcmp(test_dir_name, "NULL")) { in cgroup_parse_config_line()
485 cgroup_dir_mk(&root->ltp_dir, cgroup_test_dir, &root->test_dir); in cgroup_parse_config_line()
486 root->test_dir.we_created_it = 1; in cgroup_parse_config_line()
490 /* Load the test state config provided by tst_cg_print_config
520 * For CGroups V2 this is very simple as there is only one
559 if (root->ver && ctrl_field == root->ctrl_field) in cgroup_root_scan()
562 if (root->ctrl_field) in cgroup_root_scan()
565 root->ver = TST_CG_V2; in cgroup_root_scan()
582 if (!(ctrl_field & root->ctrl_field)) in cgroup_root_scan()
585 if (ctrl_field == root->ctrl_field) in cgroup_root_scan()
590 "Check '%s' and '%s'", root->mnt_path, mnt_dir); in cgroup_root_scan()
599 root->ver = TST_CG_V1; in cgroup_root_scan()
602 strcpy(root->mnt_path, mnt_dir); in cgroup_root_scan()
603 root->mnt_dir.dir_root = root; in cgroup_root_scan()
604 root->mnt_dir.dir_name = root->mnt_path; in cgroup_root_scan()
605 root->mnt_dir.dir_fd = mnt_dfd; in cgroup_root_scan()
606 root->ctrl_field = ctrl_field; in cgroup_root_scan()
607 root->no_cpuset_prefix = no_prefix; in cgroup_root_scan()
610 if (has_ctrl(root->ctrl_field, ctrl)) in cgroup_root_scan()
611 ctrl->ctrl_root = root; in cgroup_root_scan()
637 if (strncmp(mnt->mnt_type, "cgroup", 6)) in tst_cg_scan()
640 cgroup_root_scan(mnt->mnt_type, mnt->mnt_dir, mnt->mnt_opts); in tst_cg_scan()
679 tst_res(TINFO, "Mounted V2 CGroups on %s", mnt_path); in cgroup_mount_v2()
685 tst_res(TINFO | TERRNO, "Could not mount V2 CGroups on %s", mnt_path); in cgroup_mount_v2()
700 if (ctrl->ctrl_indx == CTRL_BLKIO && controllers[CTRL_IO].ctrl_root) { in cgroup_mount_v1()
707 tmpdir, cgroup_mount_ltp_prefix, ctrl->ctrl_name); in cgroup_mount_v1()
728 if (mount(ctrl->ctrl_name, mnt_path, "cgroup", 0, ctrl->ctrl_name)) { in cgroup_mount_v1()
737 tst_res(TINFO, "Mounted V1 %s CGroup on %s", ctrl->ctrl_name, mnt_path); in cgroup_mount_v1()
739 if (!ctrl->ctrl_root) in cgroup_mount_v1()
742 ctrl->ctrl_root->we_mounted_it = 1; in cgroup_mount_v1()
743 ctrl->ctrl_root->mnt_dir.we_created_it = made_dir; in cgroup_mount_v1()
745 if (ctrl->ctrl_indx == CTRL_MEMORY) { in cgroup_mount_v1()
746 SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd, in cgroup_mount_v1()
758 const char *const *const fname = root->no_cpuset_prefix ? n0 : n1; in cgroup_copy_cpuset()
761 SAFE_FILE_READAT(root->mnt_dir.dir_fd, in cgroup_copy_cpuset()
763 SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd, in cgroup_copy_cpuset()
783 * of cgroups. If we are on V2 we first need to enable the controller
789 * to distribute these settings to the test cgroups. This means the
790 * test author does not have to copy these settings before using the
807 if (ctrl->we_require_it) in tst_cg_require()
808 tst_res(TWARN, "Duplicate %s(%s, )", __func__, ctrl->ctrl_name); in tst_cg_require()
810 ctrl->we_require_it = 1; in tst_cg_require()
812 if (ctrl->ctrl_root) in tst_cg_require()
817 if (ctrl->ctrl_root) in tst_cg_require()
820 if (!cgroup_v2_mounted() && options->needs_ver != TST_CG_V1) in tst_cg_require()
823 if (ctrl->ctrl_root) in tst_cg_require()
826 if (options->needs_ver != TST_CG_V2) in tst_cg_require()
829 if (!ctrl->ctrl_root) { in tst_cg_require()
832 ctrl->ctrl_name); in tst_cg_require()
837 root = ctrl->ctrl_root; in tst_cg_require()
838 add_ctrl(&root->mnt_dir.ctrl_field, ctrl); in tst_cg_require()
840 if (cgroup_ctrl_on_v2(ctrl) && options->needs_ver == TST_CG_V1) { in tst_cg_require()
843 ctrl->ctrl_name); in tst_cg_require()
845 if (!cgroup_ctrl_on_v2(ctrl) && options->needs_ver == TST_CG_V2) { in tst_cg_require()
848 ctrl->ctrl_name); in tst_cg_require()
852 if (root->we_mounted_it) { in tst_cg_require()
853 SAFE_FILE_PRINTFAT(root->mnt_dir.dir_fd, in tst_cg_require()
854 cgsc, "+%s", ctrl->ctrl_name); in tst_cg_require()
856 tst_file_printfat(root->mnt_dir.dir_fd, in tst_cg_require()
857 cgsc, "+%s", ctrl->ctrl_name); in tst_cg_require()
861 if (!root->ltp_dir.dir_fd) in tst_cg_require()
862 cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir); in tst_cg_require()
864 root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; in tst_cg_require()
867 SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd, in tst_cg_require()
868 cgsc, "+%s", ctrl->ctrl_name); in tst_cg_require()
870 SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd, in tst_cg_require()
873 if (ctrl->ctrl_indx == CTRL_CPUSET) in tst_cg_require()
877 cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir); in tst_cg_require()
879 if (options->test_pid) in tst_cg_require()
880 sprintf(cgroup_test_dir, "test-%d", options->test_pid); in tst_cg_require()
882 sprintf(cgroup_test_dir, "test-%d", getpid()); in tst_cg_require()
884 cgroup_dir_mk(&root->ltp_dir, cgroup_test_dir, &root->test_dir); in tst_cg_require()
918 if (root->test_dir.dir_fd > 0) in close_path_fds()
919 SAFE_CLOSE(root->test_dir.dir_fd); in close_path_fds()
920 if (root->ltp_dir.dir_fd > 0) in close_path_fds()
921 SAFE_CLOSE(root->ltp_dir.dir_fd); in close_path_fds()
922 if (root->drain_dir.dir_fd > 0) in close_path_fds()
923 SAFE_CLOSE(root->drain_dir.dir_fd); in close_path_fds()
924 if (root->mnt_dir.dir_fd > 0) in close_path_fds()
925 SAFE_CLOSE(root->mnt_dir.dir_fd); in close_path_fds()
928 /* Maybe remove CGroups used during testing and clear our data
930 * This will never remove CGroups we did not create to allow tests to
933 * Each test process is given its own unique CGroup. Unless we want to
934 * stress test the CGroup system. We should at least remove these
935 * unique per test CGroups.
938 * this may have been created by the system manager or another test
943 * test. Note that successfully unmounting a CGroup root does not
946 * The ltp/drain CGroup is required for cleaning up test CGroups when
947 * we can not move them to the root CGroup. CGroups can only be
948 * removed when they have no members and only leaf or root CGroups may
949 * have processes within them. As test processes create and destroy
950 * their own CGroups they must move themselves either to root or
952 * unique test CGroup.
955 * the test process to root and destroy the drain and LTP
956 * CGroups. Otherwise we just leave the test process to die in the
959 * Finally we clear any data we have collected on CGroups. This will
971 if (!root->test_dir.dir_name) in tst_cg_cleanup()
974 cgroup_drain(root->ver, in tst_cg_cleanup()
975 root->test_dir.dir_fd, root->drain_dir.dir_fd); in tst_cg_cleanup()
976 SAFE_UNLINKAT(root->ltp_dir.dir_fd, root->test_dir.dir_name, in tst_cg_cleanup()
981 if (!root->ltp_dir.we_created_it) in tst_cg_cleanup()
984 cgroup_drain(root->ver, in tst_cg_cleanup()
985 root->drain_dir.dir_fd, root->mnt_dir.dir_fd); in tst_cg_cleanup()
987 if (root->drain_dir.dir_name) { in tst_cg_cleanup()
988 SAFE_UNLINKAT(root->ltp_dir.dir_fd, in tst_cg_cleanup()
989 root->drain_dir.dir_name, AT_REMOVEDIR); in tst_cg_cleanup()
992 if (root->ltp_dir.dir_name) { in tst_cg_cleanup()
993 SAFE_UNLINKAT(root->mnt_dir.dir_fd, in tst_cg_cleanup()
994 root->ltp_dir.dir_name, AT_REMOVEDIR); in tst_cg_cleanup()
999 if (!cgroup_ctrl_on_v2(ctrl) || !ctrl->ctrl_root->we_mounted_it) in tst_cg_cleanup()
1002 SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd, in tst_cg_cleanup()
1004 "-%s", ctrl->ctrl_name); in tst_cg_cleanup()
1008 if (!root->we_mounted_it) in tst_cg_cleanup()
1014 if (umount2(root->mnt_path, MNT_DETACH)) in tst_cg_cleanup()
1017 SAFE_RMDIR(root->mnt_path); in tst_cg_cleanup()
1022 ctrl->ctrl_root = NULL; in tst_cg_cleanup()
1023 ctrl->we_require_it = 0; in tst_cg_cleanup()
1040 if (dir->dir_root->ver != TST_CG_V1) in cgroup_group_add_dir()
1041 cg->dirs_by_ctrl[0] = dir; in cgroup_group_add_dir()
1044 if (!has_ctrl(dir->ctrl_field, ctrl)) in cgroup_group_add_dir()
1047 cg->dirs_by_ctrl[ctrl->ctrl_indx] = dir; in cgroup_group_add_dir()
1049 if (!parent || dir->dir_root->ver == TST_CG_V1) in cgroup_group_add_dir()
1053 "+%s", ctrl->ctrl_name); in cgroup_group_add_dir()
1056 for (i = 0; cg->dirs[i]; i++) in cgroup_group_add_dir()
1058 cg->dirs[i] = dir; in cgroup_group_add_dir()
1075 name_len = vsnprintf(cg->group_name, NAME_MAX, in tst_cg_group_mk()
1084 cgroup_dir_mk(*dir, cg->group_name, new_dir); in tst_cg_group_mk()
1093 return cg->group_name; in tst_cg_group_name()
1101 close((*dir)->dir_fd); in tst_cg_group_rm()
1102 SAFE_UNLINKAT((*dir)->dir_parent->dir_fd, in tst_cg_group_rm()
1103 (*dir)->dir_name, in tst_cg_group_rm()
1130 len = sep - file_name; in cgroup_file_find()
1142 for (cfile = ctrl->files; cfile->file_name; cfile++) { in cgroup_file_find()
1143 if (!strcmp(file_name, cfile->file_name)) in cgroup_file_find()
1147 if (!cfile->file_name) { in cgroup_file_find()
1150 file_name, ctrl->ctrl_name); in cgroup_file_find()
1177 dir = cg->dirs_by_ctrl[ctrl->ctrl_indx]; in tst_cg_ver()
1182 ctrl_name, cg->group_name); in tst_cg_ver()
1186 return dir->dir_root->ver; in tst_cg_ver()
1193 if (dir->dir_root->ver != TST_CG_V1) in cgroup_file_alias()
1194 return cfile->file_name; in cgroup_file_alias()
1196 if (cfile->ctrl_indx == CTRL_CPUSET && in cgroup_file_alias()
1197 dir->dir_root->no_cpuset_prefix && in cgroup_file_alias()
1198 cfile->file_name_v1) { in cgroup_file_alias()
1199 return strchr(cfile->file_name_v1, '.') + 1; in cgroup_file_alias()
1202 return cfile->file_name_v1; in cgroup_file_alias()
1217 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_has()
1222 if (!faccessat((*dir)->dir_fd, alias, F_OK, 0)) in safe_cg_has()
1230 (*dir)->dir_fd, tst_decode_fd((*dir)->dir_fd), alias); in safe_cg_has()
1240 if (cg->group_name[0]) { in group_from_roots()
1243 cg == &test_group ? "Test" : "Drain"); in group_from_roots()
1248 cg == &test_group ? &root->test_dir : &root->drain_dir; in group_from_roots()
1250 if (dir->ctrl_field) in group_from_roots()
1254 if (cg->dirs[0]) { in group_from_roots()
1255 strncpy(cg->group_name, cg->dirs[0]->dir_name, NAME_MAX); in group_from_roots()
1260 "No CGroups found; maybe you forgot to call tst_cg_require?"); in group_from_roots()
1282 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_read()
1291 (*dir)->dir_fd, alias, out, len); in safe_cg_read()
1321 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_printf()
1328 (*dir)->dir_fd, alias, fmt, va); in safe_cg_printf()
1343 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_open()
1348 fds[i++] = safe_openat(file, lineno, (*dir)->dir_fd, alias, flags); in safe_cg_open()
1364 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_fchown()
1369 safe_fchownat(file, lineno, (*dir)->dir_fd, alias, owner, group, 0); in safe_cg_fchown()