windows-stress-test-fixes-20050330
[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 <afs/param.h>
11 #include <afs/stds.h>
12
13 #ifndef DJGPP
14 #include <windows.h>
15 #endif /* !DJGPP */
16 #include <string.h>
17 #include <malloc.h>
18 #include <osi.h>
19 #include <rx/rx.h>
20 #ifndef DJGPP
21 #include <rx/rxkad.h>
22 #else
23 #include <rx/rxkad.h>
24 #endif
25
26 #include "afsd.h"
27
28 osi_rwlock_t cm_connLock;
29
30 long RDRtimeout = CM_CONN_DEFAULTRDRTIMEOUT;
31 long ConnDeadtimeout = CM_CONN_CONNDEADTIME;
32 long HardDeadtimeout = CM_CONN_HARDDEADTIME;
33
34 #define LANMAN_WKS_PARAM_KEY "SYSTEM\\CurrentControlSet\\Services\\lanmanworkstation\\parameters"
35 #define LANMAN_WKS_SESSION_TIMEOUT "SessTimeout"
36
37 afs_int32 cryptall = 0;
38
39 void cm_PutConn(cm_conn_t *connp)
40 {
41         lock_ObtainWrite(&cm_connLock);
42         osi_assert(connp->refCount-- > 0);
43         lock_ReleaseWrite(&cm_connLock);
44 }
45
46 void cm_InitConn(void)
47 {
48         static osi_once_t once;
49         long code;
50         DWORD sessTimeout;
51         HKEY parmKey;
52         
53     if (osi_Once(&once)) {
54                 lock_InitializeRWLock(&cm_connLock, "connection global lock");
55
56         /* keisa - read timeout value for lanmanworkstation  service.
57          * jaltman - as per 
58          *   http://support.microsoft.com:80/support/kb/articles/Q102/0/67.asp&NoWebContent=1
59          * the SessTimeout is a minimum timeout not a maximum timeout.  Therefore, 
60          * I believe that the default should not be short.  Instead, we should wait until
61          * RX times out before reporting a timeout to the SMB client.
62          */
63                 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LANMAN_WKS_PARAM_KEY,
64                             0, KEY_QUERY_VALUE, &parmKey);
65                 if (code == ERROR_SUCCESS)
66         {
67                     DWORD dummyLen = sizeof(sessTimeout);
68                     code = RegQueryValueEx(parmKey, LANMAN_WKS_SESSION_TIMEOUT, NULL, NULL, 
69                                    (BYTE *) &sessTimeout, &dummyLen);
70                     if (code == ERROR_SUCCESS)
71             {
72                 afsi_log("lanmanworkstation : SessTimeout %d", sessTimeout);
73                 RDRtimeout = sessTimeout;
74                 if ( ConnDeadtimeout < RDRtimeout + 15 ) {
75                     ConnDeadtimeout = RDRtimeout + 15;
76                     afsi_log("ConnDeadTimeout increased to %d", ConnDeadtimeout);
77                 }
78                 if ( HardDeadtimeout < 2 * ConnDeadtimeout ) {
79                     HardDeadtimeout = 2 * ConnDeadtimeout;
80                     afsi_log("HardDeadTimeout increased to %d", HardDeadtimeout);
81                 }
82             }
83         }
84
85         osi_EndOnce(&once);
86     }
87 }
88
89 void cm_InitReq(cm_req_t *reqp)
90 {
91         memset((char *)reqp, 0, sizeof(cm_req_t));
92 #ifndef DJGPP
93         reqp->startTime = GetCurrentTime();
94 #else
95         gettimeofday(&reqp->startTime, NULL);
96 #endif
97 }
98
99 static long cm_GetServerList(struct cm_fid *fidp, struct cm_user *userp,
100         struct cm_req *reqp, cm_serverRef_t ***serversppp)
101 {
102     long code;
103     cm_volume_t *volp = NULL;
104     cm_cell_t *cellp = NULL;
105
106     if (!fidp) {
107         *serversppp = NULL;
108         return 0;
109     }
110
111     cellp = cm_FindCellByID(fidp->cell);
112     if (!cellp) return CM_ERROR_NOSUCHCELL;
113
114     code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp, &volp);
115     if (code) return code;
116     
117     *serversppp = cm_GetVolServers(volp, fidp->volume);
118
119     cm_PutVolume(volp);
120     return 0;
121 }
122
123 /*
124  * Analyze the error return from an RPC.  Determine whether or not to retry,
125  * and if we're going to retry, determine whether failover is appropriate,
126  * and whether timed backoff is appropriate.
127  *
128  * If the error code is from cm_Conn() or friends, it will be a CM_ERROR code.
129  * Otherwise it will be an RPC code.  This may be a UNIX code (e.g. EDQUOT), or
130  * it may be an RX code, or it may be a special code (e.g. VNOVOL), or it may
131  * be a security code (e.g. RXKADEXPIRED).
132  *
133  * If the error code is from cm_Conn() or friends, connp will be NULL.
134  *
135  * For VLDB calls, fidp will be NULL.
136  *
137  * volSyncp and/or cbrp may also be NULL.
138  */
139 int
140 cm_Analyze(cm_conn_t *connp, cm_user_t *userp, cm_req_t *reqp,
141            struct cm_fid *fidp, 
142            AFSVolSync *volSyncp, 
143            cm_serverRef_t * serversp,
144            cm_callbackRequest_t *cbrp, long errorCode)
145 {
146     cm_server_t *serverp = 0;
147     cm_serverRef_t **serverspp = 0;
148     cm_serverRef_t *tsrp;
149     cm_ucell_t *ucellp;
150     int retry = 0;
151     int free_svr_list = 0;
152     int dead_session;
153     long timeUsed, timeLeft;
154         
155     osi_Log2(afsd_logp, "cm_Analyze connp 0x%x, code 0x%x",
156              (long) connp, errorCode);
157
158     /* no locking required, since connp->serverp never changes after
159      * creation */
160     dead_session = (userp->cellInfop == NULL);
161     if (connp)
162         serverp = connp->serverp;
163
164     /* Update callback pointer */
165     if (cbrp && serverp && errorCode == 0) {
166         if (cbrp->serverp) {
167             if ( cbrp->serverp != serverp ) {
168                 lock_ObtainWrite(&cm_serverLock);
169                 cm_PutServerNoLock(cbrp->serverp);
170                 cm_GetServerNoLock(serverp);
171                 lock_ReleaseWrite(&cm_serverLock);
172             }
173         } else {
174             cm_GetServer(serverp);
175         }
176         lock_ObtainWrite(&cm_callbackLock);
177         cbrp->serverp = serverp;
178         lock_ReleaseWrite(&cm_callbackLock);
179     }
180
181     /* If not allowed to retry, don't */
182     if (reqp->flags & CM_REQ_NORETRY)
183         goto out;
184
185     /* if timeout - check that it did not exceed the SMB timeout
186      * and retry */
187     
188     /* timeleft - get if from reqp the same way as cmXonnByMServers does */
189 #ifndef DJGPP
190     timeUsed = (GetCurrentTime() - reqp->startTime) / 1000;
191 #else
192     gettimeofday(&now, NULL);
193     timeUsed = sub_time(now, reqp->startTime) / 1000;
194 #endif
195             
196     /* leave 5 seconds margin for sleep */
197     timeLeft = RDRtimeout - timeUsed;
198
199     if (errorCode == CM_ERROR_TIMEDOUT) {
200         if (timeLeft > 5 ) {
201             thrd_Sleep(3000);
202             cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, NULL);
203             retry = 1;
204         }
205     } 
206
207     /* if there is nosuchvolume, then we have a situation in which a 
208      * previously known volume no longer has a set of servers 
209      * associated with it.  Either the volume has moved or
210      * the volume has been deleted.  Try to find a new server list
211      * until the timeout period expires.
212      */
213     else if (errorCode == CM_ERROR_NOSUCHVOLUME) {
214         if (timeLeft > 7) {
215             osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_NOSUCHVOLUME.");
216             thrd_Sleep(5000);
217             
218             retry = 1;
219
220             if (fidp != NULL)   /* Not a VLDB call */
221                 cm_ForceUpdateVolume(fidp, userp, reqp);
222         }
223     }
224
225     else if (errorCode == CM_ERROR_ALLOFFLINE) {
226         if (timeLeft > 7) {
227             osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE.");
228             thrd_Sleep(5000);
229             /* cm_ForceUpdateVolume marks all servers as non_busy */
230             /* No it doesn't and it won't do anything if all of the 
231              * the servers are marked as DOWN.  So clear the DOWN
232              * flag and reset the busy state as well.
233              */
234             if (!serversp) {
235                 cm_GetServerList(fidp, userp, reqp, &serverspp);
236                 serversp = *serverspp;
237                 free_svr_list = 1;
238             }
239             if (serversp) {
240                 lock_ObtainWrite(&cm_serverLock);
241                 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
242                     tsrp->server->flags &= ~CM_SERVERFLAG_DOWN;
243                     if (tsrp->status == busy)
244                         tsrp->status = not_busy;
245                 }
246                 lock_ReleaseWrite(&cm_serverLock);
247                 if (free_svr_list) {
248                     cm_FreeServerList(&serversp);
249                     *serverspp = serversp;
250                 }
251                 retry = 1;
252             }
253
254             if (fidp != NULL)   /* Not a VLDB call */
255                 cm_ForceUpdateVolume(fidp, userp, reqp);
256         }
257     }
258
259     /* if all servers are busy, mark them non-busy and start over */
260     else if (errorCode == CM_ERROR_ALLBUSY) {
261         if (timeLeft > 7) {
262             thrd_Sleep(5000);
263             if (!serversp) {
264                 cm_GetServerList(fidp, userp, reqp, &serverspp);
265                 serversp = *serverspp;
266                 free_svr_list = 1;
267             }
268             lock_ObtainWrite(&cm_serverLock);
269             for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
270                 if (tsrp->status == busy)
271                     tsrp->status = not_busy;
272             }
273             lock_ReleaseWrite(&cm_serverLock);
274             if (free_svr_list) {
275                 cm_FreeServerList(&serversp);
276                 *serverspp = serversp;
277             }
278             retry = 1;
279         }
280     }
281
282     /* special codes:  VBUSY and VRESTARTING */
283     else if (errorCode == VBUSY || errorCode == VRESTARTING) {
284         if (!serversp) {
285             cm_GetServerList(fidp, userp, reqp, &serverspp);
286             serversp = *serverspp;
287             free_svr_list = 1;
288         }
289         lock_ObtainWrite(&cm_serverLock);
290         for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
291             if (tsrp->server == serverp
292                  && tsrp->status == not_busy) {
293                 tsrp->status = busy;
294                 break;
295             }
296         }
297         lock_ReleaseWrite(&cm_serverLock);
298         if (free_svr_list) {
299             cm_FreeServerList(&serversp);
300             *serverspp = serversp;
301         }
302         retry = 1;
303     }
304
305     /* special codes:  missing volumes */
306     else if (errorCode == VNOVOL || errorCode == VMOVED || errorCode == VOFFLINE
307          || errorCode == VSALVAGE || errorCode == VNOSERVICE) 
308     {       
309         /* Log server being offline for this volume */
310         osi_Log4(afsd_logp, "cm_Analyze found server %d.%d.%d.%d marked offline for a volume",
311                   ((serverp->addr.sin_addr.s_addr & 0xff)),
312                   ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
313                   ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
314                   ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
315         /* Create Event Log message */ 
316         {
317             HANDLE h;
318             char *ptbuf[1];
319             char s[100];
320             h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
321             sprintf(s, "cm_Analyze: Server %d.%d.%d.%d reported volume %d as missing.",
322                      ((serverp->addr.sin_addr.s_addr & 0xff)),
323                      ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
324                      ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
325                      ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24),
326                      fidp->volume);
327             ptbuf[0] = s;
328             ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1009, NULL,
329                          1, 0, ptbuf, NULL);
330             DeregisterEventSource(h);
331         }
332
333         /* Mark server offline for this volume */
334         if (!serversp) {
335             cm_GetServerList(fidp, userp, reqp, &serverspp);
336             serversp = *serverspp;
337             free_svr_list = 1;
338         }
339         for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
340             if (tsrp->server == serverp)
341                 tsrp->status = offline;
342         }   
343         if (free_svr_list) {
344             cm_FreeServerList(&serversp);
345             *serverspp = serversp;
346         }
347         if ( timeLeft > 2 )
348             retry = 1;
349     }
350
351     /* RX codes */
352     else if (errorCode == RX_CALL_TIMEOUT) {
353         /* server took longer than hardDeadTime 
354          * don't mark server as down but don't retry
355          * this is to prevent the SMB session from timing out
356          * In addition, we log an event to the event log 
357          */
358 #ifndef DJGPP
359         HANDLE h;
360         char *ptbuf[1];
361         char s[100];
362         h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
363         sprintf(s, "cm_Analyze: HardDeadTime exceeded.");
364         ptbuf[0] = s;
365         ReportEvent(h, EVENTLOG_WARNING_TYPE, 0, 1009, NULL,
366                      1, 0, ptbuf, NULL);
367         DeregisterEventSource(h);
368 #endif /* !DJGPP */
369           
370         retry = 0;
371         osi_Log0(afsd_logp, "cm_Analyze: hardDeadTime exceeded");
372     }
373     else if (errorCode >= -64 && errorCode < 0) {
374         /* mark server as down */
375         lock_ObtainMutex(&serverp->mx);
376         serverp->flags |= CM_SERVERFLAG_DOWN;
377         lock_ReleaseMutex(&serverp->mx);
378         if ( timeLeft > 2 )
379             retry = 1;
380     }
381     else if (errorCode == RXKADEXPIRED) {
382         if (!dead_session) {
383             lock_ObtainMutex(&userp->mx);
384             ucellp = cm_GetUCell(userp, serverp->cellp);
385             if (ucellp->ticketp) {
386                 free(ucellp->ticketp);
387                 ucellp->ticketp = NULL;
388             }
389             ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
390             ucellp->gen++;
391             lock_ReleaseMutex(&userp->mx);
392             if ( timeLeft > 2 )
393                 retry = 1;
394         }
395     } else {
396         if (errorCode)
397             osi_Log1(afsd_logp, "cm_Analyze: ignoring error code 0x%x", errorCode);
398     }
399
400     if (retry && dead_session)
401         retry = 0;
402
403   out:
404     /* drop this on the way out */
405     if (connp)
406         cm_PutConn(connp);
407
408     /* retry until we fail to find a connection */
409     return retry;
410 }
411
412 long cm_ConnByMServers(cm_serverRef_t *serversp, cm_user_t *usersp,
413         cm_req_t *reqp, cm_conn_t **connpp)
414 {
415     long code;
416     cm_serverRef_t *tsrp;
417     cm_server_t *tsp;
418     long firstError = 0;
419     int someBusy = 0, someOffline = 0, allBusy = 1, allDown = 1;
420     long timeUsed, timeLeft, hardTimeLeft;
421 #ifdef DJGPP
422     struct timeval now;
423 #endif /* DJGPP */        
424
425     *connpp = NULL;
426
427 #ifndef DJGPP
428     timeUsed = (GetCurrentTime() - reqp->startTime) / 1000;
429 #else
430     gettimeofday(&now, NULL);
431     timeUsed = sub_time(now, reqp->startTime) / 1000;
432 #endif
433         
434     /* leave 5 seconds margin of safety */
435     timeLeft =  ConnDeadtimeout - timeUsed - 5;
436     hardTimeLeft = HardDeadtimeout - timeUsed - 5;
437
438     lock_ObtainWrite(&cm_serverLock);
439     for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
440         tsp = tsrp->server;
441         cm_GetServerNoLock(tsp);
442         lock_ReleaseWrite(&cm_serverLock);
443         if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
444             if (tsrp->status == busy) {
445                 allDown = 0;
446                 someBusy = 1;
447             } else if (tsrp->status == offline) {
448                 someOffline = 1;
449             } else {
450                 allDown = 0;
451                 allBusy = 0;
452                 code = cm_ConnByServer(tsp, usersp, connpp);
453                 if (code == 0) {        /* cm_CBS only returns 0 */
454                     cm_PutServer(tsp);
455                     /* Set RPC timeout */
456                     if (timeLeft > ConnDeadtimeout)
457                         timeLeft = ConnDeadtimeout;
458
459                     if (hardTimeLeft > HardDeadtimeout) 
460                         hardTimeLeft = HardDeadtimeout;
461
462                     lock_ObtainMutex(&(*connpp)->mx);
463                     rx_SetConnDeadTime((*connpp)->callp, timeLeft);
464                     rx_SetConnHardDeadTime((*connpp)->callp, (u_short) hardTimeLeft);
465                     lock_ReleaseMutex(&(*connpp)->mx);
466                     return 0;
467                 }
468                 
469                 /* therefore, this code is never executed */
470                 if (firstError == 0)
471                     firstError = code;
472             }
473         }
474         lock_ObtainWrite(&cm_serverLock);
475         cm_PutServerNoLock(tsp);
476     }   
477
478     lock_ReleaseWrite(&cm_serverLock);
479     if (firstError == 0) {
480         if (serversp == NULL)
481             firstError = CM_ERROR_NOSUCHVOLUME;
482         else if (allDown) 
483             firstError = CM_ERROR_ALLOFFLINE;
484         else if (allBusy) 
485             firstError = CM_ERROR_ALLBUSY;
486         else {
487             osi_Log0(afsd_logp, "cm_ConnByMServers returning impossible error TIMEDOUT");
488             firstError = CM_ERROR_TIMEDOUT;
489         }
490     }
491
492     osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", firstError);
493     return firstError;
494 }
495
496 /* called with a held server to GC all bad connections hanging off of the server */
497 void cm_GCConnections(cm_server_t *serverp)
498 {
499     cm_conn_t *tcp;
500     cm_conn_t **lcpp;
501     cm_user_t *userp;
502
503     lock_ObtainWrite(&cm_connLock);
504     lcpp = &serverp->connsp;
505     for (tcp = *lcpp; tcp; tcp = *lcpp) {
506         userp = tcp->userp;
507         if (userp && tcp->refCount == 0 && (userp->vcRefs == 0)) {
508             /* do the deletion of this guy */
509             cm_PutServer(tcp->serverp);
510             cm_ReleaseUser(userp);
511             *lcpp = tcp->nextp;
512             rx_DestroyConnection(tcp->callp);
513             lock_FinalizeMutex(&tcp->mx);
514             free(tcp);
515         }
516         else {
517             /* just advance to the next */
518             lcpp = &tcp->nextp;
519         }
520     }
521     lock_ReleaseWrite(&cm_connLock);
522 }
523
524 static void cm_NewRXConnection(cm_conn_t *tcp, cm_ucell_t *ucellp,
525                                cm_server_t *serverp)
526 {
527     unsigned short port;
528     int serviceID;
529     int secIndex;
530     struct rx_securityClass *secObjp;
531
532     if (serverp->type == CM_SERVER_VLDB) {
533         port = htons(7003);
534         serviceID = 52;
535     }
536     else {
537         osi_assert(serverp->type == CM_SERVER_FILE);
538         port = htons(7000);
539         serviceID = 1;
540     }
541     if (ucellp->flags & CM_UCELLFLAG_RXKAD) {
542         secIndex = 2;
543         if (cryptall) {
544             tcp->cryptlevel = rxkad_crypt;
545         } else {
546             tcp->cryptlevel = rxkad_clear;
547         }
548         secObjp = rxkad_NewClientSecurityObject(tcp->cryptlevel,
549                                                 &ucellp->sessionKey, ucellp->kvno,
550                                                 ucellp->ticketLen, ucellp->ticketp);    
551     } else {
552         /* normal auth */
553         secIndex = 0;
554         tcp->cryptlevel = rxkad_clear;
555         secObjp = rxnull_NewClientSecurityObject();
556     }
557     osi_assert(secObjp != NULL);
558     tcp->callp = rx_NewConnection(serverp->addr.sin_addr.s_addr,
559                                   port,
560                                   serviceID,
561                                   secObjp,
562                                   secIndex);
563     rx_SetConnDeadTime(tcp->callp, ConnDeadtimeout);
564     rx_SetConnHardDeadTime(tcp->callp, HardDeadtimeout);
565     tcp->ucgen = ucellp->gen;
566     if (secObjp)
567         rxs_Release(secObjp);   /* Decrement the initial refCount */
568 }
569
570 long cm_ConnByServer(cm_server_t *serverp, cm_user_t *userp, cm_conn_t **connpp)
571 {
572     cm_conn_t *tcp;
573     cm_ucell_t *ucellp;
574
575     lock_ObtainMutex(&userp->mx);
576     lock_ObtainWrite(&cm_connLock);
577     for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
578         if (tcp->userp == userp) 
579             break;
580     }
581     
582     /* find ucell structure */
583     ucellp = cm_GetUCell(userp, serverp->cellp);
584     if (!tcp) {
585         cm_GetServer(serverp);
586         tcp = malloc(sizeof(*tcp));
587         memset(tcp, 0, sizeof(*tcp));
588         tcp->nextp = serverp->connsp;
589         serverp->connsp = tcp;
590         cm_HoldUser(userp);
591         tcp->userp = userp;
592         lock_InitializeMutex(&tcp->mx, "cm_conn_t mutex");
593         lock_ObtainMutex(&tcp->mx);
594         tcp->serverp = serverp;
595         tcp->cryptlevel = rxkad_clear;
596         cm_NewRXConnection(tcp, ucellp, serverp);
597         tcp->refCount = 1;
598         lock_ReleaseMutex(&tcp->mx);
599     } else {
600         if ((tcp->ucgen < ucellp->gen) ||
601             (tcp->cryptlevel != (cryptall ? (ucellp->flags & CM_UCELLFLAG_RXKAD ? rxkad_crypt : rxkad_clear) : rxkad_clear)))
602         {
603             if (tcp->ucgen < ucellp->gen)
604                 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to token update");
605             else
606                 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to crypt change");
607             lock_ObtainMutex(&tcp->mx);
608             rx_DestroyConnection(tcp->callp);
609             cm_NewRXConnection(tcp, ucellp, serverp);
610             lock_ReleaseMutex(&tcp->mx);
611         }
612         tcp->refCount++;
613     }
614     lock_ReleaseWrite(&cm_connLock);
615     lock_ReleaseMutex(&userp->mx);
616
617     /* return this pointer to our caller */
618     osi_Log1(afsd_logp, "cm_ConnByServer returning conn 0x%x", (long) tcp);
619     *connpp = tcp;
620
621     return 0;
622 }
623
624 long cm_Conn(struct cm_fid *fidp, struct cm_user *userp, cm_req_t *reqp,
625              cm_conn_t **connpp)
626 {
627     long code;
628
629     cm_serverRef_t **serverspp;
630
631     code = cm_GetServerList(fidp, userp, reqp, &serverspp);
632     if (code) {
633         *connpp = NULL;
634         return code;
635     }
636
637     code = cm_ConnByMServers(*serverspp, userp, reqp, connpp);
638     cm_FreeServerList(serverspp);
639     return code;
640 }
641
642 extern struct rx_connection * 
643 cm_GetRxConn(cm_conn_t *connp)
644 {
645     struct rx_connection * rxconn;
646     lock_ObtainMutex(&connp->mx);
647     rxconn = connp->callp;
648     rx_GetConnection(rxconn);
649     lock_ReleaseMutex(&connp->mx);
650     return rxconn;
651 }
652