@@ -340,6 +340,7 @@ pub struct PassthroughFs {
340
340
announce_submounts : AtomicBool ,
341
341
my_uid : Option < libc:: uid_t > ,
342
342
my_gid : Option < libc:: gid_t > ,
343
+ cap_fowner : bool ,
343
344
344
345
cfg : Config ,
345
346
}
@@ -390,6 +391,9 @@ impl PassthroughFs {
390
391
Some ( unsafe { libc:: getgid ( ) } )
391
392
} ;
392
393
394
+ let cap_fowner =
395
+ has_cap ( None , CapSet :: Effective , Capability :: CAP_FOWNER ) . unwrap_or_default ( ) ;
396
+
393
397
// Safe because we just opened this fd or it was provided by our caller.
394
398
let proc_self_fd = unsafe { File :: from_raw_fd ( fd) } ;
395
399
@@ -408,6 +412,7 @@ impl PassthroughFs {
408
412
announce_submounts : AtomicBool :: new ( false ) ,
409
413
my_uid,
410
414
my_gid,
415
+ cap_fowner,
411
416
cfg,
412
417
} )
413
418
}
@@ -676,8 +681,15 @@ impl PassthroughFs {
676
681
Ok ( ( ) )
677
682
}
678
683
679
- fn do_open ( & self , inode : Inode , flags : u32 ) -> io:: Result < ( Option < Handle > , OpenOptions ) > {
684
+ fn do_open ( & self , inode : Inode , mut flags : u32 ) -> io:: Result < ( Option < Handle > , OpenOptions ) > {
680
685
debug ! ( "do_open: {:?}" , inode) ;
686
+ if !self . cap_fowner {
687
+ // O_NOATIME can only be used with CAP_FOWNER or if we are the file
688
+ // owner. Not worth checking the latter, just drop it if we don't
689
+ // have the cap. This makes overlayfs mounts with virtiofs lower dirs
690
+ // work.
691
+ flags &= !( libc:: O_NOATIME as u32 ) ;
692
+ }
681
693
let file = RwLock :: new ( self . open_inode ( inode, flags as i32 ) ?) ;
682
694
683
695
let handle = self . next_handle . fetch_add ( 1 , Ordering :: Relaxed ) ;
0 commit comments