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

Qiang Huang h.huangqiang at huawei.com
Sun Sep 22 06:43:03 UTC 2013


On 2013/9/17 21:41, Serge Hallyn wrote:
> Quoting Qiang Huang (h.huangqiang at huawei.com):
>> On 2013/9/17 11:27, Serge Hallyn wrote:
>>> Quoting Qiang Huang (h.huangqiang at huawei.com):
>>>> On 2013/9/16 12:23, Stéphane Graber wrote:
>>>>> 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.
>>>>
>>>> Well, it did works this way in the former lxc_create version.
>>>>
>>>> We used to use LXC this way:
>>>> - We made a template(rootfs, config and fstab) manually.
>>>
>>> >From here, can you just write a script 'lxc-homebrew' which
>>> copies the rootfs+config+fstab into place, and call
>>>
>>> 	lxc-create -t homebrew -n c1
>>>
>>> ?
>>>
>>> If you want to just copy the stuff in by hand, you can
>>> do that.  You don't *have* to run lxc-create if you've done
>>> everything by hand.
>>
>> OK, thanks Serge.
>>
>> So we are still not supposed to use lxc-create without -t option?
> 
> I just don't see the point, and I worry that people using the
> common case will end up accidentally deleting existing container
> data.
> 
> Well, the current code says
> 
>         /* 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)
>                 goto out;
> 
> Maybe what we want to do is add a '&& access(c->configfile, F_OK) to that
> test?  I think that would give you what you want, and I think it's what
> I really meant to say.

Yes, add a '&& access(c->configfile, F_OK) to that test will make the
lxc-create -n xxx -f config
successful, but I don't quite understand the logic here, in what situation
will this test fail?

> 
>> Is lxc-create only used for creating templates?
> 
> For running template scripts.  Near as I can tell the only thing
> you want lxc-create to do is to copy a file (the config file).

Yes, and that is what the old version of lxc-create can do, but it can't
now. And add that test seems not enough, because after create,
lxc-start -n xxx
will fail, because we create an empty rootfs in /usr/local/var/lib/lxc/xxx,
and one item of the config in that dir is changed to
lxc.rootfs = /usr/local/var/lib/lxc/xxx/rootfs

> That just seems like way overkill.

So what do you think about this?
Should I make a patch to change this, so we can use
lxc-create -n xxx -f config
to create a container with the rootfs already exist?

> 
> -serge
> 
> .
> 






More information about the lxc-devel mailing list