提交 c3e2d592 编写于 作者: J Jincheng Miao 提交者: Michal Privoznik

virsh-host: fix pagesize unit of freepages

The unit of '--pagesize' of freepages is kibibytes.

https://bugzilla.redhat.com/show_bug.cgi?id=1145048Signed-off-by: NJincheng Miao <jmiao@redhat.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 9cc1586d
......@@ -293,7 +293,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
bool ret = false;
unsigned int npages;
unsigned int *pagesize = NULL;
unsigned long long tmp = 0;
unsigned long long bytes = 0;
unsigned int kibibytes = 0;
int cell;
unsigned long long *counts = NULL;
size_t i, j;
......@@ -304,9 +305,16 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
xmlXPathContextPtr ctxt = NULL;
bool all = vshCommandOptBool(cmd, "all");
bool cellno = vshCommandOptBool(cmd, "cellno");
bool pagesz = vshCommandOptBool(cmd, "pagesize");
VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno);
if (vshCommandOptScaledInt(cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) {
vshError(ctl, "%s", _("page size has to be a number"));
goto cleanup;
}
kibibytes = VIR_DIV_UP(bytes, 1024);
if (all) {
if (!(cap_xml = virConnectGetCapabilities(ctl->conn))) {
vshError(ctl, "%s", _("unable to get node capabilities"));
......@@ -318,6 +326,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
if (!pagesz) {
nodes_cnt = virXPathNodeSet("/capabilities/host/cpu/pages", ctxt, &nodes);
if (nodes_cnt <= 0) {
......@@ -342,6 +351,11 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
npages = nodes_cnt;
VIR_FREE(nodes);
} else {
pagesize = vshMalloc(ctl, sizeof(*pagesize));
pagesize[0] = kibibytes;
npages = 1;
}
counts = vshCalloc(ctl, npages, sizeof(*counts));
......@@ -380,22 +394,19 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
}
if (cell < -1) {
vshError(ctl, "%s", _("cell number must be non-negative integer or -1"));
vshError(ctl, "%s",
_("cell number must be non-negative integer or -1"));
goto cleanup;
}
if (vshCommandOptScaledInt(cmd, "pagesize", &tmp, 1, UINT_MAX) < 0) {
vshError(ctl, "%s", _("page size has to be a number"));
if (!pagesz) {
vshError(ctl, "%s", _("missing pagesize argument"));
goto cleanup;
}
/* page size is expected in kibibytes */
pagesize = vshMalloc(ctl, sizeof(*pagesize));
*pagesize = tmp / 1024;
if (!pagesize[0]) {
vshError(ctl, "%s", _("page size must be at least 1KiB"));
goto cleanup;
}
pagesize[0] = kibibytes;
counts = vshMalloc(ctl, sizeof(*counts));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册