Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit f36fbef

Browse files
committed
share /dev/shm for all the containers in the pod
fix #323 All containers in the pod share the same ipc namespace. However, posix ipc primitives are shm_open() family whose behaviors implemented in glibc are to create&share the shm objects within /dev/shm (or scans /proceed/mounts for any tmpfs if /dev/shm is not tmpfs). So we have to create the only one tmpfs mount and share it to all the containers. Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
1 parent 4a00f0f commit f36fbef

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/container.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ static int container_setup_mount(struct hyper_container *container)
307307
return -1;
308308
}
309309

310-
if (mount("tmpfs", "./dev/shm/", "tmpfs", MS_NOSUID| MS_NODEV, NULL) < 0) {
311-
perror("mount shm failed");
310+
if (mount("/tmp/hyper/shm", "./dev/shm/", "tmpfs", MS_BIND, NULL) < 0) {
311+
perror("bind mount shared shm failed");
312312
return -1;
313313
}
314314

src/init.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,30 @@ int hyper_enter_sandbox(struct hyper_pod *pod, int pid_efd)
403403
return ret;
404404
}
405405

406+
/*
407+
* All containers in the pod share the same ipc namespace. However,
408+
* posix ipc primitives are shm_open() family whose behaviors
409+
* implemented in glibc are to create&share the shm objects within
410+
* /dev/shm (or scans /proceed/mounts for any tmpfs if /dev/shm
411+
* is not tmpfs).
412+
* So we have to create the only one tmpfs mount and share it
413+
* to all the containers.
414+
*/
415+
static int hyper_setup_shm(struct hyper_pod *pod)
416+
{
417+
if (hyper_mkdir("/tmp/hyper/shm", 0755) < 0) {
418+
perror("create shared shm directory failed");
419+
return -1;
420+
}
421+
422+
if (mount("tmpfs", "/tmp/hyper/shm", "tmpfs", MS_NOSUID| MS_NODEV, NULL) < 0) {
423+
perror("mount shm failed");
424+
return -1;
425+
}
426+
427+
return 0;
428+
}
429+
406430
#ifdef WITH_VBOX
407431

408432
#define MAX_HOST_NAME 256
@@ -535,6 +559,11 @@ static int hyper_setup_pod(struct hyper_pod *pod)
535559
return -1;
536560
}
537561

562+
if (hyper_setup_shm(pod) < 0) {
563+
fprintf(stderr, "setup shared shm failed\n");
564+
return -1;
565+
}
566+
538567
if (hyper_setup_pod_init(pod) < 0) {
539568
fprintf(stderr, "start container failed\n");
540569
return -1;

0 commit comments

Comments
 (0)