Windows: improved idle dead time handling
[openafs.git] / src / WINNT / afsd / cm_conn.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <roken.h>
13
14 #include <afs/stds.h>
15
16 #include <windows.h>
17 #include <string.h>
18 #include <malloc.h>
19 #include <osi.h>
20 #include "afsd.h"
21 #include <rx/rx.h>
22 #include <rx/rxkad.h>
23 #include <afs/unified_afs.h>
24 #include <afs/vlserver.h>
25 #include <WINNT/afsreg.h>
26
27 osi_rwlock_t cm_connLock;
28
29 DWORD RDRtimeout = CM_CONN_DEFAULTRDRTIMEOUT;
30 unsigned short ConnDeadtimeout = CM_CONN_CONNDEADTIME;
31 unsigned short HardDeadtimeout = CM_CONN_HARDDEADTIME;
32 unsigned short IdleDeadtimeout = CM_CONN_IDLEDEADTIME;
33 unsigned short ReplicaIdleDeadtimeout = CM_CONN_IDLEDEADTIME_REP;
34 unsigned short NatPingInterval = CM_CONN_NATPINGINTERVAL;
35
36 #define LANMAN_WKS_PARAM_KEY "SYSTEM\\CurrentControlSet\\Services\\lanmanworkstation\\parameters"
37 #define LANMAN_WKS_SESSION_TIMEOUT "SessTimeout"
38 #define LANMAN_WKS_EXT_SESSION_TIMEOUT "ExtendedSessTimeout"
39
40 afs_uint32 cryptall = 0;
41 afs_uint32 cm_anonvldb = 0;
42 afs_uint32 rx_pmtu_discovery = 0;
43
44 void cm_PutConn(cm_conn_t *connp)
45 {
46     afs_int32 refCount = InterlockedDecrement(&connp->refCount);
47     osi_assertx(refCount >= 0, "cm_conn_t refcount underflow");
48 }
49
50 void cm_InitConn(void)
51 {
52     static osi_once_t once;
53     long code;
54     DWORD dwValue;
55     DWORD dummyLen;
56     HKEY parmKey;
57
58     if (osi_Once(&once)) {
59         lock_InitializeRWLock(&cm_connLock, "connection global lock",
60                                LOCK_HIERARCHY_CONN_GLOBAL);
61
62         /* keisa - read timeout value for lanmanworkstation  service.
63          * jaltman - as per
64          *   http://support.microsoft.com:80/support/kb/articles/Q102/0/67.asp&NoWebContent=1
65          * the SessTimeout is a minimum timeout not a maximum timeout.  Therefore,
66          * I believe that the default should not be short.  Instead, we should wait until
67          * RX times out before reporting a timeout to the SMB client.
68          */
69         code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LANMAN_WKS_PARAM_KEY,
70                             0, KEY_QUERY_VALUE, &parmKey);
71         if (code == ERROR_SUCCESS)
72         {
73             BOOL extTimeouts = msftSMBRedirectorSupportsExtendedTimeouts();
74
75             if (extTimeouts) {
76                 /*
77                  * The default value is 1000 seconds.  However, this default
78                  * will not apply to "\\AFS" unless "AFS" is listed in
79                  * ServersWithExtendedSessTimeout which we will add when we
80                  * create the ExtendedSessTimeout value in smb_Init()
81                  */
82                 dummyLen = sizeof(DWORD);
83                 code = RegQueryValueEx(parmKey,
84                                        LANMAN_WKS_EXT_SESSION_TIMEOUT,
85                                         NULL, NULL,
86                                         (BYTE *) &dwValue, &dummyLen);
87                 if (code == ERROR_SUCCESS) {
88                     RDRtimeout = dwValue;
89                     afsi_log("lanmanworkstation : ExtSessTimeout %u", RDRtimeout);
90                 }
91             }
92             if (!extTimeouts || code != ERROR_SUCCESS) {
93                 dummyLen = sizeof(DWORD);
94                 code = RegQueryValueEx(parmKey,
95                                        LANMAN_WKS_SESSION_TIMEOUT,
96                                        NULL, NULL,
97                                        (BYTE *) &dwValue, &dummyLen);
98                 if (code == ERROR_SUCCESS) {
99                     RDRtimeout = dwValue;
100                     afsi_log("lanmanworkstation : SessTimeout %u", RDRtimeout);
101                 }
102             }
103             RegCloseKey(parmKey);
104         }
105
106         code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
107                              0, KEY_QUERY_VALUE, &parmKey);
108         if (code == ERROR_SUCCESS) {
109             dummyLen = sizeof(DWORD);
110             code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
111                                     (BYTE *) &dwValue, &dummyLen);
112             if (code == ERROR_SUCCESS) {
113                 ConnDeadtimeout = (unsigned short)dwValue;
114                 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
115             }
116             dummyLen = sizeof(DWORD);
117             code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
118                                     (BYTE *) &dwValue, &dummyLen);
119             if (code == ERROR_SUCCESS) {
120                 HardDeadtimeout = (unsigned short)dwValue;
121                 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
122             }
123             dummyLen = sizeof(DWORD);
124             code = RegQueryValueEx(parmKey, "IdleDeadTimeout", NULL, NULL,
125                                     (BYTE *) &dwValue, &dummyLen);
126             if (code == ERROR_SUCCESS) {
127                 IdleDeadtimeout = (unsigned short)dwValue;
128                 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
129             }
130             dummyLen = sizeof(DWORD);
131             code = RegQueryValueEx(parmKey, "ReplicaIdleDeadTimeout", NULL, NULL,
132                                     (BYTE *) &dwValue, &dummyLen);
133             if (code == ERROR_SUCCESS) {
134                 ReplicaIdleDeadtimeout = (unsigned short)dwValue;
135                 afsi_log("ReplicaIdleDeadTimeout is %d", ReplicaIdleDeadtimeout);
136             }
137             dummyLen = sizeof(DWORD);
138             code = RegQueryValueEx(parmKey, "NatPingInterval", NULL, NULL,
139                                     (BYTE *) &dwValue, &dummyLen);
140             if (code == ERROR_SUCCESS) {
141                 NatPingInterval = (unsigned short)dwValue;
142             }
143             afsi_log("NatPingInterval is %d", NatPingInterval);
144             RegCloseKey(parmKey);
145         }
146
147         /*
148          * If these values were not set via cpp macro or obtained
149          * from the registry, we use a value that is derived from
150          * the smb redirector session timeout (RDRtimeout).
151          *
152          * The UNIX cache manager uses 120 seconds for the hard dead
153          * timeout and 50 seconds for the connection and idle timeouts.
154          *
155          * We base our values on those while making sure we leave
156          * enough time for overhead.
157          *
158          * To further complicate matters we need to take into account
159          * file server hard dead timeouts as they affect the length
160          * of time it takes the file server to give up when attempting
161          * to break callbacks to unresponsive clients.  The file
162          * server hard dead timeout is 120 seconds.
163          *
164          * For SMB, we have no choice but to timeout quickly.  For
165          * the AFS redirector, we can wait.
166          */
167         if (smb_Enabled) {
168             afsi_log("lanmanworkstation : SessTimeout %u", RDRtimeout);
169             if (ConnDeadtimeout == 0) {
170                 ConnDeadtimeout = (unsigned short) ((RDRtimeout / 2) < 50 ? (RDRtimeout / 2) : 50);
171                 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
172             }
173             if (HardDeadtimeout == 0) {
174                 HardDeadtimeout = (unsigned short) (RDRtimeout > 125 ? 120 : (RDRtimeout - 5));
175                 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
176             }
177             if (IdleDeadtimeout == 0) {
178                 IdleDeadtimeout = 10 * (unsigned short) HardDeadtimeout;
179                 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
180             }
181             if (ReplicaIdleDeadtimeout == 0) {
182                 ReplicaIdleDeadtimeout = (unsigned short) HardDeadtimeout;
183                 afsi_log("ReplicaIdleDeadTimeout is %d", ReplicaIdleDeadtimeout);
184             }
185         } else {
186             if (ConnDeadtimeout == 0) {
187                 ConnDeadtimeout = CM_CONN_IFS_CONNDEADTIME;
188                 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
189             }
190             if (HardDeadtimeout == 0) {
191                 HardDeadtimeout = CM_CONN_IFS_HARDDEADTIME;
192                 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
193             }
194             if (IdleDeadtimeout == 0) {
195                 IdleDeadtimeout = CM_CONN_IFS_IDLEDEADTIME;
196                 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
197             }
198             if (IdleDeadtimeout == 0) {
199                 ReplicaIdleDeadtimeout = CM_CONN_IFS_IDLEDEADTIME_REP;
200                 afsi_log("ReplicaIdleDeadTimeout is %d", ReplicaIdleDeadtimeout);
201             }
202         }
203         osi_EndOnce(&once);
204     }
205 }
206
207 void cm_InitReq(cm_req_t *reqp)
208 {
209         memset(reqp, 0, sizeof(cm_req_t));
210         reqp->startTime = GetTickCount();
211 }
212
213 static long cm_GetServerList(struct cm_fid *fidp, struct cm_user *userp,
214         struct cm_req *reqp, afs_uint32 *replicated, cm_serverRef_t ***serversppp)
215 {
216     long code;
217     cm_volume_t *volp = NULL;
218     cm_vol_state_t *volstatep = NULL;
219     cm_cell_t *cellp = NULL;
220
221     if (!fidp) {
222         *serversppp = NULL;
223         return CM_ERROR_INVAL;
224     }
225
226     cellp = cm_FindCellByID(fidp->cell, 0);
227     if (!cellp)
228         return CM_ERROR_NOSUCHCELL;
229
230     code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp, CM_GETVOL_FLAG_CREATE, &volp);
231     if (code)
232         return code;
233
234     volstatep = cm_VolumeStateByID(volp, fidp->volume);
235     *replicated = (volstatep->flags & CM_VOL_STATE_FLAG_REPLICATED);
236     *serversppp = cm_GetVolServers(volp, fidp->volume, userp, reqp);
237
238     lock_ObtainRead(&cm_volumeLock);
239     cm_PutVolume(volp);
240     lock_ReleaseRead(&cm_volumeLock);
241     return (*serversppp ? 0 : CM_ERROR_NOSUCHVOLUME);
242 }
243
244 /*
245  * Analyze the error return from an RPC.  Determine whether or not to retry,
246  * and if we're going to retry, determine whether failover is appropriate,
247  * and whether timed backoff is appropriate.
248  *
249  * If the error code is from cm_ConnFromFID() or friends, it will be a CM_ERROR code.
250  * Otherwise it will be an RPC code.  This may be a UNIX code (e.g. EDQUOT), or
251  * it may be an RX code, or it may be a special code (e.g. VNOVOL), or it may
252  * be a security code (e.g. RXKADEXPIRED).
253  *
254  * If the error code is from cm_ConnFromFID() or friends, connp will be NULL.
255  *
256  * For VLDB calls, fidp will be NULL.
257  *
258  * volSyncp and/or cbrp may also be NULL.
259  */
260 int
261 cm_Analyze(cm_conn_t *connp,
262            cm_user_t *userp,
263            cm_req_t *reqp,
264            struct cm_fid *fidp,
265            afs_uint32 storeOp,
266            AFSVolSync *volSyncp,
267            cm_serverRef_t * serversp,
268            cm_callbackRequest_t *cbrp,
269            long errorCode)
270 {
271     cm_server_t *serverp = NULL;
272     cm_serverRef_t **serverspp = NULL;
273     cm_serverRef_t *tsrp;
274     cm_cell_t  *cellp = NULL;
275     cm_ucell_t *ucellp;
276     cm_volume_t * volp = NULL;
277     cm_vol_state_t *statep = NULL;
278     cm_scache_t * scp = NULL;
279     afs_uint32 replicated;
280     int retry = 0;
281     int free_svr_list = 0;
282     int dead_session;
283     long timeUsed, timeLeft;
284     long code;
285     char addr[16]="unknown";
286     int forcing_new = 0;
287     int location_updated = 0;
288     char *format;
289     DWORD msgID;
290
291     osi_Log2(afsd_logp, "cm_Analyze connp 0x%p, code 0x%x",
292              connp, errorCode);
293
294     /* no locking required, since connp->serverp never changes after
295      * creation */
296     dead_session = (userp->cellInfop == NULL);
297     if (connp)
298         serverp = connp->serverp;
299
300     /* Update callback pointer */
301     if (cbrp && serverp && errorCode == 0) {
302         if (cbrp->serverp) {
303             if ( cbrp->serverp != serverp ) {
304                 lock_ObtainWrite(&cm_serverLock);
305                 cm_PutServerNoLock(cbrp->serverp);
306                 cm_GetServerNoLock(serverp);
307                 lock_ReleaseWrite(&cm_serverLock);
308             }
309         } else {
310             cm_GetServer(serverp);
311         }
312         cbrp->serverp = serverp;
313     }
314
315     /* if timeout - check that it did not exceed the HardDead timeout
316      * and retry */
317
318     /* timeleft - get it from reqp the same way as cm_ConnByMServers does */
319     timeUsed = (GetTickCount() - reqp->startTime) / 1000;
320     if ( reqp->flags & CM_REQ_SOURCE_SMB )
321         timeLeft = HardDeadtimeout - timeUsed;
322     else
323         timeLeft = 0x0FFFFFFF;
324
325     /* get a pointer to the cell */
326     if (errorCode) {
327         if (cellp == NULL && serverp)
328             cellp = serverp->cellp;
329         if (cellp == NULL && serversp) {
330             struct cm_serverRef * refp;
331             for ( refp=serversp ; cellp == NULL && refp != NULL; refp=refp->next) {
332                 if (refp->status == srv_deleted)
333                     continue;
334                 if ( refp->server )
335                     cellp = refp->server->cellp;
336             }
337         }
338         if (cellp == NULL && fidp) {
339             cellp = cm_FindCellByID(fidp->cell, 0);
340         }
341     }
342
343     if (errorCode == CM_ERROR_TIMEDOUT) {
344         if ( timeLeft > 5 ) {
345             thrd_Sleep(3000);
346             cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, cellp);
347             retry = 1;
348         }
349     }
350
351     else if (errorCode == UAEWOULDBLOCK || errorCode == EWOULDBLOCK ||
352               errorCode == UAEAGAIN || errorCode == EAGAIN) {
353         osi_Log0(afsd_logp, "cm_Analyze passed EWOULDBLOCK or EAGAIN.");
354         if ( timeLeft > 5 ) {
355             thrd_Sleep(1000);
356             retry = 1;
357         }
358     }
359
360     /* if there is nosuchvolume, then we have a situation in which a
361      * previously known volume no longer has a set of servers
362      * associated with it.  Either the volume has moved or
363      * the volume has been deleted.  Try to find a new server list
364      * until the timeout period expires.
365      */
366     else if (errorCode == CM_ERROR_NOSUCHVOLUME) {
367         osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_NOSUCHVOLUME.");
368         /*
369          * The VNOVOL or VL_NOENT error has already been translated
370          * to CM_ERROR_NOSUCHVOLUME.  There is nothing for us to do.
371          */
372     }
373
374     else if (errorCode == CM_ERROR_ALLDOWN) {
375         /* Servers marked DOWN will be restored by the background daemon
376          * thread as they become available.  The volume status is
377          * updated as the server state changes.
378          */
379         if (fidp) {
380             osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_DOWN (FS cell %s vol 0x%x)",
381                       cellp->name, fidp->volume);
382             msgID = MSG_ALL_SERVERS_DOWN;
383             format = "All servers are unreachable when accessing cell %s volume %d.";
384             LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
385         } else {
386             osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLDOWN (VL Server)");
387         }
388     }
389
390     else if (errorCode == CM_ERROR_ALLOFFLINE) {
391         /* Volume instances marked offline will be restored by the
392          * background daemon thread as they become available
393          */
394         if (fidp) {
395             osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE (FS cell %s vol 0x%x)",
396                       cellp->name, fidp->volume);
397             msgID = MSG_ALL_SERVERS_OFFLINE;
398             format = "All servers are offline when accessing cell %s volume %d.";
399             LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
400
401             code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
402                                       CM_GETVOL_FLAG_NO_LRU_UPDATE,
403                                       &volp);
404             if (code == 0) {
405                 /*
406                  * Do not perform a cm_CheckOfflineVolume() if cm_Analyze()
407                  * was called by cm_CheckOfflineVolumeState().
408                  */
409                 if (!(reqp->flags & CM_REQ_OFFLINE_VOL_CHK) && timeLeft > 7) {
410                     thrd_Sleep(5000);
411
412                     /* cm_CheckOfflineVolume() resets the serverRef state */
413                     if (cm_CheckOfflineVolume(volp, fidp->volume))
414                         retry = 1;
415                 } else {
416                     cm_UpdateVolumeStatus(volp, fidp->volume);
417                 }
418                 lock_ObtainRead(&cm_volumeLock);
419                 cm_PutVolume(volp);
420                 lock_ReleaseRead(&cm_volumeLock);
421                 volp = NULL;
422             }
423         } else {
424             osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE (VL Server)");
425         }
426     }
427     else if (errorCode == CM_ERROR_ALLBUSY) {
428         /* Volumes that are busy cannot be determined to be non-busy
429          * without actually attempting to access them.
430          */
431         if (fidp) { /* File Server query */
432             osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY (FS cell %s vol 0x%x)",
433                      cellp->name, fidp->volume);
434             msgID = MSG_ALL_SERVERS_BUSY;
435             format = "All servers are busy when accessing cell %s volume %d.";
436             LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
437
438             code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
439                                      CM_GETVOL_FLAG_NO_LRU_UPDATE,
440                                      &volp);
441             if (code == 0) {
442                 if (timeLeft > 7) {
443                     thrd_Sleep(5000);
444
445                     statep = cm_VolumeStateByID(volp, fidp->volume);
446                     if (statep->state != vl_offline &&
447                          statep->state != vl_busy &&
448                          statep->state != vl_unknown) {
449                         retry = 1;
450                     } else {
451                         if (!serversp) {
452                             code = cm_GetServerList(fidp, userp, reqp, &replicated, &serverspp);
453                             if (code == 0) {
454                                 serversp = *serverspp;
455                                 free_svr_list = 1;
456                             }
457                         }
458                         lock_ObtainWrite(&cm_serverLock);
459                         for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
460                             if (tsrp->status == srv_deleted)
461                                 continue;
462                             if (tsrp->status == srv_busy) {
463                                 tsrp->status = srv_not_busy;
464                             }
465                         }
466                         lock_ReleaseWrite(&cm_serverLock);
467                         if (free_svr_list) {
468                             cm_FreeServerList(serverspp, 0);
469                             serversp = NULL;
470                             free_svr_list = 0;
471                         }
472
473                         cm_UpdateVolumeStatus(volp, fidp->volume);
474                         retry = 1;
475                     }
476                 } else {
477                     cm_UpdateVolumeStatus(volp, fidp->volume);
478                 }
479
480                 lock_ObtainRead(&cm_volumeLock);
481                 cm_PutVolume(volp);
482                 lock_ReleaseRead(&cm_volumeLock);
483                 volp = NULL;
484             }
485         } else {    /* VL Server query */
486             osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY (VL Server).");
487
488             if (timeLeft > 7) {
489                 thrd_Sleep(5000);
490
491                 if (serversp) {
492                     lock_ObtainWrite(&cm_serverLock);
493                     for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
494                         if (tsrp->status == srv_deleted)
495                             continue;
496                         if (tsrp->status == srv_busy) {
497                             tsrp->status = srv_not_busy;
498                         }
499                     }
500                     lock_ReleaseWrite(&cm_serverLock);
501                     retry = 1;
502                 }
503             }
504         }
505     }
506
507     /* special codes:  VBUSY and VRESTARTING */
508     else if (errorCode == VBUSY || errorCode == VRESTARTING) {
509         if (!serversp && fidp) {
510             code = cm_GetServerList(fidp, userp, reqp, &replicated, &serverspp);
511             if (code == 0) {
512                 serversp = *serverspp;
513                 free_svr_list = 1;
514             }
515         }
516
517         switch ( errorCode ) {
518         case VBUSY:
519             msgID = MSG_SERVER_REPORTS_VBUSY;
520             format = "Server %s reported busy when accessing volume %d in cell %s.";
521             break;
522         case VRESTARTING:
523             msgID = MSG_SERVER_REPORTS_VRESTARTING;
524             format = "Server %s reported restarting when accessing volume %d in cell %s.";
525             break;
526         }
527
528         if (serverp && fidp) {
529             /* Log server being offline for this volume */
530             sprintf(addr, "%d.%d.%d.%d",
531                    ((serverp->addr.sin_addr.s_addr & 0xff)),
532                    ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
533                    ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
534                    ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
535
536             osi_Log3(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
537             LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume, cellp->name);
538         }
539
540         lock_ObtainWrite(&cm_serverLock);
541         for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
542             if (tsrp->status == srv_deleted)
543                 continue;
544             if (tsrp->server == serverp && tsrp->status == srv_not_busy) {
545                 tsrp->status = srv_busy;
546                 if (fidp) { /* File Server query */
547                     lock_ReleaseWrite(&cm_serverLock);
548                     code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
549                                              CM_GETVOL_FLAG_NO_LRU_UPDATE,
550                                              &volp);
551                     if (code == 0)
552                         statep = cm_VolumeStateByID(volp, fidp->volume);
553                     lock_ObtainWrite(&cm_serverLock);
554                 }
555                 break;
556             }
557         }
558         lock_ReleaseWrite(&cm_serverLock);
559
560         if (statep) {
561             cm_UpdateVolumeStatus(volp, statep->ID);
562             lock_ObtainRead(&cm_volumeLock);
563             cm_PutVolume(volp);
564             lock_ReleaseRead(&cm_volumeLock);
565             volp = NULL;
566         }
567
568         if (free_svr_list) {
569             cm_FreeServerList(serverspp, 0);
570             serversp = NULL;
571             free_svr_list = 0;
572         }
573         retry = 1;
574     }
575
576     /* special codes:  missing volumes */
577     else if (errorCode == VNOVOL || errorCode == VMOVED || errorCode == VOFFLINE ||
578              errorCode == VSALVAGE || errorCode == VNOSERVICE || errorCode == VIO)
579     {
580         /* In case of timeout */
581         reqp->volumeError = errorCode;
582
583         switch ( errorCode ) {
584         case VNOVOL:
585             msgID = MSG_SERVER_REPORTS_VNOVOL;
586             format = "Server %s reported volume %d in cell %s as not attached (may have been moved or deleted).";
587             break;
588         case VMOVED:
589             msgID = MSG_SERVER_REPORTS_VMOVED;
590             format = "Server %s reported volume %d in cell %s as moved.";
591             break;
592         case VOFFLINE:
593             msgID = MSG_SERVER_REPORTS_VOFFLINE;
594             format = "Server %s reported volume %d in cell %s as offline.";
595             break;
596         case VSALVAGE:
597             msgID = MSG_SERVER_REPORTS_VSALVAGE;
598             format = "Server %s reported volume %d in cell %s as needs salvage.";
599             break;
600         case VNOSERVICE:
601             msgID = MSG_SERVER_REPORTS_VNOSERVICE;
602             format = "Server %s reported volume %d in cell %s as not in service.";
603             break;
604         case VIO:
605             msgID = MSG_SERVER_REPORTS_VIO;
606             format = "Server %s reported volume %d in cell %s as temporarily unaccessible.";
607             break;
608         }
609
610         if (fidp) { /* File Server query */
611             if (serverp) {
612                 /* Log server being unavailable for this volume */
613                 sprintf(addr, "%d.%d.%d.%d",
614                          ((serverp->addr.sin_addr.s_addr & 0xff)),
615                          ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
616                          ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
617                          ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
618
619                 osi_Log3(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
620                 LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume, cellp->name);
621             }
622
623             code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
624                                       CM_GETVOL_FLAG_NO_LRU_UPDATE,
625                                       &volp);
626             if (code == 0)
627                 statep = cm_VolumeStateByID(volp, fidp->volume);
628
629             if ((errorCode == VMOVED || errorCode == VNOVOL || errorCode == VOFFLINE) &&
630                 !(reqp->flags & CM_REQ_VOLUME_UPDATED))
631             {
632                 code = cm_ForceUpdateVolume(fidp, userp, reqp);
633                 if (code == 0)
634                     location_updated = 1;
635
636                 /* Even if the update fails, there might still be another replica */
637
638                 reqp->flags |= CM_REQ_VOLUME_UPDATED;
639                 osi_Log3(afsd_logp, "cm_Analyze called cm_ForceUpdateVolume cell %u vol %u code 0x%x",
640                         fidp->cell, fidp->volume, code);
641             }
642
643             if (statep) {
644                 cm_UpdateVolumeStatus(volp, statep->ID);
645                 osi_Log3(afsd_logp, "cm_Analyze NewVolState cell %u vol %u state %u",
646                          fidp->cell, fidp->volume, statep->state);
647             }
648
649             if (volp) {
650                 lock_ObtainRead(&cm_volumeLock);
651                 cm_PutVolume(volp);
652                 lock_ReleaseRead(&cm_volumeLock);
653                 volp = NULL;
654             }
655
656             /*
657              * Mark server offline for this volume or delete the volume
658              * from the server list if it was moved or is not present.
659              */
660             if (!serversp || location_updated) {
661                 code = cm_GetServerList(fidp, userp, reqp, &replicated, &serverspp);
662                 if (code == 0) {
663                     serversp = *serverspp;
664                     free_svr_list = 1;
665                 }
666             }
667         }
668
669         lock_ObtainWrite(&cm_serverLock);
670         for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
671             if (tsrp->status == srv_deleted)
672                 continue;
673
674             sprintf(addr, "%d.%d.%d.%d",
675                      ((tsrp->server->addr.sin_addr.s_addr & 0xff)),
676                      ((tsrp->server->addr.sin_addr.s_addr & 0xff00)>> 8),
677                      ((tsrp->server->addr.sin_addr.s_addr & 0xff0000)>> 16),
678                      ((tsrp->server->addr.sin_addr.s_addr & 0xff000000)>> 24));
679
680             if (cm_ServerEqual(tsrp->server, serverp)) {
681                 /* REDIRECT */
682                 if (errorCode == VMOVED || errorCode == VNOVOL) {
683                     osi_Log2(afsd_logp, "volume %d not present on server %s",
684                              fidp->volume, osi_LogSaveString(afsd_logp,addr));
685                     tsrp->status = srv_deleted;
686                     if (fidp)
687                         cm_RemoveVolumeFromServer(serverp, fidp->volume);
688                 } else {
689                     osi_Log2(afsd_logp, "volume %d instance on server %s marked offline",
690                              fidp->volume, osi_LogSaveString(afsd_logp,addr));
691                     tsrp->status = srv_offline;
692                 }
693                 /* break; */
694             } else {
695                 osi_Log3(afsd_logp, "volume %d exists on server %s with status %u",
696                          fidp->volume, osi_LogSaveString(afsd_logp,addr), tsrp->status);
697             }
698         }
699         lock_ReleaseWrite(&cm_serverLock);
700
701         /* Free the server list before cm_ForceUpdateVolume is called */
702         if (free_svr_list) {
703             cm_FreeServerList(serverspp, 0);
704             serversp = NULL;
705             free_svr_list = 0;
706         }
707
708         if ( timeLeft > 2 )
709             retry = 1;
710     } else if ( errorCode == VNOVNODE ) {
711         if ( fidp ) {
712             osi_Log4(afsd_logp, "cm_Analyze passed VNOVNODE cell %u vol %u vn %u uniq %u.",
713                       fidp->cell, fidp->volume, fidp->vnode, fidp->unique);
714
715             scp = cm_FindSCache(fidp);
716             if (scp) {
717                 cm_scache_t *pscp = NULL;
718
719                 if (scp->fileType != CM_SCACHETYPE_DIRECTORY)
720                     pscp = cm_FindSCacheParent(scp);
721
722                 lock_ObtainWrite(&scp->rw);
723                 scp->flags |= CM_SCACHEFLAG_DELETED;
724                 lock_ObtainWrite(&cm_scacheLock);
725                 cm_AdjustScacheLRU(scp);
726                 cm_RemoveSCacheFromHashTable(scp);
727                 lock_ReleaseWrite(&cm_scacheLock);
728                 cm_LockMarkSCacheLost(scp);
729                 lock_ReleaseWrite(&scp->rw);
730                 if (RDR_Initialized)
731                     RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
732                                           scp->fid.hash, scp->fileType, AFS_INVALIDATE_DELETED);
733                 cm_ReleaseSCache(scp);
734
735                 if (pscp) {
736                     if (cm_HaveCallback(pscp)) {
737                         lock_ObtainWrite(&pscp->rw);
738                         cm_DiscardSCache(pscp);
739                         lock_ReleaseWrite(&pscp->rw);
740
741                         if (RDR_Initialized)
742                             RDR_InvalidateObject(pscp->fid.cell, pscp->fid.volume, pscp->fid.vnode, pscp->fid.unique,
743                                                  pscp->fid.hash, pscp->fileType, AFS_INVALIDATE_EXPIRED);
744
745                     }
746                     cm_ReleaseSCache(pscp);
747                 }
748             }
749         } else {
750             osi_Log0(afsd_logp, "cm_Analyze passed VNOVNODE unknown fid.");
751         }
752     }
753
754     /* RX codes */
755     else if (errorCode == RX_CALL_TIMEOUT) {
756         /* RPC took longer than hardDeadTime or the server
757          * reported idle for longer than idleDeadTime
758          * don't mark server as down but don't retry
759          * this is to prevent the SMB session from timing out
760          * In addition, we log an event to the event log
761          */
762
763         if (serverp) {
764             sprintf(addr, "%d.%d.%d.%d",
765                     ((serverp->addr.sin_addr.s_addr & 0xff)),
766                     ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
767                     ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
768                     ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
769
770             LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_HARD_DEAD_TIME_EXCEEDED, addr);
771             osi_Log1(afsd_logp, "cm_Analyze: hardDeadTime or idleDeadtime exceeded addr[%s]",
772                      osi_LogSaveString(afsd_logp,addr));
773             reqp->tokenIdleErrorServp = serverp;
774             reqp->idleError++;
775         }
776
777         if (fidp && storeOp)
778             scp = cm_FindSCache(fidp);
779         if (scp) {
780             if (cm_HaveCallback(scp)) {
781                 lock_ObtainWrite(&scp->rw);
782                 cm_DiscardSCache(scp);
783                 lock_ReleaseWrite(&scp->rw);
784
785                 /*
786                 * We really should notify the redirector that we discarded
787                 * the status information but doing so in this case is not
788                 * safe as it can result in a deadlock with extent release
789                 * processing.
790                 */
791             }
792             cm_ReleaseSCache(scp);
793         }
794
795         if (timeLeft > 2) {
796             if (!fidp) { /* vldb */
797                 retry = 1;
798             } else { /* file */
799                 cm_volume_t *volp = cm_GetVolumeByFID(fidp);
800                 if (volp) {
801                     if (fidp->volume == cm_GetROVolumeID(volp))
802                         retry = 1;
803                     cm_PutVolume(volp);
804                 }
805             }
806         }
807     }
808     else if (errorCode == RX_MSGSIZE) {
809         /*
810          * RPC failed because a transmitted rx packet
811          * may have grown larger than the path mtu.
812          * Force a retry and the Rx library will try
813          * with a smaller mtu size.
814          */
815
816         if (serverp)
817             sprintf(addr, "%d.%d.%d.%d",
818                     ((serverp->addr.sin_addr.s_addr & 0xff)),
819                     ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
820                     ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
821                     ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
822
823         LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_MSGSIZE_EXCEEDED, addr);
824         osi_Log1(afsd_logp, "cm_Analyze: Path MTU may have been exceeded addr[%s]",
825                  osi_LogSaveString(afsd_logp,addr));
826
827         retry = 1;
828     }
829     else if (errorCode == RX_CALL_BUSY) {
830         /*
831          * RPC failed because the selected call channel
832          * is currently busy on the server.  Unconditionally
833          * retry the request so an alternate call channel can be used.
834          */
835         if (serverp)
836             sprintf(addr, "%d.%d.%d.%d",
837                     ((serverp->addr.sin_addr.s_addr & 0xff)),
838                     ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
839                     ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
840                     ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
841
842         LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_BUSY_CALL_CHANNEL, addr);
843         osi_Log1(afsd_logp, "cm_Analyze: Retry RPC due to busy call channel addr[%s]",
844                  osi_LogSaveString(afsd_logp,addr));
845         retry = 1;
846     }
847     else if (errorCode == RX_CALL_IDLE) {
848         /*
849          * RPC failed because the server failed to respond with data
850          * within the idle dead timeout period.  This could be for a variety
851          * of reasons:
852          *  1. The server could have a bad partition such as a failed
853          *     disk or iSCSI target and all I/O to that partition is
854          *     blocking on the server and will never complete.
855          *
856          *  2. The server vnode may be locked by another client request
857          *     that is taking a very long time.
858          *
859          *  3. The server may have a very long queue of requests
860          *     pending and is unable to process this request.
861          *
862          *  4. The server could be malicious and is performing a denial
863          *     of service attack against the client.
864          *
865          * If this is a request against a .readonly with alternate sites
866          * the server should be marked down for this request and the
867          * client should fail over to another server.  If this is a
868          * request against a single source, the client may retry once.
869          */
870         if (serverp)
871             sprintf(addr, "%d.%d.%d.%d",
872                     ((serverp->addr.sin_addr.s_addr & 0xff)),
873                     ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
874                     ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
875                     ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
876
877         if (fidp) {
878             code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
879                                      CM_GETVOL_FLAG_NO_LRU_UPDATE,
880                                      &volp);
881             if (code == 0) {
882                 statep = cm_VolumeStateByID(volp, fidp->volume);
883
884                 if (statep)
885                     replicated = (statep->flags & CM_VOL_STATE_FLAG_REPLICATED);
886
887                 lock_ObtainRead(&cm_volumeLock);
888                 cm_PutVolume(volp);
889                 lock_ReleaseRead(&cm_volumeLock);
890                 volp = NULL;
891             }
892
893             if (storeOp)
894                 scp = cm_FindSCache(fidp);
895             if (scp) {
896                 if (cm_HaveCallback(scp)) {
897                     lock_ObtainWrite(&scp->rw);
898                     cm_DiscardSCache(scp);
899                     lock_ReleaseWrite(&scp->rw);
900
901                     /*
902                      * We really should notify the redirector that we discarded
903                      * the status information but doing so in this case is not
904                      * safe as it can result in a deadlock with extent release
905                      * processing.
906                      */
907                 }
908                 cm_ReleaseSCache(scp);
909             }
910         }
911
912         if (replicated && serverp) {
913             reqp->tokenIdleErrorServp = serverp;
914             reqp->tokenError = errorCode;
915
916             if (timeLeft > 2)
917                 retry = 1;
918         }
919
920         LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_IDLE_DEAD_TIMEOUT, addr, retry);
921         osi_Log2(afsd_logp, "cm_Analyze: RPC failed due to idle dead timeout addr[%s] retry=%u",
922                  osi_LogSaveString(afsd_logp,addr), retry);
923     }
924     else if (errorCode == RX_CALL_DEAD) {
925         /* mark server as down */
926         if (serverp)
927             sprintf(addr, "%d.%d.%d.%d",
928                     ((serverp->addr.sin_addr.s_addr & 0xff)),
929                     ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
930                     ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
931                     ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
932
933         osi_Log2(afsd_logp, "cm_Analyze: Rx Call Dead addr[%s] forcedNew[%s]",
934                  osi_LogSaveString(afsd_logp,addr),
935                  (reqp->flags & CM_REQ_NEW_CONN_FORCED ? "yes" : "no"));
936
937         if (serverp) {
938             if ((reqp->flags & CM_REQ_NEW_CONN_FORCED)) {
939                 lock_ObtainMutex(&serverp->mx);
940                 if (!(serverp->flags & CM_SERVERFLAG_DOWN)) {
941                     _InterlockedOr(&serverp->flags, CM_SERVERFLAG_DOWN);
942                     serverp->downTime = time(NULL);
943                 }
944                 lock_ReleaseMutex(&serverp->mx);
945             } else {
946                 reqp->flags |= CM_REQ_NEW_CONN_FORCED;
947                 forcing_new = 1;
948                 cm_ForceNewConnections(serverp);
949             }
950         }
951
952         if (fidp && storeOp)
953             scp = cm_FindSCache(fidp);
954         if (scp) {
955             if (cm_HaveCallback(scp)) {
956                 lock_ObtainWrite(&scp->rw);
957                 cm_DiscardSCache(scp);
958                 lock_ReleaseWrite(&scp->rw);
959
960                 /*
961                 * We really should notify the redirector that we discarded
962                 * the status information but doing so in this case is not
963                 * safe as it can result in a deadlock with extent release
964                 * processing.
965                 */
966             }
967             cm_ReleaseSCache(scp);
968         }
969
970         if ( timeLeft > 2 )
971             retry = 1;
972     }
973     else if (errorCode >= -64 && errorCode < 0) {
974         /* mark server as down */
975         if (serverp)
976             sprintf(addr, "%d.%d.%d.%d",
977                     ((serverp->addr.sin_addr.s_addr & 0xff)),
978                     ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
979                     ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
980                     ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
981
982         osi_Log3(afsd_logp, "cm_Analyze: Rx Misc Error[%d] addr[%s] forcedNew[%s]",
983                  errorCode,
984                  osi_LogSaveString(afsd_logp,addr),
985                  (reqp->flags & CM_REQ_NEW_CONN_FORCED ? "yes" : "no"));
986
987         if (serverp) {
988             if (reqp->flags & CM_REQ_NEW_CONN_FORCED) {
989                 reqp->tokenIdleErrorServp = serverp;
990                 reqp->tokenError = errorCode;
991             } else {
992                 reqp->flags |= CM_REQ_NEW_CONN_FORCED;
993                 forcing_new = 1;
994                 cm_ForceNewConnections(serverp);
995             }
996         }
997         if ( timeLeft > 2 )
998             retry = 1;
999     }
1000     else if (errorCode == RXKADEXPIRED) {
1001         osi_Log1(afsd_logp, "cm_Analyze: rxkad error code 0x%x (RXKADEXPIRED)",
1002                  errorCode);
1003         if (!dead_session) {
1004             lock_ObtainMutex(&userp->mx);
1005             ucellp = cm_GetUCell(userp, serverp->cellp);
1006             if (ucellp->ticketp) {
1007                 free(ucellp->ticketp);
1008                 ucellp->ticketp = NULL;
1009             }
1010             _InterlockedAnd(&ucellp->flags, ~CM_UCELLFLAG_RXKAD);
1011             ucellp->gen++;
1012             lock_ReleaseMutex(&userp->mx);
1013             if ( timeLeft > 2 )
1014                 retry = 1;
1015         }
1016     } else if (errorCode >= ERROR_TABLE_BASE_RXK && errorCode < ERROR_TABLE_BASE_RXK + 256) {
1017         char * s = "unknown error";
1018         switch ( errorCode ) {
1019         case RXKADINCONSISTENCY: s = "RXKADINCONSISTENCY"; break;
1020         case RXKADPACKETSHORT  : s = "RXKADPACKETSHORT";   break;
1021         case RXKADLEVELFAIL    : s = "RXKADLEVELFAIL";     break;
1022         case RXKADTICKETLEN    : s = "RXKADTICKETLEN";     break;
1023         case RXKADOUTOFSEQUENCE: s = "RXKADOUTOFSEQUENCE"; break;
1024         case RXKADNOAUTH       : s = "RXKADNOAUTH";        break;
1025         case RXKADBADKEY       : s = "RXKADBADKEY";        break;
1026         case RXKADBADTICKET    : s = "RXKADBADTICKET";     break;
1027         case RXKADUNKNOWNKEY   : s = "RXKADUNKNOWNKEY";    break;
1028         case RXKADEXPIRED      : s = "RXKADEXPIRED";       break;
1029         case RXKADSEALEDINCON  : s = "RXKADSEALEDINCON";   break;
1030         case RXKADDATALEN      : s = "RXKADDATALEN";       break;
1031         case RXKADILLEGALLEVEL : s = "RXKADILLEGALLEVEL";  break;
1032         }
1033         osi_Log2(afsd_logp, "cm_Analyze: rxkad error code 0x%x (%s)",
1034                   errorCode, s);
1035
1036         if (serverp) {
1037             reqp->tokenIdleErrorServp = serverp;
1038             reqp->tokenError = errorCode;
1039             retry = 1;
1040         }
1041     } else if (errorCode >= ERROR_TABLE_BASE_U && errorCode < ERROR_TABLE_BASE_U + 256) {
1042         /*
1043          * We received a ubik error.  its possible that the server we are
1044          * communicating with has a corrupted database or is partitioned
1045          * from the rest of the servers and another server might be able
1046          * to answer our query.  Therefore, we will retry the request
1047          * and force the use of another server.
1048          */
1049         if (serverp) {
1050             reqp->tokenIdleErrorServp = serverp;
1051             reqp->tokenError = errorCode;
1052             retry = 1;
1053         }
1054     } else if (errorCode == VICECONNBAD || errorCode == VICETOKENDEAD) {
1055         cm_ForceNewConnections(serverp);
1056         if ( timeLeft > 2 )
1057             retry = 1;
1058     } else {
1059         if (errorCode) {
1060             char * s = "unknown error";
1061             switch ( errorCode ) {
1062             case VSALVAGE          : s = "VSALVAGE";           break;
1063             case VNOVNODE          : s = "VNOVNODE";           break;
1064             case VNOVOL            : s = "VNOVOL";             break;
1065             case VVOLEXISTS        : s = "VVOLEXISTS";         break;
1066             case VNOSERVICE        : s = "VNOSERVICE";         break;
1067             case VOFFLINE          : s = "VOFFLINE";           break;
1068             case VONLINE           : s = "VONLINE";            break;
1069             case VDISKFULL         : s = "VDISKFULL";          break;
1070             case VOVERQUOTA        : s = "VOVERQUOTA";         break;
1071             case VBUSY             : s = "VBUSY";              break;
1072             case VMOVED            : s = "VMOVED";             break;
1073             case VIO               : s = "VIO";                break;
1074             case VRESTRICTED       : s = "VRESTRICTED";        break;
1075             case VRESTARTING       : s = "VRESTARTING";        break;
1076             case VREADONLY         : s = "VREADONLY";          break;
1077             case EAGAIN            : s = "EAGAIN";             break;
1078             case UAEAGAIN          : s = "UAEAGAIN";           break;
1079             case EINVAL            : s = "EINVAL";             break;
1080             case UAEINVAL          : s = "UAEINVAL";           break;
1081             case EACCES            : s = "EACCES";             break;
1082             case UAEACCES          : s = "UAEACCES";           break;
1083             case ENOENT            : s = "ENOENT";             break;
1084             case UAENOENT          : s = "UAENOENT";           break;
1085             case EEXIST            : s = "EEXIST";             break;
1086             case UAEEXIST          : s = "UAEEXIST";           break;
1087             case VICECONNBAD       : s = "VICECONNBAD";        break;
1088             case VICETOKENDEAD     : s = "VICETOKENDEAD";      break;
1089             case WSAEWOULDBLOCK    : s = "WSAEWOULDBLOCK";     break;
1090             case UAEWOULDBLOCK     : s = "UAEWOULDBLOCK";      break;
1091             case VL_IDEXIST        : s = "VL_IDEXIST";         break;
1092             case VL_IO             : s = "VL_IO";              break;
1093             case VL_NAMEEXIST      : s = "VL_NAMEEXIST";       break;
1094             case VL_CREATEFAIL     : s = "VL_CREATEFAIL";      break;
1095             case VL_NOENT          : s = "VL_NOENT";           break;
1096             case VL_EMPTY          : s = "VL_EMPTY";           break;
1097             case VL_ENTDELETED     : s = "VL_ENTDELETED";      break;
1098             case VL_BADNAME        : s = "VL_BADNAME";         break;
1099             case VL_BADINDEX       : s = "VL_BADINDEX";        break;
1100             case VL_BADVOLTYPE     : s = "VL_BADVOLTYPE";      break;
1101             case VL_BADSERVER      : s = "VL_BADSERVER";       break;
1102             case VL_BADPARTITION   : s = "VL_BADPARTITION";    break;
1103             case VL_REPSFULL       : s = "VL_REPSFULL";        break;
1104             case VL_NOREPSERVER    : s = "VL_NOREPSERVER";     break;
1105             case VL_DUPREPSERVER   : s = "VL_DUPREPSERVER";    break;
1106             case VL_RWNOTFOUND     : s = "VL_RWNOTFOUND";      break;
1107             case VL_BADREFCOUNT    : s = "VL_BADREFCOUNT";     break;
1108             case VL_SIZEEXCEEDED   : s = "VL_SIZEEXCEEDED";    break;
1109             case VL_BADENTRY       : s = "VL_BADENTRY";        break;
1110             case VL_BADVOLIDBUMP   : s = "VL_BADVOLIDBUMP";    break;
1111             case VL_IDALREADYHASHED: s = "VL_IDALREADYHASHED"; break;
1112             case VL_ENTRYLOCKED    : s = "VL_ENTRYLOCKED";     break;
1113             case VL_BADVOLOPER     : s = "VL_BADVOLOPER";      break;
1114             case VL_BADRELLOCKTYPE : s = "VL_BADRELLOCKTYPE";  break;
1115             case VL_RERELEASE      : s = "VL_RERELEASE";       break;
1116             case VL_BADSERVERFLAG  : s = "VL_BADSERVERFLAG";   break;
1117             case VL_PERM           : s = "VL_PERM";            break;
1118             case VL_NOMEM          : s = "VL_NOMEM";           break;
1119             case VL_BADVERSION     : s = "VL_BADVERSION";      break;
1120             case VL_INDEXERANGE    : s = "VL_INDEXERANGE";     break;
1121             case VL_MULTIPADDR     : s = "VL_MULTIPADDR";      break;
1122             case VL_BADMASK        : s = "VL_BADMASK";         break;
1123             case CM_ERROR_NOSUCHCELL        : s = "CM_ERROR_NOSUCHCELL";         break;
1124             case CM_ERROR_NOSUCHVOLUME      : s = "CM_ERROR_NOSUCHVOLUME";       break;
1125             case CM_ERROR_TIMEDOUT          : s = "CM_ERROR_TIMEDOUT";           break;
1126             case CM_ERROR_RETRY             : s = "CM_ERROR_RETRY";              break;
1127             case CM_ERROR_NOACCESS          : s = "CM_ERROR_NOACCESS";           break;
1128             case CM_ERROR_NOSUCHFILE        : s = "CM_ERROR_NOSUCHFILE";         break;
1129             case CM_ERROR_STOPNOW           : s = "CM_ERROR_STOPNOW";            break;
1130             case CM_ERROR_TOOBIG            : s = "CM_ERROR_TOOBIG";             break;
1131             case CM_ERROR_INVAL             : s = "CM_ERROR_INVAL";              break;
1132             case CM_ERROR_BADFD             : s = "CM_ERROR_BADFD";              break;
1133             case CM_ERROR_BADFDOP           : s = "CM_ERROR_BADFDOP";            break;
1134             case CM_ERROR_EXISTS            : s = "CM_ERROR_EXISTS";             break;
1135             case CM_ERROR_CROSSDEVLINK      : s = "CM_ERROR_CROSSDEVLINK";       break;
1136             case CM_ERROR_BADOP             : s = "CM_ERROR_BADOP";              break;
1137             case CM_ERROR_BADPASSWORD       : s = "CM_ERROR_BADPASSWORD";        break;
1138             case CM_ERROR_NOTDIR            : s = "CM_ERROR_NOTDIR";             break;
1139             case CM_ERROR_ISDIR             : s = "CM_ERROR_ISDIR";              break;
1140             case CM_ERROR_READONLY          : s = "CM_ERROR_READONLY";           break;
1141             case CM_ERROR_WOULDBLOCK        : s = "CM_ERROR_WOULDBLOCK";         break;
1142             case CM_ERROR_QUOTA             : s = "CM_ERROR_QUOTA";              break;
1143             case CM_ERROR_SPACE             : s = "CM_ERROR_SPACE";              break;
1144             case CM_ERROR_BADSHARENAME      : s = "CM_ERROR_BADSHARENAME";       break;
1145             case CM_ERROR_BADTID            : s = "CM_ERROR_BADTID";             break;
1146             case CM_ERROR_UNKNOWN           : s = "CM_ERROR_UNKNOWN";            break;
1147             case CM_ERROR_NOMORETOKENS      : s = "CM_ERROR_NOMORETOKENS";       break;
1148             case CM_ERROR_NOTEMPTY          : s = "CM_ERROR_NOTEMPTY";           break;
1149             case CM_ERROR_USESTD            : s = "CM_ERROR_USESTD";             break;
1150             case CM_ERROR_REMOTECONN        : s = "CM_ERROR_REMOTECONN";         break;
1151             case CM_ERROR_ATSYS             : s = "CM_ERROR_ATSYS";              break;
1152             case CM_ERROR_NOSUCHPATH        : s = "CM_ERROR_NOSUCHPATH";         break;
1153             case CM_ERROR_CLOCKSKEW         : s = "CM_ERROR_CLOCKSKEW";          break;
1154             case CM_ERROR_BADSMB            : s = "CM_ERROR_BADSMB";             break;
1155             case CM_ERROR_ALLBUSY           : s = "CM_ERROR_ALLBUSY";            break;
1156             case CM_ERROR_NOFILES           : s = "CM_ERROR_NOFILES";            break;
1157             case CM_ERROR_PARTIALWRITE      : s = "CM_ERROR_PARTIALWRITE";       break;
1158             case CM_ERROR_NOIPC             : s = "CM_ERROR_NOIPC";              break;
1159             case CM_ERROR_BADNTFILENAME     : s = "CM_ERROR_BADNTFILENAME";      break;
1160             case CM_ERROR_BUFFERTOOSMALL    : s = "CM_ERROR_BUFFERTOOSMALL";     break;
1161             case CM_ERROR_RENAME_IDENTICAL  : s = "CM_ERROR_RENAME_IDENTICAL";   break;
1162             case CM_ERROR_ALLOFFLINE        : s = "CM_ERROR_ALLOFFLINE";         break;
1163             case CM_ERROR_AMBIGUOUS_FILENAME: s = "CM_ERROR_AMBIGUOUS_FILENAME"; break;
1164             case CM_ERROR_BADLOGONTYPE      : s = "CM_ERROR_BADLOGONTYPE";       break;
1165             case CM_ERROR_GSSCONTINUE       : s = "CM_ERROR_GSSCONTINUE";        break;
1166             case CM_ERROR_TIDIPC            : s = "CM_ERROR_TIDIPC";             break;
1167             case CM_ERROR_TOO_MANY_SYMLINKS : s = "CM_ERROR_TOO_MANY_SYMLINKS";  break;
1168             case CM_ERROR_PATH_NOT_COVERED  : s = "CM_ERROR_PATH_NOT_COVERED";   break;
1169             case CM_ERROR_LOCK_CONFLICT     : s = "CM_ERROR_LOCK_CONFLICT";      break;
1170             case CM_ERROR_SHARING_VIOLATION : s = "CM_ERROR_SHARING_VIOLATION";  break;
1171             case CM_ERROR_ALLDOWN           : s = "CM_ERROR_ALLDOWN";            break;
1172             case CM_ERROR_TOOFEWBUFS        : s = "CM_ERROR_TOOFEWBUFS";         break;
1173             case CM_ERROR_TOOMANYBUFS       : s = "CM_ERROR_TOOMANYBUFS";        break;
1174             }
1175             osi_Log2(afsd_logp, "cm_Analyze: ignoring error code 0x%x (%s)",
1176                      errorCode, s);
1177             retry = 0;
1178         }
1179     }
1180
1181     /* If not allowed to retry, don't */
1182     if (!forcing_new && (reqp->flags & CM_REQ_NORETRY) &&
1183         (errorCode != RX_MSGSIZE && errorCode != RX_CALL_BUSY))
1184         retry = 0;
1185     else if (retry && dead_session)
1186         retry = 0;
1187
1188     /* drop this on the way out */
1189     if (connp)
1190         cm_PutConn(connp);
1191
1192     /*
1193      * clear the volume updated flag if we succeed.
1194      * this way the flag will not prevent a subsequent volume
1195      * from being updated if necessary.
1196      */
1197     if (errorCode == 0)
1198     {
1199         reqp->flags &= ~CM_REQ_VOLUME_UPDATED;
1200     }
1201
1202     /* retry until we fail to find a connection */
1203     return retry;
1204 }
1205
1206 long cm_ConnByMServers(cm_serverRef_t *serversp, afs_uint32 replicated, cm_user_t *usersp,
1207                        cm_req_t *reqp, cm_conn_t **connpp)
1208 {
1209     long code;
1210     cm_serverRef_t *tsrp;
1211     cm_server_t *tsp;
1212     long firstError = 0;
1213     int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
1214 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1215     long timeUsed, timeLeft, hardTimeLeft;
1216 #endif
1217     *connpp = NULL;
1218
1219     if (serversp == NULL) {
1220         osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", CM_ERROR_ALLDOWN);
1221         return CM_ERROR_ALLDOWN;
1222     }
1223
1224 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1225     timeUsed = (GetTickCount() - reqp->startTime) / 1000;
1226
1227     /* leave 5 seconds margin of safety */
1228     timeLeft =  ConnDeadtimeout - timeUsed - 5;
1229     hardTimeLeft = HardDeadtimeout - timeUsed - 5;
1230 #endif
1231
1232     lock_ObtainRead(&cm_serverLock);
1233     for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
1234         if (tsrp->status == srv_deleted)
1235             continue;
1236
1237         tsp = tsrp->server;
1238         if (reqp->tokenIdleErrorServp) {
1239             /*
1240              * search the list until we find the server
1241              * that failed last time.  When we find it
1242              * clear the error, skip it and try the next one
1243              * in the list.
1244              */
1245             if (tsp == reqp->tokenIdleErrorServp)
1246                 reqp->tokenIdleErrorServp = NULL;
1247             continue;
1248         }
1249         if (tsp) {
1250             cm_GetServerNoLock(tsp);
1251             lock_ReleaseRead(&cm_serverLock);
1252             if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1253                 allDown = 0;
1254                 if (tsrp->status == srv_busy) {
1255                     allOffline = 0;
1256                     someBusy = 1;
1257                 } else if (tsrp->status == srv_offline) {
1258                     allBusy = 0;
1259                     someOffline = 1;
1260                 } else {
1261                     allOffline = 0;
1262                     allBusy = 0;
1263                     code = cm_ConnByServer(tsp, usersp, replicated, connpp);
1264                     if (code == 0) {        /* cm_CBS only returns 0 */
1265                         cm_PutServer(tsp);
1266 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1267                         /* Set RPC timeout */
1268                         if (timeLeft > ConnDeadtimeout)
1269                             timeLeft = ConnDeadtimeout;
1270
1271                         if (hardTimeLeft > HardDeadtimeout)
1272                             hardTimeLeft = HardDeadtimeout;
1273
1274                         lock_ObtainMutex(&(*connpp)->mx);
1275                         rx_SetConnDeadTime((*connpp)->rxconnp, timeLeft);
1276                         rx_SetConnHardDeadTime((*connpp)->rxconnp, (u_short) hardTimeLeft);
1277                         lock_ReleaseMutex(&(*connpp)->mx);
1278 #endif
1279                         return 0;
1280                     }
1281
1282                     /* therefore, this code is never executed */
1283                     if (firstError == 0)
1284                         firstError = code;
1285                 }
1286             }
1287             lock_ObtainRead(&cm_serverLock);
1288             cm_PutServerNoLock(tsp);
1289         }
1290     }
1291     lock_ReleaseRead(&cm_serverLock);
1292
1293     if (firstError == 0) {
1294         if (allDown) {
1295             firstError = (reqp->tokenError ? reqp->tokenError :
1296                           (reqp->idleError ? RX_CALL_TIMEOUT : CM_ERROR_ALLDOWN));
1297             /*
1298              * if we experienced either a token error or and idle dead time error
1299              * and now all of the servers are down, we have either tried them
1300              * all or lost connectivity.  Clear the error we are returning so
1301              * we will not return it indefinitely if the request is retried.
1302              */
1303             reqp->idleError = reqp->tokenError = 0;
1304         } else if (allBusy) {
1305             firstError = CM_ERROR_ALLBUSY;
1306         } else if (allOffline || (someBusy && someOffline)) {
1307             firstError = CM_ERROR_ALLOFFLINE;
1308         } else {
1309             osi_Log0(afsd_logp, "cm_ConnByMServers returning impossible error TIMEDOUT");
1310             firstError = CM_ERROR_TIMEDOUT;
1311         }
1312     }
1313
1314     osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", firstError);
1315     return firstError;
1316 }
1317
1318 /* called with a held server to GC all bad connections hanging off of the server */
1319 void cm_GCConnections(cm_server_t *serverp)
1320 {
1321     cm_conn_t *tcp;
1322     cm_conn_t **lcpp;
1323     cm_user_t *userp;
1324
1325     lock_ObtainWrite(&cm_connLock);
1326     lcpp = &serverp->connsp;
1327     for (tcp = *lcpp; tcp; tcp = *lcpp) {
1328         userp = tcp->userp;
1329         if (userp && tcp->refCount == 0 && (userp->vcRefs == 0)) {
1330             /* do the deletion of this guy */
1331             cm_PutServer(tcp->serverp);
1332             cm_ReleaseUser(userp);
1333             *lcpp = tcp->nextp;
1334             rx_SetConnSecondsUntilNatPing(tcp->rxconnp, 0);
1335             rx_DestroyConnection(tcp->rxconnp);
1336             lock_FinalizeMutex(&tcp->mx);
1337             free(tcp);
1338         }
1339         else {
1340             /* just advance to the next */
1341             lcpp = &tcp->nextp;
1342         }
1343     }
1344     lock_ReleaseWrite(&cm_connLock);
1345 }
1346
1347 static void cm_NewRXConnection(cm_conn_t *tcp, cm_ucell_t *ucellp,
1348                                cm_server_t *serverp, afs_uint32 replicated)
1349 {
1350     unsigned short port;
1351     int serviceID;
1352     int secIndex;
1353     struct rx_securityClass *secObjp;
1354
1355     port = serverp->addr.sin_port;
1356     switch (serverp->type) {
1357     case CM_SERVER_VLDB:
1358         if (port == 0)
1359             port = htons(7003);
1360         serviceID = 52;
1361         break;
1362     case CM_SERVER_FILE:
1363         if (port == 0)
1364             port = htons(7000);
1365         serviceID = 1;
1366         break;
1367     default:
1368         osi_panic("unknown server type", __FILE__, __LINE__);
1369     }
1370
1371     if (ucellp->flags & CM_UCELLFLAG_RXKAD) {
1372         secIndex = 2;
1373         switch (cryptall) {
1374         case 0:
1375             tcp->cryptlevel = rxkad_clear;
1376             break;
1377         case 2:
1378             tcp->cryptlevel = rxkad_auth;
1379             break;
1380         default:
1381             tcp->cryptlevel = rxkad_crypt;
1382         }
1383         secObjp = rxkad_NewClientSecurityObject(tcp->cryptlevel,
1384                                                 &ucellp->sessionKey, ucellp->kvno,
1385                                                 ucellp->ticketLen, ucellp->ticketp);
1386     } else {
1387         /* normal auth */
1388         secIndex = 0;
1389         tcp->cryptlevel = rxkad_clear;
1390         secObjp = rxnull_NewClientSecurityObject();
1391     }
1392     osi_assertx(secObjp != NULL, "null rx_securityClass");
1393     tcp->rxconnp = rx_NewConnection(serverp->addr.sin_addr.s_addr,
1394                                     port,
1395                                     serviceID,
1396                                     secObjp,
1397                                     secIndex);
1398     rx_SetConnDeadTime(tcp->rxconnp, ConnDeadtimeout);
1399     rx_SetConnHardDeadTime(tcp->rxconnp, HardDeadtimeout);
1400
1401     /*
1402      * Setting idle dead timeout to a non-zero value activates RX_CALL_IDLE errors
1403      */
1404     if (replicated) {
1405         tcp->flags &= CM_CONN_FLAG_REPLICATION;
1406         rx_SetConnIdleDeadTime(tcp->rxconnp, ReplicaIdleDeadtimeout);
1407     } else {
1408         rx_SetConnIdleDeadTime(tcp->rxconnp, IdleDeadtimeout);
1409     }
1410
1411     /*
1412      * Let the Rx library know that we can auto-retry if an
1413      * RX_MSGSIZE error is returned.
1414      */
1415     if (rx_pmtu_discovery)
1416         rx_SetMsgsizeRetryErr(tcp->rxconnp, RX_MSGSIZE);
1417
1418     /*
1419      * Attempt to limit NAT pings to the anonymous file server connections.
1420      * Only file servers implement client callbacks and we only need one ping
1421      * to be sent to each server.
1422      */
1423     if (NatPingInterval && serverp->type == CM_SERVER_FILE &&
1424          (ucellp->flags & CM_UCELLFLAG_ROOTUSER)) {
1425         rx_SetConnSecondsUntilNatPing(tcp->rxconnp, NatPingInterval);
1426     }
1427
1428     tcp->ucgen = ucellp->gen;
1429     if (secObjp)
1430         rxs_Release(secObjp);   /* Decrement the initial refCount */
1431 }
1432
1433 long cm_ConnByServer(cm_server_t *serverp, cm_user_t *userp, afs_uint32 replicated, cm_conn_t **connpp)
1434 {
1435     cm_conn_t *tcp;
1436     cm_ucell_t *ucellp;
1437
1438     *connpp = NULL;
1439
1440     if (cm_anonvldb && serverp->type == CM_SERVER_VLDB)
1441         userp = cm_rootUserp;
1442
1443     lock_ObtainMutex(&userp->mx);
1444     lock_ObtainRead(&cm_connLock);
1445     for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1446         if (tcp->userp == userp &&
1447             (replicated && (tcp->flags & CM_CONN_FLAG_REPLICATION) ||
1448              !replicated && !(tcp->flags & CM_CONN_FLAG_REPLICATION)))
1449             break;
1450     }
1451
1452     /* find ucell structure */
1453     ucellp = cm_GetUCell(userp, serverp->cellp);
1454     if (!tcp) {
1455         lock_ConvertRToW(&cm_connLock);
1456         for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1457             if (tcp->userp == userp)
1458                 break;
1459         }
1460         if (tcp) {
1461             lock_ReleaseWrite(&cm_connLock);
1462             goto haveconn;
1463         }
1464         cm_GetServer(serverp);
1465         tcp = malloc(sizeof(*tcp));
1466         memset(tcp, 0, sizeof(*tcp));
1467         tcp->nextp = serverp->connsp;
1468         serverp->connsp = tcp;
1469         cm_HoldUser(userp);
1470         tcp->userp = userp;
1471         lock_InitializeMutex(&tcp->mx, "cm_conn_t mutex", LOCK_HIERARCHY_CONN);
1472         lock_ObtainMutex(&tcp->mx);
1473         tcp->serverp = serverp;
1474         tcp->cryptlevel = rxkad_clear;
1475         cm_NewRXConnection(tcp, ucellp, serverp, replicated);
1476         tcp->refCount = 1;
1477         lock_ReleaseMutex(&tcp->mx);
1478         lock_ReleaseWrite(&cm_connLock);
1479     } else {
1480         lock_ReleaseRead(&cm_connLock);
1481       haveconn:
1482         InterlockedIncrement(&tcp->refCount);
1483
1484         lock_ObtainMutex(&tcp->mx);
1485         if ((tcp->flags & CM_CONN_FLAG_FORCE_NEW) ||
1486             (tcp->ucgen < ucellp->gen) ||
1487             (tcp->cryptlevel != (ucellp->flags & CM_UCELLFLAG_RXKAD ? (cryptall == 1 ? rxkad_crypt : (cryptall == 2 ? rxkad_auth : rxkad_clear)) : rxkad_clear)))
1488         {
1489             if (tcp->ucgen < ucellp->gen)
1490                 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to token update");
1491             else
1492                 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to crypt change");
1493             tcp->flags &= ~CM_CONN_FLAG_FORCE_NEW;
1494             rx_SetConnSecondsUntilNatPing(tcp->rxconnp, 0);
1495             rx_DestroyConnection(tcp->rxconnp);
1496             cm_NewRXConnection(tcp, ucellp, serverp, replicated);
1497         }
1498         lock_ReleaseMutex(&tcp->mx);
1499     }
1500     lock_ReleaseMutex(&userp->mx);
1501
1502     /* return this pointer to our caller */
1503     osi_Log1(afsd_logp, "cm_ConnByServer returning conn 0x%p", tcp);
1504     *connpp = tcp;
1505
1506     return 0;
1507 }
1508
1509 long cm_ServerAvailable(struct cm_fid *fidp, struct cm_user *userp)
1510 {
1511     long code;
1512     cm_req_t req;
1513     cm_serverRef_t **serverspp;
1514     cm_serverRef_t *tsrp;
1515     cm_server_t *tsp;
1516     int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
1517     afs_uint32 replicated;
1518
1519     cm_InitReq(&req);
1520
1521     code = cm_GetServerList(fidp, userp, &req, &replicated, &serverspp);
1522     if (code)
1523         return 0;
1524
1525     lock_ObtainRead(&cm_serverLock);
1526     for (tsrp = *serverspp; tsrp; tsrp=tsrp->next) {
1527         if (tsrp->status == srv_deleted)
1528             continue;
1529         tsp = tsrp->server;
1530         if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1531             allDown = 0;
1532             if (tsrp->status == srv_busy) {
1533                 allOffline = 0;
1534                 someBusy = 1;
1535             } else if (tsrp->status == srv_offline) {
1536                 allBusy = 0;
1537                 someOffline = 1;
1538             } else {
1539                 allOffline = 0;
1540                 allBusy = 0;
1541             }
1542         }
1543     }
1544     lock_ReleaseRead(&cm_serverLock);
1545     cm_FreeServerList(serverspp, 0);
1546
1547     if (allDown)
1548         return 0;
1549     else if (allBusy)
1550         return 0;
1551     else if (allOffline || (someBusy && someOffline))
1552         return 0;
1553     else
1554         return 1;
1555 }
1556
1557 /*
1558  * The returned cm_conn_t ** object is released in the subsequent call
1559  * to cm_Analyze().
1560  */
1561 long cm_ConnFromFID(struct cm_fid *fidp, struct cm_user *userp, cm_req_t *reqp,
1562                     cm_conn_t **connpp)
1563 {
1564     long code;
1565     cm_serverRef_t **serverspp;
1566     afs_uint32 replicated;
1567
1568     *connpp = NULL;
1569
1570     code = cm_GetServerList(fidp, userp, reqp, &replicated, &serverspp);
1571     if (code)
1572         return code;
1573
1574     code = cm_ConnByMServers(*serverspp, replicated, userp, reqp, connpp);
1575     cm_FreeServerList(serverspp, 0);
1576     return code;
1577 }
1578
1579
1580 long cm_ConnFromVolume(struct cm_volume *volp, unsigned long volid, struct cm_user *userp, cm_req_t *reqp,
1581                        cm_conn_t **connpp)
1582 {
1583     long code;
1584     cm_serverRef_t **serverspp;
1585     afs_uint32 replicated;
1586     cm_vol_state_t * volstatep;
1587
1588     *connpp = NULL;
1589
1590     volstatep = cm_VolumeStateByID(volp, volid);
1591     replicated = (volstatep->flags & CM_VOL_STATE_FLAG_REPLICATED);
1592     serverspp = cm_GetVolServers(volp, volid, userp, reqp);
1593
1594     code = cm_ConnByMServers(*serverspp, replicated, userp, reqp, connpp);
1595     cm_FreeServerList(serverspp, 0);
1596     return code;
1597 }
1598
1599
1600 extern struct rx_connection *
1601 cm_GetRxConn(cm_conn_t *connp)
1602 {
1603     struct rx_connection * rxconnp;
1604     lock_ObtainMutex(&connp->mx);
1605     rxconnp = connp->rxconnp;
1606     rx_GetConnection(rxconnp);
1607     lock_ReleaseMutex(&connp->mx);
1608     return rxconnp;
1609 }
1610
1611 void cm_ForceNewConnections(cm_server_t *serverp)
1612 {
1613     cm_conn_t *tcp;
1614
1615     lock_ObtainWrite(&cm_connLock);
1616     for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1617         lock_ObtainMutex(&tcp->mx);
1618         tcp->flags |= CM_CONN_FLAG_FORCE_NEW;
1619         lock_ReleaseMutex(&tcp->mx);
1620     }
1621     lock_ReleaseWrite(&cm_connLock);
1622 }