[libvirt] [PATCH] qemu_migrate: Fix assign the same port when migrating concurrently
by Wangyufei (A)
>From 6c2de34432db674072231ad66c9e8a0a600ede8a Mon Sep 17 00:00:00 2001
From: WangYufei <james.wangyufei(a)huawei.com>
Date: Mon, 30 Sep 2013 11:48:43 +0800
Subject: [PATCH] qemu_migrate: Fix assign the same port when migrating concurrently
When we migrate vms concurrently, there's a chance that libvirtd on destination assign the same port for different migrations, which will lead to migration failed during migration prepare phase on destination. So we use virPortAllocator here to solve the problem.
Signed-off-by: WangYufei <james.wangyufei(a)huawei.com>
---
src/qemu/qemu_command.h | 3 +++
src/qemu/qemu_conf.h | 6 +++---
src/qemu/qemu_driver.c | 6 ++++++
src/qemu/qemu_migration.c | 17 ++++++++++-------
4 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 2e2acfb..3277ba4 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -51,6 +51,9 @@
# define QEMU_WEBSOCKET_PORT_MIN 5700
# define QEMU_WEBSOCKET_PORT_MAX 65535
+# define QEMU_MIGRATION_PORT_MIN 49152
+# define QEMU_MIGRATION_PORT_MAX 49215
+
typedef struct _qemuBuildCommandLineCallbacks qemuBuildCommandLineCallbacks;
typedef qemuBuildCommandLineCallbacks *qemuBuildCommandLineCallbacksPtr;
struct _qemuBuildCommandLineCallbacks {
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index da29a2a..3176085 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -221,6 +221,9 @@ struct _virQEMUDriver {
/* Immutable pointer, self-locking APIs */
virPortAllocatorPtr webSocketPorts;
+ /* Immutable pointer, self-locking APIs */
+ virPortAllocatorPtr migrationPorts;
+
/* Immutable pointer, lockless APIs*/
virSysinfoDefPtr hostsysinfo;
@@ -242,9 +245,6 @@ struct _qemuDomainCmdlineDef {
char **env_value;
};
-/* Port numbers used for KVM migration. */
-# define QEMUD_MIGRATION_FIRST_PORT 49152
-# define QEMUD_MIGRATION_NUM_PORTS 64
void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e8bc04d..9437b5a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -688,6 +688,11 @@ qemuStateInitialize(bool privileged,
cfg->webSocketPortMax)) == NULL)
goto error;
+ if ((qemu_driver->migrationPorts =
+ virPortAllocatorNew(QEMU_MIGRATION_PORT_MIN,
+ QEMU_MIGRATION_PORT_MAX)) == NULL)
+ goto error;
+
if (qemuSecurityInit(qemu_driver) < 0)
goto error;
@@ -994,6 +999,7 @@ qemuStateCleanup(void) {
virObjectUnref(qemu_driver->domains);
virObjectUnref(qemu_driver->remotePorts);
virObjectUnref(qemu_driver->webSocketPorts);
+ virObjectUnref(qemu_driver->migrationPorts);
virObjectUnref(qemu_driver->xmlopt);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3a1aab7..82d90bf 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2493,7 +2493,6 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
const char *origname,
unsigned long flags)
{
- static int port = 0;
int this_port;
char *hostname = NULL;
const char *p;
@@ -2521,8 +2520,9 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
* to be a correct hostname which refers to the target machine).
*/
if (uri_in == NULL) {
- this_port = QEMUD_MIGRATION_FIRST_PORT + port++;
- if (port == QEMUD_MIGRATION_NUM_PORTS) port = 0;
+ if (virPortAllocatorAcquire(driver->migrationPorts,
+ (unsigned short *)&this_port) < 0)
+ goto cleanup;
/* Get hostname */
if ((hostname = virGetHostname()) == NULL)
@@ -2578,9 +2578,9 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
if (uri->port == 0) {
/* Generate a port */
- this_port = QEMUD_MIGRATION_FIRST_PORT + port++;
- if (port == QEMUD_MIGRATION_NUM_PORTS)
- port = 0;
+ if (virPortAllocatorAcquire(driver->migrationPorts,
+ (unsigned short *)&this_port) < 0)
+ goto cleanup;
/* Caller frees */
if (virAsprintf(uri_out, "%s:%d", uri_in, this_port) < 0)
@@ -2600,8 +2600,11 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
cleanup:
virURIFree(uri);
VIR_FREE(hostname);
- if (ret != 0)
+ if (ret != 0) {
VIR_FREE(*uri_out);
+ virPortAllocatorRelease(driver->migrationPorts,
+ (unsigned short)this_port);
+ }
return ret;
}
--
1.7.3.1.msysgit.0
Best Regards,
-WangYufei
11 years, 6 months
[libvirt] [PATCH v2 0/2] Libvirt Wireshark dissector
by Yuto KAWAMURA(kawamuray)
From: "Yuto KAWAMURA(kawamuray)" <kawamuray.dadada(a)gmail.com>
Introduce Wireshark dissector plugin which adds support to Wireshark
for dissecting libvirt RPC protocol.
This feature was presented by Michal Privoznik year before last[1].
But it did only support dissecting packet headers.
This time I enhanced that dissector to support dissecting packet
payload. Furthermore, I provide code generator of dissector. So you
can get fresh build of dissector from libvirt RPC specification file
at any version you like.
[1] http://www.redhat.com/archives/libvir-list/2011-October/msg00301.html
Yuto KAWAMURA(kawamuray) (2):
Introduce Libvirt Wireshark dissector
Add sample output of Wireshark dissector
Makefile.am | 3 +-
cfg.mk | 6 +-
configure.ac | 72 +-
tools/wireshark/Makefile.am | 29 +
tools/wireshark/README.md | 31 +
tools/wireshark/samples/libvirt-sample.pdml | 206 ++++++
tools/wireshark/src/.gitignore | 4 +
tools/wireshark/src/Makefile.am | 42 ++
tools/wireshark/src/moduleinfo.h | 37 +
tools/wireshark/src/packet-libvirt.c | 513 ++++++++++++++
tools/wireshark/src/packet-libvirt.h | 128 ++++
tools/wireshark/util/genxdrstub.pl | 1010 +++++++++++++++++++++++++++
tools/wireshark/util/make-dissector-reg | 199 ++++++
13 files changed, 2275 insertions(+), 5 deletions(-)
create mode 100644 tools/wireshark/Makefile.am
create mode 100644 tools/wireshark/README.md
create mode 100644 tools/wireshark/samples/libvirt-sample.pdml
create mode 100644 tools/wireshark/src/.gitignore
create mode 100644 tools/wireshark/src/Makefile.am
create mode 100644 tools/wireshark/src/moduleinfo.h
create mode 100644 tools/wireshark/src/packet-libvirt.c
create mode 100644 tools/wireshark/src/packet-libvirt.h
create mode 100755 tools/wireshark/util/genxdrstub.pl
create mode 100755 tools/wireshark/util/make-dissector-reg
--
1.8.1.5
11 years, 6 months
[libvirt] qemu, numa: non-contiguous cpusets
by Borislav Petkov
Btw,
while I got your attention, on a not-really related topic: how do we
feel about adding support for specifying a non-contiguous set of cpus
for a numa node in qemu with the -numa option? I.e., like this, for
example:
x86_64-softmmu/qemu-system-x86_64 -smp 8 -numa node,nodeid=0,cpus=0\;2\;4-5 -numa node,nodeid=1,cpus=1\;3\;6-7
The ';' needs to be escaped from the shell but I'm open for better
suggestions.
Here's a diff:
---
diff --git a/vl.c b/vl.c
index 4e709d5c1c20..82a6c8451fb0 100644
--- a/vl.c
+++ b/vl.c
@@ -1261,9 +1261,27 @@ char *get_boot_devices_list(size_t *size)
return list;
}
+static int __numa_set_cpus(unsigned long *map, int start, int end)
+{
+ if (end >= MAX_CPUMASK_BITS) {
+ end = MAX_CPUMASK_BITS - 1;
+ fprintf(stderr,
+ "qemu: NUMA: A max of %d VCPUs are supported\n",
+ MAX_CPUMASK_BITS);
+ return -EINVAL;
+ }
+
+ if (end < start) {
+ return -EINVAL;
+ }
+
+ bitmap_set(map, start, end-start+1);
+ return 0;
+}
+
static void numa_node_parse_cpus(int nodenr, const char *cpus)
{
- char *endptr;
+ char *endptr, *ptr = (char *)cpus;
unsigned long long value, endvalue;
/* Empty CPU range strings will be considered valid, they will simply
@@ -1273,7 +1291,8 @@ static void numa_node_parse_cpus(int nodenr, const char *cpus)
return;
}
- if (parse_uint(cpus, &value, &endptr, 10) < 0) {
+fromthetop:
+ if (parse_uint(ptr, &value, &endptr, 10) < 0) {
goto error;
}
if (*endptr == '-') {
@@ -1282,22 +1301,22 @@ static void numa_node_parse_cpus(int nodenr, const char *cpus)
}
} else if (*endptr == '\0') {
endvalue = value;
- } else {
- goto error;
- }
+ } else if (*endptr == ';') {
+ if (__numa_set_cpus(node_cpumask[nodenr], value, value) < 0) {
+ goto error;
+ }
+ endptr++;
+ if (*endptr == '\0')
+ return;
- if (endvalue >= MAX_CPUMASK_BITS) {
- endvalue = MAX_CPUMASK_BITS - 1;
- fprintf(stderr,
- "qemu: NUMA: A max of %d VCPUs are supported\n",
- MAX_CPUMASK_BITS);
- }
+ ptr = endptr;
- if (endvalue < value) {
+ goto fromthetop;
+ } else {
goto error;
}
- bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
+ __numa_set_cpus(node_cpumask[nodenr], value, endvalue);
return;
error:
--
Thanks.
--
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--
11 years, 6 months
[libvirt] [PATCH] qemu: process: Silence coverity warning when rewinding log file
by Peter Krempa
The change in ef29de14c37d14abc546e90555a0093797facfdd that introduced
better error logging from qemu introduced a warning from coverity about
unused return value from lseek. Silence this warning and fix typo in the
corresponding error message.
Reported by: John Ferlan
---
src/qemu/qemu_process.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d7be731..7a30a5e 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1845,10 +1845,10 @@ cleanup:
}
len = strlen(buf);
- /* best effor seek - we need to reset to the original position, so that
+ /* best effort seek - we need to reset to the original position, so that
* a possible read of the fd in the monitor code doesn't influence this
* error delivery option */
- lseek(logfd, pos, SEEK_SET);
+ ignore_value(lseek(logfd, pos, SEEK_SET));
qemuProcessReadLog(logfd, buf + len, buf_size - len - 1, 0, true);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("process exited while connecting to monitor: %s"),
--
1.8.3.2
11 years, 6 months
[libvirt] [PATCH v2] genprotocol.pl: Fix code on FreeBSD too
by Michal Privoznik
On some systems (linux, cygwin and gnukfreebsd) rpcgen generates files
which when compiling produces this warning:
remote/remote_protocol.c: In function 'xdr_remote_node_get_cpu_stats_ret':
remote/remote_protocol.c:530: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
Hence, on those systems we need to post-process the files by the
rpc/genprotocol.pl perl script. At the beginning of the script the OS is
detected via $^O perl variable. From my latest build on FreeBSD I see we
need to fix the code there too. On FreeBSD the variable contains
'freebsd' string:
http://perldoc.perl.org/perlport.html#PLATFORMS
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/rpc/genprotocol.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rpc/genprotocol.pl b/src/rpc/genprotocol.pl
index 4f8b6c4..6e6d6d4 100755
--- a/src/rpc/genprotocol.pl
+++ b/src/rpc/genprotocol.pl
@@ -43,7 +43,7 @@ open RPCGEN, "-|", $rpcgen, $mode, $xdrdef
open TARGET, ">$target"
or die "cannot create $target: $!";
-my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd";
+my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd" || $^O eq "freebsd";
if ($mode eq "-c") {
print TARGET "#include <config.h>\n";
--
1.8.1.5
11 years, 6 months
[libvirt] [PATCH] genprotocol.pl: Fix code on FreeBSD too
by Michal Privoznik
On some systems (linux, cygwin and freebsd) rpcgen generates files which
when compiling produces this warning:
remote/remote_protocol.c: In function 'xdr_remote_node_get_cpu_stats_ret':
remote/remote_protocol.c:530: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
Hence, on those systems we need to post-process the files by
the rpc/genprotocol.pl perl script. At the beginning of the script the
OS is detected via $^O perl variable. On FreeBSD it contains 'freebsd'
string and not 'gnukfreebsd' as is currently there:
http://perldoc.perl.org/perlport.html#PLATFORMS
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/rpc/genprotocol.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rpc/genprotocol.pl b/src/rpc/genprotocol.pl
index 4f8b6c4..abd40fd 100755
--- a/src/rpc/genprotocol.pl
+++ b/src/rpc/genprotocol.pl
@@ -43,7 +43,7 @@ open RPCGEN, "-|", $rpcgen, $mode, $xdrdef
open TARGET, ">$target"
or die "cannot create $target: $!";
-my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "gnukfreebsd";
+my $fixup = $^O eq "linux" || $^O eq "cygwin" || $^O eq "freebsd";
if ($mode eq "-c") {
print TARGET "#include <config.h>\n";
--
1.8.1.5
11 years, 6 months
[libvirt] [PATCH]lxc: goto cleanup if lxcContainerBuildInitCmd returns NULL
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
We should goto cleanup directly
if lxcContainerBuildInitCmd returns NULL,
which would avoid lots of unnecessary works.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
src/lxc/lxc_container.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 3fdf397..f03f236 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1820,7 +1820,10 @@ static int lxcContainerChild(void *data)
if ((hasReboot = lxcContainerHasReboot()) < 0)
goto cleanup;
- cmd = lxcContainerBuildInitCmd(vmDef);
+ if (!(cmd = lxcContainerBuildInitCmd(vmDef))) {
+ VIR_DEBUG("Failed to build init cmd for container");
+ goto cleanup;
+ }
virCommandWriteArgLog(cmd, 1);
if (lxcContainerSetID(vmDef) < 0)
--
1.8.2.1
11 years, 6 months
[libvirt] Openvswitch support question
by Vasiliy Tolstov
Hi all.
I'm using vs witch and libvirt 1.2.
I'm write vswitch controller and want to react on up/down port in virtual
switch.
All fork fine, but message sent to controller does not contain Mac address
of added interface. Does this libvirt problem or this is only vswitch error?
11 years, 6 months
[libvirt] [PATCH]lxc: do cleanup when failed to bind fs as read-only
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
We forgot to 'goto cleanup' when lxcContainerMountFSTmpfs
failed to bind fs as read-only.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
src/lxc/lxc_container.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index c60f5d8..3fdf397 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1451,6 +1451,7 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
virReportSystemError(errno,
_("Failed to make directory %s readonly"),
fs->dst);
+ goto cleanup;
}
}
--
1.8.2.1
11 years, 6 months