[lxc-devel] [PATCH 2/1] Use 'cgm listcontrollers' list rather than /proc/self/cgroups

Stéphane Graber stgraber at ubuntu.com
Tue May 26 15:12:52 UTC 2015


On Fri, May 01, 2015 at 09:11:28PM +0000, Serge Hallyn wrote:
> to populate the list of subsystems to use.
> 
> Cgmanager can be started with some subsystems disabled (i.e.
> cgmanager -M cpuset).  If lxc using cgmanager then uses the
> /proc/self/cgroup output to determine which controllers to use,
> it will fail when trying to do things to cpuset.  Instead, ask
> cgmanager which controllers to use.
> 
> This still defers (per patch 1/1) to the lxc.cgroup.use values.
> 
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>

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

> ---
>  src/lxc/cgmanager.c | 41 +++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 39 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c
> index c58f2e5..b2b3626 100644
> --- a/src/lxc/cgmanager.c
> +++ b/src/lxc/cgmanager.c
> @@ -818,6 +818,25 @@ out:
>  	return pids_len;
>  }
>  
> +static bool lxc_list_controllers(char ***list)
> +{
> +	if (!cgm_dbus_connect()) {
> +		ERROR("Error connecting to cgroup manager");
> +		return false;
> +	}
> +	if (cgmanager_list_controllers_sync(NULL, cgroup_manager, list) != 0) {
> +		NihError *nerr;
> +		nerr = nih_error_get();
> +		ERROR("call to cgmanager_list_controllers_sync failed: %s", nerr->message);
> +		nih_free(nerr);
> +		cgm_dbus_disconnect();
> +		return false;
> +	}
> +
> +	cgm_dbus_disconnect();
> +	return true;
> +}
> +
>  static inline void free_abs_cgroup(char *cgroup)
>  {
>  	if (!cgroup)
> @@ -1166,8 +1185,9 @@ static bool verify_and_prune(const char *cgroup_use)
>  static bool collect_subsytems(void)
>  {
>  	char *line = NULL;
> +	nih_local char **cgm_subsys_list = NULL;
>  	size_t sz = 0;
> -	FILE *f;
> +	FILE *f = NULL;
>  
>  	if (subsystems) // already initialized
>  		return true;
> @@ -1178,6 +1198,20 @@ static bool collect_subsytems(void)
>  	subsystems_inone[0] = "all";
>  	subsystems_inone[1] = NULL;
>  
> +	if (lxc_list_controllers(&cgm_subsys_list)) {
> +		while (cgm_subsys_list[nr_subsystems]) {
> +			char **tmp = NIH_MUST( realloc(subsystems,
> +						(nr_subsystems+2)*sizeof(char *)) );
> +			tmp[nr_subsystems] = NIH_MUST(
> +					strdup(cgm_subsys_list[nr_subsystems++]) );
> +			subsystems = tmp;
> +		}
> +		if (nr_subsystems)
> +			subsystems[nr_subsystems] = NULL;
> +		goto collected;
> +	}
> +
> +	INFO("cgmanager_list_controllers failed, falling back to /proc/self/cgroups");
>  	f = fopen_cloexec("/proc/self/cgroup", "r");
>  	if (!f) {
>  		f = fopen_cloexec("/proc/1/cgroup", "r");
> @@ -1219,6 +1253,8 @@ static bool collect_subsytems(void)
>  	fclose(f);
>  
>  	free(line);
> +
> +collected:
>  	if (!nr_subsystems) {
>  		ERROR("No cgroup subsystems found");
>  		return false;
> @@ -1240,7 +1276,8 @@ out_good:
>  
>  out_free:
>  	free(line);
> -	fclose(f);
> +	if (f)
> +		fclose(f);
>  	free_subsystems();
>  	return false;
>  }
> -- 
> 2.1.4
> 
> _______________________________________________
> 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: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20150526/7460e2b0/attachment.sig>


More information about the lxc-devel mailing list