<div dir="ltr">Yeah I realized that, I'll send the github url in a moment</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Apr 1, 2013 at 12:12 AM, 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 S.Çağlar Onur (<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>):<br>
> Seems like I sent the wrong path, this one works for me.<br>
<br>
</div>note your emails are coming through as html and malformed txt, which<br>
will be harder to apply. Would you mind posting a github url?<br>
<br>
The lxc-destroy modifications make me a bit uneasy, but they should be<br>
ok.<br>
<div class="im"><br>
Acked-by: Serge E. Hallyn <<a href="mailto:serge.hallyn@ubuntu.com">serge.hallyn@ubuntu.com</a>><br>
<br>
</div><div><div class="h5">> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c<br>
> index 480c4f5..9ed3443 100644<br>
> --- a/src/lxc/lxccontainer.c<br>
> +++ b/src/lxc/lxccontainer.c<br>
> @@ -523,14 +523,15 @@ static bool lxcapi_create(struct lxc_container *c,<br>
> char *t, char *const argv[])<br>
> goto out;<br>
> }<br>
><br>
> - if (!create_container_dir(c))<br>
> - goto out;<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<br>
> accessible */<br>
> + if (c->lxc_conf && c->lxc_conf->rootfs.path &&<br>
> access(c->lxc_conf->rootfs.path, F_OK) == 0)<br>
> + return false;<br>
> +<br>
> /* we're going to fork. but since we'll wait for our child, we<br>
> don't need to lxc_container_get */<br>
><br>
> @@ -767,6 +768,9 @@ static bool lxcapi_save_config(struct lxc_container *c,<br>
> const char *alt_file)<br>
> return false;<br>
> }<br>
><br>
> + if (!create_container_dir(c))<br>
> + return false;<br>
> +<br>
> FILE *fout = fopen(alt_file, "w");<br>
> if (!fout)<br>
> return false;<br>
> @@ -788,6 +792,10 @@ static bool lxcapi_destroy(struct lxc_container *c)<br>
> if (!c)<br>
> return false;<br>
><br>
> + /* container is already destroyed if we don't have a config or<br>
> rootfs.path is not accessible */<br>
> + if (!c->lxc_conf || !c->lxc_conf->rootfs.path ||<br>
> access(c->lxc_conf->rootfs.path, F_OK) != 0)<br>
> + return false;<br>
> +<br>
> pid = fork();<br>
> if (pid < 0)<br>
> return false;<br>
><br>
><br>
> On Sun, Mar 31, 2013 at 7:56 PM, S.Çağlar Onur <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>> wrote:<br>
><br>
> > What about something like following?<br>
> ><br>
> > diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c<br>
> > index 480c4f5..eb99e5a 100644<br>
> > --- a/src/lxc/lxccontainer.c<br>
> > +++ b/src/lxc/lxccontainer.c<br>
> > @@ -508,7 +508,7 @@ static bool lxcapi_create(struct lxc_container *c,<br>
> > char *t, char *const argv[])<br>
> > int len, nargs = 0;<br>
> > char **newargv;<br>
> ><br>
> > - if (!c)<br>
> > + if (!c || access(c->lxc_conf->rootfs.path, F_OK) == 0)<br>
> > return false;<br>
> ><br>
> > len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;<br>
> > @@ -523,9 +523,6 @@ static bool lxcapi_create(struct lxc_container *c,<br>
> > char *t, char *const argv[])<br>
> > goto out;<br>
> > }<br>
> ><br>
> > - if (!create_container_dir(c))<br>
> > - goto out;<br>
> > -<br>
> > if (!c->save_config(c, NULL)) {<br>
> > ERROR("failed to save starting configuration for %s\n", c->name);<br>
> > goto out;<br>
> > @@ -767,6 +764,9 @@ static bool lxcapi_save_config(struct lxc_container<br>
> > *c, const char *alt_file)<br>
> > return false;<br>
> > }<br>
> ><br>
> > + if (!create_container_dir(c))<br>
> > + return false;<br>
> > +<br>
> > FILE *fout = fopen(alt_file, "w");<br>
> > if (!fout)<br>
> > return false;<br>
> > @@ -785,7 +785,7 @@ static bool lxcapi_destroy(struct lxc_container *c)<br>
> > pid_t pid;<br>
> > int ret, status;<br>
> ><br>
> > - if (!c)<br>
> > + if (!c || access(c->lxc_conf->rootfs.path, F_OK) != 0)<br>
> > return false;<br>
> ><br>
> > pid = fork();<br>
> ><br>
> ><br>
> > and this is how it behaves with it;<br>
> ><br>
> > caglar@qgq:~$ cat test.py<br>
> > import lxc<br>
> > c = lxc.Container("abcdef")<br>
> > print (c.set_config_item("lxc.utsname", "abcdef"))<br>
> > print (c.save_config())<br>
> > print (c.create("ubuntu"))<br>
> > print (c.create("ubuntu"))<br>
> > print (c.destroy())<br>
> > print (c.destroy())<br>
> ><br>
> > caglar@qgq:~$ sudo python3 test.py<br>
> > True<br>
> > True<br>
> > True<br>
> > False<br>
> > True<br>
> > False<br>
> ><br>
> ><br>
> > On Sun, Mar 31, 2013 at 7:26 PM, S.Çağlar Onur <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>> wrote:<br>
> ><br>
> >> Hi Stéphane,<br>
> >><br>
> >> Hmm, then I believe there is another bug somewhere cause here is what<br>
> >> happens with your ordering;<br>
> >><br>
> >> caglar@qgq:~/Project/lxc$ sudo python3<br>
> >> Python 3.2.3 (default, Oct 19 2012, 19:53:16)<br>
> >> [GCC 4.7.2] on linux2<br>
> >> Type "help", "copyright", "credits" or "license" for more information.<br>
> >> >>> import lxc<br>
> >> __main__:1: Warning: The python-lxc API isn't yet stable and may change<br>
> >> at any point in the future.<br>
> >> >>> c = lxc.Container("abcdef")<br>
> >> >>> c.set_config_item("lxc.utsname", "blah")<br>
> >> True<br>
> >> >>> c.set_config_item("lxc.utsname", "abcdef")<br>
> >> True<br>
> >> >>> c.save_config()<br>
> >> False<br>
> >> >>> c.config_file_name<br>
> >> '/var/lib/lxc/abcdef/config'<br>
> >><br>
> >> so it looks like save_config don't work if the container directory is not<br>
> >> there and as long as I see only create calls create_container_dir to do<br>
> >> that.<br>
> >><br>
> >> Maybe correct way to handle that is to call create_container_dir from<br>
> >> save_config as well but checking the rootfs directory's existence from<br>
> >> create/destrory?<br>
> >><br>
> >> Best,<br>
> >><br>
> >><br>
> >> On Sun, Mar 31, 2013 at 5:22 PM, Stéphane Graber <<a href="mailto:stgraber@ubuntu.com">stgraber@ubuntu.com</a>><br>
> >> wrote:<br>
> >> ><br>
> >> > On 03/31/2013 04:22 PM, S.Çağlar Onur wrote:<br>
> >> > > From: "S.Çağlar Onur" <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>><br>
> >> > ><br>
> >> > > Currently it behaves like following which might be confusing for the<br>
> >> code that checks the return value of those calls to determine whether<br>
> >> operation completed successfully or not.<br>
> >> > ><br>
> >> > >>> c = lxc.Container("r")<br>
> >> > >>>> c.create("ubuntu")<br>
> >> > > True<br>
> >> > >>>> c.create("ubuntu")<br>
> >> > > True<br>
> >> > >>>> c.create("ubuntu")<br>
> >> > > True<br>
> >> > >>>> c.create("ubuntu")<br>
> >> > > True<br>
> >> > >>>> c.create("ubuntu")<br>
> >> > >>>> c.destroy()<br>
> >> > > True<br>
> >> > >>>> c.destroy()<br>
> >> > > lxc-destroy: 'r' does not exist<br>
> >> > > False<br>
> >> > >>>> c.destroy()<br>
> >> > > lxc-destroy: 'r' does not exist<br>
> >> > > False<br>
> >> > ><br>
> >> > > New behaviour<br>
> >> > ><br>
> >> > >>>> c = lxc.Container("r")<br>
> >> > >>>> c.create('ubuntu')<br>
> >> > > True<br>
> >> > >>>> c.create('ubuntu')<br>
> >> > > False<br>
> >> > >>>> c.destroy()<br>
> >> > > True<br>
> >> > >>>> c.destroy()<br>
> >> > > False<br>
> >> > >>>><br>
> >> ><br>
> >> ><br>
> >> > Won't this break the following?<br>
> >> > c = lxc.Container("abcdef")<br>
> >> > c.set_config_item("lxc.utsname", "blah")<br>
> >> > c.save_config()<br>
> >> > c.create("ubuntu")<br>
> >> ><br>
> >> > I personally always considered ".create()" to mean "generate a new<br>
> >> > rootfs" which doesn't at all mean "generate a new config file".<br>
> >> ><br>
> >> > ".destroy()" on the other hand destroys everything, including the<br>
> >> config.<br>
> >> ><br>
> >> ><br>
> >> ><br>
> >> > > Signed-off-by: S.Çağlar Onur <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>><br>
> >> > > ---<br>
> >> > > src/lxc/lxccontainer.c | 4 ++--<br>
> >> > > 1 file changed, 2 insertions(+), 2 deletions(-)<br>
> >> > ><br>
> >> > > diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c<br>
> >> > > index 480c4f5..7a11c85 100644<br>
> >> > > --- a/src/lxc/lxccontainer.c<br>
> >> > > +++ b/src/lxc/lxccontainer.c<br>
> >> > > @@ -508,7 +508,7 @@ static bool lxcapi_create(struct lxc_container<br>
> >> *c, char *t, char *const argv[])<br>
> >> > > int len, nargs = 0;<br>
> >> > > char **newargv;<br>
> >> > ><br>
> >> > > - if (!c)<br>
> >> > > + if (!c || lxcapi_is_defined(c))<br>
> >> > > return false;<br>
> >> > ><br>
> >> > > len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;<br>
> >> > > @@ -785,7 +785,7 @@ static bool lxcapi_destroy(struct lxc_container<br>
> >> *c)<br>
> >> > > pid_t pid;<br>
> >> > > int ret, status;<br>
> >> > ><br>
> >> > > - if (!c)<br>
> >> > > + if (!c || !lxcapi_is_defined(c))<br>
> >> > > return false;<br>
> >> > ><br>
> >> > > pid = fork();<br>
> >> > ><br>
> >> ><br>
> >> ><br>
> >> > --<br>
> >> > Stéphane Graber<br>
> >> > Ubuntu developer<br>
> >> > <a href="http://www.ubuntu.com" target="_blank">http://www.ubuntu.com</a><br>
> >> ><br>
> >> ><br>
> >> ><br>
> >> ------------------------------------------------------------------------------<br>
> >> > Own the Future-Intel(R) Level Up Game Demo Contest 2013<br>
> >> > Rise to greatness in Intel's independent game demo contest. Compete<br>
> >> > for recognition, cash, and the chance to get your game on Steam.<br>
> >> > $5K grand prize plus 10 genre and skill prizes. Submit your demo<br>
> >> > by 6/6/13. <a href="http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2" target="_blank">http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2</a><br>
> >> > _______________________________________________<br>
> >> > Lxc-devel mailing list<br>
> >> > <a href="mailto:Lxc-devel@lists.sourceforge.net">Lxc-devel@lists.sourceforge.net</a><br>
> >> > <a href="https://lists.sourceforge.net/lists/listinfo/lxc-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/lxc-devel</a><br>
> >> ><br>
> >><br>
> >><br>
> >><br>
> >> --<br>
> >> S.Çağlar Onur <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>><br>
> >><br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > S.Çağlar Onur <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>><br>
> ><br>
><br>
><br>
><br>
> --<br>
> S.Çağlar Onur <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>><br>
<br>
</div></div>> ------------------------------------------------------------------------------<br>
> Own the Future-Intel® Level Up Game Demo Contest 2013<br>
<div class="im">> Rise to greatness in Intel's independent game demo contest.<br>
> Compete for recognition, cash, and the chance to get your game<br>
> on Steam. $5K grand prize plus 10 genre and skill prizes.<br>
</div>> Submit your demo by 6/6/13. <a href="http://p.sf.net/sfu/intel_levelupd2d" target="_blank">http://p.sf.net/sfu/intel_levelupd2d</a><br>
<div class="HOEnZb"><div class="h5"><br>
> _______________________________________________<br>
> Lxc-devel mailing list<br>
> <a href="mailto:Lxc-devel@lists.sourceforge.net">Lxc-devel@lists.sourceforge.net</a><br>
> <a href="https://lists.sourceforge.net/lists/listinfo/lxc-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/lxc-devel</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>S.Çağlar Onur <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>>
</div>