@@ -129,8 +129,6 @@ pub fn bind(variant: &str, dirs: Vec<String>) -> Result<()> {
129129 . map ( |dir| dir. trim_end_matches ( "/" ) . to_string ( ) )
130130 . collect ( ) ;
131131
132- let mount_point = format ! ( "/mnt/{EPHEMERAL_MNT}" ) ;
133- let mount_point = Path :: new ( & mount_point) ;
134132 let allowed_dirs = allowed_bind_dirs ( variant) ;
135133 for dir in & dirs {
136134 let exact_match = allowed_dirs. allowed_exact . contains ( dir. as_str ( ) ) ;
@@ -150,26 +148,32 @@ pub fn bind(variant: &str, dirs: Vec<String>) -> Result<()> {
150148 }
151149 )
152150 }
153- std:: fs:: create_dir_all ( mount_point) . context ( error:: MkdirSnafu { } ) ?;
154151
155- info ! ( "mounting {device_name:?} as {mount_point:?}" ) ;
156- let output = Command :: new ( MOUNT )
157- . args ( [
158- OsString :: from ( device_name. clone ( ) ) ,
159- OsString :: from ( mount_point. as_os_str ( ) ) ,
160- ] )
161- . output ( )
162- . context ( error:: ExecutionFailureSnafu { command : MOUNT } ) ?;
152+ let mount_point = format ! ( "/mnt/{EPHEMERAL_MNT}" ) ;
153+ if !is_mounted ( & mount_point) ? {
154+ std:: fs:: create_dir_all ( & mount_point) . context ( error:: MkdirSnafu { } ) ?;
155+ info ! ( "mounting {device_name} as {mount_point}" ) ;
156+ let output = Command :: new ( MOUNT )
157+ . args ( [
158+ OsString :: from ( device_name. clone ( ) ) ,
159+ OsString :: from ( & mount_point) ,
160+ ] )
161+ . output ( )
162+ . context ( error:: ExecutionFailureSnafu { command : MOUNT } ) ?;
163163
164- ensure ! (
165- output. status. success( ) ,
166- error:: MountArrayFailureSnafu {
167- what: device_name,
168- dest: mount_point. to_string_lossy( ) . to_string( ) ,
169- output
170- }
171- ) ;
164+ ensure ! (
165+ output. status. success( ) ,
166+ error:: MountArrayFailureSnafu {
167+ what: device_name,
168+ dest: & mount_point,
169+ output
170+ }
171+ ) ;
172+ } else {
173+ info ! ( "device already mounted at {mount_point}, skipping mount" ) ;
174+ }
172175
176+ let mount_point = Path :: new ( & mount_point) ;
173177 for dir in & dirs {
174178 // construct a directory name (E.g. /var/lib/kubelet => ._var_lib_kubelet) that will be
175179 // unique between the binding targets
0 commit comments