[libvirt] building xen and libvirt with odd --prefix fails
by Olaf Hering
My xen is configured with "--prefix=/odd/path --enable-rpath". My
libvirt is configured with "env PKG_CONFIG_PATH=/odd/path/share/pkgconfig
bash -x autogen.sh --without-xen --with-libxl". Now make in libvirt fails
to find "xen/xen.h" needed by xenconfig/xen_common.c, I think it expects
it in /usr/include. But I have no xen-devel.rpm installed.
I wonder if there are wrong assumptions in libvirt about xen. Since a
while xen has a xenlight.pc which contains the required info to find
headers and libs. Can there ever be a case where libxl is somewhere else
than libxenstore and whatever else is provided by xen? I think they
always go into the very same place.
So shouldnt libvirt be updated to first check for xenlight.pc, and use
the result for everything related to xen? I think that would work for
every xen version which has a xenlight.pc (4.5+).
And initially I did not pass the matching --prefix to libvirts configure.
Even with matching --prefix libvirt does not look in $prefix/include for
xen/xen.h, even with --includedir=$prefix/include.
Olaf
9 years, 8 months
[libvirt] [PATCHv2] virBitmap: Place virBitmapIsAllClear check after virBitmapParse calls
by Erik Skultety
This patch adds checks for empty bitmaps right after the calls of
virBitmapParse. These only include spots where set API's are called and
where domain's XML is parsed.
Also, it partially reverts commit 983f5a which added a check for
invalid nodeset "0,^0" into virBitmapParse function. This change broke
the logic, as an empty bitmap should not cause an error.
https://bugzilla.redhat.com/show_bug.cgi?id=1210545
---
src/conf/domain_conf.c | 35 +++++++++++++++++++++++++++++++----
src/conf/numa_conf.c | 23 +++++++++++++++++++----
src/qemu/qemu_driver.c | 5 +++--
src/util/virbitmap.c | 3 ---
src/xenconfig/xen_sxpr.c | 7 +++++++
tests/virbitmaptest.c | 13 ++++++++++---
6 files changed, 70 insertions(+), 16 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 823e003..f7f68ba 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11577,6 +11577,12 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node,
if (virBitmapParse(nodemask, 0, &def->sourceNodes,
VIR_DOMAIN_CPUMASK_LEN) < 0)
goto cleanup;
+
+ if (virBitmapIsAllClear(def->sourceNodes)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid value of 'nodemask': %s"), nodemask);
+ goto cleanup;
+ }
}
ret = 0;
@@ -13265,6 +13271,13 @@ virDomainVcpuPinDefParseXML(xmlNodePtr node,
if (virBitmapParse(tmp, 0, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
goto error;
+ if (virBitmapIsAllClear(def->cpumask)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid value of 'cpuset': %s"),
+ tmp);
+ goto error;
+ }
+
cleanup:
VIR_FREE(tmp);
ctxt->node = oldnode;
@@ -13366,6 +13379,12 @@ virDomainHugepagesParseXML(xmlNodePtr node,
if (virBitmapParse(nodeset, 0, &hugepage->nodemask,
VIR_DOMAIN_CPUMASK_LEN) < 0)
goto cleanup;
+
+ if (virBitmapIsAllClear(hugepage->nodemask)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid value of 'nodeset': %s"), nodeset);
+ goto cleanup;
+ }
}
ret = 0;
@@ -13487,13 +13506,14 @@ virDomainThreadSchedParse(xmlNodePtr node,
goto error;
}
- if (!virBitmapParse(tmp, 0, &sp->ids,
- VIR_DOMAIN_CPUMASK_LEN) ||
- virBitmapIsAllClear(sp->ids) ||
+ if (virBitmapParse(tmp, 0, &sp->ids, VIR_DOMAIN_CPUMASK_LEN) < 0)
+ goto error;
+
+ if (virBitmapIsAllClear(sp->ids) ||
virBitmapNextSetBit(sp->ids, -1) < minid ||
virBitmapLastSetBit(sp->ids) > maxid) {
- virReportError(VIR_ERR_XML_ERROR,
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid value of '%s': %s"),
name, tmp);
goto error;
@@ -13861,6 +13881,13 @@ virDomainDefParseXML(xmlDocPtr xml,
if (virBitmapParse(tmp, 0, &def->cpumask,
VIR_DOMAIN_CPUMASK_LEN) < 0)
goto error;
+
+ if (virBitmapIsAllClear(def->cpumask)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid value of 'cpuset': %s"), tmp);
+ goto error;
+ }
+
VIR_FREE(tmp);
}
}
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index 8a0f686..7ad3f66 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -178,6 +178,12 @@ virDomainNumatuneNodeParseXML(virDomainNumaPtr numa,
if (virBitmapParse(tmp, 0, &mem_node->nodeset,
VIR_DOMAIN_CPUMASK_LEN) < 0)
goto cleanup;
+
+ if (virBitmapIsAllClear(mem_node->nodeset)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid value of 'nodeset': %s"), tmp);
+ goto cleanup;
+ }
VIR_FREE(tmp);
}
@@ -233,10 +239,19 @@ virDomainNumatuneParseXML(virDomainNumaPtr numa,
}
VIR_FREE(tmp);
- if ((tmp = virXMLPropString(node, "nodeset")) &&
- virBitmapParse(tmp, 0, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
- goto cleanup;
- VIR_FREE(tmp);
+ tmp = virXMLPropString(node, "nodeset");
+ if (tmp) {
+ if (virBitmapParse(tmp, 0, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0)
+ goto cleanup;
+
+ if (virBitmapIsAllClear(nodeset)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid value of 'nodeset': %s"), tmp);
+ goto cleanup;
+ }
+
+ VIR_FREE(tmp);
+ }
}
if (virDomainNumatuneSet(numa,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f37a11e..cbb6e1b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10134,8 +10134,9 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
goto endjob;
if (virBitmapIsAllClear(nodeset)) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("Invalid nodeset for numatune"));
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("Invalid nodeset of 'numatune': %s"),
+ param->value.s);
goto endjob;
}
}
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index 5322bce..bf905ab 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -416,9 +416,6 @@ virBitmapParse(const char *str,
}
}
- if (virBitmapIsAllClear(*bitmap))
- goto error;
-
return virBitmapCountBits(*bitmap);
error:
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index 5a170d3..d77abf3 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -1165,6 +1165,13 @@ xenParseSxpr(const struct sexpr *root,
if (virBitmapParse(cpus, 0, &def->cpumask,
VIR_DOMAIN_CPUMASK_LEN) < 0)
goto error;
+
+ if (virBitmapIsAllClear(def->cpumask)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Invalid value of 'cpumask': %s"),
+ cpus);
+ goto error;
+ }
}
def->maxvcpus = sexpr_int(root, "domain/vcpus");
diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c
index f247275..9a84e4c 100644
--- a/tests/virbitmaptest.c
+++ b/tests/virbitmaptest.c
@@ -524,16 +524,23 @@ static int
test10(const void *opaque ATTRIBUTE_UNUSED)
{
int ret = -1;
- virBitmapPtr b1 = NULL, b2 = NULL, b3 = NULL;
+ virBitmapPtr b1 = NULL, b2 = NULL, b3 = NULL, b4 = NULL;
if (virBitmapParse("0-3,5-8,11-15", 0, &b1, 20) < 0 ||
virBitmapParse("4,9,10,16-19", 0, &b2, 20) < 0 ||
- virBitmapParse("15", 0, &b3, 20) < 0)
+ virBitmapParse("15", 0, &b3, 20) < 0 ||
+ virBitmapParse("0,^0", 0, &b4, 20) < 0)
+ goto cleanup;
+
+ if (!virBitmapIsAllClear(b4))
goto cleanup;
if (virBitmapOverlaps(b1, b2) ||
+ virBitmapOverlaps(b1, b4) ||
virBitmapOverlaps(b2, b3) ||
- !virBitmapOverlaps(b1, b3))
+ virBitmapOverlaps(b2, b4) ||
+ !virBitmapOverlaps(b1, b3) ||
+ virBitmapOverlaps(b3, b4))
goto cleanup;
ret = 0;
--
1.9.3
9 years, 8 months
[libvirt] qemu: lifecycle: reboot + shutdown, unexpected vm status.
by zhang bo
Steps:
1 virsh reboot guest1 --mode=acpi
2 virsh shutdown guest1 --mode=agent
Expected result:
As the SHUTDOWN job is after REBOOT, we expected the guest to be *shutoff*. (Do you think so?)
Exacted result:
After the 2 steps above, the guest got *rebooted*.
The reason to this problem:
1 in qemuDomainReboot(mode acpi), it sets priv->fakeReboot to 1.
2 after shutdown/reboot, qemu monitor IO trigged qemuProcessHandleShutdown(), which finds that priv->fakeReboot is 1, and reboot the guest.
Root Cause of the problem:
After further look into the problem, We found that the design of acpi/agent shutdown/reboot seems a little chaotic.
-----------------------------------
sheet1 who sets fakeReboot
-----------------------------------
shutdown reboot
acpi Y(0) Y(1)
agent N N
It's apparently, *acpi-mode* jobs set fakeReboot.
-----------------------------------
sheet2 who needs to check fakeReboot(qemuProcessHandleShutdown())
-----------------------------------
shutdown reboot
acpi Y Y
agent *Y* *N*
Things become a little odd here. only agent-mode reboot doesn't check fakeReboot.
We can tell from the above 2 sheets, that they're not consistent.
*Agent-mode shutdown needs to check fakeReboot(trigger by SHUTDOWN monitorIO event), while it didn't set it before.*
The chaos is not caused by libvirtd, it's a systematic problem, including guest os and qemu. (guest os writes ACPI, triggers qemu, qemu then triggers libvirtd)
My Solution:
A simple solution is to make the 1st sheet consistent to the 2nd sheet, which is:
-----------------------------------
sheet3 who should set fakeReboot:
-----------------------------------
shutdown reboot
acpi Y(0) Y(1)
agent *Y(0)* N
-----------------------------------
we let agent-mode shutdown set fakeReboot to 0.
--------------------------------------------------------------------------------
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7eb5a7d..c751dcf 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1959,6 +1959,8 @@ static int qemuDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
goto endjob;
}
+ qemuDomainSetFakeReboot(driver, vm, isReboot);
+
if (useAgent) {
qemuDomainObjEnterAgent(vm);
ret = qemuAgentShutdown(priv->agent, agentFlag);
@@ -1970,7 +1972,6 @@ static int qemuDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
*/
if (!useAgent ||
(ret < 0 && (acpiRequested || !flags))) {
- qemuDomainSetFakeReboot(driver, vm, isReboot);
/* Even if agent failed, we have to check if guest went away
* by itself while our locks were down. */
----------------------------------------------------------------------------------
Discussion:
Although the solution above seems to have solved the problem, but it seems a little awkward to have sheets like this.
Maybe we should let sheet2 consistent with sheet1, rather than letting sheet1 consistent to sheet2. But It's too difficult to realize that, seems impossible
So, is there a better way to solve this problem? or, shall I commit this patch?
9 years, 8 months
Re: [libvirt] Building libvirt under Windows
by Matthias Bolte
2015-04-16 11:52 GMT+02:00 Pavel Fedin <p.fedin(a)samsung.com>:
> Hello!
>
> I am currently building libvirt under Windows64, and i would like to ask
> for correct way to do it.
> The first thing to resolve is absence of RPC XDR library. From configure
> source i figured out that portablexdr library may help. I have downloaded
> it, but it comes with a different RPC code generator named portable-rpcgen.
> I managed to use it, but i had to patch both libvirt (in order to recognize
> this generator and handle it properly) and portable-rpcgen (in order to
> correctly work under Windows, as well as get rid of some crashes).
> Initially i wanted to upstream portablexdr fixes and emailed the author.
> But the author replied that he is not going to fix portablexdr because it's
> now deprecated, since original XDR code comes under free license now. So, i
> have all necessary fixes in my own fork. He suggested me to come here to ask
> about these things.
> So, guys, how do you do it ? I cannot find any rpcgen package usable under
> Windows (MinGW, not Cygwin).
Hi,
In 2010 I wrote a set of scripts to build libvirt on Windows using
MinGW. Sou can find them here:
https://github.com/photron/msys_setup
I haven't update them in the last two years, so they might not work
out-of-the-box anymore. But it might still be helpful to look at them
and see how I did things.
Regarding XDR: I used portablexdr. It worked for me, I can't remember
if I had to patch it or not.
--
Matthias Bolte
http://photron.blogspot.com
9 years, 8 months
[libvirt] util: client: shall libvirtd record task histories?
by zhang bo
We recently encountered a problem:
1) migrate a domain
2) the client unexpectedly got *crashed* (let's take it as virsh command)
3) *libvirtd still kept migrating the domain*
4) after it's restarted, the client didn't know the guest is still migrating.
The problem is that libvirtd and the client has different view of the task state. After migration,
the client may wrongly think that something's wrong that the domain got unexpectedly migrated.
In my opinion, libvirtd should just *execute* tasks, like the hands of a human,
while clients should be the brain to *schedule and remember* tasks.
So, In order to avoid this problem,we should let the client record all the taskes somewhere,
and reload the states after its restart. the client may cancel or continue the task as it wishes.
Libvirtd should not record the task status.
What's your opinions? thanks in advance.
9 years, 8 months
[libvirt] [PATCH] qemu: bulk stats: Ignore errors from missing/inaccessible disks
by Peter Krempa
Rather than erroring out make the best attempt to retrieve other data if
disks are inaccessible or missing. The failure will still be logged
though.
Since the bulk stats API is called on multiple domains an error like
this makes the API unusable. This regression was introduced by commit
596a13713420e01b20ce3dc3fdbe06d073682675
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1209394
---
src/qemu/qemu_driver.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f5a3ef9..e79e2a9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19275,8 +19275,13 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
ret = 0;
goto cleanup;
}
- if (qemuStorageLimitsRefresh(driver, cfg, dom, src) < 0)
+
+ if (qemuStorageLimitsRefresh(driver, cfg, dom, src) < 0) {
+ virResetLastError();
+ ret = 0;
goto cleanup;
+ }
+
if (src->allocation)
QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx,
"allocation", src->allocation);
--
2.3.5
9 years, 8 months
[libvirt] [PATCH] added pom details
by Laszlo Hornyak
The added details are required in order to upload to maven central
Signed-off-by: Laszlo Hornyak <laszlo.hornyak(a)gmail.com>
---
pom.xml.in | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/pom.xml.in b/pom.xml.in
index 4f49a3a..2ac8822 100644
--- a/pom.xml.in
+++ b/pom.xml.in
@@ -12,6 +12,18 @@
<name>libvirt java bindings</name>
<description>Java API for the libvirt C library</description>
<url>http://www.libvirt.org</url>
+ <developers>
+ <developer>
+ <id>veillard(a)redhat.com</id>
+ <email>veillard(a)redhat.com</email>
+ <organization>redhat</organization>
+ <organizationUrl>http://www.redhat.com</organizationUrl>
+ </developer>
+ </developers>
+ <organization>
+ <name>Libvirt</name>
+ <url>https://libvirt.org/</url>
+ </organization>
<licenses>
<license>
<name>MIT license</name>
@@ -20,6 +32,8 @@
</licenses>
<scm>
<url>http://www.libvirt.org/git/?p=libvirt-java.git;a=summary</url>
+
<developerConnection>scm:git://libvirt.org/libvirt-java.git</developerConnection>
+ <connection>scm:git://libvirt.org/libvirt-java.git</connection>
</scm>
<dependencies>
--
1.9.3
9 years, 8 months
[libvirt] [PATCH] Fix virCgroupGetPercpuStats with non-continuous present CPUs
by Ján Tomko
Per-cpu stats are only shown for present CPUs in the cgroups,
but we were only parsing the largest CPU number from
/sys/devices/system/cpu/present and looking for stats even for
non-present CPUs.
This resulted in:
internal error: cpuacct parse error
---
cfg.mk | 2 +-
src/nodeinfo.c | 17 +++++++++++++++++
src/nodeinfo.h | 1 +
src/util/vircgroup.c | 24 ++++++++++++++++++------
tests/vircgroupmock.c | 44 ++++++++++++++++++++++++++++++++++++++------
tests/vircgrouptest.c | 47 +++++++++++++++++++++++++++++++++++------------
6 files changed, 110 insertions(+), 25 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 21f83c3..70612f8 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1095,7 +1095,7 @@ exclude_file_name_regexp--sc_prohibit_asprintf = \
^(bootstrap.conf$$|src/util/virstring\.[ch]$$|tests/vircgroupmock\.c$$)
exclude_file_name_regexp--sc_prohibit_strdup = \
- ^(docs/|examples/|src/util/virstring\.c|tests/virnetserverclientmock.c$$)
+ ^(docs/|examples/|src/util/virstring\.c|tests/vir(netserverclient|cgroup)mock.c$$)
exclude_file_name_regexp--sc_prohibit_close = \
(\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/virfile\.c|src/libvirt-stream\.c|tests/vir(cgroup|pci)mock\.c)$$)
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 3c22ebc..3a27c22 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -1242,6 +1242,23 @@ nodeGetCPUCount(void)
}
virBitmapPtr
+nodeGetPresentCPUBitmap(void)
+{
+ int max_present;
+
+ if ((max_present = nodeGetCPUCount()) < 0)
+ return NULL;
+
+#ifdef __linux__
+ if (virFileExists(SYSFS_SYSTEM_PATH "/cpu/present"))
+ return linuxParseCPUmap(max_present, SYSFS_SYSTEM_PATH "/cpu/present");
+#endif
+ virReportError(VIR_ERR_NO_SUPPORT, "%s",
+ _("non-continuous host cpu numbers not implemented on this platform"));
+ return NULL;
+}
+
+virBitmapPtr
nodeGetCPUBitmap(int *max_id ATTRIBUTE_UNUSED)
{
#ifdef __linux__
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
index a993c63..047bd5c 100644
--- a/src/nodeinfo.h
+++ b/src/nodeinfo.h
@@ -43,6 +43,7 @@ int nodeGetCellsFreeMemory(unsigned long long *freeMems,
int nodeGetMemory(unsigned long long *mem,
unsigned long long *freeMem);
+virBitmapPtr nodeGetPresentCPUBitmap(void);
virBitmapPtr nodeGetCPUBitmap(int *max_id);
int nodeGetCPUCount(void);
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index fe34290..e65617a 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2985,7 +2985,8 @@ static int
virCgroupGetPercpuVcpuSum(virCgroupPtr group,
unsigned int nvcpupids,
unsigned long long *sum_cpu_time,
- unsigned int num)
+ size_t nsum,
+ virBitmapPtr cpumap)
{
int ret = -1;
size_t i;
@@ -2995,7 +2996,7 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group,
for (i = 0; i < nvcpupids; i++) {
char *pos;
unsigned long long tmp;
- size_t j;
+ ssize_t j;
if (virCgroupNewVcpu(group, i, false, &group_vcpu) < 0)
goto cleanup;
@@ -3004,7 +3005,9 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group,
goto cleanup;
pos = buf;
- for (j = 0; j < num; j++) {
+ for (j = virBitmapNextSetBit(cpumap, -1);
+ j >= 0 && j < nsum;
+ j = virBitmapNextSetBit(cpumap, j)) {
if (virStrToLong_ull(pos, &pos, 10, &tmp) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cpuacct parse error"));
@@ -3042,6 +3045,7 @@ virCgroupGetPercpuStats(virCgroupPtr group,
virTypedParameterPtr ent;
int param_idx;
unsigned long long cpu_time;
+ virBitmapPtr cpumap = NULL;
/* return the number of supported params */
if (nparams == 0 && ncpus != 0) {
@@ -3052,9 +3056,11 @@ virCgroupGetPercpuStats(virCgroupPtr group,
}
/* To parse account file, we need to know how many cpus are present. */
- if ((total_cpus = nodeGetCPUCount()) < 0)
+ if (!(cpumap = nodeGetPresentCPUBitmap()))
return rv;
+ total_cpus = virBitmapSize(cpumap);
+
if (ncpus == 0)
return total_cpus;
@@ -3077,7 +3083,11 @@ virCgroupGetPercpuStats(virCgroupPtr group,
need_cpus = MIN(total_cpus, start_cpu + ncpus);
for (i = 0; i < need_cpus; i++) {
- if (virStrToLong_ull(pos, &pos, 10, &cpu_time) < 0) {
+ bool present;
+ ignore_value(virBitmapGetBit(cpumap, i, &present));
+ if (!present) {
+ cpu_time = 0;
+ } else if (virStrToLong_ull(pos, &pos, 10, &cpu_time) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cpuacct parse error"));
goto cleanup;
@@ -3097,7 +3107,8 @@ virCgroupGetPercpuStats(virCgroupPtr group,
if (VIR_ALLOC_N(sum_cpu_time, need_cpus) < 0)
goto cleanup;
- if (virCgroupGetPercpuVcpuSum(group, nvcpupids, sum_cpu_time, need_cpus) < 0)
+ if (virCgroupGetPercpuVcpuSum(group, nvcpupids, sum_cpu_time, need_cpus,
+ cpumap) < 0)
goto cleanup;
for (i = start_cpu; i < need_cpus; i++) {
@@ -3113,6 +3124,7 @@ virCgroupGetPercpuStats(virCgroupPtr group,
rv = param_idx + 1;
cleanup:
+ virBitmapFree(cpumap);
VIR_FREE(sum_cpu_time);
VIR_FREE(buf);
return rv;
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index 6e0a0e7..f2fee7d 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -51,6 +51,8 @@ const char *fakedevicedir1 = FAKEDEVDIR1;
# define SYSFS_PREFIX "/not/really/sys/fs/cgroup/"
+# define SYSFS_CPU_PRESENT "/sys/devices/system/cpu/present"
+# define SYSFS_CPU_PRESENT_MOCKED "devices_system_cpu_present"
/*
* The plan:
@@ -215,7 +217,15 @@ static int make_controller(const char *path, mode_t mode)
"user 216687025\n"
"system 43421396\n");
MAKE_FILE("cpuacct.usage", "2787788855799582\n");
- MAKE_FILE("cpuacct.usage_percpu", "1413142688153030 1374646168910542\n");
+ MAKE_FILE("cpuacct.usage_percpu",
+ "7059492996 0 0 0 0 0 0 0 4180532496 0 0 0 0 0 0 0 "
+ "1957541268 0 0 0 0 0 0 0 2065932204 0 0 0 0 0 0 0 "
+ "18228689414 0 0 0 0 0 0 0 4245525148 0 0 0 0 0 0 0 "
+ "2911161568 0 0 0 0 0 0 0 1407758136 0 0 0 0 0 0 0 "
+ "1836807700 0 0 0 0 0 0 0 1065296618 0 0 0 0 0 0 0 "
+ "2046213266 0 0 0 0 0 0 0 747889778 0 0 0 0 0 0 0 "
+ "709566900 0 0 0 0 0 0 0 444777342 0 0 0 0 0 0 0 "
+ "5683512916 0 0 0 0 0 0 0 635751356 0 0 0 0 0 0 0\n");
} else if (STRPREFIX(controller, "cpuset")) {
MAKE_FILE("cpuset.cpu_exclusive", "1\n");
if (STREQ(controller, "cpuset"))
@@ -431,6 +441,9 @@ static void init_sysfs(void)
MAKE_CONTROLLER("blkio");
MAKE_CONTROLLER("memory");
MAKE_CONTROLLER("freezer");
+
+ if (make_file(fakesysfsdir, SYSFS_CPU_PRESENT_MOCKED, "8-23,48-159\n") < 0)
+ abort();
}
@@ -623,21 +636,27 @@ int __xstat(int ver, const char *path, struct stat *sb)
int stat(const char *path, struct stat *sb)
{
+ char *newpath = NULL;
int ret;
init_syms();
- if (STRPREFIX(path, SYSFS_PREFIX)) {
+ if (STREQ(path, SYSFS_CPU_PRESENT)) {
+ init_sysfs();
+ if (asprintf(&newpath, "%s/%s",
+ fakesysfsdir,
+ SYSFS_CPU_PRESENT_MOCKED) < 0) {
+ errno = ENOMEM;
+ return -1;
+ }
+ } else if (STRPREFIX(path, SYSFS_PREFIX)) {
init_sysfs();
- char *newpath;
if (asprintf(&newpath, "%s/%s",
fakesysfsdir,
path + strlen(SYSFS_PREFIX)) < 0) {
errno = ENOMEM;
return -1;
}
- ret = realstat(newpath, sb);
- free(newpath);
} else if (STRPREFIX(path, fakedevicedir0)) {
sb->st_mode = S_IFBLK;
sb->st_rdev = makedev(8, 0);
@@ -647,8 +666,11 @@ int stat(const char *path, struct stat *sb)
sb->st_rdev = makedev(9, 0);
return 0;
} else {
- ret = realstat(path, sb);
+ if (!(newpath = strdup(path)))
+ return -1;
}
+ ret = realstat(newpath, sb);
+ free(newpath);
return ret;
}
@@ -682,6 +704,16 @@ int open(const char *path, int flags, ...)
init_syms();
+ if (STREQ(path, SYSFS_CPU_PRESENT)) {
+ init_sysfs();
+ if (asprintf(&newpath, "%s/%s",
+ fakesysfsdir,
+ SYSFS_CPU_PRESENT_MOCKED) < 0) {
+ errno = ENOMEM;
+ return -1;
+ }
+ }
+
if (STRPREFIX(path, SYSFS_PREFIX)) {
init_sysfs();
if (asprintf(&newpath, "%s/%s",
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 35ac0c0..b65ea3f 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -538,12 +538,35 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED)
virCgroupPtr cgroup = NULL;
size_t i;
int rv, ret = -1;
- virTypedParameter params[2];
+ virTypedParameterPtr params = NULL;
+# define EXPECTED_NCPUS 160
- // TODO: mock nodeGetCPUCount() as well & check 2nd cpu, too
unsigned long long expected[] = {
- 1413142688153030ULL
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 7059492996, 0, 0, 0, 0, 0, 0, 0,
+ 4180532496, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 1957541268, 0, 0, 0, 0, 0, 0, 0,
+ 2065932204, 0, 0, 0, 0, 0, 0, 0,
+ 18228689414, 0, 0, 0, 0, 0, 0, 0,
+ 4245525148, 0, 0, 0, 0, 0, 0, 0,
+ 2911161568, 0, 0, 0, 0, 0, 0, 0,
+ 1407758136, 0, 0, 0, 0, 0, 0, 0,
+ 1836807700, 0, 0, 0, 0, 0, 0, 0,
+ 1065296618, 0, 0, 0, 0, 0, 0, 0,
+ 2046213266, 0, 0, 0, 0, 0, 0, 0,
+ 747889778, 0, 0, 0, 0, 0, 0, 0,
+ 709566900, 0, 0, 0, 0, 0, 0, 0,
+ 444777342, 0, 0, 0, 0, 0, 0, 0,
+ 5683512916, 0, 0, 0, 0, 0, 0, 0,
+ 635751356, 0, 0, 0, 0, 0, 0, 0,
};
+ verify(ARRAY_CARDINALITY(expected) == EXPECTED_NCPUS);
+
+ if (VIR_ALLOC_N(params, EXPECTED_NCPUS) < 0)
+ goto cleanup;
if ((rv = virCgroupNewPartition("/virtualmachines", true,
(1 << VIR_CGROUP_CONTROLLER_CPU) |
@@ -553,37 +576,37 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED)
goto cleanup;
}
- if (nodeGetCPUCount() < 1) {
+ if (nodeGetCPUCount() != EXPECTED_NCPUS) {
fprintf(stderr, "Unexpected: nodeGetCPUCount() yields: %d\n", nodeGetCPUCount());
goto cleanup;
}
if ((rv = virCgroupGetPercpuStats(cgroup,
params,
- 2, 0, 1, 0)) < 0) {
+ 1, 0, EXPECTED_NCPUS, 0)) < 0) {
fprintf(stderr, "Failed call to virCgroupGetPercpuStats for /virtualmachines cgroup: %d\n", -rv);
goto cleanup;
}
- for (i = 0; i < ARRAY_CARDINALITY(expected); i++) {
+ for (i = 0; i < EXPECTED_NCPUS; i++) {
if (!STREQ(params[i].field, VIR_DOMAIN_CPU_STATS_CPUTIME)) {
fprintf(stderr,
- "Wrong parameter name value from virCgroupGetPercpuStats (is: %s)\n",
- params[i].field);
+ "Wrong parameter name value from virCgroupGetPercpuStats at %zu (is: %s)\n",
+ i, params[i].field);
goto cleanup;
}
if (params[i].type != VIR_TYPED_PARAM_ULLONG) {
fprintf(stderr,
- "Wrong parameter value type from virCgroupGetPercpuStats (is: %d)\n",
- params[i].type);
+ "Wrong parameter value type from virCgroupGetPercpuStats at %zu (is: %d)\n",
+ i, params[i].type);
goto cleanup;
}
if (params[i].value.ul != expected[i]) {
fprintf(stderr,
- "Wrong value from virCgroupGetMemoryUsage (expected %llu)\n",
- params[i].value.ul);
+ "Wrong value from virCgroupGetMemoryUsage at %zu (expected %llu)\n",
+ i, params[i].value.ul);
goto cleanup;
}
}
--
2.0.4
9 years, 8 months
[libvirt] [PATCH] tests: fix build on old 32-bit platforms
by Eric Blake
gcc 4.1.2 (hello RHEL 5) on 32-bit platforms complains:
vircgrouptest.c: In function 'testCgroupGetPercpuStats':
vircgrouptest.c:627: warning: integer constant is too large for 'long' type
vircgrouptest.c:628: warning: this decimal constant is unsigned only in ISO C90
vircgrouptest.c:634: warning: integer constant is too large for 'long' type
vircgrouptest.c:635: warning: this decimal constant is unsigned only in ISO C90
vircgrouptest.c:636: warning: this decimal constant is unsigned only in ISO C90
vircgrouptest.c:644: warning: integer constant is too large for 'long' type
* tests/vircgrouptest.c (testCgroupGetPercpuStats): Use ULL suffix.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Pushing under the build-breaker rule
tests/vircgrouptest.c | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 2b30258..ad49425 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2014 Red Hat, Inc.
+ * Copyright (C) 2013-2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -624,25 +624,25 @@ static int testCgroupGetPercpuStats(const void *args ATTRIBUTE_UNUSED)
unsigned long long expected[EXPECTED_NCPUS] = {
0, 0, 0, 0, 0, 0, 0, 0,
- 7059492996, 0, 0, 0, 0, 0, 0, 0,
- 4180532496, 0, 0, 0, 0, 0, 0, 0,
+ 7059492996ULL, 0, 0, 0, 0, 0, 0, 0,
+ 4180532496ULL, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
- 1957541268, 0, 0, 0, 0, 0, 0, 0,
- 2065932204, 0, 0, 0, 0, 0, 0, 0,
- 18228689414, 0, 0, 0, 0, 0, 0, 0,
- 4245525148, 0, 0, 0, 0, 0, 0, 0,
- 2911161568, 0, 0, 0, 0, 0, 0, 0,
- 1407758136, 0, 0, 0, 0, 0, 0, 0,
- 1836807700, 0, 0, 0, 0, 0, 0, 0,
- 1065296618, 0, 0, 0, 0, 0, 0, 0,
- 2046213266, 0, 0, 0, 0, 0, 0, 0,
- 747889778, 0, 0, 0, 0, 0, 0, 0,
- 709566900, 0, 0, 0, 0, 0, 0, 0,
- 444777342, 0, 0, 0, 0, 0, 0, 0,
- 5683512916, 0, 0, 0, 0, 0, 0, 0,
- 635751356, 0, 0, 0, 0, 0, 0, 0,
+ 1957541268ULL, 0, 0, 0, 0, 0, 0, 0,
+ 2065932204ULL, 0, 0, 0, 0, 0, 0, 0,
+ 18228689414ULL, 0, 0, 0, 0, 0, 0, 0,
+ 4245525148ULL, 0, 0, 0, 0, 0, 0, 0,
+ 2911161568ULL, 0, 0, 0, 0, 0, 0, 0,
+ 1407758136ULL, 0, 0, 0, 0, 0, 0, 0,
+ 1836807700ULL, 0, 0, 0, 0, 0, 0, 0,
+ 1065296618ULL, 0, 0, 0, 0, 0, 0, 0,
+ 2046213266ULL, 0, 0, 0, 0, 0, 0, 0,
+ 747889778ULL, 0, 0, 0, 0, 0, 0, 0,
+ 709566900ULL, 0, 0, 0, 0, 0, 0, 0,
+ 444777342ULL, 0, 0, 0, 0, 0, 0, 0,
+ 5683512916ULL, 0, 0, 0, 0, 0, 0, 0,
+ 635751356ULL, 0, 0, 0, 0, 0, 0, 0,
};
if (VIR_ALLOC_N(params, EXPECTED_NCPUS) < 0)
--
2.1.0
9 years, 8 months