dbus-cgroup.c revision e7ab4d1ac9f8d99eecd5e2d22eb482a1fb0fbf23
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen/***
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen This file is part of systemd.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen Copyright 2013 Lennart Poettering
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
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
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
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/>.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen***/
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen#include "bus-util.h"
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen#include "path-util.h"
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen#include "cgroup-util.h"
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen#include "cgroup.h"
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen#include "dbus-cgroup.h"
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersenstatic BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy);
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersen
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersenstatic int property_get_blockio_device_weight(
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen sd_bus *bus,
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen const char *path,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen const char *interface,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen const char *property,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen sd_bus_message *reply,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen void *userdata,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen sd_bus_error *error) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen CGroupContext *c = userdata;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen CGroupBlockIODeviceWeight *w;
3aeb37bc4f32b5edc334f2ac7c5d3c7b0a121328Tom Gundersen int r;
c6f7c917a1b494d4455800823472227463f87438Tom Gundersen
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering assert(bus);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(reply);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(c);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen r = sd_bus_message_open_container(reply, 'a', "(st)");
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersen if (r < 0)
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersen return r;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen LIST_FOREACH(device_weights, w, c->blockio_device_weights) {
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen r = sd_bus_message_append(reply, "(st)", w->path, w->weight);
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen if (r < 0)
97f2d76d4f4dfab8b0629c09926a05a1e5621125Tom Gundersen return r;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen }
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek return sd_bus_message_close_container(reply);
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek}
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmekstatic int property_get_blockio_device_bandwidths(
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek sd_bus *bus,
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek const char *path,
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek const char *interface,
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek const char *property,
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek sd_bus_message *reply,
5b9d4dc05560ddda89e48b6b39365824b15e1300Tom Gundersen void *userdata,
5b9d4dc05560ddda89e48b6b39365824b15e1300Tom Gundersen sd_bus_error *error) {
5b9d4dc05560ddda89e48b6b39365824b15e1300Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen CGroupContext *c = userdata;
5b9d4dc05560ddda89e48b6b39365824b15e1300Tom Gundersen CGroupBlockIODeviceBandwidth *b;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen int r;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(bus);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(reply);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(c);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen r = sd_bus_message_open_container(reply, 'a', "(st)");
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (r < 0)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return r;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
977085794d2996320e345433403de75f662b0622Tom Gundersen LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) {
977085794d2996320e345433403de75f662b0622Tom Gundersen
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen if (streq(property, "BlockIOReadBandwidth") != b->read)
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen continue;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
5b9d4dc05560ddda89e48b6b39365824b15e1300Tom Gundersen r = sd_bus_message_append(reply, "(st)", b->path, b->bandwidth);
5b9d4dc05560ddda89e48b6b39365824b15e1300Tom Gundersen if (r < 0)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return r;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen }
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return sd_bus_message_close_container(reply);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen}
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersenstatic int property_get_device_allow(
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen sd_bus *bus,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen const char *path,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen const char *interface,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen const char *property,
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen sd_bus_message *reply,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen void *userdata,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen sd_bus_error *error) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen CGroupContext *c = userdata;
d2df0d0ed3a88e491405b403e6022e6619750130Tom Gundersen CGroupDeviceAllow *a;
edf029b7fd9a5853a87d3ca99aac2922bb8a277eTom Gundersen int r;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(bus);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(reply);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(c);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen r = sd_bus_message_open_container(reply, 'a', "(ss)");
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (r < 0)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return r;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
03e334a1c7dc8c20c38902aa039440763acc9b17Lennart Poettering LIST_FOREACH(device_allow, a, c->device_allow) {
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen unsigned k = 0;
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen char rwm[4];
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (a->r)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen rwm[k++] = 'r';
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (a->w)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen rwm[k++] = 'w';
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (a->m)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen rwm[k++] = 'm';
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen rwm[k] = 0;
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek
6e37cd2f4af8928d905203108a4331e375d7127cThomas Hindoe Paaboel Andersen r = sd_bus_message_append(reply, "(ss)", a->path, rwm);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (r < 0)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return r;
187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6Thomas Hindoe Paaboel Andersen }
187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6Thomas Hindoe Paaboel Andersen
187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6Thomas Hindoe Paaboel Andersen return sd_bus_message_close_container(reply);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen}
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersenconst sd_bus_vtable bus_cgroup_vtable[] = {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen SD_BUS_VTABLE_START(0),
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),
e9f3d2d508bfd9fb5b54e82994bda365a71eb864Zbigniew Jędrzejewski-Szmek SD_BUS_VTABLE_END
e9f3d2d508bfd9fb5b54e82994bda365a71eb864Zbigniew Jędrzejewski-Szmek};
e9f3d2d508bfd9fb5b54e82994bda365a71eb864Zbigniew Jędrzejewski-Szmek
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmekstatic int bus_cgroup_set_transient_property(
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek Unit *u,
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek CGroupContext *c,
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek const char *name,
98a375f6d5cac24eb80d6d4e00699851324afdecTom Gundersen sd_bus_message *message,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UnitSetPropertiesMode mode,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen sd_bus_error *error) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen int r;
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(u);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(c);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(name);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen assert(message);
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen
f8a0bb5285024b6ce372c3157e761e6543ebdcd2Andreas Henriksson if (streq(name, "Delegate")) {
a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8Zbigniew Jędrzejewski-Szmek int b;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen r = sd_bus_message_read(message, "b", &b);
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen if (r < 0)
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poettering return r;
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart Poettering
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt if (mode != UNIT_CHECK) {
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poettering c->delegate = b;
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart Poettering unit_write_drop_in_private(u, mode, name, b ? "Delegate=yes" : "Delegate=no");
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen }
a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8Zbigniew Jędrzejewski-Szmek
a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8Zbigniew Jędrzejewski-Szmek return 1;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen }
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen return 0;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen}
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersenint bus_cgroup_set_property(
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen Unit *u,
edf029b7fd9a5853a87d3ca99aac2922bb8a277eTom Gundersen CGroupContext *c,
edf029b7fd9a5853a87d3ca99aac2922bb8a277eTom Gundersen const char *name,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen sd_bus_message *message,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UnitSetPropertiesMode mode,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen sd_bus_error *error) {
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen int r;
3f85ef0f05ffc51e19f86fb83a1c51e8e3cd6817Harald Hoyer
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen assert(u);
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen assert(c);
97f2d76d4f4dfab8b0629c09926a05a1e5621125Tom Gundersen assert(name);
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek assert(message);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek if (streq(name, "CPUAccounting")) {
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt int b;
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen r = sd_bus_message_read(message, "b", &b);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (r < 0)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return r;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (mode != UNIT_CHECK) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen c->cpu_accounting = b;
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");
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen }
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return 1;
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen } else if (streq(name, "CPUShares")) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen uint64_t shares;
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen r = sd_bus_message_read(message, "t", &shares);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (r < 0)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return r;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen if (!CGROUP_CPU_SHARES_IS_OK(shares))
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "CPUShares value out of range");
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom Gundersen if (mode != UNIT_CHECK) {
edbb03e95a3c31bf719d5c6c46eec14d0bcb9c8fTom Gundersen c->cpu_shares = shares;
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_CPU);
edbb03e95a3c31bf719d5c6c46eec14d0bcb9c8fTom Gundersen
eb7040ec50fbfe5aad9eaf305bd442a4a235abaaTom Gundersen if (shares == CGROUP_CPU_SHARES_INVALID)
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom Gundersen unit_write_drop_in_private(u, mode, name, "CPUShares=");
9b1c2626cef16722603bded9bb52033aba34dd74Tom Gundersen else
bf175aafd20c9ef974709ef12c5acf836121af33Tom Gundersen unit_write_drop_in_private_format(u, mode, name, "CPUShares=%" PRIu64, shares);
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom Gundersen }
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen return 1;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen } else if (streq(name, "StartupCPUShares")) {
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen uint64_t shares;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen r = sd_bus_message_read(message, "t", &shares);
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (r < 0)
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen return r;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (!CGROUP_CPU_SHARES_IS_OK(shares))
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "StartupCPUShares value out of range");
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (mode != UNIT_CHECK) {
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen c->startup_cpu_shares = shares;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_CPU);
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (shares == CGROUP_CPU_SHARES_INVALID)
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen unit_write_drop_in_private(u, mode, name, "StartupCPUShares=");
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen else
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen unit_write_drop_in_private_format(u, mode, name, "StartupCPUShares=%" PRIu64, shares);
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen }
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen return 1;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen } else if (streq(name, "CPUQuotaPerSecUSec")) {
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen uint64_t u64;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen r = sd_bus_message_read(message, "t", &u64);
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (r < 0)
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen return r;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (u64 <= 0)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "CPUQuotaPerSecUSec value out of range");
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (mode != UNIT_CHECK) {
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen c->cpu_quota_per_sec_usec = u64;
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_CPU);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen unit_write_drop_in_private_format(u, mode, "CPUQuota", "CPUQuota=%0.f%%", (double) (c->cpu_quota_per_sec_usec / 10000));
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen }
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen return 1;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen } else if (streq(name, "BlockIOAccounting")) {
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen int b;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen r = sd_bus_message_read(message, "b", &b);
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen if (r < 0)
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen return r;
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen if (mode != UNIT_CHECK) {
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen c->blockio_accounting = b;
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO);
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen unit_write_drop_in_private(u, mode, name, b ? "BlockIOAccounting=yes" : "BlockIOAccounting=no");
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen }
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen return 1;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen } else if (streq(name, "BlockIOWeight")) {
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen uint64_t weight;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen r = sd_bus_message_read(message, "t", &weight);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen if (r < 0)
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen return r;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen if (!CGROUP_BLKIO_WEIGHT_IS_OK(weight))
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "BlockIOWeight value out of range");
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen if (mode != UNIT_CHECK) {
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen c->blockio_weight = weight;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen if (weight == CGROUP_BLKIO_WEIGHT_INVALID)
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen unit_write_drop_in_private(u, mode, name, "BlockIOWeight=");
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen else
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen unit_write_drop_in_private_format(u, mode, name, "BlockIOWeight=%" PRIu64, weight);
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen }
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen return 1;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen } else if (streq(name, "StartupBlockIOWeight")) {
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen uint64_t weight;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen r = sd_bus_message_read(message, "t", &weight);
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen if (r < 0)
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen return r;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen if (CGROUP_BLKIO_WEIGHT_IS_OK(weight))
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen return sd_bus_error_set_errnof(error, EINVAL, "StartupBlockIOWeight value out of range");
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen if (mode != UNIT_CHECK) {
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering c->startup_blockio_weight = weight;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO);
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering if (weight == CGROUP_BLKIO_WEIGHT_INVALID)
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen unit_write_drop_in_private(u, mode, name, "StartupBlockIOWeight=");
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering else
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering unit_write_drop_in_private_format(u, mode, name, "StartupBlockIOWeight=%" PRIu64, weight);
b5db00e52ee2e20578839e4e4488f7b9af9abc38Umut Tezduyar Lindskog }
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen
55428d84f31b52da1c50b7469f14e15740547f20Tom Gundersen return 1;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering } else if (streq(name, "BlockIOReadBandwidth") || streq(name, "BlockIOWriteBandwidth")) {
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering const char *path;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen bool read = true;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen unsigned n = 0;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen uint64_t u64;
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen if (streq(name, "BlockIOWriteBandwidth"))
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen read = false;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen r = sd_bus_message_enter_container(message, 'a', "(st)");
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen if (r < 0)
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen return r;
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen if (mode != UNIT_CHECK) {
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen CGroupBlockIODeviceBandwidth *a = NULL, *b;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen LIST_FOREACH(device_bandwidths, b, c->blockio_device_bandwidths) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (path_equal(path, b->path) && read == b->read) {
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen a = b;
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen break;
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen }
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen }
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen if (!a) {
3e137a1b9a0eac2bf43d493d3302c3c959b6ccdbTom Gundersen a = new0(CGroupBlockIODeviceBandwidth, 1);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (!a)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return -ENOMEM;
aedca89268ed4fd6be41e55a605f011033ad1fb5Tom Gundersen
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen a->read = read;
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen a->path = strdup(path);
755bde375f4db393ad06e73340bfcf4d0cf91bb2Lennart Poettering if (!a->path) {
755bde375f4db393ad06e73340bfcf4d0cf91bb2Lennart Poettering free(a);
755bde375f4db393ad06e73340bfcf4d0cf91bb2Lennart Poettering return -ENOMEM;
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersen }
aedca89268ed4fd6be41e55a605f011033ad1fb5Tom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, a);
755bde375f4db393ad06e73340bfcf4d0cf91bb2Lennart Poettering }
755bde375f4db393ad06e73340bfcf4d0cf91bb2Lennart Poettering
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen a->bandwidth = u64;
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen }
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen n++;
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen }
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen if (r < 0)
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen return r;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen r = sd_bus_message_exit_container(message);
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen if (r < 0)
68ba38770640413b4fa06773447666eb88a38d4cTom Gundersen return r;
68ba38770640413b4fa06773447666eb88a38d4cTom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen if (mode != UNIT_CHECK) {
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen CGroupBlockIODeviceBandwidth *a, *next;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen _cleanup_free_ char *buf = NULL;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen _cleanup_fclose_ FILE *f = NULL;
e51660ae56bb747ece2cab8fe6eec37f4d06a438Tom Gundersen size_t size = 0;
e51660ae56bb747ece2cab8fe6eec37f4d06a438Tom Gundersen
e51660ae56bb747ece2cab8fe6eec37f4d06a438Tom Gundersen if (n == 0) {
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen LIST_FOREACH_SAFE(device_bandwidths, a, next, c->blockio_device_bandwidths)
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen if (a->read == read)
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen cgroup_context_free_blockio_device_bandwidth(c, a);
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen }
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO);
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen f = open_memstream(&buf, &size);
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen if (!f)
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen return -ENOMEM;
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen if (read) {
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen fputs("BlockIOReadBandwidth=\n", f);
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths)
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen if (a->read)
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen fprintf(f, "BlockIOReadBandwidth=%s %" PRIu64 "\n", a->path, a->bandwidth);
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen } else {
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen fputs("BlockIOWriteBandwidth=\n", f);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen LIST_FOREACH(device_bandwidths, a, c->blockio_device_bandwidths)
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen if (!a->read)
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen fprintf(f, "BlockIOWriteBandwidth=%s %" PRIu64 "\n", a->path, a->bandwidth);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen }
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen fflush(f);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen unit_write_drop_in_private(u, mode, name, buf);
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen }
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
92d927f850d4b668b44f3e5f41e266d934d03726Tom Gundersen return 1;
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
a669ea9860900d5cdebbc4cb9aaea72db7e28a02Tom Gundersen } else if (streq(name, "BlockIODeviceWeight")) {
a669ea9860900d5cdebbc4cb9aaea72db7e28a02Tom Gundersen const char *path;
a669ea9860900d5cdebbc4cb9aaea72db7e28a02Tom Gundersen uint64_t weight;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen unsigned n = 0;
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen r = sd_bus_message_enter_container(message, 'a', "(st)");
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen if (r < 0)
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen return r;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen while ((r = sd_bus_message_read(message, "(st)", &path, &weight)) > 0) {
a669ea9860900d5cdebbc4cb9aaea72db7e28a02Tom Gundersen
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");
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen if (mode != UNIT_CHECK) {
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen CGroupBlockIODeviceWeight *a = NULL, *b;
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen LIST_FOREACH(device_weights, b, c->blockio_device_weights) {
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen if (path_equal(b->path, path)) {
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen a = b;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen break;
aedca89268ed4fd6be41e55a605f011033ad1fb5Tom Gundersen }
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen }
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt if (!a) {
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen a = new0(CGroupBlockIODeviceWeight, 1);
d95b83b87d7d7c50e550f7128827f73a321c8934Tom Gundersen if (!a)
d95b83b87d7d7c50e550f7128827f73a321c8934Tom Gundersen return -ENOMEM;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen a->path = strdup(path);
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen if (!a->path) {
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen free(a);
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen return -ENOMEM;
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen }
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen LIST_PREPEND(device_weights,c->blockio_device_weights, a);
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen }
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen a->weight = weight;
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen }
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen
aedca89268ed4fd6be41e55a605f011033ad1fb5Tom Gundersen n++;
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen }
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen r = sd_bus_message_exit_container(message);
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen if (r < 0)
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen return r;
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen
847a8a5fed4d265dfa659917515c6f9bd1b8d5c4Tom Gundersen if (mode != UNIT_CHECK) {
2c5859afecee81e345fc9526b1083bf79990ffb8Daniel Mack _cleanup_free_ char *buf = NULL;
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen _cleanup_fclose_ FILE *f = NULL;
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen CGroupBlockIODeviceWeight *a;
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen size_t size = 0;
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen if (n == 0) {
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen while (c->blockio_device_weights)
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights);
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen }
2c5859afecee81e345fc9526b1083bf79990ffb8Daniel Mack
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen unit_invalidate_cgroup(u, CGROUP_MASK_BLKIO);
e51660ae56bb747ece2cab8fe6eec37f4d06a438Tom Gundersen
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen f = open_memstream(&buf, &size);
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen if (!f)
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen return -ENOMEM;
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen fputs("BlockIODeviceWeight=\n", f);
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
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen fflush(f);
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen unit_write_drop_in_private(u, mode, name, buf);
}
return 1;
} else if (streq(name, "MemoryAccounting")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->memory_accounting = b;
unit_invalidate_cgroup(u, CGROUP_MASK_MEMORY);
unit_write_drop_in_private(u, mode, name, b ? "MemoryAccounting=yes" : "MemoryAccounting=no");
}
return 1;
} else if (streq(name, "MemoryLimit")) {
uint64_t limit;
r = sd_bus_message_read(message, "t", &limit);
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->memory_limit = limit;
unit_invalidate_cgroup(u, CGROUP_MASK_MEMORY);
if (limit == (uint64_t) -1)
unit_write_drop_in_private(u, mode, name, "MemoryLimit=infinity");
else
unit_write_drop_in_private_format(u, mode, name, "MemoryLimit=%" PRIu64, limit);
}
return 1;
} else if (streq(name, "DevicePolicy")) {
const char *policy;
CGroupDevicePolicy p;
r = sd_bus_message_read(message, "s", &policy);
if (r < 0)
return r;
p = cgroup_device_policy_from_string(policy);
if (p < 0)
return -EINVAL;
if (mode != UNIT_CHECK) {
char *buf;
c->device_policy = p;
unit_invalidate_cgroup(u, CGROUP_MASK_DEVICES);
buf = strjoina("DevicePolicy=", policy);
unit_write_drop_in_private(u, mode, name, buf);
}
return 1;
} else if (streq(name, "DeviceAllow")) {
const char *path, *rwm;
unsigned n = 0;
r = sd_bus_message_enter_container(message, 'a', "(ss)");
if (r < 0)
return r;
while ((r = sd_bus_message_read(message, "(ss)", &path, &rwm)) > 0) {
if ((!startswith(path, "/dev/") &&
!startswith(path, "block-") &&
!startswith(path, "char-")) ||
strpbrk(path, WHITESPACE))
return sd_bus_error_set_errnof(error, EINVAL, "DeviceAllow= requires device node");
if (isempty(rwm))
rwm = "rwm";
if (!in_charset(rwm, "rwm"))
return sd_bus_error_set_errnof(error, EINVAL, "DeviceAllow= requires combination of rwm flags");
if (mode != UNIT_CHECK) {
CGroupDeviceAllow *a = NULL, *b;
LIST_FOREACH(device_allow, b, c->device_allow) {
if (path_equal(b->path, path)) {
a = b;
break;
}
}
if (!a) {
a = new0(CGroupDeviceAllow, 1);
if (!a)
return -ENOMEM;
a->path = strdup(path);
if (!a->path) {
free(a);
return -ENOMEM;
}
LIST_PREPEND(device_allow, c->device_allow, a);
}
a->r = !!strchr(rwm, 'r');
a->w = !!strchr(rwm, 'w');
a->m = !!strchr(rwm, 'm');
}
n++;
}
if (r < 0)
return r;
r = sd_bus_message_exit_container(message);
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
_cleanup_free_ char *buf = NULL;
_cleanup_fclose_ FILE *f = NULL;
CGroupDeviceAllow *a;
size_t size = 0;
if (n == 0) {
while (c->device_allow)
cgroup_context_free_device_allow(c, c->device_allow);
}
unit_invalidate_cgroup(u, CGROUP_MASK_DEVICES);
f = open_memstream(&buf, &size);
if (!f)
return -ENOMEM;
fputs("DeviceAllow=\n", f);
LIST_FOREACH(device_allow, a, c->device_allow)
fprintf(f, "DeviceAllow=%s %s%s%s\n", a->path, a->r ? "r" : "", a->w ? "w" : "", a->m ? "m" : "");
fflush(f);
unit_write_drop_in_private(u, mode, name, buf);
}
return 1;
} else if (streq(name, "TasksAccounting")) {
int b;
r = sd_bus_message_read(message, "b", &b);
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->tasks_accounting = b;
unit_invalidate_cgroup(u, CGROUP_MASK_PIDS);
unit_write_drop_in_private(u, mode, name, b ? "TasksAccounting=yes" : "TasksAccounting=no");
}
return 1;
} else if (streq(name, "TasksMax")) {
uint64_t limit;
r = sd_bus_message_read(message, "t", &limit);
if (r < 0)
return r;
if (mode != UNIT_CHECK) {
c->tasks_max = limit;
unit_invalidate_cgroup(u, CGROUP_MASK_PIDS);
if (limit == (uint64_t) -1)
unit_write_drop_in_private(u, mode, name, "TasksMax=infinity");
else
unit_write_drop_in_private_format(u, mode, name, "TasksMax=%" PRIu64, limit);
}
return 1;
}
if (u->transient && u->load_state == UNIT_STUB) {
r = bus_cgroup_set_transient_property(u, c, name, message, mode, error);
if (r != 0)
return r;
}
return 0;
}