Windows: multi ping do not leak ping count
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 30 Sep 2015 17:23:36 +0000 (13:23 -0400)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 8 Oct 2015 03:36:31 +0000 (23:36 -0400)
In cm_CheckServersMulti() if cm_ConnByServer() fails or if cm_noIPAddr is
zero then a cm_server.pingCount will be leaked.  This can result in
servers being marked down and never restored to an up state.

This change adds the necessary pingCount decrement and moves the
assignment of the cm_server_t pointer to serversp[] to make it clear
that the cm_server_t will not be in the array if a failure occurs.
Only objects in the array will have the pingCount decremented after
the RPCs are issued.

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

src/WINNT/afsd/cm_server.c

index 89e8c43..8b327aa 100644 (file)
@@ -527,17 +527,17 @@ static void cm_CheckServersMulti(afs_uint32 flags, cm_cell_t *cellp)
            InterlockedIncrement(&tsp->pingCount);
             lock_ReleaseMutex(&tsp->mx);
 
-            serversp[nconns] = tsp;
            if (cm_noIPAddr > 0)
                code = cm_ConnByServer(tsp, cm_rootUserp, FALSE, &conns[nconns]);
            else
                code = RX_CALL_DEAD;
             if (code) {
-               if (code == RX_CALL_DEAD) {
-                   lock_ObtainMutex(&tsp->mx);
+               lock_ObtainMutex(&tsp->mx);
+               if (code == RX_CALL_DEAD)
                    cm_MarkServerDown(tsp, code, isDown);
-                   lock_ReleaseMutex(&tsp->mx);
-               }
+               InterlockedDecrement(&tsp->pingCount);
+               lock_ReleaseMutex(&tsp->mx);
+
                lock_ObtainRead(&cm_serverLock);
                cm_PutServerNoLock(tsp);
                 continue;
@@ -546,7 +546,7 @@ static void cm_CheckServersMulti(afs_uint32 flags, cm_cell_t *cellp)
             rxconns[nconns] = cm_GetRxConn(conns[nconns]);
             if (conntimer[nconns] = (isDown ? 1 : 0))
                 rx_SetConnHardDeadTime(rxconns[nconns], 10);
-
+           serversp[nconns] = tsp;
             nconns++;
         }
         lock_ReleaseRead(&cm_serverLock);
@@ -669,17 +669,17 @@ static void cm_CheckServersMulti(afs_uint32 flags, cm_cell_t *cellp)
            InterlockedIncrement(&tsp->pingCount);
             lock_ReleaseMutex(&tsp->mx);
 
-            serversp[nconns] = tsp;
            if (cm_noIPAddr > 0)
                code = cm_ConnByServer(tsp, cm_rootUserp, FALSE, &conns[nconns]);
            else
                code = RX_CALL_DEAD;
             if (code) {
-               if (code == RX_CALL_DEAD) {
-                   lock_ObtainMutex(&tsp->mx);
+               lock_ObtainMutex(&tsp->mx);
+               if (code == RX_CALL_DEAD)
                    cm_MarkServerDown(tsp, code, isDown);
-                   lock_ReleaseMutex(&tsp->mx);
-               }
+               InterlockedDecrement(&tsp->pingCount);
+               lock_ReleaseMutex(&tsp->mx);
+
                lock_ObtainRead(&cm_serverLock);
                 cm_PutServerNoLock(tsp);
                 continue;
@@ -689,7 +689,7 @@ static void cm_CheckServersMulti(afs_uint32 flags, cm_cell_t *cellp)
             conntimer[nconns] = (isDown ? 1 : 0);
             if (isDown)
                 rx_SetConnHardDeadTime(rxconns[nconns], 10);
-
+           serversp[nconns] = tsp;
             nconns++;
         }
         lock_ReleaseRead(&cm_serverLock);