From 59487c2d1aeee28af0c74004196b5fa0f3da613c Mon Sep 17 00:00:00 2001 From: tanyifeng Date: Wed, 15 May 2019 12:42:08 +0800 Subject: [PATCH 098/131] lxc: make /dev bind mount from host tmpfs for system container reason:make /dev bind mount from host tmpfs for system container Signed-off-by: zhangsong Signed-off-by: LiFeng --- src/lxc/conf.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 341fdab5..3780966a 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1122,7 +1122,7 @@ on_error: * error, log it but don't fail yet. */ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, - const char *lxcpath) + const char *lxcpath, char *systemd) { int ret; size_t clen; @@ -1147,13 +1147,21 @@ static int mount_autodev(const char *name, const struct lxc_rootfs *rootfs, goto reset_umask; } - ret = safe_mount("none", path, "tmpfs", 0, "size=500000,mode=755", + if (systemd != NULL && !strcmp(systemd, "true")) { + ret = mount(path, path, "", MS_BIND, NULL); + if (ret < 0) { + SYSERROR("Failed to bind mount path \"%s\"", path); + goto reset_umask; + } + } else { + ret = safe_mount("none", path, "tmpfs", 0, "size=500000,mode=755", rootfs->path ? rootfs->mount : NULL); - if (ret < 0) { - SYSERROR("Failed to mount tmpfs on \"%s\"", path); - goto reset_umask; - } - TRACE("Mounted tmpfs on \"%s\"", path); + if (ret < 0) { + SYSERROR("Failed to mount tmpfs on \"%s\"", path); + goto reset_umask; + } + TRACE("Mounted tmpfs on \"%s\"", path); + } ret = snprintf(path, clen, "%s/dev/pts", rootfs->path ? rootfs->mount : ""); if (ret < 0 || (size_t)ret >= clen) { @@ -4130,7 +4138,7 @@ int lxc_setup(struct lxc_handler *handler) } if (lxc_conf->autodev > 0) { - ret = mount_autodev(name, &lxc_conf->rootfs, lxcpath); + ret = mount_autodev(name, &lxc_conf->rootfs, lxcpath, lxc_conf->systemd); if (ret < 0) { ERROR("Failed to mount \"/dev\""); goto on_error; -- 2.23.0