Skip to content

Commit 48507f6

Browse files
author
David Scott
committed
Host.disconnect: fail if a connection is currently in progress
Signed-off-by: David Scott <[email protected]>
1 parent b8e2563 commit 48507f6

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

idl/xenvm_interface.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
exception HostNotCreated
44

5+
exception HostStillConnecting of string
6+
57
let _journal_name = "xenvm_journal"
68

79
external get_lv: name:string -> (Vg_wrapper.t * Lv_wrapper.t) = ""

xenvmd/xenvmd.ml

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)