@@ -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,42 @@ 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+ if !path. exists ( ) {
70+ return Err ( eyre ! ( "Explicit virtiofsd binary not found at: {}" , path) ) ;
71+ }
72+ path. to_string ( )
73+ } else {
74+ // Try common virtiofsd binary locations
75+ let virtiofsd_paths = [
76+ "/usr/libexec/virtiofsd" ,
77+ "/usr/bin/virtiofsd" ,
78+ "/usr/local/bin/virtiofsd" ,
79+ "/usr/lib/virtiofsd" ,
80+ ] ;
81+
82+ virtiofsd_paths
83+ . iter ( )
84+ . find ( |path| std:: path:: Path :: new ( path) . exists ( ) )
85+ . ok_or_else ( || {
86+ eyre ! (
87+ "virtiofsd binary not found. Searched paths: {}. \
88+ Set --virtiofsd or VIRTIOFSD_BIN to specify the path explicitly.",
89+ virtiofsd_paths. join( ", " )
90+ )
91+ } ) ?
92+ . to_string ( )
93+ } ;
8194
8295 // Check if virtiofsd supports --readonly flag
83- let supports_readonly = virtiofsd_supports_readonly ( virtiofsd_binary) . await ;
96+ let supports_readonly = virtiofsd_supports_readonly ( & virtiofsd_binary) . await ;
8497 debug ! (
8598 "virtiofsd at {} supports --readonly: {}" ,
8699 virtiofsd_binary, supports_readonly
87100 ) ;
88101
89- let mut cmd = tokio:: process:: Command :: new ( virtiofsd_binary) ;
102+ let mut cmd = tokio:: process:: Command :: new ( & virtiofsd_binary) ;
90103 // SAFETY: This API is safe to call in a forked child.
91104 #[ allow( unsafe_code) ]
92105 unsafe {
@@ -148,13 +161,13 @@ pub async fn spawn_virtiofsd_async(config: &VirtiofsConfig) -> Result<tokio::pro
148161 let child = cmd. spawn ( ) . with_context ( || {
149162 format ! (
150163 "Failed to spawn virtiofsd. Binary: {}, Socket: {}, Shared dir: {}" ,
151- virtiofsd_binary, config. socket_path, config. shared_dir
164+ & virtiofsd_binary, config. socket_path, config. shared_dir
152165 )
153166 } ) ?;
154167
155168 debug ! (
156169 "Spawned virtiofsd: binary={}, socket={}, shared_dir={}, debug={}, log_file={:?}" ,
157- virtiofsd_binary, config. socket_path, config. shared_dir, config. debug, config. log_file
170+ & virtiofsd_binary, config. socket_path, config. shared_dir, config. debug, config. log_file
158171 ) ;
159172
160173 Ok ( child)
0 commit comments