[lxc-devel] [lxc/master] Fix console none migration

tych0 on Github lxc-bot at linuxcontainers.org
Mon Mar 21 23:04:22 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 300 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160321/74c606f1/attachment.bin>
-------------- next part --------------
From 36d2096cf43340701150778d5547ec4f5a127338 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Mon, 21 Mar 2016 16:50:39 -0600
Subject: [PATCH 1/2] c/r: don't pass --ext-mount-map flag when console=none

We don't pass anything on the restore side since we didn't save anything,
but the restore side will expect something if we pass this. Instead, let's
not pass anything.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 src/lxc/criu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index 7b72c6e..1b3c4ac 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -259,9 +259,10 @@ static void exec_criu(struct criu_opts *opts)
 		DECLARE_ARG("--freeze-cgroup");
 		DECLARE_ARG(log);
 
-		DECLARE_ARG("--ext-mount-map");
-		DECLARE_ARG("/dev/console:console");
 		if (opts->tty_id[0]) {
+			DECLARE_ARG("--ext-mount-map");
+			DECLARE_ARG("/dev/console:console");
+
 			DECLARE_ARG("--external");
 			DECLARE_ARG(opts->tty_id);
 		}

From 97e4f1a91f39fa3b4012eedf8f4e56f419dd2cca Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Mon, 21 Mar 2016 16:52:02 -0600
Subject: [PATCH 2/2] c/r: don't fail if there is no console_fd on restore

If we set lxc.console=none, this fd won't exist, so let's not fail if it
doesn't. We already partially handled this case correctly, so let's
actually handle it correctly :)

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 src/lxc/criu.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index 1b3c4ac..16449bc 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -290,6 +290,11 @@ static void exec_criu(struct criu_opts *opts)
 		DECLARE_ARG(opts->cgroup_path);
 
 		if (tty_info[0]) {
+			if (opts->console_fd < 0) {
+				ERROR("lxc.console configured on source host but not target");
+				goto err;
+			}
+
 			ret = snprintf(buf, sizeof(buf), "fd[%d]:%s", opts->console_fd, tty_info);
 			if (ret < 0 || ret >= sizeof(buf))
 				goto err;
@@ -624,20 +629,22 @@ void do_restore(struct lxc_container *c, int status_pipe, char *directory, bool
 		os.cgroup_path = cgroup_canonical_path(handler);
 		os.console_fd = c->lxc_conf->console.slave;
 
-		/* Twiddle the FD_CLOEXEC bit. We want to pass this FD to criu
-		 * via --inherit-fd, so we don't want it to close.
-		 */
-		flags = fcntl(os.console_fd, F_GETFD);
-		if (flags < 0) {
-			SYSERROR("F_GETFD failed");
-			goto out_fini_handler;
-		}
+		if (os.console_fd >= 0) {
+			/* Twiddle the FD_CLOEXEC bit. We want to pass this FD to criu
+			 * via --inherit-fd, so we don't want it to close.
+			 */
+			flags = fcntl(os.console_fd, F_GETFD);
+			if (flags < 0) {
+				SYSERROR("F_GETFD failed: %d", os.console_fd);
+				goto out_fini_handler;
+			}
 
-		flags &= ~FD_CLOEXEC;
+			flags &= ~FD_CLOEXEC;
 
-		if (fcntl(os.console_fd, F_SETFD, flags) < 0) {
-			SYSERROR("F_SETFD failed");
-			goto out_fini_handler;
+			if (fcntl(os.console_fd, F_SETFD, flags) < 0) {
+				SYSERROR("F_SETFD failed");
+				goto out_fini_handler;
+			}
 		}
 		os.console_name = c->lxc_conf->console.name;
 


More information about the lxc-devel mailing list