]> git.proxmox.com Git - mirror_lxc.git/commitdiff
Add autodev.tmpfs.size config parameter
authorClaudio Kuenzler <ck@claudiokuenzler.com>
Wed, 28 Aug 2019 11:01:00 +0000 (04:01 -0700)
committerSerge Hallyn <shallyn@cisco.com>
Fri, 4 Oct 2019 16:47:23 +0000 (09:47 -0700)
Signed-off-by: Claudio Kuenzler <ck@claudiokuenzler.com>
doc/lxc.container.conf.sgml.in
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/tests/parse_config_file.c

index a24ee3bae6edaef9f9f52375460dafb9566bc6fa..882eae14d4847d65301ff49babe98e1aaec2fe32 100644 (file)
@@ -1064,7 +1064,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
         <filename>/dev</filename> to be set up as needed in the container
         rootfs.  If lxc.autodev is set to 1, then after mounting the container's
         rootfs LXC will mount a fresh tmpfs under <filename>/dev</filename>
-        (limited to 500k) and fill in a minimal set of initial devices.
+        (limited to 500K by default, unless defined in lxc.autodev.tmpfs.size)
+        and fill in a minimal set of initial devices.
         This is generally required when starting a container containing
         a "systemd" based "init" but may be optional at other times.  Additional
         devices in the containers /dev directory may be created through the
@@ -1082,6 +1083,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
             </para>
           </listitem>
         </varlistentry>
+
+        <varlistentry>
+          <term>
+            <option>lxc.autodev.tmpfs.size</option>
+          </term>
+          <listitem>
+            <para>
+              Set this to define the size of the /dev tmpfs.
+              The default value is 500000 (500K). If the parameter is used
+              but without value, the default value is used.
+            </para>
+          </listitem>
+        </varlistentry>
       </variablelist>
     </refsect2>
 
index 97da012d38c7845622aec4a7fcd7772ac3039129..06e4adcc387ec0117e2cfc56d00702470d31d7b0 100644 (file)
@@ -1135,18 +1135,21 @@ on_error:
  * error, log it but don't fail yet.
  */
 static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
-                        const char *lxcpath)
+                        int autodevtmpfssize, const char *lxcpath)
 {
        __do_free char *path = NULL;
        int ret;
        size_t clen;
        mode_t cur_mask;
+        char mount_options[128];
 
        INFO("Preparing \"/dev\"");
 
        /* $(rootfs->mount) + "/dev/pts" + '\0' */
        clen = (rootfs->path ? strlen(rootfs->mount) : 0) + 9;
        path = must_realloc(NULL, clen);
+       sprintf(mount_options, "size=%d,mode=755", (autodevtmpfssize != 0) ? autodevtmpfssize : 500000);
+       DEBUG("Using mount options: %s", mount_options);
 
        ret = snprintf(path, clen, "%s/dev", rootfs->path ? rootfs->mount : "");
        if (ret < 0 || (size_t)ret >= clen)
@@ -1160,8 +1163,8 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
                goto reset_umask;
        }
 
-       ret = safe_mount("none", path, "tmpfs", 0, "size=500000,mode=755",
-                        rootfs->path ? rootfs->mount : NULL);
+       ret = safe_mount("none", path, "tmpfs", 0, mount_options,
+                        rootfs->path ? rootfs->mount : NULL );
        if (ret < 0) {
                SYSERROR("Failed to mount tmpfs on \"%s\"", path);
                goto reset_umask;
@@ -3579,7 +3582,7 @@ int lxc_setup(struct lxc_handler *handler)
        }
 
        if (lxc_conf->autodev > 0) {
-               ret = mount_autodev(name, &lxc_conf->rootfs, lxcpath);
+               ret = mount_autodev(name, &lxc_conf->rootfs, lxc_conf->autodevtmpfssize, lxcpath);
                if (ret < 0) {
                        ERROR("Failed to mount \"/dev\"");
                        return -1;
index 2664a1527ce4f600e37a591bfe1b5ff4d117535d..9f4a93d0b2156127bebffd266b22b7ef41762411 100644 (file)
@@ -299,6 +299,7 @@ struct lxc_conf {
        struct lxc_seccomp seccomp;
        int maincmd_fd;
        unsigned int autodev;  /* if 1, mount and fill a /dev at start */
+       int autodevtmpfssize; /* size of the /dev tmpfs */
        int haltsignal; /* signal used to halt container */
        int rebootsignal; /* signal used to reboot container */
        int stopsignal; /* signal used to hard stop container */
@@ -423,6 +424,7 @@ extern int lxc_clear_groups(struct lxc_conf *c);
 extern int lxc_clear_environment(struct lxc_conf *c);
 extern int lxc_clear_limits(struct lxc_conf *c, const char *key);
 extern int lxc_delete_autodev(struct lxc_handler *handler);
+extern int lxc_clear_autodev_tmpfs_size(struct lxc_conf *c);
 extern void lxc_clear_includes(struct lxc_conf *conf);
 extern int lxc_setup_rootfs_prepare_root(struct lxc_conf *conf,
                                         const char *name, const char *lxcpath);
index c0cba7c54716bbaaa1c76edef012f0992c2fdde2..0fae17da053b11c0dfa1a3059f11feeed4693f8e 100644 (file)
@@ -83,6 +83,7 @@ lxc_log_define(confile, lxc);
                                           void *);
 
 lxc_config_define(autodev);
+lxc_config_define(autodev_tmpfs_size);
 lxc_config_define(apparmor_allow_incomplete);
 lxc_config_define(apparmor_allow_nesting);
 lxc_config_define(apparmor_profile);
@@ -173,6 +174,7 @@ static struct lxc_config_t config_jump_table[] = {
        { "lxc.apparmor.allow_incomplete", set_config_apparmor_allow_incomplete,   get_config_apparmor_allow_incomplete,   clr_config_apparmor_allow_incomplete, },
        { "lxc.apparmor.allow_nesting",    set_config_apparmor_allow_nesting,      get_config_apparmor_allow_nesting,      clr_config_apparmor_allow_nesting,    },
        { "lxc.apparmor.raw",              set_config_apparmor_raw,                get_config_apparmor_raw,                clr_config_apparmor_raw,              },
+       { "lxc.autodev.tmpfs.size",        set_config_autodev_tmpfs_size,          get_config_autodev_tmpfs_size,          clr_config_autodev_tmpfs_size,        },
        { "lxc.autodev",                   set_config_autodev,                     get_config_autodev,                     clr_config_autodev,                   },
        { "lxc.cap.drop",                  set_config_cap_drop,                    get_config_cap_drop,                    clr_config_cap_drop,                  },
        { "lxc.cap.keep",                  set_config_cap_keep,                    get_config_cap_keep,                    clr_config_cap_keep,                  },
@@ -1552,6 +1554,20 @@ static int set_config_autodev(const char *key, const char *value,
        return 0;
 }
 
+static int set_config_autodev_tmpfs_size(const char *key, const char *value,
+                             struct lxc_conf *lxc_conf, void *data)
+{
+       if (lxc_config_value_empty(value)) {
+               lxc_conf->autodevtmpfssize = 500000;
+               return 0;
+       }
+
+       if (lxc_safe_int(value, &lxc_conf->autodevtmpfssize) < 0)
+               lxc_conf->autodevtmpfssize = 500000;
+
+       return 0;
+}
+
 static int set_config_signal_halt(const char *key, const char *value,
                                 struct lxc_conf *lxc_conf, void *data)
 {
@@ -4020,6 +4036,12 @@ static int get_config_autodev(const char *key, char *retv, int inlen,
        return lxc_get_conf_int(c, retv, inlen, c->autodev);
 }
 
+static int get_config_autodev_tmpfs_size(const char *key, char *retv, int inlen,
+                             struct lxc_conf *c, void *data)
+{
+       return lxc_get_conf_int(c, retv, inlen, c->autodevtmpfssize);
+}
+
 static int get_config_signal_halt(const char *key, char *retv, int inlen,
                                  struct lxc_conf *c, void *data)
 {
@@ -4642,6 +4664,13 @@ static inline int clr_config_autodev(const char *key, struct lxc_conf *c,
        return 0;
 }
 
+static inline int clr_config_autodev_tmpfs_size(const char *key, struct lxc_conf *c,
+                                    void *data)
+{
+       c->autodevtmpfssize = 500000;
+       return 0;
+}
+
 static inline int clr_config_signal_halt(const char *key, struct lxc_conf *c,
                                        void *data)
 {
@@ -5956,6 +5985,7 @@ int lxc_list_subkeys(struct lxc_conf *conf, const char *key, char *retv,
                strprint(retv, inlen, "name\n");
        } else if (!strcmp(key, "lxc.hook")) {
                strprint(retv, inlen, "autodev\n");
+               strprint(retv, inlen, "autodevtmpfssize\n");
                strprint(retv, inlen, "clone\n");
                strprint(retv, inlen, "destroy\n");
                strprint(retv, inlen, "mount\n");
index bc68ae24cca81ed9ebfeb7bd7a77fa064bb68fdd..9adbdd6a6761d0c0c9ae02f24d5cf9be4f2eaf41 100644 (file)
@@ -560,6 +560,11 @@ int main(int argc, char *argv[])
                goto non_test_error;
        }
 
+       if (set_get_compare_clear_save_load(c, "lxc.autodev.tmpfs.size", "1", tmpf, true) < 0) {
+               lxc_error("%s\n", "lxc.autodev.tmpfs.size");
+               goto non_test_error;
+       }
+
        if (set_get_compare_clear_save_load(c, "lxc.autodev", "1", tmpf, true) <
            0) {
                lxc_error("%s\n", "lxc.autodev");