mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
Merge pull request #34408 from Werkov/fix-device-limits
core/cgroup: Apply IODevice*= directives in configured order
This commit is contained in:
commit
51e905b9fa
@ -1424,7 +1424,7 @@ int bus_cgroup_set_property(
|
||||
for (type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++)
|
||||
a->limits[type] = cgroup_io_limit_defaults[type];
|
||||
|
||||
LIST_PREPEND(device_limits, c->io_device_limits, a);
|
||||
LIST_APPEND(device_limits, c->io_device_limits, a);
|
||||
}
|
||||
|
||||
a->limits[iol_type] = u64;
|
||||
@ -1504,7 +1504,7 @@ int bus_cgroup_set_property(
|
||||
free(a);
|
||||
return -ENOMEM;
|
||||
}
|
||||
LIST_PREPEND(device_weights, c->io_device_weights, a);
|
||||
LIST_APPEND(device_weights, c->io_device_weights, a);
|
||||
}
|
||||
|
||||
a->weight = weight;
|
||||
@ -1578,7 +1578,7 @@ int bus_cgroup_set_property(
|
||||
free(a);
|
||||
return -ENOMEM;
|
||||
}
|
||||
LIST_PREPEND(device_latencies, c->io_device_latencies, a);
|
||||
LIST_APPEND(device_latencies, c->io_device_latencies, a);
|
||||
}
|
||||
|
||||
a->target_usec = target;
|
||||
@ -1659,7 +1659,7 @@ int bus_cgroup_set_property(
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, a);
|
||||
LIST_APPEND(device_bandwidths, c->blockio_device_bandwidths, a);
|
||||
}
|
||||
|
||||
if (read)
|
||||
@ -1753,7 +1753,7 @@ int bus_cgroup_set_property(
|
||||
free(a);
|
||||
return -ENOMEM;
|
||||
}
|
||||
LIST_PREPEND(device_weights, c->blockio_device_weights, a);
|
||||
LIST_APPEND(device_weights, c->blockio_device_weights, a);
|
||||
}
|
||||
|
||||
a->weight = weight;
|
||||
|
@ -4257,7 +4257,7 @@ int config_parse_io_device_weight(
|
||||
w->path = TAKE_PTR(resolved);
|
||||
w->weight = u;
|
||||
|
||||
LIST_PREPEND(device_weights, c->io_device_weights, w);
|
||||
LIST_APPEND(device_weights, c->io_device_weights, w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -4328,7 +4328,7 @@ int config_parse_io_device_latency(
|
||||
l->path = TAKE_PTR(resolved);
|
||||
l->target_usec = usec;
|
||||
|
||||
LIST_PREPEND(device_latencies, c->io_device_latencies, l);
|
||||
LIST_APPEND(device_latencies, c->io_device_latencies, l);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -4414,7 +4414,7 @@ int config_parse_io_limit(
|
||||
for (CGroupIOLimitType i = 0; i < _CGROUP_IO_LIMIT_TYPE_MAX; i++)
|
||||
l->limits[i] = cgroup_io_limit_defaults[i];
|
||||
|
||||
LIST_PREPEND(device_limits, c->io_device_limits, l);
|
||||
LIST_APPEND(device_limits, c->io_device_limits, l);
|
||||
}
|
||||
|
||||
l->limits[type] = num;
|
||||
@ -4495,7 +4495,7 @@ int config_parse_blockio_device_weight(
|
||||
w->path = TAKE_PTR(resolved);
|
||||
w->weight = u;
|
||||
|
||||
LIST_PREPEND(device_weights, c->blockio_device_weights, w);
|
||||
LIST_APPEND(device_weights, c->blockio_device_weights, w);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -4582,7 +4582,7 @@ int config_parse_blockio_bandwidth(
|
||||
b->rbps = CGROUP_LIMIT_MAX;
|
||||
b->wbps = CGROUP_LIMIT_MAX;
|
||||
|
||||
LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, b);
|
||||
LIST_APPEND(device_bandwidths, c->blockio_device_bandwidths, b);
|
||||
}
|
||||
|
||||
if (read)
|
||||
|
65
test/units/TEST-19-CGROUP.keyed-properties.sh
Executable file
65
test/units/TEST-19-CGROUP.keyed-properties.sh
Executable file
@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
set -ex
|
||||
set -o pipefail
|
||||
|
||||
# shellcheck source=test/units/test-control.sh
|
||||
. "$(dirname "$0")"/test-control.sh
|
||||
# shellcheck source=test/units/util.sh
|
||||
. "$(dirname "$0")"/util.sh
|
||||
|
||||
if [[ "$(get_cgroup_hierarchy)" != unified ]]; then
|
||||
echo "Skipping $0 as we're not running with the unified cgroup hierarchy"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
testcase_iodevice_dbus () {
|
||||
# Test that per-device properties are applied in configured order even for different devices (because
|
||||
# they may resolve to same underlying device in the end
|
||||
# Note: if device does not exist cgroup attribute write fails but systemd should still track the
|
||||
# configured properties
|
||||
systemd-run --unit=test0.service \
|
||||
--property="IOAccounting=yes" \
|
||||
sleep inf
|
||||
|
||||
systemctl set-property test0.service \
|
||||
IOReadBandwidthMax="/dev/sda1 1M" \
|
||||
IOReadBandwidthMax="/dev/sda2 2M" \
|
||||
IOReadBandwidthMax="/dev/sda3 4M"
|
||||
|
||||
local output
|
||||
output=$(mktemp)
|
||||
trap 'rm -f "$output"' RETURN
|
||||
systemctl show -P IOReadBandwidthMax test0.service >"$output"
|
||||
diff -u "$output" - <<EOF
|
||||
/dev/sda1 1000000
|
||||
/dev/sda2 2000000
|
||||
/dev/sda3 4000000
|
||||
EOF
|
||||
|
||||
systemctl stop test0.service
|
||||
}
|
||||
|
||||
testcase_iodevice_unitfile () {
|
||||
cat >/run/systemd/system/test1.service <<EOF
|
||||
[Service]
|
||||
ExecStart=/usr/bin/sleep inf
|
||||
IOReadBandwidthMax=/dev/sda1 1M
|
||||
IOReadBandwidthMax=/dev/sda2 2M
|
||||
IOReadBandwidthMax=/dev/sda3 4M
|
||||
EOF
|
||||
systemctl daemon-reload
|
||||
|
||||
local output
|
||||
output=$(mktemp)
|
||||
trap 'rm -f "$output"' RETURN
|
||||
systemctl show -P IOReadBandwidthMax test1.service >"$output"
|
||||
diff -u "$output" - <<EOF
|
||||
/dev/sda1 1000000
|
||||
/dev/sda2 2000000
|
||||
/dev/sda3 4000000
|
||||
EOF
|
||||
rm -f /run/systemd/system/test1.service
|
||||
}
|
||||
|
||||
run_testcases
|
Loading…
x
Reference in New Issue
Block a user