From: Stefan Berger Date: Thu, 14 Apr 2011 18:48:03 +0000 (-0400) Subject: Migrate VMs between different-endianess hosts X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=cf2145d5467c52070d1470214d8806a3ea65f48a;p=libvirt.git Migrate VMs between different-endianess hosts This patch enables the migration of Qemu VMs between hosts of different endianess. I tested this by migrating a i686 VM between a x86 and ppc64 host. I am converting the 'int's in the VM's state header to uint32_t assuming this doesn't break compatibility with existing deployments other than Linux. --- diff --git a/bootstrap.conf b/bootstrap.conf index 3db0c6373a..293f86eb9e 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -21,6 +21,7 @@ gnulib_modules=' areadlink base64 +byteswap c-ctype c-strcase c-strcasestr diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index b580a0caf4..c1a44c9593 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "qemu_driver.h" @@ -1810,13 +1811,22 @@ VIR_ENUM_IMPL(qemudSaveCompression, QEMUD_SAVE_FORMAT_LAST, struct qemud_save_header { char magic[sizeof(QEMUD_SAVE_MAGIC)-1]; - int version; - int xml_len; - int was_running; - int compressed; - int unused[15]; + uint32_t version; + uint32_t xml_len; + uint32_t was_running; + uint32_t compressed; + uint32_t unused[15]; }; +static inline void +bswap_header(struct qemud_save_header *hdr) { + hdr->version = bswap_32(hdr->version); + hdr->xml_len = bswap_32(hdr->xml_len); + hdr->was_running = bswap_32(hdr->was_running); + hdr->compressed = bswap_32(hdr->compressed); +} + + /* return -errno on failure, or 0 on success */ static int qemuDomainSaveHeader(int fd, const char *path, char *xml, @@ -3025,6 +3035,11 @@ qemuDomainSaveImageOpen(struct qemud_driver *driver, goto error; } + if (header.version > QEMUD_SAVE_VERSION) { + /* convert endianess and try again */ + bswap_header(&header); + } + if (header.version > QEMUD_SAVE_VERSION) { qemuReportError(VIR_ERR_OPERATION_FAILED, _("image version is not supported (%d > %d)"),