From ea196f786da2a9a7d8c30e372f44faa76739003a Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Sat, 2 Apr 2016 17:41:55 +0800 Subject: [PATCH] move mount of fsmap into container_setup_volume() Signed-off-by: Lai Jiangshan --- src/container.c | 84 ++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/src/container.c b/src/container.c index 8769686..de99c2d 100644 --- a/src/container.c +++ b/src/container.c @@ -74,6 +74,47 @@ static int container_setup_volume(struct hyper_container *container) umount(path); } + for (i = 0; i < container->maps_num; i++) { + struct stat st; + char src[512]; + struct fsmap *map = &container->maps[i]; + + sprintf(src, "/.oldroot/tmp/hyper/shared/%s", map->source); + fprintf(stdout, "mount %s to %s\n", src, map->path); + + stat(src, &st); + if (st.st_mode & S_IFDIR) { + if (hyper_mkdir(map->path) < 0) { + perror("create map dir failed"); + continue; + } + + if (map->docker && container->initialize && + (container_populate_volume(map->path, src) < 0)) { + fprintf(stderr, "fail to populate volume %s\n", map->path); + continue; + } + } else { + int fd = open(map->path, O_CREAT|O_WRONLY, 0755); + if (fd < 0) { + perror("create map file failed"); + continue; + } + close(fd); + } + + if (mount(src, map->path, NULL, MS_BIND, NULL) < 0) { + perror("mount fsmap faled"); + continue; + } + + if (map->readonly == 0) + continue; + + if (mount(src, map->path, NULL, MS_BIND | MS_REMOUNT | MS_RDONLY, NULL) < 0) + perror("mount fsmap faled"); + } + return 0; } @@ -113,9 +154,7 @@ static void container_unmount_oldroot(char *path) static int container_setup_mount(struct hyper_container *container) { - int i, fd; char src[512]; - struct fsmap *map; hyper_mkdir("/proc"); hyper_mkdir("/sys"); @@ -158,47 +197,6 @@ static int container_setup_mount(struct hyper_container *container) if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) perror("link /dev/pts/ptmx to /dev/ptmx failed"); - for (i = 0; i < container->maps_num; i++) { - struct stat st; - - map = &container->maps[i]; - - sprintf(src, "/.oldroot/tmp/hyper/shared/%s", map->source); - fprintf(stdout, "mount %s to %s\n", src, map->path); - - stat(src, &st); - if (st.st_mode & S_IFDIR) { - if (hyper_mkdir(map->path) < 0) { - perror("create map dir failed"); - continue; - } - - if (map->docker && container->initialize && - (container_populate_volume(map->path, src) < 0)) { - fprintf(stderr, "fail to populate volume %s\n", map->path); - continue; - } - } else { - fd = open(map->path, O_CREAT|O_WRONLY, 0755); - if (fd < 0) { - perror("create map file failed"); - continue; - } - close(fd); - } - - if (mount(src, map->path, NULL, MS_BIND, NULL) < 0) { - perror("mount fsmap faled"); - continue; - } - - if (map->readonly == 0) - continue; - - if (mount(src, map->path, NULL, MS_BIND | MS_REMOUNT | MS_RDONLY, NULL) < 0) - perror("mount fsmap faled"); - } - return 0; }