Windows: cm_UpdateIFInfo consolidate syscfg_GetIFInfo calls
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 4 Sep 2014 13:04:42 +0000 (09:04 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Wed, 24 Sep 2014 22:16:05 +0000 (18:16 -0400)
Add a new function cm_UpdateIFInfo() that consolidates all of the
syscfg_GetIFInfo() call functionality into a single rountine.  Replace
all of the existing call sites.

It is safe to call cm_UpdateIFInfo() without holding cm_syscfgLock
during afsd initialization because no other threads have been created.

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

src/WINNT/afsd/afsd_init.c
src/WINNT/afsd/cm_callback.c
src/WINNT/afsd/cm_server.c
src/WINNT/afsd/cm_server.h

index 5ef1aeb..4c67674 100644 (file)
@@ -533,11 +533,6 @@ afsd_InitCM(char **reasonP)
     /*int freelanceEnabled;*/
     WSADATA WSAjunk;
     int i;
-    int cm_noIPAddr;         /* number of client network interfaces */
-    int cm_IPAddr[CM_MAXINTERFACE_ADDR];    /* client's IP address in host order */
-    int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
-    int cm_NetMtu[CM_MAXINTERFACE_ADDR];    /* client's MTU sizes */
-    int cm_NetFlags[CM_MAXINTERFACE_ADDR];  /* network flags */
     DWORD dwPriority;
     OSVERSIONINFO osVersion;
 
@@ -1444,11 +1439,7 @@ afsd_InitCM(char **reasonP)
     cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
 
     /* get network related info */
-    cm_noIPAddr = CM_MAXINTERFACE_ADDR;
-    code = syscfg_GetIFInfo(&cm_noIPAddr,
-                             cm_IPAddr, cm_SubnetMask,
-                             cm_NetMtu, cm_NetFlags);
-
+    code = cm_UpdateIFInfo();
     if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
         afsi_log("syscfg_GetIFInfo error code %d", code);
     else
index ae89f10..5816bbe 100644 (file)
@@ -948,14 +948,9 @@ SRXAFSCB_WhoAreYou(struct rx_call *callp, struct interfaceAddr* addr)
     lock_ObtainRead(&cm_syscfgLock);
     if (cm_LanAdapterChangeDetected) {
         lock_ConvertRToW(&cm_syscfgLock);
-        if (cm_LanAdapterChangeDetected) {
-            /* get network related info */
-            cm_noIPAddr = CM_MAXINTERFACE_ADDR;
-            code = syscfg_GetIFInfo(&cm_noIPAddr,
-                                     cm_IPAddr, cm_SubnetMask,
-                                     cm_NetMtu, cm_NetFlags);
-            cm_LanAdapterChangeDetected = 0;
-        }
+       if (cm_LanAdapterChangeDetected) {
+           code = cm_UpdateIFInfo();
+       }
         lock_ConvertWToR(&cm_syscfgLock);
     }
 
@@ -1255,12 +1250,7 @@ SRXAFSCB_TellMeAboutYourself( struct rx_call *callp,
     if (cm_LanAdapterChangeDetected) {
         lock_ConvertRToW(&cm_syscfgLock);
         if (cm_LanAdapterChangeDetected) {
-            /* get network related info */
-            cm_noIPAddr = CM_MAXINTERFACE_ADDR;
-            code = syscfg_GetIFInfo(&cm_noIPAddr,
-                                     cm_IPAddr, cm_SubnetMask,
-                                     cm_NetMtu, cm_NetFlags);
-            cm_LanAdapterChangeDetected = 0;
+           code = cm_UpdateIFInfo();
         }
         lock_ConvertWToR(&cm_syscfgLock);
     }
index cf0bba8..8fdb32a 100644 (file)
@@ -874,25 +874,32 @@ void cm_SetServerNoInlineBulk(cm_server_t * serverp, int no)
     lock_ReleaseMutex(&serverp->mx);
 }
 
+afs_int32 cm_UpdateIFInfo(void)
+{
+    afs_int32 code;
+    /* get network related info */
+    cm_noIPAddr = CM_MAXINTERFACE_ADDR;
+    code = syscfg_GetIFInfo(&cm_noIPAddr,
+                            cm_IPAddr, cm_SubnetMask,
+                            cm_NetMtu, cm_NetFlags);
+    cm_LanAdapterChangeDetected = 0;
+    return code;
+}
+
 void cm_SetServerIPRank(cm_server_t * serverp)
 {
     unsigned long      serverAddr;     /* in host byte order */
     unsigned long      myAddr, myNet, mySubnet;/* in host byte order */
     unsigned long      netMask;
     int                i;
-    long code;
+    afs_int32          code;
 
     lock_ObtainRead(&cm_syscfgLock);
     if (cm_LanAdapterChangeDetected) {
         lock_ConvertRToW(&cm_syscfgLock);
         if (cm_LanAdapterChangeDetected) {
-            /* get network related info */
-            cm_noIPAddr = CM_MAXINTERFACE_ADDR;
-            code = syscfg_GetIFInfo(&cm_noIPAddr,
-                                     cm_IPAddr, cm_SubnetMask,
-                                     cm_NetMtu, cm_NetFlags);
-            cm_LanAdapterChangeDetected = 0;
-        }
+           code = cm_UpdateIFInfo();
+       }
         lock_ConvertWToR(&cm_syscfgLock);
     }
 
index 302655a..c779db2 100644 (file)
@@ -123,6 +123,8 @@ extern void cm_RankUpServers();
 
 extern void cm_SetServerIPRank(cm_server_t * serverp);
 
+extern afs_int32 cm_UpdateIFInfo(void);
+
 extern void cm_InsertServerList(cm_serverRef_t** list,cm_serverRef_t* element);
 
 extern long cm_ChangeRankServer(cm_serverRef_t** list, cm_server_t* server);