Windows: improve shutdown time
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 20 Jul 2011 18:21:09 +0000 (14:21 -0400)
committerJeffrey Altman <jaltman@openafs.org>
Fri, 22 Jul 2011 15:55:29 +0000 (08:55 -0700)
During Windows OS shutdown the service may be given as little
as six seconds to shut itself down before it will be terminated.
Forced termination will leave the cache file in a dirty state.
This patchset makes several minor changes to reduce the overall
time required for shutdown:

1. do not wait for the IP address change notification thread.
   by the time it terminates the ip address has been lost.

2. send give up all callbacks earlier.

3. reorder the daemon thread waits.

4. change the daemon thread loop sleep time to 500ms in order
   to prevent the service from waiting up to 10 seconds for
   the thread to notice a shutdown is in progress.

Change-Id: Ib1ff3eaf2e5116d9b3d7561670b8266e1bc5d1cf
Reviewed-on: http://gerrit.openafs.org/5055
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>

src/WINNT/afsd/cm_daemon.c
src/WINNT/afsd/cm_scache.c

index 59f1ae4..6de9b0c 100644 (file)
@@ -524,8 +524,9 @@ void cm_Daemon(long parm)
 
         if (bAddrChangeCheck &&
             daemon_ShutdownFlag == 0 &&
-            powerStateSuspended == 0)
+            powerStateSuspended == 0) {
             cm_ForceNewConnectionsAllServers();
+        }
 
         /* check up servers */
         if ((bAddrChangeCheck || now > lastUpServerCheck + cm_daemonCheckUpInterval) &&
@@ -648,8 +649,14 @@ void cm_Daemon(long parm)
            now = osi_Time();
         }
 
-        thrd_Sleep(10000);             /* sleep 10 seconds */
+        /*
+         * sleep .5 seconds.  if the thread blocks for a long time
+         * we risk not being able to close the cache before Windows
+         * kills our process during system shutdown.
+         */
+        thrd_Sleep(500);
     }
+
     thrd_SetEvent(cm_Daemon_ShutdownEvent);
 }
 
@@ -662,19 +669,27 @@ void cm_DaemonShutdown(void)
     osi_Wakeup((LONG_PTR) &cm_bkgListp);
 
     /* wait for shutdown */
+    for ( i=0; i<cm_nDaemons; i++) {
+        if (cm_BkgDaemon_ShutdownEvent[i])
+            code = thrd_WaitForSingleObject_Event(cm_BkgDaemon_ShutdownEvent[i], INFINITE);
+    }
+
     if (cm_Daemon_ShutdownEvent)
         code = thrd_WaitForSingleObject_Event(cm_Daemon_ShutdownEvent, INFINITE);
 
     if (cm_LockDaemon_ShutdownEvent)
         code = thrd_WaitForSingleObject_Event(cm_LockDaemon_ShutdownEvent, INFINITE);
 
-    for ( i=0; i<cm_nDaemons; i++) {
-        if (cm_BkgDaemon_ShutdownEvent[i])
-            code = thrd_WaitForSingleObject_Event(cm_BkgDaemon_ShutdownEvent[i], INFINITE);
-    }
-
+#if 0
+    /*
+     * Do not waste precious time waiting for the ipaddr daemon to shutdown.
+     * When it does it means we have lost our network connection and we need
+     * it during cache shutdown in order to notify the file servers that this
+     * client is giving up all callbacks.
+     */
     if (cm_IPAddrDaemon_ShutdownEvent)
         code = thrd_WaitForSingleObject_Event(cm_IPAddrDaemon_ShutdownEvent, INFINITE);
+#endif
 }
 
 void cm_InitDaemon(int nDaemons)
index b1ac261..ffbce16 100644 (file)
@@ -579,6 +579,8 @@ cm_ShutdownSCache(void)
 {
     cm_scache_t * scp;
 
+    cm_GiveUpAllCallbacksAllServersMulti(FALSE);
+
     lock_ObtainWrite(&cm_scacheLock);
 
     for ( scp = cm_data.allSCachesp; scp;
@@ -610,8 +612,6 @@ cm_ShutdownSCache(void)
     }
     lock_ReleaseWrite(&cm_scacheLock);
 
-    cm_GiveUpAllCallbacksAllServersMulti(FALSE);
-
     return cm_dnlcShutdown();
 }