Skip to content

Commit 09e4a36

Browse files
committed
xenvmd/xenvm: Return the pid on shutdown API call
This allows xenvm to wait for the shutdown to complete. Signed-off-by: Jon Ludlam <[email protected]>
1 parent 0369124 commit 09e4a36

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

idl/xenvm_interface.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ external flush : name:string -> unit = ""
3232
(** [flush lv] processes all pending allocations for this LV, such that
3333
future calls to [get_lv] will return accurate metadata. *)
3434

35-
external shutdown : unit -> unit = ""
35+
(** [shutdown ()] will cause xenvmd to exit shortly after returning.
36+
The returned value is the pid of the process to enable the caller
37+
to wait until the process has actually exitted. *)
38+
external shutdown : unit -> int = ""
3639

3740
type queue = {
3841
lv: string;

xenvm/xenvm.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,19 @@ let host_list copts (vg_name,_) =
124124
Lwt_main.run t
125125

126126
let shutdown copts (vg_name,_) =
127+
let is_alive pid =
128+
try Unix.kill pid 0; true with _ -> false
129+
in
130+
let lwt_while guard body =
131+
let rec inner () =
132+
if guard () then body () >>= inner else Lwt.return ()
133+
in inner ()
134+
in
127135
let t =
128136
get_vg_info_t copts vg_name >>= fun info ->
129137
set_uri copts info;
130-
Client.shutdown ()
138+
Client.shutdown () >>= fun pid ->
139+
lwt_while (fun () -> is_alive pid) (fun () -> Lwt_unix.sleep 1.0)
131140
in Lwt_main.run t
132141

133142
let benchmark copts (vg_name,_) =

xenvmd/xenvmd.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ module Impl = struct
661661
Lwt_unix.sleep 1.
662662
>>= fun () ->
663663
exit 0 in
664-
return ()
664+
return (Unix.getpid ())
665665

666666
module Host = struct
667667
let create context ~name = VolumeManager.Host.create name

0 commit comments

Comments
 (0)