提交 f69ece07 编写于 作者: M Michal Privoznik

virsh: Teach cmdFreepages to work with lxc driver

Some drivers don't expose available huge page sizes in the
capabilities XML. For instance, LXC driver is one of those.
This has a downside that when virsh is trying to get
aggregated info on free pages per all NUMA nodes, it fails.
The problem is that the virNodeGetFreePages() API expects
caller to pass an array of page sizes he is interested in.
In virsh, this array is filled from the capabilities from
'/capabilities/host/cpu/pages' XPath. As said, in LXC
there's no such XPath and therefore virsh fails currently.
But hey, we can fallback: the page sizes are exposed under
'/capabilities/host/topology/cells/cell/pages'. The page
size can be collected from there, and voilà the command
works again. But now we must make sure that there are no
duplicates in the array passed to the public API. Otherwise
we won't get as beautiful output as we are getting now.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 416d0e94
...@@ -285,6 +285,15 @@ static const vshCmdOptDef opts_freepages[] = { ...@@ -285,6 +285,15 @@ static const vshCmdOptDef opts_freepages[] = {
{.name = NULL} {.name = NULL}
}; };
static int
vshPageSizeSorter(const void *a, const void *b)
{
unsigned int pa = *(unsigned int *)a;
unsigned int pb = *(unsigned int *)b;
return pa - pb;
}
static bool static bool
cmdFreepages(vshControl *ctl, const vshCmd *cmd) cmdFreepages(vshControl *ctl, const vshCmd *cmd)
{ {
...@@ -326,9 +335,15 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ...@@ -326,9 +335,15 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
nodes_cnt = virXPathNodeSet("/capabilities/host/cpu/pages", ctxt, &nodes); nodes_cnt = virXPathNodeSet("/capabilities/host/cpu/pages", ctxt, &nodes);
if (nodes_cnt <= 0) { if (nodes_cnt <= 0) {
vshError(ctl, "%s", _("could not get information about " /* Some drivers don't export page sizes under the
"supported page sizes")); * XPath above. Do another trick to get them. */
goto cleanup; nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell/pages",
ctxt, &nodes);
if (nodes_cnt <= 0) {
vshError(ctl, "%s", _("could not get information about "
"supported page sizes"));
goto cleanup;
}
} }
pagesize = vshCalloc(ctl, nodes_cnt, sizeof(*pagesize)); pagesize = vshCalloc(ctl, nodes_cnt, sizeof(*pagesize));
...@@ -345,6 +360,22 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ...@@ -345,6 +360,22 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
VIR_FREE(val); VIR_FREE(val);
} }
/* Here, if we've done the trick few lines above,
* @pagesize array will contain duplicates. We should
* remove them otherwise not very nice output will be
* produced. */
qsort(pagesize, nodes_cnt, sizeof(*pagesize), vshPageSizeSorter);
for (i = 0; i < nodes_cnt - 1;) {
if (pagesize[i] == pagesize[i + 1]) {
memmove(pagesize + i, pagesize + i + 1,
(nodes_cnt - i + 1) * sizeof(*pagesize));
nodes_cnt--;
} else {
i++;
}
}
npages = nodes_cnt; npages = nodes_cnt;
VIR_FREE(nodes); VIR_FREE(nodes);
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册