@@ -40,6 +40,7 @@ pub struct VmConfigHandle {
4040
4141impl VmConfigHandle {
4242 pub fn new ( ) -> Self {
43+ crate :: diagnostics:: ensure_tracing_init ( ) ;
4344 Self {
4445 builder : Mutex :: new ( VmConfigBuilder :: new ( ) ) ,
4546 }
@@ -51,12 +52,29 @@ impl VmConfigHandle {
5152
5253 pub fn create_vm ( & self , socket_path : String , timeout_ms : u32 ) -> Result < VmHandle , HRESULT > {
5354 if timeout_ms == 0 {
55+ tracing:: warn!( target: "wslopenvmm::rpc" , "CreateVm requires a nonzero timeout" ) ;
5456 return Err ( E_INVALIDARG ) ;
5557 }
5658 let timeout = Duration :: from_millis ( u64:: from ( timeout_ms) ) ;
57- let deadline = Instant :: now ( ) + timeout;
58- let mut builder = self . builder . try_lock_until ( deadline) . ok_or ( rpc:: TIMEOUT ) ?;
59- builder. create_vm ( socket_path, timeout, deadline)
59+ let started = Instant :: now ( ) ;
60+ let deadline = started + timeout;
61+ tracing:: info!( target: "wslopenvmm::rpc" , "CreateVm starting with timeout {timeout_ms} ms" ) ;
62+ let Some ( mut builder) = self . builder . try_lock_until ( deadline) else {
63+ tracing:: warn!( target: "wslopenvmm::rpc" , "CreateVm timed out waiting for the configuration lock; no request sent" ) ;
64+ return Err ( rpc:: TIMEOUT ) ;
65+ } ;
66+ let result = builder. create_vm ( socket_path, timeout, deadline) ;
67+ match & result {
68+ Ok ( _) => {
69+ tracing:: info!( target: "wslopenvmm::rpc" , "CreateVm completed in {:?}" , started. elapsed( ) )
70+ }
71+ Err ( error) => tracing:: warn!(
72+ target: "wslopenvmm::rpc" ,
73+ "CreateVm failed with HRESULT {:#010x} after {:?}; configuration status: {:?}" ,
74+ error. 0 , started. elapsed( ) , builder. status
75+ ) ,
76+ }
77+ result
6078 }
6179}
6280
@@ -94,31 +112,42 @@ impl VmConfigBuilder {
94112 deadline : Instant ,
95113 ) -> Result < VmHandle , HRESULT > {
96114 if self . status == VmConfigStatus :: CreationOutcomeUnknown {
115+ tracing:: warn!( target: "wslopenvmm::rpc" , "CreateVm rejected: previous creation outcome is unknown" ) ;
97116 return Err ( rpc:: INVALID_STATE ) ;
98117 }
99118 let runtime = match tokio:: runtime:: Builder :: new_current_thread ( )
100119 . enable_all ( )
101120 . build ( )
102121 {
103122 Ok ( runtime) => runtime,
104- Err ( _) => return Err ( E_FAIL ) ,
123+ Err ( _) => {
124+ tracing:: error!( target: "wslopenvmm::rpc" , "CreateVm could not initialize the RPC runtime" ) ;
125+ return Err ( E_FAIL ) ;
126+ }
105127 } ;
106128 let remaining = deadline. saturating_duration_since ( Instant :: now ( ) ) ;
107129 if remaining. is_zero ( ) {
130+ tracing:: warn!( target: "wslopenvmm::rpc" , "CreateVm deadline expired before connecting" ) ;
108131 return Err ( rpc:: TIMEOUT ) ;
109132 }
110- let channel =
111- match runtime. block_on ( af_unix:: connect_channel ( socket_path. into ( ) , remaining) ) {
112- Ok ( channel) => channel,
113- Err ( error) => return Err ( rpc:: io_error_to_hresult ( & error) ) ,
114- } ;
133+ let channel = match runtime
134+ . block_on ( af_unix:: connect_channel ( socket_path. into ( ) , remaining) )
135+ {
136+ Ok ( channel) => channel,
137+ Err ( error) => {
138+ let result = rpc:: io_error_to_hresult ( & error) ;
139+ tracing:: warn!( target: "wslopenvmm::rpc" , "CreateVm connection failed with HRESULT {:#010x}; no creation request sent" , result. 0 ) ;
140+ return Err ( result) ;
141+ }
142+ } ;
115143 let mut client = VmClient :: new ( channel) ;
116144 let request = CreateVmRequest {
117145 config : Some ( self . config . clone ( ) ) ,
118146 log_id : String :: new ( ) ,
119147 } ;
120148 let remaining = deadline. saturating_duration_since ( Instant :: now ( ) ) ;
121149 if remaining. is_zero ( ) {
150+ tracing:: warn!( target: "wslopenvmm::rpc" , "CreateVm deadline expired before dispatch" ) ;
122151 return Err ( rpc:: TIMEOUT ) ;
123152 }
124153 match runtime. block_on ( rpc:: execute (
@@ -130,6 +159,7 @@ impl VmConfigBuilder {
130159 Err ( error) => {
131160 if error. uncertain {
132161 self . status = VmConfigStatus :: CreationOutcomeUnknown ;
162+ tracing:: warn!( target: "wslopenvmm::rpc" , "CreateVm outcome is unknown; discard the configuration and process before retrying" ) ;
133163 }
134164 Err ( error. result )
135165 }
@@ -261,23 +291,29 @@ impl VmHandle {
261291
262292 pub fn cancel_requests ( & self ) -> HRESULT {
263293 self . cancellation . send_replace ( true ) ;
294+ tracing:: info!( target: "wslopenvmm::rpc" , "VM request cancellation signalled" ) ;
264295 S_OK
265296 }
266297
267298 fn with_operation (
268299 & self ,
300+ name : & ' static str ,
269301 cleanup : bool ,
270302 operation : impl FnOnce ( & mut VmHandleInner , Instant , Option < watch:: Receiver < bool > > ) -> HRESULT ,
271303 ) -> HRESULT {
272- let deadline = Instant :: now ( ) + self . timeout ;
304+ let started = Instant :: now ( ) ;
305+ let deadline = started + self . timeout ;
306+ tracing:: info!( target: "wslopenvmm::rpc" , "{name} starting" ) ;
273307 let Some ( mut inner) = self . inner . try_lock_until ( deadline) else {
274308 // No request was sent, so lock contention alone does not invalidate the VM.
309+ tracing:: warn!( target: "wslopenvmm::rpc" , "{name} timed out waiting for the VM lock; no request sent" ) ;
275310 return rpc:: TIMEOUT ;
276311 } ;
277312 if * self . cancellation . borrow ( ) {
278313 inner. status = VmStatus :: RecoveryRequired ;
279314 }
280315 if !cleanup && inner. status == VmStatus :: RecoveryRequired {
316+ tracing:: warn!( target: "wslopenvmm::rpc" , "{name} rejected: VM requires recovery" ) ;
281317 return rpc:: INVALID_STATE ;
282318 }
283319 let cancellation = if cleanup {
@@ -290,11 +326,24 @@ impl VmHandle {
290326 if * self . cancellation . borrow ( ) {
291327 inner. status = VmStatus :: RecoveryRequired ;
292328 }
329+ if result. is_err ( ) {
330+ tracing:: warn!(
331+ target: "wslopenvmm::rpc" ,
332+ "{name} failed with HRESULT {:#010x} after {:?}; VM status: {:?}" ,
333+ result. 0 , started. elapsed( ) , inner. status
334+ ) ;
335+ } else {
336+ tracing:: info!(
337+ target: "wslopenvmm::rpc" ,
338+ "{name} completed in {:?}; VM status: {:?}" ,
339+ started. elapsed( ) , inner. status
340+ ) ;
341+ }
293342 result
294343 }
295344
296345 pub fn resume_vm ( & self ) -> HRESULT {
297- self . with_operation ( false , |inner, deadline, cancellation| {
346+ self . with_operation ( "ResumeVm" , false , |inner, deadline, cancellation| {
298347 self . rpc (
299348 inner,
300349 deadline,
@@ -306,7 +355,7 @@ impl VmHandle {
306355 }
307356
308357 pub fn teardown_vm ( & self ) -> HRESULT {
309- self . with_operation ( true , |inner, deadline, cancellation| {
358+ self . with_operation ( "TeardownVm" , true , |inner, deadline, cancellation| {
310359 let result = self . rpc (
311360 inner,
312361 deadline,
@@ -322,7 +371,7 @@ impl VmHandle {
322371 }
323372
324373 pub fn quit ( & self ) -> HRESULT {
325- self . with_operation ( true , |inner, deadline, cancellation| {
374+ self . with_operation ( "Quit" , true , |inner, deadline, cancellation| {
326375 self . rpc (
327376 inner,
328377 deadline,
@@ -356,7 +405,7 @@ impl VmHandle {
356405 }
357406
358407 pub fn add_share ( & self , tag : String , host_path : String , read_only : bool ) -> HRESULT {
359- self . with_operation ( false , |inner, deadline, cancellation| {
408+ self . with_operation ( "AddShare" , false , |inner, deadline, cancellation| {
360409 if inner. shares . contains_key ( & tag) {
361410 return HRESULT :: from_win32 ( ERROR_ALREADY_EXISTS . 0 ) ;
362411 }
@@ -393,7 +442,7 @@ impl VmHandle {
393442 }
394443
395444 pub fn remove_share ( & self , tag : & str ) -> HRESULT {
396- self . with_operation ( false , |inner, deadline, cancellation| {
445+ self . with_operation ( "RemoveShare" , false , |inner, deadline, cancellation| {
397446 let Some ( instance_id) = inner. shares . get ( tag) else {
398447 return HRESULT :: from_win32 ( ERROR_NOT_FOUND . 0 ) ;
399448 } ;
@@ -428,6 +477,7 @@ impl VmHandle {
428477 {
429478 let remaining = deadline. saturating_duration_since ( Instant :: now ( ) ) ;
430479 if remaining. is_zero ( ) {
480+ tracing:: warn!( target: "wslopenvmm::rpc" , "RPC deadline expired before dispatch; no request sent" ) ;
431481 return rpc:: TIMEOUT ;
432482 }
433483 let result = inner. runtime . block_on ( rpc:: execute (
@@ -443,6 +493,7 @@ impl VmHandle {
443493 Err ( error) => {
444494 if error. uncertain {
445495 inner. status = VmStatus :: RecoveryRequired ;
496+ tracing:: warn!( target: "wslopenvmm::rpc" , "Uncertain RPC outcome; VM requires teardown and recreation" ) ;
446497 }
447498 error. result
448499 }
@@ -457,7 +508,12 @@ impl VmHandle {
457508 host_path : String ,
458509 read_only : bool ,
459510 ) -> HRESULT {
460- self . with_operation ( false , |inner, deadline, cancellation| {
511+ let name = if modify_type == ModifyType :: Add {
512+ "AttachScsiDisk"
513+ } else {
514+ "DetachScsiDisk"
515+ } ;
516+ self . with_operation ( name, false , |inner, deadline, cancellation| {
461517 let request = ModifyResourceRequest {
462518 r#type : modify_type as i32 ,
463519 resource : Some ( vmservice:: modify_resource_request:: Resource :: ScsiDisk (
@@ -488,7 +544,12 @@ impl VmHandle {
488544 tcp : bool ,
489545 family : i32 ,
490546 ) -> HRESULT {
491- self . with_operation ( false , |inner, deadline, cancellation| {
547+ let name = if modify_type == ModifyType :: Update {
548+ "BindPort"
549+ } else {
550+ "UnbindPort"
551+ } ;
552+ self . with_operation ( name, false , |inner, deadline, cancellation| {
492553 let host_address = match family {
493554 family if family == i32:: from ( AF_INET ) => "127.0.0.1" ,
494555 family if family == i32:: from ( AF_INET6 ) => "::1" ,
0 commit comments