@@ -464,6 +464,15 @@ pub struct Config {
464
464
/// share memory file to attack the host.
465
465
pub seal_size : bool ,
466
466
467
+ /// Whether count mount ID or not when comparing two inodes. By default we think two inodes
468
+ /// are same if their inode number and st_dev are the same. When `enable_mntid` is set as
469
+ /// 'true', inode's mount ID will be taken into account as well. For example, bindmount the
470
+ /// same file into virtiofs' source dir, the two bindmounted files will be identified as two
471
+ /// different inodes when this option is true, so the don't share pagecache.
472
+ ///
473
+ /// The default value for this option is `false`.
474
+ pub enable_mntid : bool ,
475
+
467
476
/// What size file supports dax
468
477
/// * If dax_file_size == None, DAX will disable to all files.
469
478
/// * If dax_file_size == 0, DAX will enable all files.
@@ -488,6 +497,7 @@ impl Default for Config {
488
497
inode_file_handles : false ,
489
498
no_readdir : false ,
490
499
seal_size : false ,
500
+ enable_mntid : false ,
491
501
dax_file_size : None ,
492
502
}
493
503
}
@@ -591,6 +601,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
591
601
592
602
let ( file_or_handle, st, ids_altkey, handle_altkey) = Self :: open_file_or_handle (
593
603
self . cfg . inode_file_handles ,
604
+ self . cfg . enable_mntid ,
594
605
libc:: AT_FDCWD ,
595
606
& root,
596
607
& self . mount_fds ,
@@ -775,6 +786,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
775
786
/// Create a File or File Handle for `name` under directory `dir_fd` to support `lookup()`.
776
787
fn open_file_or_handle < F > (
777
788
use_handle : bool ,
789
+ use_mntid : bool ,
778
790
dir_fd : RawFd ,
779
791
name : & CStr ,
780
792
mount_fds : & MountFds ,
@@ -805,13 +817,21 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
805
817
806
818
let inode_stat = match & file_or_handle {
807
819
FileOrHandle :: File ( f) => {
808
- // TODO: use statx(2) to query mntid when 5.8 kernel or later are widely used.
820
+ // Count mount ID as part of alt key if use_mntid is true. Note that using
821
+ // name_to_handle_at() to get mntid is kind of expensive in Lookup intensive
822
+ // workloads, e.g. when cache is none and accessing lots of files.
809
823
//
810
824
// Some filesystems don't support file handle, for example overlayfs mounted
811
825
// without index feature, if so just use mntid 0 in that case.
812
- let mnt_id = match FileHandle :: from_name_at ( dir_fd, name) {
813
- Ok ( h) => h. mnt_id ,
814
- Err ( _) => 0 ,
826
+ //
827
+ // TODO: use statx(2) to query mntid when 5.8 kernel or later are widely used.
828
+ let mnt_id = if use_mntid {
829
+ match FileHandle :: from_name_at ( dir_fd, name) {
830
+ Ok ( h) => h. mnt_id ,
831
+ Err ( _) => 0 ,
832
+ }
833
+ } else {
834
+ 0
815
835
} ;
816
836
InodeStat {
817
837
stat : Self :: stat ( f, None ) ?,
@@ -849,6 +869,7 @@ impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
849
869
let dir_file = dir. get_file ( & self . mount_fds ) ?;
850
870
let ( file_or_handle, st, ids_altkey, handle_altkey) = Self :: open_file_or_handle (
851
871
self . cfg . inode_file_handles ,
872
+ self . cfg . enable_mntid ,
852
873
dir_file. as_raw_fd ( ) ,
853
874
name,
854
875
& self . mount_fds ,
0 commit comments