1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
diff -Nurp util-vserver-0.30.210.orig/scripts/vserver.functions util-vserver-0.30.210.cpuset/scripts/vserver.functions
--- util-vserver-0.30.210.orig/scripts/vserver.functions 2006-01-22 13:24:25.000000000 +0100
+++ util-vserver-0.30.210.cpuset/scripts/vserver.functions 2006-04-13 01:36:34.000000000 +0200
@@ -690,6 +690,54 @@ function generateOptions
fi
}
+function addtoCPUSET
+{
+ local vdir=$1
+ local cpuset
+ local f="$vdir"/cpuset
+ local i
+ local configured=0
+
+ test -d "$f" || return 0
+ test -e "$f"/name || return 0
+
+ read cpuset < "$f"/name
+ test -e "$f"/nocreate || {
+ test -d /dev/cpuset/"$cpuset" || mkdir /dev/cpuset/"$cpuset" || configured=1
+ for i in cpus mems cpu_exclusive mem_exclusive virtualize; do
+ if test -e "$f"/"$i"; then
+ cat "$f"/"$i" >/dev/cpuset/"$cpuset"/"$i" 2>/dev/null || {
+ configured=1
+ break
+ }
+ fi
+ done
+ }
+
+ echo $$ >/dev/cpuset/"$cpuset"/tasks || configured=1
+ if [ "$configured" -ne 0 ]; then
+ warning $"\
+WARNING: Failed to create or CPUSET \"$cpuset\" does not exist! Not using it!" >&2
+ rmdir /dev/cpuset/"$cpuset" 2>/dev/null || :
+ return 0
+ fi
+}
+
+function removeCPUSET
+{
+ local vdir=$1
+ local cpuset
+ local f="$vdir"/cpuset
+
+ test -d "$f" || return 0
+ test -e "$f"/name || return 0
+
+ read cpuset < "$f"/name
+ test -e "$f"/nocreate || {
+ rmdir /dev/cpuset/"$cpuset" 2>/dev/null || :
+ }
+}
+
function _mountVserverInternal
{
local fstab="$1"
diff -Nurp util-vserver-0.30.210.orig/scripts/vserver-setup.functions util-vserver-0.30.210.cpuset/scripts/vserver-setup.functions
--- util-vserver-0.30.210.orig/scripts/vserver-setup.functions 2006-01-03 00:50:21.000000000 +0100
+++ util-vserver-0.30.210.cpuset/scripts/vserver-setup.functions 2006-04-13 01:39:08.000000000 +0200
@@ -24,11 +24,15 @@ SETUP_LOCKFILE=
SETUP_CONFDIR=
SETUP_CONTEXT=
SETUP_INITSTYLE=
+SETUP_CPUSET=
+SETUP_CPUSETCPUS=
+SETUP_CPUSETMEMS=
+SETUP_CPUSETVIRT=
declare -a SETUP_INTERFACES=()
declare -a SETUP_FLAGS=()
-declare -r SETUP_OPTIONS="confdir:,lockfile:,hostname:,netdev:,netmask:,netprefix:,netbcast:,interface:,flags:,context:,initstyle:"
+declare -r SETUP_OPTIONS="confdir:,lockfile:,hostname:,netdev:,netmask:,netprefix:,netbcast:,interface:,flags:,context:,initstyle:,cpuset:,cpusetcpus:,cpusetmems:,cpusetvirt"
declare -r SETUP_HELPMSG=$"
--context ... the static context of the vserver [default: none; a dynamic
context will be assumed]
@@ -55,6 +59,19 @@ declare -r SETUP_HELPMSG=$"
this becomes a per vserver limit)
private: No other process can join this security context.
Even root
+ --cpuset <name>
+ ... declares the CPUSET this vserver will run in [default: none]
+ --cpusetcpus <number[-number][:<exclusive>]>
+ ... sets which cpus belong to the CPUSET,
+ exclusive is a flag (0|1) prohibiting any other cpuset from
+ using those cpus
+ --cpusetmems <number[-number][:<exclusive>]>
+ ... sets which memory pools belong to the CPUSET,
+ exclusive is a flag (0|1) prohibiting any other cpuset from
+ using those memory pools
+ --cpusetvirt
+ ... virtualize cpuset (guest will see only CPUs defined in cpuset)
+ Requires kernel patch from http://www.bullopensource.org/cpuset/
--initstyle <style>
... configures the initstyle (e.g. minit,sysv,plain)
"
@@ -71,7 +88,23 @@ function setup_setOption2
(--netprefix) SETUP_NETPREFIX=$2;;
(--netbcast) SETUP_NETBCAST=$2;;
(--interface) SETUP_INTERFACES=( "${SETUP_INTERFACES[@]}" "$2" );;
- (--initstyle) SETUP_INITSTYLE=$2;;
+ (--initstyle) SETUP_INITSTYLE=$2;;
+ (--cpuset) SETUP_CPUSET=$2;;
+ (--cpusetcpus) old_IFS=$IFS
+ IFS=:
+ set -- $2
+ SETUP_CPUSETCPUS=$1
+ SETUP_CPUSETCPUSEXCL=$2
+ IFS=$old_IFS
+ ;;
+ (--cpusetmems) old_IFS=$IFS
+ IFS=:
+ set -- $2
+ SETUP_CPUSETMEMS=$1
+ SETUP_CPUSETMEMSEXCL=$2
+ IFS=$old_IFS
+ ;;
+ (--cpusetvirt) SETUP_CPUSETVIRT=1;;
(--flags) old_IFS=$IFS
IFS=,
set -- $2
@@ -140,7 +173,7 @@ function setup_writeOption
local cfgdir=${SETUP_CONFDIR:?}
local i
- mkdir -p "$cfgdir"/interfaces "$cfgdir"/apps/init "$cfgdir"/uts
+ mkdir -p "$cfgdir"/interfaces "$cfgdir"/apps/init "$cfgdir"/uts "$cfgdir"/cpuset
_setup_writeSingleOption "$name" "$cfgdir"/name
_setup_writeSingleOption "$SETUP_CONTEXT" "$cfgdir"/context
@@ -150,6 +183,12 @@ function setup_writeOption
_setup_writeSingleOption "$SETUP_NETPREFIX" "$cfgdir"/interfaces/prefix
_setup_writeSingleOption "$SETUP_NETBCAST" "$cfgdir"/interfaces/bcast
_setup_writeSingleOption "$SETUP_INITSTYLE" "$cfgdir"/apps/init/style
+ _setup_writeSingleOption "$SETUP_CPUSET" "$cfgdir"/cpuset/name
+ _setup_writeSingleOption "$SETUP_CPUSETCPUS" "$cfgdir"/cpuset/cpus
+ _setup_writeSingleOption "$SETUP_CPUSETCPUSEXCL" "$cfgdir"/cpuset/cpus_exclusive
+ _setup_writeSingleOption "$SETUP_CPUSETMEMS" "$cfgdir"/cpuset/mems
+ _setup_writeSingleOption "$SETUP_CPUSETMEMSEXCL" "$cfgdir"/cpuset/mem_exclusive
+ _setup_writeSingleOption "$SETUP_CPUSETVIRT" "$cfgdir"/cpuset/virtualize
local idx=0
for i in "${SETUP_INTERFACES[@]}"; do
diff -Nurp util-vserver-0.30.210.orig/scripts/vserver.start util-vserver-0.30.210.cpuset/scripts/vserver.start
--- util-vserver-0.30.210.orig/scripts/vserver.start 2006-01-22 13:24:25.000000000 +0100
+++ util-vserver-0.30.210.cpuset/scripts/vserver.start 2006-04-13 01:36:34.000000000 +0200
@@ -113,6 +113,7 @@ enableInterfaces "$VSERVER_DIR" && have_
mountVserver "$VSERVER_DIR" && is_mounted=1
prepareInit "$VSERVER_DIR"
+addtoCPUSET "$VSERVER_DIR"
pushd "$VSERVER_DIR"/vdir/ >/dev/null
execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" pre-start
diff -Nurp util-vserver-0.30.210.orig/scripts/vserver.stop util-vserver-0.30.210.cpuset/scripts/vserver.stop
--- util-vserver-0.30.210.orig/scripts/vserver.stop 2006-01-21 14:22:23.000000000 +0100
+++ util-vserver-0.30.210.cpuset/scripts/vserver.stop 2006-04-13 01:36:34.000000000 +0200
@@ -101,3 +101,4 @@ disableInterfaces "$VSERVER_DIR"
saveDiskLimits "$VSERVER_DIR"
execScriptlets "$VSERVER_DIR" "$VSERVER_NAME" postpost-stop
+removeCPUSET "$VSERVER_DIR"
diff -Nurp util-vserver-0.30.210.orig/scripts/vserver.suexec util-vserver-0.30.210.cpuset/scripts/vserver.suexec
--- util-vserver-0.30.210.orig/scripts/vserver.suexec 2005-07-15 21:01:06.000000000 +0200
+++ util-vserver-0.30.210.cpuset/scripts/vserver.suexec 2006-04-13 01:36:34.000000000 +0200
@@ -22,6 +22,7 @@ test -z "$is_stopped" -o "$OPTION_INSECU
exit 1
}
generateOptions "$VSERVER_DIR"
+addtoCPUSET "$VSERVER_DIR"
user=$1
shift
|