[lxc-devel] [lxc/master] start: remove umount2()
brauner on Github
lxc-bot at linuxcontainers.org
Wed May 10 11:35:19 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 829 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170510/99ee032f/attachment.bin>
-------------- next part --------------
From a1766c7ecef73ed33787d17b8ea6ab4b1d485399 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 10 May 2017 13:27:38 +0200
Subject: [PATCH 1/2] start: remove umount2()
I really fail to see the point of this and git {blame, log -S} don't really
enlighten me on the reason for this as well. But I might be dense. The way I
see it the only thing this line achieves is causing trouble when the container
is started as root because the umount2() call will umount e.g.
/usr/lib/x86_64-linux-gnu/lxc in case it is a mountpoint on the host. Note,
this is because lxc_spawn() is still called in the hosts namespaces.
Closes #3255.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/start.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 61d268a..db2a56e 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -1289,9 +1289,6 @@ static int lxc_spawn(struct lxc_handler *handler)
if (lxc_sync_barrier_child(handler, LXC_SYNC_POST_CGROUP))
return -1;
- if (detect_shared_rootfs())
- umount2(handler->conf->rootfs.mount, MNT_DETACH);
-
if (handler->ops->post_start(handler, handler->data))
goto out_abort;
From 3aa1c7cceea7147347b27544360910d632d8fbf0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 10 May 2017 13:32:23 +0200
Subject: [PATCH 2/2] conf: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/conf.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 8372da6..35bdb24 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1287,23 +1287,23 @@ int prepare_ramfs_root(char *root)
char *p2;
if (realpath(root, nroot) == NULL)
- return -1;
+ return -errno;
if (chdir("/") == -1)
- return -1;
+ return -errno;
/*
* We could use here MS_MOVE, but in userns this mount is
* locked and can't be moved.
*/
- if (mount(root, "/", NULL, MS_REC | MS_BIND, NULL)) {
+ if (mount(root, "/", NULL, MS_REC | MS_BIND, NULL) < 0) {
SYSERROR("Failed to move %s into /", root);
- return -1;
+ return -errno;
}
- if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
+ if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL) < 0) {
SYSERROR("Failed to make . rprivate");
- return -1;
+ return -errno;
}
/*
@@ -1369,17 +1369,28 @@ int prepare_ramfs_root(char *root)
static int setup_pivot_root(const struct lxc_rootfs *rootfs)
{
- if (!rootfs->path)
+ if (!rootfs->path) {
+ DEBUG("container does not have a rootfs, so not doing pivot root");
return 0;
+ }
if (detect_ramfs_rootfs()) {
- if (prepare_ramfs_root(rootfs->mount))
+ DEBUG("detected that container is on ramfs");
+ if (prepare_ramfs_root(rootfs->mount)) {
+ ERROR("failed to prepare minimal ramfs root");
return -1;
- } else if (setup_rootfs_pivot_root(rootfs->mount)) {
- ERROR("failed to setup pivot root");
+ }
+
+ DEBUG("prepared ramfs root for container");
+ return 0;
+ }
+
+ if (setup_rootfs_pivot_root(rootfs->mount) < 0) {
+ ERROR("failed to pivot root");
return -1;
}
+ DEBUG("finished pivot root");
return 0;
}
More information about the lxc-devel
mailing list