Created
May 1, 2020 12:14
-
-
Save Werkov/001d1c6ce28a74c35ac9c246d592899f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wrk=$(mktemp) | |
CGROOT=/sys/fs/cgroup | |
SUBGROUP=subgroup | |
IFS=: | |
cp /proc/self/cgroup $wrk | |
while read id ctrl path ; do | |
[ "$path" = "/" ] && continue | |
[ "$ctrl" = "name=systemd" ] && ctrl=systemd | |
[ "$ctrl" = "" ] && ctrl=unified | |
case $ctrl in | |
systemd|unified|cpu,cpuacct) | |
mkdir -p $CGROOT/$ctrl/$path/$SUBGROUP | |
if echo $$ >$CGROOT/$ctrl/$path/$SUBGROUP/cgroup.procs ; then | |
echo "Migrated to $ctrl $path/$SUBGROUP" | |
else | |
echo "Failed migration to $ctrl $path/$SUBGROUP" | |
fi | |
;; | |
*) | |
echo "Skipping $ctrl" | |
;; | |
esac | |
done <$wrk | |
cat /proc/self/cgroup | |
sleep infinity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wrk=$(mktemp) | |
CGROOT=/sys/fs/cgroup | |
SUBGROUP=subgroup | |
IFS=: | |
cp /proc/self/cgroup $wrk | |
while read id ctrl path ; do | |
[ "$path" = "/" ] && continue | |
[ "$ctrl" = "name=systemd" ] && ctrl=systemd | |
[ "$ctrl" = "" ] && ctrl=unified | |
case $ctrl in | |
systemd|unified|cpu,cpuacct) | |
[ "$ctrl" = "unified" ] && ctrl="" | |
mkdir -p $CGROOT/$ctrl/$path/$SUBGROUP | |
if echo $$ >$CGROOT/$ctrl/$path/$SUBGROUP/cgroup.procs ; then | |
echo "Migrated to $ctrl $path/$SUBGROUP" | |
else | |
echo "Failed migration to $ctrl $path/$SUBGROUP" | |
fi | |
;; | |
*) | |
echo "Skipping $ctrl" | |
;; | |
esac | |
done <$wrk | |
cat /proc/self/cgroup | |
sleep infinity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RED='\033[0;31m' | |
NC='\033[0m' # No Colo | |
ASYNC=1 | |
function exp() { | |
local _exp="$1" | |
local _act="$2" | |
local rc=0 | |
if echo "$2" | grep -q "$1" ; then | |
echo -e "OK\t$1" | |
else | |
echo -e "${RED}FAIL${NC}\t$1\t$2" | |
rc=1 | |
fi | |
return $rc | |
} | |
setup_delegation() { | |
cat >/etc/systemd/system/test-delegate1.service <<EOD | |
[Service] | |
Delegate=yes | |
ExecStart=/root/sd-14917/delegated-v1 | |
EOD | |
cat >/etc/systemd/system/test-delegate2.service <<EOD | |
[Service] | |
Delegate=cpu | |
ExecStart=/root/sd-14917/delegated-v1 | |
EOD | |
systemctl daemon-reload | |
systemctl start test-delegate1.service | |
p=$(systemctl show -p MainPID test-delegate1) | |
t1=${p#MainPID=} | |
systemctl start test-delegate2.service | |
p=$(systemctl show -p MainPID test-delegate2) | |
t2=${p#MainPID=} | |
# weait for delegated migration | |
sleep 0.1 | |
} | |
# delegation per controller is expected analogous to v2 behavior | |
test_delegation() { | |
echo "### Delegation {" | |
exp "^0::/system.slice/test-delegate1.service/subgroup" $(grep "^0:" /proc/$t1/cgroup) | |
exp "^1:name=systemd:/system.slice/test-delegate1.service/subgroup" $(grep "^1:" /proc/$t1/cgroup) | |
exp ":/system.slice/test-delegate1.service/subgroup" $(grep "cpu,cpuacct" /proc/$t1/cgroup) | |
exp "^0::/system.slice/test-delegate2.service/subgroup" $(grep "^0:" /proc/$t2/cgroup) | |
exp "^1:name=systemd:/system.slice/test-delegate2.service/subgroup" $(grep "^1:" /proc/$t2/cgroup) | |
exp ":/system.slice/test-delegate2.service/subgroup" $(grep "cpu,cpuacct" /proc/$t2/cgroup) | |
echo "}" | |
} | |
echo "### Test non-root {" | |
systemd-run --scope --unit=something.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep $ASYNC | |
exp "^0::/system.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/system.slice/something.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/$" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
systemctl set-property something.scope CPUQuota=25% | |
sleep $ASYNC | |
exp "^0::/system.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/system.slice/something.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/system.slice/something.scope" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
systemctl set-property something.scope CPUQuota= | |
sleep $ASYNC | |
# wait for asynchronous cleanup | |
sleep 0.1 | |
exp "^0::/system.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/system.slice/something.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/$" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
systemctl stop something.scope | |
echo "}" | |
echo "### Test root {" | |
systemd-run --scope --slice=-.slice --unit=something2.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::/something2.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/something2.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/$" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
systemctl set-property something2.scope CPUQuota=25% | |
exp "^0::/something2.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/something2.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/something2.scope" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
systemctl set-property something2.scope CPUQuota= | |
exp "^0::/something2.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/something2.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/$" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
systemctl stop something2.scope | |
echo "}" | |
setup_delegation | |
test_delegation | |
echo "### Test non-root w/d {" | |
systemd-run --scope --unit=something3.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::/system.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/system.slice/something3.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/system.slice/something3.scope$" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
exp "^-1$" $(cat /sys/fs/cgroup/cpu,cpuacct/system.slice/something3.scope/cpu.cfs_quota_us) | |
systemctl set-property something3.scope CPUQuota=25% | |
exp "^0::/system.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/system.slice/something3.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/system.slice/something3.scope" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
systemctl set-property something3.scope CPUQuota= | |
exp "^0::/system.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/system.slice/something3.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/system.slice/something3.scope$" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
exp "^-1$" $(cat /sys/fs/cgroup/cpu,cpuacct/system.slice/something3.scope/cpu.cfs_quota_us) | |
systemctl stop something3.scope | |
echo "}" | |
test_delegation | |
echo "### Test root w/d {" | |
systemd-run --scope --slice=-.slice --unit=something4.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/something4.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/something4.scope$" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
exp "^-1$" $(cat /sys/fs/cgroup/cpu,cpuacct/something4.scope/cpu.cfs_quota_us) | |
systemctl set-property something4.scope CPUQuota=25% | |
exp "^0::/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/something4.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/something4.scope" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
systemctl set-property something4.scope CPUQuota= | |
exp "^0::/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "^1:name=systemd:/something4.scope" $(grep "^1:" /proc/$pid/cgroup) | |
exp ":/something4.scope$" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
exp "^-1$" $(cat /sys/fs/cgroup/cpu,cpuacct/something4.scope/cpu.cfs_quota_us) | |
systemctl stop something4.scope | |
echo "}" | |
test_delegation | |
systemctl stop test-delegate1 | |
systemctl stop test-delegate2 | |
echo "### Test cleanup/recreation {" | |
# This test assumes it's started from a user session scope | |
p=$(systemctl show -p MainPID sshd) | |
pid_ssh=${p#MainPID=} | |
systemctl daemon-reload | |
systemd-run -p CPUQuota=20% --unit=something5.scope --scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp ":/system.slice/something5.scope" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
exp ":/system.slice/sshd.service" $(grep "cpu,cpuacct" /proc/$pid_ssh/cgroup) | |
exp ":/init.scope" $(grep "cpu,cpuacct" /proc/1/cgroup) | |
exp ":/user.slice$" $(grep "cpu,cpuacct" /proc/self/cgroup) | |
systemctl stop something5.scope | |
sleep 0.1 | |
exp ":/$" $(grep "cpu,cpuacct" /proc/$pid_ssh/cgroup) | |
exp ":/$" $(grep "cpu,cpuacct" /proc/1/cgroup) | |
exp ":/$" $(grep "cpu,cpuacct" /proc/self/cgroup) | |
systemd-run -p CPUQuota=20% --unit=something6.scope --scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp ":/system.slice/something6.scope" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
exp ":/system.slice/sshd.service" $(grep "cpu,cpuacct" /proc/$pid_ssh/cgroup) | |
exp ":/init.scope" $(grep "cpu,cpuacct" /proc/1/cgroup) | |
exp ":/user.slice$" $(grep "cpu,cpuacct" /proc/self/cgroup) | |
systemctl stop something6.scope | |
echo "}" | |
echo "### Test cleanup/recreation 2 {" | |
systemd-run --slice=test-system.slice --unit=background1.scope --scope /usr/bin/sleep infinity & | |
pid_bg1=$! | |
systemd-run --slice=test.slice --unit=background2.scope --scope /usr/bin/sleep infinity & | |
pid_bg2=$! | |
systemctl set-property test.slice CPUQuota=100% | |
systemctl daemon-reload | |
systemd-run -p CPUQuota=20% --slice=test-system.slice --unit=something5.scope --scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp ":/test.slice/test-system.slice/something5.scope" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
exp ":/test.slice/test-system.slice/background1.scope" $(grep "cpu,cpuacct" /proc/$pid_bg1/cgroup) | |
exp ":/test.slice/background2.scope" $(grep "cpu,cpuacct" /proc/$pid_bg2/cgroup) | |
systemctl stop something5.scope | |
sleep 0.1 | |
exp ":/test.slice$" $(grep "cpu,cpuacct" /proc/$pid_bg1/cgroup) | |
exp ":/test.slice$" $(grep "cpu,cpuacct" /proc/$pid_bg2/cgroup) | |
systemd-run -p CPUQuota=20% --slice=test-system.slice --unit=something6.scope --scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp ":/test.slice/test-system.slice/something6.scope" $(grep "cpu,cpuacct" /proc/$pid/cgroup) | |
exp ":/test.slice/test-system.slice/background1.scope" $(grep "cpu,cpuacct" /proc/$pid_bg1/cgroup) | |
exp ":/test.slice/background2.scope" $(grep "cpu,cpuacct" /proc/$pid_bg2/cgroup) | |
systemctl stop something6.scope | |
systemctl stop background2.scope | |
systemctl stop background1.scope | |
systemctl stop test-system.slice | |
systemctl stop test.slice | |
echo "}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RED='\033[0;31m' | |
NC='\033[0m' # No Colo | |
ASYNCTEST=0.1 | |
CGBASE=/user.slice/user-$UID.slice/user@$UID.service | |
function exp() { | |
local _exp="$1" | |
local _act="$2" | |
local rc=0 | |
if echo "$2" | grep -q "$1" ; then | |
echo -e "OK\t$1" | |
else | |
echo -e "${RED}FAIL${NC}\t$1\t$2 (exp act)" | |
rc=1 | |
fi | |
return $rc | |
} | |
setup_delegation() { | |
mkdir -p $HOME/.config/systemd/user | |
cat >$HOME/.config/systemd/user/test-delegate1.service <<EOD | |
[Service] | |
Delegate=yes | |
ExecStart=/root/sd-14917/delegated-v2 | |
EOD | |
cat >$HOME/.config/systemd/user/test-delegate2.service <<EOD | |
[Service] | |
Delegate=cpu | |
ExecStart=/root/sd-14917/delegated-v2 | |
EOD | |
systemctl --user daemon-reload | |
systemctl --user start test-delegate1.service | |
p=$(systemctl --user show -p MainPID test-delegate1) | |
t1=${p#MainPID=} | |
systemctl --user start test-delegate2.service | |
p=$(systemctl --user show -p MainPID test-delegate2) | |
t2=${p#MainPID=} | |
# weait for delegated migration | |
sleep 0.1 | |
} | |
# delegation per controller is expected analogous to v2 behavior | |
test_delegation() { | |
echo "### Delegation {" | |
exp "^0::$CGBASE/test-delegate1.service/subgroup" $(grep "^0:" /proc/$t1/cgroup) | |
exp "cpu\b" "$(cat /sys/fs/cgroup/$CGBASE/test-delegate1.service/cgroup.controllers)" | |
exp "^0::$CGBASE/test-delegate2.service/subgroup" $(grep "^0:" /proc/$t2/cgroup) | |
exp "cpu\b" "$(cat /sys/fs/cgroup/$CGBASE/test-delegate2.service/cgroup.controllers)" | |
echo "}" | |
} | |
echo "### Test non-root {" | |
systemd-run --user --scope --slice=parent.slice --unit=something.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::$CGBASE/parent.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/parent.slice/something.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/parent.slice/something.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user set-property something.scope CPUQuota=25% | |
exp "^0::$CGBASE/parent.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$(cat /sys/fs/cgroup$CGBASE/parent.slice/something.scope/cpu.max)" | |
systemctl --user set-property something.scope CPUQuota= | |
sleep $ASYNCTEST | |
exp "^0::$CGBASE/parent.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/parent.slice/something.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/parent.slice/something.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user stop something.scope | |
systemctl --user stop parent.slice | |
echo "}" | |
echo "### Test root (implicit) {" | |
systemd-run --user --scope --unit=something2a.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::$CGBASE/something2a.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/something2a.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something2a.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user set-property something2a.scope CPUQuota=25% | |
sleep $ASYNCTEST | |
exp "^0::$CGBASE/something2a.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$([ -f /sys/fs/cgroup$CGBASE/something2a.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something2a.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user set-property something2a.scope CPUQuota= | |
exp "^0::$CGBASE/something2a.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/something2a.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something2a.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user stop something2a.scope | |
echo "}" | |
echo "### Test root {" | |
systemd-run --user --scope --slice=-.slice --unit=something2b.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::$CGBASE/something2b.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/something2b.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something2b.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user set-property something2b.scope CPUQuota=25% | |
sleep $ASYNCTEST | |
exp "^0::$CGBASE/something2b.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$([ -f /sys/fs/cgroup$CGBASE/something2b.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something2b.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user set-property something2b.scope CPUQuota= | |
exp "^0::$CGBASE/something2b.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/something2b.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something2b.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user stop something2b.scope | |
echo "}" | |
setup_delegation | |
test_delegation | |
echo "### Test non-root w/d {" | |
systemd-run --user --scope --slice=parent.slice --unit=something3.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::$CGBASE/parent.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/parent.slice/something3.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/parent.slice/something3.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user set-property something3.scope CPUQuota=25% | |
exp "^0::$CGBASE/parent.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$(cat /sys/fs/cgroup$CGBASE/parent.slice/something3.scope/cpu.max)" | |
systemctl --user set-property something3.scope CPUQuota= | |
sleep $ASYNCTEST | |
exp "^0::$CGBASE/parent.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/parent.slice/something3.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/parent.slice/something3.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user stop something3.scope | |
systemctl --user stop parent.slice | |
echo "}" | |
test_delegation | |
echo "### Test root w/d{" | |
#systemd-run --user --scope --slice=-.slice --unit=something4.scope /usr/bin/sleep infinity & | |
systemd-run --user --scope --unit=something4.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::$CGBASE/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/something4.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something4.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user set-property something4.scope CPUQuota=25% | |
exp "^0::$CGBASE/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$([ -f /sys/fs/cgroup$CGBASE/something4.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something4.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user set-property something4.scope CPUQuota= | |
exp "^0::$CGBASE/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup$CGBASE/something4.scope/cpu.max ] && cat /sys/fs/cgroup$CGBASE/something4.scope/cpu.max || echo \"max 100000\")" | |
systemctl --user stop something4.scope | |
echo "}" | |
test_delegation | |
systemctl --user stop test-delegate1 | |
systemctl --user stop test-delegate2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RED='\033[0;31m' | |
NC='\033[0m' # No Colo | |
ASYNC=0.1 | |
function exp() { | |
local _exp="$1" | |
local _act="$2" | |
local rc=0 | |
if echo "$2" | grep -q "$1" ; then | |
echo -e "OK\t$1" | |
else | |
echo -e "${RED}FAIL${NC}\t$1\t$2" | |
rc=1 | |
fi | |
return $rc | |
} | |
setup_delegation() { | |
cat >/etc/systemd/system/test-delegate1.service <<EOD | |
[Service] | |
Delegate=yes | |
ExecStart=/root/sd-14917/delegated-v2 | |
EOD | |
cat >/etc/systemd/system/test-delegate2.service <<EOD | |
[Service] | |
Delegate=cpu | |
ExecStart=/root/sd-14917/delegated-v2 | |
EOD | |
systemctl daemon-reload | |
systemctl start test-delegate1.service | |
p=$(systemctl show -p MainPID test-delegate1) | |
t1=${p#MainPID=} | |
systemctl start test-delegate2.service | |
p=$(systemctl show -p MainPID test-delegate2) | |
t2=${p#MainPID=} | |
# weait for delegated migration | |
sleep 0.1 | |
} | |
# delegation per controller is expected analogous to v2 behavior | |
test_delegation() { | |
echo "### Delegation {" | |
exp "^0::/system.slice/test-delegate1.service/subgroup" $(grep "^0:" /proc/$t1/cgroup) | |
exp "cpu\b" "$(cat /sys/fs/cgroup/system.slice/test-delegate1.service/cgroup.controllers)" | |
exp "^0::/system.slice/test-delegate2.service/subgroup" $(grep "^0:" /proc/$t2/cgroup) | |
exp "cpu\b" "$(cat /sys/fs/cgroup/system.slice/test-delegate2.service/cgroup.controllers)" | |
echo "}" | |
} | |
echo "### Test non-root {" | |
systemd-run --scope --unit=something.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::/system.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup/system.slice/something.scope/cpu.max ] && cat /sys/fs/cgroup/system.slice/something.scope/cpu.max || echo \"max 100000\")" | |
systemctl set-property something.scope CPUQuota=25% | |
exp "^0::/system.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$(cat /sys/fs/cgroup/system.slice/something.scope/cpu.max)" | |
systemctl set-property something.scope CPUQuota= | |
sleep $ASYNC | |
exp "^0::/system.slice/something.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup/system.slice/something.scope/cpu.max ] && cat /sys/fs/cgroup/system.slice/something.scope/cpu.max || echo \"max 100000\")" | |
systemctl stop something.scope | |
echo "}" | |
echo "### Test root {" | |
systemd-run --scope --slice=-.slice --unit=something2.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::/something2.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup/something2.scope/cpu.max ] && cat /sys/fs/cgroup/something2.scope/cpu.max || echo \"max 100000\")" | |
systemctl set-property something2.scope CPUQuota=25% | |
exp "^0::/something2.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$([ -f /sys/fs/cgroup/something2.scope/cpu.max ] && cat /sys/fs/cgroup/something2.scope/cpu.max || echo \"max 100000\")" | |
systemctl set-property something2.scope CPUQuota= | |
exp "^0::/something2.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup/something2.scope/cpu.max ] && cat /sys/fs/cgroup/something2.scope/cpu.max || echo \"max 100000\")" | |
systemctl stop something2.scope | |
echo "}" | |
setup_delegation | |
test_delegation | |
echo "### Test non-root w/d {" | |
systemd-run --scope --unit=something3.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::/system.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup/system.slice/something3.scope/cpu.max ] && cat /sys/fs/cgroup/system.slice/something3.scope/cpu.max || echo \"max 100000\")" | |
systemctl set-property something3.scope CPUQuota=25% | |
exp "^0::/system.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$(cat /sys/fs/cgroup/system.slice/something3.scope/cpu.max)" | |
systemctl set-property something3.scope CPUQuota= | |
exp "^0::/system.slice/something3.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup/system.slice/something3.scope/cpu.max ] && cat /sys/fs/cgroup/system.slice/something3.scope/cpu.max || echo \"max 100000\")" | |
systemctl stop something3.scope | |
echo "}" | |
test_delegation | |
echo "### Test root w/d{" | |
systemd-run --scope --slice=-.slice --unit=something4.scope /usr/bin/sleep infinity & | |
pid=$! | |
sleep 0.1 | |
exp "^0::/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup/something4.scope/cpu.max ] && cat /sys/fs/cgroup/something4.scope/cpu.max || echo \"max 100000\")" | |
systemctl set-property something4.scope CPUQuota=25% | |
exp "^0::/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "25000 100000" "$([ -f /sys/fs/cgroup/something4.scope/cpu.max ] && cat /sys/fs/cgroup/something4.scope/cpu.max || echo \"max 100000\")" | |
systemctl set-property something4.scope CPUQuota= | |
exp "^0::/something4.scope" $(grep "^0:" /proc/$pid/cgroup) | |
exp "max 100000" "$([ -f /sys/fs/cgroup/something4.scope/cpu.max ] && cat /sys/fs/cgroup/something4.scope/cpu.max || echo \"max 100000\")" | |
systemctl stop something4.scope | |
echo "}" | |
test_delegation | |
systemctl stop test-delegate1 | |
systemctl stop test-delegate2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment