[lxc-devel] [lxc/master] Add devfs_size config parameter
Napsty on Github
lxc-bot at linuxcontainers.org
Tue Aug 27 20:03:46 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1641 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190827/6df7f258/attachment.bin>
-------------- next part --------------
From 55b37bac575a7a782f100e7530f7af55281c6abd Mon Sep 17 00:00:00 2001
From: Claudio Kuenzler <ck at claudiokuenzler.com>
Date: Tue, 27 Aug 2019 12:55:13 -0700
Subject: [PATCH] Add devfs_size config parameter
---
doc/lxc.container.conf.sgml.in | 18 ++++++++++++++++--
src/lxc/conf.c | 11 +++++++----
src/lxc/conf.h | 2 ++
src/lxc/confile.c | 30 ++++++++++++++++++++++++++++++
4 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/doc/lxc.container.conf.sgml.in b/doc/lxc.container.conf.sgml.in
index a24ee3bae6..f6dc2fd21f 100644
--- a/doc/lxc.container.conf.sgml.in
+++ b/doc/lxc.container.conf.sgml.in
@@ -1064,9 +1064,10 @@ 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.devfs_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
+ a "systemd" based "init" but may be optional at other times. Additional
devices in the containers /dev directory may be created through the
use of the <option>lxc.hook.autodev</option> hook.
</para>
@@ -1082,6 +1083,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>lxc.devfs_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 set
+ but without value, the default value is used.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect2>
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 97da012d38..5abe1d5688 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1135,18 +1135,21 @@ static int lxc_create_ttys(struct lxc_handler *handler)
* error, log it but don't fail yet.
*/
static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs,
- const char *lxcpath)
+ int devfs_size, 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", (devfs_size != 0) ? devfs_size : 500000);
+ INFO("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->devfs_size, lxcpath);
if (ret < 0) {
ERROR("Failed to mount \"/dev\"");
return -1;
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 2664a1527c..da55f1dda3 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -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 devfs_size; /* 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_devfs_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);
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index c0cba7c547..4856f50903 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -98,6 +98,7 @@ lxc_config_define(console_logfile);
lxc_config_define(console_path);
lxc_config_define(console_rotate);
lxc_config_define(console_size);
+lxc_config_define(devfs_size);
lxc_config_define(environment);
lxc_config_define(ephemeral);
lxc_config_define(execute_cmd);
@@ -185,6 +186,7 @@ static struct lxc_config_t config_jump_table[] = {
{ "lxc.console.path", set_config_console_path, get_config_console_path, clr_config_console_path, },
{ "lxc.console.rotate", set_config_console_rotate, get_config_console_rotate, clr_config_console_rotate, },
{ "lxc.console.size", set_config_console_size, get_config_console_size, clr_config_console_size, },
+ { "lxc.devfs_size", set_config_devfs_size, get_config_devfs_size, clr_config_devfs_size, },
{ "lxc.environment", set_config_environment, get_config_environment, clr_config_environment, },
{ "lxc.ephemeral", set_config_ephemeral, get_config_ephemeral, clr_config_ephemeral, },
{ "lxc.execute.cmd", set_config_execute_cmd, get_config_execute_cmd, clr_config_execute_cmd, },
@@ -1552,6 +1554,20 @@ static int set_config_autodev(const char *key, const char *value,
return 0;
}
+static int set_config_devfs_size(const char *key, const char *value,
+ struct lxc_conf *lxc_conf, void *data)
+{
+ if (lxc_config_value_empty(value)) {
+ lxc_conf->devfs_size = 500000;
+ return 0;
+ }
+
+ if (lxc_safe_int(value, &lxc_conf->devfs_size) < 0)
+ lxc_conf->devfs_size = 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_devfs_size(const char *key, char *retv, int inlen,
+ struct lxc_conf *c, void *data)
+{
+ return lxc_get_conf_int(c, retv, inlen, c->devfs_size);
+}
+
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_devfs_size(const char *key, struct lxc_conf *c,
+ void *data)
+{
+ c->devfs_size = 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, "devfs_size\n");
strprint(retv, inlen, "clone\n");
strprint(retv, inlen, "destroy\n");
strprint(retv, inlen, "mount\n");
More information about the lxc-devel
mailing list