confile: add lxc.console.buffer.size

Determines the size of the ringbuffer. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 05e1745c
...@@ -682,6 +682,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ...@@ -682,6 +682,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
where the output of this console goes. where the output of this console goes.
</para> </para>
<variablelist> <variablelist>
<varlistentry>
<term>
<option>lxc.console.buffer.size</option>
</term>
<listitem>
<para>
Setting this option instructs liblxc to allocate an in-memory
ringbuffer. The container's console output will be written to the
ringbuffer. Note that ringbuffer must be at least as big as a
standard page size. When passed a value smaller than a single page
size liblxc will allocate a ringbuffer of a single page size. A page
size is usually 4kB.
The keyword 'auto' will cause liblxc to allocate a ringbuffer of
128kB.
When manually specifying a size for the ringbuffer the value should
be a power of 2 when converted to bytes. Valid size prefixes are
'kB', 'MB', 'GB'. (Note that all conversions are based on multiples
of 1024. That means 'kb' == 'KiB', 'MB' == 'MiB', 'GB' == 'GiB'.)
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term> <term>
<option>lxc.console.logfile</option> <option>lxc.console.logfile</option>
......
...@@ -1026,7 +1026,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req, ...@@ -1026,7 +1026,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req,
struct lxc_handler *handler) struct lxc_handler *handler)
{ {
struct lxc_cmd_rsp rsp; struct lxc_cmd_rsp rsp;
uint64_t logsize = handler->conf->console.log_size; uint64_t buffer_size = handler->conf->console.buffer_size;
const struct lxc_cmd_console_log *log = req->data; const struct lxc_cmd_console_log *log = req->data;
struct lxc_console *console = &handler->conf->console; struct lxc_console *console = &handler->conf->console;
struct lxc_ringbuf *buf = &handler->conf->console.ringbuf; struct lxc_ringbuf *buf = &handler->conf->console.ringbuf;
...@@ -1034,7 +1034,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req, ...@@ -1034,7 +1034,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req,
rsp.ret = -EFAULT; rsp.ret = -EFAULT;
rsp.datalen = 0; rsp.datalen = 0;
rsp.data = NULL; rsp.data = NULL;
if (logsize <= 0) if (buffer_size <= 0)
goto out; goto out;
rsp.datalen = lxc_ringbuf_used(buf); rsp.datalen = lxc_ringbuf_used(buf);
......
...@@ -2432,7 +2432,7 @@ struct lxc_conf *lxc_conf_init(void) ...@@ -2432,7 +2432,7 @@ struct lxc_conf *lxc_conf_init(void)
new->autodev = 1; new->autodev = 1;
new->console.log_path = NULL; new->console.log_path = NULL;
new->console.log_fd = -1; new->console.log_fd = -1;
new->console.log_size = 0; new->console.buffer_size = 0;
new->console.path = NULL; new->console.path = NULL;
new->console.peer = -1; new->console.peer = -1;
new->console.peerpty.busy = -1; new->console.peerpty.busy = -1;
...@@ -3463,7 +3463,7 @@ void lxc_conf_free(struct lxc_conf *conf) ...@@ -3463,7 +3463,7 @@ void lxc_conf_free(struct lxc_conf *conf)
current_config = NULL; current_config = NULL;
free(conf->console.log_path); free(conf->console.log_path);
free(conf->console.path); free(conf->console.path);
if (conf->console.log_size > 0 && conf->console.ringbuf.addr) if (conf->console.buffer_size > 0 && conf->console.ringbuf.addr)
lxc_ringbuf_release(&conf->console.ringbuf); lxc_ringbuf_release(&conf->console.ringbuf);
free(conf->rootfs.mount); free(conf->rootfs.mount);
free(conf->rootfs.bdev_type); free(conf->rootfs.bdev_type);
......
...@@ -153,7 +153,7 @@ struct lxc_console { ...@@ -153,7 +153,7 @@ struct lxc_console {
char name[MAXPATHLEN]; char name[MAXPATHLEN];
struct termios *tios; struct termios *tios;
struct lxc_tty_state *tty_state; struct lxc_tty_state *tty_state;
uint64_t log_size; uint64_t buffer_size;
struct lxc_ringbuf ringbuf; struct lxc_ringbuf ringbuf;
}; };
......
...@@ -83,7 +83,7 @@ lxc_config_define(cap_keep); ...@@ -83,7 +83,7 @@ lxc_config_define(cap_keep);
lxc_config_define(cgroup_controller); lxc_config_define(cgroup_controller);
lxc_config_define(cgroup_dir); lxc_config_define(cgroup_dir);
lxc_config_define(console_logfile); lxc_config_define(console_logfile);
lxc_config_define(console_logsize); lxc_config_define(console_buffer_size);
lxc_config_define(console_path); lxc_config_define(console_path);
lxc_config_define(environment); lxc_config_define(environment);
lxc_config_define(ephemeral); lxc_config_define(ephemeral);
...@@ -149,8 +149,8 @@ static struct lxc_config_t config[] = { ...@@ -149,8 +149,8 @@ static struct lxc_config_t config[] = {
{ "lxc.cap.keep", false, set_config_cap_keep, get_config_cap_keep, clr_config_cap_keep, }, { "lxc.cap.keep", false, set_config_cap_keep, get_config_cap_keep, clr_config_cap_keep, },
{ "lxc.cgroup.dir", false, set_config_cgroup_dir, get_config_cgroup_dir, clr_config_cgroup_dir, }, { "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.cgroup", false, set_config_cgroup_controller, get_config_cgroup_controller, clr_config_cgroup_controller, },
{ "lxc.console.buffer.size", false, set_config_console_buffer_size, get_config_console_buffer_size, clr_config_console_buffer_size, },
{ "lxc.console.logfile", false, set_config_console_logfile, get_config_console_logfile, clr_config_console_logfile, }, { "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.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.environment", false, set_config_environment, get_config_environment, clr_config_environment, },
{ "lxc.ephemeral", false, set_config_ephemeral, get_config_ephemeral, clr_config_ephemeral, }, { "lxc.ephemeral", false, set_config_ephemeral, get_config_ephemeral, clr_config_ephemeral, },
...@@ -1794,21 +1794,21 @@ static int set_config_console_logfile(const char *key, const char *value, ...@@ -1794,21 +1794,21 @@ static int set_config_console_logfile(const char *key, const char *value,
return set_config_path_item(&lxc_conf->console.log_path, value); return set_config_path_item(&lxc_conf->console.log_path, value);
} }
static int set_config_console_logsize(const char *key, const char *value, static int set_config_console_buffer_size(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
int ret; int ret;
int64_t size; int64_t size;
uint64_t logsize, pgsz; uint64_t buffer_size, pgsz;
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->console.log_size = 0; lxc_conf->console.buffer_size = 0;
return 0; return 0;
} }
/* If the user specified "auto" the default log size is 2^17 = 128 Kib */ /* If the user specified "auto" the default log size is 2^17 = 128 Kib */
if (!strcmp(value, "auto")) { if (!strcmp(value, "auto")) {
lxc_conf->console.log_size = 1 << 17; lxc_conf->console.buffer_size = 1 << 17;
return 0; return 0;
} }
...@@ -1829,15 +1829,15 @@ static int set_config_console_logsize(const char *key, const char *value, ...@@ -1829,15 +1829,15 @@ static int set_config_console_logsize(const char *key, const char *value,
size = pgsz; size = pgsz;
} }
logsize = lxc_find_next_power2((uint64_t)size); buffer_size = lxc_find_next_power2((uint64_t)size);
if (logsize == 0) if (buffer_size == 0)
return -EINVAL; return -EINVAL;
if (logsize != size) if (buffer_size != size)
NOTICE("Passed size was not a power of 2. Rounding log size to " NOTICE("Passed size was not a power of 2. Rounding log size to "
"next power of two: %" PRIu64 " bytes", logsize); "next power of two: %" PRIu64 " bytes", buffer_size);
lxc_conf->console.log_size = logsize; lxc_conf->console.buffer_size = buffer_size;
return 0; return 0;
} }
...@@ -3091,8 +3091,9 @@ static int get_config_console_logfile(const char *key, char *retv, int inlen, ...@@ -3091,8 +3091,9 @@ static int get_config_console_logfile(const char *key, char *retv, int inlen,
return lxc_get_conf_str(retv, inlen, c->console.log_path); return lxc_get_conf_str(retv, inlen, c->console.log_path);
} }
static int get_config_console_logsize(const char *key, char *retv, int inlen, static int get_config_console_buffer_size(const char *key, char *retv,
struct lxc_conf *c, void *data) int inlen, struct lxc_conf *c,
void *data)
{ {
return lxc_get_conf_uint64(c, retv, inlen, c->autodev); return lxc_get_conf_uint64(c, retv, inlen, c->autodev);
} }
...@@ -3501,10 +3502,10 @@ static inline int clr_config_console_logfile(const char *key, ...@@ -3501,10 +3502,10 @@ static inline int clr_config_console_logfile(const char *key,
return 0; return 0;
} }
static inline int clr_config_console_logsize(const char *key, static inline int clr_config_console_buffer_size(const char *key,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
{ {
c->console.log_size = 0; c->console.buffer_size = 0;
return 0; return 0;
} }
......
...@@ -238,7 +238,7 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data, ...@@ -238,7 +238,7 @@ static int lxc_console_cb_con(int fd, uint32_t events, void *data,
w = lxc_write_nointr(console->peer, buf, r); w = lxc_write_nointr(console->peer, buf, r);
/* write to console ringbuffer */ /* write to console ringbuffer */
if (console->log_size > 0) if (console->buffer_size > 0)
w_rbuf = lxc_ringbuf_write(&console->ringbuf, buf, r); w_rbuf = lxc_ringbuf_write(&console->ringbuf, buf, r);
/* write to console log */ /* write to console log */
...@@ -617,7 +617,7 @@ static int lxc_setup_console_ringbuf(struct lxc_console *console) ...@@ -617,7 +617,7 @@ static int lxc_setup_console_ringbuf(struct lxc_console *console)
{ {
int ret; int ret;
struct lxc_ringbuf *buf = &console->ringbuf; struct lxc_ringbuf *buf = &console->ringbuf;
uint64_t size = console->log_size; uint64_t size = console->buffer_size;
/* no ringbuffer previously allocated and no ringbuffer requested */ /* no ringbuffer previously allocated and no ringbuffer requested */
if (!buf->addr && size <= 0) if (!buf->addr && size <= 0)
...@@ -698,7 +698,7 @@ int lxc_console_create(struct lxc_conf *conf) ...@@ -698,7 +698,7 @@ int lxc_console_create(struct lxc_conf *conf)
goto err; goto err;
} }
if (console->log_path && console->log_size <= 0) { if (console->log_path && console->buffer_size <= 0) {
console->log_fd = lxc_unpriv(open(console->log_path, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600)); console->log_fd = lxc_unpriv(open(console->log_path, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600));
if (console->log_fd < 0) { if (console->log_fd < 0) {
SYSERROR("Failed to open console log file \"%s\"", console->log_path); SYSERROR("Failed to open console log file \"%s\"", console->log_path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment