@@ -804,7 +804,10 @@ fn have_required_join_capabilities() -> Result<bool> {
804804}
805805
806806const OVERLAY_ARGS_RO_PREFIX : & str = "ro" ;
807+ const OVERLAY_ARGS_INDEX : & str = "index" ;
807808const OVERLAY_ARGS_INDEX_ON : & str = "index=on" ;
809+ const OVERLAY_ARGS_METACOPY : & str = "metacopy" ;
810+ const OVERLAY_ARGS_METACOPY_ON : & str = "metacopy=on" ;
808811
809812/// A struct for holding the options that will be included
810813/// in the overlayfs mount command when mounting an environment.
@@ -821,7 +824,11 @@ pub(crate) struct OverlayMountOptions {
821824 /// spfs, since we rely on hardlinks for deduplication but
822825 /// expect that file to be able to appear in mutliple places
823826 /// as separate files that just so happen to share the same content.
824- pub break_hardlinks : bool ,
827+ break_hardlinks : bool ,
828+ /// When true, overlayfs will use extended file attributes to avoid
829+ /// copying file data when only the metadata of a file has changed.
830+ /// https://www.kernel.org/doc/html/latest/filesystems/overlayfs.html#metadata-only-copy-up
831+ metadata_copy_up : bool ,
825832}
826833
827834impl OverlayMountOptions {
@@ -830,18 +837,23 @@ impl OverlayMountOptions {
830837 Self {
831838 read_only : !rt. status . editable ,
832839 break_hardlinks : true ,
840+ metadata_copy_up : true ,
833841 }
834842 }
835843
836844 /// Return the options that should be included in the mount request.
837- pub ( crate ) fn options ( & self ) -> Vec < & str > {
845+ pub fn to_options ( & self ) -> Vec < & ' static str > {
846+ let params = runtime:: overlayfs:: overlayfs_available_options ( ) ;
838847 let mut opts = Vec :: new ( ) ;
839848 if self . read_only {
840849 opts. push ( OVERLAY_ARGS_RO_PREFIX ) ;
841850 }
842- if self . break_hardlinks {
851+ if self . break_hardlinks && params . contains ( OVERLAY_ARGS_INDEX ) {
843852 opts. push ( OVERLAY_ARGS_INDEX_ON ) ;
844853 }
854+ if self . metadata_copy_up && params. contains ( OVERLAY_ARGS_METACOPY ) {
855+ opts. push ( OVERLAY_ARGS_METACOPY_ON ) ;
856+ }
845857 opts
846858 }
847859}
@@ -860,7 +872,7 @@ pub(crate) fn get_overlay_args<P: AsRef<Path>>(
860872 let mut args = String :: with_capacity ( 4096 ) ;
861873
862874 let mount_options = OverlayMountOptions :: new ( rt) ;
863- for option in mount_options. options ( ) {
875+ for option in mount_options. to_options ( ) {
864876 args. push_str ( option) ;
865877 args. push ( ',' ) ;
866878 }
0 commit comments