]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
configure container architecture
authorDaniel Lezcano <daniel.lezcano@free.fr>
Mon, 13 Sep 2010 13:36:20 +0000 (15:36 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Mon, 13 Sep 2010 13:36:20 +0000 (15:36 +0200)
When a container is installed with 32bits binaries while we are
running on a 64bits host, inside the container we are seen as
64bits arch. That leads to some problems for the package updates
because the scripts will download 64bits packages instead of 32bits.

This patch defines a configuration variable to set the architecture
of the container.

lxc.arch = i686 | x86 | x86_64 | amd64

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
doc/lxc.conf.sgml.in
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c

index a6454b9190b55a4f421ec84b91be5b981877a5ca..f975d57e7052234d52ef5da65be1846885ee47a8 100644 (file)
@@ -75,6 +75,38 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
       the line is a comment.
     </para>
 
+    <refsect2>
+      <title>Architecture</title>
+      <para>
+       Allows to set the architecture for the container. For example,
+       set a 32bits architecture for a container running 32bits
+       binaries on a 64bits host. That fix the container scripts
+       which rely on the architecture to do some work like
+       downloading the packages.
+      </para>
+
+      <variablelist>
+       <varlistentry>
+         <term>
+           <option>lxc.arch</option>
+         </term>
+         <listitem>
+           <para>
+             Specify the architecture for the container.
+           </para>
+           <para>
+             Valid options are
+             <option>x86</option>,
+             <option>i686</option>,
+             <option>x86_64</option>,
+             <option>amd64</option>
+           </para>
+         </listitem>
+       </varlistentry>
+      </variablelist>
+
+    </refsect2>
+
     <refsect2>
       <title>Hostname</title>
       <para>
index c955213650baf81c90cf01c9a20205efb6dc31ad..8cb8e20508ca8088744d91b44a5e4c3986d03689 100644 (file)
@@ -40,6 +40,7 @@
 #include <sys/mman.h>
 #include <sys/prctl.h>
 #include <sys/capability.h>
+#include <sys/personality.h>
 
 #include <arpa/inet.h>
 #include <fcntl.h>
@@ -655,6 +656,21 @@ out:
        return 0;
 }
 
+static int setup_personality(int persona)
+{
+       if (persona == -1)
+               return 0;
+
+       if (personality(persona) < 0) {
+               SYSERROR("failed to set personality to '0x%x'", persona);
+               return -1;
+       }
+
+       INFO("set personality to '0x%x'", persona);
+
+       return 0;
+}
+
 static int setup_console(const struct lxc_rootfs *rootfs,
                         const struct lxc_console *console)
 {
@@ -1125,6 +1141,7 @@ struct lxc_conf *lxc_conf_init(void)
        }
        memset(new, 0, sizeof(*new));
 
+       new->personality = -1;
        new->console.path = NULL;
        new->console.peer = -1;
        new->console.master = -1;
@@ -1475,6 +1492,11 @@ int lxc_setup(const char *name, struct lxc_conf *lxc_conf)
                return -1;
        }
 
+       if (setup_personality(lxc_conf->personality)) {
+               ERROR("failed to setup personality");
+               return -1;
+       }
+
        if (setup_caps(&lxc_conf->caps)) {
                ERROR("failed to drop capabilities");
                return -1;
index 32135b656285186893a9d1bf7bdf4bebd23ef5d4..b12a3466e88bf70adbd31798f784b49ba42505a4 100644 (file)
@@ -194,6 +194,7 @@ struct lxc_conf {
        int tty;
        int pts;
        int reboot;
+       int personality;
        struct utsname *utsname;
        struct lxc_list cgroup;
        struct lxc_list network;
index e2c015d7c449bdab0b8437f38ec4179df666368e..610ca154bc37716d9defa98df4d60076e306f4ce 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/utsname.h>
+#include <sys/personality.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <net/if.h>
@@ -43,6 +44,7 @@
 
 lxc_log_define(lxc_confile, lxc);
 
+static int config_personality(const char *, char *, struct lxc_conf *);
 static int config_pts(const char *, char *, struct lxc_conf *);
 static int config_tty(const char *, char *, struct lxc_conf *);
 static int config_cgroup(const char *, char *, struct lxc_conf *);
@@ -74,6 +76,7 @@ struct config {
 
 static struct config config[] = {
 
+       { "lxc.arch",                 config_personality          },
        { "lxc.pts",                  config_pts                  },
        { "lxc.tty",                  config_tty                  },
        { "lxc.cgroup",               config_cgroup               },
@@ -475,6 +478,34 @@ static int config_network_ipv6(const char *key, char *value,
        return 0;
 }
 
+static int config_personality(const char *key, char *value,
+                             struct lxc_conf *lxc_conf)
+{
+       struct per_name {
+               char *name;
+               int per;
+       } pername[4] = {
+               { "x86", PER_LINUX32 },
+               { "i686", PER_LINUX32 },
+               { "x86_64", PER_LINUX },
+               { "amd64", PER_LINUX },
+       };
+
+       int i;
+
+       for (i = 0; i < sizeof(pername); i++) {
+
+               if (strcmp(pername[i].name, value))
+                   continue;
+
+               lxc_conf->personality = pername[i].per;
+               return 0;
+       }
+
+       ERROR("unsupported personality '%s'", value);
+       return -1;
+}
+
 static int config_pts(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
        int maxpts = atoi(value);