@@ -668,7 +668,18 @@ pub struct PassthroughFs<S: BitmapSlice + Send + Sync = ()> {
668668
669669impl < S : BitmapSlice + Send + Sync > PassthroughFs < S > {
670670 /// Create a Passthrough file system instance.
671- pub fn new ( cfg : Config ) -> io:: Result < PassthroughFs < S > > {
671+ pub fn new ( mut cfg : Config ) -> io:: Result < PassthroughFs < S > > {
672+ if cfg. no_open && cfg. cache_policy != CachePolicy :: Always {
673+ warn ! ( "passthroughfs: no_open only work with cache=always, reset to open mode" ) ;
674+ cfg. no_open = false ;
675+ }
676+ if cfg. writeback && cfg. cache_policy == CachePolicy :: Never {
677+ warn ! (
678+ "passthroughfs: writeback cache conflicts with cache=none, reset to no_writeback"
679+ ) ;
680+ cfg. writeback = false ;
681+ }
682+
672683 // Safe because this is a constant value and a valid C string.
673684 let proc_self_fd_cstr = unsafe { CStr :: from_bytes_with_nul_unchecked ( PROC_SELF_FD_CSTR ) } ;
674685 let proc_self_fd = Self :: open_file (
@@ -1985,4 +1996,54 @@ mod tests {
19851996 assert_eq ! ( unique_inode, 0x80800000000005 ) ;
19861997 }
19871998 }
1999+
2000+ #[ test]
2001+ fn test_validate_virtiofs_config ( ) {
2002+ // cache=none + writeback, writeback should be disabled
2003+ let fs_cfg = Config {
2004+ writeback : true ,
2005+ cache_policy : CachePolicy :: Never ,
2006+ ..Default :: default ( )
2007+ } ;
2008+ let fs = PassthroughFs :: < ( ) > :: new ( fs_cfg) . unwrap ( ) ;
2009+ assert ! ( !fs. cfg. writeback) ;
2010+
2011+ // cache=none + no_open, no_open should be disabled
2012+ let fs_cfg = Config {
2013+ no_open : true ,
2014+ cache_policy : CachePolicy :: Never ,
2015+ ..Default :: default ( )
2016+ } ;
2017+ let fs = PassthroughFs :: < ( ) > :: new ( fs_cfg) . unwrap ( ) ;
2018+ assert ! ( !fs. cfg. no_open) ;
2019+
2020+ // cache=auto + no_open, no_open should be disabled
2021+ let fs_cfg = Config {
2022+ no_open : true ,
2023+ cache_policy : CachePolicy :: Auto ,
2024+ ..Default :: default ( )
2025+ } ;
2026+ let fs = PassthroughFs :: < ( ) > :: new ( fs_cfg) . unwrap ( ) ;
2027+ assert ! ( !fs. cfg. no_open) ;
2028+
2029+ // cache=always + no_open, no_open should be set
2030+ let fs_cfg = Config {
2031+ no_open : true ,
2032+ cache_policy : CachePolicy :: Always ,
2033+ ..Default :: default ( )
2034+ } ;
2035+ let fs = PassthroughFs :: < ( ) > :: new ( fs_cfg) . unwrap ( ) ;
2036+ assert ! ( fs. cfg. no_open) ;
2037+
2038+ // cache=none + no_open + writeback, no_open and writeback should be disabled
2039+ let fs_cfg = Config {
2040+ no_open : true ,
2041+ writeback : true ,
2042+ cache_policy : CachePolicy :: Never ,
2043+ ..Default :: default ( )
2044+ } ;
2045+ let fs = PassthroughFs :: < ( ) > :: new ( fs_cfg) . unwrap ( ) ;
2046+ assert ! ( !fs. cfg. no_open) ;
2047+ assert ! ( !fs. cfg. writeback) ;
2048+ }
19882049}
0 commit comments