On 10/10/2011 08:27 PM, Vivek Goyal wrote: > On Fri, Sep 23, 2011 at 03:52:46PM +0200, Jan Safranek wrote: >> groups >> >> New flag CGFLAG_DELETE_EMPTY_ONLY tells cgroup_delete_cgroup_ext that the >> group being deleted must be empty, i.e. have no subgroups and no tasks >> inside. >> >> Signed-off-by: Jan Safranek <jsafr...@redhat.com> >> --- >> >> include/libcgroup/groups.h | 7 +++ >> src/api.c | 114 >> +++++++++++++++++++++++++------------------- >> 2 files changed, 71 insertions(+), 50 deletions(-) >> >> diff --git a/include/libcgroup/groups.h b/include/libcgroup/groups.h >> index 86c5b76..f375a82 100644 >> --- a/include/libcgroup/groups.h >> +++ b/include/libcgroup/groups.h >> @@ -26,6 +26,13 @@ enum cgroup_delete_flag { >> * Recursively delete all child groups. >> */ >> CGFLAG_DELETE_RECURSIVE = 2, >> + >> + /** >> + * Delete the cgroup only if it is empty, i.e. it has no subgroups and >> + * no processes inside. This flag cannot be used with >> + * CGFLAG_DELETE_RECURSIVE. >> + */ >> + CGFLAG_DELETE_EMPTY_ONLY = 4, >> }; >> >> /** >> diff --git a/src/api.c b/src/api.c >> index f6f806e..769c080 100644 >> --- a/src/api.c >> +++ b/src/api.c >> @@ -1856,30 +1856,33 @@ static int cg_delete_cgroup_controller(char >> *cgroup_name, char *controller, >> >> cgroup_dbg("Removing group %s:%s\n", controller, cgroup_name); >> >> - /* >> - * Open tasks file of the group to delete. >> - */ >> - if (!cg_build_path(cgroup_name, path, controller)) >> - return ECGROUPSUBSYSNOTMOUNTED; >> - strncat(path, "tasks", sizeof(path) - strlen(path)); >> - >> - delete_tasks = fopen(path, "re"); >> - if (delete_tasks) { >> - ret = cg_move_task_files(delete_tasks, target_tasks); >> - fclose(delete_tasks); >> - } else { >> + if (!(flags & CGFLAG_DELETE_EMPTY_ONLY)) { >> /* > > Will it make sense to introduce a function to check for empty cgroup and > return if CGFLAG_DELETE_EMPTY_ONLY is set but cgroup is not empty. It > does involve little extra processing but also makes the code little > simpler.
The idea here was to let rmdir() if it succeeds or not. Cgroups infrastructure is inherently racy, there is no way, how to check if a group is empty and then ensure it stays empty until rmdir(). > > I think same holds good for other changes in cgroup_delete_cgroup_ext(). > > Thanks > Vivek ------------------------------------------------------------------------------ RSA® Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1 _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel