]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: add lxc.console.buffer.size
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 14 Nov 2017 22:55:33 +0000 (23:55 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 17 Nov 2017 23:17:44 +0000 (00:17 +0100)
Determines the size of the ringbuffer.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
doc/lxc.container.conf.sgml.in
src/lxc/commands.c
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/console.c

index 059942bc9191f2dda9fd8c6a7e6e1d7ef00aa0f4..2ed83ca7850b471b664a2915a042a24652be479d 100644 (file)
@@ -682,6 +682,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
         where the output of this console goes.
       </para>
       <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>
           <term>
             <option>lxc.console.logfile</option>
index 880cb28c2f66a02dfb371d83fbfaacf2c9c71b90..653fd994f59b891ace33fb4694bc50d2e924ec3c 100644 (file)
@@ -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);
index 2e9077c1b1157400a6169667ab201acb234473fc..a2b3673a79b8115d29fea4d99e2fee26dc0a373f 100644 (file)
@@ -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);
index 43eeb4dedf26b7815ccd4786755fd8bd78fe1e91..1dc8924307a0d21438aa3b0449bf0c9438a058ff 100644 (file)
@@ -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;
 };
 
index c4d4c23945374dfafb6328f133589cd738696a2a..852589531a240cc2ef77e90c863ddde46a7d8abf 100644 (file)
@@ -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;
 }
 
index e152005f48ebfea773a5a2b99a0ed3827ccf66b1..c16e39bb685bb46495d53bc4b89e0cfcbd4e6867 100644 (file)
@@ -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);