render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Daniel P. Berrange 25ea2f
diff -rup libvirt-0.6.0.orig/qemud/event.c libvirt-0.6.0.new/qemud/event.c
Daniel P. Berrange 25ea2f
--- libvirt-0.6.0.orig/qemud/event.c	2008-12-22 13:02:54.000000000 +0000
Daniel P. Berrange 25ea2f
+++ libvirt-0.6.0.new/qemud/event.c	2009-02-06 19:29:28.000000000 +0000
Daniel P. Berrange c80b7f
@@ -68,6 +68,7 @@ struct virEventTimeout {
Daniel P. Berrange c80b7f
 /* State for the main event loop */
Daniel P. Berrange c80b7f
 struct virEventLoop {
Daniel P. Berrange c80b7f
     pthread_mutex_t lock;
Daniel P. Berrange c80b7f
+    int running;
Daniel P. Berrange c80b7f
     pthread_t leader;
Daniel P. Berrange c80b7f
     int wakeupfd[2];
Daniel P. Berrange c80b7f
     int handlesCount;
Daniel P. Berrange c80b7f
@@ -521,6 +522,7 @@ int virEventRunOnce(void) {
Daniel P. Berrange c80b7f
     int ret, timeout, nfds;
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
     virEventLock();
Daniel P. Berrange c80b7f
+    eventLoop.running = 1;
Daniel P. Berrange c80b7f
     eventLoop.leader = pthread_self();
Daniel P. Berrange c80b7f
     if ((nfds = virEventMakePollFDs(&fds)) < 0) {
Daniel P. Berrange c80b7f
         virEventUnlock();
Daniel P. Berrange c80b7f
@@ -572,7 +574,7 @@ int virEventRunOnce(void) {
Daniel P. Berrange c80b7f
         return -1;
Daniel P. Berrange c80b7f
     }
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
-    eventLoop.leader = 0;
Daniel P. Berrange c80b7f
+    eventLoop.running = 0;
Daniel P. Berrange c80b7f
     virEventUnlock();
Daniel P. Berrange c80b7f
     return 0;
Daniel P. Berrange c80b7f
 }
Daniel P. Berrange c80b7f
@@ -611,7 +613,9 @@ int virEventInit(void)
Daniel P. Berrange c80b7f
 static int virEventInterruptLocked(void)
Daniel P. Berrange c80b7f
 {
Daniel P. Berrange c80b7f
     char c = '\0';
Daniel P. Berrange c80b7f
-    if (pthread_self() == eventLoop.leader)
Daniel P. Berrange c80b7f
+
Daniel P. Berrange c80b7f
+    if (!eventLoop.running ||
Daniel P. Berrange c80b7f
+        pthread_self() == eventLoop.leader)
Daniel P. Berrange c80b7f
         return 0;
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
     if (safewrite(eventLoop.wakeupfd[1], &c, sizeof(c)) != sizeof(c))
Daniel P. Berrange 25ea2f
diff -rup libvirt-0.6.0.orig/qemud/qemud.c libvirt-0.6.0.new/qemud/qemud.c
Daniel P. Berrange 25ea2f
--- libvirt-0.6.0.orig/qemud/qemud.c	2009-01-31 09:04:17.000000000 +0000
Daniel P. Berrange 25ea2f
+++ libvirt-0.6.0.new/qemud/qemud.c	2009-02-06 19:29:28.000000000 +0000
Daniel P. Berrange c80b7f
@@ -2013,11 +2013,15 @@ static int qemudOneLoop(void) {
Daniel P. Berrange c80b7f
     return 0;
Daniel P. Berrange c80b7f
 }
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
-static void qemudInactiveTimer(int timer ATTRIBUTE_UNUSED, void *data) {
Daniel P. Berrange c80b7f
+static void qemudInactiveTimer(int timerid, void *data) {
Daniel P. Berrange c80b7f
     struct qemud_server *server = (struct qemud_server *)data;
Daniel P. Berrange c80b7f
-    DEBUG0("Got inactive timer expiry");
Daniel P. Berrange c80b7f
-    if (!virStateActive()) {
Daniel P. Berrange c80b7f
-        DEBUG0("No state active, shutting down");
Daniel P. Berrange c80b7f
+
Daniel P. Berrange c80b7f
+    if (virStateActive() ||
Daniel P. Berrange c80b7f
+        server->clients) {
Daniel P. Berrange c80b7f
+        DEBUG0("Timer expired but still active, not shutting down");
Daniel P. Berrange c80b7f
+        virEventUpdateTimeoutImpl(timerid, -1);
Daniel P. Berrange c80b7f
+    } else {
Daniel P. Berrange c80b7f
+        DEBUG0("Timer expired and inactive, shutting down");
Daniel P. Berrange c80b7f
         server->shutdown = 1;
Daniel P. Berrange c80b7f
     }
Daniel P. Berrange c80b7f
 }
Daniel P. Berrange c80b7f
@@ -2048,9 +2052,18 @@ static void qemudFreeClient(struct qemud
Daniel P. Berrange c80b7f
 static int qemudRunLoop(struct qemud_server *server) {
Daniel P. Berrange c80b7f
     int timerid = -1;
Daniel P. Berrange c80b7f
     int ret = -1, i;
Daniel P. Berrange c80b7f
+    int timerActive = 0;
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
     virMutexLock(&server->lock);
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
+    if (timeout > 0 &&
Daniel P. Berrange c80b7f
+        (timerid = virEventAddTimeoutImpl(-1,
Daniel P. Berrange c80b7f
+                                          qemudInactiveTimer,
Daniel P. Berrange c80b7f
+                                          server, NULL)) < 0) {
Daniel P. Berrange c80b7f
+        VIR_ERROR0(_("Failed to register shutdown timeout"));
Daniel P. Berrange c80b7f
+        return -1;
Daniel P. Berrange c80b7f
+    }
Daniel P. Berrange c80b7f
+
Daniel P. Berrange c80b7f
     if (min_workers > max_workers)
Daniel P. Berrange c80b7f
         max_workers = min_workers;
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
@@ -2071,11 +2084,21 @@ static int qemudRunLoop(struct qemud_ser
Daniel P. Berrange c80b7f
          * if any drivers have active state, if not
Daniel P. Berrange c80b7f
          * shutdown after timeout seconds
Daniel P. Berrange c80b7f
          */
Daniel P. Berrange c80b7f
-        if (timeout > 0 && !virStateActive() && !server->clients) {
Daniel P. Berrange c80b7f
-            timerid = virEventAddTimeoutImpl(timeout*1000,
Daniel P. Berrange c80b7f
-                                             qemudInactiveTimer,
Daniel P. Berrange c80b7f
-                                             server, NULL);
Daniel P. Berrange c80b7f
-            DEBUG("Scheduling shutdown timer %d", timerid);
Daniel P. Berrange c80b7f
+        if (timeout > 0) {
Daniel P. Berrange c80b7f
+            if (timerActive) {
Daniel P. Berrange c80b7f
+                if (server->clients) {
Daniel P. Berrange c80b7f
+                    DEBUG("Deactivating shutdown timer %d", timerid);
Daniel P. Berrange c80b7f
+                    virEventUpdateTimeoutImpl(timerid, -1);
Daniel P. Berrange c80b7f
+                    timerActive = 0;
Daniel P. Berrange c80b7f
+                }
Daniel P. Berrange c80b7f
+            } else {
Daniel P. Berrange c80b7f
+                if (!virStateActive() &&
Daniel P. Berrange c80b7f
+                    !server->clients) {
Daniel P. Berrange c80b7f
+                    DEBUG("Activating shutdown timer %d", timerid);
Daniel P. Berrange c80b7f
+                    virEventUpdateTimeoutImpl(timerid, timeout * 1000);
Daniel P. Berrange c80b7f
+                    timerActive = 1;
Daniel P. Berrange c80b7f
+                }
Daniel P. Berrange c80b7f
+            }
Daniel P. Berrange c80b7f
         }
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
         virMutexUnlock(&server->lock);
Daniel P. Berrange c80b7f
@@ -2129,15 +2152,6 @@ static int qemudRunLoop(struct qemud_ser
Daniel P. Berrange c80b7f
             }
Daniel P. Berrange c80b7f
         }
Daniel P. Berrange c80b7f
 
Daniel P. Berrange c80b7f
-        /* Unregister any timeout that's active, since we
Daniel P. Berrange c80b7f
-         * just had an event processed
Daniel P. Berrange c80b7f
-         */
Daniel P. Berrange c80b7f
-        if (timerid != -1) {
Daniel P. Berrange c80b7f
-            DEBUG("Removing shutdown timer %d", timerid);
Daniel P. Berrange c80b7f
-            virEventRemoveTimeoutImpl(timerid);
Daniel P. Berrange c80b7f
-            timerid = -1;
Daniel P. Berrange c80b7f
-        }
Daniel P. Berrange c80b7f
-
Daniel P. Berrange c80b7f
         if (server->shutdown) {
Daniel P. Berrange c80b7f
             ret = 0;
Daniel P. Berrange c80b7f
             break;