[lxc-devel] [PATCH RFC] api_start: don't get a container reference for the daemonized case

Qiang Huang h.huangqiang at huawei.com
Mon Jan 20 07:03:48 UTC 2014


On 2014/1/20 2:17, Serge Hallyn wrote:
> In the daemonized case we will fork, so the anonymous container memlock
> will not be shared between parent and child.

I'm basically agree with this patch.

And I'm also confused about why we need this lxc_container_get
in the first place. Seems like it only work for multi-threads cases,
not this fork() case, because any writing lxc_container will cause
COW, and father's lxc_container_free won't affect child.

After a bit dig, I found this is the only place where uses
lxc_container_get(there are two more in test code, not necessary), so
maybe we can just remove this api till we really need it?

Or maybe I'm missing something, hope somebody clear me up. :)

> 
> Please review.
> 
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
> ---
>  src/lxc/lxccontainer.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 0bebdff..0e22ccf 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -583,15 +583,11 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv
>  	* while container is running...
>  	*/
>  	if (daemonize) {
> -		if (!lxc_container_get(c))
> -			return false;
>  		lxc_monitord_spawn(c->config_path);
>  
>  		pid_t pid = fork();
> -		if (pid < 0) {
> -			lxc_container_put(c);
> +		if (pid < 0)
>  			return false;
> -		}
>  		if (pid != 0)
>  			return wait_on_daemonized_start(c, pid);
>  
> @@ -632,12 +628,10 @@ reboot:
>  		goto reboot;
>  	}
>  
> -	if (daemonize) {
> -		lxc_container_put(c);

Can we leave this put operation here to free lxc_container? Although this
is not a really memory leak, but for this process, it still have
numthreads = 1 and have no where to minus it.

> +	if (daemonize)
>  		exit (ret == 0 ? true : false);
> -	} else {
> +	else
>  		return (ret == 0 ? true : false);
> -	}
>  }
>  
>  /*
> 




More information about the lxc-devel mailing list