remove unnecessary freebsd-specific teardown code (bhyvectl --destroy), since 0.6 reverted privdrop
This commit is contained in:
parent
2db9e0c15e
commit
4787b0cf1f
|
@ -150,25 +150,16 @@ 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 free_resources name taps =
|
|
||||||
(* same order as prepare! *)
|
|
||||||
Bos.OS.File.delete (Name.image_file name) >>= fun () ->
|
|
||||||
Bos.OS.File.delete (Name.fifo_file name) >>= fun () ->
|
|
||||||
List.fold_left (fun r n -> r >>= fun () -> destroy_tap n) (Ok ()) taps
|
|
||||||
|
|
||||||
let vm_device vm =
|
let vm_device vm =
|
||||||
match Lazy.force uname with
|
match Lazy.force uname with
|
||||||
| x when x = "FreeBSD" -> Ok ("solo5-" ^ string_of_int vm.Unikernel.pid)
|
| x when x = "FreeBSD" -> Ok ("solo5-" ^ string_of_int vm.Unikernel.pid)
|
||||||
| _ -> Error (`Msg "don't know what you mean, sorry")
|
| _ -> Error (`Msg "don't know what you mean, sorry")
|
||||||
|
|
||||||
let shutdown name vm =
|
let free_system_resources name taps =
|
||||||
(* since solo5 0.4.1, it drops privileges on FreeBSD *)
|
(* same order as prepare! *)
|
||||||
(* this results in solo5-hvt not being able to sysctl hw.vmm.destroy *)
|
Bos.OS.File.delete (Name.image_file name) >>= fun () ->
|
||||||
(match Lazy.force uname, vm_device vm with
|
Bos.OS.File.delete (Name.fifo_file name) >>= fun () ->
|
||||||
| x, Ok name when x = "FreeBSD" ->
|
List.fold_left (fun r n -> r >>= fun () -> destroy_tap n) (Ok ()) taps
|
||||||
ignore (Bos.OS.Cmd.run Bos.Cmd.(v "bhyvectl" % "--destroy" % ("--vm=" ^ name)))
|
|
||||||
| _ -> ()) ;
|
|
||||||
free_resources name vm.Unikernel.taps
|
|
||||||
|
|
||||||
let cpuset cpu =
|
let cpuset cpu =
|
||||||
let cpustring = string_of_int cpu in
|
let cpustring = string_of_int cpu in
|
||||||
|
|
|
@ -9,9 +9,7 @@ val prepare : Name.t -> Unikernel.config -> (string list, [> R.msg ]) result
|
||||||
val exec : Name.t -> Unikernel.config -> string list -> Name.t option ->
|
val exec : Name.t -> Unikernel.config -> string list -> Name.t option ->
|
||||||
(Unikernel.t, [> R.msg ]) result
|
(Unikernel.t, [> R.msg ]) result
|
||||||
|
|
||||||
val free_resources : Name.t -> string list -> (unit, [> R.msg ]) result
|
val free_system_resources : Name.t -> string list -> (unit, [> R.msg ]) result
|
||||||
|
|
||||||
val shutdown : Name.t -> Unikernel.t -> (unit, [> R.msg ]) result
|
|
||||||
|
|
||||||
val destroy : Unikernel.t -> unit
|
val destroy : Unikernel.t -> unit
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ let handle_create t hdr name vm_config =
|
||||||
let t, stat_out = setup_stats t name vm in
|
let t, stat_out = setup_stats t name vm in
|
||||||
(t, stat_out, log_out, (hdr, `Success (`String "created VM")), name, vm)
|
(t, stat_out, log_out, (hdr, `Success (`String "created VM")), name, vm)
|
||||||
and fail () =
|
and fail () =
|
||||||
match Vmm_unix.free_resources name taps with
|
match Vmm_unix.free_system_resources name taps with
|
||||||
| Ok () -> (hdr, `Failure "could not create VM: console failed")
|
| Ok () -> (hdr, `Failure "could not create VM: console failed")
|
||||||
| Error (`Msg msg) ->
|
| Error (`Msg msg) ->
|
||||||
let m = "could not create VM: console failed, and also " ^ msg ^ " while cleaning resources" in
|
let m = "could not create VM: console failed, and also " ^ msg ^ " while cleaning resources" in
|
||||||
|
@ -162,7 +162,7 @@ let handle_create t hdr name vm_config =
|
||||||
`Create (cons_out, success, fail))
|
`Create (cons_out, success, fail))
|
||||||
|
|
||||||
let handle_shutdown t name vm r =
|
let handle_shutdown t name vm r =
|
||||||
(match Vmm_unix.shutdown name vm with
|
(match Vmm_unix.free_system_resources name vm.Unikernel.taps with
|
||||||
| Ok () -> ()
|
| Ok () -> ()
|
||||||
| Error (`Msg e) -> Logs.warn (fun m -> m "%s while shutdown vm %a" e Unikernel.pp vm)) ;
|
| Error (`Msg e) -> Logs.warn (fun m -> m "%s while shutdown vm %a" e Unikernel.pp vm)) ;
|
||||||
let resources = match Vmm_resources.remove_vm t.resources name with
|
let resources = match Vmm_resources.remove_vm t.resources name with
|
||||||
|
|
Loading…
Reference in a new issue