<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Oct 25, 2013 at 9:55 PM, Serge Hallyn <span dir="ltr"><<a href="mailto:serge.hallyn@ubuntu.com" target="_blank">serge.hallyn@ubuntu.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Quoting Sheng Yong (<a href="mailto:shyodx@gmail.com">shyodx@gmail.com</a>):<br>
> [code] ### lxccontainer.c: 1111<br>
> if (lxcapi_is_defined(c) && c->lxc_conf && c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) == 0)<br>
>       goto out;<br>
> [/code]<br>
><br>
>       If lxc.rootfs is set and no failure happens before we check<br>
>       whether the container is already created, the condition will be<br>
>       always true. In "out" section, lxcapi_destroy() is called to<br>
>       remove rootfs directory indicated by lxc.rootfs.<br>
><br>
>       If lxc.rootfs is set, we believe that rootfs is ready. Then the<br>
>       creation should be successful.<br>
><br>
> NOTE: the situation where both -t options and lxc.rootfs are set should<br>
> be considered.<br>
<br>
</div>Hi,<br>
<br>
thanks for the patch.  Please sign off commits in the future (you can do<br>
this using 'git commit -s').  However, nack to this particular version.<br>
How about the below alternative?<br></blockquote><div>This is much better. Thanks for giving me the suggestion :-)<br><br></div><div>regards,<br>shyodx<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<br>
Subject: [PATCH 1/1] lxcapi_create: don't delete if container already exists<br>
<br>
1. don't save the starting config until we've ensured the container<br>
   does noet yet exist.<br>
2. If the container exists, return false (because creation did not<br>
   happen) but don't delete the container.<br>
<br>
Signed-off-by: Serge Hallyn <<a href="mailto:serge.hallyn@ubuntu.com">serge.hallyn@ubuntu.com</a>><br>
Cc: Sheng Yong <<a href="mailto:shyodx@gmail.com">shyodx@gmail.com</a>><br>
---<br>
 src/lxc/lxccontainer.c | 13 ++++++++-----<br>
 1 file changed, 8 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c<br>
index 9aea614..6699e9c 100644<br>
--- a/src/lxc/lxccontainer.c<br>
+++ b/src/lxc/lxccontainer.c<br>
@@ -1090,6 +1090,7 @@ static bool lxcapi_create(struct lxc_container *c, const char *t,<br>
        pid_t pid;<br>
        char *tpath = NULL;<br>
        int partial_fd;<br>
+       bool delete_on_err = false;<br>
<br>
        if (!c)<br>
                return false;<br>
@@ -1102,15 +1103,17 @@ static bool lxcapi_create(struct lxc_container *c, const char *t,<br>
                }<br>
        }<br>
<br>
+       /* container is already created if we have a config and rootfs.path is accessible */<br>
<div class="im">+       if (lxcapi_is_defined(c) && c->lxc_conf && c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) == 0)<br>
</div>+               goto out;<br>
+<br>
+       delete_on_err = true;<br>
+<br>
        if (!c->save_config(c, NULL)) {<br>
                ERROR("failed to save starting configuration for %s\n", c->name);<br>
                goto out;<br>
        }<br>
<br>
-       /* container is already created if we have a config and rootfs.path is accessible */<br>
<div class="im">-       if (lxcapi_is_defined(c) && c->lxc_conf && c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) == 0)<br>
</div>-               goto out;<br>
-<br>
<div class="im">        /* Mark that this container is being created */<br>
        if ((partial_fd = create_partial(c)) < 0)<br>
</div>                goto out;<br>
@@ -1183,7 +1186,7 @@ out_unlock:<br>
 out:<br>
        if (tpath)<br>
                free(tpath);<br>
-       if (!bret && c)<br>
+       if (delete_on_err && !bret && c)<br>
                lxcapi_destroy(c);<br>
        return bret;<br>
 }<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.2<br>
<br>
</font></span></blockquote></div><br></div></div>