From 25cc30c4c8747e11410b9780df22e967f665b2c1 Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Wed, 17 Apr 2019 00:42:55 -0700 Subject: [PATCH] core: support DisableControllers= for transient units --- docs/TRANSIENT-SETTINGS.md | 1 + src/core/cgroup.c | 5 +++++ src/core/dbus-cgroup.c | 30 +++++++++++++++++++++--------- src/shared/bus-unit-util.c | 4 ++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/docs/TRANSIENT-SETTINGS.md b/docs/TRANSIENT-SETTINGS.md index 798793f3ee..3aa68c0a26 100644 --- a/docs/TRANSIENT-SETTINGS.md +++ b/docs/TRANSIENT-SETTINGS.md @@ -253,6 +253,7 @@ All cgroup/resource control settings are available for transient units ✓ TasksAccounting= ✓ TasksMax= ✓ Delegate= +✓ DisableControllers= ✓ IPAccounting= ✓ IPAddressAllow= ✓ IPAddressDeny= diff --git a/src/core/cgroup.c b/src/core/cgroup.c index ceb7ee2189..a288c07bc9 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -202,6 +202,7 @@ void cgroup_context_done(CGroupContext *c) { } void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) { + _cleanup_free_ char *disable_controllers_str = NULL; CGroupIODeviceLimit *il; CGroupIODeviceWeight *iw; CGroupIODeviceLatency *l; @@ -217,6 +218,8 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) { prefix = strempty(prefix); + (void) cg_mask_to_string(c->disable_controllers, &disable_controllers_str); + fprintf(f, "%sCPUAccounting=%s\n" "%sIOAccounting=%s\n" @@ -243,6 +246,7 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) { "%sMemoryLimit=%" PRIu64 "\n" "%sTasksMax=%" PRIu64 "\n" "%sDevicePolicy=%s\n" + "%sDisableControllers=%s\n" "%sDelegate=%s\n", prefix, yes_no(c->cpu_accounting), prefix, yes_no(c->io_accounting), @@ -269,6 +273,7 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) { prefix, c->memory_limit, prefix, c->tasks_max, prefix, cgroup_device_policy_to_string(c->device_policy), + prefix, strnull(disable_controllers_str), prefix, yes_no(c->delegate)); if (c->delegate) { diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 5327bfb17d..74a583d81b 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -401,10 +401,10 @@ static int bus_cgroup_set_transient_property( return 1; - } else if (streq(name, "DelegateControllers")) { + } else if (STR_IN_SET(name, "DelegateControllers", "DisableControllers")) { CGroupMask mask = 0; - if (!UNIT_VTABLE(u)->can_delegate) + if (streq(name, "DelegateControllers") && !UNIT_VTABLE(u)->can_delegate) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Delegation not available for unit type"); r = sd_bus_message_enter_container(message, 'a', "s"); @@ -439,13 +439,25 @@ static int bus_cgroup_set_transient_property( if (r < 0) return r; - c->delegate = true; - if (mask == 0) - c->delegate_controllers = 0; - else - c->delegate_controllers |= mask; + if (streq(name, "DelegateControllers")) { - unit_write_settingf(u, flags, name, "Delegate=%s", strempty(t)); + c->delegate = true; + if (mask == 0) + c->delegate_controllers = 0; + else + c->delegate_controllers |= mask; + + unit_write_settingf(u, flags, name, "Delegate=%s", strempty(t)); + + } else if (streq(name, "DisableControllers")) { + + if (mask == 0) + c->disable_controllers = 0; + else + c->disable_controllers |= mask; + + unit_write_settingf(u, flags, name, "%s=%s", name, strempty(t)); + } } return 1; @@ -1426,7 +1438,7 @@ int bus_cgroup_set_property( return 1; } - if (u->transient && u->load_state == UNIT_STUB) + if (streq(name, "DisableControllers") || (u->transient && u->load_state == UNIT_STUB)) return bus_cgroup_set_transient_property(u, c, name, message, flags, error); return 0; diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index cae526ba40..c6cbc9828c 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -396,6 +396,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons return bus_append_cg_blkio_weight_parse(m, field, eq); + if (streq(field, "DisableControllers")) + + return bus_append_strv(m, "DisableControllers", eq, EXTRACT_QUOTES); + if (streq(field, "Delegate")) { r = parse_boolean(eq);