1
- #![ cfg( not( windows) ) ]
2
1
/*
3
2
Copyright The containerd Authors.
4
3
@@ -25,30 +24,27 @@ use std::{
25
24
26
25
use lazy_static:: lazy_static;
27
26
use log:: error;
28
- #[ cfg( target_os = "linux" ) ]
29
- use nix:: mount:: { mount, MsFlags } ;
30
- #[ cfg( target_os = "linux" ) ]
31
- use nix:: sched:: { unshare, CloneFlags } ;
32
- #[ cfg( target_os = "linux" ) ]
33
- use nix:: unistd:: { fork, ForkResult } ;
27
+ use nix:: {
28
+ mount:: { mount, MsFlags } ,
29
+ sched:: { unshare, CloneFlags } ,
30
+ unistd:: { fork, ForkResult } ,
31
+ } ;
34
32
35
33
use crate :: error:: { Error , Result } ;
36
34
#[ cfg( not( feature = "async" ) ) ]
37
35
use crate :: monitor:: { monitor_subscribe, wait_pid, Topic } ;
38
36
39
- #[ cfg( target_os = "linux" ) ]
40
37
struct Flag {
41
38
clear : bool ,
42
39
flags : MsFlags ,
43
40
}
44
41
45
42
const OVERLAY_LOWERDIR_PREFIX : & str = "lowerdir=" ;
46
43
47
- #[ cfg( target_os = "linux" ) ]
48
44
lazy_static ! {
49
45
static ref MOUNT_FLAGS : HashMap <& ' static str , Flag > = {
50
46
let mut mf = HashMap :: new( ) ;
51
- let zero: MsFlags = MsFlags :: from_bits ( 0 ) . unwrap ( ) ;
47
+ let zero: MsFlags = MsFlags :: empty ( ) ;
52
48
mf. insert(
53
49
"async" ,
54
50
Flag {
@@ -267,20 +263,17 @@ fn longest_common_prefix(dirs: &[String]) -> &str {
267
263
// NOTE: the snapshot id is based on digits.
268
264
// in order to avoid to get snapshots/x, should be back to parent dir.
269
265
// however, there is assumption that the common dir is ${root}/io.containerd.v1.overlayfs/snapshots.
270
- #[ cfg( target_os = "linux" ) ]
271
266
fn trim_flawed_dir ( s : & str ) -> String {
272
267
s[ 0 ..s. rfind ( '/' ) . unwrap_or ( 0 ) + 1 ] . to_owned ( )
273
268
}
274
269
275
- #[ cfg( target_os = "linux" ) ]
276
270
#[ derive( Default ) ]
277
271
struct LowerdirCompactor {
278
272
options : Vec < String > ,
279
273
lowerdirs : Option < Vec < String > > ,
280
274
lowerdir_prefix : Option < String > ,
281
275
}
282
276
283
- #[ cfg( target_os = "linux" ) ]
284
277
impl LowerdirCompactor {
285
278
fn new ( options : & [ String ] ) -> Self {
286
279
Self {
@@ -409,7 +402,6 @@ impl From<MountExitCode> for Result<()> {
409
402
}
410
403
411
404
#[ cfg( not( feature = "async" ) ) ]
412
- #[ cfg( target_os = "linux" ) ]
413
405
pub fn mount_rootfs (
414
406
fs_type : Option < & str > ,
415
407
source : Option < & str > ,
@@ -428,7 +420,7 @@ pub fn mount_rootfs(
428
420
( None , options. to_vec ( ) )
429
421
} ;
430
422
431
- let mut flags: MsFlags = MsFlags :: from_bits ( 0 ) . unwrap ( ) ;
423
+ let mut flags: MsFlags = MsFlags :: empty ( ) ;
432
424
let mut data = Vec :: new ( ) ;
433
425
options. iter ( ) . for_each ( |x| {
434
426
if let Some ( f) = MOUNT_FLAGS . get ( x. as_str ( ) ) {
@@ -467,7 +459,7 @@ pub fn mount_rootfs(
467
459
}
468
460
// mount with non-propagation first, or remount with changed data
469
461
let oflags = flags. bitand ( PROPAGATION_TYPES . not ( ) ) ;
470
- let zero: MsFlags = MsFlags :: from_bits ( 0 ) . unwrap ( ) ;
462
+ let zero: MsFlags = MsFlags :: empty ( ) ;
471
463
if flags. bitand ( MsFlags :: MS_REMOUNT ) . eq ( & zero) || data. is_some ( ) {
472
464
mount ( source, target. as_ref ( ) , fs_type, oflags, data) . unwrap_or_else ( |err| {
473
465
error ! (
@@ -524,7 +516,6 @@ pub fn mount_rootfs(
524
516
}
525
517
526
518
#[ cfg( feature = "async" ) ]
527
- #[ cfg( target_os = "linux" ) ]
528
519
pub fn mount_rootfs (
529
520
fs_type : Option < & str > ,
530
521
source : Option < & str > ,
@@ -541,7 +532,7 @@ pub fn mount_rootfs(
541
532
( None , options. to_vec ( ) )
542
533
} ;
543
534
544
- let mut flags: MsFlags = MsFlags :: from_bits ( 0 ) . unwrap ( ) ;
535
+ let mut flags: MsFlags = MsFlags :: empty ( ) ;
545
536
let mut data = Vec :: new ( ) ;
546
537
options. iter ( ) . for_each ( |x| {
547
538
if let Some ( f) = MOUNT_FLAGS . get ( x. as_str ( ) ) {
@@ -562,15 +553,15 @@ pub fn mount_rootfs(
562
553
None
563
554
} ;
564
555
565
- unshare ( CloneFlags :: CLONE_FS ) . unwrap ( ) ;
566
556
if let Some ( workdir) = chdir {
557
+ unshare ( CloneFlags :: CLONE_FS ) ?;
567
558
env:: set_current_dir ( Path :: new ( & workdir) ) . unwrap_or_else ( |_| {
568
559
unsafe { libc:: _exit ( i32:: from ( MountExitCode :: ChdirErr ) ) } ;
569
560
} ) ;
570
561
}
571
562
// mount with non-propagation first, or remount with changed data
572
563
let oflags = flags. bitand ( PROPAGATION_TYPES . not ( ) ) ;
573
- let zero: MsFlags = MsFlags :: from_bits ( 0 ) . unwrap ( ) ;
564
+ let zero: MsFlags = MsFlags :: empty ( ) ;
574
565
if flags. bitand ( MsFlags :: MS_REMOUNT ) . eq ( & zero) || data. is_some ( ) {
575
566
mount ( source, target. as_ref ( ) , fs_type, oflags, data) . map_err ( mount_error ! (
576
567
e,
@@ -605,18 +596,7 @@ pub fn mount_rootfs(
605
596
Ok ( ( ) )
606
597
}
607
598
608
- #[ cfg( not( target_os = "linux" ) ) ]
609
- pub fn mount_rootfs (
610
- fs_type : Option < & str > ,
611
- source : Option < & str > ,
612
- options : & [ String ] ,
613
- target : impl AsRef < Path > ,
614
- ) -> Result < ( ) > {
615
- Err ( Error :: Unimplemented ( "start" . to_string ( ) ) )
616
- }
617
-
618
599
#[ cfg( test) ]
619
- #[ cfg( target_os = "linux" ) ]
620
600
mod tests {
621
601
use super :: * ;
622
602
0 commit comments