vmm_vmmd, vmm_unix: compute device name (/dev/vmm/solo5-PID) in vmm_unix (depending on host OS); also destroy this device on shutdown (used to be done by solo5-hvt, but that now drops privileges and is no longer able to do this)
This commit is contained in:
parent
c372c8405e
commit
943ea45e25
|
@ -150,7 +150,18 @@ let prepare name vm =
|
||||||
Bos.OS.File.write (Name.image_file name) (Cstruct.to_string image) >>= fun () ->
|
Bos.OS.File.write (Name.image_file name) (Cstruct.to_string image) >>= fun () ->
|
||||||
Ok (List.rev taps)
|
Ok (List.rev taps)
|
||||||
|
|
||||||
|
let vm_device vm =
|
||||||
|
match Lazy.force uname with
|
||||||
|
| x when x = "FreeBSD" -> Ok ("solo5-" ^ string_of_int vm.Unikernel.pid)
|
||||||
|
| _ -> Error (`Msg "don't know what you mean, sorry")
|
||||||
|
|
||||||
let shutdown name vm =
|
let shutdown name vm =
|
||||||
|
(* since solo5 0.4.1, it drops privileges on FreeBSD *)
|
||||||
|
(* this results in solo5-hvt not being able to sysctl hw.vmm.destroy *)
|
||||||
|
(match Lazy.force uname, vm_device vm with
|
||||||
|
| x, Ok name when x = "FreeBSD" ->
|
||||||
|
ignore (Bos.OS.Cmd.run Bos.Cmd.(v "bhyvectl" % "--destroy" % ("--vm=" ^ name)))
|
||||||
|
| _ -> ()) ;
|
||||||
(* same order as prepare! *)
|
(* same order as prepare! *)
|
||||||
Bos.OS.File.delete (Name.image_file name) >>= fun () ->
|
Bos.OS.File.delete (Name.image_file name) >>= fun () ->
|
||||||
Bos.OS.File.delete (Name.fifo_file name) >>= fun () ->
|
Bos.OS.File.delete (Name.fifo_file name) >>= fun () ->
|
||||||
|
|
|
@ -24,3 +24,5 @@ val find_block_devices : unit -> ((Name.t * int) list, [> R.msg ]) result
|
||||||
val dump : Cstruct.t -> (unit, [> R.msg ]) result
|
val dump : Cstruct.t -> (unit, [> R.msg ]) result
|
||||||
|
|
||||||
val restore : unit -> (Cstruct.t, [> R.msg | `NoFile ]) result
|
val restore : unit -> (Cstruct.t, [> R.msg | `NoFile ]) result
|
||||||
|
|
||||||
|
val vm_device : Unikernel.t -> (string, [> R.msg ]) result
|
||||||
|
|
|
@ -108,11 +108,12 @@ let dump_unikernels t =
|
||||||
|
|
||||||
let setup_stats t name vm =
|
let setup_stats t name vm =
|
||||||
let stat_out =
|
let stat_out =
|
||||||
let pid = vm.Unikernel.pid in
|
let name = match Vmm_unix.vm_device vm with
|
||||||
let name = "solo5-" ^ string_of_int pid
|
| Error _ -> ""
|
||||||
|
| Ok name -> name
|
||||||
and ifs = Unikernel.(List.combine vm.config.network_interfaces vm.taps)
|
and ifs = Unikernel.(List.combine vm.config.network_interfaces vm.taps)
|
||||||
in
|
in
|
||||||
`Stats_add (name, pid, ifs)
|
`Stats_add (name, vm.Unikernel.pid, ifs)
|
||||||
in
|
in
|
||||||
let header = Vmm_commands.{ version = t.wire_version ; sequence = t.stats_counter ; name } in
|
let header = Vmm_commands.{ version = t.wire_version ; sequence = t.stats_counter ; name } in
|
||||||
let t = { t with stats_counter = Int64.succ t.stats_counter } in
|
let t = { t with stats_counter = Int64.succ t.stats_counter } in
|
||||||
|
|
Loading…
Reference in a new issue