more cleanups

This commit is contained in:
Hannes Mehnert 2018-10-23 22:14:28 +02:00
parent 46548418cd
commit ce0c42fa77
5 changed files with 8 additions and 38 deletions

View file

@ -5,8 +5,6 @@
(* communication channel is a single unix domain socket shared between vmmd and (* communication channel is a single unix domain socket shared between vmmd and
vmm_log. There are two commands from vmmd to vmm_log, history and data. *) vmm_log. There are two commands from vmmd to vmm_log, history and data. *)
(* TODO: this should (optionally?) persist to a remote target *)
(* internally, a ring buffer for the last N events is preserved in memory (* internally, a ring buffer for the last N events is preserved in memory
each new event is directly written to disk! *) each new event is directly written to disk! *)
@ -55,11 +53,6 @@ let write_to_file file =
in in
mvar, write_loop mvar, write_loop
(* TODO:
- should there be an unsubscribe <prefix> command?
- should there be acks for history/datain?
*)
let tree = ref Vmm_trie.empty let tree = ref Vmm_trie.empty
let bcast = ref 0L let bcast = ref 0L

View file

@ -142,7 +142,6 @@ let good_bridge idxs nets =
List.for_all (fun n -> String.Map.mem n nets) idxs List.for_all (fun n -> String.Map.mem n nets) idxs
let vm_matches_res (res : policy) (vm : vm_config) = let vm_matches_res (res : policy) (vm : vm_config) =
(* TODO block device *)
res.vms >= 1 && IS.mem vm.cpuid res.cpuids && res.vms >= 1 && IS.mem vm.cpuid res.cpuids &&
vm.requested_memory <= res.memory && vm.requested_memory <= res.memory &&
good_bridge vm.network res.bridges good_bridge vm.network res.bridges

View file

@ -12,10 +12,6 @@ type 'a t = {
console_counter : int64 ; console_counter : int64 ;
stats_counter : int64 ; stats_counter : int64 ;
log_counter : int64 ; log_counter : int64 ;
(* TODO: refine, maybe:
bridges : (Macaddr.t String.Map.t * String.Set.t) String.Map.t ; *)
used_bridges : String.Set.t String.Map.t ;
(* TODO: used block devices (since each may only be active once) *)
resources : Vmm_resources.t ; resources : Vmm_resources.t ;
tasks : 'a String.Map.t ; tasks : 'a String.Map.t ;
} }
@ -25,7 +21,6 @@ let init wire_version = {
console_counter = 1L ; console_counter = 1L ;
stats_counter = 1L ; stats_counter = 1L ;
log_counter = 1L ; log_counter = 1L ;
used_bridges = String.Map.empty ;
resources = Vmm_resources.empty ; resources = Vmm_resources.empty ;
tasks = String.Map.empty ; tasks = String.Map.empty ;
} }
@ -58,7 +53,6 @@ let handle_create t hdr vm_config =
(* prepare VM: save VM image to disk, create fifo, ... *) (* prepare VM: save VM image to disk, create fifo, ... *)
Vmm_unix.prepare name vm_config >>= fun taps -> Vmm_unix.prepare name vm_config >>= fun taps ->
Logs.debug (fun m -> m "prepared vm with taps %a" Fmt.(list ~sep:(unit ",@ ") string) taps) ; Logs.debug (fun m -> m "prepared vm with taps %a" Fmt.(list ~sep:(unit ",@ ") string) taps) ;
(* TODO should we pre-reserve sth in t? *)
let cons_out = let cons_out =
let header = Vmm_asn.{ version = t.wire_version ; sequence = t.console_counter ; id = name } in let header = Vmm_asn.{ version = t.wire_version ; sequence = t.console_counter ; id = name } in
(header, `Command (`Console_cmd `Console_add)) (header, `Command (`Console_cmd `Console_add))
@ -70,16 +64,7 @@ let handle_create t hdr vm_config =
Logs.debug (fun m -> m "exec()ed vm") ; Logs.debug (fun m -> m "exec()ed vm") ;
Vmm_resources.insert_vm t.resources name vm >>= fun resources -> Vmm_resources.insert_vm t.resources name vm >>= fun resources ->
let tasks = String.Map.add (string_of_id name) task t.tasks in let tasks = String.Map.add (string_of_id name) task t.tasks in
let used_bridges = let t = { t with resources ; tasks } in
List.fold_left2 (fun b br ta ->
let old = match String.Map.find br b with
| None -> String.Set.empty
| Some x -> x
in
String.Map.add br (String.Set.add ta old) b)
t.used_bridges vm_config.network taps
in
let t = { t with resources ; tasks ; used_bridges } in
let t, out = log t name (`VM_start (vm.pid, vm.taps, None)) in let t, out = log t name (`VM_start (vm.pid, vm.taps, None)) in
let data = `Success (`String "created VM") in let data = `Success (`String "created VM") in
Ok (t, [ `Data (hdr, data) ; out ], name, vm))) Ok (t, [ `Data (hdr, data) ; out ], name, vm)))
@ -95,19 +80,10 @@ let handle_shutdown t name vm r =
| Ok () -> () | Ok () -> ()
| Error (`Msg e) -> Logs.warn (fun m -> m "%s while shutdown vm %a" e pp_vm vm)) ; | Error (`Msg e) -> Logs.warn (fun m -> m "%s while shutdown vm %a" e pp_vm vm)) ;
let resources = Vmm_resources.remove t.resources name in let resources = Vmm_resources.remove t.resources name in
let used_bridges =
List.fold_left2 (fun b br ta ->
let old = match String.Map.find br b with
| None -> String.Set.empty
| Some x -> x
in
String.Map.add br (String.Set.remove ta old) b)
t.used_bridges vm.config.network vm.taps
in
let stat_out = `Stats_remove in let stat_out = `Stats_remove in
let header = Vmm_asn.{ version = t.wire_version ; sequence = t.stats_counter ; id = name } in let header = Vmm_asn.{ version = t.wire_version ; sequence = t.stats_counter ; id = name } in
let tasks = String.Map.remove (string_of_id name) t.tasks in let tasks = String.Map.remove (string_of_id name) t.tasks in
let t = { t with stats_counter = Int64.succ t.stats_counter ; resources ; used_bridges ; tasks } in let t = { t with stats_counter = Int64.succ t.stats_counter ; resources ; tasks } in
let t, logout = log t name (`VM_stop (vm.pid, r)) let t, logout = log t name (`VM_stop (vm.pid, r))
in in
(t, [ `Stat (header, `Command (`Stats_cmd stat_out)) ; logout ]) (t, [ `Stat (header, `Command (`Stats_cmd stat_out)) ; logout ])

View file

@ -10,7 +10,8 @@ type res_entry = {
let empty_res = { running_vms = 0 ; used_memory = 0 } let empty_res = { running_vms = 0 ; used_memory = 0 }
let check_resource (policy : policy) (vm : vm_config) (res : res_entry) = let check_resource (policy : policy) (vm : vm_config) (res : res_entry) =
succ res.running_vms <= policy.vms && res.used_memory + vm.requested_memory <= policy.memory && succ res.running_vms <= policy.vms &&
res.used_memory + vm.requested_memory <= policy.memory &&
vm_matches_res policy vm vm_matches_res policy vm
let check_resource_policy (policy : policy) (res : res_entry) = let check_resource_policy (policy : policy) (res : res_entry) =
@ -81,8 +82,10 @@ let check_policy_below t name p =
match res, entry with match res, entry with
| Ok p, Policy p' -> if is_sub ~super:p ~sub:p then Ok p' else Error () | Ok p, Policy p' -> if is_sub ~super:p ~sub:p then Ok p' else Error ()
| Ok p, Vm vm -> | Ok p, Vm vm ->
(* TODO block device *) let cfg = vm.config in
if IS.mem vm.config.cpuid p.cpuids && good_bridge vm.config.network p.bridges then Ok p else Error () if IS.mem cfg.cpuid p.cpuids && good_bridge cfg.network p.bridges
then Ok p
else Error ()
| res, _ -> res) | res, _ -> res)
(Ok p) (Ok p)

View file

@ -146,7 +146,6 @@ let cpuset cpu =
| x -> Error (`Msg ("unsupported operating system " ^ x)) | x -> Error (`Msg ("unsupported operating system " ^ x))
let exec name vm taps = let exec name vm taps =
(* TODO: --net-mac=xx *)
let net = List.map (fun t -> "--net=" ^ t) taps in let net = List.map (fun t -> "--net=" ^ t) taps in
let argv = match vm.argv with None -> [] | Some xs -> xs in let argv = match vm.argv with None -> [] | Some xs -> xs in
(match taps with (match taps with