]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: support DisableControllers= for transient units 12336/head
authorAnita Zhang <the.anitazha@gmail.com>
Wed, 17 Apr 2019 07:42:55 +0000 (00:42 -0700)
committerAnita Zhang <the.anitazha@gmail.com>
Mon, 22 Apr 2019 18:52:08 +0000 (11:52 -0700)
docs/TRANSIENT-SETTINGS.md
src/core/cgroup.c
src/core/dbus-cgroup.c
src/shared/bus-unit-util.c

index 798793f3eefc4495decbe31d927fd6b95cda00d7..3aa68c0a2629d18766547f5d33545f4f06601294 100644 (file)
@@ -253,6 +253,7 @@ All cgroup/resource control settings are available for transient units
 ✓ TasksAccounting=
 ✓ TasksMax=
 ✓ Delegate=
+✓ DisableControllers=
 ✓ IPAccounting=
 ✓ IPAddressAllow=
 ✓ IPAddressDeny=
index ceb7ee21892d2debdeb170fcb71c0464a4deb9f9..a288c07bc9121031fcfde5a36ef98bfc2a4fb901 100644 (file)
@@ -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) {
index 5327bfb17d901045d77884e3251e806378084083..74a583d81b7bf21abf284ab74c865618b00f9cd3 100644 (file)
@@ -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")) {
+
+                                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));
 
-                        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;
index cae526ba40931fe695f72f900a00d7428ef6c84a..c6cbc9828c88d9ef0c16315136e4e65e797db952 100644 (file)
@@ -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);