@@ -302,7 +302,7 @@ module VolumeManager = struct
302302 match Vg_IO. find vg toLVM, Vg_IO. find vg fromLVM, Vg_IO. find vg freeLVM with
303303 | Some toLVM_id , Some fromLVM_id , Some freeLVM_id ->
304304 Hashtbl. replace host_connections name Resuming_to_LVM ;
305- let background_t =
305+ let background_t () =
306306 Vg_IO.Volume. connect toLVM_id
307307 >> = function
308308 | `Error _ -> fail (Failure (Printf. sprintf " Failed to open %s" toLVM))
@@ -345,7 +345,7 @@ module VolumeManager = struct
345345 return (toLVM_q, fromLVM_q, freeLVM_id) in
346346 Lwt. catch
347347 (fun () ->
348- background_t
348+ background_t ()
349349 >> = fun (toLVM_q , fromLVM_q , freeLVM_id ) ->
350350 Hashtbl. replace host_connections name Connected ;
351351 to_LVMs := (name, toLVM_q) :: ! to_LVMs;
@@ -391,21 +391,25 @@ module VolumeManager = struct
391391 end
392392
393393 let disconnect name =
394- if not (List. mem_assoc name ! to_LVMs)
395- then return () (* already disconnected *)
396- else
397- let to_lvm = List. assoc name ! to_LVMs in
398- debug " Suspending ToLVM queue for %s" name;
399- ToLVM. suspend to_lvm
400- >> = fun () ->
401- (* There may still be updates in the ToLVM queue *)
402- Lwt_mutex. with_lock flush_m (fun () -> flush_already_locked name)
403- >> = fun () ->
404- debug " ToLVM queue for %s has been suspended and flushed" name;
405- to_LVMs := List. filter (fun (n , _ ) -> n <> name) ! to_LVMs;
406- from_LVMs := List. filter (fun (n , _ ) -> n <> name) ! from_LVMs;
407- free_LVs := List. filter (fun (n , _ ) -> n <> name) ! free_LVs;
408- return ()
394+ if Hashtbl. mem host_connections name then begin
395+ match Hashtbl. find host_connections name with
396+ | Connected ->
397+ let to_lvm = List. assoc name ! to_LVMs in
398+ debug " Suspending ToLVM queue for %s" name;
399+ ToLVM. suspend to_lvm
400+ >> = fun () ->
401+ (* There may still be updates in the ToLVM queue *)
402+ Lwt_mutex. with_lock flush_m (fun () -> flush_already_locked name)
403+ >> = fun () ->
404+ debug " ToLVM queue for %s has been suspended and flushed" name;
405+ to_LVMs := List. filter (fun (n , _ ) -> n <> name) ! to_LVMs;
406+ from_LVMs := List. filter (fun (n , _ ) -> n <> name) ! from_LVMs;
407+ free_LVs := List. filter (fun (n , _ ) -> n <> name) ! free_LVs;
408+ Hashtbl. remove host_connections name;
409+ return ()
410+ | x ->
411+ fail (Xenvm_interface. HostStillConnecting (Sexplib.Sexp. to_string (sexp_of_connection_state x)))
412+ end else return ()
409413
410414 let destroy name =
411415 disconnect name
0 commit comments