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.
151 afsi_log("lanmanworkstation : SessTimeout %u", RDRtimeout);
152 if (ConnDeadtimeout == 0) {
153 ConnDeadtimeout = (unsigned short) ((RDRtimeout / 2) < 50 ? (RDRtimeout / 2) : 50);
154 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
156 if (HardDeadtimeout == 0) {
157 HardDeadtimeout = (unsigned short) (RDRtimeout > 125 ? 120 : (RDRtimeout - 5));
158 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
160 if (IdleDeadtimeout == 0) {
161 IdleDeadtimeout = (unsigned short) ConnDeadtimeout;
162 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
165 if (ConnDeadtimeout == 0) {
166 ConnDeadtimeout = CM_CONN_IFS_CONNDEADTIME;
167 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
169 if (HardDeadtimeout == 0) {
170 HardDeadtimeout = CM_CONN_IFS_HARDDEADTIME;
171 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
173 if (IdleDeadtimeout == 0) {
174 IdleDeadtimeout = CM_CONN_IFS_IDLEDEADTIME;
175 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
182 void cm_InitReq(cm_req_t *reqp)
184 memset(reqp, 0, sizeof(cm_req_t));
185 reqp->startTime = GetTickCount();
188 static long cm_GetServerList(struct cm_fid *fidp, struct cm_user *userp,
189 struct cm_req *reqp, cm_serverRef_t ***serversppp)
192 cm_volume_t *volp = NULL;
193 cm_cell_t *cellp = NULL;
197 return CM_ERROR_INVAL;
200 cellp = cm_FindCellByID(fidp->cell, 0);
202 return CM_ERROR_NOSUCHCELL;
204 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp, CM_GETVOL_FLAG_CREATE, &volp);
208 *serversppp = cm_GetVolServers(volp, fidp->volume, userp, reqp);
210 lock_ObtainRead(&cm_volumeLock);
212 lock_ReleaseRead(&cm_volumeLock);
213 return (*serversppp ? 0 : CM_ERROR_NOSUCHVOLUME);
217 * Analyze the error return from an RPC. Determine whether or not to retry,
218 * and if we're going to retry, determine whether failover is appropriate,
219 * and whether timed backoff is appropriate.
221 * If the error code is from cm_ConnFromFID() or friends, it will be a CM_ERROR code.
222 * Otherwise it will be an RPC code. This may be a UNIX code (e.g. EDQUOT), or
223 * it may be an RX code, or it may be a special code (e.g. VNOVOL), or it may
224 * be a security code (e.g. RXKADEXPIRED).
226 * If the error code is from cm_ConnFromFID() or friends, connp will be NULL.
228 * For VLDB calls, fidp will be NULL.
230 * volSyncp and/or cbrp may also be NULL.
233 cm_Analyze(cm_conn_t *connp, cm_user_t *userp, cm_req_t *reqp,
235 AFSVolSync *volSyncp,
236 cm_serverRef_t * serversp,
237 cm_callbackRequest_t *cbrp, long errorCode)
239 cm_server_t *serverp = NULL;
240 cm_serverRef_t **serverspp = NULL;
241 cm_serverRef_t *tsrp;
242 cm_cell_t *cellp = NULL;
244 cm_volume_t * volp = NULL;
245 cm_vol_state_t *statep = NULL;
247 int free_svr_list = 0;
249 long timeUsed, timeLeft;
251 char addr[16]="unknown";
253 int location_updated = 0;
257 osi_Log2(afsd_logp, "cm_Analyze connp 0x%p, code 0x%x",
260 /* no locking required, since connp->serverp never changes after
262 dead_session = (userp->cellInfop == NULL);
264 serverp = connp->serverp;
266 /* Update callback pointer */
267 if (cbrp && serverp && errorCode == 0) {
269 if ( cbrp->serverp != serverp ) {
270 lock_ObtainWrite(&cm_serverLock);
271 cm_PutServerNoLock(cbrp->serverp);
272 cm_GetServerNoLock(serverp);
273 lock_ReleaseWrite(&cm_serverLock);
276 cm_GetServer(serverp);
278 lock_ObtainWrite(&cm_callbackLock);
279 cbrp->serverp = serverp;
280 lock_ReleaseWrite(&cm_callbackLock);
283 /* if timeout - check that it did not exceed the HardDead timeout
286 /* timeleft - get it from reqp the same way as cm_ConnByMServers does */
287 timeUsed = (GetTickCount() - reqp->startTime) / 1000;
288 if ( reqp->flags & CM_REQ_SOURCE_SMB )
289 timeLeft = HardDeadtimeout - timeUsed;
291 timeLeft = 0x0FFFFFFF;
293 /* get a pointer to the cell */
295 if (cellp == NULL && serverp)
296 cellp = serverp->cellp;
297 if (cellp == NULL && serversp) {
298 struct cm_serverRef * refp;
299 for ( refp=serversp ; cellp == NULL && refp != NULL; refp=refp->next) {
300 if (refp->status == srv_deleted)
303 cellp = refp->server->cellp;
306 if (cellp == NULL && fidp) {
307 cellp = cm_FindCellByID(fidp->cell, 0);
311 if (errorCode == CM_ERROR_TIMEDOUT) {
312 if ( timeLeft > 5 ) {
314 cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, cellp);
319 else if (errorCode == UAEWOULDBLOCK || errorCode == EWOULDBLOCK ||
320 errorCode == UAEAGAIN || errorCode == EAGAIN) {
321 osi_Log0(afsd_logp, "cm_Analyze passed EWOULDBLOCK or EAGAIN.");
322 if ( timeLeft > 5 ) {
328 /* if there is nosuchvolume, then we have a situation in which a
329 * previously known volume no longer has a set of servers
330 * associated with it. Either the volume has moved or
331 * the volume has been deleted. Try to find a new server list
332 * until the timeout period expires.
334 else if (errorCode == CM_ERROR_NOSUCHVOLUME) {
335 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_NOSUCHVOLUME.");
337 * The VNOVOL or VL_NOENT error has already been translated
338 * to CM_ERROR_NOSUCHVOLUME. There is nothing for us to do.
342 else if (errorCode == CM_ERROR_ALLDOWN) {
343 /* Servers marked DOWN will be restored by the background daemon
344 * thread as they become available. The volume status is
345 * updated as the server state changes.
348 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_DOWN (FS cell %s vol 0x%x)",
349 cellp->name, fidp->volume);
350 msgID = MSG_ALL_SERVERS_DOWN;
351 format = "All servers are unreachable when accessing cell %s volume %d.";
352 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
354 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLDOWN (VL Server)");
358 else if (errorCode == CM_ERROR_ALLOFFLINE) {
359 /* Volume instances marked offline will be restored by the
360 * background daemon thread as they become available
363 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE (FS cell %s vol 0x%x)",
364 cellp->name, fidp->volume);
365 msgID = MSG_ALL_SERVERS_OFFLINE;
366 format = "All servers are offline when accessing cell %s volume %d.";
367 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
369 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
370 CM_GETVOL_FLAG_NO_LRU_UPDATE,
374 * Do not perform a cm_CheckOfflineVolume() if cm_Analyze()
375 * was called by cm_CheckOfflineVolumeState().
377 if (!(reqp->flags & CM_REQ_OFFLINE_VOL_CHK) && timeLeft > 7) {
380 /* cm_CheckOfflineVolume() resets the serverRef state */
381 if (cm_CheckOfflineVolume(volp, fidp->volume))
384 cm_UpdateVolumeStatus(volp, fidp->volume);
386 lock_ObtainRead(&cm_volumeLock);
388 lock_ReleaseRead(&cm_volumeLock);
392 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE (VL Server)");
395 else if (errorCode == CM_ERROR_ALLBUSY) {
396 /* Volumes that are busy cannot be determined to be non-busy
397 * without actually attempting to access them.
399 if (fidp) { /* File Server query */
400 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY (FS cell %s vol 0x%x)",
401 cellp->name, fidp->volume);
402 msgID = MSG_ALL_SERVERS_BUSY;
403 format = "All servers are busy when accessing cell %s volume %d.";
404 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
406 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
407 CM_GETVOL_FLAG_NO_LRU_UPDATE,
413 statep = cm_VolumeStateByID(volp, fidp->volume);
414 if (statep->state != vl_offline &&
415 statep->state != vl_busy &&
416 statep->state != vl_unknown) {
420 code = cm_GetServerList(fidp, userp, reqp, &serverspp);
422 serversp = *serverspp;
426 lock_ObtainWrite(&cm_serverLock);
427 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
428 if (tsrp->status == srv_deleted)
430 if (tsrp->status == srv_busy) {
431 tsrp->status = srv_not_busy;
434 lock_ReleaseWrite(&cm_serverLock);
436 cm_FreeServerList(serverspp, 0);
441 cm_UpdateVolumeStatus(volp, fidp->volume);
445 cm_UpdateVolumeStatus(volp, fidp->volume);
448 lock_ObtainRead(&cm_volumeLock);
450 lock_ReleaseRead(&cm_volumeLock);
453 } else { /* VL Server query */
454 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY (VL Server).");
460 lock_ObtainWrite(&cm_serverLock);
461 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
462 if (tsrp->status == srv_deleted)
464 if (tsrp->status == srv_busy) {
465 tsrp->status = srv_not_busy;
468 lock_ReleaseWrite(&cm_serverLock);
475 /* special codes: VBUSY and VRESTARTING */
476 else if (errorCode == VBUSY || errorCode == VRESTARTING) {
477 if (!serversp && fidp) {
478 code = cm_GetServerList(fidp, userp, reqp, &serverspp);
480 serversp = *serverspp;
485 switch ( errorCode ) {
487 msgID = MSG_SERVER_REPORTS_VBUSY;
488 format = "Server %s reported busy when accessing volume %d in cell %s.";
491 msgID = MSG_SERVER_REPORTS_VRESTARTING;
492 format = "Server %s reported restarting when accessing volume %d in cell %s.";
496 if (serverp && fidp) {
497 /* Log server being offline for this volume */
498 sprintf(addr, "%d.%d.%d.%d",
499 ((serverp->addr.sin_addr.s_addr & 0xff)),
500 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
501 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
502 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
504 osi_Log3(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
505 LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume, cellp->name);
508 lock_ObtainWrite(&cm_serverLock);
509 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
510 if (tsrp->status == srv_deleted)
512 if (tsrp->server == serverp && tsrp->status == srv_not_busy) {
513 tsrp->status = srv_busy;
514 if (fidp) { /* File Server query */
515 lock_ReleaseWrite(&cm_serverLock);
516 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
517 CM_GETVOL_FLAG_NO_LRU_UPDATE,
520 statep = cm_VolumeStateByID(volp, fidp->volume);
521 lock_ObtainWrite(&cm_serverLock);
526 lock_ReleaseWrite(&cm_serverLock);
529 cm_UpdateVolumeStatus(volp, statep->ID);
530 lock_ObtainRead(&cm_volumeLock);
532 lock_ReleaseRead(&cm_volumeLock);
537 cm_FreeServerList(serverspp, 0);
544 /* special codes: missing volumes */
545 else if (errorCode == VNOVOL || errorCode == VMOVED || errorCode == VOFFLINE ||
546 errorCode == VSALVAGE || errorCode == VNOSERVICE || errorCode == VIO)
548 /* In case of timeout */
549 reqp->volumeError = errorCode;
551 switch ( errorCode ) {
553 msgID = MSG_SERVER_REPORTS_VNOVOL;
554 format = "Server %s reported volume %d in cell %s as not attached (may have been moved or deleted).";
557 msgID = MSG_SERVER_REPORTS_VMOVED;
558 format = "Server %s reported volume %d in cell %s as moved.";
561 msgID = MSG_SERVER_REPORTS_VOFFLINE;
562 format = "Server %s reported volume %d in cell %s as offline.";
565 msgID = MSG_SERVER_REPORTS_VSALVAGE;
566 format = "Server %s reported volume %d in cell %s as needs salvage.";
569 msgID = MSG_SERVER_REPORTS_VNOSERVICE;
570 format = "Server %s reported volume %d in cell %s as not in service.";
573 msgID = MSG_SERVER_REPORTS_VIO;
574 format = "Server %s reported volume %d in cell %s as temporarily unaccessible.";
578 if (fidp) { /* File Server query */
580 /* Log server being unavailable for this volume */
581 sprintf(addr, "%d.%d.%d.%d",
582 ((serverp->addr.sin_addr.s_addr & 0xff)),
583 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
584 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
585 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
587 osi_Log3(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
588 LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume, cellp->name);
591 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
592 CM_GETVOL_FLAG_NO_LRU_UPDATE,
595 statep = cm_VolumeStateByID(volp, fidp->volume);
597 if ((errorCode == VMOVED || errorCode == VNOVOL || errorCode == VOFFLINE) &&
598 !(reqp->flags & CM_REQ_VOLUME_UPDATED))
600 code = cm_ForceUpdateVolume(fidp, userp, reqp);
602 location_updated = 1;
604 /* Even if the update fails, there might still be another replica */
606 reqp->flags |= CM_REQ_VOLUME_UPDATED;
607 osi_Log3(afsd_logp, "cm_Analyze called cm_ForceUpdateVolume cell %u vol %u code 0x%x",
608 fidp->cell, fidp->volume, code);
612 cm_UpdateVolumeStatus(volp, statep->ID);
613 osi_Log3(afsd_logp, "cm_Analyze NewVolState cell %u vol %u state %u",
614 fidp->cell, fidp->volume, statep->state);
618 lock_ObtainRead(&cm_volumeLock);
620 lock_ReleaseRead(&cm_volumeLock);
625 * Mark server offline for this volume or delete the volume
626 * from the server list if it was moved or is not present.
628 if (!serversp || location_updated) {
629 code = cm_GetServerList(fidp, userp, reqp, &serverspp);
631 serversp = *serverspp;
637 lock_ObtainWrite(&cm_serverLock);
638 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
639 if (tsrp->status == srv_deleted)
642 sprintf(addr, "%d.%d.%d.%d",
643 ((tsrp->server->addr.sin_addr.s_addr & 0xff)),
644 ((tsrp->server->addr.sin_addr.s_addr & 0xff00)>> 8),
645 ((tsrp->server->addr.sin_addr.s_addr & 0xff0000)>> 16),
646 ((tsrp->server->addr.sin_addr.s_addr & 0xff000000)>> 24));
648 if (cm_ServerEqual(tsrp->server, serverp)) {
650 if (errorCode == VMOVED || errorCode == VNOVOL) {
651 osi_Log2(afsd_logp, "volume %d not present on server %s",
652 fidp->volume, osi_LogSaveString(afsd_logp,addr));
653 tsrp->status = srv_deleted;
655 cm_RemoveVolumeFromServer(serverp, fidp->volume);
657 osi_Log2(afsd_logp, "volume %d instance on server %s marked offline",
658 fidp->volume, osi_LogSaveString(afsd_logp,addr));
659 tsrp->status = srv_offline;
663 osi_Log3(afsd_logp, "volume %d exists on server %s with status %u",
664 fidp->volume, osi_LogSaveString(afsd_logp,addr), tsrp->status);
667 lock_ReleaseWrite(&cm_serverLock);
669 /* Free the server list before cm_ForceUpdateVolume is called */
671 cm_FreeServerList(serverspp, 0);
678 } else if ( errorCode == VNOVNODE ) {
681 osi_Log4(afsd_logp, "cm_Analyze passed VNOVNODE cell %u vol %u vn %u uniq %u.",
682 fidp->cell, fidp->volume, fidp->vnode, fidp->unique);
684 scp = cm_FindSCache(fidp);
686 cm_scache_t *pscp = NULL;
688 if (scp->fileType != CM_SCACHETYPE_DIRECTORY)
689 pscp = cm_FindSCacheParent(scp);
691 lock_ObtainWrite(&scp->rw);
692 scp->flags |= CM_SCACHEFLAG_DELETED;
693 lock_ObtainWrite(&cm_scacheLock);
694 cm_AdjustScacheLRU(scp);
695 cm_RemoveSCacheFromHashTable(scp);
696 lock_ReleaseWrite(&cm_scacheLock);
697 cm_LockMarkSCacheLost(scp);
698 lock_ReleaseWrite(&scp->rw);
700 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
701 scp->fid.hash, scp->fileType, AFS_INVALIDATE_DELETED);
702 cm_ReleaseSCache(scp);
705 if (cm_HaveCallback(pscp)) {
706 lock_ObtainWrite(&pscp->rw);
707 cm_DiscardSCache(pscp);
708 lock_ReleaseWrite(&pscp->rw);
711 RDR_InvalidateObject(pscp->fid.cell, pscp->fid.volume, pscp->fid.vnode, pscp->fid.unique,
712 pscp->fid.hash, pscp->fileType, AFS_INVALIDATE_EXPIRED);
715 cm_ReleaseSCache(pscp);
719 osi_Log0(afsd_logp, "cm_Analyze passed VNOVNODE unknown fid.");
724 else if (errorCode == RX_CALL_TIMEOUT) {
725 /* RPC took longer than hardDeadTime or the server
726 * reported idle for longer than idleDeadTime
727 * don't mark server as down but don't retry
728 * this is to prevent the SMB session from timing out
729 * In addition, we log an event to the event log
733 sprintf(addr, "%d.%d.%d.%d",
734 ((serverp->addr.sin_addr.s_addr & 0xff)),
735 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
736 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
737 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
739 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_HARD_DEAD_TIME_EXCEEDED, addr);
740 osi_Log1(afsd_logp, "cm_Analyze: hardDeadTime or idleDeadtime exceeded addr[%s]",
741 osi_LogSaveString(afsd_logp,addr));
742 reqp->tokenIdleErrorServp = serverp;
747 if (!fidp) { /* vldb */
750 cm_volume_t *volp = cm_GetVolumeByFID(fidp);
752 if (fidp->volume == cm_GetROVolumeID(volp))
759 else if (errorCode == RX_MSGSIZE) {
761 * RPC failed because a transmitted rx packet
762 * may have grown larger than the path mtu.
763 * Force a retry and the Rx library will try
764 * with a smaller mtu size.
768 sprintf(addr, "%d.%d.%d.%d",
769 ((serverp->addr.sin_addr.s_addr & 0xff)),
770 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
771 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
772 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
774 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_MSGSIZE_EXCEEDED, addr);
775 osi_Log1(afsd_logp, "cm_Analyze: Path MTU may have been exceeded addr[%s]",
776 osi_LogSaveString(afsd_logp,addr));
780 else if (errorCode == CM_RX_RETRY_BUSY_CALL) {
782 * RPC failed because the selected call channel
783 * is currently busy on the server. Unconditionally
784 * retry the request so an alternate call channel can be used.
787 sprintf(addr, "%d.%d.%d.%d",
788 ((serverp->addr.sin_addr.s_addr & 0xff)),
789 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
790 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
791 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
793 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_BUSY_CALL_CHANNEL, addr);
794 osi_Log1(afsd_logp, "cm_Analyze: Retry RPC due to busy call channel addr[%s]",
795 osi_LogSaveString(afsd_logp,addr));
798 else if (errorCode >= -64 && errorCode < 0) {
799 /* mark server as down */
801 sprintf(addr, "%d.%d.%d.%d",
802 ((serverp->addr.sin_addr.s_addr & 0xff)),
803 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
804 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
805 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
807 if (errorCode == RX_CALL_DEAD)
808 osi_Log2(afsd_logp, "cm_Analyze: Rx Call Dead addr[%s] forcedNew[%s]",
809 osi_LogSaveString(afsd_logp,addr),
810 (reqp->flags & CM_REQ_NEW_CONN_FORCED ? "yes" : "no"));
812 osi_Log3(afsd_logp, "cm_Analyze: Rx Misc Error[%d] addr[%s] forcedNew[%s]",
814 osi_LogSaveString(afsd_logp,addr),
815 (reqp->flags & CM_REQ_NEW_CONN_FORCED ? "yes" : "no"));
818 lock_ObtainMutex(&serverp->mx);
819 if (errorCode == RX_CALL_DEAD &&
820 (reqp->flags & CM_REQ_NEW_CONN_FORCED)) {
821 if (!(serverp->flags & CM_SERVERFLAG_DOWN)) {
822 _InterlockedOr(&serverp->flags, CM_SERVERFLAG_DOWN);
823 serverp->downTime = time(NULL);
826 if (reqp->flags & CM_REQ_NEW_CONN_FORCED) {
827 reqp->tokenIdleErrorServp = serverp;
828 reqp->tokenError = errorCode;
830 reqp->flags |= CM_REQ_NEW_CONN_FORCED;
834 lock_ReleaseMutex(&serverp->mx);
835 cm_ForceNewConnections(serverp);
840 else if (errorCode == RXKADEXPIRED) {
841 osi_Log1(afsd_logp, "cm_Analyze: rxkad error code 0x%x (RXKADEXPIRED)",
844 lock_ObtainMutex(&userp->mx);
845 ucellp = cm_GetUCell(userp, serverp->cellp);
846 if (ucellp->ticketp) {
847 free(ucellp->ticketp);
848 ucellp->ticketp = NULL;
850 _InterlockedAnd(&ucellp->flags, ~CM_UCELLFLAG_RXKAD);
852 lock_ReleaseMutex(&userp->mx);
856 } else if (errorCode >= ERROR_TABLE_BASE_RXK && errorCode < ERROR_TABLE_BASE_RXK + 256) {
857 char * s = "unknown error";
858 switch ( errorCode ) {
859 case RXKADINCONSISTENCY: s = "RXKADINCONSISTENCY"; break;
860 case RXKADPACKETSHORT : s = "RXKADPACKETSHORT"; break;
861 case RXKADLEVELFAIL : s = "RXKADLEVELFAIL"; break;
862 case RXKADTICKETLEN : s = "RXKADTICKETLEN"; break;
863 case RXKADOUTOFSEQUENCE: s = "RXKADOUTOFSEQUENCE"; break;
864 case RXKADNOAUTH : s = "RXKADNOAUTH"; break;
865 case RXKADBADKEY : s = "RXKADBADKEY"; break;
866 case RXKADBADTICKET : s = "RXKADBADTICKET"; break;
867 case RXKADUNKNOWNKEY : s = "RXKADUNKNOWNKEY"; break;
868 case RXKADEXPIRED : s = "RXKADEXPIRED"; break;
869 case RXKADSEALEDINCON : s = "RXKADSEALEDINCON"; break;
870 case RXKADDATALEN : s = "RXKADDATALEN"; break;
871 case RXKADILLEGALLEVEL : s = "RXKADILLEGALLEVEL"; break;
873 osi_Log2(afsd_logp, "cm_Analyze: rxkad error code 0x%x (%s)",
877 reqp->tokenIdleErrorServp = serverp;
878 reqp->tokenError = errorCode;
881 } else if (errorCode >= ERROR_TABLE_BASE_U && errorCode < ERROR_TABLE_BASE_U + 256) {
883 * We received a ubik error. its possible that the server we are
884 * communicating with has a corrupted database or is partitioned
885 * from the rest of the servers and another server might be able
886 * to answer our query. Therefore, we will retry the request
887 * and force the use of another server.
890 reqp->tokenIdleErrorServp = serverp;
891 reqp->tokenError = errorCode;
894 } else if (errorCode == VICECONNBAD || errorCode == VICETOKENDEAD) {
895 cm_ForceNewConnections(serverp);
900 char * s = "unknown error";
901 switch ( errorCode ) {
902 case VSALVAGE : s = "VSALVAGE"; break;
903 case VNOVNODE : s = "VNOVNODE"; break;
904 case VNOVOL : s = "VNOVOL"; break;
905 case VVOLEXISTS : s = "VVOLEXISTS"; break;
906 case VNOSERVICE : s = "VNOSERVICE"; break;
907 case VOFFLINE : s = "VOFFLINE"; break;
908 case VONLINE : s = "VONLINE"; break;
909 case VDISKFULL : s = "VDISKFULL"; break;
910 case VOVERQUOTA : s = "VOVERQUOTA"; break;
911 case VBUSY : s = "VBUSY"; break;
912 case VMOVED : s = "VMOVED"; break;
913 case VIO : s = "VIO"; break;
914 case VRESTRICTED : s = "VRESTRICTED"; break;
915 case VRESTARTING : s = "VRESTARTING"; break;
916 case VREADONLY : s = "VREADONLY"; break;
917 case EAGAIN : s = "EAGAIN"; break;
918 case UAEAGAIN : s = "UAEAGAIN"; break;
919 case EINVAL : s = "EINVAL"; break;
920 case UAEINVAL : s = "UAEINVAL"; break;
921 case EACCES : s = "EACCES"; break;
922 case UAEACCES : s = "UAEACCES"; break;
923 case ENOENT : s = "ENOENT"; break;
924 case UAENOENT : s = "UAENOENT"; break;
925 case EEXIST : s = "EEXIST"; break;
926 case UAEEXIST : s = "UAEEXIST"; break;
927 case VICECONNBAD : s = "VICECONNBAD"; break;
928 case VICETOKENDEAD : s = "VICETOKENDEAD"; break;
929 case WSAEWOULDBLOCK : s = "WSAEWOULDBLOCK"; break;
930 case UAEWOULDBLOCK : s = "UAEWOULDBLOCK"; break;
931 case VL_IDEXIST : s = "VL_IDEXIST"; break;
932 case VL_IO : s = "VL_IO"; break;
933 case VL_NAMEEXIST : s = "VL_NAMEEXIST"; break;
934 case VL_CREATEFAIL : s = "VL_CREATEFAIL"; break;
935 case VL_NOENT : s = "VL_NOENT"; break;
936 case VL_EMPTY : s = "VL_EMPTY"; break;
937 case VL_ENTDELETED : s = "VL_ENTDELETED"; break;
938 case VL_BADNAME : s = "VL_BADNAME"; break;
939 case VL_BADINDEX : s = "VL_BADINDEX"; break;
940 case VL_BADVOLTYPE : s = "VL_BADVOLTYPE"; break;
941 case VL_BADSERVER : s = "VL_BADSERVER"; break;
942 case VL_BADPARTITION : s = "VL_BADPARTITION"; break;
943 case VL_REPSFULL : s = "VL_REPSFULL"; break;
944 case VL_NOREPSERVER : s = "VL_NOREPSERVER"; break;
945 case VL_DUPREPSERVER : s = "VL_DUPREPSERVER"; break;
946 case VL_RWNOTFOUND : s = "VL_RWNOTFOUND"; break;
947 case VL_BADREFCOUNT : s = "VL_BADREFCOUNT"; break;
948 case VL_SIZEEXCEEDED : s = "VL_SIZEEXCEEDED"; break;
949 case VL_BADENTRY : s = "VL_BADENTRY"; break;
950 case VL_BADVOLIDBUMP : s = "VL_BADVOLIDBUMP"; break;
951 case VL_IDALREADYHASHED: s = "VL_IDALREADYHASHED"; break;
952 case VL_ENTRYLOCKED : s = "VL_ENTRYLOCKED"; break;
953 case VL_BADVOLOPER : s = "VL_BADVOLOPER"; break;
954 case VL_BADRELLOCKTYPE : s = "VL_BADRELLOCKTYPE"; break;
955 case VL_RERELEASE : s = "VL_RERELEASE"; break;
956 case VL_BADSERVERFLAG : s = "VL_BADSERVERFLAG"; break;
957 case VL_PERM : s = "VL_PERM"; break;
958 case VL_NOMEM : s = "VL_NOMEM"; break;
959 case VL_BADVERSION : s = "VL_BADVERSION"; break;
960 case VL_INDEXERANGE : s = "VL_INDEXERANGE"; break;
961 case VL_MULTIPADDR : s = "VL_MULTIPADDR"; break;
962 case VL_BADMASK : s = "VL_BADMASK"; break;
963 case CM_ERROR_NOSUCHCELL : s = "CM_ERROR_NOSUCHCELL"; break;
964 case CM_ERROR_NOSUCHVOLUME : s = "CM_ERROR_NOSUCHVOLUME"; break;
965 case CM_ERROR_TIMEDOUT : s = "CM_ERROR_TIMEDOUT"; break;
966 case CM_ERROR_RETRY : s = "CM_ERROR_RETRY"; break;
967 case CM_ERROR_NOACCESS : s = "CM_ERROR_NOACCESS"; break;
968 case CM_ERROR_NOSUCHFILE : s = "CM_ERROR_NOSUCHFILE"; break;
969 case CM_ERROR_STOPNOW : s = "CM_ERROR_STOPNOW"; break;
970 case CM_ERROR_TOOBIG : s = "CM_ERROR_TOOBIG"; break;
971 case CM_ERROR_INVAL : s = "CM_ERROR_INVAL"; break;
972 case CM_ERROR_BADFD : s = "CM_ERROR_BADFD"; break;
973 case CM_ERROR_BADFDOP : s = "CM_ERROR_BADFDOP"; break;
974 case CM_ERROR_EXISTS : s = "CM_ERROR_EXISTS"; break;
975 case CM_ERROR_CROSSDEVLINK : s = "CM_ERROR_CROSSDEVLINK"; break;
976 case CM_ERROR_BADOP : s = "CM_ERROR_BADOP"; break;
977 case CM_ERROR_BADPASSWORD : s = "CM_ERROR_BADPASSWORD"; break;
978 case CM_ERROR_NOTDIR : s = "CM_ERROR_NOTDIR"; break;
979 case CM_ERROR_ISDIR : s = "CM_ERROR_ISDIR"; break;
980 case CM_ERROR_READONLY : s = "CM_ERROR_READONLY"; break;
981 case CM_ERROR_WOULDBLOCK : s = "CM_ERROR_WOULDBLOCK"; break;
982 case CM_ERROR_QUOTA : s = "CM_ERROR_QUOTA"; break;
983 case CM_ERROR_SPACE : s = "CM_ERROR_SPACE"; break;
984 case CM_ERROR_BADSHARENAME : s = "CM_ERROR_BADSHARENAME"; break;
985 case CM_ERROR_BADTID : s = "CM_ERROR_BADTID"; break;
986 case CM_ERROR_UNKNOWN : s = "CM_ERROR_UNKNOWN"; break;
987 case CM_ERROR_NOMORETOKENS : s = "CM_ERROR_NOMORETOKENS"; break;
988 case CM_ERROR_NOTEMPTY : s = "CM_ERROR_NOTEMPTY"; break;
989 case CM_ERROR_USESTD : s = "CM_ERROR_USESTD"; break;
990 case CM_ERROR_REMOTECONN : s = "CM_ERROR_REMOTECONN"; break;
991 case CM_ERROR_ATSYS : s = "CM_ERROR_ATSYS"; break;
992 case CM_ERROR_NOSUCHPATH : s = "CM_ERROR_NOSUCHPATH"; break;
993 case CM_ERROR_CLOCKSKEW : s = "CM_ERROR_CLOCKSKEW"; break;
994 case CM_ERROR_BADSMB : s = "CM_ERROR_BADSMB"; break;
995 case CM_ERROR_ALLBUSY : s = "CM_ERROR_ALLBUSY"; break;
996 case CM_ERROR_NOFILES : s = "CM_ERROR_NOFILES"; break;
997 case CM_ERROR_PARTIALWRITE : s = "CM_ERROR_PARTIALWRITE"; break;
998 case CM_ERROR_NOIPC : s = "CM_ERROR_NOIPC"; break;
999 case CM_ERROR_BADNTFILENAME : s = "CM_ERROR_BADNTFILENAME"; break;
1000 case CM_ERROR_BUFFERTOOSMALL : s = "CM_ERROR_BUFFERTOOSMALL"; break;
1001 case CM_ERROR_RENAME_IDENTICAL : s = "CM_ERROR_RENAME_IDENTICAL"; break;
1002 case CM_ERROR_ALLOFFLINE : s = "CM_ERROR_ALLOFFLINE"; break;
1003 case CM_ERROR_AMBIGUOUS_FILENAME: s = "CM_ERROR_AMBIGUOUS_FILENAME"; break;
1004 case CM_ERROR_BADLOGONTYPE : s = "CM_ERROR_BADLOGONTYPE"; break;
1005 case CM_ERROR_GSSCONTINUE : s = "CM_ERROR_GSSCONTINUE"; break;
1006 case CM_ERROR_TIDIPC : s = "CM_ERROR_TIDIPC"; break;
1007 case CM_ERROR_TOO_MANY_SYMLINKS : s = "CM_ERROR_TOO_MANY_SYMLINKS"; break;
1008 case CM_ERROR_PATH_NOT_COVERED : s = "CM_ERROR_PATH_NOT_COVERED"; break;
1009 case CM_ERROR_LOCK_CONFLICT : s = "CM_ERROR_LOCK_CONFLICT"; break;
1010 case CM_ERROR_SHARING_VIOLATION : s = "CM_ERROR_SHARING_VIOLATION"; break;
1011 case CM_ERROR_ALLDOWN : s = "CM_ERROR_ALLDOWN"; break;
1012 case CM_ERROR_TOOFEWBUFS : s = "CM_ERROR_TOOFEWBUFS"; break;
1013 case CM_ERROR_TOOMANYBUFS : s = "CM_ERROR_TOOMANYBUFS"; break;
1015 osi_Log2(afsd_logp, "cm_Analyze: ignoring error code 0x%x (%s)",
1021 /* If not allowed to retry, don't */
1022 if (!forcing_new && (reqp->flags & CM_REQ_NORETRY) &&
1023 (errorCode != RX_MSGSIZE && errorCode != CM_RX_RETRY_BUSY_CALL))
1025 else if (retry && dead_session)
1028 /* drop this on the way out */
1033 * clear the volume updated flag if we succeed.
1034 * this way the flag will not prevent a subsequent volume
1035 * from being updated if necessary.
1039 reqp->flags &= ~CM_REQ_VOLUME_UPDATED;
1042 /* retry until we fail to find a connection */
1046 long cm_ConnByMServers(cm_serverRef_t *serversp, cm_user_t *usersp,
1047 cm_req_t *reqp, cm_conn_t **connpp)
1050 cm_serverRef_t *tsrp;
1052 long firstError = 0;
1053 int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
1054 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1055 long timeUsed, timeLeft, hardTimeLeft;
1059 if (serversp == NULL) {
1060 osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", CM_ERROR_ALLDOWN);
1061 return CM_ERROR_ALLDOWN;
1064 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1065 timeUsed = (GetTickCount() - reqp->startTime) / 1000;
1067 /* leave 5 seconds margin of safety */
1068 timeLeft = ConnDeadtimeout - timeUsed - 5;
1069 hardTimeLeft = HardDeadtimeout - timeUsed - 5;
1072 lock_ObtainRead(&cm_serverLock);
1073 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
1074 if (tsrp->status == srv_deleted)
1078 if (reqp->tokenIdleErrorServp) {
1080 * search the list until we find the server
1081 * that failed last time. When we find it
1082 * clear the error, skip it and try the next one
1085 if (tsp == reqp->tokenIdleErrorServp)
1086 reqp->tokenIdleErrorServp = NULL;
1090 cm_GetServerNoLock(tsp);
1091 lock_ReleaseRead(&cm_serverLock);
1092 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1094 if (tsrp->status == srv_busy) {
1097 } else if (tsrp->status == srv_offline) {
1103 code = cm_ConnByServer(tsp, usersp, connpp);
1104 if (code == 0) { /* cm_CBS only returns 0 */
1106 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1107 /* Set RPC timeout */
1108 if (timeLeft > ConnDeadtimeout)
1109 timeLeft = ConnDeadtimeout;
1111 if (hardTimeLeft > HardDeadtimeout)
1112 hardTimeLeft = HardDeadtimeout;
1114 lock_ObtainMutex(&(*connpp)->mx);
1115 rx_SetConnDeadTime((*connpp)->rxconnp, timeLeft);
1116 rx_SetConnHardDeadTime((*connpp)->rxconnp, (u_short) hardTimeLeft);
1117 lock_ReleaseMutex(&(*connpp)->mx);
1122 /* therefore, this code is never executed */
1123 if (firstError == 0)
1127 lock_ObtainRead(&cm_serverLock);
1128 cm_PutServerNoLock(tsp);
1131 lock_ReleaseRead(&cm_serverLock);
1133 if (firstError == 0) {
1135 firstError = (reqp->tokenError ? reqp->tokenError :
1136 (reqp->idleError ? RX_CALL_TIMEOUT : CM_ERROR_ALLDOWN));
1138 * if we experienced either a token error or and idle dead time error
1139 * and now all of the servers are down, we have either tried them
1140 * all or lost connectivity. Clear the error we are returning so
1141 * we will not return it indefinitely if the request is retried.
1143 reqp->idleError = reqp->tokenError = 0;
1144 } else if (allBusy) {
1145 firstError = CM_ERROR_ALLBUSY;
1146 } else if (allOffline || (someBusy && someOffline)) {
1147 firstError = CM_ERROR_ALLOFFLINE;
1149 osi_Log0(afsd_logp, "cm_ConnByMServers returning impossible error TIMEDOUT");
1150 firstError = CM_ERROR_TIMEDOUT;
1154 osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", firstError);
1158 /* called with a held server to GC all bad connections hanging off of the server */
1159 void cm_GCConnections(cm_server_t *serverp)
1165 lock_ObtainWrite(&cm_connLock);
1166 lcpp = &serverp->connsp;
1167 for (tcp = *lcpp; tcp; tcp = *lcpp) {
1169 if (userp && tcp->refCount == 0 && (userp->vcRefs == 0)) {
1170 /* do the deletion of this guy */
1171 cm_PutServer(tcp->serverp);
1172 cm_ReleaseUser(userp);
1174 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, 0);
1175 rx_DestroyConnection(tcp->rxconnp);
1176 lock_FinalizeMutex(&tcp->mx);
1180 /* just advance to the next */
1184 lock_ReleaseWrite(&cm_connLock);
1187 static void cm_NewRXConnection(cm_conn_t *tcp, cm_ucell_t *ucellp,
1188 cm_server_t *serverp)
1190 unsigned short port;
1193 struct rx_securityClass *secObjp;
1195 port = serverp->addr.sin_port;
1196 switch (serverp->type) {
1197 case CM_SERVER_VLDB:
1202 case CM_SERVER_FILE:
1208 osi_panic("unknown server type", __FILE__, __LINE__);
1211 if (ucellp->flags & CM_UCELLFLAG_RXKAD) {
1215 tcp->cryptlevel = rxkad_clear;
1218 tcp->cryptlevel = rxkad_auth;
1221 tcp->cryptlevel = rxkad_crypt;
1223 secObjp = rxkad_NewClientSecurityObject(tcp->cryptlevel,
1224 &ucellp->sessionKey, ucellp->kvno,
1225 ucellp->ticketLen, ucellp->ticketp);
1229 tcp->cryptlevel = rxkad_clear;
1230 secObjp = rxnull_NewClientSecurityObject();
1232 osi_assertx(secObjp != NULL, "null rx_securityClass");
1233 tcp->rxconnp = rx_NewConnection(serverp->addr.sin_addr.s_addr,
1238 rx_SetConnDeadTime(tcp->rxconnp, ConnDeadtimeout);
1239 rx_SetConnHardDeadTime(tcp->rxconnp, HardDeadtimeout);
1240 rx_SetConnIdleDeadTime(tcp->rxconnp, IdleDeadtimeout);
1243 * Register the error to be returned on an idle dead timeout
1245 rx_SetServerConnIdleDeadErr(tcp->rxconnp, RX_CALL_DEAD);
1248 * Let the Rx library know that we can auto-retry if an
1249 * RX_MSGSIZE error is returned.
1251 if (rx_pmtu_discovery)
1252 rx_SetMsgsizeRetryErr(tcp->rxconnp, RX_MSGSIZE);
1255 * Attempt to limit NAT pings to the anonymous file server connections.
1256 * Only file servers implement client callbacks and we only need one ping
1257 * to be sent to each server.
1259 if (NatPingInterval && serverp->type == CM_SERVER_FILE &&
1260 (ucellp->flags & CM_UCELLFLAG_ROOTUSER)) {
1261 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, NatPingInterval);
1264 tcp->ucgen = ucellp->gen;
1266 rxs_Release(secObjp); /* Decrement the initial refCount */
1269 long cm_ConnByServer(cm_server_t *serverp, cm_user_t *userp, cm_conn_t **connpp)
1276 if (cm_anonvldb && serverp->type == CM_SERVER_VLDB)
1277 userp = cm_rootUserp;
1279 lock_ObtainMutex(&userp->mx);
1280 lock_ObtainRead(&cm_connLock);
1281 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1282 if (tcp->userp == userp)
1286 /* find ucell structure */
1287 ucellp = cm_GetUCell(userp, serverp->cellp);
1289 lock_ConvertRToW(&cm_connLock);
1290 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1291 if (tcp->userp == userp)
1295 lock_ReleaseWrite(&cm_connLock);
1298 cm_GetServer(serverp);
1299 tcp = malloc(sizeof(*tcp));
1300 memset(tcp, 0, sizeof(*tcp));
1301 tcp->nextp = serverp->connsp;
1302 serverp->connsp = tcp;
1305 lock_InitializeMutex(&tcp->mx, "cm_conn_t mutex", LOCK_HIERARCHY_CONN);
1306 lock_ObtainMutex(&tcp->mx);
1307 tcp->serverp = serverp;
1308 tcp->cryptlevel = rxkad_clear;
1309 cm_NewRXConnection(tcp, ucellp, serverp);
1311 lock_ReleaseMutex(&tcp->mx);
1312 lock_ReleaseWrite(&cm_connLock);
1314 lock_ReleaseRead(&cm_connLock);
1316 InterlockedIncrement(&tcp->refCount);
1318 lock_ObtainMutex(&tcp->mx);
1319 if ((tcp->flags & CM_CONN_FLAG_FORCE_NEW) ||
1320 (tcp->ucgen < ucellp->gen) ||
1321 (tcp->cryptlevel != (ucellp->flags & CM_UCELLFLAG_RXKAD ? (cryptall == 1 ? rxkad_crypt : (cryptall == 2 ? rxkad_auth : rxkad_clear)) : rxkad_clear)))
1323 if (tcp->ucgen < ucellp->gen)
1324 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to token update");
1326 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to crypt change");
1327 tcp->flags &= ~CM_CONN_FLAG_FORCE_NEW;
1328 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, 0);
1329 rx_DestroyConnection(tcp->rxconnp);
1330 cm_NewRXConnection(tcp, ucellp, serverp);
1332 lock_ReleaseMutex(&tcp->mx);
1334 lock_ReleaseMutex(&userp->mx);
1336 /* return this pointer to our caller */
1337 osi_Log1(afsd_logp, "cm_ConnByServer returning conn 0x%p", tcp);
1343 long cm_ServerAvailable(struct cm_fid *fidp, struct cm_user *userp)
1347 cm_serverRef_t **serverspp;
1348 cm_serverRef_t *tsrp;
1350 int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
1354 code = cm_GetServerList(fidp, userp, &req, &serverspp);
1358 lock_ObtainRead(&cm_serverLock);
1359 for (tsrp = *serverspp; tsrp; tsrp=tsrp->next) {
1360 if (tsrp->status == srv_deleted)
1363 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1365 if (tsrp->status == srv_busy) {
1368 } else if (tsrp->status == srv_offline) {
1377 lock_ReleaseRead(&cm_serverLock);
1378 cm_FreeServerList(serverspp, 0);
1384 else if (allOffline || (someBusy && someOffline))
1391 * The returned cm_conn_t ** object is released in the subsequent call
1394 long cm_ConnFromFID(struct cm_fid *fidp, struct cm_user *userp, cm_req_t *reqp,
1398 cm_serverRef_t **serverspp;
1402 code = cm_GetServerList(fidp, userp, reqp, &serverspp);
1407 code = cm_ConnByMServers(*serverspp, userp, reqp, connpp);
1408 cm_FreeServerList(serverspp, 0);
1413 long cm_ConnFromVolume(struct cm_volume *volp, unsigned long volid, struct cm_user *userp, cm_req_t *reqp,
1417 cm_serverRef_t **serverspp;
1421 serverspp = cm_GetVolServers(volp, volid, userp, reqp);
1423 code = cm_ConnByMServers(*serverspp, userp, reqp, connpp);
1424 cm_FreeServerList(serverspp, 0);
1429 extern struct rx_connection *
1430 cm_GetRxConn(cm_conn_t *connp)
1432 struct rx_connection * rxconnp;
1433 lock_ObtainMutex(&connp->mx);
1434 rxconnp = connp->rxconnp;
1435 rx_GetConnection(rxconnp);
1436 lock_ReleaseMutex(&connp->mx);
1440 void cm_ForceNewConnections(cm_server_t *serverp)
1444 lock_ObtainWrite(&cm_connLock);
1445 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1446 lock_ObtainMutex(&tcp->mx);
1447 tcp->flags |= CM_CONN_FLAG_FORCE_NEW;
1448 lock_ReleaseMutex(&tcp->mx);
1450 lock_ReleaseWrite(&cm_connLock);