From a04220de0b0f402b0f312ba514bc382d39d0e05c Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Wed, 18 Oct 2017 16:20:36 +0200 Subject: [PATCH] confile: add lxc.console.logsize Closes #1857. Signed-off-by: Christian Brauner --- src/lxc/conf.h | 1 + src/lxc/confile.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 169857f2b..d89aed400 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -152,6 +152,7 @@ struct lxc_console { char name[MAXPATHLEN]; struct termios *tios; struct lxc_tty_state *tty_state; + uint64_t log_size; }; /* diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 3567525da..d94a30719 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -83,6 +83,7 @@ lxc_config_define(cap_keep); lxc_config_define(cgroup_controller); lxc_config_define(cgroup_dir); lxc_config_define(console_logfile); +lxc_config_define(console_logsize); lxc_config_define(console_path); lxc_config_define(environment); lxc_config_define(ephemeral); @@ -148,6 +149,7 @@ static struct lxc_config_t config[] = { { "lxc.cgroup.dir", false, set_config_cgroup_dir, get_config_cgroup_dir, clr_config_cgroup_dir, }, { "lxc.cgroup", false, set_config_cgroup_controller, get_config_cgroup_controller, clr_config_cgroup_controller, }, { "lxc.console.logfile", false, set_config_console_logfile, get_config_console_logfile, clr_config_console_logfile, }, + { "lxc.console.logsize", false, set_config_console_logsize, get_config_console_logsize, clr_config_console_logsize, }, { "lxc.console.path", false, set_config_console_path, get_config_console_path, clr_config_console_path, }, { "lxc.environment", false, set_config_environment, get_config_environment, clr_config_environment, }, { "lxc.ephemeral", false, set_config_ephemeral, get_config_ephemeral, clr_config_ephemeral, }, @@ -1790,6 +1792,53 @@ static int set_config_console_logfile(const char *key, const char *value, return set_config_path_item(&lxc_conf->console.log_path, value); } +static int set_config_console_logsize(const char *key, const char *value, + struct lxc_conf *lxc_conf, void *data) +{ + int ret; + int64_t size; + uint64_t logsize, pgsz; + + if (lxc_config_value_empty(value)) { + lxc_conf->console.log_size = 0; + return 0; + } + + /* If the user specified "auto" the default log size is 2^17 = 128 Kib */ + if (!strcmp(value, "auto")) { + lxc_conf->console.log_size = 1 << 17; + return 0; + } + + ret = parse_byte_size_string(value, &size); + if (ret < 0) + return -1; + + if (size < 0) + return -EINVAL; + + /* must be at least a page size */ + pgsz = lxc_getpagesize(); + if ((uint64_t)size < pgsz) { + NOTICE("Requested ringbuffer size for the console is %" PRId64 + " but must be at least %" PRId64 + " bytes. Setting ringbuffer size to %" PRId64 " bytes", + size, pgsz, pgsz); + size = pgsz; + } + + logsize = lxc_find_next_power2((uint64_t)size); + if (logsize == 0) + return -EINVAL; + + if (logsize != size) + NOTICE("Passed size was not a power of 2. Rounding log size to " + "next power of two: %" PRIu64 " bytes", logsize); + + lxc_conf->console.log_size = logsize; + return 0; +} + int append_unexp_config_line(const char *line, struct lxc_conf *conf) { size_t len = conf->unexpanded_len, linelen = strlen(line); @@ -3023,6 +3072,12 @@ static int get_config_console_logfile(const char *key, char *retv, int inlen, return lxc_get_conf_str(retv, inlen, c->console.log_path); } +static int get_config_console_logsize(const char *key, char *retv, int inlen, + struct lxc_conf *c, void *data) +{ + return lxc_get_conf_uint64(c, retv, inlen, c->autodev); +} + static int get_config_seccomp_profile(const char *key, char *retv, int inlen, struct lxc_conf *c, void *data) { @@ -3405,6 +3460,13 @@ static inline int clr_config_console_logfile(const char *key, return 0; } +static inline int clr_config_console_logsize(const char *key, + struct lxc_conf *c, void *data) +{ + c->console.log_size = 0; + return 0; +} + static inline int clr_config_seccomp_profile(const char *key, struct lxc_conf *c, void *data) { -- 2.47.2