[lxc-devel] Including files in LXC config

2011-12-06 Thread Andre Nathan
Hello

Attached is a patch that allows one to include other configuration files
from the main container config. The main motivation is to make the
automation of container configuration changes easier. Shell globs are
allowed, so you can do

lxc.include = /var/lib/lxc/mycontainer/conf.d/*.conf

I used the config value "lxc.include" to avoid having to change the
parse_line function, but since this is not really an LXC setting, maybe
something different would be desired (maybe "#include"?)

Any comments are appreciated.

Thanks in advance,
Andre
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 550102c..7b7ae94 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -69,6 +70,7 @@ static int config_network_ipv6(const char *, char *, struct lxc_conf *);
 static int config_network_ipv6_gateway(const char *, char *, struct lxc_conf *);
 static int config_cap_drop(const char *, char *, struct lxc_conf *);
 static int config_console(const char *, char *, struct lxc_conf *);
+static int config_include(const char *, char *, struct lxc_conf *);
 
 typedef int (*config_cb)(const char *, char *, struct lxc_conf *);
 
@@ -104,6 +106,7 @@ static struct config config[] = {
 	{ "lxc.network.ipv6", config_network_ipv6 },
 	{ "lxc.cap.drop", config_cap_drop },
 	{ "lxc.console",  config_console  },
+	{ "lxc.include",  config_include  },
 };
 
 static const size_t config_size = sizeof(config)/sizeof(struct config);
@@ -943,6 +946,31 @@ int lxc_config_read(const char *file, struct lxc_conf *conf)
 	return lxc_file_for_each_line(file, parse_line, conf);
 }
 
+static int config_include(const char *key, char *value, struct lxc_conf *lxc_conf)
+{
+	int i, ret;
+	glob_t gl;
+
+	ret = glob(value, GLOB_ERR | GLOB_BRACE | GLOB_TILDE, NULL, &gl);
+	if (ret != 0) {
+		globfree(&gl);
+		ERROR("failed to read included configuration file "
+"'%s': %s", value, strerror(errno));
+		return -1;
+	}
+	for (i = 0; i < gl.gl_pathc; i++) {
+		char *file = gl.gl_pathv[i];
+		ret = lxc_config_read(file, lxc_conf);
+		if (ret != 0) {
+			globfree(&gl);
+			ERROR("failed to read included configuration file "
+"'%s': %s", file, strerror(errno));
+			return -1;
+		}
+	}
+	return 0;
+}
+
 int lxc_config_define_add(struct lxc_list *defines, char* arg)
 {
 	struct lxc_list *dent;
--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] Including files in LXC config

2011-12-06 Thread Andre Nathan
Hi

Guido Jäkel has pointed out that I missed a globfree() call, so that
would have to be added.

There's also the question about redefining pre-existing parameters.
Should this be allowed or should it be an error?

Thanks,
Andre


On Tue, 2011-12-06 at 13:10 -0200, Andre Nathan wrote:
> Hello
> 
> Attached is a patch that allows one to include other configuration files
> from the main container config. The main motivation is to make the
> automation of container configuration changes easier. Shell globs are
> allowed, so you can do
> 
> lxc.include = /var/lib/lxc/mycontainer/conf.d/*.conf
> 
> I used the config value "lxc.include" to avoid having to change the
> parse_line function, but since this is not really an LXC setting, maybe
> something different would be desired (maybe "#include"?)
> 
> Any comments are appreciated.
> 
> Thanks in advance,
> Andre
> --
> Cloud Services Checklist: Pricing and Packaging Optimization
> This white paper is intended to serve as a reference, checklist and point of 
> discussion for anyone considering optimizing the pricing and packaging model 
> of a cloud services business. Read Now!
> http://www.accelacomm.com/jaw/sfnl/114/51491232/
> ___ Lxc-devel mailing list 
> Lxc-devel@lists.sourceforge.net 
> https://lists.sourceforge.net/lists/listinfo/lxc-devel



--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] lxc on ia64

2011-12-06 Thread Vadym S. Khondar
On пн, 05-гру-2011 23:12:39 +0200, Daniel Lezcano wrote:
> On 12/01/2011 05:23 PM, Vadym S. Khondar wrote:
>> Hello everybody.
>>

>
> Ha! great someone willing to run lxc on itanium :)
>
> Can you try this patch ?
>
> Index: lxc/src/lxc/namespace.c
> ===
> --- lxc.orig/src/lxc/namespace.c2011-12-05 22:09:47.117725955 +0100
> +++ lxc/src/lxc/namespace.c2011-12-05 22:11:11.967725935 +0100
> @@ -67,13 +67,15 @@ pid_t lxc_clone(int (*fn)(void *), void
>   };
>
>   long stack_size = sysconf(_SC_PAGESIZE);
> - void *stack = alloca(stack_size) + stack_size;
> + void *stack;
>   pid_t ret;
>
>   #ifdef __ia64__
> +stack = malloc(stack_size);
>   ret = __clone2(do_clone, stack,
>  stack_size, flags | SIGCHLD,&clone_arg);
>   #else
> +stack = alloca(stack_size) + stack_size;
>   ret = clone(do_clone, stack, flags | SIGCHLD,&clone_arg);
>   #endif
>   if (ret<  0)
>
>

Thank you, Daniel and Greg, for your patches.
Problem was indeed only in how stack is treated on ia64 (needed to 
supply the pointer to start of memory area, not to the place after end).

Don't know why this didn't work out previous time - probably I 
shouldn't have done things on late night :) (more probable - wrong 
version of liblxc was resolved by ld.so) - but now it works!

Here is patch that worked for me (but actually it's the same like 
yours):

--- namespace.c.orig2011-12-06 21:01:19.0 +0300
+++ namespace.c 2011-12-06 21:07:45.0 +0300
@@ -67,14 +67,15 @@
};
 
long stack_size = sysconf(_SC_PAGESIZE);
-   void *stack = alloca(stack_size) + stack_size;
+   void *stack = alloca(stack_size);
+
pid_t ret;
 
 #ifdef __ia64__
ret = __clone2(do_clone, stack,
   stack_size, flags | SIGCHLD, &clone_arg);
 #else
-   ret = clone(do_clone, stack, flags | SIGCHLD, &clone_arg);
+   ret = clone(do_clone, stack + stack_size, flags | SIGCHLD, 
&clone_arg);
 #endif
if (ret < 0)
ERROR("failed to clone(0x%x): %s", flags, 
strerror(errno));



-- 
Vadym S. Khondar,
Engineer @ HPCC

--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Set high byte of mac addresses for host veth devices to 0xfe

2011-12-06 Thread Serge Hallyn
On 12/04/2011 05:18 PM, Daniel Lezcano wrote:
> On 12/05/2011 12:11 AM, Serge Hallyn wrote:
>> On 12/04/2011 04:28 AM, Daniel Lezcano wrote:
>>> On 11/16/2011 05:49 PM, Christian Seiler wrote:
 Hi,

 I've run into the same problem as was discussed in BUG #3411497 [1]
 and on
 the users mailing list [2]. To solve this, I've decided to implement
 the
 patch that was proposed on the mailing list [3].

 The attached patch is against current trunk. Since trunk currently
 doesn't
 compile for me, I tested the patch against the current Debian
 package for
 LXC version 0.7.2. There, it still applies and works as expected for
 me,
 the bridge interface still keeps its mac address and the high byte
 of the
 mac address of the host veth interface is correctly set to 0xfe.

 It would be great if this patch or a slightly modified version could be
 applied to LXC.
>>> Hi guys
>>>
>>> are ok with this patch ?
>>>
>>> Thanks
>>> -- Daniel
>>
>> Sorry, where is the patch?  I don't find it in the archives.  Can
>> someone send it (inline)?
>>
>
> It was in attachment. Here it is.
>
>  From e1b4779a89964ec43fa2bc5f76fafd965c89f73f Mon Sep 17 00:00:00 2001
> From: Christian Seiler
> Date: Tue, 15 Nov 2011 18:53:53 +0100
> Subject: [PATCH] Set high byte of mac addresses for host veth devices to 0xfe
>
> When used in conjunction with a bridge, veth devices with random addresses
> may change the mac address of the bridge itself if the mac address of the
> interface newly added is numerically lower than the previous mac address
> of the bridge. This is documented kernel behavior. To avoid changing the
> host's mac address back and forth when starting and/or stopping containers,
> this patch ensures that the high byte of the mac address of the veth
> interface visible from the host side is set to 0xfe.
>
> A similar logic is also implemented in libvirt.
>
> Fixes SF bug #3411497
> See 
> also:
> ---
>   src/lxc/conf.c |   40 
>   1 files changed, 40 insertions(+), 0 deletions(-)
>
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index 613e476..a5d067b 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -1402,6 +1402,36 @@ static int setup_network(struct lxc_list *network)
>   return 0;
>   }
>
> +static int setup_private_host_hw_addr(char *veth1)
> +{
> + struct ifreq ifr;
> + int err;
> + int sockfd;
> + 
> + sockfd = socket(AF_INET, SOCK_DGRAM, 0);
> + if (sockfd<  0)
> + return -errno;
> + 
> + snprintf((char *)ifr.ifr_name, IFNAMSIZ, "%s", veth1);
> + err = ioctl(sockfd, SIOCGIFHWADDR,&ifr);
> + if (err<  0) {
> + close(sockfd);
> + return -errno;
> + }
> + 
> + ifr.ifr_hwaddr.sa_data[0] = 0xfe;
> + err = ioctl(sockfd, SIOCSIFHWADDR,&ifr);
> + close(sockfd);
> + if (err<  0)
> + return -errno;
> + 
> + DEBUG("mac address of host interface '%s' changed to private 
> %02x:%02x:%02x:%02x:%02x:%02x",
> +   veth1, ifr.ifr_hwaddr.sa_data[0]&  0xff, 
> ifr.ifr_hwaddr.sa_data[1]&  0xff, ifr.ifr_hwaddr.sa_data[2]&  0xff,
> +   ifr.ifr_hwaddr.sa_data[3]&  0xff, ifr.ifr_hwaddr.sa_data[4]&  
> 0xff, ifr.ifr_hwaddr.sa_data[5]&  0xff);
> + 
> + return 0;
> +}
> +
>   struct lxc_conf *lxc_conf_init(void)
>   {
>   struct lxc_conf *new;
> @@ -1455,6 +1485,16 @@ static int instanciate_veth(struct lxc_handler 
> *handler, struct lxc_netdev *netd
> strerror(-err));
>   return -1;
>   }
> + 
> + /* changing the high byte of the mac address to 0xfe, the bridge 
> interface
> +  * will always keep the host's mac address and not take the mac address
> +  * of a container */
> + err = setup_private_host_hw_addr(veth1);
> + if (err) {
> + ERROR("failed to change mac address of host interface '%s' : 
> %s",
> + veth1, strerror(-err));
> + goto out_delete;
> + }
>
>   if (netdev->mtu) {
>   err = lxc_netdev_set_mtu(veth1, atoi(netdev->mtu));
> -- 1.7.2.5
>

Thanks, sorry for the trouble.  Looks good, with one exception - if 
ioctl failed, then you may end up returning the wrong errno (from the 
close syscall).  With that fixed, please do apply.

Thanks, Christian.

thanks,
-serge

--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge