Linux Container Development
 help / color / mirror / Atom feed
  • [parent not found: <20100729195736.GA19015@hallyn.com>]
  • [parent not found: <20100729195812.GB19015@hallyn.com>]
  • * [PATCH 1/3] cgroup : add clone_children control file
    @ 2010-09-04  7:31 Daniel Lezcano
           [not found] ` <1283585466-30265-1-git-send-email-daniel.lezcano-GANU6spQydw@public.gmane.org>
      0 siblings, 1 reply; 14+ messages in thread
    From: Daniel Lezcano @ 2010-09-04  7:31 UTC (permalink / raw)
      To: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b
      Cc: Serge E. Hallyn,
    	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
    	Eric W. Biederman, menage-hpIqsD4AKlfQT0dZR+AlfA
    
    This patch is sent as an answer to a previous thread around the ns_cgroup.
    
    https://lists.linux-foundation.org/pipermail/containers/2009-June/018627.html
    
    It adds a control file 'clone_children' for a cgroup.
    This control file is a boolean specifying if the child cgroup should
    be a clone of the parent cgroup or not. The default value is 'false'.
    
    This flag makes the child cgroup to call the post_clone callback of all
    the subsystem, if it is available.
    
    At present, the cpuset is the only one which had implemented the post_clone
    callback.
    
    The option can be set at mount time by specifying the 'clone_children' mount
    option.
    
    Signed-off-by: Daniel Lezcano <daniel.lezcano-GANU6spQydw@public.gmane.org>
    Signed-off-by: Serge E. Hallyn <serge.hallyn-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
    Cc: Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
    Cc: Paul Menage <menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
    Reviewed-by: Li Zefan <lizf-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
    ---
     Documentation/cgroups/cgroups.txt |   14 +++++++++++-
     include/linux/cgroup.h            |    4 +++
     kernel/cgroup.c                   |   39 +++++++++++++++++++++++++++++++++++++
     3 files changed, 55 insertions(+), 2 deletions(-)
    
    diff --git a/Documentation/cgroups/cgroups.txt b/Documentation/cgroups/cgroups.txt
    index b34823f..190018b 100644
    --- a/Documentation/cgroups/cgroups.txt
    +++ b/Documentation/cgroups/cgroups.txt
    @@ -18,7 +18,8 @@ CONTENTS:
       1.2 Why are cgroups needed ?
       1.3 How are cgroups implemented ?
       1.4 What does notify_on_release do ?
    -  1.5 How do I use cgroups ?
    +  1.5 What does clone_children do ?
    +  1.6 How do I use cgroups ?
     2. Usage Examples and Syntax
       2.1 Basic Usage
       2.2 Attaching processes
    @@ -293,7 +294,16 @@ notify_on_release in the root cgroup at system boot is disabled
     value of their parents notify_on_release setting. The default value of
     a cgroup hierarchy's release_agent path is empty.
     
    -1.5 How do I use cgroups ?
    +1.5 What does clone_children do ?
    +---------------------------------
    +
    +If the clone_children flag is enabled (1) in a cgroup, then all
    +cgroups created beneath will call the post_clone callbacks for each
    +subsystem of the newly created cgroup. Usually when this callback is
    +implemented for a subsystem, it copies the values of the parent
    +subsystem, this is the case for the cpuset.
    +
    +1.6 How do I use cgroups ?
     --------------------------
     
     To start a new job that is to be contained within a cgroup, using
    diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
    index 3cb7d04..d01543b 100644
    --- a/include/linux/cgroup.h
    +++ b/include/linux/cgroup.h
    @@ -154,6 +154,10 @@ enum {
     	 * A thread in rmdir() is wating for this cgroup.
     	 */
     	CGRP_WAIT_ON_RMDIR,
    +	/*
    +	 * Clone cgroup values when creating a new child cgroup
    +	 */
    +	CGRP_CLONE_CHILDREN,
     };
     
     /* which pidlist file are we talking about? */
    diff --git a/kernel/cgroup.c b/kernel/cgroup.c
    index e5c5497..0473a9a 100644
    --- a/kernel/cgroup.c
    +++ b/kernel/cgroup.c
    @@ -229,6 +229,7 @@ inline int cgroup_is_removed(const struct cgroup *cgrp)
     /* bits in struct cgroupfs_root flags field */
     enum {
     	ROOT_NOPREFIX, /* mounted subsystems have no named prefix */
    +	ROOT_CLONE_CHILDREN, /* mounted subsystems will inherit from parent */
     };
     
     static int cgroup_is_releasable(const struct cgroup *cgrp)
    @@ -244,6 +245,11 @@ static int notify_on_release(const struct cgroup *cgrp)
     	return test_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
     }
     
    +static int clone_children(const struct cgroup *cgrp)
    +{
    +	return test_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
    +}
    +
     /*
      * for_each_subsys() allows you to iterate on each subsystem attached to
      * an active hierarchy
    @@ -1038,6 +1044,8 @@ static int cgroup_show_options(struct seq_file *seq, struct vfsmount *vfs)
     		seq_printf(seq, ",%s", ss->name);
     	if (test_bit(ROOT_NOPREFIX, &root->flags))
     		seq_puts(seq, ",noprefix");
    +	if (test_bit(ROOT_CLONE_CHILDREN, &root->flags))
    +		seq_puts(seq, ",clone_children");
     	if (strlen(root->release_agent_path))
     		seq_printf(seq, ",release_agent=%s", root->release_agent_path);
     	if (strlen(root->name))
    @@ -1097,6 +1105,8 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
     			opts->none = true;
     		} else if (!strcmp(token, "noprefix")) {
     			set_bit(ROOT_NOPREFIX, &opts->flags);
    +		} else if (!strcmp(token, "clone_children")) {
    +			set_bit(ROOT_CLONE_CHILDREN, &opts->flags);
     		} else if (!strncmp(token, "release_agent=", 14)) {
     			/* Specifying two release agents is forbidden */
     			if (opts->release_agent)
    @@ -1357,6 +1367,8 @@ static struct cgroupfs_root *cgroup_root_from_opts(struct cgroup_sb_opts *opts)
     		strcpy(root->release_agent_path, opts->release_agent);
     	if (opts->name)
     		strcpy(root->name, opts->name);
    +	if (test_bit(ROOT_CLONE_CHILDREN, &opts->flags))
    +		set_bit(CGRP_CLONE_CHILDREN, &root->top_cgroup.flags);
     	return root;
     }
     
    @@ -3175,6 +3187,23 @@ fail:
     	return ret;
     }
     
    +static u64 cgroup_clone_children_read(struct cgroup *cgrp,
    +				    struct cftype *cft)
    +{
    +	return clone_children(cgrp);
    +}
    +
    +static int cgroup_clone_children_write(struct cgroup *cgrp,
    +				     struct cftype *cft,
    +				     u64 val)
    +{
    +	if (val)
    +		set_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
    +	else
    +		clear_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
    +	return 0;
    +}
    +
     /*
      * for the common functions, 'private' gives the type of file
      */
    @@ -3205,6 +3234,11 @@ static struct cftype files[] = {
     		.write_string = cgroup_write_event_control,
     		.mode = S_IWUGO,
     	},
    +	{
    +		.name = "cgroup.clone_children",
    +		.read_u64 = cgroup_clone_children_read,
    +		.write_u64 = cgroup_clone_children_write,
    +	},
     };
     
     static struct cftype cft_release_agent = {
    @@ -3334,6 +3368,9 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
     	if (notify_on_release(parent))
     		set_bit(CGRP_NOTIFY_ON_RELEASE, &cgrp->flags);
     
    +	if (clone_children(parent))
    +		set_bit(CGRP_CLONE_CHILDREN, &cgrp->flags);
    +
     	for_each_subsys(root, ss) {
     		struct cgroup_subsys_state *css = ss->create(ss, cgrp);
     
    @@ -3348,6 +3385,8 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
     				goto err_destroy;
     		}
     		/* At error, ->destroy() callback has to free assigned ID. */
    +		if (clone_children(parent) && ss->post_clone)
    +			ss->post_clone(ss, cgrp);
     	}
     
     	cgroup_lock_hierarchy(root);
    -- 
    1.7.0.4
    
    ^ permalink raw reply related	[flat|nested] 14+ messages in thread

    end of thread, other threads:[~2010-09-07 20:24 UTC | newest]
    
    Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
    -- links below jump to the message on this page --
         [not found] <20100729195629.GA13378@hallyn.com>
         [not found] ` <20100729195629.GA13378-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
    2010-07-29 19:57   ` [PATCH 2/3] cgroup : make the mount options parsing more accurate Serge E. Hallyn
    2010-07-29 19:58   ` [PATCH 3/3] cgroup : remove the ns_cgroup Serge E. Hallyn
    2010-08-03  8:30   ` [PATCH 1/3] cgroup : add clone_children control file Li Zefan
         [not found] ` <20100729195736.GA19015@hallyn.com>
         [not found]   ` <20100729195736.GA19015-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
    2010-08-03  8:30     ` [PATCH 2/3] cgroup : make the mount options parsing more accurate Li Zefan
         [not found] ` <20100729195812.GB19015@hallyn.com>
         [not found]   ` <20100729214008.GA2785@count0.beaverton.ibm.com>
         [not found]     ` <20100729214008.GA2785-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
    2010-07-29 22:39       ` [PATCH 3/3] cgroup : remove the ns_cgroup Serge E. Hallyn
         [not found]     ` <20100729223957.GA12387@hallyn.com>
         [not found]       ` <20100729223957.GA12387-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
    2010-07-29 23:00         ` Remaining work for userns (WAS Re: [PATCH 3/3] cgroup : remove the ns_cgroup) Matt Helsley
         [not found]       ` <20100729230052.GB2785@count0.beaverton.ibm.com>
         [not found]         ` <20100729230052.GB2785-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
    2010-07-29 23:23           ` Serge E. Hallyn
         [not found]         ` <20100729232352.GC13902@hallyn.com>
         [not found]           ` <20100729232352.GC13902-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
    2010-07-31  0:23             ` Remaining work for userns Eric W. Biederman
         [not found]   ` <20100729195812.GB19015-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
    2010-07-29 21:40     ` [PATCH 3/3] cgroup : remove the ns_cgroup Matt Helsley
    2010-07-29 21:46     ` Paul Menage
    2010-08-03  8:31     ` Li Zefan
    2010-09-04  7:31 [PATCH 1/3] cgroup : add clone_children control file Daniel Lezcano
         [not found] ` <1283585466-30265-1-git-send-email-daniel.lezcano-GANU6spQydw@public.gmane.org>
    2010-09-04  7:31   ` [PATCH 2/3] cgroup : make the mount options parsing more accurate Daniel Lezcano
         [not found]     ` <1283585466-30265-2-git-send-email-daniel.lezcano-GANU6spQydw@public.gmane.org>
    2010-09-07 19:38       ` Paul Menage
         [not found]         ` <AANLkTi=2qWKXGBsqmbZjUs_H2VSDykheAABha079puT3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
    2010-09-07 20:24           ` Daniel Lezcano
    

    This is a public inbox, see mirroring instructions
    for how to clone and mirror all data and code used for this inbox