[lxc-devel] [PATCH] API shouldn't be calling create for already defined containers or destroy for non defined ones.

Stéphane Graber stgraber at ubuntu.com
Sun Mar 31 21:22:46 UTC 2013


On 03/31/2013 04:22 PM, S.Çağlar Onur wrote:
> From: "S.Çağlar Onur" <caglar at 10ur.org>
> 
> Currently it behaves like following which might be confusing for the code that checks the return value of those calls to determine whether operation completed successfully or not.
> 
>>> c = lxc.Container("r")
>>>> c.create("ubuntu")
> True
>>>> c.create("ubuntu")
> True
>>>> c.create("ubuntu")
> True
>>>> c.create("ubuntu")
> True
>>>> c.create("ubuntu")
>>>> c.destroy()
> True
>>>> c.destroy()
> lxc-destroy: 'r' does not exist
> False
>>>> c.destroy()
> lxc-destroy: 'r' does not exist
> False
> 
> New behaviour
> 
>>>> c = lxc.Container("r")
>>>> c.create('ubuntu')
> True
>>>> c.create('ubuntu')
> False
>>>> c.destroy()
> True
>>>> c.destroy()
> False
>>>>


Won't this break the following?
c = lxc.Container("abcdef")
c.set_config_item("lxc.utsname", "blah")
c.save_config()
c.create("ubuntu")

I personally always considered ".create()" to mean "generate a new
rootfs" which doesn't at all mean "generate a new config file".

".destroy()" on the other hand destroys everything, including the config.



> Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>
> ---
>  src/lxc/lxccontainer.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 480c4f5..7a11c85 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -508,7 +508,7 @@ static bool lxcapi_create(struct lxc_container *c, char *t, char *const argv[])
>  	int len, nargs = 0;
>  	char **newargv;
>  
> -	if (!c)
> +	if (!c || lxcapi_is_defined(c))
>  		return false;
>  
>  	len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;
> @@ -785,7 +785,7 @@ static bool lxcapi_destroy(struct lxc_container *c)
>  	pid_t pid;
>  	int ret, status;
>  
> -	if (!c)
> +	if (!c || !lxcapi_is_defined(c))
>  		return false;
>  
>  	pid = fork();
> 


-- 
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: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130331/8c9e302f/attachment.pgp>


More information about the lxc-devel mailing list