diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-02-27 18:50:41 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-02-27 18:50:41 +0100 |
commit | 26d04f86a36595e3565c74d67863e076c3e3c773 (patch) | |
tree | 374ba1bdf5dfc95a9c05df1232ffc44d8bd98397 /src/core/cgroup-attr.c | |
parent | 416389f7ae262ae7a0848302e7a6516597f9fad1 (diff) |
unit: rework resource management API
This introduces a new static list of known attributes and their special
semantics. This means that cgroup attribute values can now be
automatically translated from user to kernel notation for command line
set settings, too.
This also adds proper support for multi-line attributes.
Diffstat (limited to 'src/core/cgroup-attr.c')
-rw-r--r-- | src/core/cgroup-attr.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/core/cgroup-attr.c b/src/core/cgroup-attr.c index 1373684bdb..2ab4d4623e 100644 --- a/src/core/cgroup-attr.c +++ b/src/core/cgroup-attr.c @@ -25,8 +25,8 @@ #include "fileio.h" int cgroup_attribute_apply(CGroupAttribute *a, CGroupBonding *b) { - int r; _cleanup_free_ char *path = NULL, *v = NULL; + int r; assert(a); @@ -34,8 +34,8 @@ int cgroup_attribute_apply(CGroupAttribute *a, CGroupBonding *b) { if (!b) return 0; - if (a->map_callback) { - r = a->map_callback(a->controller, a->name, a->value, &v); + if (a->semantics && a->semantics->map_write) { + r = a->semantics->map_write(a->semantics, a->value, &v); if (r < 0) return r; } @@ -66,6 +66,29 @@ int cgroup_attribute_apply_list(CGroupAttribute *first, CGroupBonding *b) { return r; } +bool cgroup_attribute_matches(CGroupAttribute *a, const char *controller, const char *name) { + assert(a); + + if (controller) { + if (streq(a->controller, controller) && (!name || streq(a->name, name))) + return true; + + } else if (!name) + return true; + else if (streq(a->name, name)) { + size_t x, y; + x = strlen(a->controller); + y = strlen(name); + + if (y > x && + memcmp(a->controller, name, x) == 0 && + name[x] == '.') + return true; + } + + return false; +} + CGroupAttribute *cgroup_attribute_find_list( CGroupAttribute *first, const char *controller, @@ -74,24 +97,9 @@ CGroupAttribute *cgroup_attribute_find_list( assert(name); - LIST_FOREACH(by_unit, a, first) { - - - if (controller) { - if (streq(a->controller, controller) && streq(a->name, name)) - return a; - - } else if (streq(a->name, name)) { - size_t x, y; - x = strlen(a->controller); - y = strlen(name); - - if (y > x && - memcmp(a->controller, name, x) == 0 && - name[x] == '.') - return a; - } - } + LIST_FOREACH(by_unit, a, first) + if (cgroup_attribute_matches(a, controller, name)) + return a; return NULL; } @@ -114,3 +122,11 @@ void cgroup_attribute_free_list(CGroupAttribute *first) { LIST_FOREACH_SAFE(by_unit, a, n, first) cgroup_attribute_free(a); } + +void cgroup_attribute_free_some(CGroupAttribute *first, const char *controller, const char *name) { + CGroupAttribute *a, *n; + + LIST_FOREACH_SAFE(by_unit, a, n, first) + if (cgroup_attribute_matches(a, controller, name)) + cgroup_attribute_free(a); +} |