Skip to content

Commit

Permalink
confile: add lxc.console.logsize
Browse files Browse the repository at this point in the history
Closes #1857.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Oct 21, 2017
1 parent 2ea479c commit a04220d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lxc/conf.h
Expand Up @@ -152,6 +152,7 @@ struct lxc_console {
char name[MAXPATHLEN];
struct termios *tios;
struct lxc_tty_state *tty_state;
uint64_t log_size;
};

/*
Expand Down
62 changes: 62 additions & 0 deletions src/lxc/confile.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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, },
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit a04220d

Please sign in to comment.