From 1bdb22a9390e5be69c65b78bdde1d4c42f804725 Mon Sep 17 00:00:00 2001 From: Andrii Sultanov Date: Mon, 21 Oct 2024 16:16:47 +0100 Subject: [PATCH] CA-400860: rrdp-netdev - drop xenctrl, use xenstore to get UUIDs from domids instead Signed-off-by: Andrii Sultanov --- ocaml/xcp-rrdd/bin/rrdp-netdev/dune | 2 +- ocaml/xcp-rrdd/bin/rrdp-netdev/rrdp_netdev.ml | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ocaml/xcp-rrdd/bin/rrdp-netdev/dune b/ocaml/xcp-rrdd/bin/rrdp-netdev/dune index c5acc80a8b..55c31d4d9f 100644 --- a/ocaml/xcp-rrdd/bin/rrdp-netdev/dune +++ b/ocaml/xcp-rrdd/bin/rrdp-netdev/dune @@ -3,6 +3,7 @@ (name rrdp_netdev) (libraries astring + ezxenstore.core integers netlink rrdd-plugin @@ -13,7 +14,6 @@ xapi-log xapi-rrd xapi-stdext-std - xenctrl ) ) diff --git a/ocaml/xcp-rrdd/bin/rrdp-netdev/rrdp_netdev.ml b/ocaml/xcp-rrdd/bin/rrdp-netdev/rrdp_netdev.ml index 299bb9a97d..c7dab55ac9 100644 --- a/ocaml/xcp-rrdd/bin/rrdp-netdev/rrdp_netdev.ml +++ b/ocaml/xcp-rrdd/bin/rrdp-netdev/rrdp_netdev.ml @@ -13,11 +13,14 @@ *) open Rrdd_plugin +open Ezxenstore_core module D = Debug.Make (struct let name = "xcp-rrdp-netdev" end) module Process = Rrdd_plugin.Process (struct let name = "xcp-rrdd-netdev" end) +let fail = Printf.ksprintf failwith + type iface_stats = { tx_bytes: int64 (** bytes emitted *) ; tx_pkts: int64 (** packets emitted *) @@ -132,18 +135,16 @@ let transform_taps devs = newdevnames let generate_netdev_dss () = - let _, doms, _ = - Xenctrl.with_intf (fun xc -> Xenctrl_lib.domain_snapshot xc) - in - - let uuid_of_domid domains domid = - let _, uuid, _ = - try List.find (fun (_, _, domid') -> domid = domid') domains - with Not_found -> - failwith - (Printf.sprintf "Failed to find uuid corresponding to domid: %d" domid) - in - uuid + let uuid_of_domid domid = + try + Xenstore.with_xs (fun xs -> + let vm = xs.Xenstore.Xs.getdomainpath domid ^ "/vm" in + let vm_dir = xs.Xenstore.Xs.read vm in + xs.Xenstore.Xs.read (vm_dir ^ "/uuid") + ) + with e -> + fail "Failed to find uuid corresponding to domid: %d (%s)" domid + (Printexc.to_string e) in let dbg = "rrdp_netdev" in @@ -198,7 +199,7 @@ let generate_netdev_dss () = let vif_name = Printf.sprintf "vif_%d" d2 in (* Note: rx and tx are the wrong way round because from dom0 we see the vms backwards *) - let uuid = uuid_of_domid doms d1 in + let uuid = uuid_of_domid d1 in ( Rrd.VM uuid , Ds.ds_make ~name:(vif_name ^ "_tx") ~units:"B/s" ~description: