Migration support
authorroot <root@xenapi.xen>
Sun, 5 Oct 2008 03:24:24 +0000 (5 05:24 +0200)
committerroot <root@xenapi.xen>
Sun, 5 Oct 2008 03:24:24 +0000 (5 05:24 +0200)
Signal TERM is send, we will not accept any new offers.

node/avahi.c
node/main.c
node/migrate.c [new file with mode: 0644]
node/publish.c

index 9cbd2fa..3e6d645 100644 (file)
@@ -53,12 +53,12 @@ static void modify_callback(AvahiTimeout *e, void *userdata) {
      * service and create it anew */
 
     if (avahi_client_get_state(client) != AVAHI_CLIENT_FAILURE) {
-        /* And create them again with the new name */
-        struct timeval tv;
+            /* And create them again with the new name */
+            struct timeval tv;
 
-        create_services(client);
+            create_services(client);
 
-        avahi_simple_poll_get(simple_poll)->timeout_update(e, avahi_elapse_time(&tv, 1000*POLL, 0));
+            avahi_simple_poll_get(simple_poll)->timeout_update(e, avahi_elapse_time(&tv, 1000*POLL, 0));
     }
 }
 
@@ -121,7 +121,7 @@ void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED vo
                                           * name on the network, so it's time to create our services */
                                          struct timeval tv;
 
-                                         if (!avahi_service_browser_new(c, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_offer._tcp", NULL, 0, browse_callback, NULL)) {
+                                         if (! (offerServiceBrowser = avahi_service_browser_new(c, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_offer._tcp", NULL, 0, browse_callback, NULL))) {
                                              fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(c)));
                                          }
 
index 8fef498..fce15cf 100644 (file)
@@ -3,19 +3,28 @@
 
 #include <avahi-client/client.h>
 #include <avahi-common/simple-watch.h>
+#include <signal.h>
 
 #include "node.h"
 
+void terminate(int sig) {
+    if (offerServiceBrowser)
+        avahi_service_browser_free(offerServiceBrowser);
+
+}
+
 int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) {
     /* Allocate main loop object */
     if (!(simple_poll = avahi_simple_poll_new())) {
         fprintf(stderr, "Failed to create simple poll object.\n");
         goto fail;
     }
-    
+
     /* The client that is going to do the work */
     client_callback(NULL, AVAHI_CLIENT_FAILURE, NULL);
 
+    signal(SIGTERM, terminate);
+
     /* Run the main loop */
     avahi_simple_poll_loop(simple_poll);
 
diff --git a/node/migrate.c b/node/migrate.c
new file mode 100644 (file)
index 0000000..b2c944e
--- /dev/null
@@ -0,0 +1,49 @@
+#include <avahi-client/publish.h>
+#include <avahi-client/lookup.h>
+
+#include <avahi-common/alternative.h>
+#include <avahi-common/simple-watch.h>
+#include <avahi-common/malloc.h>
+#include <avahi-common/error.h>
+#include <avahi-common/timeval.h>
+#include <avahi-common/strlst.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <libvirt/libvirt.h>
+
+#include "../handler_virt_tender.h"
+
+int migrate_domain(AvahiClient *client, virDomainPtr dom) {
+    int ret = -1;
+    unsigned long memory;
+    char *target;
+    char destination[1024];
+    virConnectPtr dconn;
+
+    memory = virDomainGetMaxMemory(dom);
+    target = create_tender(client, NULL, virDomainGetName(dom), virDomainGetMaxMemory(dom));
+
+    snprintf(destination, 1022, "xen://%s/", target);
+    destination[1023] = '\0';
+    free(target);
+
+    dconn = virConnectOpen(destination);
+
+    if (dconn) {
+        virDomainPtr desDom;
+
+        desDom = virDomainMigrate(dom, dconn, VIR_MIGRATE_LIVE, NULL, NULL, 1000);
+
+        if (desDom) {
+            ret = 0;
+            virDomainFree(desDom);
+        }
+
+        virConnectClose(dconn);
+    }
+
+    return ret;
+}
index f949bc7..63750f6 100644 (file)
@@ -68,6 +68,31 @@ void remove_everything() {
     }
 }
 
+void migrate_everything(AvahiClient *c) {
+    if (domus) {
+        virConnectPtr conn;
+        conn = virConnectOpen(NULL);
+
+        if (conn) {
+            int i;
+            for (i = 0; i < domu_count; i++) {
+                virDomainPtr dom;
+                dom = virDomainLookupByID (conn, domus[i].domainid);
+
+                if (dom) {
+                    if (migrate_domain(c, dom) != 0) {
+                        virDomainShutdown(dom); 
+                    }
+
+                    virDomainFree(dom);
+                }
+
+            }
+            virConnectClose(conn);
+        }
+    }
+}
+
 
 void create_services(AvahiClient *c) {
     virConnectPtr conn = virConnectOpenReadOnly(NULL);