[lxc-devel] [PATCH] lxc-create: conside create succeed when container is already created

Stéphane Graber stgraber at ubuntu.com
Mon Sep 16 04:23:21 UTC 2013


On Mon, Sep 16, 2013 at 11:37:02AM +0800, Qiang Huang wrote:
> Sometimes we use:
> lxc-create -n xxx -f config
> to copy config to the default lxcpath with the rootfs already
> exist.
> But we will get error right now, so fix this.

Hmm, I'm not sure I understand.

Running "lxc-create -n xxx -f config" when xxx already exists is an
error and should return an error code so the current code seems
perfectly right to me.

The API should only return true if the requested action has been carried
out, in this case, creating a container xxx with config as its config
file. If the container already exists, it can't do that and so should
return false.

> 
> Signed-off-by: Qiang Huang <h.huangqiang at huawei.com>
> ---
>  src/lxc/lxccontainer.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 79237df..e8436cc 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -1018,9 +1018,15 @@ static bool lxcapi_create(struct lxc_container *c, const char *t,
>  		goto out;
>  	}
> 
> -	/* container is already created if we have a config and rootfs.path is accessible */
> -	if (lxcapi_is_defined(c) && c->lxc_conf && c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) == 0)
> +	/*
> +	 * Container is already created if we have a config and rootfs.path
> +	 * is accessible. We'll conside lxc_create succeed in this condition.
> +	 */
> +	if (lxcapi_is_defined(c) && c->lxc_conf && c->lxc_conf->rootfs.path &&
> +		access(c->lxc_conf->rootfs.path, F_OK) == 0) {
> +		bret = true;
>  		goto out;
> +	}
> 
>  	/* Mark that this container is being created */
>  	if ((partial_fd = create_partial(c)) < 0)
> -- 
> 1.8.3
> 

-- 
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/20130916/fcee9769/attachment.pgp>


More information about the lxc-devel mailing list