[systemd-commits] 5 commits - TODO src/core src/shared src/test

Lennart Poettering lennart at kemper.freedesktop.org
Thu Jul 11 09:50:10 PDT 2013


 TODO                        |    4 +-
 src/core/cgroup.c           |    9 ++++--
 src/core/unit.c             |   63 ++++++++++++++++++++++++++++----------------
 src/shared/cgroup-util.c    |   24 ++--------------
 src/test/test-cgroup-util.c |   23 +++++++++-------
 5 files changed, 66 insertions(+), 57 deletions(-)

New commits:
commit 05b23cae8ebf6fbafd23ab8a0b0cfed747745d15
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jul 11 18:49:44 2013 +0200

    update TODO

diff --git a/TODO b/TODO
index 8645161..34634fb 100644
--- a/TODO
+++ b/TODO
@@ -36,6 +36,8 @@ Fedora 19:
 
 CGroup Rework Completion:
 
+* systemctl user.slice doesn't show the full tree?
+
 * introduce "mainpid" for scopes
 
 * implement system-wide DefaultCPUAccounting=1 switch (and similar for blockio, memory?)
@@ -48,8 +50,6 @@ CGroup Rework Completion:
 
 * fix machine regstration to forward property array
 
-* add implicit slice for instantiated services
-
 * make BlockIODeviceWeight=, BlockIODeviceBandwidth= runtime settable
 
 * split up BlockIOWeight= and BlockIODeviceWeight=

commit d7bd3de0654669e65b9642c248c5fa6d1d9a9f61
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jul 11 18:47:20 2013 +0200

    cgroup: simplify how instantiated units are mapped to cgroups
    
    Previously for an instantiated unit foo at bar.service we created a cgroup
    foo at .service/foo at bar.service, in order to place all instances of the
    same template inside the same subtree. As we now implicitly add all
    instantiated units into one per-template slice we don't need this
    complexity anymore, and instance units can map directly to the cgroups
    of their full name.

diff --git a/src/core/unit.c b/src/core/unit.c
index bfde08d..8645285 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -1991,7 +1991,7 @@ char *unit_dbus_path(Unit *u) {
 }
 
 char *unit_default_cgroup_path(Unit *u) {
-        _cleanup_free_ char *escaped_instance = NULL, *slice = NULL;
+        _cleanup_free_ char *escaped = NULL, *slice = NULL;
         int r;
 
         assert(u);
@@ -2005,28 +2005,14 @@ char *unit_default_cgroup_path(Unit *u) {
                         return NULL;
         }
 
-        escaped_instance = cg_escape(u->id);
-        if (!escaped_instance)
+        escaped = cg_escape(u->id);
+        if (!escaped)
                 return NULL;
 
-        if (u->instance) {
-                _cleanup_free_ char *t = NULL, *escaped_template = NULL;
-
-                t = unit_name_template(u->id);
-                if (!t)
-                        return NULL;
-
-                escaped_template = cg_escape(t);
-                if (!escaped_template)
-                        return NULL;
-
-                return strjoin(u->manager->cgroup_root, "/",
-                               slice ? slice : "", slice ? "/" : "",
-                               escaped_template, "/", escaped_instance, NULL);
-        } else
-                return strjoin(u->manager->cgroup_root, "/",
-                               slice ? slice : "", slice ? "/" : "",
-                               escaped_instance, NULL);
+        if (slice)
+                return strjoin(u->manager->cgroup_root, "/", slice, "/", escaped, NULL);
+        else
+                return strjoin(u->manager->cgroup_root, "/", escaped, NULL);
 }
 
 int unit_add_default_slice(Unit *u) {
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 8f3c64f..1d545e0 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -1126,7 +1126,7 @@ int cg_pid_get_path_shifted(pid_t pid, char **root, char **cgroup) {
 }
 
 int cg_path_decode_unit(const char *cgroup, char **unit){
-        char *p, *e, *c, *s, *k;
+        char *e, *c, *s;
 
         assert(cgroup);
         assert(unit);
@@ -1135,28 +1135,10 @@ int cg_path_decode_unit(const char *cgroup, char **unit){
         c = strndupa(cgroup, e - cgroup);
         c = cg_unescape(c);
 
-        /* Could this be a valid unit name? */
-        if (!unit_name_is_valid(c, true))
+        if (!unit_name_is_valid(c, false))
                 return -EINVAL;
 
-        if (!unit_name_is_template(c))
-                s = strdup(c);
-        else {
-                if (*e != '/')
-                        return -EINVAL;
-
-                e += strspn(e, "/");
-
-                p = strchrnul(e, '/');
-                k = strndupa(e, p - e);
-                k = cg_unescape(k);
-
-                if (!unit_name_is_valid(k, false))
-                        return -EINVAL;
-
-                s = strdup(k);
-        }
-
+        s = strdup(c);
         if (!s)
                 return -ENOMEM;
 
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index ed2c6ae..295bb02 100644
--- a/src/test/test-cgroup-util.c
+++ b/src/test/test-cgroup-util.c
@@ -32,12 +32,15 @@ static void check_p_d_u(const char *path, int code, const char *result) {
 }
 
 static void test_path_decode_unit(void) {
-        check_p_d_u("getty at .service/getty at tty2.service", 0, "getty at tty2.service");
-        check_p_d_u("getty at .service/getty at tty2.service/xxx", 0, "getty at tty2.service");
+        check_p_d_u("getty at tty2.service", 0, "getty at tty2.service");
+        check_p_d_u("getty at tty2.service/", 0, "getty at tty2.service");
+        check_p_d_u("getty at tty2.service/xxx", 0, "getty at tty2.service");
         check_p_d_u("getty at .service/", -EINVAL, NULL);
         check_p_d_u("getty at .service", -EINVAL, NULL);
         check_p_d_u("getty.service", 0, "getty.service");
         check_p_d_u("getty", -EINVAL, NULL);
+        check_p_d_u("getty/waldo", -EINVAL, NULL);
+        check_p_d_u("_cpu.service", 0, "cpu.service");
 }
 
 static void check_p_g_u(const char *path, int code, const char *result) {
@@ -49,13 +52,14 @@ static void check_p_g_u(const char *path, int code, const char *result) {
 
 static void test_path_get_unit(void) {
         check_p_g_u("/system.slice/foobar.service/sdfdsaf", 0, "foobar.service");
-        check_p_g_u("/system.slice/getty at .service/getty at tty5.service", 0, "getty at tty5.service");
-        check_p_g_u("/system.slice/getty at .service/getty at tty5.service/aaa/bbb", 0, "getty at tty5.service");
-        check_p_g_u("/system.slice/getty at .service/getty at tty5.service/", 0, "getty at tty5.service");
+        check_p_g_u("/system.slice/getty at tty5.service", 0, "getty at tty5.service");
+        check_p_g_u("/system.slice/getty at tty5.service/aaa/bbb", 0, "getty at tty5.service");
+        check_p_g_u("/system.slice/getty at tty5.service/", 0, "getty at tty5.service");
         check_p_g_u("/system.slice/getty at tty6.service/tty5", 0, "getty at tty6.service");
         check_p_g_u("sadfdsafsda", -EINVAL, NULL);
-        check_p_g_u("/system.slice/getty####@tty6.service/tty5", -EINVAL, NULL);
+        check_p_g_u("/system.slice/getty####@tty6.service/xxx", -EINVAL, NULL);
         check_p_g_u("/system.slice/system-waldo.slice/foobar.service/sdfdsaf", 0, "foobar.service");
+        check_p_g_u("/system.slice/system-waldo.slice/_cpu.service/sdfdsaf", 0, "cpu.service");
 }
 
 static void check_p_g_u_u(const char *path, int code, const char *result) {
@@ -71,10 +75,11 @@ static void test_path_get_user_unit(void) {
         check_p_g_u_u("/user.slice/user-1002.slice/session-2.scope/foobar.service/waldo", 0, "foobar.service");
         check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar.service/waldo/uuuux", 0, "foobar.service");
         check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/waldo/waldo/uuuux", -EINVAL, NULL);
-        check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar at .service/foobar at pie.service/pa/po", 0, "foobar at pie.service");
-        check_p_g_u_u("/session-2.scope/foobar at .service/foobar at pie.service/pa/po", 0, "foobar at pie.service");
-        check_p_g_u_u("/xyz.slice/xyz-waldo.slice/session-77.scope/foobar at .service/foobar at pie.service/pa/po", 0, "foobar at pie.service");
+        check_p_g_u_u("/user.slice/user-1000.slice/session-2.scope/foobar at pie.service/pa/po", 0, "foobar at pie.service");
+        check_p_g_u_u("/session-2.scope/foobar at pie.service/pa/po", 0, "foobar at pie.service");
+        check_p_g_u_u("/xyz.slice/xyz-waldo.slice/session-77.scope/foobar at pie.service/pa/po", 0, "foobar at pie.service");
         check_p_g_u_u("/meh.service", -ENOENT, NULL);
+        check_p_g_u_u("/session-3.scope/_cpu.service", 0, "cpu.service");
 }
 
 static void check_p_g_s(const char *path, int code, const char *result) {

commit 8a84192905a9845fda31b65cc433127f9c2f95ae
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jul 11 18:42:12 2013 +0200

    cgroup: don't ever try to destroy the cgroup of the root slice
    
    The root slice is after all the root cgroup, so don't attempt to delete
    it.

diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index b9ef00c..d0f36cb 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -531,7 +531,7 @@ void unit_destroy_cgroup(Unit *u) {
         if (!u->cgroup_path)
                 return;
 
-        r = cg_trim_with_mask(u->cgroup_mask, u->cgroup_path, true);
+        r = cg_trim_with_mask(u->cgroup_mask, u->cgroup_path, !unit_has_name(u, SPECIAL_ROOT_SLICE));
         if (r < 0)
                 log_debug("Failed to destroy cgroup %s: %s", u->cgroup_path, strerror(-r));
 

commit be2c1bd2a843aa61901086fccbae15b3aa085fb1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jul 11 18:37:14 2013 +0200

    cgroup: don't move systemd into systems.slice when running as --user instance

diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index b5d1347..b9ef00c 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -638,8 +638,11 @@ int manager_setup_cgroup(Manager *m) {
         }
 
         /* 4. Realize the system slice and put us in there */
-        a = strappenda(m->cgroup_root, "/" SPECIAL_SYSTEM_SLICE);
-        r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, a, 0);
+        if (m->running_as == SYSTEMD_SYSTEM) {
+                a = strappenda(m->cgroup_root, "/" SPECIAL_SYSTEM_SLICE);
+                r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, a, 0);
+        } else
+                r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, 0);
         if (r < 0) {
                 log_error("Failed to create root cgroup hierarchy: %s", strerror(-r));
                 return r;

commit a8833944647bfd10e43569646be954db5cbac54e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu Jul 11 03:52:43 2013 +0200

    core: implicitly create a per-template slice for all instantiated units by default
    
    If no explicit slice is configured for an instantiated unit, create an
    implicit one for all instances of the same template.

diff --git a/src/core/unit.c b/src/core/unit.c
index 5bc57e2..bfde08d 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2030,6 +2030,8 @@ char *unit_default_cgroup_path(Unit *u) {
 }
 
 int unit_add_default_slice(Unit *u) {
+        _cleanup_free_ char *b = NULL;
+        const char *slice_name;
         Unit *slice;
         int r;
 
@@ -2041,7 +2043,38 @@ int unit_add_default_slice(Unit *u) {
         if (!unit_get_cgroup_context(u))
                 return 0;
 
-        r = manager_load_unit(u->manager, u->manager->running_as == SYSTEMD_SYSTEM ? SPECIAL_SYSTEM_SLICE : SPECIAL_ROOT_SLICE, NULL, NULL, &slice);
+        if (u->instance) {
+                _cleanup_free_ char *prefix = NULL, *escaped = NULL;
+                        ;
+                /* Implicitly place all instantiated units in their
+                 * own per-template slice */
+
+                prefix = unit_name_to_prefix(u->id);
+                if (!prefix)
+                        return -ENOMEM;
+
+                /* The prefix is already escaped, but it might include
+                 * "-" which has a special meaning for slice units,
+                 * hence escape it here extra. */
+                escaped = strreplace(prefix, "-", "\\x2d");
+                if (!escaped)
+                        return -ENOMEM;
+
+                if (u->manager->running_as == SYSTEMD_SYSTEM)
+                        b = strjoin("system-", escaped, ".slice", NULL);
+                else
+                        b = strappend(escaped, ".slice");
+                if (!b)
+                        return -ENOMEM;
+
+                slice_name = b;
+        } else
+                slice_name =
+                        u->manager->running_as == SYSTEMD_SYSTEM
+                        ? SPECIAL_SYSTEM_SLICE
+                        : SPECIAL_ROOT_SLICE;
+
+        r = manager_load_unit(u->manager, slice_name, NULL, NULL, &slice);
         if (r < 0)
                 return r;
 



More information about the systemd-commits mailing list