Lines 13-30
Link Here
|
13 |
RULES_FILE="/etc/cgroup/cgrules.conf" |
13 |
RULES_FILE="/etc/cgroup/cgrules.conf" |
14 |
|
14 |
|
15 |
# Support multiple mount points |
15 |
# Support multiple mount points |
16 |
MAX_INDEX=0 |
16 |
#MAX_INDEX=0 |
17 |
declare -a MOUNT_POINTS MOUNT_OPTIONS |
17 |
local MOUNT_POINTS MOUNT_OPTIONS |
18 |
|
18 |
|
19 |
move_all_to_init_class() { |
19 |
move_all_to_init_class() { |
20 |
local i |
20 |
local i |
21 |
for i in $(seq 1 ${MAX_INDEX}); do |
21 |
for i in ${MOUNT_POINTS}; do |
22 |
cd ${MOUNT_POINTS[$i]} |
22 |
cd ${i} |
23 |
|
23 |
|
24 |
if grep -qw ${MOUNT_POINTS[$i]} ${MOUNTS_FILE}; then |
24 |
if grep -qw ${i} ${MOUNTS_FILE}; then |
25 |
local directory |
25 |
local directory |
26 |
for directory in $(find . -depth -type d); do |
26 |
for directory in $(find . -depth -type d); do |
27 |
if [[ ${directory} != "." ]]; then |
27 |
if [ ${directory} != "." ]; then |
28 |
# cat fails with "Argument list too long" error |
28 |
# cat fails with "Argument list too long" error |
29 |
sed -nu p < ${directory}/tasks > tasks |
29 |
sed -nu p < ${directory}/tasks > tasks |
30 |
rmdir ${directory} |
30 |
rmdir ${directory} |
Lines 41-59
Link Here
|
41 |
parse_mounts() { |
41 |
parse_mounts() { |
42 |
local device mount_point fs_type options other |
42 |
local device mount_point fs_type options other |
43 |
while read device mount_point fs_type options other; do |
43 |
while read device mount_point fs_type options other; do |
44 |
if grep -q ${device} <<< ${CGROUP_FS}; then |
44 |
if [ "${fs_type}" = "${CGROUP_FS}" ]; then |
45 |
let MAX_INDEX++ |
45 |
#let MAX_INDEX++ |
46 |
MOUNT_POINTS[${MAX_INDEX}]=${mount_point} |
46 |
MOUNT_POINTS="${MOUNT_POINTS} ${mount_point}" |
47 |
MOUNT_OPTIONS[${MAX_INDEX}]=${options} |
47 |
MOUNT_OPTIONS="${MOUNT_OPTIONS} ${options}" |
48 |
fi |
48 |
fi |
49 |
done < ${MOUNTS_FILE} |
49 |
done < ${MOUNTS_FILE} |
50 |
} |
50 |
} |
51 |
|
51 |
|
52 |
umount_fs() { |
52 |
umount_fs() { |
53 |
local i |
53 |
local i |
54 |
for i in $(seq 1 ${MAX_INDEX}); do |
54 |
for i in ${MOUNT_POINTS}; do |
55 |
umount ${MOUNT_POINTS[$i]} |
55 |
umount ${i} |
56 |
rmdir ${MOUNT_POINTS[$i]} |
56 |
rmdir ${i} |
57 |
done |
57 |
done |
58 |
} |
58 |
} |
59 |
|
59 |
|
Lines 74-111
Link Here
|
74 |
|
74 |
|
75 |
# Find default cgroup name in rules file |
75 |
# Find default cgroup name in rules file |
76 |
local default_cgroup |
76 |
local default_cgroup |
77 |
if [[ -f ${RULES_FILE} ]]; then |
77 |
if [ -f ${RULES_FILE} ]; then |
78 |
local user controller |
78 |
local user controller |
79 |
read user controller default_cgroup <<< $(grep -m1 ^\* ${RULES_FILE}) |
79 |
read user controller default_cgroup <<E |
80 |
if [[ $default_cgroup == "*" ]]; then |
80 |
$(grep -m1 ^* ${RULES_FILE}) |
|
|
81 |
E |
82 |
if [ "$default_cgroup" = "*" ]; then |
81 |
ewarn "${RULES_FILE} incorrect" |
83 |
ewarn "${RULES_FILE} incorrect" |
82 |
ewarn "Overriding it" |
84 |
ewarn "Overriding it" |
83 |
default_cgroup= |
85 |
default_cgroup= |
84 |
fi |
86 |
fi |
85 |
fi |
87 |
fi |
86 |
# Use predefined name if none was found |
88 |
# Use predefined name if none was found |
87 |
if [[ -z ${default_cgroup} ]]; then |
89 |
if [ -z ${default_cgroup} ]; then |
88 |
default_cgroup=sysdefault |
90 |
default_cgroup=sysdefault |
89 |
fi |
91 |
fi |
90 |
|
92 |
|
91 |
# Create a default cgroup for tasks to return back to |
93 |
# Create a default cgroup for tasks to return back to |
92 |
local i |
94 |
local i |
93 |
for i in $(seq 1 ${MAX_INDEX}); do |
95 |
for i in ${MOUNT_POINTS}; do |
94 |
# Ignore if directory already exists |
96 |
# Ignore if directory already exists |
95 |
mkdir -p ${MOUNT_POINTS[$i]}/${default_cgroup} |
97 |
mkdir -p ${i}/${default_cgroup} |
96 |
find ${MOUNT_POINTS[$i]}/ -name tasks | xargs chmod a+rw |
98 |
find ${i}/ -name tasks | xargs chmod a+rw |
97 |
chmod go-w ${MOUNT_POINTS[$i]}/tasks |
99 |
chmod go-w ${i}/tasks |
98 |
|
100 |
|
99 |
# Special rule for cpusets |
101 |
# Special rule for cpusets |
100 |
if grep -qw cpuset <<< ${MOUNT_OPTIONS[$i]}; then |
102 |
if grep -qw cpuset < ${i}; then |
101 |
cat ${MOUNT_POINTS[$i]}/cpuset.cpus > ${MOUNT_POINTS[$i]}/${default_cgroup}/cpuset.cpus |
103 |
cat ${i}/cpuset.cpus > ${i}/${default_cgroup}/cpuset.cpus |
102 |
cat ${MOUNT_POINTS[$i]}/cpuset.mems > ${MOUNT_POINTS[$i]}/${default_cgroup}/cpuset.mems |
104 |
cat ${i}/cpuset.mems > ${i}/${default_cgroup}/cpuset.mems |
103 |
fi |
105 |
fi |
104 |
|
106 |
|
105 |
# Classify everything to default cgroup |
107 |
# Classify everything to default cgroup |
106 |
local j |
108 |
local j |
107 |
for j in $(ps --no-headers -eL o tid); do |
109 |
for j in $(ps --no-headers -eL o tid); do |
108 |
echo $j > ${MOUNT_POINTS[$i]}/${default_cgroup}/tasks 2>/dev/null |
110 |
echo $j > ${i}/${default_cgroup}/tasks 2>/dev/null |
109 |
done |
111 |
done |
110 |
done |
112 |
done |
111 |
|
113 |
|