Windows: introduce cm_MarkServerDown
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 4 Sep 2014 13:11:25 +0000 (09:11 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Wed, 24 Sep 2014 22:16:31 +0000 (18:16 -0400)
Consolidate the operations necessary to mark a server down into a
new routine cm_MarkServerDown()

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

src/WINNT/afsd/cm_server.c

index 8fdb32a..68fe24e 100644 (file)
@@ -206,6 +206,51 @@ cm_RankServer(cm_server_t * tsp)
     return code;
 }
 
+static void
+cm_MarkServerDown(cm_server_t *tsp, afs_int32 code, int wasDown)
+{
+
+    /* mark server as down */
+    if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
+       _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
+       tsp->downTime = time(NULL);
+    }
+    if (code != VRESTARTING) {
+       lock_ReleaseMutex(&tsp->mx);
+       cm_ForceNewConnections(tsp);
+       lock_ObtainMutex(&tsp->mx);
+    }
+    /* Now update the volume status if necessary */
+    if (!wasDown) {
+       if (tsp->type == CM_SERVER_FILE) {
+           cm_server_vols_t * tsrvp;
+           cm_volume_t * volp;
+           int i;
+           cm_req_t req;
+
+           for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
+               for (i=0; i<NUM_SERVER_VOLS; i++) {
+                   if (tsrvp->ids[i] != 0) {
+                       cm_InitReq(&req);
+
+                       lock_ReleaseMutex(&tsp->mx);
+                       code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i],
+                                                cm_rootUserp, &req,
+                                                CM_GETVOL_FLAG_NO_LRU_UPDATE,
+                                                &volp);
+                       lock_ObtainMutex(&tsp->mx);
+                       if (code == 0) {
+                           cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
+                           cm_PutVolume(volp);
+                       }
+                   }
+               }
+           }
+       }
+       cm_RankServer(tsp);
+    }
+}
+
 void
 cm_PingServer(cm_server_t *tsp)
 {
@@ -311,45 +356,12 @@ cm_PingServer(cm_server_t *tsp)
             cm_RankServer(tsp);
         }
     } else {
-       /* mark server as down */
-        if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
-            _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
-            tsp->downTime = time(NULL);
-        }
-       if (code != VRESTARTING) {
-            lock_ReleaseMutex(&tsp->mx);
-           cm_ForceNewConnections(tsp);
-            lock_ObtainMutex(&tsp->mx);
-        }
+       cm_MarkServerDown(tsp, code, wasDown);
+
        osi_Log3(afsd_logp, "cm_PingServer server %s (%s) is down with caps 0x%x",
                  osi_LogSaveString(afsd_logp, hoststr),
                  tsp->type == CM_SERVER_VLDB ? "vldb" : "file",
                  tsp->capabilities);
-
-        /* Now update the volume status if necessary */
-        if (!wasDown) {
-            cm_server_vols_t * tsrvp;
-            cm_volume_t * volp;
-            int i;
-
-            for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
-                for (i=0; i<NUM_SERVER_VOLS; i++) {
-                    if (tsrvp->ids[i] != 0) {
-                        cm_InitReq(&req);
-
-                        lock_ReleaseMutex(&tsp->mx);
-                        code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
-                                                &req, CM_GETVOL_FLAG_NO_LRU_UPDATE, &volp);
-                        lock_ObtainMutex(&tsp->mx);
-                        if (code == 0) {
-                            cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
-                            cm_PutVolume(volp);
-                        }
-                    }
-                }
-            }
-            cm_RankServer(tsp);
-        }
     }
 
     if (tsp->waitCount == 0)
@@ -604,46 +616,13 @@ static void cm_CheckServersMulti(afs_uint32 flags, cm_cell_t *cellp)
                     cm_RankServer(tsp);
                 }
             } else {
-                /* mark server as down */
-                if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
-                    _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
-                    tsp->downTime = time(NULL);
-                }
-                if (code != VRESTARTING) {
-                    lock_ReleaseMutex(&tsp->mx);
-                    cm_ForceNewConnections(tsp);
-                    lock_ObtainMutex(&tsp->mx);
-                }
-                afs_inet_ntoa_r(tsp->addr.sin_addr.S_un.S_addr, hoststr);
+               cm_MarkServerDown(tsp, results[i], wasDown);
+
+               afs_inet_ntoa_r(tsp->addr.sin_addr.S_un.S_addr, hoststr);
                 osi_Log3(afsd_logp, "cm_MultiPingServer server %s (%s) is down with caps 0x%x",
                           osi_LogSaveString(afsd_logp, hoststr),
                           tsp->type == CM_SERVER_VLDB ? "vldb" : "file",
                           tsp->capabilities);
-
-                /* Now update the volume status if necessary */
-                if (!wasDown) {
-                    cm_server_vols_t * tsrvp;
-                    cm_volume_t * volp;
-                    int i;
-
-                    for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) {
-                        for (i=0; i<NUM_SERVER_VOLS; i++) {
-                            if (tsrvp->ids[i] != 0) {
-                                cm_InitReq(&req);
-
-                                lock_ReleaseMutex(&tsp->mx);
-                                code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp,
-                                                         &req, CM_GETVOL_FLAG_NO_LRU_UPDATE, &volp);
-                                lock_ObtainMutex(&tsp->mx);
-                                if (code == 0) {
-                                    cm_UpdateVolumeStatus(volp, tsrvp->ids[i]);
-                                    cm_PutVolume(volp);
-                                }
-                            }
-                        }
-                    }
-                    cm_RankServer(tsp);
-                }
             }
 
             if (tsp->waitCount == 0)
@@ -741,23 +720,13 @@ static void cm_CheckServersMulti(afs_uint32 flags, cm_cell_t *cellp)
                 if (wasDown)
                     cm_RankServer(tsp);
             } else {
-                /* mark server as down */
-                if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
-                    _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN);
-                    tsp->downTime = time(NULL);
-                }
-                if (code != VRESTARTING) {
-                    lock_ReleaseMutex(&tsp->mx);
-                    cm_ForceNewConnections(tsp);
-                    lock_ObtainMutex(&tsp->mx);
-                }
-                afs_inet_ntoa_r(tsp->addr.sin_addr.S_un.S_addr, hoststr);
+               cm_MarkServerDown(tsp, results[i], wasDown);
+
+               afs_inet_ntoa_r(tsp->addr.sin_addr.S_un.S_addr, hoststr);
                 osi_Log3(afsd_logp, "cm_MultiPingServer server %s (%s) is down with caps 0x%x",
                           osi_LogSaveString(afsd_logp, hoststr),
                           tsp->type == CM_SERVER_VLDB ? "vldb" : "file",
                           tsp->capabilities);
-                if (!wasDown)
-                    cm_RankServer(tsp);
             }
 
             if (tsp->waitCount == 0)