|
|
9119d9 |
From c269ac2030e77ba9e84e3014535e5b5acfaee524 Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <c269ac2030e77ba9e84e3014535e5b5acfaee524@dist-git>
|
|
|
9119d9 |
From: Jincheng Miao <jmiao@redhat.com>
|
|
|
9119d9 |
Date: Tue, 23 Sep 2014 10:34:03 +0200
|
|
|
9119d9 |
Subject: [PATCH] virsh-host: fix pagesize unit of freepages
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1145048
|
|
|
9119d9 |
|
|
|
9119d9 |
The unit of '--pagesize' of freepages is kibibytes.
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Jincheng Miao <jmiao@redhat.com>
|
|
|
9119d9 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
9119d9 |
(cherry picked from commit c3e2d5929c1bfaaeb2ef2df121dc90d767b228f5)
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
tools/virsh-host.c | 69 +++++++++++++++++++++++++++++++-----------------------
|
|
|
9119d9 |
1 file changed, 40 insertions(+), 29 deletions(-)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
|
|
|
9119d9 |
index ad821b3..e1d5bae 100644
|
|
|
9119d9 |
--- a/tools/virsh-host.c
|
|
|
9119d9 |
+++ b/tools/virsh-host.c
|
|
|
9119d9 |
@@ -293,7 +293,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
|
|
|
9119d9 |
bool ret = false;
|
|
|
9119d9 |
unsigned int npages;
|
|
|
9119d9 |
unsigned int *pagesize = NULL;
|
|
|
9119d9 |
- unsigned long long tmp = 0;
|
|
|
9119d9 |
+ unsigned long long bytes = 0;
|
|
|
9119d9 |
+ unsigned int kibibytes = 0;
|
|
|
9119d9 |
int cell;
|
|
|
9119d9 |
unsigned long long *counts = NULL;
|
|
|
9119d9 |
size_t i, j;
|
|
|
9119d9 |
@@ -304,9 +305,16 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
|
|
|
9119d9 |
xmlXPathContextPtr ctxt = NULL;
|
|
|
9119d9 |
bool all = vshCommandOptBool(cmd, "all");
|
|
|
9119d9 |
bool cellno = vshCommandOptBool(cmd, "cellno");
|
|
|
9119d9 |
+ bool pagesz = vshCommandOptBool(cmd, "pagesize");
|
|
|
9119d9 |
|
|
|
9119d9 |
VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno);
|
|
|
9119d9 |
|
|
|
9119d9 |
+ if (vshCommandOptScaledInt(cmd, "pagesize", &bytes, 1024, UINT_MAX) < 0) {
|
|
|
9119d9 |
+ vshError(ctl, "%s", _("page size has to be a number"));
|
|
|
9119d9 |
+ goto cleanup;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+ kibibytes = VIR_DIV_UP(bytes, 1024);
|
|
|
9119d9 |
+
|
|
|
9119d9 |
if (all) {
|
|
|
9119d9 |
if (!(cap_xml = virConnectGetCapabilities(ctl->conn))) {
|
|
|
9119d9 |
vshError(ctl, "%s", _("unable to get node capabilities"));
|
|
|
9119d9 |
@@ -318,31 +326,37 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- nodes_cnt = virXPathNodeSet("/capabilities/host/cpu/pages", ctxt, &nodes);
|
|
|
9119d9 |
+ if (!pagesz) {
|
|
|
9119d9 |
+ nodes_cnt = virXPathNodeSet("/capabilities/host/cpu/pages", ctxt, &nodes);
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (nodes_cnt <= 0) {
|
|
|
9119d9 |
- vshError(ctl, "%s", _("could not get information about "
|
|
|
9119d9 |
- "supported page sizes"));
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
- }
|
|
|
9119d9 |
-
|
|
|
9119d9 |
- pagesize = vshCalloc(ctl, nodes_cnt, sizeof(*pagesize));
|
|
|
9119d9 |
-
|
|
|
9119d9 |
- for (i = 0; i < nodes_cnt; i++) {
|
|
|
9119d9 |
- char *val = virXMLPropString(nodes[i], "size");
|
|
|
9119d9 |
-
|
|
|
9119d9 |
- if (virStrToLong_ui(val, NULL, 10, &pagesize[i]) < 0) {
|
|
|
9119d9 |
- vshError(ctl, _("unable to parse page size: %s"), val);
|
|
|
9119d9 |
- VIR_FREE(val);
|
|
|
9119d9 |
+ if (nodes_cnt <= 0) {
|
|
|
9119d9 |
+ vshError(ctl, "%s", _("could not get information about "
|
|
|
9119d9 |
+ "supported page sizes"));
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- VIR_FREE(val);
|
|
|
9119d9 |
+ pagesize = vshCalloc(ctl, nodes_cnt, sizeof(*pagesize));
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ for (i = 0; i < nodes_cnt; i++) {
|
|
|
9119d9 |
+ char *val = virXMLPropString(nodes[i], "size");
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ if (virStrToLong_ui(val, NULL, 10, &pagesize[i]) < 0) {
|
|
|
9119d9 |
+ vshError(ctl, _("unable to parse page size: %s"), val);
|
|
|
9119d9 |
+ VIR_FREE(val);
|
|
|
9119d9 |
+ goto cleanup;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ VIR_FREE(val);
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ npages = nodes_cnt;
|
|
|
9119d9 |
+ VIR_FREE(nodes);
|
|
|
9119d9 |
+ } else {
|
|
|
9119d9 |
+ pagesize = vshMalloc(ctl, sizeof(*pagesize));
|
|
|
9119d9 |
+ pagesize[0] = kibibytes;
|
|
|
9119d9 |
+ npages = 1;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- npages = nodes_cnt;
|
|
|
9119d9 |
- VIR_FREE(nodes);
|
|
|
9119d9 |
-
|
|
|
9119d9 |
counts = vshCalloc(ctl, npages, sizeof(*counts));
|
|
|
9119d9 |
|
|
|
9119d9 |
nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell",
|
|
|
9119d9 |
@@ -380,22 +394,19 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
if (cell < -1) {
|
|
|
9119d9 |
- vshError(ctl, "%s", _("cell number must be non-negative integer or -1"));
|
|
|
9119d9 |
+ vshError(ctl, "%s",
|
|
|
9119d9 |
+ _("cell number must be non-negative integer or -1"));
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
- if (vshCommandOptScaledInt(cmd, "pagesize", &tmp, 1, UINT_MAX) < 0) {
|
|
|
9119d9 |
- vshError(ctl, "%s", _("page size has to be a number"));
|
|
|
9119d9 |
+ if (!pagesz) {
|
|
|
9119d9 |
+ vshError(ctl, "%s", _("missing pagesize argument"));
|
|
|
9119d9 |
goto cleanup;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
/* page size is expected in kibibytes */
|
|
|
9119d9 |
pagesize = vshMalloc(ctl, sizeof(*pagesize));
|
|
|
9119d9 |
- *pagesize = tmp / 1024;
|
|
|
9119d9 |
-
|
|
|
9119d9 |
- if (!pagesize[0]) {
|
|
|
9119d9 |
- vshError(ctl, "%s", _("page size must be at least 1KiB"));
|
|
|
9119d9 |
- goto cleanup;
|
|
|
9119d9 |
- }
|
|
|
9119d9 |
+ pagesize[0] = kibibytes;
|
|
|
9119d9 |
|
|
|
9119d9 |
counts = vshMalloc(ctl, sizeof(*counts));
|
|
|
9119d9 |
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.1
|
|
|
9119d9 |
|