Windows: Setting Server Preferences
authorJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 11 Aug 2009 12:59:39 +0000 (08:59 -0400)
committerJeffrey Altman <jaltman@openafs.org>
Tue, 11 Aug 2009 15:08:35 +0000 (08:08 -0700)
The Windows cache manager can apply administrator specified
server preferences as specified in the registry.   When these
rankings are applied the CM_SERVERFLAG_PREF_SET flag was not
set on the cm_server_t object.  In addition, appropriate locking
was not being used in the places where the flag was set.

LICENSE MIT

Reviewed-on: http://gerrit.openafs.org/303
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>

src/WINNT/afsd/afsd_init.c
src/WINNT/afsd/cm_ioctl.c

index 455a03a..d6d1d46 100644 (file)
@@ -303,7 +303,10 @@ static void afsd_InitServerPreferences(void)
             tsp = cm_FindServer(&saddr, CM_SERVER_VLDB);
             if ( tsp )         /* an existing server - ref count increased */
             {
-                tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
+                lock_ObtainMutex(&tsp->mx);
+                tsp->ipRank = (USHORT)dwRank;
+                tsp->flags |= CM_SERVERFLAG_PREF_SET;
+                lock_ReleaseMutex(&tsp->mx);
 
                 /* set preferences for an existing vlserver */
                 cm_ChangeRankCellVLServer(tsp);
@@ -312,7 +315,10 @@ static void afsd_InitServerPreferences(void)
             else       /* add a new server without a cell */
             {
                 tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
+                lock_ObtainMutex(&tsp->mx);
                 tsp->ipRank = (USHORT)dwRank;
+                tsp->flags |= CM_SERVERFLAG_PREF_SET;
+                lock_ReleaseMutex(&tsp->mx);
             }
         }
 
@@ -370,7 +376,10 @@ static void afsd_InitServerPreferences(void)
             tsp = cm_FindServer(&saddr, CM_SERVER_FILE);
             if ( tsp )         /* an existing server - ref count increased */
             {
-                tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
+                lock_ObtainMutex(&tsp->mx);
+                tsp->ipRank = (USHORT)dwRank;
+                tsp->flags |= CM_SERVERFLAG_PREF_SET;
+                lock_ReleaseMutex(&tsp->mx);
 
                 /* find volumes which might have RO copy 
                 /* on server and change the ordering of 
@@ -382,7 +391,10 @@ static void afsd_InitServerPreferences(void)
             else       /* add a new server without a cell */
             {
                 tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
+                lock_ObtainMutex(&tsp->mx);
                 tsp->ipRank = (USHORT)dwRank;
+                tsp->flags |= CM_SERVERFLAG_PREF_SET;
+                lock_ReleaseMutex(&tsp->mx);
             }
         }
 
index 495d239..66fce80 100644 (file)
@@ -1753,30 +1753,35 @@ cm_IoctlSetSPrefs(struct cm_ioctl *ioctlp, struct cm_user *userp)
         tsp = cm_FindServer(&tmp, type);
         if ( tsp )             /* an existing server - ref count increased */
         {
-            tsp->ipRank = rank; /* no need to protect by mutex*/
-
-            if (type == CM_SERVER_FILE)
-            {   /* fileserver */
-                /* find volumes which might have RO copy 
-                /* on server and change the ordering of 
+            lock_ObtainMutex(&tsp->mx);
+            tsp->ipRank = rank;
+            tsp->flags |= CM_SERVERFLAG_PREF_SET;
+            lock_ReleaseMutex(&tsp->mx);
+
+            switch (type) {
+            case CM_SERVER_FILE:
+                /*
+                 * find volumes which might have RO copy
+                 * on server and change the ordering of 
                  * their RO list 
                  */
                 cm_ChangeRankVolume(tsp);
-            }
-            else       
-            {
+                break;
+            case CM_SERVER_VLDB:
                 /* set preferences for an existing vlserver */
                 cm_ChangeRankCellVLServer(tsp);
+                break;
             }
         }
         else   /* add a new server without a cell */
         {
             tsp = cm_NewServer(&tmp, type, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
+            lock_ObtainMutex(&tsp->mx);
+            tsp->ipRank = rank;
+            tsp->flags |= CM_SERVERFLAG_PREF_SET;
+            lock_ReleaseMutex(&tsp->mx);
             tsp->ipRank = rank;
         }
-       lock_ObtainMutex(&tsp->mx);
-       tsp->flags |= CM_SERVERFLAG_PREF_SET;
-       lock_ReleaseMutex(&tsp->mx);
        cm_PutServer(tsp);  /* decrease refcount */
     }
     return 0;