[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
13 years, 11 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
13 years, 11 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
13 years, 11 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
13 years, 11 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
13 years, 11 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
13 years, 11 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
13 years, 11 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
13 years, 11 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
13 years, 11 months
[libvirt] [libvirt PATCH] 802.1Qbh: Add support for IFLA_VF_MAC
by Roopa Prabhu
From: Roopa Prabhu <roprabhu(a)cisco.com>
Current code does not pass VM mac address to a 802.1Qbh direct attach
interface using IFLA_VF_MAC. This patch adds support in macvtap code to
send IFLA_VF_MAC netlink request during port profile association on a
802.1Qbh interface.
Stefan Cc'ed for comments because this patch changes a condition for
802.1Qbg
802.1Qbh support for IFLA_VF_MAC in enic driver has been posted and is
pending acceptance at http://marc.info/?l=linux-netdev&m=129185244410557&w=2
Signed-off-by: Roopa Prabhu <roprabhu(a)cisco.com>
Signed-off-by: David Wang <dwang2(a)cisco.com>
Signed-off-by: Christian Benvenuti <benve(a)cisco.com>
---
src/util/macvtap.c | 59 ++++++++++++++++++++++++++++------------------------
1 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/src/util/macvtap.c b/src/util/macvtap.c
index 4345d97..96df301 100644
--- a/src/util/macvtap.c
+++ b/src/util/macvtap.c
@@ -1031,19 +1031,8 @@ doPortProfileOpSetLink(bool nltarget_kernel,
nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
goto buffer_too_small;
- if (macaddr && vlanid >= 0) {
+ if (macaddr || vlanid >= 0) {
struct nlattr *vfinfolist, *vfinfo;
- struct ifla_vf_mac ifla_vf_mac = {
- .vf = vf,
- .mac = { 0, },
- };
- struct ifla_vf_vlan ifla_vf_vlan = {
- .vf = vf,
- .vlan = vlanid,
- .qos = 0,
- };
-
- memcpy(ifla_vf_mac.mac, macaddr, 6);
if (!(vfinfolist = nla_nest_start(nl_msg, IFLA_VFINFO_LIST)))
goto buffer_too_small;
@@ -1051,13 +1040,30 @@ doPortProfileOpSetLink(bool nltarget_kernel,
if (!(vfinfo = nla_nest_start(nl_msg, IFLA_VF_INFO)))
goto buffer_too_small;
- if (!nla_put(nl_msg, IFLA_VF_MAC, sizeof(ifla_vf_mac),
- &ifla_vf_mac) < 0)
- goto buffer_too_small;
+ if (macaddr) {
+ struct ifla_vf_mac ifla_vf_mac = {
+ .vf = vf,
+ .mac = { 0, },
+ };
- if (!nla_put(nl_msg, IFLA_VF_VLAN, sizeof(ifla_vf_vlan),
- &ifla_vf_vlan) < 0)
- goto buffer_too_small;
+ memcpy(ifla_vf_mac.mac, macaddr, 6);
+
+ if (!nla_put(nl_msg, IFLA_VF_MAC, sizeof(ifla_vf_mac),
+ &ifla_vf_mac) < 0)
+ goto buffer_too_small;
+ }
+
+ if (vlanid >= 0) {
+ struct ifla_vf_vlan ifla_vf_vlan = {
+ .vf = vf,
+ .vlan = vlanid,
+ .qos = 0,
+ };
+
+ if (!nla_put(nl_msg, IFLA_VF_VLAN, sizeof(ifla_vf_vlan),
+ &ifla_vf_vlan) < 0)
+ goto buffer_too_small;
+ }
nla_nest_end(nl_msg, vfinfo);
nla_nest_end(nl_msg, vfinfolist);
@@ -1402,6 +1408,7 @@ getPhysfn(const char *linkdev,
static int
doPortProfileOp8021Qbh(const char *ifname,
+ const unsigned char *macaddr,
const virVirtualPortProfileParamsPtr virtPort,
const unsigned char *vm_uuid,
enum virVirtualPortOp virtPortOp)
@@ -1411,6 +1418,7 @@ doPortProfileOp8021Qbh(const char *ifname,
# ifndef IFLA_VF_PORT_MAX
(void)ifname;
+ (void)macaddr;
(void)virtPort;
(void)vm_uuid;
(void)virtPortOp;
@@ -1426,7 +1434,6 @@ doPortProfileOp8021Qbh(const char *ifname,
bool nltarget_kernel = true;
int ifindex;
int vlanid = -1;
- const unsigned char *macaddr = NULL;
rc = getPhysfn(ifname, &vf, &physfndev);
if (rc)
@@ -1456,7 +1463,7 @@ doPortProfileOp8021Qbh(const char *ifname,
/* Association timed out, disassociate */
doPortProfileOpCommon(nltarget_kernel, NULL, ifindex,
NULL,
- 0,
+ vlanid,
NULL,
NULL,
NULL,
@@ -1470,7 +1477,7 @@ doPortProfileOp8021Qbh(const char *ifname,
case DISASSOCIATE:
rc = doPortProfileOpCommon(nltarget_kernel, NULL, ifindex,
NULL,
- 0,
+ vlanid,
NULL,
NULL,
NULL,
@@ -1545,9 +1552,8 @@ vpAssociatePortProfileId(const char *macvtap_ifname,
/* avoid associating twice */
if (vmOp == VIR_VM_OP_MIGRATE_IN_FINISH)
break;
- rc = doPortProfileOp8021Qbh(linkdev, virtPort,
- vmuuid,
- ASSOCIATE);
+ rc = doPortProfileOp8021Qbh(linkdev, macvtap_macaddr,
+ virtPort, vmuuid, ASSOCIATE);
break;
}
@@ -1594,9 +1600,8 @@ vpDisassociatePortProfileId(const char *macvtap_ifname,
/* avoid disassociating twice */
if (vmOp == VIR_VM_OP_MIGRATE_IN_FINISH)
break;
- rc = doPortProfileOp8021Qbh(linkdev, virtPort,
- NULL,
- DISASSOCIATE);
+ rc = doPortProfileOp8021Qbh(linkdev, macvtap_macaddr,
+ virtPort, NULL, DISASSOCIATE);
break;
}
13 years, 11 months