From: Christian Brauner Date: Tue, 14 Nov 2017 22:55:33 +0000 (+0100) Subject: confile: add lxc.console.buffer.size X-Git-Tag: lxc-3.0.0.beta1~182^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28f3b1cdbec39afc17843c12b018584e801fdf11;p=thirdparty%2Flxc.git confile: add lxc.console.buffer.size Determines the size of the ringbuffer. Signed-off-by: Christian Brauner --- diff --git a/doc/lxc.container.conf.sgml.in b/doc/lxc.container.conf.sgml.in index 059942bc9..2ed83ca78 100644 --- a/doc/lxc.container.conf.sgml.in +++ b/doc/lxc.container.conf.sgml.in @@ -682,6 +682,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA where the output of this console goes. + + + + + + + + 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'.) + + + + diff --git a/src/lxc/commands.c b/src/lxc/commands.c index 880cb28c2..653fd994f 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -1026,7 +1026,7 @@ static int lxc_cmd_console_log_callback(int fd, struct lxc_cmd_req *req, struct lxc_handler *handler) { 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; struct lxc_console *console = &handler->conf->console; 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, rsp.ret = -EFAULT; rsp.datalen = 0; rsp.data = NULL; - if (logsize <= 0) + if (buffer_size <= 0) goto out; rsp.datalen = lxc_ringbuf_used(buf); diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 2e9077c1b..a2b3673a7 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -2432,7 +2432,7 @@ struct lxc_conf *lxc_conf_init(void) new->autodev = 1; new->console.log_path = NULL; new->console.log_fd = -1; - new->console.log_size = 0; + new->console.buffer_size = 0; new->console.path = NULL; new->console.peer = -1; new->console.peerpty.busy = -1; @@ -3463,7 +3463,7 @@ void lxc_conf_free(struct lxc_conf *conf) current_config = NULL; free(conf->console.log_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); free(conf->rootfs.mount); free(conf->rootfs.bdev_type); diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 43eeb4ded..1dc892430 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -153,7 +153,7 @@ struct lxc_console { char name[MAXPATHLEN]; struct termios *tios; struct lxc_tty_state *tty_state; - uint64_t log_size; + uint64_t buffer_size; struct lxc_ringbuf ringbuf; }; diff --git a/src/lxc/confile.c b/src/lxc/confile.c index c4d4c2394..852589531 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -83,7 +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_buffer_size); lxc_config_define(console_path); lxc_config_define(environment); lxc_config_define(ephemeral); @@ -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.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.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.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, }, @@ -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); } -static int set_config_console_logsize(const char *key, const char *value, - struct lxc_conf *lxc_conf, void *data) +static int set_config_console_buffer_size(const char *key, const char *value, + struct lxc_conf *lxc_conf, void *data) { int ret; int64_t size; - uint64_t logsize, pgsz; + uint64_t buffer_size, pgsz; if (lxc_config_value_empty(value)) { - lxc_conf->console.log_size = 0; + lxc_conf->console.buffer_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; + lxc_conf->console.buffer_size = 1 << 17; return 0; } @@ -1829,15 +1829,15 @@ static int set_config_console_logsize(const char *key, const char *value, size = pgsz; } - logsize = lxc_find_next_power2((uint64_t)size); - if (logsize == 0) + buffer_size = lxc_find_next_power2((uint64_t)size); + if (buffer_size == 0) return -EINVAL; - if (logsize != size) + if (buffer_size != size) 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; } @@ -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); } -static int get_config_console_logsize(const char *key, char *retv, int inlen, - struct lxc_conf *c, void *data) +static int get_config_console_buffer_size(const char *key, char *retv, + int inlen, struct lxc_conf *c, + void *data) { return lxc_get_conf_uint64(c, retv, inlen, c->autodev); } @@ -3501,10 +3502,10 @@ 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) +static inline int clr_config_console_buffer_size(const char *key, + struct lxc_conf *c, void *data) { - c->console.log_size = 0; + c->console.buffer_size = 0; return 0; } diff --git a/src/lxc/console.c b/src/lxc/console.c index e152005f4..c16e39bb6 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -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); /* write to console ringbuffer */ - if (console->log_size > 0) + if (console->buffer_size > 0) w_rbuf = lxc_ringbuf_write(&console->ringbuf, buf, r); /* write to console log */ @@ -617,7 +617,7 @@ static int lxc_setup_console_ringbuf(struct lxc_console *console) { int ret; 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 */ if (!buf->addr && size <= 0) @@ -698,7 +698,7 @@ int lxc_console_create(struct lxc_conf *conf) 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)); if (console->log_fd < 0) { SYSERROR("Failed to open console log file \"%s\"", console->log_path);