summaryrefslogtreecommitdiff
path: root/src/shared/bus-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-11 16:48:24 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-11 18:31:49 +0200
commitd53d94743c5e5e3a4a668b0c707826a90a08949a (patch)
treec9f88941f6a5f072263ee7707500d577bf077300 /src/shared/bus-util.c
parentafc966e288b5013de55c56b18ddc9a5723b865d5 (diff)
core: refactor cpu shares/blockio weight cgroup logic
Let's stop using the "unsigned long" type for weights/shares, and let's just use uint64_t for this, as that's what we expose on the bus. Unify parsers, and always validate the range for these fields. Correct the default blockio weight to 500, since that's what the kernel actually uses. When parsing the weight/shares settings from unit files accept the empty string as a way to reset the weight/shares value. When getting it via the bus, uniformly map (uint64_t) -1 to unset. Open up StartupCPUShares= and StartupBlockIOWeight= to transient units.
Diffstat (limited to 'src/shared/bus-util.c')
-rw-r--r--src/shared/bus-util.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 4dc4ca581d..a2c5d8acca 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -23,22 +23,24 @@
#include "sd-daemon.h"
#include "sd-event.h"
-#include "util.h"
-#include "strv.h"
-#include "macro.h"
+#include "sd-bus.h"
+
+#include "bus-error.h"
+#include "bus-internal.h"
+#include "bus-label.h"
+#include "bus-message.h"
+#include "cgroup-util.h"
#include "def.h"
-#include "path-util.h"
+#include "macro.h"
#include "missing.h"
+#include "path-util.h"
#include "set.h"
#include "signal-util.h"
+#include "strv.h"
#include "unit-name.h"
+#include "util.h"
-#include "sd-bus.h"
-#include "bus-error.h"
-#include "bus-label.h"
-#include "bus-message.h"
#include "bus-util.h"
-#include "bus-internal.h"
static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
sd_event *e = userdata;
@@ -1463,10 +1465,21 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
r = sd_bus_message_append(m, "v", "t", n);
- } else if (STR_IN_SET(field, "CPUShares", "BlockIOWeight")) {
+ } else if (STR_IN_SET(field, "CPUShares", "StartupCPUShares")) {
+ uint64_t u;
+
+ r = cg_cpu_shares_parse(eq, &u);
+ if (r < 0) {
+ log_error("Failed to parse %s value %s.", field, eq);
+ return -EINVAL;
+ }
+
+ r = sd_bus_message_append(m, "v", "t", u);
+
+ } else if (STR_IN_SET(field, "BlockIOWeight", "StartupBlockIOWeight")) {
uint64_t u;
- r = safe_atou64(eq, &u);
+ r = cg_cpu_shares_parse(eq, &u);
if (r < 0) {
log_error("Failed to parse %s value %s.", field, eq);
return -EINVAL;