Skip to content

Commit

Permalink
Adapted xen-api code to the changes in xenctrl (namespaces).
Browse files Browse the repository at this point in the history
Signed-off-by: Rok Strnisa <rok.strnisa@citrix.com>
  • Loading branch information
Rok Strniša committed Jul 13, 2012
1 parent 3ec17eb commit 267c545
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 236 deletions.
102 changes: 61 additions & 41 deletions ocaml/rrdd/interface/monitor_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,85 @@
* @group Performance Monitoring
*)

(*
type vcpuinfo = {
online: bool;
blocked: bool;
running: bool;
cputime: int64;
cpumap: int32;
}
let from_xenctrl_vcpuinfo vi : Xenctrl.vcpuinfo -> vcpuinfo = {
online = vi.Xenctrl.online;
blocked = vi.Xenctrl.blocked;
running = vi.Xenctrl.running;
cputime = vi.Xenctrl.cputime;
cpumap = vi.Xenctrl.cpumap;
}
*)

open Xenctrl

type vcpu = {
vcpu_sumcpus: float;
vcpu_vcpus: float array;
vcpu_rawvcpus: Xenctrl.vcpuinfo array;
vcpu_cputime: int64;
vcpu_sumcpus: float;
vcpu_vcpus: float array;
vcpu_rawvcpus: Vcpu_info.t array;
vcpu_cputime: int64;
}

type memory = {
memory_mem: int64;
memory_mem: int64;
}

type vif = {
vif_n: int;
vif_name: string;
vif_tx: float;
vif_rx: float;
vif_raw_tx: int64;
vif_raw_rx: int64;
vif_raw_tx_err: int64;
vif_raw_rx_err: int64;
vif_n: int;
vif_name: string;
vif_tx: float;
vif_rx: float;
vif_raw_tx: int64;
vif_raw_rx: int64;
vif_raw_tx_err: int64;
vif_raw_rx_err: int64;
}

type vbd = {
vbd_device_id: int;
vbd_io_read: float;
vbd_io_write: float;
vbd_raw_io_read: int64;
vbd_raw_io_write: int64;
vbd_device_id: int;
vbd_io_read: float;
vbd_io_write: float;
vbd_raw_io_read: int64;
vbd_raw_io_write: int64;
}

type pcpus = {
pcpus_usage: float array;
pcpus_usage: float array;
}

type pif = {
pif_name: string;
pif_tx: float;
pif_rx: float;
pif_raw_tx: int64;
pif_raw_rx: int64;
pif_carrier: bool;
pif_speed: int;
pif_duplex: Network_interface.duplex;
pif_pci_bus_path: string;
pif_vendor_id: string;
pif_device_id: string;
pif_name: string;
pif_tx: float;
pif_rx: float;
pif_raw_tx: int64;
pif_raw_rx: int64;
pif_carrier: bool;
pif_speed: int;
pif_duplex: Network_interface.duplex;
pif_pci_bus_path: string;
pif_vendor_id: string;
pif_device_id: string;
}

type host_stats = {
timestamp: float;
host_ref: [ `host ] Ref.t;
total_kib: int64;
free_kib: int64;
timestamp: float;
host_ref: [ `host ] Ref.t;
total_kib: int64;
free_kib: int64;

pifs : pif list; (* host pif metrics *)
pcpus : pcpus; (* host pcpu usage metrics *)
vbds : (string * vbd) list; (* domain uuid * vbd stats list *)
vifs : (string * vif) list; (* domain uuid * vif stats list *)
vcpus : (string * vcpu) list; (* domain uuid to vcpus stats assoc list *)
mem : (string * memory) list; (* domain uuid to memory stats assoc list *)
registered : string list; (* registered domain uuids *)
pifs : pif list; (* host pif metrics *)
pcpus : pcpus; (* host pcpu usage metrics *)
vbds : (string * vbd) list; (* domain uuid * vbd stats list *)
vifs : (string * vif) list; (* domain uuid * vif stats list *)
vcpus : (string * vcpu) list; (* domain uuid to vcpus stats assoc list *)
mem : (string * memory) list; (* domain uuid to memory stats assoc list *)
registered : string list; (* registered domain uuids *)
}
31 changes: 17 additions & 14 deletions ocaml/rrdd/rrdd_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ let copy_bonds_status () =
let uuid_of_domid domains domid =
try
Rrdd_server.string_of_domain_handle
(List.find (fun di -> di.Xenctrl.domid = domid) domains)
(List.find (fun di -> di.Xenctrl.Domain_info.domid = domid) domains)
with Not_found ->
failwith (Printf.sprintf "Failed to find uuid corresponding to domid: %d" domid)

Expand All @@ -156,9 +156,10 @@ let uuid_of_domid domains domid =
* of the VMs present on this host. *)
let update_vcpus xc doms =
List.fold_left (fun (dss, uuid_domids, domids) dom ->
let domid = dom.Xenctrl.domid in
let maxcpus = dom.Xenctrl.max_vcpu_id + 1 in
let uuid = Uuid.string_of_uuid (Uuid.uuid_of_int_array dom.Xenctrl.handle) in
let open Xenctrl.Domain_info in
let domid = dom.domid in
let maxcpus = dom.max_vcpu_id + 1 in
let uuid = Uuid.string_of_uuid (Uuid.uuid_of_int_array dom.handle) in

let rec cpus i dss =
if i>=maxcpus then dss else
Expand All @@ -167,7 +168,7 @@ let update_vcpus xc doms =
ds_make
~name:(Printf.sprintf "cpu%d" i)
~description:(Printf.sprintf "CPU%d usage" i)
~value:(Rrd.VT_Float ((Int64.to_float vcpuinfo.Xenctrl.cputime) /. 1.0e9))
~value:(Rrd.VT_Float ((Int64.to_float vcpuinfo.Xenctrl.Vcpu_info.cputime) /. 1.0e9))
~ty:Rrd.Derive ~default:true ~min:0.0 ~max:1.0())::dss)
in

Expand Down Expand Up @@ -199,7 +200,7 @@ let update_pcpus xc =
let len = Array.length !physcpus in
let newinfos = if len = 0 then (
let physinfo = Xenctrl.physinfo xc in
let pcpus = physinfo.Xenctrl.nr_cpus in
let pcpus = physinfo.Xenctrl.Phys_info.nr_cpus in
physcpus := if pcpus > 0 then (Array.make pcpus 0L) else [| |];
Xenctrl.pcpu_info xc pcpus
) else (
Expand All @@ -216,10 +217,11 @@ let update_pcpus xc =

let update_memory xc doms =
List.fold_left (fun acc dom ->
let domid = dom.Xenctrl.domid in
let kib = Xenctrl.pages_to_kib (Int64.of_nativeint dom.Xenctrl.total_memory_pages) in
let open Xenctrl.Domain_info in
let domid = dom.domid in
let kib = Xenctrl.pages_to_kib (Int64.of_nativeint dom.total_memory_pages) in
let memory = Int64.mul kib 1024L in
let uuid = Uuid.string_of_uuid (Uuid.uuid_of_int_array dom.Xenctrl.handle) in
let uuid = Uuid.string_of_uuid (Uuid.uuid_of_int_array dom.handle) in
let main_mem_ds = (
VM uuid,
ds_make ~name:"memory" ~description:"Memory currently allocated to VM"
Expand Down Expand Up @@ -274,7 +276,7 @@ let vif_device_of_string x =
let ty = String.sub x 0 3 and params = String.sub_to_end x 3 in
let domid, devid = Scanf.sscanf params "%d.%d" (fun x y -> x,y) in
let di = Xenctrl.with_intf (fun xc -> Xenctrl.domain_getinfo xc domid) in
let uuid = Uuid.uuid_of_int_array di.Xenctrl.handle |> Uuid.to_string in
let uuid = Uuid.uuid_of_int_array di.Xenctrl.Domain_info.handle |> Uuid.to_string in
let vif = (uuid, string_of_int devid) in
match ty with
| "vif" -> Some { pv = true; vif = vif; domid = domid; devid = devid }
Expand Down Expand Up @@ -455,8 +457,8 @@ let previous_live_words = ref 0

let read_mem_metrics xc =
let physinfo = Xenctrl.physinfo xc in
let total_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.total_pages)
and free_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.free_pages) in
let total_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.Phys_info.total_pages)
and free_kib = Xenctrl.pages_to_kib (Int64.of_nativeint physinfo.Xenctrl.Phys_info.free_pages) in
let gcstat =
if !Xapi_globs.xapi_gc_debug then (
if !previous_oldness > 5 then (
Expand Down Expand Up @@ -582,9 +584,10 @@ let read_all_dom0_stats xc =
let timestamp = Unix.gettimeofday () in
let my_rebooting_vms =
StringSet.fold (fun uuid acc -> uuid::acc) !rebooting_vms [] in
let open Xenctrl.Domain_info in
let uuid_of_domain d =
Uuid.to_string (Uuid.uuid_of_int_array (d.Xenctrl.handle)) in
let domain_paused d = d.Xenctrl.paused in
Uuid.to_string (Uuid.uuid_of_int_array (d.handle)) in
let domain_paused d = d.paused in
let my_paused_domain_uuids =
List.map uuid_of_domain (List.filter domain_paused domains) in
let vifs, pifs =
Expand Down
4 changes: 2 additions & 2 deletions ocaml/rrdd/rrdd_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ let update_use_min_max _ ~(value : bool) : unit =
use_min_max := value

let string_of_domain_handle dh =
Uuid.string_of_uuid (Uuid.uuid_of_int_array dh.Xenctrl.handle)
Uuid.string_of_uuid (Uuid.uuid_of_int_array dh.Xenctrl.Domain_info.handle)

let add_to_uncooperative_domains _ ~(domid : int) : unit =
Mutex.execute uncooperative_domains_m
Expand All @@ -443,7 +443,7 @@ let get_uncooperative_domains _ () : string list =
let domids = Mutex.execute uncooperative_domains_m
(fun () -> Hashtbl.fold (fun domid _ acc -> domid::acc) uncooperative_domains []) in
let dis = Xenctrl.with_intf (fun xc -> Xenctrl.domain_getinfolist xc 0) in
let dis_uncoop = List.filter (fun di -> List.mem di.Xenctrl.domid domids) dis in
let dis_uncoop = List.filter (fun di -> List.mem di.Xenctrl.Domain_info.domid domids) dis in
List.map string_of_domain_handle dis_uncoop

let update_vm_memory_target _ ~(domid : int) ~(target : int64) : unit =
Expand Down
5 changes: 3 additions & 2 deletions ocaml/xapi/create_misc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ let read_localhost_info () =
let xc = Xenctrl.interface_open () in
let v = Xenctrl.version xc in
Xenctrl.interface_close xc;
Printf.sprintf "%d.%d%s" v.Xenctrl.major v.Xenctrl.minor v.Xenctrl.extra
let open Xenctrl.Version in
Printf.sprintf "%d.%d%s" v.major v.minor v.extra
and linux_verstring =
let verstring = ref "" in
let f line =
Expand Down Expand Up @@ -396,7 +397,7 @@ let create_host_cpu ~__context =
let xc = Xenctrl.interface_open () in
let p = Xenctrl.physinfo xc in
Xenctrl.interface_close xc;
p.Xenctrl.nr_cpus
p.Xenctrl.Phys_info.nr_cpus
in
let trim_end s =
let i = ref (String.length s - 1) in
Expand Down
3 changes: 2 additions & 1 deletion ocaml/xapi/helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ let vif_of_devid ~__context ~vm devid =
let domid_of_vm ~__context ~self =
let uuid = Uuid.uuid_of_string (Db.VM.get_uuid ~__context ~self) in
let all = Xenctrl.with_intf (fun xc -> Xenctrl.domain_getinfolist xc 0) in
let uuid_to_domid = List.map (fun di -> Uuid.uuid_of_int_array di.Xenctrl.handle, di.Xenctrl.domid) all in
let open Xenctrl.Domain_info in
let uuid_to_domid = List.map (fun di -> Uuid.uuid_of_int_array di.handle, di.domid) all in
if List.mem_assoc uuid uuid_to_domid
then List.assoc uuid uuid_to_domid
else -1 (* for backwards compat with old behaviour *)
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xapi/vmopshelpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ let with_xc_and_xs f =
Xenctrl.with_intf (fun xc -> with_xs (fun xs -> f xc xs))

let get_uuid ~xc domid =
Uuid.uuid_of_int_array (Xenctrl.domain_getinfo xc domid).Xenctrl.handle
Uuid.uuid_of_int_array (Xenctrl.domain_getinfo xc domid).Xenctrl.Domain_info.handle
7 changes: 4 additions & 3 deletions ocaml/xapi/xapi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,11 @@ let resynchronise_ha_state () =
let calculate_boot_time_host_free_memory () =
let ( + ) = Nativeint.add in
let host_info = with_xc (fun xc -> Xenctrl.physinfo xc) in
let host_free_pages = host_info.Xenctrl.free_pages in
let host_scrub_pages = host_info.Xenctrl.scrub_pages in
let open Xenctrl.Phys_info in
let host_free_pages = host_info.free_pages in
let host_scrub_pages = host_info.scrub_pages in
let domain0_info = with_xc (fun xc -> Xenctrl.domain_getinfo xc 0) in
let domain0_total_pages = domain0_info.Xenctrl.total_memory_pages in
let domain0_total_pages = domain0_info.Xenctrl.Domain_info.total_memory_pages in
let boot_time_host_free_pages =
host_free_pages + host_scrub_pages + domain0_total_pages in
let boot_time_host_free_kib =
Expand Down
3 changes: 2 additions & 1 deletion ocaml/xapi/xapi_xenops.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1138,9 +1138,10 @@ let rec events_watch ~__context from =

let manage_dom0 dbg =
(* Tell xenopsd to manage domain 0 *)
let open Xenctrl.Domain_info in
let uuid = Xapi_inventory.lookup Xapi_inventory._control_domain_uuid in
let di = Vmopshelpers.with_xc (fun xc -> Xenctrl.domain_getinfo xc 0) in
let memory_actual_bytes = Xenctrl.pages_to_kib Int64.(mul (of_nativeint di.Xenctrl.total_memory_pages) 1024L) in
let memory_actual_bytes = Xenctrl.pages_to_kib Int64.(mul (of_nativeint di.total_memory_pages) 1024L) in
let open Vm in
if not(vm_exists_in_xenopsd dbg uuid)
then begin
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xenops/device.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ let clean_shutdown (task: Xenops_task.t) ~xs (x: device) =
let devs = enumerate_devs ~xs x in
Xenctrl.with_intf (fun xc ->
let hvm =
try (Xenctrl.domain_getinfo xc x.frontend.domid).Xenctrl.hvm_guest
try (Xenctrl.domain_getinfo xc x.frontend.domid).Xenctrl.Domain_info.hvm_guest
with _ -> false
in
try release ~xc ~xs ~hvm devs x.frontend.domid x.frontend.devid
Expand Down
9 changes: 5 additions & 4 deletions ocaml/xenops/domain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@ let domarch_of_string = function
| _ -> Arch_native

let get_uuid ~xc domid =
Uuid.uuid_of_int_array (Xenctrl.domain_getinfo xc domid).Xenctrl.handle
Uuid.uuid_of_int_array (Xenctrl.domain_getinfo xc domid).Xenctrl.Domain_info.handle

let wait_xen_free_mem ~xc ?(maximum_wait_time_seconds=64) required_memory_kib : bool =
let open Memory in
let rec wait accumulated_wait_time_seconds =
let host_info = Xenctrl.physinfo xc in
let open Xenctrl.Phys_info in
let free_memory_kib =
kib_of_pages (Int64.of_nativeint host_info.Xenctrl.free_pages) in
kib_of_pages (Int64.of_nativeint host_info.free_pages) in
let scrub_memory_kib =
kib_of_pages (Int64.of_nativeint host_info.Xenctrl.scrub_pages) in
kib_of_pages (Int64.of_nativeint host_info.scrub_pages) in
(* At exponentially increasing intervals, write *)
(* a debug message saying how long we've waited: *)
if is_power_of_2 accumulated_wait_time_seconds then debug
Expand Down Expand Up @@ -301,7 +302,7 @@ let shutdown ~xc ~xs domid req =
let shutdown_wait_for_ack (t: Xenops_task.t) ?(timeout=60.) ~xc ~xs domid req =
let di = Xenctrl.domain_getinfo xc domid in
let uuid = get_uuid ~xc domid in
if di.Xenctrl.hvm_guest then begin
if di.Xenctrl.Domain_info.hvm_guest then begin
if not (Xenctrl.hvm_check_pvdriver xc domid)
then begin
debug "VM = %s; domid = %d; HVM guest without PV drivers: not expecting any acknowledgement" (Uuid.to_string uuid) domid;
Expand Down
39 changes: 20 additions & 19 deletions ocaml/xenops/list_domains.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,37 @@ let all_the_rest = ref false

let xc_handle = Xenctrl.interface_open()

let hashtbl_of_domaininfo (x: Xenctrl.domaininfo) : (string, string) Hashtbl.t =
let hashtbl_of_domaininfo (x : Xenctrl.Domain_info.t) : (string, string) Hashtbl.t =
let table = Hashtbl.create 10 in

let pages_to_string_bytes x = Int64.to_string (Memory.bytes_of_pages (Int64.of_nativeint (x))) in
let pages_to_string_mib_used x = Int64.to_string (Memory.mib_of_pages_used (Int64.of_nativeint (x))) in
let pages_to_string_pages x = Int64.to_string ( (Int64.of_nativeint (x))) in

let int = string_of_int and int64 = Int64.to_string and int32 = Int32.to_string in
Hashtbl.add table "id" (int x.Xenctrl.domid);
let open Xenctrl.Domain_info in
Hashtbl.add table "id" (int x.domid);
let state = let bool ch = function true -> ch | _ -> " " in
(bool "D" x.Xenctrl.dying) ^ (bool "S" x.Xenctrl.shutdown) ^
(bool "P" x.Xenctrl.paused) ^ (bool "B" x.Xenctrl.blocked) ^
(bool "R" x.Xenctrl.running) ^ (bool "H" x.Xenctrl.hvm_guest) in
(bool "D" x.dying) ^ (bool "S" x.shutdown) ^
(bool "P" x.paused) ^ (bool "B" x.blocked) ^
(bool "R" x.running) ^ (bool "H" x.hvm_guest) in
Hashtbl.add table "state" state;
Hashtbl.add table "shutdown code" (int x.Xenctrl.shutdown_code);
Hashtbl.add table "tot bytes" (pages_to_string_bytes x.Xenctrl.total_memory_pages);
Hashtbl.add table "tot pages" (pages_to_string_pages x.Xenctrl.total_memory_pages);
Hashtbl.add table "tot MiB" (pages_to_string_mib_used x.Xenctrl.total_memory_pages);
Hashtbl.add table "max bytes" (if x.Xenctrl.domid = 0 then "N/A" else (pages_to_string_bytes x.Xenctrl.max_memory_pages));
Hashtbl.add table "max pages" (if x.Xenctrl.domid = 0 then "N/A" else (pages_to_string_pages x.Xenctrl.max_memory_pages));
Hashtbl.add table "max MiB" (if x.Xenctrl.domid = 0 then "N/A" else (pages_to_string_mib_used x.Xenctrl.max_memory_pages));
Hashtbl.add table "sif" (int64 x.Xenctrl.shared_info_frame);
Hashtbl.add table "cpu time" (int64 x.Xenctrl.cpu_time);
Hashtbl.add table "vcpus online" (int x.Xenctrl.nr_online_vcpus);
Hashtbl.add table "max vcpu id" (int x.Xenctrl.max_vcpu_id);
Hashtbl.add table "ssidref" (int32 x.Xenctrl.ssidref);
Hashtbl.add table "uuid" (Uuid.to_string (Uuid.uuid_of_int_array x.Xenctrl.handle));
Hashtbl.add table "shutdown code" (int x.shutdown_code);
Hashtbl.add table "tot bytes" (pages_to_string_bytes x.total_memory_pages);
Hashtbl.add table "tot pages" (pages_to_string_pages x.total_memory_pages);
Hashtbl.add table "tot MiB" (pages_to_string_mib_used x.total_memory_pages);
Hashtbl.add table "max bytes" (if x.domid = 0 then "N/A" else (pages_to_string_bytes x.max_memory_pages));
Hashtbl.add table "max pages" (if x.domid = 0 then "N/A" else (pages_to_string_pages x.max_memory_pages));
Hashtbl.add table "max MiB" (if x.domid = 0 then "N/A" else (pages_to_string_mib_used x.max_memory_pages));
Hashtbl.add table "sif" (int64 x.shared_info_frame);
Hashtbl.add table "cpu time" (int64 x.cpu_time);
Hashtbl.add table "vcpus online" (int x.nr_online_vcpus);
Hashtbl.add table "max vcpu id" (int x.max_vcpu_id);
Hashtbl.add table "ssidref" (int32 x.ssidref);
Hashtbl.add table "uuid" (Uuid.to_string (Uuid.uuid_of_int_array x.handle));
(* Ask for shadow allocation separately *)
let shadow_mib =
try Some (Int64.of_int (Xenctrl.shadow_allocation_get xc_handle x.Xenctrl.domid))
try Some (Int64.of_int (Xenctrl.shadow_allocation_get xc_handle x.domid))
with _ -> None in
let shadow_bytes = may Memory.bytes_of_mib shadow_mib in
let shadow_pages = may Memory.pages_of_mib shadow_mib in
Expand Down
Loading

0 comments on commit 267c545

Please sign in to comment.