Windows: power management suspend/resume changes
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 4 Sep 2014 13:16:47 +0000 (09:16 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Wed, 24 Sep 2014 22:16:56 +0000 (18:16 -0400)
1. Call cm_UpdateIFInfo() for all power management events to force
   an update of the valid network interface count.

2. Ensure that regardless of which Suspend and Resume events are
   generated that the service only suspends once and resumes once.

Change-Id: If0c2fe5b6a18dd6b7ee01b511378cb78837efa3d
Reviewed-on: http://gerrit.openafs.org/11447
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsd/afsd_service.c

index e819f0e..3ae290a 100644 (file)
@@ -336,7 +336,9 @@ afsd_ServiceControlHandlerEx(
             ** i.e. as if returning BROADCAST_QUERY_DENY
             */
             if (powerEventsRegistered) {
-                switch((int) dwEventType)
+               cm_UpdateIFInfo();
+
+               switch((int) dwEventType)
                 {
                 case PBT_APMQUERYSUSPEND:
                     afsi_log("SERVICE_CONTROL_APMQUERYSUSPEND");
@@ -363,14 +365,15 @@ afsd_ServiceControlHandlerEx(
                 case PBT_APMSUSPEND:
                     afsi_log("SERVICE_CONTROL_APMSUSPEND");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMSUSPEND");
-                   powerStateSuspended = 1;
-                   if (osVersion.dwMajorVersion >= 6)
-                       smb_StopListeners(0);
-
-                    if (RDR_Initialized)
-                        RDR_Suspend();
-                    cm_SuspendSCache();
-
+                   if (!powerStateSuspended) {
+                       powerStateSuspended = 1;
+                       if (osVersion.dwMajorVersion >= 6)
+                           smb_StopListeners(0);
+
+                       if (RDR_Initialized)
+                           RDR_Suspend();
+                       cm_SuspendSCache();
+                   }
                     dwRet = NO_ERROR;
                     afsi_log("SERVICE_CONTROL_APMSUSPEND complete");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMSUSPEND complete");
@@ -378,12 +381,14 @@ afsd_ServiceControlHandlerEx(
                 case PBT_APMSTANDBY:
                     afsi_log("SERVICE_CONTROL_APMSTANDBY");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMSTANDBY");
-                   powerStateSuspended = 1;
-                   if (osVersion.dwMajorVersion >= 6)
-                       smb_StopListeners(0);
-                    if (RDR_Initialized)
-                        RDR_Suspend();
-                    cm_SuspendSCache();
+                   if (!powerStateSuspended) {
+                       powerStateSuspended = 1;
+                       if (osVersion.dwMajorVersion >= 6)
+                           smb_StopListeners(0);
+                       if (RDR_Initialized)
+                           RDR_Suspend();
+                       cm_SuspendSCache();
+                   }
                     dwRet = NO_ERROR;
                     afsi_log("SERVICE_CONTROL_APMSTANDBY complete");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMSTANDBY complete");
@@ -391,11 +396,15 @@ afsd_ServiceControlHandlerEx(
                 case PBT_APMRESUMECRITICAL:
                     afsi_log("SERVICE_CONTROL_APMRESUMECRITICAL");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMRESUMECRITICAL");
-                   if (osVersion.dwMajorVersion >= 6)
-                       smb_RestartListeners(0);
-                    cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, NULL);
-                    if (RDR_Initialized)
-                        RDR_Resume();
+                   if (powerStateSuspended) {
+                       powerStateSuspended = 0;
+                       if (osVersion.dwMajorVersion >= 6)
+                           smb_RestartListeners(0);
+                       cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS
+                                        | CM_FLAG_CHECKUPSERVERS, NULL);
+                       if (RDR_Initialized)
+                           RDR_Resume();
+                   }
                     dwRet = NO_ERROR;
                     afsi_log("SERVICE_CONTROL_APMRESUMECRITICAL complete");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMRESUMECRITICAL complete");
@@ -404,15 +413,18 @@ afsd_ServiceControlHandlerEx(
                    /* User logged in after suspend */
                     afsi_log("SERVICE_CONTROL_APMRESUMESUSPEND");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMRESUMESUSPEND");
-                   powerStateSuspended = 0;
-                    cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, NULL);
-                   if (osVersion.dwMajorVersion >= 6)
-                       smb_RestartListeners(0);
-                   if (smb_Enabled && osVersion.dwMajorVersion >= 6) {
-                       smb_SetLanAdapterChangeDetected();
-                    }
-                    if (RDR_Initialized)
-                        RDR_Resume();
+                   if (powerStateSuspended) {
+                       powerStateSuspended = 0;
+                       cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS
+                                        | CM_FLAG_CHECKUPSERVERS, NULL);
+                       if (osVersion.dwMajorVersion >= 6)
+                           smb_RestartListeners(0);
+                       if (smb_Enabled && osVersion.dwMajorVersion >= 6) {
+                           smb_SetLanAdapterChangeDetected();
+                       }
+                       if (RDR_Initialized)
+                           RDR_Resume();
+                   }
                     dwRet = NO_ERROR;
                     afsi_log("SERVICE_CONTROL_APMRESUMESUSPEND complete");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMRESUMESUSPEND complete");
@@ -421,15 +433,18 @@ afsd_ServiceControlHandlerEx(
                    /* User logged in after standby */
                     afsi_log("SERVICE_CONTROL_APMRESUMESTANDBY");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMRESUMESTANDBY");
-                   powerStateSuspended = 0;
-                    cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, NULL);
-                   if (osVersion.dwMajorVersion >= 6)
-                       smb_RestartListeners(0);
-                   if (smb_Enabled && osVersion.dwMajorVersion >= 6) {
-                       smb_SetLanAdapterChangeDetected();
-                    }
-                    if (RDR_Initialized)
-                        RDR_Resume();
+                   if (powerStateSuspended) {
+                       powerStateSuspended = 0;
+                       cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS
+                                        | CM_FLAG_CHECKUPSERVERS, NULL);
+                       if (osVersion.dwMajorVersion >= 6)
+                           smb_RestartListeners(0);
+                       if (smb_Enabled && osVersion.dwMajorVersion >= 6) {
+                           smb_SetLanAdapterChangeDetected();
+                       }
+                       if (RDR_Initialized)
+                           RDR_Resume();
+                   }
                     dwRet = NO_ERROR;
                     afsi_log("SERVICE_CONTROL_APMRESUMESTANDBY complete");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMRESUMESTANDBY complete");
@@ -457,10 +472,18 @@ afsd_ServiceControlHandlerEx(
                    /* This is the message delivered once all devices are up */
                     afsi_log("SERVICE_CONTROL_APMRESUMEAUTOMATIC");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMRESUMEAUTOMATIC");
-                   if (smb_Enabled && osVersion.dwMajorVersion >= 6) {
-                       smb_SetLanAdapterChangeDetected();
-                    }
-                    cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, NULL);
+                   if (powerStateSuspended) {
+                       powerStateSuspended = 0;
+                       cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS
+                                        | CM_FLAG_CHECKUPSERVERS, NULL);
+                       if (osVersion.dwMajorVersion >= 6)
+                           smb_RestartListeners(0);
+                       if (smb_Enabled && osVersion.dwMajorVersion >= 6) {
+                           smb_SetLanAdapterChangeDetected();
+                       }
+                       if (RDR_Initialized)
+                           RDR_Resume();
+                   }
                     dwRet = NO_ERROR;
                     afsi_log("SERVICE_CONTROL_APMRESUMEAUTOMATIC complete");
                     osi_Log0(afsd_logp,"SERVICE_CONTROL_APMRESUMEAUTOMATIC complete");