>From 5b9c5881773f209d06235fba421704f0a0e44712 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Fri, 9 Jun 2017 12:21:52 -0400 Subject: [PATCH 5/7] libxc: Add xc_list_numa Implement the libxc call to retrieve NUMA ranges. Signed-off-by: Konrad Rzeszutek Wilk --- tools/libxc/xc_misc.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/libxc/xenctrl.h | 1 + 2 files changed, 63 insertions(+) diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 851f341..8ce8fc4 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -1373,6 +1373,68 @@ int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout) return _xc_livepatch_action(xch, name, LIVEPATCH_ACTION_REPLACE, timeout); } +int xc_list_numa(xc_interface *xch, struct xen_vmemrange** _info) +{ + int rc = 0; + unsigned int nodes; + DECLARE_DOMCTL; + DECLARE_HYPERCALL_BUFFER(xen_vmemrange_t, ranges); + + if ( !_info ) + { + errno = EINVAL; + return -1; + } + + memset(&domctl, 0, sizeof(domctl)); + domctl.cmd = XEN_DOMCTL_get_numa_ranges; + domctl.u.get_numa_ranges.nodes = 0; + + rc = do_domctl(xch, &domctl); + /* E2BIG is expected here since we didn't allocate any. */ + if ( rc && errno != E2BIG ) + return rc; + + nodes = domctl.u.get_numa_ranges.nodes; + if ( nodes == 0 ) + { + /* No NUMA at all? It should have one entry at least! */ + *_info = NULL; + errno = EINVAL; + return -1; + } + *_info = calloc(nodes, sizeof(**_info)); + if ( !*_info ) + { + errno = ENOMEM; + return -1; + } + + ranges = xc_hypercall_buffer_alloc(xch, ranges, nodes * sizeof(xen_vmemrange_t)); + if ( !ranges ) + { + free(*_info); + errno = ENOMEM; + return -1; + } + set_xen_guest_handle(domctl.u.get_numa_ranges.ranges, ranges); + memset(*_info, 0, nodes * sizeof(**_info)); + + rc = do_domctl(xch, &domctl); + + if ( !rc && (domctl.u.get_numa_ranges.nodes != (nodes - 1)) ) + memcpy(*_info, ranges, nodes * sizeof(*ranges)); + + xc_hypercall_buffer_free(xch, ranges); + if ( rc < 0 ) + { + free(*_info); + *_info = NULL; + } + + return (rc < 0) ? -1 : nodes; +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 5802d69..2ba2b47 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -2569,4 +2569,5 @@ int xc_livepatch_revert(xc_interface *xch, char *name, uint32_t timeout); int xc_livepatch_unload(xc_interface *xch, char *name, uint32_t timeout); int xc_livepatch_replace(xc_interface *xch, char *name, uint32_t timeout); +int xc_list_numa(xc_interface *xch, struct xen_vmemrange** _info); #endif /* XENCTRL_H */ -- 2.9.4