From fb385181517aa97fc5b379380cde0c2567f5f444 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 10 Jul 2010 17:34:42 +0200 Subject: [PATCH] unit: trim cgroups when going down --- src/cgroup.c | 14 ++++++++++++++ src/cgroup.h | 3 +++ src/unit.c | 3 +++ 3 files changed, 20 insertions(+) diff --git a/src/cgroup.c b/src/cgroup.c index 27130a9c..244a6020 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -101,6 +101,20 @@ void cgroup_bonding_free_list(CGroupBonding *first) { cgroup_bonding_free(b); } +void cgroup_bonding_trim(CGroupBonding *b, bool delete_root) { + assert(b); + + if (b->realized && b->only_us && b->clean_up) + cg_trim(b->controller, b->path, delete_root); +} + +void cgroup_bonding_trim_list(CGroupBonding *first, bool delete_root) { + CGroupBonding *b; + + LIST_FOREACH(by_unit, b, first) + cgroup_bonding_trim(b, delete_root); +} + int cgroup_bonding_install(CGroupBonding *b, pid_t pid) { int r; diff --git a/src/cgroup.h b/src/cgroup.h index 11d2aba8..05c858c4 100644 --- a/src/cgroup.h +++ b/src/cgroup.h @@ -61,6 +61,9 @@ int cgroup_bonding_install_list(CGroupBonding *first, pid_t pid); int cgroup_bonding_kill(CGroupBonding *b, int sig); int cgroup_bonding_kill_list(CGroupBonding *first, int sig); +void cgroup_bonding_trim(CGroupBonding *first, bool delete_root); +void cgroup_bonding_trim_list(CGroupBonding *first, bool delete_root); + int cgroup_bonding_is_empty(CGroupBonding *b); int cgroup_bonding_is_empty_list(CGroupBonding *first); diff --git a/src/unit.c b/src/unit.c index c287310a..18faae22 100644 --- a/src/unit.c +++ b/src/unit.c @@ -973,6 +973,9 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns) { if (ns != os && ns == UNIT_MAINTENANCE) log_notice("Unit %s entered maintenance state.", u->meta.id); + if (UNIT_IS_INACTIVE_OR_MAINTENANCE(ns)) + cgroup_bonding_trim_list(u->meta.cgroup_bondings, true); + timer_unit_notify(u, ns); path_unit_notify(u, ns); -- 2.39.5