[lxc-devel] [PATCH 1/1] cgroup: don't set clone_children when it is already 1

Stéphane Graber stgraber at ubuntu.com
Thu Dec 19 21:21:13 UTC 2013


On Thu, Dec 19, 2013 at 03:18:24PM -0600, Serge Hallyn wrote:
> In particular, if it's already 1, and we can't change it, we currently
> fail out.  That's silly.
> 
> I was going to just always continue, but if clone_children is not 1,
> then the container *will* fail to start later on, so I'd rather stop
> earlier on so the original cause doesn't get lost in the noise.
> 
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>

Acked-by: Stéphane Graber <stgraber at ubuntu.com>

> ---
>  src/lxc/cgroup.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
> index 8be0ebf..f2a686a 100644
> --- a/src/lxc/cgroup.c
> +++ b/src/lxc/cgroup.c
> @@ -1944,6 +1944,7 @@ int count_lines(const char *fn)
>  int handle_cgroup_settings(struct cgroup_mount_point *mp, char *cgroup_path)
>  {
>  	int r, saved_errno = 0;
> +	char buf[2];
>  
>  	/* If this is the memory cgroup, we want to enforce hierarchy.
>  	 * But don't fail if for some reason we can't.
> @@ -1951,9 +1952,12 @@ int handle_cgroup_settings(struct cgroup_mount_point *mp, char *cgroup_path)
>  	if (lxc_string_in_array("memory", (const char **)mp->hierarchy->subsystems)) {
>  		char *cc_path = cgroup_to_absolute_path(mp, cgroup_path, "/memory.use_hierarchy");
>  		if (cc_path) {
> -			r = lxc_write_to_file(cc_path, "1", 1, false);
> -			if (r < 0)
> -				SYSERROR("failed to set memory.use_hiararchy to 1; continuing");
> +			r = lxc_read_from_file(cc_path, buf, 1);
> +			if (r < 1 || buf[0] != '1') {
> +				r = lxc_write_to_file(cc_path, "1", 1, false);
> +				if (r < 0)
> +					SYSERROR("failed to set memory.use_hiararchy to 1; continuing");
> +			}
>  			free(cc_path);
>  		}
>  	}
> @@ -1966,6 +1970,11 @@ int handle_cgroup_settings(struct cgroup_mount_point *mp, char *cgroup_path)
>  		char *cc_path = cgroup_to_absolute_path(mp, cgroup_path, "/cgroup.clone_children");
>  		if (!cc_path)
>  			return -1;
> +		r = lxc_read_from_file(cc_path, buf, 1);
> +		if (r == 1 && buf[0] == '1') {
> +			free(cc_path);
> +			return 0;
> +		}
>  		r = lxc_write_to_file(cc_path, "1", 1, false);
>  		saved_errno = errno;
>  		free(cc_path);
> -- 
> 1.8.5.2
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20131219/d8aa8457/attachment.pgp>


More information about the lxc-devel mailing list