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.
- We put all template related files in a dir(like /home/test), now
  lxc-ls say nothing because we haven't create any.
- We use lxc-create -n xxx -f /home/test/config, so we can see a
  created container from lxc-ls
- Use lxc-start -n xxx to start the container.

So when we use lxc-create -n xxx -f config, the container named xxx
didn't exactly exist, we just have the rootfs.

I don't know if have the rootfs means we already created a container.
I used to report a bug that lxc-create can't be used without the -t
option, and it's fixed right now.

So I have two questions:
1. Is the way we using LXC reasonable?
2. What do you define lxc-create, is it only use to create
   templates themselves?

Thanks!
Qiang Huang

> 
> 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.huangqi...@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
>>
> 



------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to