[libvirt] [PATCH 0/2] Clean up rest of migration code

As requested in review. Peter Krempa (2): qemu: monitor: Remove unused qemuMonitorMigrateToFile qemu: Remove unnecessary calculations in qemuDomainSaveMemory src/qemu/qemu_driver.c | 30 ++---------------------- src/qemu/qemu_monitor.c | 61 ------------------------------------------------- src/qemu/qemu_monitor.h | 17 -------------- 3 files changed, 2 insertions(+), 106 deletions(-) -- 2.6.2

With the currently supported qemus we always migrate to file descriptors so the old function is not required any more. Additionally QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE macro is now unused. --- src/qemu/qemu_monitor.c | 61 ------------------------------------------------- src/qemu/qemu_monitor.h | 7 ------ 2 files changed, 68 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 6b23e88..58a7475 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2213,67 +2213,6 @@ qemuMonitorMigrateToCommand(qemuMonitorPtr mon, int -qemuMonitorMigrateToFile(qemuMonitorPtr mon, - unsigned int flags, - const char * const *argv, - const char *target, - unsigned long long offset) -{ - char *argstr; - char *dest = NULL; - int ret = -1; - char *safe_target = NULL; - virBuffer buf = VIR_BUFFER_INITIALIZER; - VIR_DEBUG("argv=%p target=%s offset=%llu flags=%x", - argv, target, offset, flags); - - QEMU_CHECK_MONITOR(mon); - - if (offset % QEMU_MONITOR_MIGRATE_TO_FILE_BS) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("file offset must be a multiple of %llu"), - QEMU_MONITOR_MIGRATE_TO_FILE_BS); - return -1; - } - - argstr = virArgvToString(argv); - if (!argstr) - goto cleanup; - - /* Migrate to file */ - virBufferEscapeShell(&buf, target); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - safe_target = virBufferContentAndReset(&buf); - - /* Two dd processes, sharing the same stdout, are necessary to - * allow starting at an alignment of 512, but without wasting - * padding to get to the larger alignment useful for speed. Use - * <> redirection to avoid truncating a regular file. */ - if (virAsprintf(&dest, "exec:" VIR_WRAPPER_SHELL_PREFIX "%s | " - "{ dd bs=%llu seek=%llu if=/dev/null && " - "dd ibs=%llu obs=%llu; } 1<>%s" VIR_WRAPPER_SHELL_SUFFIX, - argstr, QEMU_MONITOR_MIGRATE_TO_FILE_BS, - offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS, - QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE, - QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE, - safe_target) < 0) - goto cleanup; - - if (mon->json) - ret = qemuMonitorJSONMigrate(mon, flags, dest); - else - ret = qemuMonitorTextMigrate(mon, flags, dest); - - cleanup: - VIR_FREE(safe_target); - VIR_FREE(argstr); - VIR_FREE(dest); - return ret; -} - - -int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, unsigned int flags, const char *unixfile) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 9d7d5f3..d731344 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -569,13 +569,6 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon, * larger but only aligned to the smaller block size. */ # define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 4) -# define QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE (1024llu * 1024) - -int qemuMonitorMigrateToFile(qemuMonitorPtr mon, - unsigned int flags, - const char * const *argv, - const char *target, - unsigned long long offset); int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, unsigned int flags, -- 2.6.2

Now that the file migration doesn't require us to use 'dd' and other legacy stuff for too old qemus we don't even have to calcuate the offsets and other stuff. --- src/qemu/qemu_driver.c | 30 ++---------------------------- src/qemu/qemu_monitor.h | 10 ---------- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 77f4baa..2ca6700 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3128,38 +3128,13 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, int directFlag = 0; virFileWrapperFdPtr wrapperFd = NULL; unsigned int wrapperFlags = VIR_FILE_WRAPPER_NON_BLOCKING; - unsigned long long pad; - unsigned long long offset; - size_t len; - char *xml = NULL; memset(&header, 0, sizeof(header)); memcpy(header.magic, QEMU_SAVE_PARTIAL, sizeof(header.magic)); header.version = QEMU_SAVE_VERSION; header.was_running = was_running ? 1 : 0; - header.compressed = compressed; - - len = strlen(domXML) + 1; - offset = sizeof(header) + len; - - /* Due to way we append QEMU state on our header with dd, - * we need to ensure there's a 512 byte boundary. Unfortunately - * we don't have an explicit offset in the header, so we fake - * it by padding the XML string with NUL bytes. Additionally, - * we want to ensure that virDomainSaveImageDefineXML can supply - * slightly larger XML, so we add a minimum padding prior to - * rounding out to page boundaries. - */ - pad = 1024; - pad += (QEMU_MONITOR_MIGRATE_TO_FILE_BS - - ((offset + pad) % QEMU_MONITOR_MIGRATE_TO_FILE_BS)); - if (VIR_ALLOC_N(xml, len + pad) < 0) - goto cleanup; - strcpy(xml, domXML); - - offset += pad; - header.xml_len = len; + header.xml_len = strlen(domXML) + 1; /* Obtain the file handle. */ if ((flags & VIR_DOMAIN_SAVE_BYPASS_CACHE)) { @@ -3184,7 +3159,7 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, goto cleanup; /* Write header to file, followed by XML */ - if (qemuDomainSaveHeader(fd, path, xml, &header) < 0) + if (qemuDomainSaveHeader(fd, path, domXML, &header) < 0) goto cleanup; /* Perform the migration */ @@ -3226,7 +3201,6 @@ qemuDomainSaveMemory(virQEMUDriverPtr driver, cleanup: VIR_FORCE_CLOSE(fd); virFileWrapperFdFree(wrapperFd); - VIR_FREE(xml); if (ret < 0 && needUnlink) unlink(path); diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index d731344..134cbb6 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -560,16 +560,6 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon, unsigned int flags, const char * const *argv); -/* In general, BS is the smallest fundamental block size we can use to - * access a block device; everything must be aligned to a multiple of - * this. Linux generally supports a BS as small as 512, but with - * newer disks with 4k sectors, performance is better if we guarantee - * alignment to the sector size. However, operating on BS-sized - * blocks is painfully slow, so we also have a transfer size that is - * larger but only aligned to the smaller block size. - */ -# define QEMU_MONITOR_MIGRATE_TO_FILE_BS (1024llu * 4) - int qemuMonitorMigrateToUnix(qemuMonitorPtr mon, unsigned int flags, const char *unixfile); -- 2.6.2

On Wed, Feb 17, 2016 at 01:35:50PM +0100, Peter Krempa wrote:
As requested in review.
Peter Krempa (2): qemu: monitor: Remove unused qemuMonitorMigrateToFile qemu: Remove unnecessary calculations in qemuDomainSaveMemory
ACK series Patch 1/2 also removes the last use of VIR_WRAPPER_SHELL* macros from qemu_monitor.h. The whole lv_wrapper_shell in configure.ac can also be removed. Jan
src/qemu/qemu_driver.c | 30 ++---------------------- src/qemu/qemu_monitor.c | 61 ------------------------------------------------- src/qemu/qemu_monitor.h | 17 -------------- 3 files changed, 2 insertions(+), 106 deletions(-)
-- 2.6.2
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Ján Tomko
-
Peter Krempa