[libvirt] [PATCH] tests: avoid spurious failure of nodeinfotest
by Eric Blake
When running 'make check' under a multi-cpu Dom0 xen machine,
nodeinfotest had a spurious failure it was reading from
/sys/devices/system/cpu, but xen has no notion of topology. The test
was intended to be isolated from reading any real system files; the
regression was introduced in Mar 2010 with commit aa2f6f96dd.
Fix things by allowing an early exit for the testsuite.
* src/nodeinfo.c (linuxNodeInfoCPUPopulate): Add parameter.
(nodeGetInfo): Adjust caller.
* tests/nodeinfotest.c (linuxTestCompareFiles): Likewise.
---
src/nodeinfo.c | 11 ++++++++---
tests/nodeinfotest.c | 5 +++--
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index acd3188..22d53e5 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -61,7 +61,8 @@
/* NB, this is not static as we need to call it from the testsuite */
int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
- virNodeInfoPtr nodeinfo);
+ virNodeInfoPtr nodeinfo,
+ bool need_hyperthreads);
/* Return the positive decimal contents of the given
* CPU_SYS_PATH/cpu%u/FILE, or -1 on error. If MISSING_OK and the
@@ -167,7 +168,8 @@ static int parse_socket(unsigned int cpu)
}
int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
- virNodeInfoPtr nodeinfo)
+ virNodeInfoPtr nodeinfo,
+ bool need_hyperthreads)
{
char line[1024];
DIR *cpudir = NULL;
@@ -244,6 +246,9 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
return -1;
}
+ if (!need_hyperthreads)
+ return 0;
+
/* OK, we've parsed what we can out of /proc/cpuinfo. Get the socket
* and thread information from /sys
*/
@@ -338,7 +343,7 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) {
_("cannot open %s"), CPUINFO_PATH);
return -1;
}
- ret = linuxNodeInfoCPUPopulate(cpuinfo, nodeinfo);
+ ret = linuxNodeInfoCPUPopulate(cpuinfo, nodeinfo, true);
VIR_FORCE_FCLOSE(cpuinfo);
if (ret < 0)
return -1;
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index f56247b..c690403 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -26,7 +26,8 @@ static char *abs_srcdir;
# define MAX_FILE 4096
-extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, virNodeInfoPtr nodeinfo);
+extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, virNodeInfoPtr nodeinfo,
+ bool need_hyperthreads);
static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) {
char actualData[MAX_FILE];
@@ -43,7 +44,7 @@ static int linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile
return -1;
memset(&nodeinfo, 0, sizeof(nodeinfo));
- if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo) < 0) {
+ if (linuxNodeInfoCPUPopulate(cpuinfo, &nodeinfo, false) < 0) {
if (virTestGetDebug()) {
virErrorPtr error = virSaveLastError();
if (error && error->code != VIR_ERR_OK)
--
1.7.3.3
14 years, 5 months
[libvirt] [PATCH] tests: avoid data race
by Eric Blake
I got some spurious failures when commandhelper won the race and
ran to the point of parent detection prior to the intermediate
daemonizing process getting a chance to exit. This fixes it.
* tests/commandhelper.c (main): Checking for re-parenting to
init(1) is racy; instead check that we belong to a new session.
---
tests/commandhelper.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 5b2f301..f400e8d 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -95,7 +95,7 @@ int main(int argc, char **argv) {
fprintf(log, "FD:%d\n", i);
}
- fprintf(log, "DAEMON:%s\n", getppid() == 1 ? "yes" : "no");
+ fprintf(log, "DAEMON:%s\n", getpgrp() == getsid(0) ? "yes" : "no");
char cwd[1024];
if (!getcwd(cwd, sizeof(cwd)))
return EXIT_FAILURE;
--
1.7.3.3
14 years, 5 months
[libvirt] How to detect if a PCI device is in use?
by Osier Yang
Hi, all
As the $subject says, currently we don't check whether the
PCI device is in use or not by guest when reattaching it
to host, it causes problems, should we prevent reattaching
if the device is in use? if yes, how to detect whether the
device is in use or not?
The easiest way in my mind is to check if the device is bound
to some driver by check if symbol link "driver"
(e.g. /sys/bus/pci/devices/0000\:00\:1f.2/) exists, but it's
not reasonable, as even if the device is bound to some driver,
it probly is not in use by guest, e.g.
1) attach PCI device to guest (non-managed)
2) destroy the guest without detaching the device first
3) reattach the PCI device to host
It will be success, and should be success, as it's not used
by any stuff, though it's bound to driver ("pci-stub" for qemu,
"pciback" for xen).
And it seems we can't do any futher lookup to see if the device
is in use or not via sysfs.
Any idea?
Thanks
Osier
14 years, 5 months
[libvirt] [PATCH v2 2/2] auto cold migration fallback at timeout
by Wen Congyang
implement auto cold migration fallback at timeout
Signed-off-by: Wen Congyang <wency(a)cn.fujitsu.com>
---
tools/virsh.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 4e37f2d..794b97a 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -54,6 +54,7 @@
#include "files.h"
#include "../daemon/event.h"
#include "configmake.h"
+#include "timer.h"
static char *progname;
@@ -3378,9 +3379,32 @@ static const vshCmdOptDef opts_migrate[] = {
{"desturi", VSH_OT_DATA, VSH_OFLAG_REQ, N_("connection URI of the destination host")},
{"migrateuri", VSH_OT_DATA, 0, N_("migration URI, usually can be omitted")},
{"dname", VSH_OT_DATA, 0, N_("rename to new name during migration (if supported)")},
+ {"timeout", VSH_OT_INT, 0, N_("auto cold migration fallback when live migration timeouts(in seconds)")},
{NULL, 0, 0, NULL}
};
+static void migrateTimeoutHandler(void *data)
+{
+ virDomainPtr dom = (virDomainPtr)data;
+ virDomainInfo info;
+ unsigned int id;
+
+ id = virDomainGetID(dom);
+ if (id == ((unsigned int)-1))
+ return;
+
+ /* The error reason has been reported in virDomainGetInfo() and
+ * virDomainSuspend() when it fails. So we do not check the return value.
+ */
+ if (virDomainGetInfo(dom, &info) == 0) {
+ if (info.state == VIR_DOMAIN_SHUTOFF)
+ return;
+
+ /* suspend the domain when migration timeouts. */
+ virDomainSuspend(dom);
+ }
+}
+
static int
cmdMigrate (vshControl *ctl, const vshCmd *cmd)
{
@@ -3388,6 +3412,8 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
const char *desturi;
const char *migrateuri;
const char *dname;
+ long long timeout;
+ virTimerPtr migratetimer = NULL;
int flags = 0, found, ret = FALSE;
if (!vshConnectionUsability (ctl, ctl->conn))
@@ -3425,6 +3451,23 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool (cmd, "copy-storage-inc"))
flags |= VIR_MIGRATE_NON_SHARED_INC;
+ timeout = vshCommandOptLongLong(cmd, "timeout", &found);
+ if (found) {
+ if (! flags & VIR_MIGRATE_LIVE) {
+ vshError(ctl, "%s", _("migrate: Unexpected timeout for cold migration"));
+ goto done;
+ }
+
+ if (timeout < 1) {
+ vshError(ctl, "%s", _("migrate: Invalid timeout"));
+ goto done;
+ }
+
+ migratetimer = virNewTimer(migrateTimeoutHandler, (void *)dom);
+ if (!migratetimer)
+ goto done;
+ }
+
if ((flags & VIR_MIGRATE_PEER2PEER) ||
vshCommandOptBool (cmd, "direct")) {
/* For peer2peer migration or direct migration we only expect one URI
@@ -3435,6 +3478,9 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
goto done;
}
+ if (migratetimer)
+ virModTimer(migratetimer, get_clock() + timeout * 1000000000ULL);
+
if (virDomainMigrateToURI (dom, desturi, flags, dname, 0) == 0)
ret = TRUE;
} else {
@@ -3445,6 +3491,9 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
dconn = virConnectOpenAuth (desturi, virConnectAuthPtrDefault, 0);
if (!dconn) goto done;
+ if (migratetimer)
+ virModTimer(migratetimer, get_clock() + timeout * 1000000000ULL);
+
ddom = virDomainMigrate (dom, dconn, flags, dname, migrateuri, 0);
if (ddom) {
virDomainFree(ddom);
@@ -3454,6 +3503,10 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
}
done:
+ if (migratetimer) {
+ virDelTimer(migratetimer);
+ virFreeTimer(migratetimer);
+ }
if (dom) virDomainFree (dom);
return ret;
}
--
1.7.1
14 years, 5 months
[libvirt] [Patch v2 0/2] Add new feature into live migration
by Wen Congyang
If the memory of guest OS is changed constantly, the live migration
can not be ended ever for ever.
We can use the command 'virsh migrate-setmaxdowntime' to control the
live migration. But the value of maxdowntime is diffcult to calculate
because it depends on the transfer speed of network and constantly
changing memroy size. We need a easy way to control the live migration.
This patch set add the support of auto cold migration fallback on
timeout. With this patch set, when we migrate the guest OS, we can
specify a timeout. If the live migration timeouts, the migration will
fallback to cold migration.
Test of this patchset on Linux:
Env:
a. The size of guest OS's memory: 1GB
b. The transfer speed of network: about 100Mb/s
c. The size of constantly changing memory: more than 900MB
1. migrate without timeout
# virsh migrate --live RHEL6RC qemu+ssh://<dest IP>/system tcp://<dest IP>:49152
The migration does not end after 12 hours.
2. migrate with timeout(30 minutes):
# date
Wed Dec 15 09:39:23 CST 2010
# virsh migrate --live --timeout 1800 RHEL6RC qemu+ssh://<dest IP>/system tcp:<dest IP>:49152
# date
Wed Dec 15 10:09:52 CST 2010
This patchset is not tested on Windows(I have no such environment).
v2:
- implemente timer for Windows
- implemente dynamic timers
Wen Congyang (2):
timer impl
auto cold migration fallback at timeout
configure.ac | 4 +
src/Makefile.am | 6 +-
src/libvirt.c | 2 +
src/libvirt_private.syms | 6 ++
src/util/timer.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++
src/util/timer.h | 37 ++++++++++
src/util/timer_linux.c | 130 ++++++++++++++++++++++++++++++++++++
src/util/timer_win32.c | 128 +++++++++++++++++++++++++++++++++++
tools/virsh.c | 53 +++++++++++++++
9 files changed, 530 insertions(+), 2 deletions(-)
create mode 100644 src/util/timer.c
create mode 100644 src/util/timer.h
create mode 100644 src/util/timer_linux.c
create mode 100644 src/util/timer_win32.c
14 years, 5 months
[libvirt] [PATCH] build: improve testsuite results with older automake
by Eric Blake
* tests/Makefile.am (TESTS_ENVIRONMENT, commandtest_CFLAGS)
(commandhelper_CFLAGS): Avoid $(builddir) and $(abs_builddir) in
automake 1.9.6; fixes spurious failures of commandtest.
---
tests/Makefile.am | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0a235cf..07df5a1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -206,12 +206,12 @@ TESTS += cputest
path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/daemon$(PATH_SEPARATOR)$$abs_top_builddir/tools
# NB, automake < 1.10 does not provide the real
-# abs_top_{src/build}dir variables, so don't rely
+# abs_top_{src/build}dir or builddir variables, so don't rely
# on them here. Fake them with 'pwd'
TESTS_ENVIRONMENT = \
abs_top_builddir=`cd '$(top_builddir)'; pwd` \
abs_top_srcdir=`cd '$(top_srcdir)'; pwd` \
- abs_builddir=`cd '$(builddir)'; pwd` \
+ abs_builddir=`pwd` \
abs_srcdir=`cd '$(srcdir)'; pwd` \
CONFIG_HEADER="`cd '$(top_builddir)'; pwd`/config.h" \
PATH="$(path_add)$(PATH_SEPARATOR)$$PATH" \
@@ -353,12 +353,12 @@ nodeinfotest_LDADD = $(LDADDS)
commandtest_SOURCES = \
commandtest.c testutils.h testutils.c
-commandtest_CFLAGS = -Dabs_builddir="\"$(abs_builddir)\""
+commandtest_CFLAGS = -Dabs_builddir="\"`pwd`\""
commandtest_LDADD = $(LDADDS)
commandhelper_SOURCES = \
commandhelper.c
-commandhelper_CFLAGS = -Dabs_builddir="\"$(abs_builddir)\""
+commandhelper_CFLAGS = -Dabs_builddir="\"`pwd`\""
commandhelper_LDADD = $(LDADDS)
if WITH_SECDRIVER_SELINUX
--
1.7.3.3
14 years, 5 months
[libvirt] [PATCH] qemu: plug memory leak
by Eric Blake
https://bugzilla.redhat.com/show_bug.cgi?id=656795
* src/qemu/qemu_monitor.c (qemuMonitorFree): Also free the buffer.
---
src/qemu/qemu_monitor.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 86ed82f..85d0d0f 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -199,6 +199,7 @@ static void qemuMonitorFree(qemuMonitorPtr mon)
if (virCondDestroy(&mon->notify) < 0)
{}
virMutexDestroy(&mon->lock);
+ VIR_FREE(mon->buffer);
VIR_FREE(mon);
}
--
1.7.3.2
14 years, 5 months
[libvirt] [PATCH 1/2] build: properly handle ./configure --with-libpcap
by Diego Elio Pettenò
Without this fix, ./configure --with-libpcap will cause --with-libpcap=yes
to be implicitly passed down, which cause yes/bin/pcap-config to be
searched for rather than /usr/bin/pcap-config.
Also output pcap: no when pcap is not found or disabled.
---
configure.ac | 30 ++++++++++++++++--------------
1 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/configure.ac b/configure.ac
index d8be160..b5c995f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1194,20 +1194,22 @@ LIBPCAP_FOUND="no"
AC_ARG_WITH([libpcap], AC_HELP_STRING([--with-libpcap=@<:@PFX@:>@], [libpcap location]))
if test "$with_qemu" = "yes"; then
- if test "x$with_libpcap" != "xno" ; then
- if test "x$with_libpcap" != "x" ; then
- LIBPCAP_CONFIG=$with_libpcap/bin/$LIBPCAP_CONFIG
- fi
- AC_MSG_CHECKING(libpcap $LIBPCAP_CONFIG >= $LIBPCAP_REQUIRED )
- if ! $LIBPCAP_CONFIG --libs > /dev/null 2>&1 ; then
- AC_MSG_RESULT(no)
- else
- LIBPCAP_LIBS="`$LIBPCAP_CONFIG --libs`"
- LIBPCAP_CFLAGS="`$LIBPCAP_CONFIG --cflags`"
- LIBPCAP_FOUND="yes"
- AC_MSG_RESULT(yes)
- fi
+ AS_CASE(["x$with_libpcap"],
+ [xno], [LIBPCAP_CONFIG=""],
+ [x|xyes], [LIBPCAP_CONFIG="pcap-config"],
+ [LIBPCAP_CONFIG="$with_libpcap/bin/pcap-config"]
+ )
+ AS_IF([test "x$LIBPCAP_CONFIG" != "x"], [
+ AC_MSG_CHECKING(libpcap $LIBPCAP_CONFIG >= $LIBPCAP_REQUIRED )
+ if ! $LIBPCAP_CONFIG --libs > /dev/null 2>&1 ; then
+ AC_MSG_RESULT(no)
+ else
+ LIBPCAP_LIBS="`$LIBPCAP_CONFIG --libs`"
+ LIBPCAP_CFLAGS="`$LIBPCAP_CONFIG --cflags`"
+ LIBPCAP_FOUND="yes"
+ AC_MSG_RESULT(yes)
fi
+ ])
fi
if test "x$LIBPCAP_FOUND" = "xyes"; then
@@ -2406,7 +2408,7 @@ AC_MSG_NOTICE([ xmlrpc: $XMLRPC_CFLAGS $XMLRPC_LIBS])
else
AC_MSG_NOTICE([ xmlrpc: no])
fi
-if test "$with_qemu" = "yes" ; then
+if test "$with_qemu" = "yes" -a "$LIBPCAP_FOUND" != "no"; then
AC_MSG_NOTICE([ pcap: $LIBPCAP_CFLAGS $LIBPCAP_LIBS])
else
AC_MSG_NOTICE([ pcap: no])
--
1.7.3.3
14 years, 5 months
[libvirt] libvirt-guests output
by Laurent Léonard
Hi,
Here is an example of libvirt-guest output:
$Running guests on default URI: test-vm
$Suspending guests on default URI...
$Suspending test-vm: $done
Why all the lines begin with "$" ?
Thank you,
--
Laurent Léonard
14 years, 5 months
[libvirt] [PATCH 0/3] Makes the code more compact
by Hu Tao
These three patches introduce two new functions and one macro
respectively, which make the code clean and compact.
Hu Tao (3):
Add a macro timeval_to_ms to compute micro seconds from timeval
Add a new function doStopCPUs
Add a new function doStartCPUs
src/qemu/qemu_driver.c | 151 ++++++++++++++++++------------------------------
1 files changed, 57 insertions(+), 94 deletions(-)
--
1.7.3
--
Thanks,
Hu Tao
14 years, 5 months