[libvirt] [Patch v3 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
Fri Dec 17 15:35:24 CST 2010
# virsh migrate --live --timeout 1800 RHEL6RC qemu+ssh://<dest IP>/system tcp:<dest IP>:49152
# date
Fri Dec 17 16:05:51 CST 2010
v3:
- use the existing virEventXXXTimeout() APT to implement timer
v2:
- implement timer for Windows
- implement dynamic timers
Wen Congyang (2):
timer impl
auto cold migration fallback at timeout
tools/Makefile.am | 1 +
tools/timer.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/timer.h | 38 ++++++++++++
tools/virsh.c | 69 +++++++++++++++++++++
4 files changed, 278 insertions(+), 0 deletions(-)
create mode 100644 tools/timer.c
create mode 100644 tools/timer.h
14 years
[libvirt] [C# bindings] [PATCH]
by arnaud.champion@devatom.fr
?Hi there,
a long time since some update for C# bindings, sorry, I'm a little busy.
Anyway here are some patches that correct marshaling around network functions, and as usual a new sample code related to network functions.
Regards,
Arnaud
14 years
[libvirt] [PATCH] maint: improve tests distribution
by Eric Blake
* tests/Makefile.am (EXTRA_DIST): Sort, and add directories.
(SUBDIRS): Drop automake recursion into subdirs.
* tests/commanddata/Makefile.am: Delete.
* tests/confdata/Makefile.am: Likewise.
* tests/sexpr2xmldata/Makefile.am: Likewise.
* tests/xencapsdata/Makefile.am: Likewise.
* tests/xmconfigdata/Makefile.am: Likewise.
* tests/xml2sexprdata/Makefile.am: Likewise.
---
This deletes more than it adds; the worst part of the diff is that I
mixed sorting with addition. Let me know if you want those actions
split into two pieces for easier review.
configure.ac | 6 ----
tests/Makefile.am | 57 ++++++++++++++++++++------------------
tests/commanddata/Makefile.am | 2 -
tests/confdata/Makefile.am | 2 -
tests/sexpr2xmldata/Makefile.am | 2 -
tests/xencapsdata/Makefile.am | 3 --
tests/xmconfigdata/Makefile.am | 2 -
tests/xml2sexprdata/Makefile.am | 2 -
8 files changed, 30 insertions(+), 46 deletions(-)
delete mode 100644 tests/commanddata/Makefile.am
delete mode 100644 tests/confdata/Makefile.am
delete mode 100644 tests/sexpr2xmldata/Makefile.am
delete mode 100644 tests/xencapsdata/Makefile.am
delete mode 100644 tests/xmconfigdata/Makefile.am
delete mode 100644 tests/xml2sexprdata/Makefile.am
diff --git a/configure.ac b/configure.ac
index 64e76dc..a52a03c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2251,12 +2251,6 @@ AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
daemon/Makefile \
tools/Makefile \
tests/Makefile \
- tests/xml2sexprdata/Makefile \
- tests/sexpr2xmldata/Makefile \
- tests/xmconfigdata/Makefile \
- tests/xencapsdata/Makefile \
- tests/confdata/Makefile \
- tests/commanddata/Makefile \
examples/apparmor/Makefile \
examples/domain-events/events-c/Makefile \
examples/domsuspend/Makefile \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0a235cf..de2ff91 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,9 +2,6 @@
SHELL = $(PREFERABLY_POSIX_SHELL)
-SUBDIRS = commanddata confdata sexpr2xmldata \
- xml2sexprdata xmconfigdata xencapsdata
-
INCLUDES = \
-I$(top_srcdir)/gnulib/lib -I../gnulib/lib \
-I$(top_builddir)/include \
@@ -39,38 +36,44 @@ LDADDS = \
$(COVERAGE_LDFLAGS)
EXTRA_DIST = \
- oomtrace.pl \
- test-lib.sh \
- qemuxml2argvdata \
- qemuxml2xmloutdata \
- nodeinfodata \
- schematestutils.sh \
- capabilityschematest \
capabilityschemadata \
- networkschematest \
- networkxml2xmlout \
- networkxml2xmlin \
- domainschematest \
+ capabilityschematest \
+ commanddata \
+ confdata \
+ cputestdata \
domainschemadata \
+ domainschematest \
+ domainsnapshotschematest \
+ domainsnapshotxml2xmlin \
+ domainsnapshotxml2xmlout \
interfaceschemadata \
+ networkschematest \
+ networkxml2xmlin \
+ networkxml2xmlout \
+ nodedevschemadata \
+ nodedevschematest \
+ nodeinfodata \
+ nwfilterschematest \
+ nwfilterxml2xmlin \
+ nwfilterxml2xmlout \
+ oomtrace.pl \
+ qemuhelpdata \
+ qemuxml2argvdata \
+ qemuxml2xmloutdata \
+ schematestutils.sh \
+ sexpr2xmldata \
storagepoolschematest \
- storagepoolxml2xmlout \
storagepoolxml2xmlin \
+ storagepoolxml2xmlout \
storagevolschematest \
- storagevolxml2xmlout \
storagevolxml2xmlin \
- nodedevschematest \
- nodedevschemadata \
+ storagevolxml2xmlout \
+ test-lib.sh \
vmx2xmldata \
- xml2vmxdata \
- nwfilterxml2xmlout \
- nwfilterxml2xmlin \
- nwfilterschematest \
- domainsnapshotschematest \
- domainsnapshotxml2xmlout \
- domainsnapshotxml2xmlin \
- qemuhelpdata \
- cputestdata
+ xencapsdata \
+ xmconfigdata \
+ xml2sexprdata \
+ xml2vmxdata
check_PROGRAMS = virshtest conftest sockettest \
nodeinfotest qparamtest virbuftest \
diff --git a/tests/commanddata/Makefile.am b/tests/commanddata/Makefile.am
deleted file mode 100644
index ea0f8e1..0000000
--- a/tests/commanddata/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-EXTRA_DIST = \
- $(patsubst $(srcdir)/%,%,$(wildcard $(srcdir)/*.log))
diff --git a/tests/confdata/Makefile.am b/tests/confdata/Makefile.am
deleted file mode 100644
index eaaadbc..0000000
--- a/tests/confdata/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-EXTRA_DIST = \
- $(patsubst $(srcdir)/%,%,$(wildcard $(srcdir)/*.out $(srcdir)/*.conf))
diff --git a/tests/sexpr2xmldata/Makefile.am b/tests/sexpr2xmldata/Makefile.am
deleted file mode 100644
index db43109..0000000
--- a/tests/sexpr2xmldata/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-EXTRA_DIST = \
- $(patsubst $(srcdir)/%,%,$(wildcard $(srcdir)/*.xml $(srcdir)/*.sexpr))
diff --git a/tests/xencapsdata/Makefile.am b/tests/xencapsdata/Makefile.am
deleted file mode 100644
index ed08bc4..0000000
--- a/tests/xencapsdata/Makefile.am
+++ /dev/null
@@ -1,3 +0,0 @@
-EXTRA_DIST = \
- $(patsubst $(srcdir)/%,%,$(wildcard \
- $(srcdir)/*.xml $(srcdir)/*.cpuinfo $(srcdir)/*.caps))
diff --git a/tests/xmconfigdata/Makefile.am b/tests/xmconfigdata/Makefile.am
deleted file mode 100644
index af0cb09..0000000
--- a/tests/xmconfigdata/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-EXTRA_DIST = \
- $(patsubst $(srcdir)/%,%,$(wildcard $(srcdir)/*.xml $(srcdir)/*.cfg))
diff --git a/tests/xml2sexprdata/Makefile.am b/tests/xml2sexprdata/Makefile.am
deleted file mode 100644
index 20028bb..0000000
--- a/tests/xml2sexprdata/Makefile.am
+++ /dev/null
@@ -1,2 +0,0 @@
-EXTRA_DIST = \
- $(patsubst $(srcdir)/%,%,$(wildcard $(srcdir)/*.xml $(srcdir)/*.sexpr))
--
1.7.3.3
14 years
[libvirt] [PATCH] build: fix typo that broke 'make dist'
by Eric Blake
* src/Makefile.am (QEMU_DRIVER_SOURCES): Ship qemu_cgroup.h.
---
Pushing this under the build-breaker rule, to fix 'make distcheck'.
src/Makefile.am | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 64e890f..55d96df 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -271,7 +271,7 @@ QEMU_DRIVER_SOURCES = \
qemu/qemu_command.c qemu/qemu_command.h \
qemu/qemu_domain.c qemu/qemu_domain.h \
qemu/qemu_audit.c qemu/qemu_audit.h \
- qemu/qemu_cgroup.c qemu/qemu_cgroup.c \
+ qemu/qemu_cgroup.c qemu/qemu_cgroup.h \
qemu/qemu_hostdev.c qemu/qemu_hostdev.h \
qemu/qemu_hotplug.c qemu/qemu_hotplug.h \
qemu/qemu_conf.c qemu/qemu_conf.h \
--
1.7.3.3
14 years
[libvirt] [PATCH] Adapt test suite to code movement in the QEMU driver
by Matthias Bolte
---
tests/qemuargv2xmltest.c | 1 +
tests/qemuhelptest.c | 5 +++--
tests/qemuxml2argvtest.c | 8 +++++---
tests/testutilsqemu.c | 6 ++----
4 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index adff05a..dfb9d99 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -14,6 +14,7 @@
# include "internal.h"
# include "testutils.h"
# include "qemu/qemu_conf.h"
+# include "qemu/qemu_command.h"
# include "testutilsqemu.h"
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index 6ff1feb..3f82692 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -7,6 +7,7 @@
# include "testutils.h"
# include "qemu/qemu_conf.h"
+# include "qemu/qemu_capabilities.h"
# define MAX_HELP_OUTPUT_SIZE 1024*64
@@ -50,8 +51,8 @@ static int testHelpStrParsing(const void *data)
if (virtTestLoadFile(path, &help, MAX_HELP_OUTPUT_SIZE) < 0)
return -1;
- if (qemudParseHelpStr("QEMU", help, &flags,
- &version, &is_kvm, &kvm_version) == -1)
+ if (qemuCapsParseHelpStr("QEMU", help, &flags,
+ &version, &is_kvm, &kvm_version) == -1)
return -1;
if (flags != info->flags) {
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 5387432..158204d 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -14,6 +14,8 @@
# include "internal.h"
# include "testutils.h"
# include "qemu/qemu_conf.h"
+# include "qemu/qemu_command.h"
+# include "qemu/qemu_capabilities.h"
# include "datatypes.h"
# include "cpu/cpu_map.h"
@@ -110,9 +112,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
free(virtTestLogContentAndReset());
virResetLastError();
- if (!(cmd = qemudBuildCommandLine(conn, &driver,
- vmdef, &monitor_chr, false, flags,
- migrateFrom, NULL, VIR_VM_OP_CREATE)))
+ if (!(cmd = qemuBuildCommandLine(conn, &driver,
+ vmdef, &monitor_chr, false, flags,
+ migrateFrom, NULL, VIR_VM_OP_CREATE)))
goto fail;
if (!!virGetLastError() != expectError) {
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 72fc8aa..bfac307 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -8,6 +8,7 @@
# include "memory.h"
# include "cpu_conf.h"
# include "qemu/qemu_driver.h"
+# include "qemu/qemu_domain.h"
static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
{
@@ -102,10 +103,7 @@ virCapsPtr testQemuCapsInit(void) {
(machines = testQemuAllocMachines(&nmachines)) == NULL)
goto cleanup;
- caps->ns.parse = qemuDomainDefNamespaceParse;
- caps->ns.free = qemuDomainDefNamespaceFree;
- caps->ns.format = qemuDomainDefNamespaceFormatXML;
- caps->ns.href = qemuDomainDefNamespaceHref;
+ qemuDomainSetNamespaceHooks(caps);
if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
"/usr/bin/qemu", NULL,
--
1.7.0.4
14 years
[libvirt] [PATCH v2 1/2] timer impl
by Wen Congyang
* src/util/timer.c src/util/timer.h src/util/timer_linux.c src/util/timer_win32.c:
timer implementation
* src/Makefile.am: build timer
* src/libvirt_private.syms: Export public functions
* src/libvirt.c: Initialize timer
* configure.ac: check the functions in librt used by timer
Signed-off-by: Wen Congyang <wency(a)cn.fujitsu.com>
---
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 +++++++++++++++++++++++++++++++++++
8 files changed, 477 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
diff --git a/configure.ac b/configure.ac
index 64e76dc..49b77c5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -107,6 +107,10 @@ LIBS="$LIBS $LIB_PTHREAD"
AC_CHECK_FUNCS([pthread_sigmask pthread_mutexattr_init])
LIBS=$old_libs
+dnl Availability of rt functions
+AC_CHECK_LIB([rt],[timer_gettime],[])
+AC_CHECK_FUNCS([clock_gettime timer_create timer_settime timer_delete])
+
dnl Availability of various common headers (non-fatal if missing).
AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h sys/un.h \
sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h \
diff --git a/src/Makefile.am b/src/Makefile.am
index 196d8af..13a66be 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,9 +79,11 @@ UTIL_SOURCES = \
util/util.c util/util.h \
util/xml.c util/xml.h \
util/virtaudit.c util/virtaudit.h \
- util/virterror.c util/virterror_internal.h
+ util/virterror.c util/virterror_internal.h \
+ util/timer.c util/timer.h
-EXTRA_DIST += util/threads-pthread.c util/threads-win32.c
+EXTRA_DIST += util/threads-pthread.c util/threads-win32.c \
+ util/timer_linux.c
# Internal generic driver infrastructure
NODE_INFO_SOURCES = nodeinfo.h nodeinfo.c
diff --git a/src/libvirt.c b/src/libvirt.c
index 4188b45..a5578c0 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -40,6 +40,7 @@
#include "util.h"
#include "memory.h"
#include "configmake.h"
+#include "timer.h"
#ifndef WITH_DRIVER_MODULES
# ifdef WITH_TEST
@@ -329,6 +330,7 @@ virInitialize(void)
if (virThreadInitialize() < 0 ||
virErrorInitialize() < 0 ||
+ virTimerInitialize() < 0 ||
virRandomInitialize(time(NULL) ^ getpid()))
return -1;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0e3033d..928316a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -787,6 +787,12 @@ virThreadJoin;
virThreadSelf;
virThreadSelfID;
+# timer.h
+get_clock;
+virNewTimer;
+virFreeTimer;
+virModTimer;
+virDelTimer;
# usb.h
usbDeviceFileIterate;
diff --git a/src/util/timer.c b/src/util/timer.c
new file mode 100644
index 0000000..2a62a39
--- /dev/null
+++ b/src/util/timer.c
@@ -0,0 +1,166 @@
+/*
+ * timer.c: timer functions
+ *
+ * Copyright (C) 2010 Fujitsu Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Wen Congyang <wency(a)cn.fujitsu.com>
+ */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "timer.h"
+#include "virterror_internal.h"
+#include "memory.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+struct virTimer {
+ uint64_t expire_time;
+ virTimerCB function;
+ void *data;
+ virTimerPtr next;
+};
+
+static virTimerPtr timer_list = NULL;
+static void realarm_timer(void);
+static void __realarm_timer(uint64_t);
+static int timer_fd[2] = {-1, -1};
+
+virTimerPtr virNewTimer(virTimerCB callback, void *data)
+{
+ virTimerPtr timer = NULL;
+
+ if (VIR_ALLOC(timer) < 0) {
+ virReportOOMError();
+ return NULL;
+ }
+
+ timer->function = callback;
+ timer->data = data;
+
+ return timer;
+}
+
+void virFreeTimer(virTimerPtr timer)
+{
+ VIR_FREE(timer);
+}
+
+void virDelTimer(virTimerPtr timer)
+{
+ virTimerPtr *pt, t;
+
+ pt = &timer_list;
+ for (t = *pt; t; t = t->next) {
+ if (t == timer) {
+ *pt = t->next;
+ break;
+ }
+ pt = &t->next;
+ }
+
+ realarm_timer();
+}
+
+void virModTimer(virTimerPtr timer, uint64_t expire_time)
+{
+ virTimerPtr *pt, t;
+
+ virDelTimer(timer);
+
+ pt = &timer_list;
+ for (t = *pt; t; t = t->next) {
+ if (t->expire_time > expire_time)
+ break;
+ pt = &t->next;
+ }
+ timer->expire_time = expire_time;
+ timer->next = *pt;
+ *pt = timer;
+
+ realarm_timer();
+}
+
+static void realarm_timer()
+{
+ if (!timer_list)
+ return;
+
+ __realarm_timer(timer_list->expire_time);
+}
+
+static void timer_handler(void)
+{
+ uint64_t current_time = 0;
+ virTimerPtr *timer_list_head = &timer_list;
+ virTimerPtr timer = NULL;
+
+ if (!timer_list)
+ return;
+
+ current_time = get_clock();
+ for (timer = timer_list; timer; timer = timer->next) {
+ if (current_time < timer->expire_time)
+ break;
+
+ /* remove timer from the list before calling the callback */
+ *timer_list_head = timer->next;
+ timer->next = NULL;
+ timer->function(timer->data);
+
+ /* timer->function may take a while, so we should update cuttent_time */
+ current_time = get_clock();
+ }
+
+ realarm_timer();
+}
+
+static void timer_loop(void *arg ATTRIBUTE_UNUSED)
+{
+ fd_set readfds;
+ int ret;
+ int readinfo = 0;
+
+ while(1) {
+ FD_ZERO(&readfds);
+ FD_SET(timer_fd[0], &readfds);
+
+ reselect:
+ ret = select(timer_fd[0] + 1, &readfds, NULL, NULL, NULL);
+ if (ret < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ goto reselect;
+ else
+ continue;
+ }
+
+ ret = read(timer_fd[0], &readinfo, sizeof(int));
+ timer_handler();
+ }
+
+ return;
+}
+
+#if defined HAVE_TIMER_CREATE
+#include "timer_linux.c"
+#elif defined WIN32
+#include "timer_win32.c"
+#else
+# error "gnu timer is required"
+#endif
diff --git a/src/util/timer.h b/src/util/timer.h
new file mode 100644
index 0000000..f521c1b
--- /dev/null
+++ b/src/util/timer.h
@@ -0,0 +1,37 @@
+/*
+ * timer.h: structure and entry points for timer support
+ *
+ * Copyright (C) 2010 Fujitsu Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Wen Congyang <wency(a)cn.fujitsu.com>
+ */
+
+#ifndef __VIR_TIMER_H__
+# define __VIR_TIMER_H__
+
+#include <stdint.h>
+typedef struct virTimer virTimer;
+typedef virTimer *virTimerPtr;
+typedef void (*virTimerCB)(void *);
+
+extern uint64_t get_clock(void);
+extern virTimerPtr virNewTimer(virTimerCB, void *);
+extern void virFreeTimer(virTimerPtr);
+extern void virModTimer(virTimerPtr, uint64_t);
+extern void virDelTimer(virTimerPtr);
+extern int virTimerInitialize(void);
+#endif /* __VIR_TIMER_H__ */
diff --git a/src/util/timer_linux.c b/src/util/timer_linux.c
new file mode 100644
index 0000000..be483cf
--- /dev/null
+++ b/src/util/timer_linux.c
@@ -0,0 +1,130 @@
+/*
+ * timer.c: timer functions
+ *
+ * Copyright (C) 2010 Fujitsu Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Wen Congyang <wency(a)cn.fujitsu.com>
+ */
+
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <stddef.h>
+#include <time.h>
+#include <sys/time.h>
+#include <signal.h>
+#include <sys/select.h>
+#include <pthread.h>
+
+#include "timer.h"
+#include "threads.h"
+
+static int timer_initialized = 0;
+static pthread_attr_t timer_thread_attr;
+static timer_t timer_id;
+
+uint64_t get_clock(void)
+{
+ struct timespec ts;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+}
+
+static void __realarm_timer(uint64_t next_time)
+{
+ uint64_t current_time = 0;
+ uint64_t timeout = 0;
+ struct itimerspec its;
+
+ current_time = get_clock();
+ if (current_time < next_time) {
+ timeout = next_time - current_time;
+ } else {
+ timeout = 1;
+ }
+
+ its.it_interval.tv_sec = 0;
+ its.it_interval.tv_nsec = 0;
+ its.it_value.tv_sec = timeout / 1000000000ULL;
+ its.it_value.tv_nsec = timeout % 1000000000ULL;
+
+ timer_settime(timer_id, 0, &its, NULL);
+}
+
+static void timer_nofity_thread(sigval_t sigev_value ATTRIBUTE_UNUSED)
+{
+ int write_info = 1;
+ int ret;
+
+ ret = write(timer_fd[1], &write_info, sizeof(int));
+}
+
+int virTimerInitialize(void)
+{
+ struct sigevent timer_event;
+ struct itimerspec its;
+ struct virThread timer_thread;
+ struct timespec ts;
+ int ret;
+
+ if (timer_initialized)
+ return 0;
+
+ /* Make sure we can use system call clock_gettime(), so we can ignore the
+ * return value of clock_gettime() in the function get_clock().
+ */
+ ret = clock_gettime(CLOCK_MONOTONIC, &ts);
+ if (ret != 0)
+ return -1;
+
+ ret = pipe(timer_fd);
+ if (ret < 0)
+ return -1;
+
+ pthread_attr_init(&timer_thread_attr);
+ pthread_attr_setdetachstate(&timer_thread_attr, 1);
+
+ timer_event.sigev_notify = SIGEV_THREAD;
+ timer_event.sigev_notify_function = timer_nofity_thread;
+ timer_event.sigev_notify_attributes = &timer_thread_attr;
+ timer_event.sigev_value.sival_ptr = NULL;
+ ret = timer_create(CLOCK_MONOTONIC, &timer_event, &timer_id);
+ if (ret != 0)
+ return -1;
+
+ its.it_interval.tv_sec = 0;
+ its.it_interval.tv_nsec = 0;
+ its.it_value.tv_sec = 0;
+ its.it_value.tv_nsec = 0;
+
+ /* Make sure we can use system call timer_settime(), so we can ignore the
+ * return value of timer_settime() in the function __realarm_timer().
+ */
+ ret = timer_settime(timer_id, 0, &its, NULL);
+ if (ret != 0) {
+ timer_delete(timer_id);
+ return -1;
+ }
+
+ if (virThreadCreate(&timer_thread, 0, timer_loop, NULL) < 0) {
+ timer_delete(timer_id);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/util/timer_win32.c b/src/util/timer_win32.c
new file mode 100644
index 0000000..98248f7
--- /dev/null
+++ b/src/util/timer_win32.c
@@ -0,0 +1,128 @@
+/*
+ * timer.c: timer functions
+ *
+ * Copyright (C) 2010 Fujitsu Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Wen Congyang <wency(a)cn.fujitsu.com>
+ */
+
+#include <windows.h>
+#include <mmsystem.h>
+#include <stdint.h>
+
+#include "threads.h"
+
+uint64_t clock_frequency = 0;
+uint64_t ticks_per_second = 1000000000;
+uint period = 0;
+MMRESULT timer_id;
+
+uint64_t get_clock(void)
+{
+ LARGE_INTEGER time;
+ LARGE_INTEGER result;
+ uint64_t result_low, result_high;
+
+ QueryPerformanceCounter(&time);
+
+ /* calculate time * ticks_per_second / clock_frequency */
+ result_high = (uint64_t)time.HighPart * ticks_per_second;
+ result_low = (uint64_t)time.LowPart * ticks_per_second;
+ result_high += result_low >> 32;
+ result_low = ((result_high % clock_frequency) << 32) +
+ result_low & 0xFFFFFFFF;
+ result.HighPart = result_high / clock_frequency;
+ result.LowPart = result_low / clock_frequency;
+
+ return result.QuadPart;
+}
+
+static void CALLBACK wakeup_timer(UINT uTimerID, UINT uMsg,
+ DWORD_PTR dwUser, DWORD_PTR dw1,
+ DWORD_PTR dw2)
+{
+ int write_info = 1;
+ int ret;
+
+ ret = write(timer_fd[1], &write_info, sizeof(int));
+}
+
+static void __realarm_timer(uint64_t next_time)
+{
+ uint64_t current_time = 0;
+ UINT timeout = 0;
+ UINT flags;
+
+ current_time = get_clock();
+ if (current_time + 100000ULL < next_time) {
+ timeout = (next_time - current_time) / 1000000ULL;
+ } else {
+ timeout = 1;
+ }
+
+ flags = TIME_CALLBACK_FUNCTION | TIME_ONESHOT;
+ timer_id = timeSetEvent(timeout, period, wakeup_timer,
+ (DWORD_PTR)NULL, flags);
+}
+
+int virTimerInitialize(void)
+{
+ LARGE_INTEGER frequency;
+ int ret;
+ TIMECAPS timecaps;
+ MMRESULT mmresult;
+ UINT flags;
+ struct virThread timer_thread;
+
+ ret = pipe(timer_fd);
+ if (ret < 0)
+ return -1;
+
+ ret = QueryPerformanceFrequency(&frequency);
+ if (ret != 0) {
+ return -1;
+ }
+ clock_frequency = frequency.QuadPart;
+
+ memset(&timecaps, 0, sizeof(TIMECAPS));
+ mmresult = timeGetDevCaps(&timecaps, sizeof(TIMECAPS));
+ if (mmresult != MMSYSERR_NOERROR)
+ return -1;
+ period = timecaps.wPeriodMin;
+
+ mmresult = timeBeginPeriod(period);
+ if (mmresult != TIMERR_NOERROR)
+ return -1;
+
+ /* Make sure we can use timeSetEvent(), so we can ignore the return value
+ * of timeSetEvent() in the function __realarm_timer().
+ */
+ flags = TIME_CALLBACK_FUNCTION | TIME_ONESHOT;
+ mmresult = timeSetEvent(1000, period, wakeup_timer, (DWORD_PTR)NULL, flags);
+ if (!mmresult) {
+ timeEndPeriod(period);
+ return -1;
+ }
+ timeKillEvent(mmresult);
+
+ if (virThreadCreate(&timer_thread, 0, timer_loop, NULL) < 0) {
+ timeEndPeriod(period);
+ return -1;
+ }
+
+ return 0;
+}
--
1.7.1
14 years
[libvirt] [PATCH 00/10] Re-arrange the QEMU driver code
by Daniel P. Berrange
The QEMU driver is getting horribly large & I constantly find myself
getting lost in it. This series re-arranges the code, pulling out
the following areas of functionality into new files
- capabilities construction
- command line arg generation/parsing
- domain private data / namespace handling
- audit reporting
- cgroup management
- host device management
- device hotplug
There is no functional change in any of these patches. A handful
of methods have been renamed if they started with the obsolete
'qemud' prefix.
Since these patches will massively conflict with any further
patches to the QEMU driver, the sooner they're applied the
better...
There is more to be pulled out later which is slightly more
entangled / difficult
- Events
- Process startup/shutdown
- Migration
Daniel
14 years
[libvirt] VolumeCreateXML "XML" description for ESX
by Sherif Nagy
Hello,
I am using libvirt 0.8.6 "python bindings " can someone point me to where i
find the XML description of creating volumes using storagecolumecreateXML
function ? i am getting libvir: ESX error : internal error Volume name
'nameXXXX.vmdk' doesn't have expected format '<directory>/<file>'
thank you
regards,
Sherif
14 years