From: dlezcano Date: Mon, 16 Feb 2009 10:13:15 +0000 (+0000) Subject: Mount bind the rootfs directory X-Git-Tag: lxc_0_6_0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b0f04774f57733d8c04b8a0f4c1dc76c28cd257;p=thirdparty%2Flxc.git Mount bind the rootfs directory From: Daniel Lezcano Instead of using a symlink to the rootfs, just mount bind the rootfs directory. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index adee146f7..f19f69585 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -454,7 +454,10 @@ static int configure_rootfs(const char *name, const char *rootfs) { char path[MAXPATHLEN]; char absrootfs[MAXPATHLEN]; + char fstab[MAXPATHLEN]; char *pwd; + int ret; + FILE *f; snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name); @@ -469,6 +472,29 @@ static int configure_rootfs(const char *name, const char *rootfs) return -1; } + if (mkdir(path, 0755)) { + lxc_log_syserror("failed to create the '%s' directory", path); + return -1; + } + + snprintf(fstab, MAXPATHLEN, LXCPATH "/%s/fstab", name); + + f = fopen(fstab, "a+"); + if (!f) { + lxc_log_syserror("failed to open fstab file"); + return -1; + } + + ret = fprintf(f, "%s %s none bind 0 0\n", absrootfs, path); + fclose(f); + + if (ret < 0) { + lxc_log_syserror("failed to add rootfs mount in fstab"); + return -1; + } + + snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs/rootfs", name); + return symlink(absrootfs, path); } @@ -641,8 +667,14 @@ static int unconfigure_rootfs(const char *name) { char path[MAXPATHLEN]; - snprintf(path, MAXPATHLEN, LXCPATH "/%s", name); + snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name); + +#warning deprecated code to be removed in the next version + + /* ugly but for backward compatibily, */ delete_info(path, "rootfs"); + rmdir(path); + unlink(path); return 0; } @@ -1202,16 +1234,16 @@ int lxc_configure(const char *name, struct lxc_conf *conf) return -LXC_ERROR_CONF_TTY; } - if (conf->rootfs && configure_rootfs(name, conf->rootfs)) { - lxc_log_error("failed to configure the rootfs"); - return -LXC_ERROR_CONF_ROOTFS; - } - if (conf->fstab && configure_mount(name, conf->fstab)) { lxc_log_error("failed to configure the mount points"); return -LXC_ERROR_CONF_MOUNT; } + if (conf->rootfs && configure_rootfs(name, conf->rootfs)) { + lxc_log_error("failed to configure the rootfs"); + return -LXC_ERROR_CONF_ROOTFS; + } + if (conf->pts && configure_pts(name, conf->pts)) { lxc_log_error("failed to configure a new pts instance"); return -LXC_ERROR_CONF_PTS; @@ -1550,12 +1582,6 @@ int lxc_create_tty(const char *name, struct lxc_tty_info *tty_info) if (!conf_has_tty(name)) return 0; -/* - if (!conf_has_rootfs(name)) { - lxc_log_warning("no rootfs is configured, ignoring ttys"); - return 0; - } -*/ snprintf(path, MAXPATHLEN, LXCPATH "/%s", name); if (read_info(path, "tty", tty, sizeof(tty)) < 0) {