mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
libxl/libxc: Move libxl_get_numainfo()'s hypercall buffer management to libxc
xc_numainfo() is not expected to be used on a hot path and therefore hypercall buffer management can be pushed into libxc. This will simplify life for callers. Also update error logging macros. Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Acked-by: Ian Campbell <ian.campbell@citrix.com>
This commit is contained in:
1 parent
250f0b43af
commit
85d78b4cdf
4 files changed
+58
-67
No files matched your search
@@ -1293,33 +1293,23 @@ out:
|
||||
|
||||
static PyObject *pyxc_numainfo(XcObject *self)
|
||||
{
|
||||
xc_numainfo_t ninfo = { 0 };
|
||||
unsigned i, j;
|
||||
unsigned i, j, num_nodes;
|
||||
uint64_t free_heap;
|
||||
PyObject *ret_obj = NULL, *node_to_node_dist_list_obj;
|
||||
PyObject *node_to_memsize_obj, *node_to_memfree_obj;
|
||||
PyObject *node_to_dma32_mem_obj, *node_to_node_dist_obj;
|
||||
DECLARE_HYPERCALL_BUFFER(xen_sysctl_meminfo_t, meminfo);
|
||||
DECLARE_HYPERCALL_BUFFER(uint32_t, distance);
|
||||
xc_meminfo_t *meminfo = NULL;
|
||||
uint32_t *distance = NULL;
|
||||
|
||||
set_xen_guest_handle(ninfo.meminfo, HYPERCALL_BUFFER_NULL);
|
||||
set_xen_guest_handle(ninfo.distance, HYPERCALL_BUFFER_NULL);
|
||||
if ( xc_numainfo(self->xc_handle, &ninfo) != 0 )
|
||||
if ( xc_numainfo(self->xc_handle, &num_nodes, NULL, NULL) != 0 )
|
||||
goto out;
|
||||
|
||||
meminfo = xc_hypercall_buffer_alloc(self->xc_handle, meminfo,
|
||||
sizeof(*meminfo) * ninfo.num_nodes);
|
||||
if ( meminfo == NULL )
|
||||
goto out;
|
||||
distance = xc_hypercall_buffer_alloc(self->xc_handle, distance,
|
||||
sizeof(*distance) *
|
||||
ninfo.num_nodes * ninfo.num_nodes);
|
||||
if ( distance == NULL )
|
||||
meminfo = calloc(num_nodes, sizeof(*meminfo));
|
||||
distance = calloc(num_nodes * num_nodes, sizeof(*distance));
|
||||
if ( (meminfo == NULL) || (distance == NULL) )
|
||||
goto out;
|
||||
|
||||
set_xen_guest_handle(ninfo.meminfo, meminfo);
|
||||
set_xen_guest_handle(ninfo.distance, distance);
|
||||
if ( xc_numainfo(self->xc_handle, &ninfo) != 0 )
|
||||
if ( xc_numainfo(self->xc_handle, &num_nodes, meminfo, distance) != 0 )
|
||||
goto out;
|
||||
|
||||
/* Construct node-to-* lists. */
|
||||
@@ -1327,7 +1317,7 @@ static PyObject *pyxc_numainfo(XcObject *self)
|
||||
node_to_memfree_obj = PyList_New(0);
|
||||
node_to_dma32_mem_obj = PyList_New(0);
|
||||
node_to_node_dist_list_obj = PyList_New(0);
|
||||
for ( i = 0; i < ninfo.num_nodes; i++ )
|
||||
for ( i = 0; i < num_nodes; i++ )
|
||||
{
|
||||
PyObject *pyint;
|
||||
unsigned invalid_node;
|
||||
@@ -1351,9 +1341,9 @@ static PyObject *pyxc_numainfo(XcObject *self)
|
||||
/* Node to Node Distance */
|
||||
node_to_node_dist_obj = PyList_New(0);
|
||||
invalid_node = (meminfo[i].memsize == XEN_INVALID_MEM_SZ);
|
||||
for ( j = 0; j < ninfo.num_nodes; j++ )
|
||||
for ( j = 0; j < num_nodes; j++ )
|
||||
{
|
||||
uint32_t dist = distance[i * ninfo.num_nodes + j];
|
||||
uint32_t dist = distance[i * num_nodes + j];
|
||||
if ( invalid_node || (dist == XEN_INVALID_NODE_DIST) )
|
||||
{
|
||||
PyList_Append(node_to_node_dist_obj, Py_None);
|
||||
@@ -1369,7 +1359,7 @@ static PyObject *pyxc_numainfo(XcObject *self)
|
||||
Py_DECREF(node_to_node_dist_obj);
|
||||
}
|
||||
|
||||
ret_obj = Py_BuildValue("{s:i}", "max_node_index", ninfo.num_nodes + 1);
|
||||
ret_obj = Py_BuildValue("{s:i}", "max_node_index", num_nodes + 1);
|
||||
|
||||
PyDict_SetItemString(ret_obj, "node_memsize", node_to_memsize_obj);
|
||||
Py_DECREF(node_to_memsize_obj);
|
||||
@@ -1385,8 +1375,8 @@ static PyObject *pyxc_numainfo(XcObject *self)
|
||||
Py_DECREF(node_to_node_dist_list_obj);
|
||||
|
||||
out:
|
||||
xc_hypercall_buffer_free(self->xc_handle, meminfo);
|
||||
xc_hypercall_buffer_free(self->xc_handle, distance);
|
||||
free(meminfo);
|
||||
free(distance);
|
||||
return ret_obj ? ret_obj : pyxc_error_to_exception(self->xc_handle);
|
||||
}
|
||||
|
||||
|
||||