@@ -28,6 +28,8 @@ use log::error;
28
28
#[ cfg( target_os = "linux" ) ]
29
29
use nix:: mount:: { mount, MsFlags } ;
30
30
#[ cfg( target_os = "linux" ) ]
31
+ use nix:: sched:: { unshare, CloneFlags } ;
32
+ #[ cfg( target_os = "linux" ) ]
31
33
use nix:: unistd:: { fork, ForkResult } ;
32
34
33
35
use crate :: error:: { Error , Result } ;
@@ -530,7 +532,15 @@ pub fn mount_rootfs(
530
532
target : impl AsRef < Path > ,
531
533
) -> Result < ( ) > {
532
534
//TODO add helper to mount fuse
533
- //TODO compactLowerdirOption for overlay
535
+ let max_size = page_size:: get ( ) ;
536
+ // NOTE: 512 id a buffer during pagesize check.
537
+ let ( chdir, options) =
538
+ if fs_type. unwrap_or ( "" ) == "overlay" && options_size ( options) >= max_size - 512 {
539
+ LowerdirCompactor :: new ( options) . compact ( )
540
+ } else {
541
+ ( None , options. to_vec ( ) )
542
+ } ;
543
+
534
544
let mut flags: MsFlags = MsFlags :: from_bits ( 0 ) . unwrap ( ) ;
535
545
let mut data = Vec :: new ( ) ;
536
546
options. iter ( ) . for_each ( |x| {
@@ -552,6 +562,12 @@ pub fn mount_rootfs(
552
562
None
553
563
} ;
554
564
565
+ unshare ( CloneFlags :: CLONE_FS ) . unwrap ( ) ;
566
+ if let Some ( workdir) = chdir {
567
+ env:: set_current_dir ( Path :: new ( & workdir) ) . unwrap_or_else ( |_| {
568
+ unsafe { libc:: _exit ( i32:: from ( MountExitCode :: ChdirErr ) ) } ;
569
+ } ) ;
570
+ }
555
571
// mount with non-propagation first, or remount with changed data
556
572
let oflags = flags. bitand ( PROPAGATION_TYPES . not ( ) ) ;
557
573
let zero: MsFlags = MsFlags :: from_bits ( 0 ) . unwrap ( ) ;
0 commit comments