[PATCH 2/2] auto cold migration fallback at timeout

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

 



implement auto cold migration fallback at timeout

Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx>

---
 tools/virsh.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 441fd77..c6b9009 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -54,6 +54,7 @@
 #include "files.h"
 #include "../daemon/event.h"
 #include "configmake.h"
+#include "timer.h"
 
 static char *progname;
 
@@ -3377,9 +3378,32 @@ static const vshCmdOptDef opts_migrate[] = {
     {"desturi", VSH_OT_DATA, VSH_OFLAG_REQ, N_("connection URI of the destination host")},
     {"migrateuri", VSH_OT_DATA, 0, N_("migration URI, usually can be omitted")},
     {"dname", VSH_OT_DATA, 0, N_("rename to new name during migration (if supported)")},
+    {"timeout", VSH_OT_INT, VSH_OFLAG_REQ, N_("auto cold migration fallback when live migration timeouts(in seconds)")},
     {NULL, 0, 0, NULL}
 };
 
+static void migrateTimeoutHandler(void *data)
+{
+    virDomainPtr dom = (virDomainPtr)data;
+    virDomainInfo info;
+    unsigned int id;
+
+    id = virDomainGetID(dom);
+    if (id == ((unsigned int)-1))
+        return;
+
+    /* The error reason has been reported in virDomainGetInfo() and
+     * virDomainSuspend() when it fails. So we do not check the return value.
+     */
+    if (virDomainGetInfo(dom, &info) == 0) {
+        if (info.state == VIR_DOMAIN_SHUTOFF)
+            return;
+
+        /* suspend the domain when migration timeouts. */
+        virDomainSuspend(dom);
+    }
+}
+
 static int
 cmdMigrate (vshControl *ctl, const vshCmd *cmd)
 {
@@ -3387,6 +3411,8 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
     const char *desturi;
     const char *migrateuri;
     const char *dname;
+    long long timeout;
+    virTimerPtr migratetimer = NULL;
     int flags = 0, found, ret = FALSE;
 
     if (!vshConnectionUsability (ctl, ctl->conn))
@@ -3424,6 +3450,23 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptBool (cmd, "copy-storage-inc"))
         flags |= VIR_MIGRATE_NON_SHARED_INC;
 
+    timeout = vshCommandOptLongLong(cmd, "timeout", &found);
+    if (found) {
+        if (! flags & VIR_MIGRATE_LIVE) {
+            vshError(ctl, "%s", _("migrate: Unexpected timeout for cold migration"));
+            goto done;
+        }
+
+        if (timeout < 1) {
+            vshError(ctl, "%s", _("migrate: Invalid timeout"));
+            goto done;
+        }
+
+        migratetimer = virNewTimer(migrateTimeoutHandler, (void *)dom);
+        if (!migratetimer)
+            goto done;
+    }
+
     if ((flags & VIR_MIGRATE_PEER2PEER) ||
         vshCommandOptBool (cmd, "direct")) {
         /* For peer2peer migration or direct migration we only expect one URI
@@ -3434,6 +3477,9 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
             goto done;
         }
 
+        if (migratetimer)
+            virModTimer(migratetimer, get_clock() + timeout * 1000000000ULL);
+
         if (virDomainMigrateToURI (dom, desturi, flags, dname, 0) == 0)
             ret = TRUE;
     } else {
@@ -3444,6 +3490,9 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
         dconn = virConnectOpenAuth (desturi, virConnectAuthPtrDefault, 0);
         if (!dconn) goto done;
 
+        if (migratetimer)
+            virModTimer(migratetimer, get_clock() + timeout * 1000000000ULL);
+
         ddom = virDomainMigrate (dom, dconn, flags, dname, migrateuri, 0);
         if (ddom) {
             virDomainFree(ddom);
@@ -3453,6 +3502,10 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
     }
 
  done:
+    if (migratetimer) {
+        virDelTimer(migratetimer);
+        virFreeTimer(migratetimer);
+    }
     if (dom) virDomainFree (dom);
     return ret;
 }
-- 
1.7.1

--
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]