[lxc-devel] [lxc/lxc] 5f4e44: c/r: explicitly emit bind mounts as criu arguments

2016-10-31 Thread GitHub
  Branch: refs/heads/master
  Home:   https://github.com/lxc/lxc
  Commit: 5f4e44a22df60c25005c95b9326fd989efd80569
  https://github.com/lxc/lxc/commit/5f4e44a22df60c25005c95b9326fd989efd80569
  Author: Tycho Andersen 
  Date:   2016-10-31 (Mon, 31 Oct 2016)

  Changed paths:
M src/lxc/criu.c

  Log Message:
  ---
  c/r: explicitly emit bind mounts as criu arguments

We switched to --ext-mount-map auto because of "system" (liblxc) added
mounts like the cgmanager socket that weren't in the config file. This had
the added advantage that we could drop all the mount processing code,
because we no longer needed an --ext-mount-map argument.

The problem here is that mounts can move between hosts. While
--ext-mount-map auto does its best to detect this situation, it explicitly
disallows moves that change the path name. In LXD, we bind mount
/var/lib/lxd/shmounts/$container to /dev/.lxd-mounts for each container,
and so when a container is renamed in a migration, the name changes.
--ext-mount-map auto won't detect this, and so the migration fails.

We *could* implement mount rewriting in CRIU, but my experience with cgroup
and apparmor rewriting is that this is painful and error prone. Instead, it
is much easier to go back to explicitly listing --ext-mount-map arguments
from the config file, and allow the source of the bind to change. We leave
--ext-mount-map auto to catch any stragling (or future) system added
mounts.

I believe this should fix Launchpad Bug 1580765

Signed-off-by: Tycho Andersen 


  Commit: ed408e6674bd5372d6213c5d672422bf4d2862a7
  https://github.com/lxc/lxc/commit/ed408e6674bd5372d6213c5d672422bf4d2862a7
  Author: Tycho Andersen 
  Date:   2016-10-31 (Mon, 31 Oct 2016)

  Changed paths:
M src/lxc/log.h

  Log Message:
  ---
  log: bump LXC_LOG_BUFFER_SIZE to 4096

We need to log longer lines due to CRIU arguments.

Signed-off-by: Tycho Andersen 


  Commit: 52e129450eae6f916f1e5bf4342f543d07cfb481
  https://github.com/lxc/lxc/commit/52e129450eae6f916f1e5bf4342f543d07cfb481
  Author: Stéphane Graber 
  Date:   2016-10-31 (Mon, 31 Oct 2016)

  Changed paths:
M src/lxc/criu.c
M src/lxc/log.h

  Log Message:
  ---
  Merge pull request #1266 from tych0/do-mount-rewriting

Do mount rewriting


Compare: https://github.com/lxc/lxc/compare/a99e57fe9bd9...52e129450eae___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [lxc/master] Do mount rewriting

2016-10-31 Thread tych0 on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/1266

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===

From 5f4e44a22df60c25005c95b9326fd989efd80569 Mon Sep 17 00:00:00 2001
From: Tycho Andersen 
Date: Mon, 31 Oct 2016 10:07:25 -0600
Subject: [PATCH 1/2] c/r: explicitly emit bind mounts as criu arguments

We switched to --ext-mount-map auto because of "system" (liblxc) added
mounts like the cgmanager socket that weren't in the config file. This had
the added advantage that we could drop all the mount processing code,
because we no longer needed an --ext-mount-map argument.

The problem here is that mounts can move between hosts. While
--ext-mount-map auto does its best to detect this situation, it explicitly
disallows moves that change the path name. In LXD, we bind mount
/var/lib/lxd/shmounts/$container to /dev/.lxd-mounts for each container,
and so when a container is renamed in a migration, the name changes.
--ext-mount-map auto won't detect this, and so the migration fails.

We *could* implement mount rewriting in CRIU, but my experience with cgroup
and apparmor rewriting is that this is painful and error prone. Instead, it
is much easier to go back to explicitly listing --ext-mount-map arguments
from the config file, and allow the source of the bind to change. We leave
--ext-mount-map auto to catch any stragling (or future) system added
mounts.

I believe this should fix Launchpad Bug 1580765

Signed-off-by: Tycho Andersen 
---
 src/lxc/criu.c | 40 
 1 file changed, 40 insertions(+)

diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index 0940967..867139b 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -46,6 +46,12 @@
 #include "network.h"
 #include "utils.h"
 
+#if IS_BIONIC
+#include <../include/lxcmntent.h>
+#else
+#include 
+#endif
+
 #define CRIU_VERSION   "2.0"
 
 #define CRIU_GITID_VERSION "2.0"
@@ -123,6 +129,8 @@ static void exec_criu(struct criu_opts *opts)
int static_args = 23, argc = 0, i, ret;
int netnr = 0;
struct lxc_list *it;
+   FILE *mnts;
+   struct mntent mntent;
 
char buf[4096], tty_info[32];
size_t pos;
@@ -200,6 +208,8 @@ static void exec_criu(struct criu_opts *opts)
if (opts->user->action_script)
static_args += 2;
 
+   static_args += 2 * lxc_list_len(&opts->c->lxc_conf->mount_list);
+
ret = snprintf(log, PATH_MAX, "%s/%s.log", opts->user->directory, 
opts->action);
if (ret < 0 || ret >= PATH_MAX) {
ERROR("logfile name too long\n");
@@ -315,6 +325,36 @@ static void exec_criu(struct criu_opts *opts)
DECLARE_ARG(opts->user->action_script);
}
 
+   mnts = write_mount_file(&opts->c->lxc_conf->mount_list);
+   if (!mnts)
+   goto err;
+
+   while (getmntent_r(mnts, &mntent, buf, sizeof(buf))) {
+   char *fmt, *key, *val;
+   char arg[2 * PATH_MAX + 2];
+
+   if (strcmp(opts->action, "dump") == 0) {
+   fmt = "/%s:%s";
+   key = mntent.mnt_dir;
+   val = mntent.mnt_dir;
+   } else {
+   fmt = "%s:%s";
+   key = mntent.mnt_dir;
+   val = mntent.mnt_fsname;
+   }
+
+   ret = snprintf(arg, sizeof(arg), fmt, key, val);
+   if (ret < 0 || ret >= sizeof(arg)) {
+   fclose(mnts);
+   ERROR("snprintf failed");
+   goto err;
+   }
+
+   DECLARE_ARG("--ext-mount-map");
+   DECLARE_ARG(arg);
+   }
+   fclose(mnts);
+
if (strcmp(opts->action, "dump") == 0 || strcmp(opts->action, 
"pre-dump") == 0) {
char pid[32], *freezer_relative;
 

From ed408e6674bd5372d6213c5d672422bf4d2862a7 Mon Sep 17 00:00:00 2001
From: Tycho Andersen 
Date: Mon, 31 Oct 2016 19:48:38 +
Subject: [PATCH 2/2] log: bump LXC_LOG_BUFFER_SIZE to 4096

We need to log longer lines due to CRIU arguments.

Signed-off-by: Tycho Andersen 
---
 src/lxc/log.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/log.h b/src/lxc/log.h
index 7a36600..3c0bbaa 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -46,7 +46,7 @@
 #endif
 
 #define LXC_LOG_PREFIX_SIZE32
-#define LXC_LOG_BUFFER_SIZE1024
+#define LXC_LOG_BUFFER_SIZE4096
 
 /* This attribute is required to silence clang warnings */
 #if defined(__GNUC__)
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [lxd/master] correctly set liblxc loglevel to debug when in --debug mode

2016-10-31 Thread tych0 on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2585

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Tycho Andersen 
From a79e8ad5c4d107763d84e551d7c99799262b0ff8 Mon Sep 17 00:00:00 2001
From: Tycho Andersen 
Date: Mon, 31 Oct 2016 19:44:05 +
Subject: [PATCH] correctly set liblxc loglevel to debug when in --debug mode

Signed-off-by: Tycho Andersen 
---
 lxd/container_lxc.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 640618e..1917180 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -537,6 +537,7 @@ func (c *containerLXC) initLXC() error {
 
logLevel := "warn"
if debug {
+   logLevel = "debug"
} else if verbose {
logLevel = "info"
} else {
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel