chiark / gitweb /
manager: make list of default controllers configurable
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Nov 2010 23:42:35 +0000 (00:42 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 17 Nov 2010 23:42:35 +0000 (00:42 +0100)
man/systemd.conf.xml
src/dbus-manager.c
src/main.c
src/manager.c
src/manager.h
src/system.conf
src/unit.c

index 6759f978148b5f3f6a8a837aa4dff08ed1ad7cfa..32eae2b8e0a98587b179564d11e1a5bdbf8d7b24 100644 (file)
                                 whether this job is left to some other
                                 system script.</para></listitem>
                         </varlistentry>
                                 whether this job is left to some other
                                 system script.</para></listitem>
                         </varlistentry>
+
+                        <varlistentry>
+                                <term><varname>DefaultControllers=cpu</varname></term>
+
+                                <listitem><para>Configures in which
+                                cgroup controller hierarchies to
+                                create per-service cgroups
+                                automatically, in addition to the
+                                name=systemd named hierarchy. Defaults
+                                to 'cpu'. Takes a space seperated list
+                                of controller names. Pass an empty
+                                string to ensure that systemd does not
+                                touch any hiearchies but its
+                                own.</para></listitem>
+                        </varlistentry>
                 </variablelist>
         </refsect1>
 
                 </variablelist>
         </refsect1>
 
index d1d3b4784e7fa33484d01d925b711c3f6857078a..28986e54269b7600e9f347b072c5e0e155e584ec 100644 (file)
         "  <property name=\"NotifySocket\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"MountAuto\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"NotifySocket\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"MountAuto\" type=\"b\" access=\"read\"/>\n" \
-        "  <property name=\"SwapAuto\" type=\"b\" access=\"read\"/>\n"
+        "  <property name=\"SwapAuto\" type=\"b\" access=\"read\"/>\n"  \
+        "  <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n"
+                                                                        \
 
 #ifdef HAVE_SYSV_COMPAT
 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV                           \
 
 #ifdef HAVE_SYSV_COMPAT
 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV                           \
@@ -319,7 +321,8 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
                 { "org.freedesktop.systemd1.Manager", "NotifySocket",  bus_property_append_string,    "s",  m->notify_socket   },
                 { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy },
                 { "org.freedesktop.systemd1.Manager", "MountAuto",     bus_property_append_bool,      "b",  &m->mount_auto     },
                 { "org.freedesktop.systemd1.Manager", "NotifySocket",  bus_property_append_string,    "s",  m->notify_socket   },
                 { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy },
                 { "org.freedesktop.systemd1.Manager", "MountAuto",     bus_property_append_bool,      "b",  &m->mount_auto     },
-                { "org.freedesktop.systemd1.Manager", "SwapAuto",      bus_property_append_bool,      "b",  &m->swap_auto     },
+                { "org.freedesktop.systemd1.Manager", "SwapAuto",      bus_property_append_bool,      "b",  &m->swap_auto      },
+                { "org.freedesktop.systemd1.Manager", "DefaultControllers", bus_property_append_strv, "as", m->default_controllers },
 #ifdef HAVE_SYSV_COMPAT
                 { "org.freedesktop.systemd1.Manager", "SysVConsole",   bus_property_append_bool,      "b",  &m->sysv_console   },
                 { "org.freedesktop.systemd1.Manager", "SysVInitPath",  bus_property_append_strv,      "as", m->lookup_paths.sysvinit_path },
 #ifdef HAVE_SYSV_COMPAT
                 { "org.freedesktop.systemd1.Manager", "SysVConsole",   bus_property_append_bool,      "b",  &m->sysv_console   },
                 { "org.freedesktop.systemd1.Manager", "SysVInitPath",  bus_property_append_strv,      "as", m->lookup_paths.sysvinit_path },
index 4bdc6763fabf83546407b784ecb9b51c4c4654d7..99e277c67b9fd290bd4095425344c852e62e529e 100644 (file)
@@ -49,6 +49,7 @@
 #include "missing.h"
 #include "label.h"
 #include "build.h"
 #include "missing.h"
 #include "label.h"
 #include "build.h"
+#include "strv.h"
 
 static enum {
         ACTION_RUN,
 
 static enum {
         ACTION_RUN,
@@ -72,6 +73,7 @@ static bool arg_sysv_console = true;
 static bool arg_mount_auto = true;
 static bool arg_swap_auto = true;
 static char *arg_console = NULL;
 static bool arg_mount_auto = true;
 static bool arg_swap_auto = true;
 static char *arg_console = NULL;
+static char **arg_default_controllers = NULL;
 
 static FILE* serialization = NULL;
 
 
 static FILE* serialization = NULL;
 
@@ -502,6 +504,7 @@ static int parse_config_file(void) {
                 { "CPUAffinity", config_parse_cpu_affinity, NULL,               "Manager" },
                 { "MountAuto",   config_parse_bool,         &arg_mount_auto,    "Manager" },
                 { "SwapAuto",    config_parse_bool,         &arg_swap_auto,     "Manager" },
                 { "CPUAffinity", config_parse_cpu_affinity, NULL,               "Manager" },
                 { "MountAuto",   config_parse_bool,         &arg_mount_auto,    "Manager" },
                 { "SwapAuto",    config_parse_bool,         &arg_swap_auto,     "Manager" },
+                { "DefaultControllers", config_parse_strv,  &arg_default_controllers, "Manager" },
                 { NULL, NULL, NULL, NULL }
         };
 
                 { NULL, NULL, NULL, NULL }
         };
 
@@ -1089,6 +1092,9 @@ int main(int argc, char *argv[]) {
         if (arg_console)
                 manager_set_console(m, arg_console);
 
         if (arg_console)
                 manager_set_console(m, arg_console);
 
+        if (arg_default_controllers)
+                manager_set_default_controllers(m, arg_default_controllers);
+
         if ((r = manager_startup(m, serialization, fds)) < 0)
                 log_error("Failed to fully start up daemon: %s", strerror(-r));
 
         if ((r = manager_startup(m, serialization, fds)) < 0)
                 log_error("Failed to fully start up daemon: %s", strerror(-r));
 
@@ -1211,6 +1217,7 @@ finish:
 
         free(arg_default_unit);
         free(arg_console);
 
         free(arg_default_unit);
         free(arg_console);
+        strv_free(arg_default_controllers);
 
         dbus_shutdown();
 
 
         dbus_shutdown();
 
index 827e9937c65af551456a24142fd4851c84f6a72f..62847061a27319be99daebe533c49afd0352d20e 100644 (file)
@@ -222,6 +222,9 @@ int manager_new(ManagerRunningAs running_as, Manager **_m) {
         if (!(m->environment = strv_copy(environ)))
                 goto fail;
 
         if (!(m->environment = strv_copy(environ)))
                 goto fail;
 
+        if (!(m->default_controllers = strv_new("cpu", NULL)))
+                goto fail;
+
         if (!(m->units = hashmap_new(string_hash_func, string_compare_func)))
                 goto fail;
 
         if (!(m->units = hashmap_new(string_hash_func, string_compare_func)))
                 goto fail;
 
@@ -461,6 +464,8 @@ void manager_free(Manager *m) {
         lookup_paths_free(&m->lookup_paths);
         strv_free(m->environment);
 
         lookup_paths_free(&m->lookup_paths);
         strv_free(m->environment);
 
+        strv_free(m->default_controllers);
+
         hashmap_free(m->cgroup_bondings);
         set_free_free(m->unit_path_cache);
 
         hashmap_free(m->cgroup_bondings);
         set_free_free(m->unit_path_cache);
 
@@ -2988,6 +2993,20 @@ void manager_undo_generators(Manager *m) {
         m->generator_unit_path = NULL;
 }
 
         m->generator_unit_path = NULL;
 }
 
+int manager_set_default_controllers(Manager *m, char **controllers) {
+        char **l;
+
+        assert(m);
+
+        if (!(l = strv_copy(controllers)))
+                return -ENOMEM;
+
+        strv_free(m->default_controllers);
+        m->default_controllers = l;
+
+        return 0;
+}
+
 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
         [MANAGER_SYSTEM] = "system",
         [MANAGER_USER] = "user"
 static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = {
         [MANAGER_SYSTEM] = "system",
         [MANAGER_USER] = "user"
index c7ace2dd5ebd8f483f1de0c85b349ef7cfc79320..f9c769e42b7eb4c4f665659f9bb92b6657b5488d 100644 (file)
@@ -142,6 +142,7 @@ struct Manager {
         Set *unit_path_cache;
 
         char **environment;
         Set *unit_path_cache;
 
         char **environment;
+        char **default_controllers;
 
         dual_timestamp initrd_timestamp;
         dual_timestamp startup_timestamp;
 
         dual_timestamp initrd_timestamp;
         dual_timestamp startup_timestamp;
@@ -256,6 +257,7 @@ unsigned manager_dispatch_run_queue(Manager *m);
 unsigned manager_dispatch_dbus_queue(Manager *m);
 
 int manager_set_console(Manager *m, const char *console);
 unsigned manager_dispatch_dbus_queue(Manager *m);
 
 int manager_set_console(Manager *m, const char *console);
+int manager_set_default_controllers(Manager *m, char **controllers);
 
 int manager_loop(Manager *m);
 
 
 int manager_loop(Manager *m);
 
index c6a7bf3df8b129b8d44810b9aaeaa8fe7703b96a..c94cf3601fb0cdfdd86e150ffa5d657a6cb707a3 100644 (file)
@@ -20,3 +20,4 @@
 #CPUAffinity=1 2
 #MountAuto=yes
 #SwapAuto=yes
 #CPUAffinity=1 2
 #MountAuto=yes
 #SwapAuto=yes
+#DefaultControllers=cpu
index bfb1dd644ebb62013d7f98cd23e112b9998f504b..7d673e138d291340b7eb334ea620bf51eb8060c7 100644 (file)
@@ -1785,55 +1785,61 @@ fail:
         return r;
 }
 
         return r;
 }
 
-int unit_add_default_cgroups(Unit *u) {
+static int unit_add_one_default_cgroup(Unit *u, const char *controller) {
         CGroupBonding *b = NULL;
         int r = -ENOMEM;
         CGroupBonding *b = NULL;
         int r = -ENOMEM;
-        const char * const default_controllers[] = {
-                SYSTEMD_CGROUP_CONTROLLER,
-                "cpu",
-                NULL
-        };
-        const char * const*c;
 
         assert(u);
 
 
         assert(u);
 
-        /* Adds in the default cgroups, if it wasn't specified yet */
-
-        STRV_FOREACH(c, default_controllers) {
-
-                if (cgroup_bonding_find_list(u->meta.cgroup_bondings, *c))
-                        continue;
+        if (!controller)
+                controller = SYSTEMD_CGROUP_CONTROLLER;
 
 
-                if (!(b = new0(CGroupBonding, 1)))
-                        return -ENOMEM;
+        if (cgroup_bonding_find_list(u->meta.cgroup_bondings, controller))
+                return 0;
 
 
-                if (!(b->path = default_cgroup_path(u)))
-                        goto fail;
+        if (!(b = new0(CGroupBonding, 1)))
+                return -ENOMEM;
 
 
-                if (!(b->controller = strdup(*c)))
-                        goto fail;
+        if (!(b->controller = strdup(controller)))
+                goto fail;
 
 
-                b->ours = true;
-                b->essential = c == default_controllers; /* the first one is essential */
+        if (!(b->path = default_cgroup_path(u)))
+                goto fail;
 
 
-                if ((r = unit_add_cgroup(u, b)) < 0)
-                        goto fail;
+        b->ours = true;
+        b->essential = streq(controller, SYSTEMD_CGROUP_CONTROLLER);
 
 
-                b = NULL;
-        }
+        if ((r = unit_add_cgroup(u, b)) < 0)
+                goto fail;
 
         return 0;
 
 fail:
 
         return 0;
 
 fail:
-        if (b) {
-                free(b->path);
-                free(b->controller);
-                free(b);
-        }
+        free(b->path);
+        free(b->controller);
+        free(b);
 
         return r;
 }
 
 
         return r;
 }
 
+int unit_add_default_cgroups(Unit *u) {
+        char **c;
+        int r;
+        assert(u);
+
+        /* Adds in the default cgroups, if they weren't specified
+         * otherwise. */
+
+        if ((r = unit_add_one_default_cgroup(u, NULL)) < 0)
+                return r;
+
+        STRV_FOREACH(c, u->meta.manager->default_controllers)
+                if ((r = unit_add_one_default_cgroup(u, *c)) < 0)
+                        return r;
+
+        return 0;
+}
+
 CGroupBonding* unit_get_default_cgroup(Unit *u) {
         assert(u);
 
 CGroupBonding* unit_get_default_cgroup(Unit *u) {
         assert(u);