I'm tired of maintaining two copies of migration uri generation.
* src/qemu/qemu_monitor_text.h (qemuMonitorTextMigrate): Declare
in place of individual monitor commands.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONMigrate): Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextMigrateToFd)
(qemuMonitorTextMigrateToHost, qemuMonitorTextMigrateToCommand)
(qemuMonitorTextMigrateToFile, qemuMonitorTextMigrateToUnix):
Delete.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONMigrateToFd)
(qemuMonitorJSONMigrateToHost, qemuMonitorJSONMigrateToCommand)
(qemuMonitorJSONMigrateToFile, qemuMonitorJSONMigrateToUnix):
Delete.
* src/qemu/qemu_monitor.c (qemuMonitorMigrateToFd)
(qemuMonitorMigrateToHost, qemuMonitorMigrateToCommand)
(qemuMonitorMigrateToFile, qemuMonitorMigrateToUnix): Consolidate
shared code.
---
To be applied after patch 2/10; or I can rebase and apply this first
and make patch 2/10 smaller (only has to touch qemu_monitor.[ch]).
src/qemu/qemu_monitor.c | 106 +++++++++++++++++++++++++++----
src/qemu/qemu_monitor_json.c | 143 +-----------------------------------------
src/qemu/qemu_monitor_json.h | 25 +-------
src/qemu/qemu_monitor_text.c | 141 +----------------------------------------
src/qemu/qemu_monitor_text.h | 25 +-------
5 files changed, 105 insertions(+), 335 deletions(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 312e797..1e79523 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1398,10 +1398,19 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
return -1;
}
+ if (qemuMonitorSendFileHandle(mon, "migrate", fd) < 0)
+ return -1;
+
if (mon->json)
- ret = qemuMonitorJSONMigrateToFd(mon, flags, fd);
+ ret = qemuMonitorJSONMigrate(mon, flags, "fd:migrate");
else
- ret = qemuMonitorTextMigrateToFd(mon, flags, fd);
+ ret = qemuMonitorTextMigrate(mon, flags, "fd:migrate");
+
+ if (ret < 0) {
+ if (qemuMonitorCloseFileHandle(mon, "migrate") < 0)
+ VIR_WARN0("failed to close migration handle");
+ }
+
return ret;
}
@@ -1412,6 +1421,7 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
int port)
{
int ret;
+ char *uri = NULL;
VIR_DEBUG("mon=%p hostname=%s port=%d flags=%u",
mon, hostname, port, flags);
@@ -1421,10 +1431,18 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
return -1;
}
+
+ if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
if (mon->json)
- ret = qemuMonitorJSONMigrateToHost(mon, flags, hostname, port);
+ ret = qemuMonitorJSONMigrate(mon, flags, uri);
else
- ret = qemuMonitorTextMigrateToHost(mon, flags, hostname, port);
+ ret = qemuMonitorTextMigrate(mon, flags, uri);
+
+ VIR_FREE(uri);
return ret;
}
@@ -1433,7 +1451,9 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
unsigned int flags,
const char * const *argv)
{
- int ret;
+ char *argstr;
+ char *dest = NULL;
+ int ret = -1;
VIR_DEBUG("mon=%p argv=%p flags=%u",
mon, argv, flags);
@@ -1443,10 +1463,25 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
return -1;
}
+ argstr = virArgvToString(argv);
+ if (!argstr) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ if (virAsprintf(&dest, "exec:%s", argstr) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
if (mon->json)
- ret = qemuMonitorJSONMigrateToCommand(mon, flags, argv);
+ ret = qemuMonitorJSONMigrate(mon, flags, dest);
else
- ret = qemuMonitorTextMigrateToCommand(mon, flags, argv);
+ ret = qemuMonitorTextMigrate(mon, flags, dest);
+
+cleanup:
+ VIR_FREE(argstr);
+ VIR_FREE(dest);
return ret;
}
@@ -1456,7 +1491,10 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
const char *target,
unsigned long long offset)
{
- int ret;
+ char *argstr;
+ char *dest = NULL;
+ int ret = -1;
+ char *safe_target = NULL;
VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%u",
mon, argv, target, offset, flags);
@@ -1473,10 +1511,44 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
return -1;
}
+ argstr = virArgvToString(argv);
+ if (!argstr) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ /* Migrate to file */
+ safe_target = qemuMonitorEscapeShell(target);
+ if (!safe_target) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ /* 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) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
if (mon->json)
- ret = qemuMonitorJSONMigrateToFile(mon, flags, argv, target, offset);
+ ret = qemuMonitorJSONMigrate(mon, flags, dest);
else
- ret = qemuMonitorTextMigrateToFile(mon, flags, argv, target, offset);
+ ret = qemuMonitorTextMigrate(mon, flags, dest);
+
+cleanup:
+ VIR_FREE(safe_target);
+ VIR_FREE(argstr);
+ VIR_FREE(dest);
return ret;
}
@@ -1484,7 +1556,8 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
unsigned int flags,
const char *unixfile)
{
- int ret;
+ char *dest = NULL;
+ int ret = -1;
VIR_DEBUG("mon=%p, unixfile=%s flags=%u",
mon, unixfile, flags);
@@ -1494,10 +1567,17 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
return -1;
}
+ if (virAsprintf(&dest, "unix:%s", unixfile) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
if (mon->json)
- ret = qemuMonitorJSONMigrateToUnix(mon, flags, unixfile);
+ ret = qemuMonitorJSONMigrate(mon, flags, dest);
else
- ret = qemuMonitorTextMigrateToUnix(mon, flags, unixfile);
+ ret = qemuMonitorTextMigrate(mon, flags, dest);
+
+ VIR_FREE(dest);
return ret;
}
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 5fb43b0..5cf35b9 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1669,9 +1669,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon,
}
-static int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
- unsigned int flags,
- const char *uri)
+int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
+ unsigned int flags,
+ const char *uri)
{
int ret;
virJSONValuePtr cmd =
@@ -1696,143 +1696,6 @@ static int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
return ret;
}
-
-int qemuMonitorJSONMigrateToFd(qemuMonitorPtr mon,
- unsigned int flags,
- int fd)
-{
- int ret;
-
- if (qemuMonitorJSONSendFileHandle(mon, "migrate", fd) < 0)
- return -1;
-
- ret = qemuMonitorJSONMigrate(mon, flags, "fd:migrate");
-
- if (ret < 0) {
- if (qemuMonitorJSONCloseFileHandle(mon, "migrate") < 0)
- VIR_WARN0("failed to close migration handle");
- }
-
- return ret;
-}
-
-int qemuMonitorJSONMigrateToHost(qemuMonitorPtr mon,
- unsigned int flags,
- const char *hostname,
- int port)
-{
- char *uri = NULL;
- int ret;
-
- if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) {
- virReportOOMError();
- return -1;
- }
-
- ret = qemuMonitorJSONMigrate(mon, flags, uri);
-
- VIR_FREE(uri);
-
- return ret;
-}
-
-
-int qemuMonitorJSONMigrateToCommand(qemuMonitorPtr mon,
- unsigned int flags,
- const char * const *argv)
-{
- char *argstr;
- char *dest = NULL;
- int ret = -1;
-
- argstr = virArgvToString(argv);
- if (!argstr) {
- virReportOOMError();
- goto cleanup;
- }
-
- if (virAsprintf(&dest, "exec:%s", argstr) < 0) {
- virReportOOMError();
- goto cleanup;
- }
-
- ret = qemuMonitorJSONMigrate(mon, flags, dest);
-
-cleanup:
- VIR_FREE(argstr);
- VIR_FREE(dest);
- return ret;
-}
-
-int qemuMonitorJSONMigrateToFile(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;
-
- argstr = virArgvToString(argv);
- if (!argstr) {
- virReportOOMError();
- goto cleanup;
- }
-
- /* Migrate to file */
- safe_target = qemuMonitorEscapeShell(target);
- if (!safe_target) {
- virReportOOMError();
- goto cleanup;
- }
-
- /* 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) {
- virReportOOMError();
- goto cleanup;
- }
-
- ret = qemuMonitorJSONMigrate(mon, flags, dest);
-
-cleanup:
- VIR_FREE(safe_target);
- VIR_FREE(argstr);
- VIR_FREE(dest);
- return ret;
-}
-
-int qemuMonitorJSONMigrateToUnix(qemuMonitorPtr mon,
- unsigned int flags,
- const char *unixfile)
-{
- char *dest = NULL;
- int ret = -1;
-
- if (virAsprintf(&dest, "unix:%s", unixfile) < 0) {
- virReportOOMError();
- return -1;
- }
-
- ret = qemuMonitorJSONMigrate(mon, flags, dest);
-
- VIR_FREE(dest);
-
- return ret;
-}
-
-
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
{
int ret;
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index c2b45f3..bca7070 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -104,28 +104,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon,
unsigned long long *remaining,
unsigned long long *total);
-int qemuMonitorJSONMigrateToFd(qemuMonitorPtr mon,
- unsigned int flags,
- int fd);
-
-int qemuMonitorJSONMigrateToHost(qemuMonitorPtr mon,
- unsigned int flags,
- const char *hostname,
- int port);
-
-int qemuMonitorJSONMigrateToCommand(qemuMonitorPtr mon,
- unsigned int flags,
- const char * const *argv);
-
-int qemuMonitorJSONMigrateToFile(qemuMonitorPtr mon,
- unsigned int flags,
- const char * const *argv,
- const char *target,
- unsigned long long offset);
-
-int qemuMonitorJSONMigrateToUnix(qemuMonitorPtr mon,
- unsigned int flags,
- const char *unixfile);
+int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
+ unsigned int flags,
+ const char *uri);
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon);
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 3c9f799..f6275b2 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -1205,9 +1205,9 @@ cleanup:
}
-static int qemuMonitorTextMigrate(qemuMonitorPtr mon,
- unsigned int flags,
- const char *dest)
+int qemuMonitorTextMigrate(qemuMonitorPtr mon,
+ unsigned int flags,
+ const char *dest)
{
char *cmd = NULL;
char *info = NULL;
@@ -1272,141 +1272,6 @@ cleanup:
return ret;
}
-int qemuMonitorTextMigrateToFd(qemuMonitorPtr mon,
- unsigned int flags,
- int fd)
-{
- int ret;
-
- if (qemuMonitorTextSendFileHandle(mon, "migrate", fd) < 0)
- return -1;
-
- ret = qemuMonitorTextMigrate(mon, flags, "fd:migrate");
-
- if (ret < 0) {
- if (qemuMonitorTextCloseFileHandle(mon, "migrate") < 0)
- VIR_WARN0("failed to close migration handle");
- }
-
- return ret;
-}
-
-int qemuMonitorTextMigrateToHost(qemuMonitorPtr mon,
- unsigned int flags,
- const char *hostname,
- int port)
-{
- char *uri = NULL;
- int ret;
-
- if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) {
- virReportOOMError();
- return -1;
- }
-
- ret = qemuMonitorTextMigrate(mon, flags, uri);
-
- VIR_FREE(uri);
-
- return ret;
-}
-
-
-int qemuMonitorTextMigrateToCommand(qemuMonitorPtr mon,
- unsigned int flags,
- const char * const *argv)
-{
- char *argstr;
- char *dest = NULL;
- int ret = -1;
-
- argstr = virArgvToString(argv);
- if (!argstr) {
- virReportOOMError();
- goto cleanup;
- }
-
- if (virAsprintf(&dest, "exec:%s", argstr) < 0) {
- virReportOOMError();
- goto cleanup;
- }
-
- ret = qemuMonitorTextMigrate(mon, flags, dest);
-
-cleanup:
- VIR_FREE(argstr);
- VIR_FREE(dest);
- return ret;
-}
-
-int qemuMonitorTextMigrateToFile(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;
-
- argstr = virArgvToString(argv);
- if (!argstr) {
- virReportOOMError();
- goto cleanup;
- }
-
- /* Migrate to file */
- safe_target = qemuMonitorEscapeShell(target);
- if (!safe_target) {
- virReportOOMError();
- goto cleanup;
- }
-
- /* 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) {
- virReportOOMError();
- goto cleanup;
- }
-
- ret = qemuMonitorTextMigrate(mon, flags, dest);
-
-cleanup:
- VIR_FREE(safe_target);
- VIR_FREE(argstr);
- VIR_FREE(dest);
- return ret;
-}
-
-int qemuMonitorTextMigrateToUnix(qemuMonitorPtr mon,
- unsigned int flags,
- const char *unixfile)
-{
- char *dest = NULL;
- int ret = -1;
-
- if (virAsprintf(&dest, "unix:%s", unixfile) < 0) {
- virReportOOMError();
- return -1;
- }
-
- ret = qemuMonitorTextMigrate(mon, flags, dest);
-
- VIR_FREE(dest);
-
- return ret;
-}
-
int qemuMonitorTextMigrateCancel(qemuMonitorPtr mon)
{
char *info = NULL;
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
index f1b53fc..c2a85b7 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -102,28 +102,9 @@ int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon,
unsigned long long *remaining,
unsigned long long *total);
-int qemuMonitorTextMigrateToFd(qemuMonitorPtr mon,
- unsigned int flags,
- int fd);
-
-int qemuMonitorTextMigrateToHost(qemuMonitorPtr mon,
- unsigned int flags,
- const char *hostname,
- int port);
-
-int qemuMonitorTextMigrateToCommand(qemuMonitorPtr mon,
- unsigned int flags,
- const char * const *argv);
-
-int qemuMonitorTextMigrateToFile(qemuMonitorPtr mon,
- unsigned int flags,
- const char * const *argv,
- const char *target,
- unsigned long long offset);
-
-int qemuMonitorTextMigrateToUnix(qemuMonitorPtr mon,
- unsigned int flags,
- const char *unixfile);
+int qemuMonitorTextMigrate(qemuMonitorPtr mon,
+ unsigned int flags,
+ const char *uri);
int qemuMonitorTextMigrateCancel(qemuMonitorPtr mon);
--
1.7.4