2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
23 #include <afs/unified_afs.h>
24 #include <afs/vlserver.h>
25 #include <WINNT/afsreg.h>
27 osi_rwlock_t cm_connLock;
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 NatPingInterval = CM_CONN_NATPINGINTERVAL;
35 #define LANMAN_WKS_PARAM_KEY "SYSTEM\\CurrentControlSet\\Services\\lanmanworkstation\\parameters"
36 #define LANMAN_WKS_SESSION_TIMEOUT "SessTimeout"
37 #define LANMAN_WKS_EXT_SESSION_TIMEOUT "ExtendedSessTimeout"
39 afs_uint32 cryptall = 0;
40 afs_uint32 cm_anonvldb = 0;
41 afs_uint32 rx_pmtu_discovery = 0;
43 void cm_PutConn(cm_conn_t *connp)
45 afs_int32 refCount = InterlockedDecrement(&connp->refCount);
46 osi_assertx(refCount >= 0, "cm_conn_t refcount underflow");
49 void cm_InitConn(void)
51 static osi_once_t once;
57 if (osi_Once(&once)) {
58 lock_InitializeRWLock(&cm_connLock, "connection global lock",
59 LOCK_HIERARCHY_CONN_GLOBAL);
61 /* keisa - read timeout value for lanmanworkstation service.
63 * http://support.microsoft.com:80/support/kb/articles/Q102/0/67.asp&NoWebContent=1
64 * the SessTimeout is a minimum timeout not a maximum timeout. Therefore,
65 * I believe that the default should not be short. Instead, we should wait until
66 * RX times out before reporting a timeout to the SMB client.
68 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LANMAN_WKS_PARAM_KEY,
69 0, KEY_QUERY_VALUE, &parmKey);
70 if (code == ERROR_SUCCESS)
72 BOOL extTimeouts = msftSMBRedirectorSupportsExtendedTimeouts();
76 * The default value is 1000 seconds. However, this default
77 * will not apply to "\\AFS" unless "AFS" is listed in
78 * ServersWithExtendedSessTimeout which we will add when we
79 * create the ExtendedSessTimeout value in smb_Init()
81 dummyLen = sizeof(DWORD);
82 code = RegQueryValueEx(parmKey,
83 LANMAN_WKS_EXT_SESSION_TIMEOUT,
85 (BYTE *) &dwValue, &dummyLen);
86 if (code == ERROR_SUCCESS) {
88 afsi_log("lanmanworkstation : ExtSessTimeout %u", RDRtimeout);
91 if (!extTimeouts || code != ERROR_SUCCESS) {
92 dummyLen = sizeof(DWORD);
93 code = RegQueryValueEx(parmKey,
94 LANMAN_WKS_SESSION_TIMEOUT,
96 (BYTE *) &dwValue, &dummyLen);
97 if (code == ERROR_SUCCESS) {
99 afsi_log("lanmanworkstation : SessTimeout %u", RDRtimeout);
102 RegCloseKey(parmKey);
105 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
106 0, KEY_QUERY_VALUE, &parmKey);
107 if (code == ERROR_SUCCESS) {
108 dummyLen = sizeof(DWORD);
109 code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
110 (BYTE *) &dwValue, &dummyLen);
111 if (code == ERROR_SUCCESS) {
112 ConnDeadtimeout = (unsigned short)dwValue;
113 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
115 dummyLen = sizeof(DWORD);
116 code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
117 (BYTE *) &dwValue, &dummyLen);
118 if (code == ERROR_SUCCESS) {
119 HardDeadtimeout = (unsigned short)dwValue;
120 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
122 dummyLen = sizeof(DWORD);
123 code = RegQueryValueEx(parmKey, "IdleDeadTimeout", NULL, NULL,
124 (BYTE *) &dwValue, &dummyLen);
125 if (code == ERROR_SUCCESS) {
126 IdleDeadtimeout = (unsigned short)dwValue;
127 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
129 dummyLen = sizeof(DWORD);
130 code = RegQueryValueEx(parmKey, "NatPingInterval", NULL, NULL,
131 (BYTE *) &dwValue, &dummyLen);
132 if (code == ERROR_SUCCESS) {
133 NatPingInterval = (unsigned short)dwValue;
135 afsi_log("NatPingInterval is %d", NatPingInterval);
136 RegCloseKey(parmKey);
140 * If these values were not set via cpp macro or obtained
141 * from the registry, we use a value that is derived from
142 * the smb redirector session timeout (RDRtimeout).
144 * The UNIX cache manager uses 120 seconds for the hard dead
145 * timeout and 50 seconds for the connection and idle timeouts.
147 * We base our values on those while making sure we leave
148 * enough time for overhead.
150 if (ConnDeadtimeout == 0) {
151 ConnDeadtimeout = (unsigned short) ((RDRtimeout / 2) < 50 ? (RDRtimeout / 2) : 50);
152 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
154 if (HardDeadtimeout == 0) {
155 HardDeadtimeout = (unsigned short) (RDRtimeout > 125 ? 120 : (RDRtimeout - 5));
156 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
158 if (IdleDeadtimeout == 0) {
159 IdleDeadtimeout = (unsigned short) ConnDeadtimeout;
160 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
166 void cm_InitReq(cm_req_t *reqp)
168 memset(reqp, 0, sizeof(cm_req_t));
169 reqp->startTime = GetTickCount();
172 static long cm_GetServerList(struct cm_fid *fidp, struct cm_user *userp,
173 struct cm_req *reqp, cm_serverRef_t ***serversppp)
176 cm_volume_t *volp = NULL;
177 cm_cell_t *cellp = NULL;
181 return CM_ERROR_INVAL;
184 cellp = cm_FindCellByID(fidp->cell, 0);
186 return CM_ERROR_NOSUCHCELL;
188 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp, CM_GETVOL_FLAG_CREATE, &volp);
192 *serversppp = cm_GetVolServers(volp, fidp->volume, userp, reqp);
194 lock_ObtainRead(&cm_volumeLock);
196 lock_ReleaseRead(&cm_volumeLock);
197 return (*serversppp ? 0 : CM_ERROR_NOSUCHVOLUME);
201 * Analyze the error return from an RPC. Determine whether or not to retry,
202 * and if we're going to retry, determine whether failover is appropriate,
203 * and whether timed backoff is appropriate.
205 * If the error code is from cm_ConnFromFID() or friends, it will be a CM_ERROR code.
206 * Otherwise it will be an RPC code. This may be a UNIX code (e.g. EDQUOT), or
207 * it may be an RX code, or it may be a special code (e.g. VNOVOL), or it may
208 * be a security code (e.g. RXKADEXPIRED).
210 * If the error code is from cm_ConnFromFID() or friends, connp will be NULL.
212 * For VLDB calls, fidp will be NULL.
214 * volSyncp and/or cbrp may also be NULL.
217 cm_Analyze(cm_conn_t *connp, cm_user_t *userp, cm_req_t *reqp,
219 AFSVolSync *volSyncp,
220 cm_serverRef_t * serversp,
221 cm_callbackRequest_t *cbrp, long errorCode)
223 cm_server_t *serverp = NULL;
224 cm_serverRef_t **serverspp = NULL;
225 cm_serverRef_t *tsrp;
226 cm_cell_t *cellp = NULL;
228 cm_volume_t * volp = NULL;
229 cm_vol_state_t *statep = NULL;
231 int free_svr_list = 0;
233 long timeUsed, timeLeft;
235 char addr[16]="unknown";
237 int location_updated = 0;
241 osi_Log2(afsd_logp, "cm_Analyze connp 0x%p, code 0x%x",
244 /* no locking required, since connp->serverp never changes after
246 dead_session = (userp->cellInfop == NULL);
248 serverp = connp->serverp;
250 /* Update callback pointer */
251 if (cbrp && serverp && errorCode == 0) {
253 if ( cbrp->serverp != serverp ) {
254 lock_ObtainWrite(&cm_serverLock);
255 cm_PutServerNoLock(cbrp->serverp);
256 cm_GetServerNoLock(serverp);
257 lock_ReleaseWrite(&cm_serverLock);
260 cm_GetServer(serverp);
262 lock_ObtainWrite(&cm_callbackLock);
263 cbrp->serverp = serverp;
264 lock_ReleaseWrite(&cm_callbackLock);
267 /* if timeout - check that it did not exceed the HardDead timeout
270 /* timeleft - get it from reqp the same way as cm_ConnByMServers does */
271 timeUsed = (GetTickCount() - reqp->startTime) / 1000;
272 timeLeft = HardDeadtimeout - timeUsed;
274 /* get a pointer to the cell */
276 if (cellp == NULL && serverp)
277 cellp = serverp->cellp;
278 if (cellp == NULL && serversp) {
279 struct cm_serverRef * refp;
280 for ( refp=serversp ; cellp == NULL && refp != NULL; refp=refp->next) {
281 if (refp->status == srv_deleted)
284 cellp = refp->server->cellp;
287 if (cellp == NULL && fidp) {
288 cellp = cm_FindCellByID(fidp->cell, 0);
292 if (errorCode == CM_ERROR_TIMEDOUT) {
293 if ( timeLeft > 5 ) {
295 cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, cellp);
300 else if (errorCode == UAEWOULDBLOCK || errorCode == EWOULDBLOCK ||
301 errorCode == UAEAGAIN || errorCode == EAGAIN) {
302 osi_Log0(afsd_logp, "cm_Analyze passed EWOULDBLOCK or EAGAIN.");
303 if ( timeLeft > 5 ) {
309 /* if there is nosuchvolume, then we have a situation in which a
310 * previously known volume no longer has a set of servers
311 * associated with it. Either the volume has moved or
312 * the volume has been deleted. Try to find a new server list
313 * until the timeout period expires.
315 else if (errorCode == CM_ERROR_NOSUCHVOLUME) {
316 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_NOSUCHVOLUME.");
318 * The VNOVOL or VL_NOENT error has already been translated
319 * to CM_ERROR_NOSUCHVOLUME. There is nothing for us to do.
323 else if (errorCode == CM_ERROR_ALLDOWN) {
324 /* Servers marked DOWN will be restored by the background daemon
325 * thread as they become available. The volume status is
326 * updated as the server state changes.
329 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_DOWN (FS cell %s vol 0x%x)",
330 cellp->name, fidp->volume);
331 msgID = MSG_ALL_SERVERS_DOWN;
332 format = "All servers are unreachable when accessing cell %s volume %d.";
333 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
335 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLDOWN (VL Server)");
339 else if (errorCode == CM_ERROR_ALLOFFLINE) {
340 /* Volume instances marked offline will be restored by the
341 * background daemon thread as they become available
344 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE (FS cell %s vol 0x%x)",
345 cellp->name, fidp->volume);
346 msgID = MSG_ALL_SERVERS_OFFLINE;
347 format = "All servers are offline when accessing cell %s volume %d.";
348 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
350 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
351 CM_GETVOL_FLAG_NO_LRU_UPDATE,
357 /* cm_CheckOfflineVolume() resets the serverRef state */
358 if (cm_CheckOfflineVolume(volp, fidp->volume))
361 cm_UpdateVolumeStatus(volp, fidp->volume);
363 lock_ObtainRead(&cm_volumeLock);
365 lock_ReleaseRead(&cm_volumeLock);
369 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE (VL Server)");
372 else if (errorCode == CM_ERROR_ALLBUSY) {
373 /* Volumes that are busy cannot be determined to be non-busy
374 * without actually attempting to access them.
376 if (fidp) { /* File Server query */
377 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY (FS cell %s vol 0x%x)",
378 cellp->name, fidp->volume);
379 msgID = MSG_ALL_SERVERS_BUSY;
380 format = "All servers are busy when accessing cell %s volume %d.";
381 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
383 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
384 CM_GETVOL_FLAG_NO_LRU_UPDATE,
390 statep = cm_VolumeStateByID(volp, fidp->volume);
391 if (statep->state != vl_offline &&
392 statep->state != vl_busy &&
393 statep->state != vl_unknown) {
397 code = cm_GetServerList(fidp, userp, reqp, &serverspp);
399 serversp = *serverspp;
403 lock_ObtainWrite(&cm_serverLock);
404 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
405 if (tsrp->status == srv_deleted)
407 if (tsrp->status == srv_busy) {
408 tsrp->status = srv_not_busy;
411 lock_ReleaseWrite(&cm_serverLock);
413 cm_FreeServerList(serverspp, 0);
418 cm_UpdateVolumeStatus(volp, fidp->volume);
422 cm_UpdateVolumeStatus(volp, fidp->volume);
425 lock_ObtainRead(&cm_volumeLock);
427 lock_ReleaseRead(&cm_volumeLock);
430 } else { /* VL Server query */
431 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY (VL Server).");
437 lock_ObtainWrite(&cm_serverLock);
438 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
439 if (tsrp->status == srv_deleted)
441 if (tsrp->status == srv_busy) {
442 tsrp->status = srv_not_busy;
445 lock_ReleaseWrite(&cm_serverLock);
452 /* special codes: VBUSY and VRESTARTING */
453 else if (errorCode == VBUSY || errorCode == VRESTARTING) {
454 if (!serversp && fidp) {
455 code = cm_GetServerList(fidp, userp, reqp, &serverspp);
457 serversp = *serverspp;
462 switch ( errorCode ) {
464 msgID = MSG_SERVER_REPORTS_VBUSY;
465 format = "Server %s reported busy when accessing volume %d in cell %s.";
468 msgID = MSG_SERVER_REPORTS_VRESTARTING;
469 format = "Server %s reported restarting when accessing volume %d in cell %s.";
473 if (serverp && fidp) {
474 /* Log server being offline for this volume */
475 sprintf(addr, "%d.%d.%d.%d",
476 ((serverp->addr.sin_addr.s_addr & 0xff)),
477 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
478 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
479 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
481 osi_Log3(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
482 LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume, cellp->name);
485 lock_ObtainWrite(&cm_serverLock);
486 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
487 if (tsrp->status == srv_deleted)
489 if (tsrp->server == serverp && tsrp->status == srv_not_busy) {
490 tsrp->status = srv_busy;
491 if (fidp) { /* File Server query */
492 lock_ReleaseWrite(&cm_serverLock);
493 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
494 CM_GETVOL_FLAG_NO_LRU_UPDATE,
497 statep = cm_VolumeStateByID(volp, fidp->volume);
498 lock_ObtainWrite(&cm_serverLock);
503 lock_ReleaseWrite(&cm_serverLock);
506 cm_UpdateVolumeStatus(volp, statep->ID);
507 lock_ObtainRead(&cm_volumeLock);
509 lock_ReleaseRead(&cm_volumeLock);
514 cm_FreeServerList(serverspp, 0);
521 /* special codes: missing volumes */
522 else if (errorCode == VNOVOL || errorCode == VMOVED || errorCode == VOFFLINE ||
523 errorCode == VSALVAGE || errorCode == VNOSERVICE || errorCode == VIO)
525 /* In case of timeout */
526 reqp->volumeError = errorCode;
528 switch ( errorCode ) {
530 msgID = MSG_SERVER_REPORTS_VNOVOL;
531 format = "Server %s reported volume %d in cell %s as not attached (may have been moved or deleted).";
534 msgID = MSG_SERVER_REPORTS_VMOVED;
535 format = "Server %s reported volume %d in cell %s as moved.";
538 msgID = MSG_SERVER_REPORTS_VOFFLINE;
539 format = "Server %s reported volume %d in cell %s as offline.";
542 msgID = MSG_SERVER_REPORTS_VSALVAGE;
543 format = "Server %s reported volume %d in cell %s as needs salvage.";
546 msgID = MSG_SERVER_REPORTS_VNOSERVICE;
547 format = "Server %s reported volume %d in cell %s as not in service.";
550 msgID = MSG_SERVER_REPORTS_VIO;
551 format = "Server %s reported volume %d in cell %s as temporarily unaccessible.";
555 if (fidp) { /* File Server query */
557 /* Log server being unavailable for this volume */
558 sprintf(addr, "%d.%d.%d.%d",
559 ((serverp->addr.sin_addr.s_addr & 0xff)),
560 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
561 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
562 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
564 osi_Log3(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
565 LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume, cellp->name);
568 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
569 CM_GETVOL_FLAG_NO_LRU_UPDATE,
572 statep = cm_VolumeStateByID(volp, fidp->volume);
574 if ((errorCode == VMOVED || errorCode == VNOVOL || errorCode == VOFFLINE) &&
575 !(reqp->flags & CM_REQ_VOLUME_UPDATED))
577 code = cm_ForceUpdateVolume(fidp, userp, reqp);
579 location_updated = 1;
581 /* Even if the update fails, there might still be another replica */
583 reqp->flags |= CM_REQ_VOLUME_UPDATED;
584 osi_Log3(afsd_logp, "cm_Analyze called cm_ForceUpdateVolume cell %u vol %u code 0x%x",
585 fidp->cell, fidp->volume, code);
589 cm_UpdateVolumeStatus(volp, statep->ID);
590 osi_Log3(afsd_logp, "cm_Analyze NewVolState cell %u vol %u state %u",
591 fidp->cell, fidp->volume, statep->state);
595 lock_ObtainRead(&cm_volumeLock);
597 lock_ReleaseRead(&cm_volumeLock);
602 * Mark server offline for this volume or delete the volume
603 * from the server list if it was moved or is not present.
605 if (!serversp || location_updated) {
606 code = cm_GetServerList(fidp, userp, reqp, &serverspp);
608 serversp = *serverspp;
614 lock_ObtainWrite(&cm_serverLock);
615 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
616 if (tsrp->status == srv_deleted)
619 sprintf(addr, "%d.%d.%d.%d",
620 ((tsrp->server->addr.sin_addr.s_addr & 0xff)),
621 ((tsrp->server->addr.sin_addr.s_addr & 0xff00)>> 8),
622 ((tsrp->server->addr.sin_addr.s_addr & 0xff0000)>> 16),
623 ((tsrp->server->addr.sin_addr.s_addr & 0xff000000)>> 24));
625 if (cm_ServerEqual(tsrp->server, serverp)) {
627 if (errorCode == VMOVED || errorCode == VNOVOL) {
628 osi_Log2(afsd_logp, "volume %d not present on server %s",
629 fidp->volume, osi_LogSaveString(afsd_logp,addr));
630 tsrp->status = srv_deleted;
632 cm_RemoveVolumeFromServer(serverp, fidp->volume);
634 osi_Log2(afsd_logp, "volume %d instance on server %s marked offline",
635 fidp->volume, osi_LogSaveString(afsd_logp,addr));
636 tsrp->status = srv_offline;
640 osi_Log3(afsd_logp, "volume %d exists on server %s with status %u",
641 fidp->volume, osi_LogSaveString(afsd_logp,addr), tsrp->status);
644 lock_ReleaseWrite(&cm_serverLock);
646 /* Free the server list before cm_ForceUpdateVolume is called */
648 cm_FreeServerList(serverspp, 0);
655 } else if ( errorCode == VNOVNODE ) {
658 osi_Log4(afsd_logp, "cm_Analyze passed VNOVNODE cell %u vol %u vn %u uniq %u.",
659 fidp->cell, fidp->volume, fidp->vnode, fidp->unique);
661 scp = cm_FindSCache(fidp);
663 cm_scache_t *pscp = NULL;
665 if (scp->fileType != CM_SCACHETYPE_DIRECTORY)
666 pscp = cm_FindSCacheParent(scp);
668 lock_ObtainWrite(&scp->rw);
669 lock_ObtainWrite(&cm_scacheLock);
670 cm_RemoveSCacheFromHashTable(scp);
671 lock_ReleaseWrite(&cm_scacheLock);
672 cm_LockMarkSCacheLost(scp);
673 scp->flags |= CM_SCACHEFLAG_DELETED;
674 lock_ReleaseWrite(&scp->rw);
675 cm_ReleaseSCache(scp);
678 if (cm_HaveCallback(pscp)) {
679 lock_ObtainWrite(&pscp->rw);
680 cm_DiscardSCache(pscp);
681 lock_ReleaseWrite(&pscp->rw);
683 cm_ReleaseSCache(pscp);
687 osi_Log0(afsd_logp, "cm_Analyze passed VNOVNODE unknown fid.");
692 else if (errorCode == RX_CALL_TIMEOUT) {
693 /* RPC took longer than hardDeadTime or the server
694 * reported idle for longer than idleDeadTime
695 * don't mark server as down but don't retry
696 * this is to prevent the SMB session from timing out
697 * In addition, we log an event to the event log
701 sprintf(addr, "%d.%d.%d.%d",
702 ((serverp->addr.sin_addr.s_addr & 0xff)),
703 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
704 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
705 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
707 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_HARD_DEAD_TIME_EXCEEDED, addr);
708 osi_Log1(afsd_logp, "cm_Analyze: hardDeadTime or idleDeadtime exceeded addr[%s]",
709 osi_LogSaveString(afsd_logp,addr));
710 reqp->tokenIdleErrorServp = serverp;
715 if (!fidp) { /* vldb */
718 cm_volume_t *volp = cm_GetVolumeByFID(fidp);
720 if (fidp->volume == cm_GetROVolumeID(volp))
727 else if (errorCode == RX_MSGSIZE) {
729 * RPC failed because a transmitted rx packet
730 * may have grown larger than the path mtu.
731 * Force a retry and the Rx library will try
732 * with a smaller mtu size.
736 sprintf(addr, "%d.%d.%d.%d",
737 ((serverp->addr.sin_addr.s_addr & 0xff)),
738 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
739 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
740 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
742 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_MSGSIZE_EXCEEDED, addr);
743 osi_Log1(afsd_logp, "cm_Analyze: Path MTU may have been exceeded addr[%s]",
744 osi_LogSaveString(afsd_logp,addr));
749 else if (errorCode >= -64 && errorCode < 0) {
750 /* mark server as down */
752 sprintf(addr, "%d.%d.%d.%d",
753 ((serverp->addr.sin_addr.s_addr & 0xff)),
754 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
755 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
756 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
758 if (errorCode == RX_CALL_DEAD)
759 osi_Log2(afsd_logp, "cm_Analyze: Rx Call Dead addr[%s] forcedNew[%s]",
760 osi_LogSaveString(afsd_logp,addr),
761 (reqp->flags & CM_REQ_NEW_CONN_FORCED ? "yes" : "no"));
763 osi_Log3(afsd_logp, "cm_Analyze: Rx Misc Error[%d] addr[%s] forcedNew[%s]",
765 osi_LogSaveString(afsd_logp,addr),
766 (reqp->flags & CM_REQ_NEW_CONN_FORCED ? "yes" : "no"));
769 lock_ObtainMutex(&serverp->mx);
770 if (errorCode == RX_CALL_DEAD &&
771 (reqp->flags & CM_REQ_NEW_CONN_FORCED)) {
772 if (!(serverp->flags & CM_SERVERFLAG_DOWN)) {
773 serverp->flags |= CM_SERVERFLAG_DOWN;
774 serverp->downTime = time(NULL);
777 if (reqp->flags & CM_REQ_NEW_CONN_FORCED) {
778 reqp->tokenIdleErrorServp = serverp;
779 reqp->tokenError = errorCode;
781 reqp->flags |= CM_REQ_NEW_CONN_FORCED;
785 lock_ReleaseMutex(&serverp->mx);
786 cm_ForceNewConnections(serverp);
791 else if (errorCode == RXKADEXPIRED) {
792 osi_Log1(afsd_logp, "cm_Analyze: rxkad error code 0x%x (RXKADEXPIRED)",
795 lock_ObtainMutex(&userp->mx);
796 ucellp = cm_GetUCell(userp, serverp->cellp);
797 if (ucellp->ticketp) {
798 free(ucellp->ticketp);
799 ucellp->ticketp = NULL;
801 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
803 lock_ReleaseMutex(&userp->mx);
807 } else if (errorCode >= ERROR_TABLE_BASE_RXK && errorCode < ERROR_TABLE_BASE_RXK + 256) {
808 char * s = "unknown error";
809 switch ( errorCode ) {
810 case RXKADINCONSISTENCY: s = "RXKADINCONSISTENCY"; break;
811 case RXKADPACKETSHORT : s = "RXKADPACKETSHORT"; break;
812 case RXKADLEVELFAIL : s = "RXKADLEVELFAIL"; break;
813 case RXKADTICKETLEN : s = "RXKADTICKETLEN"; break;
814 case RXKADOUTOFSEQUENCE: s = "RXKADOUTOFSEQUENCE"; break;
815 case RXKADNOAUTH : s = "RXKADNOAUTH"; break;
816 case RXKADBADKEY : s = "RXKADBADKEY"; break;
817 case RXKADBADTICKET : s = "RXKADBADTICKET"; break;
818 case RXKADUNKNOWNKEY : s = "RXKADUNKNOWNKEY"; break;
819 case RXKADEXPIRED : s = "RXKADEXPIRED"; break;
820 case RXKADSEALEDINCON : s = "RXKADSEALEDINCON"; break;
821 case RXKADDATALEN : s = "RXKADDATALEN"; break;
822 case RXKADILLEGALLEVEL : s = "RXKADILLEGALLEVEL"; break;
824 osi_Log2(afsd_logp, "cm_Analyze: rxkad error code 0x%x (%s)",
828 reqp->tokenIdleErrorServp = serverp;
829 reqp->tokenError = errorCode;
832 } else if (errorCode >= ERROR_TABLE_BASE_U && errorCode < ERROR_TABLE_BASE_U + 256) {
834 * We received a ubik error. its possible that the server we are
835 * communicating with has a corrupted database or is partitioned
836 * from the rest of the servers and another server might be able
837 * to answer our query. Therefore, we will retry the request
838 * and force the use of another server.
841 reqp->tokenIdleErrorServp = serverp;
842 reqp->tokenError = errorCode;
845 } else if (errorCode == VICECONNBAD || errorCode == VICETOKENDEAD) {
846 cm_ForceNewConnections(serverp);
851 char * s = "unknown error";
852 switch ( errorCode ) {
853 case VSALVAGE : s = "VSALVAGE"; break;
854 case VNOVNODE : s = "VNOVNODE"; break;
855 case VNOVOL : s = "VNOVOL"; break;
856 case VVOLEXISTS : s = "VVOLEXISTS"; break;
857 case VNOSERVICE : s = "VNOSERVICE"; break;
858 case VOFFLINE : s = "VOFFLINE"; break;
859 case VONLINE : s = "VONLINE"; break;
860 case VDISKFULL : s = "VDISKFULL"; break;
861 case VOVERQUOTA : s = "VOVERQUOTA"; break;
862 case VBUSY : s = "VBUSY"; break;
863 case VMOVED : s = "VMOVED"; break;
864 case VIO : s = "VIO"; break;
865 case VRESTRICTED : s = "VRESTRICTED"; break;
866 case VRESTARTING : s = "VRESTARTING"; break;
867 case VREADONLY : s = "VREADONLY"; break;
868 case EAGAIN : s = "EAGAIN"; break;
869 case UAEAGAIN : s = "UAEAGAIN"; break;
870 case EINVAL : s = "EINVAL"; break;
871 case UAEINVAL : s = "UAEINVAL"; break;
872 case EACCES : s = "EACCES"; break;
873 case UAEACCES : s = "UAEACCES"; break;
874 case ENOENT : s = "ENOENT"; break;
875 case UAENOENT : s = "UAENOENT"; break;
876 case EEXIST : s = "EEXIST"; break;
877 case UAEEXIST : s = "UAEEXIST"; break;
878 case VICECONNBAD : s = "VICECONNBAD"; break;
879 case VICETOKENDEAD : s = "VICETOKENDEAD"; break;
880 case WSAEWOULDBLOCK : s = "WSAEWOULDBLOCK"; break;
881 case UAEWOULDBLOCK : s = "UAEWOULDBLOCK"; break;
882 case VL_IDEXIST : s = "VL_IDEXIST"; break;
883 case VL_IO : s = "VL_IO"; break;
884 case VL_NAMEEXIST : s = "VL_NAMEEXIST"; break;
885 case VL_CREATEFAIL : s = "VL_CREATEFAIL"; break;
886 case VL_NOENT : s = "VL_NOENT"; break;
887 case VL_EMPTY : s = "VL_EMPTY"; break;
888 case VL_ENTDELETED : s = "VL_ENTDELETED"; break;
889 case VL_BADNAME : s = "VL_BADNAME"; break;
890 case VL_BADINDEX : s = "VL_BADINDEX"; break;
891 case VL_BADVOLTYPE : s = "VL_BADVOLTYPE"; break;
892 case VL_BADSERVER : s = "VL_BADSERVER"; break;
893 case VL_BADPARTITION : s = "VL_BADPARTITION"; break;
894 case VL_REPSFULL : s = "VL_REPSFULL"; break;
895 case VL_NOREPSERVER : s = "VL_NOREPSERVER"; break;
896 case VL_DUPREPSERVER : s = "VL_DUPREPSERVER"; break;
897 case VL_RWNOTFOUND : s = "VL_RWNOTFOUND"; break;
898 case VL_BADREFCOUNT : s = "VL_BADREFCOUNT"; break;
899 case VL_SIZEEXCEEDED : s = "VL_SIZEEXCEEDED"; break;
900 case VL_BADENTRY : s = "VL_BADENTRY"; break;
901 case VL_BADVOLIDBUMP : s = "VL_BADVOLIDBUMP"; break;
902 case VL_IDALREADYHASHED: s = "VL_IDALREADYHASHED"; break;
903 case VL_ENTRYLOCKED : s = "VL_ENTRYLOCKED"; break;
904 case VL_BADVOLOPER : s = "VL_BADVOLOPER"; break;
905 case VL_BADRELLOCKTYPE : s = "VL_BADRELLOCKTYPE"; break;
906 case VL_RERELEASE : s = "VL_RERELEASE"; break;
907 case VL_BADSERVERFLAG : s = "VL_BADSERVERFLAG"; break;
908 case VL_PERM : s = "VL_PERM"; break;
909 case VL_NOMEM : s = "VL_NOMEM"; break;
910 case VL_BADVERSION : s = "VL_BADVERSION"; break;
911 case VL_INDEXERANGE : s = "VL_INDEXERANGE"; break;
912 case VL_MULTIPADDR : s = "VL_MULTIPADDR"; break;
913 case VL_BADMASK : s = "VL_BADMASK"; break;
914 case CM_ERROR_NOSUCHCELL : s = "CM_ERROR_NOSUCHCELL"; break;
915 case CM_ERROR_NOSUCHVOLUME : s = "CM_ERROR_NOSUCHVOLUME"; break;
916 case CM_ERROR_TIMEDOUT : s = "CM_ERROR_TIMEDOUT"; break;
917 case CM_ERROR_RETRY : s = "CM_ERROR_RETRY"; break;
918 case CM_ERROR_NOACCESS : s = "CM_ERROR_NOACCESS"; break;
919 case CM_ERROR_NOSUCHFILE : s = "CM_ERROR_NOSUCHFILE"; break;
920 case CM_ERROR_STOPNOW : s = "CM_ERROR_STOPNOW"; break;
921 case CM_ERROR_TOOBIG : s = "CM_ERROR_TOOBIG"; break;
922 case CM_ERROR_INVAL : s = "CM_ERROR_INVAL"; break;
923 case CM_ERROR_BADFD : s = "CM_ERROR_BADFD"; break;
924 case CM_ERROR_BADFDOP : s = "CM_ERROR_BADFDOP"; break;
925 case CM_ERROR_EXISTS : s = "CM_ERROR_EXISTS"; break;
926 case CM_ERROR_CROSSDEVLINK : s = "CM_ERROR_CROSSDEVLINK"; break;
927 case CM_ERROR_BADOP : s = "CM_ERROR_BADOP"; break;
928 case CM_ERROR_BADPASSWORD : s = "CM_ERROR_BADPASSWORD"; break;
929 case CM_ERROR_NOTDIR : s = "CM_ERROR_NOTDIR"; break;
930 case CM_ERROR_ISDIR : s = "CM_ERROR_ISDIR"; break;
931 case CM_ERROR_READONLY : s = "CM_ERROR_READONLY"; break;
932 case CM_ERROR_WOULDBLOCK : s = "CM_ERROR_WOULDBLOCK"; break;
933 case CM_ERROR_QUOTA : s = "CM_ERROR_QUOTA"; break;
934 case CM_ERROR_SPACE : s = "CM_ERROR_SPACE"; break;
935 case CM_ERROR_BADSHARENAME : s = "CM_ERROR_BADSHARENAME"; break;
936 case CM_ERROR_BADTID : s = "CM_ERROR_BADTID"; break;
937 case CM_ERROR_UNKNOWN : s = "CM_ERROR_UNKNOWN"; break;
938 case CM_ERROR_NOMORETOKENS : s = "CM_ERROR_NOMORETOKENS"; break;
939 case CM_ERROR_NOTEMPTY : s = "CM_ERROR_NOTEMPTY"; break;
940 case CM_ERROR_USESTD : s = "CM_ERROR_USESTD"; break;
941 case CM_ERROR_REMOTECONN : s = "CM_ERROR_REMOTECONN"; break;
942 case CM_ERROR_ATSYS : s = "CM_ERROR_ATSYS"; break;
943 case CM_ERROR_NOSUCHPATH : s = "CM_ERROR_NOSUCHPATH"; break;
944 case CM_ERROR_CLOCKSKEW : s = "CM_ERROR_CLOCKSKEW"; break;
945 case CM_ERROR_BADSMB : s = "CM_ERROR_BADSMB"; break;
946 case CM_ERROR_ALLBUSY : s = "CM_ERROR_ALLBUSY"; break;
947 case CM_ERROR_NOFILES : s = "CM_ERROR_NOFILES"; break;
948 case CM_ERROR_PARTIALWRITE : s = "CM_ERROR_PARTIALWRITE"; break;
949 case CM_ERROR_NOIPC : s = "CM_ERROR_NOIPC"; break;
950 case CM_ERROR_BADNTFILENAME : s = "CM_ERROR_BADNTFILENAME"; break;
951 case CM_ERROR_BUFFERTOOSMALL : s = "CM_ERROR_BUFFERTOOSMALL"; break;
952 case CM_ERROR_RENAME_IDENTICAL : s = "CM_ERROR_RENAME_IDENTICAL"; break;
953 case CM_ERROR_ALLOFFLINE : s = "CM_ERROR_ALLOFFLINE"; break;
954 case CM_ERROR_AMBIGUOUS_FILENAME: s = "CM_ERROR_AMBIGUOUS_FILENAME"; break;
955 case CM_ERROR_BADLOGONTYPE : s = "CM_ERROR_BADLOGONTYPE"; break;
956 case CM_ERROR_GSSCONTINUE : s = "CM_ERROR_GSSCONTINUE"; break;
957 case CM_ERROR_TIDIPC : s = "CM_ERROR_TIDIPC"; break;
958 case CM_ERROR_TOO_MANY_SYMLINKS : s = "CM_ERROR_TOO_MANY_SYMLINKS"; break;
959 case CM_ERROR_PATH_NOT_COVERED : s = "CM_ERROR_PATH_NOT_COVERED"; break;
960 case CM_ERROR_LOCK_CONFLICT : s = "CM_ERROR_LOCK_CONFLICT"; break;
961 case CM_ERROR_SHARING_VIOLATION : s = "CM_ERROR_SHARING_VIOLATION"; break;
962 case CM_ERROR_ALLDOWN : s = "CM_ERROR_ALLDOWN"; break;
963 case CM_ERROR_TOOFEWBUFS : s = "CM_ERROR_TOOFEWBUFS"; break;
964 case CM_ERROR_TOOMANYBUFS : s = "CM_ERROR_TOOMANYBUFS"; break;
966 osi_Log2(afsd_logp, "cm_Analyze: ignoring error code 0x%x (%s)",
972 /* If not allowed to retry, don't */
973 if (!forcing_new && (reqp->flags & CM_REQ_NORETRY) && (errorCode != RX_MSGSIZE))
975 else if (retry && dead_session)
978 /* drop this on the way out */
983 * clear the volume updated flag if we succeed.
984 * this way the flag will not prevent a subsequent volume
985 * from being updated if necessary.
989 reqp->flags &= ~CM_REQ_VOLUME_UPDATED;
992 /* retry until we fail to find a connection */
996 long cm_ConnByMServers(cm_serverRef_t *serversp, cm_user_t *usersp,
997 cm_req_t *reqp, cm_conn_t **connpp)
1000 cm_serverRef_t *tsrp;
1002 long firstError = 0;
1003 int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
1004 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1005 long timeUsed, timeLeft, hardTimeLeft;
1009 if (serversp == NULL) {
1010 osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", CM_ERROR_ALLDOWN);
1011 return CM_ERROR_ALLDOWN;
1014 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1015 timeUsed = (GetTickCount() - reqp->startTime) / 1000;
1017 /* leave 5 seconds margin of safety */
1018 timeLeft = ConnDeadtimeout - timeUsed - 5;
1019 hardTimeLeft = HardDeadtimeout - timeUsed - 5;
1022 lock_ObtainRead(&cm_serverLock);
1023 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
1024 if (tsrp->status == srv_deleted)
1028 if (reqp->tokenIdleErrorServp) {
1030 * search the list until we find the server
1031 * that failed last time. When we find it
1032 * clear the error, skip it and try the one
1035 if (tsp == reqp->tokenIdleErrorServp)
1036 reqp->tokenIdleErrorServp = NULL;
1040 cm_GetServerNoLock(tsp);
1041 lock_ReleaseRead(&cm_serverLock);
1042 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1044 if (tsrp->status == srv_busy) {
1047 } else if (tsrp->status == srv_offline) {
1053 code = cm_ConnByServer(tsp, usersp, connpp);
1054 if (code == 0) { /* cm_CBS only returns 0 */
1056 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1057 /* Set RPC timeout */
1058 if (timeLeft > ConnDeadtimeout)
1059 timeLeft = ConnDeadtimeout;
1061 if (hardTimeLeft > HardDeadtimeout)
1062 hardTimeLeft = HardDeadtimeout;
1064 lock_ObtainMutex(&(*connpp)->mx);
1065 rx_SetConnDeadTime((*connpp)->rxconnp, timeLeft);
1066 rx_SetConnHardDeadTime((*connpp)->rxconnp, (u_short) hardTimeLeft);
1067 lock_ReleaseMutex(&(*connpp)->mx);
1072 /* therefore, this code is never executed */
1073 if (firstError == 0)
1077 lock_ObtainRead(&cm_serverLock);
1078 cm_PutServerNoLock(tsp);
1081 lock_ReleaseRead(&cm_serverLock);
1083 if (firstError == 0) {
1085 firstError = (reqp->tokenError ? reqp->tokenError :
1086 (reqp->idleError ? RX_CALL_TIMEOUT : CM_ERROR_ALLDOWN));
1088 * if we experienced either a token error or and idle dead time error
1089 * and now all of the servers are down, we have either tried them
1090 * all or lost connectivity. Clear the error we are returning so
1091 * we will not return it indefinitely if the request is retried.
1093 reqp->idleError = reqp->tokenError = 0;
1094 } else if (allBusy) {
1095 firstError = CM_ERROR_ALLBUSY;
1096 } else if (allOffline || (someBusy && someOffline)) {
1097 firstError = CM_ERROR_ALLOFFLINE;
1099 osi_Log0(afsd_logp, "cm_ConnByMServers returning impossible error TIMEDOUT");
1100 firstError = CM_ERROR_TIMEDOUT;
1104 osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", firstError);
1108 /* called with a held server to GC all bad connections hanging off of the server */
1109 void cm_GCConnections(cm_server_t *serverp)
1115 lock_ObtainWrite(&cm_connLock);
1116 lcpp = &serverp->connsp;
1117 for (tcp = *lcpp; tcp; tcp = *lcpp) {
1119 if (userp && tcp->refCount == 0 && (userp->vcRefs == 0)) {
1120 /* do the deletion of this guy */
1121 cm_PutServer(tcp->serverp);
1122 cm_ReleaseUser(userp);
1124 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, 0);
1125 rx_DestroyConnection(tcp->rxconnp);
1126 lock_FinalizeMutex(&tcp->mx);
1130 /* just advance to the next */
1134 lock_ReleaseWrite(&cm_connLock);
1137 static void cm_NewRXConnection(cm_conn_t *tcp, cm_ucell_t *ucellp,
1138 cm_server_t *serverp)
1140 unsigned short port;
1143 struct rx_securityClass *secObjp;
1145 port = serverp->addr.sin_port;
1146 switch (serverp->type) {
1147 case CM_SERVER_VLDB:
1152 case CM_SERVER_FILE:
1158 osi_panic("unknown server type", __FILE__, __LINE__);
1161 if (ucellp->flags & CM_UCELLFLAG_RXKAD) {
1165 tcp->cryptlevel = rxkad_clear;
1168 tcp->cryptlevel = rxkad_auth;
1171 tcp->cryptlevel = rxkad_crypt;
1173 secObjp = rxkad_NewClientSecurityObject(tcp->cryptlevel,
1174 &ucellp->sessionKey, ucellp->kvno,
1175 ucellp->ticketLen, ucellp->ticketp);
1179 tcp->cryptlevel = rxkad_clear;
1180 secObjp = rxnull_NewClientSecurityObject();
1182 osi_assertx(secObjp != NULL, "null rx_securityClass");
1183 tcp->rxconnp = rx_NewConnection(serverp->addr.sin_addr.s_addr,
1188 rx_SetConnDeadTime(tcp->rxconnp, ConnDeadtimeout);
1189 rx_SetConnHardDeadTime(tcp->rxconnp, HardDeadtimeout);
1190 rx_SetConnIdleDeadTime(tcp->rxconnp, IdleDeadtimeout);
1193 * Register the error to be returned on an idle dead timeout
1195 rx_SetServerConnIdleDeadErr(tcp->rxconnp, RX_CALL_DEAD);
1198 * Let the Rx library know that we can auto-retry if an
1199 * RX_MSGSIZE error is returned.
1201 if (rx_pmtu_discovery)
1202 rx_SetMsgsizeRetryErr(tcp->rxconnp, RX_MSGSIZE);
1205 * Attempt to limit NAT pings to the anonymous file server connections.
1206 * Only file servers implement client callbacks and we only need one ping
1207 * to be sent to each server.
1209 if (NatPingInterval && serverp->type == CM_SERVER_FILE && secIndex == 0)
1210 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, NatPingInterval);
1212 tcp->ucgen = ucellp->gen;
1214 rxs_Release(secObjp); /* Decrement the initial refCount */
1217 long cm_ConnByServer(cm_server_t *serverp, cm_user_t *userp, cm_conn_t **connpp)
1224 if (cm_anonvldb && serverp->type == CM_SERVER_VLDB)
1225 userp = cm_rootUserp;
1227 lock_ObtainMutex(&userp->mx);
1228 lock_ObtainRead(&cm_connLock);
1229 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1230 if (tcp->userp == userp)
1234 /* find ucell structure */
1235 ucellp = cm_GetUCell(userp, serverp->cellp);
1237 lock_ConvertRToW(&cm_connLock);
1238 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1239 if (tcp->userp == userp)
1243 lock_ReleaseWrite(&cm_connLock);
1246 cm_GetServer(serverp);
1247 tcp = malloc(sizeof(*tcp));
1248 memset(tcp, 0, sizeof(*tcp));
1249 tcp->nextp = serverp->connsp;
1250 serverp->connsp = tcp;
1253 lock_InitializeMutex(&tcp->mx, "cm_conn_t mutex", LOCK_HIERARCHY_CONN);
1254 lock_ObtainMutex(&tcp->mx);
1255 tcp->serverp = serverp;
1256 tcp->cryptlevel = rxkad_clear;
1257 cm_NewRXConnection(tcp, ucellp, serverp);
1259 lock_ReleaseMutex(&tcp->mx);
1260 lock_ReleaseWrite(&cm_connLock);
1262 lock_ReleaseRead(&cm_connLock);
1264 InterlockedIncrement(&tcp->refCount);
1266 lock_ObtainMutex(&tcp->mx);
1267 if ((tcp->flags & CM_CONN_FLAG_FORCE_NEW) ||
1268 (tcp->ucgen < ucellp->gen) ||
1269 (tcp->cryptlevel != (ucellp->flags & CM_UCELLFLAG_RXKAD ? (cryptall == 1 ? rxkad_crypt : (cryptall == 2 ? rxkad_auth : rxkad_clear)) : rxkad_clear)))
1271 if (tcp->ucgen < ucellp->gen)
1272 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to token update");
1274 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to crypt change");
1275 tcp->flags &= ~CM_CONN_FLAG_FORCE_NEW;
1276 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, 0);
1277 rx_DestroyConnection(tcp->rxconnp);
1278 cm_NewRXConnection(tcp, ucellp, serverp);
1280 lock_ReleaseMutex(&tcp->mx);
1282 lock_ReleaseMutex(&userp->mx);
1284 /* return this pointer to our caller */
1285 osi_Log1(afsd_logp, "cm_ConnByServer returning conn 0x%p", tcp);
1291 long cm_ServerAvailable(struct cm_fid *fidp, struct cm_user *userp)
1295 cm_serverRef_t **serverspp;
1296 cm_serverRef_t *tsrp;
1298 int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
1302 code = cm_GetServerList(fidp, userp, &req, &serverspp);
1306 lock_ObtainRead(&cm_serverLock);
1307 for (tsrp = *serverspp; tsrp; tsrp=tsrp->next) {
1308 if (tsrp->status == srv_deleted)
1311 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1313 if (tsrp->status == srv_busy) {
1316 } else if (tsrp->status == srv_offline) {
1325 lock_ReleaseRead(&cm_serverLock);
1326 cm_FreeServerList(serverspp, 0);
1332 else if (allOffline || (someBusy && someOffline))
1339 * The returned cm_conn_t ** object is released in the subsequent call
1342 long cm_ConnFromFID(struct cm_fid *fidp, struct cm_user *userp, cm_req_t *reqp,
1346 cm_serverRef_t **serverspp;
1350 code = cm_GetServerList(fidp, userp, reqp, &serverspp);
1355 code = cm_ConnByMServers(*serverspp, userp, reqp, connpp);
1356 cm_FreeServerList(serverspp, 0);
1361 long cm_ConnFromVolume(struct cm_volume *volp, unsigned long volid, struct cm_user *userp, cm_req_t *reqp,
1365 cm_serverRef_t **serverspp;
1369 serverspp = cm_GetVolServers(volp, volid, userp, reqp);
1371 code = cm_ConnByMServers(*serverspp, userp, reqp, connpp);
1372 cm_FreeServerList(serverspp, 0);
1377 extern struct rx_connection *
1378 cm_GetRxConn(cm_conn_t *connp)
1380 struct rx_connection * rxconnp;
1381 lock_ObtainMutex(&connp->mx);
1382 rxconnp = connp->rxconnp;
1383 rx_GetConnection(rxconnp);
1384 lock_ReleaseMutex(&connp->mx);
1388 void cm_ForceNewConnections(cm_server_t *serverp)
1392 lock_ObtainWrite(&cm_connLock);
1393 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1394 lock_ObtainMutex(&tcp->mx);
1395 tcp->flags |= CM_CONN_FLAG_FORCE_NEW;
1396 lock_ReleaseMutex(&tcp->mx);
1398 lock_ReleaseWrite(&cm_connLock);