[PATCHv4 02/15] qemu: consolidate duplicated monitor migration code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* 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 (qemuMonitorTextMigrateToHost)
(qemuMonitorTextMigrateToCommand, qemuMonitorTextMigrateToFile)
(qemuMonitorTextMigrateToUnix): Delete.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONMigrateToHost)
(qemuMonitorJSONMigrateToCommand, qemuMonitorJSONMigrateToFile)
(qemuMonitorJSONMigrateToUnix): Delete.
* src/qemu/qemu_monitor.c (qemuMonitorMigrateToHost)
(qemuMonitorMigrateToCommand, qemuMonitorMigrateToFile)
(qemuMonitorMigrateToUnix): Consolidate shared code.
---
 src/qemu/qemu_monitor.c      |   92 +++++++++++++++++++++++++++----
 src/qemu/qemu_monitor_json.c |  125 +----------------------------------------
 src/qemu/qemu_monitor_json.h |   23 +------
 src/qemu/qemu_monitor_text.c |  123 +----------------------------------------
 src/qemu/qemu_monitor_text.h |   23 +------
 5 files changed, 97 insertions(+), 289 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index dfb1aad..eb6f8d4 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1390,6 +1390,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);

@@ -1399,10 +1400,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;
 }

@@ -1411,7 +1420,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);

@@ -1421,10 +1432,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;
 }

@@ -1434,7 +1460,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);

@@ -1451,10 +1480,43 @@ 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 bs=%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,
+                    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;
 }

@@ -1462,7 +1524,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);

@@ -1472,10 +1535,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 e6903a1..5cf35b9 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1,7 +1,7 @@
 /*
  * qemu_monitor_json.c: interaction with QEMU monitor console
  *
- * Copyright (C) 2006-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2011 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -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,123 +1696,6 @@ static int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
     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 bs=%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,
-                    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 4ae472a..bca7070 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -1,7 +1,7 @@
 /*
  * qemu_monitor_json.h: interaction with QEMU monitor console
  *
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2009, 2011 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -104,24 +104,9 @@ int qemuMonitorJSONGetMigrationStatus(qemuMonitorPtr mon,
                                       unsigned long long *remaining,
                                       unsigned long long *total);

-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 0aed690..9b93e1c 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -1,7 +1,7 @@
 /*
  * qemu_monitor_text.c: interaction with QEMU monitor console
  *
- * Copyright (C) 2006-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2011 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -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;
@@ -1271,121 +1271,6 @@ cleanup:
     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 bs=%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,
-                    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 b29dbcc..c2a85b7 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -1,7 +1,7 @@
 /*
  * qemu_monitor_text.h: interaction with QEMU monitor console
  *
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2009, 2011 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -102,24 +102,9 @@ int qemuMonitorTextGetMigrationStatus(qemuMonitorPtr mon,
                                       unsigned long long *remaining,
                                       unsigned long long *total);

-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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]