@@ -775,17 +775,14 @@ void hyper_unmount_all(void)
775
775
{
776
776
FILE * mtab ;
777
777
struct mntent * mnt ;
778
- char * mntlist [128 ];
779
- int i , n = 0 ;
780
- char * filesys ;
781
778
782
779
mtab = setmntent ("/proc/mounts" , "r" );
783
780
if (mtab == NULL ) {
784
781
fprintf (stderr , "cannot open /proc/mount" );
785
782
return ;
786
783
}
787
784
788
- while (n < 128 ) {
785
+ while (true ) {
789
786
mnt = getmntent (mtab );
790
787
if (mnt == NULL )
791
788
break ;
@@ -799,22 +796,20 @@ void hyper_unmount_all(void)
799
796
strcmp (mnt -> mnt_type , "devpts" ) == 0 )
800
797
continue ;
801
798
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 ));
803
810
}
804
811
805
812
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
-
818
813
sync ();
819
814
}
820
815
0 commit comments