[lxc-devel] [go-lxc/v2] container: add ConsoleLog() API extension
brauner on Github
lxc-bot at linuxcontainers.org
Thu Nov 9 09:27:06 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 365 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171109/8ae4e8cc/attachment.bin>
-------------- next part --------------
From fb735da937253900d770ab9d8811552328dc0762 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 9 Nov 2017 10:23:34 +0100
Subject: [PATCH 1/2] lxc-binding: export VERSION_AT_LEAST()
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxc-binding.c | 5 -----
lxc-binding.h | 5 +++++
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lxc-binding.c b/lxc-binding.c
index 53542b8..02fc15f 100644
--- a/lxc-binding.c
+++ b/lxc-binding.c
@@ -19,11 +19,6 @@
#define LXC_DEVEL 0
#endif
-#define VERSION_AT_LEAST(major, minor, micro) \
- ((LXC_DEVEL == 1) || (!(major > LXC_VERSION_MAJOR || \
- major == LXC_VERSION_MAJOR && minor > LXC_VERSION_MINOR || \
- major == LXC_VERSION_MAJOR && minor == LXC_VERSION_MINOR && micro > LXC_VERSION_MICRO)))
-
bool go_lxc_defined(struct lxc_container *c) {
return c->is_defined(c);
}
diff --git a/lxc-binding.h b/lxc-binding.h
index cbf9ce2..34ca2c0 100644
--- a/lxc-binding.h
+++ b/lxc-binding.h
@@ -2,6 +2,11 @@
// Use of this source code is governed by a LGPLv2.1
// license that can be found in the LICENSE file.
+#define VERSION_AT_LEAST(major, minor, micro) \
+ ((LXC_DEVEL == 1) || (!(major > LXC_VERSION_MAJOR || \
+ major == LXC_VERSION_MAJOR && minor > LXC_VERSION_MINOR || \
+ major == LXC_VERSION_MAJOR && minor == LXC_VERSION_MINOR && micro > LXC_VERSION_MICRO)))
+
extern bool go_lxc_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path);
extern void go_lxc_clear_config(struct lxc_container *c);
extern bool go_lxc_clear_config_item(struct lxc_container *c, const char *key);
From eafbe8a65020a617b0a863d40570de61af366949 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 9 Nov 2017 10:24:11 +0100
Subject: [PATCH 2/2] container: add ConsoleLog() API extension
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
container.go | 29 +++++++++++++++++++++++++++++
lxc-binding.c | 8 ++++++++
lxc-binding.h | 12 ++++++++++++
options.go | 8 ++++++++
4 files changed, 57 insertions(+)
diff --git a/container.go b/container.go
index af5485a..b338857 100644
--- a/container.go
+++ b/container.go
@@ -22,6 +22,7 @@ import (
"strconv"
"strings"
"sync"
+ "syscall"
"time"
"unsafe"
)
@@ -1866,3 +1867,31 @@ func (c *Container) SetRunningConfigItem(key string, value string) error {
}
return nil
}
+
+// ConsoleLog allows to perform operations on the container's in-memory console
+// buffer.
+func (c *Container) ConsoleLog(opt ConsoleLogOptions) ([]byte, error) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ readMax := C.uint64_t(opt.ReadMax)
+ lxcConsoleLog := C.struct_lxc_console_log{
+ clear: C.bool(opt.ClearLog),
+ read: C.bool(opt.ReadLog),
+ read_max: &readMax,
+ data: nil,
+ write_logfile: C.bool(opt.WriteToLogFile),
+ }
+
+ ret := C.go_lxc_console_log(c.container, &lxcConsoleLog)
+ if ret < 0 {
+ return nil, syscall.Errno(-ret)
+ }
+
+ numBytes := C.int(*lxcConsoleLog.read_max)
+ if C.uint64_t(numBytes) != *lxcConsoleLog.read_max {
+ return nil, syscall.ERANGE
+ }
+
+ return C.GoBytes(unsafe.Pointer(lxcConsoleLog.data), numBytes), nil
+}
diff --git a/lxc-binding.c b/lxc-binding.c
index 02fc15f..9ac5bc5 100644
--- a/lxc-binding.c
+++ b/lxc-binding.c
@@ -458,3 +458,11 @@ bool go_lxc_set_running_config_item(struct lxc_container *c, const char *key, co
return false;
#endif
}
+
+int go_lxc_console_log(struct lxc_container *c, struct lxc_console_log *log) {
+#if VERSION_AT_LEAST(3, 0, 0)
+ return c->console_log(c, log);
+#else
+ return false;
+#endif
+}
diff --git a/lxc-binding.h b/lxc-binding.h
index 34ca2c0..6412f70 100644
--- a/lxc-binding.h
+++ b/lxc-binding.h
@@ -113,3 +113,15 @@ int go_lxc_migrate(struct lxc_container *c, unsigned int cmd, struct migrate_opt
extern bool go_lxc_attach_interface(struct lxc_container *c, const char *dev, const char *dst_dev);
extern bool go_lxc_detach_interface(struct lxc_container *c, const char *dev, const char *dst_dev);
+
+#if !VERSION_AT_LEAST(3, 0, 0)
+struct lxc_console_log {
+ bool clear;
+ bool read;
+ uint64_t *read_max;
+ char *data;
+ bool write_logfile;
+};
+#endif
+
+extern int go_lxc_console_log(struct lxc_container *c, struct lxc_console_log *log);
diff --git a/options.go b/options.go
index 7130851..df5ee22 100644
--- a/options.go
+++ b/options.go
@@ -198,3 +198,11 @@ type MigrateOptions struct {
PreservesInodes bool
GhostLimit uint64
}
+
+// ConsoleLogOptioins type is used for defining console log options.
+type ConsoleLogOptions struct {
+ ClearLog bool
+ ReadLog bool
+ ReadMax uint64
+ WriteToLogFile bool
+}
More information about the lxc-devel
mailing list