]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/cpusets
22ea4d6c7393194bf8f69c0f3a40251e673315d5
[projects/rc-scripts.git] / rc.d / init.d / cpusets
1 #!/bin/sh
2 #
3 # cpusets       Create/remove cpusets
4 #
5 # chkconfig:    12345 01 99
6 # description:  Creates/Removes all cpu sets configured to \
7 #               start at boot time.
8 #
9 # probe:        true
10
11 # $Id$
12
13 . /etc/sysconfig/system
14
15 if [ "${CPUSETS:-no}" = "no" ]; then
16         case "$1" in
17         start|stop|restart)
18                 exit 0
19                 ;;
20         esac
21 fi
22
23 # Source function library.
24 . /etc/rc.d/init.d/functions
25
26 CGDIR=
27 CSUBSYS=
28 if grep -q "/dev/cgroup" /proc/mounts ; then
29         CGDIR="/dev/cgroup"
30 elif grep -q "/dev/cpuset" /proc/mounts ; then
31         CGDIR="/dev/cpuset"
32 fi
33
34 if [ -n "${CGDIR}" ]; then
35         if [ -e ${CGDIR}/cpuset.cpus ]; then
36                 CSUBSYS="cpuset."
37         elif [ ! -e ${CGDIR}/cpus ]; then
38                 nls "ERROR: CGROUP/CPUSET mounted in a way I can't recognize" >&2
39                 exit 1
40         fi
41 fi
42
43 cpuset_mount() {
44         [ -n "${CGDIR}" ] && return
45
46         if grep -q cgroup /proc/filesystems 2>/dev/null ; then
47                 mkdir -p /dev/cpuset 2>/dev/null
48                 mount -t cgroup none /dev/cpuset -ocpuset
49                 CSUBSYS="cpuset."
50         elif grep -q cpuset /proc/filesystems 2>/dev/null ; then
51                 mkdir -p /dev/cpuset 2>/dev/null
52                 mount -t cpuset none /dev/cpuset
53                 CSUBSYS=""
54         else
55                 nls "ERROR: CGROUP/CPUSET support not enabled in kernel" >&2
56                 exit 1
57         fi
58         CGDIR="/dev/cpuset"
59 }
60
61 cpuset_create() {
62         local CPUS MEMS CPU_EXCLUSIVE MEM_EXCLUSIVE NOTIFY_ON_RELEASE TASKS
63
64         . /etc/sysconfig/cpusets/cpuset-$i
65
66         if mkdir "${CGDIR}/${NAME}" >/dev/null 2>&1 ; then
67                 [ -n "$CPUS" ] && echo "$CPUS" >"${CGDIR}/${NAME}/${CSUBSYS}cpus"
68                 [ -n "$MEMS" ] && echo "$MEMS" >"${CGDIR}/${NAME}/${CSUBSYS}mems"
69                 [ -n "$CPU_EXCLUSIVE" ] && echo "$CPU_EXCLUSIVE" >"${CGDIR}/${NAME}/${CSUBSYS}cpu_exclusive"
70                 [ -n "$MEM_EXCLUSIVE" ] && echo "$MEM_EXCLUSIVE" >"${CGDIR}/${NAME}/${CSUBSYS}mem_exclusive"
71                 [ -n "$VIRTUALIZE" ] && echo "$VIRTUALIZE" >"${CGDIR}/${NAME}/${CSUBSYS}virtualize"
72                 [ -n "$NOTIFY_ON_RELEASE" ] && echo "$NOTIFY_ON_RELEASE" >"${CGDIR}/${NAME}/${CSUBSYS}notify_on_release"
73                 [ -n "$TASKS" ] && echo "$TASKS" >"${CGDIR}/${NAME}/tasks"
74                 return 0
75         fi
76         return 1
77 }
78
79 cpuset_remove() {
80         local CPUS MEMS CPU_EXCLUSIVE MEM_EXCLUSIVE NOTIFY_ON_RELEASE TASKS
81
82         . /etc/sysconfig/cpusets/cpuset-$i
83
84         # This MUST be rmdir (not rm -rf)
85         if rmdir "${CGDIR}/${NAME}" >/dev/null 2>&1 ; then
86                 return 0
87         else
88                 return 1
89         fi
90 }
91
92 cpuset_empty() {
93         if [ $(cat "${CGDIR}/$1/tasks" 2>/dev/null | wc -c) -eq 0 ] ; then
94                 # true returns zero
95                 return 0
96         else
97                 # false returns one
98                 return 1
99         fi
100 }
101
102 start() {
103         rc_splash "bootcpusets start"
104
105         for i in $cpusets_boot; do
106                 show "$(nls -n "Creating cpuset %s" "$i")"
107                 if cpuset_create $i ; then
108                         ok
109                 else
110                         fail
111                 fi
112         done
113
114         touch /var/lock/subsys/cpusets
115 }
116
117 stop() {
118         for i in $cpusets_boot; do
119                 show "$(nls -n "Removing cpuset %s" "$i")"
120                 busy
121                 if cpuset_empty $i; then
122                         if cpuset_remove $i; then
123                                 ok
124                         else
125                                 fail
126                         fi
127                 else
128                         fail
129                 fi
130         done
131
132         rm -f /var/lock/subsys/cpusets >/dev/null 2>&1
133 }
134
135 # Get list of config files
136 # ignores editor backup files and rpm blackups
137 cpuset_configs() {
138         local match="$1"
139         for a in /etc/sysconfig/cpusets/$match; do
140                 case "$a" in
141                 *rpmorig|*rpmnew|*rpmsave|*~|*.orig)
142                         continue
143                         ;;
144                 *)
145                         echo $a
146                 ;;
147                 esac
148         done
149 }
150
151 cpuset_files="$(cpuset_configs 'cpuset-*')"
152 cpusets_boot=$(
153         for i in $cpuset_files; do
154                 ONBOOT=""; . "$i" 2>/dev/null
155                 is_yes "$ONBOOT" && echo "${i##*/cpuset-}"
156         done
157 )
158
159 # See how we were called.
160 case "$1" in
161   start)
162         cpuset_mount
163         start
164         ;;
165   stop)
166         stop
167         ;;
168   status)
169         nls "Configured cpusets:"
170         echo "$cpusets_boot"
171         echo
172         nls "Currently empty cpusets:"
173         for i in $(ls /dev/cpuset 2>/dev/null); do
174                 if [ -d ${CGDIR}/$i ]; then
175                         cpuset_empty $i && echo $i
176                 fi
177         done
178         echo
179         nls "Currently active cpusets:"
180         for i in $(ls /dev/cpuset 2>/dev/null); do
181                 if [ -d ${CGDIR}/$i ]; then
182                         cpuset_empty $i || echo $i
183                 fi
184         done
185         echo
186         ;;
187   restart)
188         stop
189         cpuset_mount
190         start
191         ;;
192   *)
193         msg_usage "$0 {start|stop|restart|status}"
194         exit 3
195 esac
196
197 exit 0
This page took 0.042191 seconds and 3 git commands to generate.