Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions idl/xenvm_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ external remove : name:string -> unit = ""
external resize : name:string -> size:int64 -> unit = ""
external set_status : name:string -> readonly:bool -> unit = ""

external flush : name:string -> unit = ""
(** [flush lv] processes all pending allocations for this LV, such that
future calls to [get_lv] will return accurate metadata. *)

external shutdown : unit -> unit = ""

type queue = {
Expand Down
3 changes: 2 additions & 1 deletion xenvm/lvchange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ let lvchange_activate copts vg_name lv_name physical_device =
)

let deactivate vg lv =
let open Xenvm_common in
let name = Mapper.name_of vg lv in
let all = Devmapper.ls () in
if List.mem name all
then Devmapper.remove name;
(* Delete the device node *)
let path = dev_path_of vg.Lvm.Vg.name lv.Lvm.Lv.name in
Lwt.catch (fun () -> Lwt_unix.unlink path) (fun _ -> Lwt.return ()) >>= fun () ->
return ()
Client.flush ~name:lv.Lvm.Lv.name

let lvchange_deactivate copts vg_name lv_name =
let open Xenvm_common in
Expand Down
25 changes: 19 additions & 6 deletions xenvmd/xenvmd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ module VolumeManager = struct
free_LVs := (name, (freeLVM,freeLVMid)) :: !free_LVs;
return ()

let flush name =
(* Hold this mutex when actively flushing from the ToLVM queues *)
let flush_m = Lwt_mutex.create ()

let flush_already_locked name =
if not(List.mem_assoc name !to_LVMs)
then return ()
else begin
Expand Down Expand Up @@ -309,7 +312,7 @@ module VolumeManager = struct
ToLVM.suspend to_lvm
>>= fun () ->
(* There may still be updates in the ToLVM queue *)
flush name
Lwt_mutex.with_lock flush_m (fun () -> flush_already_locked name)
>>= fun () ->
debug "ToLVM queue for %s has been suspended and flushed" name;
to_LVMs := List.filter (fun (n, _) -> n <> name) !to_LVMs;
Expand Down Expand Up @@ -358,6 +361,15 @@ module VolumeManager = struct
) !to_LVMs
end

let flush_all () =
Lwt_mutex.with_lock Host.flush_m
(fun () ->
Lwt_list.iter_s
(fun (host, _) ->
Host.flush_already_locked host
) !to_LVMs
)

let shutdown () =
Lwt_list.iter_s
(fun (host, _) ->
Expand Down Expand Up @@ -566,6 +578,10 @@ module Impl = struct
return (`Ok ({ vg with Vg.lvs = Vg.LVs.empty }, lv))
))

let flush context ~name =
(* We don't know where [name] is attached so we have to flush everything *)
VolumeManager.flush_all ()

let shutdown context () =
VolumeManager.shutdown ()
>>= fun () ->
Expand Down Expand Up @@ -616,10 +632,7 @@ let run port config daemon =
>>= fun () ->

(* 2. Are there any pending LVM updates from hosts? *)
Lwt_list.iter_s
(fun (host, _) ->
VolumeManager.Host.flush host
) !VolumeManager.to_LVMs
VolumeManager.flush_all ()
>>= fun () ->

debug "sleeping for 5s";
Expand Down