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

Commit 7048d75

Browse files
authored
Merge pull request #306 from bergwolf/rootfs-ro
umount 9p with MNT_DETACH flag
2 parents 83bc75a + e3d13e7 commit 7048d75

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/util.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -775,17 +775,14 @@ void hyper_unmount_all(void)
775775
{
776776
FILE *mtab;
777777
struct mntent *mnt;
778-
char *mntlist[128];
779-
int i, n = 0;
780-
char *filesys;
781778

782779
mtab = setmntent("/proc/mounts", "r");
783780
if (mtab == NULL) {
784781
fprintf(stderr, "cannot open /proc/mount");
785782
return;
786783
}
787784

788-
while (n < 128) {
785+
while (true) {
789786
mnt = getmntent(mtab);
790787
if (mnt == NULL)
791788
break;
@@ -799,22 +796,20 @@ void hyper_unmount_all(void)
799796
strcmp(mnt->mnt_type, "devpts") == 0)
800797
continue;
801798

802-
mntlist[n++] = strdup(mnt->mnt_dir);
799+
fprintf(stdout, "umount %s\n", mnt->mnt_dir);
800+
/*
801+
* Umounting root w/o MNT_DETACH will make it readonly.
802+
* While it is ok for block devices, we do want to reuse
803+
* the same 9p share mount when the container is restarted.
804+
*
805+
* Just do MNT_DETACH umount because we call sync() afterwards.
806+
*/
807+
if (umount2(mnt->mnt_dir, MNT_DETACH) < 0)
808+
fprintf(stderr, ("umount %s: %s failed\n"),
809+
mnt->mnt_dir, strerror(errno));
803810
}
804811

805812
endmntent(mtab);
806-
807-
for (i = n - 1; i >= 0; i--) {
808-
filesys = mntlist[i];
809-
fprintf(stdout, "umount %s\n", filesys);
810-
if ((umount(mntlist[i]) < 0) && (umount2(mntlist[i], MNT_DETACH) < 0)) {
811-
fprintf(stdout, ("umount %s: %s failed\n"),
812-
filesys, strerror(errno));
813-
}
814-
free(filesys);
815-
mntlist[i] = NULL;
816-
}
817-
818813
sync();
819814
}
820815

0 commit comments

Comments
 (0)