]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: add lxc.console.logsize
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 18 Oct 2017 14:20:36 +0000 (16:20 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sat, 21 Oct 2017 16:38:14 +0000 (18:38 +0200)
Closes #1857.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.h
src/lxc/confile.c

index 169857f2bb711c25f53503ce9aec969f934dbe4d..d89aed400cab822836107ac7e2a99f07dc767bae 100644 (file)
@@ -152,6 +152,7 @@ struct lxc_console {
        char name[MAXPATHLEN];
        struct termios *tios;
        struct lxc_tty_state *tty_state;
+       uint64_t log_size;
 };
 
 /*
index 3567525da0cdb8508a7c2896da4a0983f7fe0659..d94a307191fc586acd97f81ed1a5e272110b4f55 100644 (file)
@@ -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)
 {