vmmd: lock self_destruct with a mutex, respect result of killall (nothing killed, nothing to do)
This commit is contained in:
parent
d84013103c
commit
e58ab236b7
17
app/vmmd.ml
17
app/vmmd.ml
|
@ -154,14 +154,17 @@ let jump _ =
|
||||||
(create_mbox `Log >|= function
|
(create_mbox `Log >|= function
|
||||||
| None -> invalid_arg "cannot connect to log socket"
|
| None -> invalid_arg "cannot connect to log socket"
|
||||||
| Some l -> l) >>= fun (l, l_fd, l_mut) ->
|
| Some l -> l) >>= fun (l, l_fd, l_mut) ->
|
||||||
|
let self_destruct_mutex = Lwt_mutex.create () in
|
||||||
let self_destruct () =
|
let self_destruct () =
|
||||||
Vmm_vmmd.kill !state ;
|
Lwt_mutex.with_lock self_destruct_mutex (fun () ->
|
||||||
(* not too happy about the sleep here, but cleaning up resources is
|
(if Vmm_vmmd.killall !state then
|
||||||
really important (fifos, vm images, tap devices) - which is done in
|
(* not too happy about the sleep here, but cleaning up resources
|
||||||
asynchronous (waiter tasks)
|
is really important (fifos, vm images, tap devices) - which is
|
||||||
*)
|
done asynchronously (in the task waitpid() on the pid) *)
|
||||||
Lwt_unix.sleep 1. >>= fun () ->
|
Lwt_unix.sleep 1.
|
||||||
Vmm_lwt.safe_close ss
|
else
|
||||||
|
Lwt.return_unit) >>= fun () ->
|
||||||
|
Vmm_lwt.safe_close ss)
|
||||||
in
|
in
|
||||||
Sys.(set_signal sigterm (Signal_handle (fun _ -> Lwt.async self_destruct)));
|
Sys.(set_signal sigterm (Signal_handle (fun _ -> Lwt.async self_destruct)));
|
||||||
(create_mbox `Console >|= function
|
(create_mbox `Console >|= function
|
||||||
|
|
|
@ -16,9 +16,10 @@ type 'a t = {
|
||||||
waiters : 'a String.Map.t ;
|
waiters : 'a String.Map.t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
let kill t =
|
let killall t =
|
||||||
List.iter Vmm_unix.destroy
|
match List.map snd (Vmm_trie.all t.resources.Vmm_resources.unikernels) with
|
||||||
(List.map snd (Vmm_trie.all t.resources.Vmm_resources.unikernels))
|
| [] -> false
|
||||||
|
| vms -> List.iter Vmm_unix.destroy vms ; true
|
||||||
|
|
||||||
let waiter t id =
|
let waiter t id =
|
||||||
let name = Name.to_string id in
|
let name = Name.to_string id in
|
||||||
|
|
|
@ -31,4 +31,4 @@ val handle_command : 'a t -> Vmm_commands.wire ->
|
||||||
[ `Create of 'a t -> ('a t * out list * Name.t * Unikernel.t, [> Rresult.R.msg ]) result
|
[ `Create of 'a t -> ('a t * out list * Name.t * Unikernel.t, [> Rresult.R.msg ]) result
|
||||||
| `End ]) ]
|
| `End ]) ]
|
||||||
|
|
||||||
val kill : 'a t -> unit
|
val killall : 'a t -> bool
|
||||||
|
|
Loading…
Reference in a new issue