@@ -21,6 +21,8 @@ pub struct VirtiofsConfig {
2121 pub readonly : bool ,
2222 /// Optional log file path for virtiofsd output.
2323 pub log_file : Option < Utf8PathBuf > ,
24+ /// Optional explicit path to virtiofsd binary (overrides auto-detection).
25+ pub virtiofsd_binary : Option < Utf8PathBuf > ,
2426}
2527
2628impl Default for VirtiofsConfig {
@@ -32,6 +34,7 @@ impl Default for VirtiofsConfig {
3234 // We don't need to write to this, there's a transient overlay
3335 readonly : true ,
3436 log_file : None ,
37+ virtiofsd_binary : None ,
3538 }
3639 }
3740}
@@ -61,32 +64,39 @@ pub async fn spawn_virtiofsd_async(config: &VirtiofsConfig) -> Result<tokio::pro
6164 // Validate configuration
6265 validate_virtiofsd_config ( config) ?;
6366
64- // Try common virtiofsd binary locations
65- let virtiofsd_paths = [
66- "/usr/libexec/virtiofsd" ,
67- "/usr/bin/virtiofsd" ,
68- "/usr/local/bin/virtiofsd" ,
69- "/usr/lib/virtiofsd" ,
70- ] ;
71-
72- let virtiofsd_binary = virtiofsd_paths
73- . iter ( )
74- . find ( |path| std:: path:: Path :: new ( path) . exists ( ) )
75- . ok_or_else ( || {
76- eyre ! (
77- "virtiofsd binary not found. Searched paths: {}. Please install virtiofsd." ,
78- virtiofsd_paths. join( ", " )
79- )
80- } ) ?;
67+ // Resolve virtiofsd binary: explicit override or path search
68+ let virtiofsd_binary: String = if let Some ( ref path) = config. virtiofsd_binary {
69+ path. to_string ( )
70+ } else {
71+ // Try common virtiofsd binary locations
72+ let virtiofsd_paths = [
73+ "/usr/libexec/virtiofsd" ,
74+ "/usr/bin/virtiofsd" ,
75+ "/usr/local/bin/virtiofsd" ,
76+ "/usr/lib/virtiofsd" ,
77+ ] ;
78+
79+ virtiofsd_paths
80+ . iter ( )
81+ . find ( |path| std:: path:: Path :: new ( path) . exists ( ) )
82+ . ok_or_else ( || {
83+ eyre ! (
84+ "virtiofsd binary not found. Searched paths: {}. \
85+ Set --virtiofsd or VIRTIOFSD_BIN to specify the path explicitly.",
86+ virtiofsd_paths. join( ", " )
87+ )
88+ } ) ?
89+ . to_string ( )
90+ } ;
8191
8292 // Check if virtiofsd supports --readonly flag
83- let supports_readonly = virtiofsd_supports_readonly ( virtiofsd_binary) . await ;
93+ let supports_readonly = virtiofsd_supports_readonly ( & virtiofsd_binary) . await ;
8494 debug ! (
8595 "virtiofsd at {} supports --readonly: {}" ,
8696 virtiofsd_binary, supports_readonly
8797 ) ;
8898
89- let mut cmd = tokio:: process:: Command :: new ( virtiofsd_binary) ;
99+ let mut cmd = tokio:: process:: Command :: new ( & virtiofsd_binary) ;
90100 // SAFETY: This API is safe to call in a forked child.
91101 #[ allow( unsafe_code) ]
92102 unsafe {
@@ -148,13 +158,13 @@ pub async fn spawn_virtiofsd_async(config: &VirtiofsConfig) -> Result<tokio::pro
148158 let child = cmd. spawn ( ) . with_context ( || {
149159 format ! (
150160 "Failed to spawn virtiofsd. Binary: {}, Socket: {}, Shared dir: {}" ,
151- virtiofsd_binary, config. socket_path, config. shared_dir
161+ & virtiofsd_binary, config. socket_path, config. shared_dir
152162 )
153163 } ) ?;
154164
155165 debug ! (
156166 "Spawned virtiofsd: binary={}, socket={}, shared_dir={}, debug={}, log_file={:?}" ,
157- virtiofsd_binary, config. socket_path, config. shared_dir, config. debug, config. log_file
167+ & virtiofsd_binary, config. socket_path, config. shared_dir, config. debug, config. log_file
158168 ) ;
159169
160170 Ok ( child)
0 commit comments