dbus-cgroup.c revision e7ab4d1ac9f8d99eecd5e2d22eb482a1fb0fbf23
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen This file is part of systemd.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen Copyright 2013 Lennart Poettering
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen systemd is free software; you can redistribute it and/or modify it
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen under the terms of the GNU Lesser General Public License as published by
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen (at your option) any later version.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen systemd is distributed in the hope that it will be useful, but
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen Lesser General Public License for more details.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen You should have received a copy of the GNU Lesser General Public License
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersenstatic BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen r = sd_bus_message_open_container(reply, 'a', "(st)");
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen LIST_FOREACH(device_weights, w, c->blockio_device_weights) {
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen r = sd_bus_message_append(reply, "(st)", w->path, w->weight);
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek return sd_bus_message_close_container(reply);
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmekstatic int property_get_blockio_device_bandwidths(
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen r = sd_bus_message_open_container(reply, 'a', "(st)");
977085794d2996320e345433403de75f662b0622Tom Gundersen LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) {
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen if (streq(property, "BlockIOReadBandwidth") != b->read)
5b9d4dc05560ddda89e48b6b39365824b15e1300Tom Gundersen r = sd_bus_message_append(reply, "(st)", b->path, b->bandwidth);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen r = sd_bus_message_open_container(reply, 'a', "(ss)");
03e334a1c7dc8c20c38902aa039440763acc9b17Lennart Poettering LIST_FOREACH(device_allow, a, c->device_allow) {
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen unsigned k = 0;
6e37cd2f4af8928d905203108a4331e375d7127cThomas Hindoe Paaboel Andersen r = sd_bus_message_append(reply, "(ss)", a->path, rwm);
187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6Thomas Hindoe Paaboel Andersen return sd_bus_message_close_container(reply);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen SD_BUS_PROPERTY("Delegate", "b", bus_property_get_bool, offsetof(CGroupContext, delegate), 0),
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpu_accounting), 0),
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen SD_BUS_PROPERTY("CPUShares", "t", NULL, offsetof(CGroupContext, cpu_shares), 0),
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen SD_BUS_PROPERTY("StartupCPUShares", "t", NULL, offsetof(CGroupContext, startup_cpu_shares), 0),
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_per_sec_usec), 0),
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("BlockIOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, blockio_accounting), 0),
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("BlockIOWeight", "t", NULL, offsetof(CGroupContext, blockio_weight), 0),
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("StartupBlockIOWeight", "t", NULL, offsetof(CGroupContext, startup_blockio_weight), 0),
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("BlockIODeviceWeight", "a(st)", property_get_blockio_device_weight, 0, 0),
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen SD_BUS_PROPERTY("BlockIOReadBandwidth", "a(st)", property_get_blockio_device_bandwidths, 0, 0),
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("BlockIOWriteBandwidth", "a(st)", property_get_blockio_device_bandwidths, 0, 0),
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek SD_BUS_PROPERTY("MemoryAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, memory_accounting), 0),
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen SD_BUS_PROPERTY("MemoryLimit", "t", NULL, offsetof(CGroupContext, memory_limit), 0),
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy, offsetof(CGroupContext, device_policy), 0),
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen SD_BUS_PROPERTY("DeviceAllow", "a(ss)", property_get_device_allow, 0, 0),
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen SD_BUS_PROPERTY("TasksAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, tasks_accounting), 0),
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen SD_BUS_PROPERTY("TasksMax", "t", NULL, offsetof(CGroupContext, tasks_max), 0),
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmekstatic int bus_cgroup_set_transient_property(
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart Poettering unit_write_drop_in_private(u, mode, name, b ? "Delegate=yes" : "Delegate=no");
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek if (streq(name, "CPUAccounting")) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_CPUACCT|CGROUP_MASK_CPU);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen unit_write_drop_in_private(u, mode, name, b ? "CPUAccounting=yes" : "CPUAccounting=no");
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen r = sd_bus_message_read(message, "t", &shares);
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "CPUShares value out of range");
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom Gundersen unit_write_drop_in_private(u, mode, name, "CPUShares=");
bf175aafd20c9ef974709ef12c5acf836121af33Tom Gundersen unit_write_drop_in_private_format(u, mode, name, "CPUShares=%" PRIu64, shares);
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen r = sd_bus_message_read(message, "t", &shares);
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "StartupCPUShares value out of range");
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen unit_write_drop_in_private(u, mode, name, "StartupCPUShares=");
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen unit_write_drop_in_private_format(u, mode, name, "StartupCPUShares=%" PRIu64, shares);
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen } else if (streq(name, "CPUQuotaPerSecUSec")) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "CPUQuotaPerSecUSec value out of range");
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen unit_write_drop_in_private_format(u, mode, "CPUQuota", "CPUQuota=%0.f%%", (double) (c->cpu_quota_per_sec_usec / 10000));
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen } else if (streq(name, "BlockIOAccounting")) {
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen unit_write_drop_in_private(u, mode, name, b ? "BlockIOAccounting=yes" : "BlockIOAccounting=no");
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen r = sd_bus_message_read(message, "t", &weight);
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "BlockIOWeight value out of range");
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen unit_write_drop_in_private(u, mode, name, "BlockIOWeight=");
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen unit_write_drop_in_private_format(u, mode, name, "BlockIOWeight=%" PRIu64, weight);
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen } else if (streq(name, "StartupBlockIOWeight")) {
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen r = sd_bus_message_read(message, "t", &weight);
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "StartupBlockIOWeight value out of range");
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering if (weight == CGROUP_BLKIO_WEIGHT_INVALID)
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen unit_write_drop_in_private(u, mode, name, "StartupBlockIOWeight=");
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering unit_write_drop_in_private_format(u, mode, name, "StartupBlockIOWeight=%" PRIu64, weight);
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering } else if (streq(name, "BlockIOReadBandwidth") || streq(name, "BlockIOWriteBandwidth")) {
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen unsigned n = 0;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen r = sd_bus_message_enter_container(message, 'a', "(st)");
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (path_equal(path, b->path) && read == b->read) {
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, a);
e51660ae56bb747ece2cab8fe6eec37f4d06a438Tom Gundersen if (n == 0) {
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen LIST_FOREACH_SAFE(device_bandwidths, a, next, c->blockio_device_bandwidths)
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen cgroup_context_free_blockio_device_bandwidth(c, a);
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths)
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen fprintf(f, "BlockIOReadBandwidth=%s %" PRIu64 "\n", a->path, a->bandwidth);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths)
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen fprintf(f, "BlockIOWriteBandwidth=%s %" PRIu64 "\n", a->path, a->bandwidth);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen unit_write_drop_in_private(u, mode, name, buf);
a669ea9860900d5cdebbc4cb9aaea72db7e28a02Tom Gundersen } else if (streq(name, "BlockIODeviceWeight")) {
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen unsigned n = 0;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen r = sd_bus_message_enter_container(message, 'a', "(st)");
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen while ((r = sd_bus_message_read(message, "(st)", &path, &weight)) > 0) {
a669ea9860900d5cdebbc4cb9aaea72db7e28a02Tom Gundersen if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight) || weight == CGROUP_BLKIO_WEIGHT_INVALID)
a669ea9860900d5cdebbc4cb9aaea72db7e28a02Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "BlockIODeviceWeight out of range");
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen LIST_FOREACH(device_weights, b, c->blockio_device_weights) {
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen LIST_PREPEND(device_weights,c->blockio_device_weights, a);
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen if (n == 0) {
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights);
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen LIST_FOREACH(device_weights, a, c->blockio_device_weights)
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen fprintf(f, "BlockIODeviceWeight=%s %" PRIu64 "\n", a->path, a->weight);
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen unit_write_drop_in_private(u, mode, name, buf);
c->memory_accounting = b;
const char *policy;
return -EINVAL;
char *buf;
c->device_policy = p;
return -ENOMEM;
if (!a->path) {
free(a);
return -ENOMEM;
while (c->device_allow)
return -ENOMEM;
fflush(f);
c->tasks_accounting = b;