• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:root

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
28 * traverse from leaf towards root.
34 /* Shortcut to root */
39 * this field. So it may be different from root->css_field.
51 /* The root of a CGroup hierarchy/tree */
57 * controllers found while scanning this root.
61 /* CGroup hierarchy: mnt -> ltp -> {drain, test -> ??? } We
80 /* Controller sub-systems */
165 /* procs exists on V1, however it was read-only until kernel v3.0. */
306 for ((r) = first_root; (r)->ver; (r)++)
308 for ((r) = roots + 1; (r)->ver; (r)++)
310 for ((ctrl) = controllers; (ctrl)->ctrl_name; (ctrl)++)
320 for ((t) = (ctrl) ? (cg)->dirs_by_ctrl + (ctrl) : (cg)->dirs; \
322 (t) = (ctrl) ? (cg)->dirs + ROOTS_MAX : (t) + 1)
328 return !!(ctrl_field & (1 << ctrl->ctrl_indx)); in has_ctrl()
335 *ctrl_field |= 1 << ctrl->ctrl_indx; in add_ctrl()
356 return ctrl->ctrl_root && ctrl->ctrl_root->ver == TST_CG_V2; in cgroup_ctrl_on_v2()
366 new->dir_root = parent->dir_root; in cgroup_dir_mk()
367 new->dir_name = dir_name; in cgroup_dir_mk()
368 new->dir_parent = parent; in cgroup_dir_mk()
369 new->ctrl_field = parent->ctrl_field; in cgroup_dir_mk()
370 new->we_created_it = 0; in cgroup_dir_mk()
372 if (!mkdirat(parent->dir_fd, dir_name, 0777)) { in cgroup_dir_mk()
373 new->we_created_it = 1; in cgroup_dir_mk()
380 dpath = tst_decode_fd(parent->dir_fd); in cgroup_dir_mk()
384 "Lack permission to make '%s/%s'; premake it or run as root", in cgroup_dir_mk()
387 tst_brk(TCONF | TERRNO, "'%s/%s' must not be read-only", in cgroup_dir_mk()
392 parent->dir_fd, dpath, dir_name); in cgroup_dir_mk()
396 new->dir_fd = SAFE_OPENAT(parent->dir_fd, dir_name, in cgroup_dir_mk()
416 struct cgroup_root *root = ctrl->ctrl_root; in tst_cg_print_config() local
418 if (!root) in tst_cg_print_config()
422 ctrl->ctrl_name, in tst_cg_print_config()
423 root->ver, in tst_cg_print_config()
424 ctrl->we_require_it, in tst_cg_print_config()
425 root->mnt_path, in tst_cg_print_config()
426 root->we_mounted_it, in tst_cg_print_config()
427 root->ltp_dir.we_created_it, in tst_cg_print_config()
428 root->test_dir.dir_name ? root->test_dir.dir_name : "NULL"); in tst_cg_print_config()
438 if (!strcmp(ctrl_name, ctrl->ctrl_name)) in cgroup_find_ctrl()
447 struct cgroup_root *root; in cgroup_find_root() local
449 for_each_root(root) { in cgroup_find_root()
450 if (!strcmp(root->mnt_path, mnt_path)) in cgroup_find_root()
451 return root; in cgroup_find_root()
461 struct cgroup_root *root; in cgroup_parse_config_line() local
475 ctrl->we_require_it = we_require_it; in cgroup_parse_config_line()
477 root = cgroup_find_root(mnt_path); in cgroup_parse_config_line()
478 if (!root) in cgroup_parse_config_line()
479 tst_brk(TBROK, "Could not find root from config. Config possibly malformed?"); in cgroup_parse_config_line()
482 root->we_mounted_it = 1; in cgroup_parse_config_line()
484 if (!root->ltp_dir.dir_name) { in cgroup_parse_config_line()
485 cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir); in cgroup_parse_config_line()
486 cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir); in cgroup_parse_config_line()
488 root->ltp_dir.we_created_it = 1; in cgroup_parse_config_line()
489 root->drain_dir.we_created_it = 1; in cgroup_parse_config_line()
493 if (!root->test_dir.dir_name && strcmp(test_dir_name, "NULL")) { in cgroup_parse_config_line()
495 cgroup_dir_mk(&root->ltp_dir, cgroup_test_dir, &root->test_dir); in cgroup_parse_config_line()
496 root->test_dir.we_created_it = 1; in cgroup_parse_config_line()
541 * Each controller partition has its own hierarchy (root) which we
549 struct cgroup_root *root = roots; in cgroup_root_scan() local
569 if (root->ver && ctrl_field == root->ctrl_field) in cgroup_root_scan()
572 if (root->ctrl_field) in cgroup_root_scan()
575 root->ver = TST_CG_V2; in cgroup_root_scan()
591 for_each_v1_root(root) { in cgroup_root_scan()
592 if (!(ctrl_field & root->ctrl_field)) in cgroup_root_scan()
595 if (ctrl_field == root->ctrl_field) in cgroup_root_scan()
600 "Check '%s' and '%s'", root->mnt_path, mnt_dir); in cgroup_root_scan()
603 if (root >= roots + ROOTS_MAX) { in cgroup_root_scan()
609 root->ver = TST_CG_V1; in cgroup_root_scan()
612 strcpy(root->mnt_path, mnt_dir); in cgroup_root_scan()
613 root->mnt_dir.dir_root = root; in cgroup_root_scan()
614 root->mnt_dir.dir_name = root->mnt_path; in cgroup_root_scan()
615 root->mnt_dir.dir_fd = mnt_dfd; in cgroup_root_scan()
616 root->ctrl_field = ctrl_field; in cgroup_root_scan()
617 root->no_cpuset_prefix = no_prefix; in cgroup_root_scan()
620 if (has_ctrl(root->ctrl_field, ctrl)) in cgroup_root_scan()
621 ctrl->ctrl_root = root; in cgroup_root_scan()
647 if (strncmp(mnt->mnt_type, "cgroup", 6)) in tst_cg_scan()
650 cgroup_root_scan(mnt->mnt_type, mnt->mnt_dir, mnt->mnt_opts); in tst_cg_scan()
673 "Lack permission to make %s, premake it or run as root", in cgroup_mount_v2()
710 if (ctrl->ctrl_indx == CTRL_BLKIO && controllers[CTRL_IO].ctrl_root) { in cgroup_mount_v1()
712 "IO controller found on V2 root, skipping blkio mount that would unmount IO controller"); in cgroup_mount_v1()
717 tmpdir, cgroup_mount_ltp_prefix, ctrl->ctrl_name); in cgroup_mount_v1()
729 "Lack permission to make %s, premake it or run as root", in cgroup_mount_v1()
738 if (mount(ctrl->ctrl_name, mnt_path, "cgroup", 0, ctrl->ctrl_name)) { in cgroup_mount_v1()
747 tst_res(TINFO, "Mounted V1 %s CGroup on %s", ctrl->ctrl_name, mnt_path); in cgroup_mount_v1()
749 if (!ctrl->ctrl_root) in cgroup_mount_v1()
752 ctrl->ctrl_root->we_mounted_it = 1; in cgroup_mount_v1()
753 ctrl->ctrl_root->mnt_dir.we_created_it = made_dir; in cgroup_mount_v1()
755 if (ctrl->ctrl_indx == CTRL_MEMORY) { in cgroup_mount_v1()
756 SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd, in cgroup_mount_v1()
762 static void cgroup_copy_cpuset(const struct cgroup_root *const root) in cgroup_copy_cpuset() argument
768 const char *const *const fname = root->no_cpuset_prefix ? n0 : n1; in cgroup_copy_cpuset()
771 SAFE_FILE_READAT(root->mnt_dir.dir_fd, in cgroup_copy_cpuset()
773 SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd, in cgroup_copy_cpuset()
794 * for all children of root. Then we create hierarchy described in
798 * from root to the ltp group and set clone_children on the ltp group
809 struct cgroup_root *root; in tst_cg_require() local
810 int base = !strcmp(ctrl->ctrl_name, "base"); in tst_cg_require()
812 if (base && options->needs_ver != TST_CG_V2) in tst_cg_require()
821 if (ctrl->we_require_it) in tst_cg_require()
822 tst_res(TWARN, "Duplicate %s(%s, )", __func__, ctrl->ctrl_name); in tst_cg_require()
824 ctrl->we_require_it = 1; in tst_cg_require()
826 if (ctrl->ctrl_root) in tst_cg_require()
831 if (ctrl->ctrl_root) in tst_cg_require()
834 if (!cgroup_v2_mounted() && options->needs_ver != TST_CG_V1) in tst_cg_require()
837 if (ctrl->ctrl_root) in tst_cg_require()
840 if (options->needs_ver != TST_CG_V2) in tst_cg_require()
844 ctrl->ctrl_root = roots; in tst_cg_require()
846 if (!ctrl->ctrl_root) { in tst_cg_require()
849 ctrl->ctrl_name); in tst_cg_require()
854 root = ctrl->ctrl_root; in tst_cg_require()
855 add_ctrl(&root->mnt_dir.ctrl_field, ctrl); in tst_cg_require()
857 if (cgroup_ctrl_on_v2(ctrl) && options->needs_ver == TST_CG_V1) { in tst_cg_require()
860 ctrl->ctrl_name); in tst_cg_require()
862 if (!cgroup_ctrl_on_v2(ctrl) && options->needs_ver == TST_CG_V2) { in tst_cg_require()
865 ctrl->ctrl_name); in tst_cg_require()
869 if (root->we_mounted_it) { in tst_cg_require()
870 SAFE_FILE_PRINTFAT(root->mnt_dir.dir_fd, in tst_cg_require()
871 cgsc, "+%s", ctrl->ctrl_name); in tst_cg_require()
873 tst_file_printfat(root->mnt_dir.dir_fd, in tst_cg_require()
874 cgsc, "+%s", ctrl->ctrl_name); in tst_cg_require()
878 if (!root->ltp_dir.dir_fd) in tst_cg_require()
879 cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir); in tst_cg_require()
881 root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; in tst_cg_require()
885 SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd, in tst_cg_require()
886 cgsc, "+%s", ctrl->ctrl_name); in tst_cg_require()
888 SAFE_FILE_PRINTFAT(root->ltp_dir.dir_fd, in tst_cg_require()
891 if (ctrl->ctrl_indx == CTRL_CPUSET) in tst_cg_require()
892 cgroup_copy_cpuset(root); in tst_cg_require()
896 cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir); in tst_cg_require()
898 if (options->test_pid) in tst_cg_require()
899 sprintf(cgroup_test_dir, "test-%d", options->test_pid); in tst_cg_require()
901 sprintf(cgroup_test_dir, "test-%d", getpid()); in tst_cg_require()
903 cgroup_dir_mk(&root->ltp_dir, cgroup_test_dir, &root->test_dir); in tst_cg_require()
935 static void close_path_fds(struct cgroup_root *const root) in close_path_fds() argument
937 if (root->test_dir.dir_fd > 0) in close_path_fds()
938 SAFE_CLOSE(root->test_dir.dir_fd); in close_path_fds()
939 if (root->ltp_dir.dir_fd > 0) in close_path_fds()
940 SAFE_CLOSE(root->ltp_dir.dir_fd); in close_path_fds()
941 if (root->drain_dir.dir_fd > 0) in close_path_fds()
942 SAFE_CLOSE(root->drain_dir.dir_fd); in close_path_fds()
943 if (root->mnt_dir.dir_fd > 0) in close_path_fds()
944 SAFE_CLOSE(root->mnt_dir.dir_fd); in close_path_fds()
962 * test. Note that successfully unmounting a CGroup root does not
966 * we can not move them to the root CGroup. CGroups can only be
967 * removed when they have no members and only leaf or root CGroups may
969 * their own CGroups they must move themselves either to root or
973 * If we have access to root and created the LTP CGroup we then move
974 * the test process to root and destroy the drain and LTP
983 struct cgroup_root *root; in tst_cg_cleanup() local
989 for_each_root(root) { in tst_cg_cleanup()
990 if (!root->test_dir.dir_name) in tst_cg_cleanup()
993 cgroup_drain(root->ver, in tst_cg_cleanup()
994 root->test_dir.dir_fd, root->drain_dir.dir_fd); in tst_cg_cleanup()
995 SAFE_UNLINKAT(root->ltp_dir.dir_fd, root->test_dir.dir_name, in tst_cg_cleanup()
999 for_each_root(root) { in tst_cg_cleanup()
1000 if (!root->ltp_dir.we_created_it) in tst_cg_cleanup()
1003 cgroup_drain(root->ver, in tst_cg_cleanup()
1004 root->drain_dir.dir_fd, root->mnt_dir.dir_fd); in tst_cg_cleanup()
1006 if (root->drain_dir.dir_name) { in tst_cg_cleanup()
1007 SAFE_UNLINKAT(root->ltp_dir.dir_fd, in tst_cg_cleanup()
1008 root->drain_dir.dir_name, AT_REMOVEDIR); in tst_cg_cleanup()
1011 if (root->ltp_dir.dir_name) { in tst_cg_cleanup()
1012 SAFE_UNLINKAT(root->mnt_dir.dir_fd, in tst_cg_cleanup()
1013 root->ltp_dir.dir_name, AT_REMOVEDIR); in tst_cg_cleanup()
1018 if (!cgroup_ctrl_on_v2(ctrl) || !ctrl->ctrl_root->we_mounted_it in tst_cg_cleanup()
1019 || !strcmp(ctrl->ctrl_name, "base")) in tst_cg_cleanup()
1022 SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd, in tst_cg_cleanup()
1024 "-%s", ctrl->ctrl_name); in tst_cg_cleanup()
1027 for_each_root(root) { in tst_cg_cleanup()
1028 if (!root->we_mounted_it) in tst_cg_cleanup()
1031 /* This probably does not result in the CGroup root in tst_cg_cleanup()
1034 if (umount2(root->mnt_path, MNT_DETACH)) in tst_cg_cleanup()
1037 SAFE_RMDIR(root->mnt_path); in tst_cg_cleanup()
1042 ctrl->ctrl_root = NULL; in tst_cg_cleanup()
1043 ctrl->we_require_it = 0; in tst_cg_cleanup()
1046 for_each_root(root) in tst_cg_cleanup()
1047 close_path_fds(root); in tst_cg_cleanup()
1060 if (dir->dir_root->ver != TST_CG_V1) in cgroup_group_add_dir()
1061 cg->dirs_by_ctrl[0] = dir; in cgroup_group_add_dir()
1064 if (!has_ctrl(dir->ctrl_field, ctrl)) in cgroup_group_add_dir()
1067 cg->dirs_by_ctrl[ctrl->ctrl_indx] = dir; in cgroup_group_add_dir()
1069 if (!parent || dir->dir_root->ver == TST_CG_V1) in cgroup_group_add_dir()
1072 if (strcmp(ctrl->ctrl_name, "base")) { in cgroup_group_add_dir()
1074 "+%s", ctrl->ctrl_name); in cgroup_group_add_dir()
1078 for (i = 0; cg->dirs[i]; i++) in cgroup_group_add_dir()
1080 cg->dirs[i] = dir; in cgroup_group_add_dir()
1097 name_len = vsnprintf(cg->group_name, NAME_MAX, in tst_cg_group_mk()
1106 cgroup_dir_mk(*dir, cg->group_name, new_dir); in tst_cg_group_mk()
1115 return cg->group_name; in tst_cg_group_name()
1120 if(cg->dirs_by_ctrl[0]) in tst_cg_group_unified_dir_fd()
1121 return cg->dirs_by_ctrl[0]->dir_fd; in tst_cg_group_unified_dir_fd()
1123 return -1; in tst_cg_group_unified_dir_fd()
1131 close((*dir)->dir_fd); in tst_cg_group_rm()
1132 SAFE_UNLINKAT((*dir)->dir_parent->dir_fd, in tst_cg_group_rm()
1133 (*dir)->dir_name, in tst_cg_group_rm()
1160 len = sep - file_name; in cgroup_file_find()
1172 for (cfile = ctrl->files; cfile->file_name; cfile++) { in cgroup_file_find()
1173 if (!strcmp(file_name, cfile->file_name)) in cgroup_file_find()
1177 if (!cfile->file_name) { in cgroup_file_find()
1180 file_name, ctrl->ctrl_name); in cgroup_file_find()
1207 dir = cg->dirs_by_ctrl[ctrl->ctrl_indx]; in tst_cg_ver()
1212 ctrl_name, cg->group_name); in tst_cg_ver()
1216 return dir->dir_root->ver; in tst_cg_ver()
1223 if (dir->dir_root->ver != TST_CG_V1) in cgroup_file_alias()
1224 return cfile->file_name; in cgroup_file_alias()
1226 if (cfile->ctrl_indx == CTRL_CPUSET && in cgroup_file_alias()
1227 dir->dir_root->no_cpuset_prefix && in cgroup_file_alias()
1228 cfile->file_name_v1) { in cgroup_file_alias()
1229 return strchr(cfile->file_name_v1, '.') + 1; in cgroup_file_alias()
1232 return cfile->file_name_v1; in cgroup_file_alias()
1247 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_has()
1252 if (!faccessat((*dir)->dir_fd, alias, F_OK, 0)) in safe_cg_has()
1260 (*dir)->dir_fd, tst_decode_fd((*dir)->dir_fd), alias); in safe_cg_has()
1268 struct cgroup_root *root; in group_from_roots() local
1270 if (cg->group_name[0]) { in group_from_roots()
1276 for_each_root(root) { in group_from_roots()
1278 cg == &test_group ? &root->test_dir : &root->drain_dir; in group_from_roots()
1280 if (dir->ctrl_field) in group_from_roots()
1284 if (cg->dirs[0]) { in group_from_roots()
1285 strncpy(cg->group_name, cg->dirs[0]->dir_name, NAME_MAX); in group_from_roots()
1312 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_read()
1321 (*dir)->dir_fd, alias, out, len); in safe_cg_read()
1351 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_printf()
1358 (*dir)->dir_fd, alias, fmt, va); in safe_cg_printf()
1373 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_open()
1378 fds[i++] = safe_openat(file, lineno, (*dir)->dir_fd, alias, flags); in safe_cg_open()
1394 for_each_dir(cg, cfile->ctrl_indx, dir) { in safe_cg_fchown()
1399 safe_fchownat(file, lineno, (*dir)->dir_fd, alias, owner, group, 0); in safe_cg_fchown()