mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-08-24 08:07:21 +00:00
Merge pull request #60 from laijs/msmove
Set the rootfs of the namespace to be the rootfs of the container
This commit is contained in:
+10
-5
@@ -351,7 +351,7 @@ static int hyper_container_init(void *data)
|
||||
{
|
||||
struct hyper_container_arg *arg = data;
|
||||
struct hyper_container *container = arg->c;
|
||||
char root[512], oldroot[512];
|
||||
char root[512], oldroot[512], rootfs[512];
|
||||
|
||||
fprintf(stdout, "%s in\n", __func__);
|
||||
if (container->exec.argv == NULL) {
|
||||
@@ -443,15 +443,20 @@ static int hyper_container_init(void *data)
|
||||
perror("bind oldroot failed");
|
||||
goto fail;
|
||||
}
|
||||
/* reuse oldroot array */
|
||||
sprintf(oldroot, "%s/%s/", root, container->rootfs);
|
||||
if (mount(oldroot, oldroot, NULL, MS_BIND|MS_REC, NULL) < 0) {
|
||||
|
||||
sprintf(rootfs, "%s/%s/", root, container->rootfs);
|
||||
if (mount(rootfs, rootfs, NULL, MS_BIND|MS_REC, NULL) < 0) {
|
||||
perror("failed to bind rootfs");
|
||||
goto fail;
|
||||
}
|
||||
chdir(rootfs);
|
||||
if (mount(rootfs, "/", NULL, MS_MOVE, NULL) < 0) {
|
||||
perror("failed to move rootfs");
|
||||
goto fail;
|
||||
}
|
||||
/* pivot_root won't work, see
|
||||
* Documention/filesystem/ramfs-rootfs-initramfs.txt */
|
||||
chroot(oldroot);
|
||||
chroot(".");
|
||||
|
||||
chdir("/");
|
||||
|
||||
|
||||
@@ -410,16 +410,7 @@ int hyper_enter_container(struct hyper_pod *pod,
|
||||
goto out;
|
||||
}
|
||||
|
||||
sprintf(path, "/tmp/hyper/%s/root/%s/", c->id, c->rootfs);
|
||||
fprintf(stdout, "root directory for container is %s, exec %s\n",
|
||||
path, exec->argv[0]);
|
||||
|
||||
/* TODO: wait for container finishing setup root */
|
||||
if (chroot(path) < 0) {
|
||||
perror("chroot for exec command failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
chdir("/");
|
||||
|
||||
ret = hyper_setup_env(c->envs, c->envs_num);
|
||||
|
||||
+2
-14
@@ -734,20 +734,14 @@ static int hyper_cmd_write_file(char *json, int length)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* TODO: wait for container finishing setup root */
|
||||
if (setns(mntns, CLONE_NEWNS) < 0) {
|
||||
perror("fail to enter container ns");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
sprintf(path, "/tmp/hyper/%s/root/%s/", c->id, c->rootfs);
|
||||
fprintf(stdout, "write file %s, data len %d\n", writter.file, writter.len);
|
||||
|
||||
/* TODO: wait for container finishing setup root */
|
||||
if (chroot(path) < 0) {
|
||||
perror("chroot for exec command failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
fd = open(writter.file, O_CREAT| O_TRUNC| O_WRONLY, 0644);
|
||||
if (fd < 0) {
|
||||
perror("fail to open target file");
|
||||
@@ -796,6 +790,7 @@ static int hyper_do_cmd_read_file(void *data)
|
||||
int len = 0, size, fd, ret = -1;
|
||||
struct hyper_file_arg *arg = data;
|
||||
|
||||
/* TODO: wait for container finishing setup root */
|
||||
if (setns(arg->mntns, CLONE_NEWNS) < 0) {
|
||||
perror("fail to enter container ns");
|
||||
goto err;
|
||||
@@ -803,12 +798,6 @@ static int hyper_do_cmd_read_file(void *data)
|
||||
|
||||
fprintf(stdout, "read file %s\n", arg->file);
|
||||
|
||||
/* TODO: wait for container finishing setup root */
|
||||
if (chroot(arg->root) < 0) {
|
||||
perror("chroot for exec command failed");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (stat(arg->file, &st) < 0) {
|
||||
perror("fail to state file");
|
||||
goto err;
|
||||
@@ -888,7 +877,6 @@ static int hyper_cmd_read_file(char *json, int length, uint32_t *datalen, uint8_
|
||||
arg.file = reader.file;
|
||||
arg.datalen = datalen;
|
||||
arg.data = data;
|
||||
sprintf(arg.root, "/tmp/hyper/%s/root/%s/", c->id, c->rootfs);
|
||||
|
||||
stack = malloc(stacksize);
|
||||
if (stack == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user