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 ReplicaIdleDeadtimeout = CM_CONN_IDLEDEADTIME_REP;
34 unsigned short NatPingInterval = CM_CONN_NATPINGINTERVAL;
36 #define LANMAN_WKS_PARAM_KEY "SYSTEM\\CurrentControlSet\\Services\\lanmanworkstation\\parameters"
37 #define LANMAN_WKS_SESSION_TIMEOUT "SessTimeout"
38 #define LANMAN_WKS_EXT_SESSION_TIMEOUT "ExtendedSessTimeout"
40 afs_uint32 cryptall = 0;
41 afs_uint32 cm_anonvldb = 0;
42 afs_uint32 rx_pmtu_discovery = 0;
44 void cm_PutConn(cm_conn_t *connp)
46 afs_int32 refCount = InterlockedDecrement(&connp->refCount);
47 osi_assertx(refCount >= 0, "cm_conn_t refcount underflow");
50 void cm_InitConn(void)
52 static osi_once_t once;
58 if (osi_Once(&once)) {
59 lock_InitializeRWLock(&cm_connLock, "connection global lock",
60 LOCK_HIERARCHY_CONN_GLOBAL);
62 /* keisa - read timeout value for lanmanworkstation service.
64 * http://support.microsoft.com:80/support/kb/articles/Q102/0/67.asp&NoWebContent=1
65 * the SessTimeout is a minimum timeout not a maximum timeout. Therefore,
66 * I believe that the default should not be short. Instead, we should wait until
67 * RX times out before reporting a timeout to the SMB client.
69 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, LANMAN_WKS_PARAM_KEY,
70 0, KEY_QUERY_VALUE, &parmKey);
71 if (code == ERROR_SUCCESS)
73 BOOL extTimeouts = msftSMBRedirectorSupportsExtendedTimeouts();
77 * The default value is 1000 seconds. However, this default
78 * will not apply to "\\AFS" unless "AFS" is listed in
79 * ServersWithExtendedSessTimeout which we will add when we
80 * create the ExtendedSessTimeout value in smb_Init()
82 dummyLen = sizeof(DWORD);
83 code = RegQueryValueEx(parmKey,
84 LANMAN_WKS_EXT_SESSION_TIMEOUT,
86 (BYTE *) &dwValue, &dummyLen);
87 if (code == ERROR_SUCCESS) {
89 afsi_log("lanmanworkstation : ExtSessTimeout %u", RDRtimeout);
92 if (!extTimeouts || code != ERROR_SUCCESS) {
93 dummyLen = sizeof(DWORD);
94 code = RegQueryValueEx(parmKey,
95 LANMAN_WKS_SESSION_TIMEOUT,
97 (BYTE *) &dwValue, &dummyLen);
98 if (code == ERROR_SUCCESS) {
100 afsi_log("lanmanworkstation : SessTimeout %u", RDRtimeout);
103 RegCloseKey(parmKey);
106 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
107 0, KEY_QUERY_VALUE, &parmKey);
108 if (code == ERROR_SUCCESS) {
109 dummyLen = sizeof(DWORD);
110 code = RegQueryValueEx(parmKey, "ConnDeadTimeout", NULL, NULL,
111 (BYTE *) &dwValue, &dummyLen);
112 if (code == ERROR_SUCCESS) {
113 ConnDeadtimeout = (unsigned short)dwValue;
114 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
116 dummyLen = sizeof(DWORD);
117 code = RegQueryValueEx(parmKey, "HardDeadTimeout", NULL, NULL,
118 (BYTE *) &dwValue, &dummyLen);
119 if (code == ERROR_SUCCESS) {
120 HardDeadtimeout = (unsigned short)dwValue;
121 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
123 dummyLen = sizeof(DWORD);
124 code = RegQueryValueEx(parmKey, "IdleDeadTimeout", NULL, NULL,
125 (BYTE *) &dwValue, &dummyLen);
126 if (code == ERROR_SUCCESS) {
127 IdleDeadtimeout = (unsigned short)dwValue;
128 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
130 dummyLen = sizeof(DWORD);
131 code = RegQueryValueEx(parmKey, "ReplicaIdleDeadTimeout", NULL, NULL,
132 (BYTE *) &dwValue, &dummyLen);
133 if (code == ERROR_SUCCESS) {
134 ReplicaIdleDeadtimeout = (unsigned short)dwValue;
135 afsi_log("ReplicaIdleDeadTimeout is %d", ReplicaIdleDeadtimeout);
137 dummyLen = sizeof(DWORD);
138 code = RegQueryValueEx(parmKey, "NatPingInterval", NULL, NULL,
139 (BYTE *) &dwValue, &dummyLen);
140 if (code == ERROR_SUCCESS) {
141 NatPingInterval = (unsigned short)dwValue;
143 afsi_log("NatPingInterval is %d", NatPingInterval);
144 RegCloseKey(parmKey);
148 * If these values were not set via cpp macro or obtained
149 * from the registry, we use a value that is derived from
150 * the smb redirector session timeout (RDRtimeout).
152 * The UNIX cache manager uses 120 seconds for the hard dead
153 * timeout and 50 seconds for the connection and idle timeouts.
155 * We base our values on those while making sure we leave
156 * enough time for overhead.
158 * To further complicate matters we need to take into account
159 * file server hard dead timeouts as they affect the length
160 * of time it takes the file server to give up when attempting
161 * to break callbacks to unresponsive clients. The file
162 * server hard dead timeout is 120 seconds.
164 * For SMB, we have no choice but to timeout quickly. For
165 * the AFS redirector, we can wait.
168 afsi_log("lanmanworkstation : SessTimeout %u", RDRtimeout);
169 if (ConnDeadtimeout == 0) {
170 ConnDeadtimeout = (unsigned short) ((RDRtimeout / 2) < 50 ? (RDRtimeout / 2) : 50);
171 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
173 if (HardDeadtimeout == 0) {
174 HardDeadtimeout = (unsigned short) (RDRtimeout > 125 ? 120 : (RDRtimeout - 5));
175 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
177 if (IdleDeadtimeout == 0) {
178 IdleDeadtimeout = 10 * (unsigned short) HardDeadtimeout;
179 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
181 if (ReplicaIdleDeadtimeout == 0) {
182 ReplicaIdleDeadtimeout = (unsigned short) HardDeadtimeout;
183 afsi_log("ReplicaIdleDeadTimeout is %d", ReplicaIdleDeadtimeout);
186 if (ConnDeadtimeout == 0) {
187 ConnDeadtimeout = CM_CONN_IFS_CONNDEADTIME;
188 afsi_log("ConnDeadTimeout is %d", ConnDeadtimeout);
190 if (HardDeadtimeout == 0) {
191 HardDeadtimeout = CM_CONN_IFS_HARDDEADTIME;
192 afsi_log("HardDeadTimeout is %d", HardDeadtimeout);
194 if (IdleDeadtimeout == 0) {
195 IdleDeadtimeout = CM_CONN_IFS_IDLEDEADTIME;
196 afsi_log("IdleDeadTimeout is %d", IdleDeadtimeout);
198 if (IdleDeadtimeout == 0) {
199 ReplicaIdleDeadtimeout = CM_CONN_IFS_IDLEDEADTIME_REP;
200 afsi_log("ReplicaIdleDeadTimeout is %d", ReplicaIdleDeadtimeout);
207 void cm_InitReq(cm_req_t *reqp)
209 memset(reqp, 0, sizeof(cm_req_t));
210 reqp->startTime = GetTickCount();
213 long cm_GetVolServerList(cm_volume_t *volp, afs_uint32 volid, struct cm_user *userp,
214 struct cm_req *reqp, afs_uint32 *replicated,
215 cm_serverRef_t ***serversppp)
217 *serversppp = cm_GetVolServers(volp, volid, userp, reqp, replicated);
218 return (*serversppp ? 0 : CM_ERROR_NOSUCHVOLUME);
221 long cm_GetServerList(struct cm_fid *fidp, struct cm_user *userp,
222 struct cm_req *reqp, afs_uint32 *replicated, cm_serverRef_t ***serversppp)
225 cm_volume_t *volp = NULL;
226 cm_cell_t *cellp = NULL;
230 return CM_ERROR_INVAL;
233 cellp = cm_FindCellByID(fidp->cell, 0);
235 return CM_ERROR_NOSUCHCELL;
237 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp, CM_GETVOL_FLAG_CREATE, &volp);
241 *serversppp = cm_GetVolServers(volp, fidp->volume, userp, reqp, replicated);
243 lock_ObtainRead(&cm_volumeLock);
245 lock_ReleaseRead(&cm_volumeLock);
246 return (*serversppp ? 0 : CM_ERROR_NOSUCHVOLUME);
250 cm_SetServerBusyStatus(cm_serverRef_t **serverspp, cm_server_t *serverp)
252 cm_serverRef_t *tsrp;
254 lock_ObtainRead(&cm_serverLock);
255 for (tsrp = *serverspp; tsrp; tsrp=tsrp->next) {
256 if (tsrp->status == srv_deleted)
258 if (cm_ServerEqual(tsrp->server, serverp) && tsrp->status == srv_not_busy) {
259 tsrp->status = srv_busy;
263 lock_ReleaseRead(&cm_serverLock);
267 cm_ResetServerBusyStatus(cm_serverRef_t **serverspp)
269 cm_serverRef_t *tsrp;
271 lock_ObtainRead(&cm_serverLock);
272 for (tsrp = *serverspp; tsrp; tsrp=tsrp->next) {
273 if (tsrp->status == srv_deleted)
275 if (tsrp->status == srv_busy) {
276 tsrp->status = srv_not_busy;
279 lock_ReleaseRead(&cm_serverLock);
283 * Analyze the error return from an RPC. Determine whether or not to retry,
284 * and if we're going to retry, determine whether failover is appropriate,
285 * and whether timed backoff is appropriate.
287 * If the error code is from cm_ConnFromFID() or friends, it will be a CM_ERROR code.
288 * Otherwise it will be an RPC code. This may be a UNIX code (e.g. EDQUOT), or
289 * it may be an RX code, or it may be a special code (e.g. VNOVOL), or it may
290 * be a security code (e.g. RXKADEXPIRED).
292 * If the error code is from cm_ConnFromFID() or friends, connp will be NULL.
294 * For VLDB calls, fidp will be NULL and cellp will not be.
296 * volSyncp and/or cbrp may also be NULL.
299 cm_Analyze(cm_conn_t *connp,
305 AFSFetchStatus *statusp,
306 AFSVolSync *volSyncp,
307 cm_serverRef_t ** vlServerspp,
308 cm_callbackRequest_t *cbrp,
311 cm_server_t *serverp = NULL;
312 cm_serverRef_t **volServerspp = NULL;
313 cm_serverRef_t *tsrp;
315 cm_volume_t * volp = NULL;
316 cm_vol_state_t *statep = NULL;
317 cm_scache_t * scp = NULL;
318 afs_uint32 replicated = 0;
320 int free_svr_list = 0;
321 int dead_session = (userp->cellInfop == NULL);
322 long timeUsed, timeLeft;
324 char addr[16]="unknown";
326 int location_updated = 0;
329 int invalid_status = 0;
331 osi_Log2(afsd_logp, "cm_Analyze connp 0x%p, code 0x%x",
334 /* no locking required, since connp->serverp never changes after
337 serverp = connp->serverp;
339 /* Update callback pointer */
340 if (cbrp && serverp && errorCode == 0) {
342 if ( cbrp->serverp != serverp ) {
343 lock_ObtainWrite(&cm_serverLock);
344 cm_PutServerNoLock(cbrp->serverp);
345 cm_GetServerNoLock(serverp);
346 lock_ReleaseWrite(&cm_serverLock);
349 cm_GetServer(serverp);
351 cbrp->serverp = serverp;
354 /* if timeout - check that it did not exceed the HardDead timeout
357 /* timeleft - get it from reqp the same way as cm_ConnByMServers does */
358 timeUsed = (GetTickCount() - reqp->startTime) / 1000;
359 if ( (reqp->flags & CM_REQ_SOURCE_SMB) ||
360 (serverp && serverp->type == CM_SERVER_VLDB))
361 timeLeft = HardDeadtimeout - timeUsed;
363 timeLeft = 0x0FFFFFFF;
366 * Similar to the UNIX cache manager, if the AFSFetchStatus info
367 * returned by the file server is invalid, consider the response
368 * as being equivalent to VBUSY so that another file server can
369 * be queried if there is one. If there is no replica, then the
372 if (errorCode == 0 && statusp && !cm_IsStatusValid(statusp)) {
377 /* get a pointer to the cell */
379 if (cellp == NULL && serverp)
380 cellp = serverp->cellp;
381 if (cellp == NULL && vlServerspp) {
382 struct cm_serverRef * refp;
383 lock_ObtainRead(&cm_serverLock);
384 for ( refp=*vlServerspp ; cellp == NULL && refp != NULL; refp=refp->next) {
385 if (refp->status == srv_deleted)
388 cellp = refp->server->cellp;
390 lock_ReleaseRead(&cm_serverLock);
392 if (cellp == NULL && fidp) {
393 cellp = cm_FindCellByID(fidp->cell, 0);
397 if (errorCode == 0) {
399 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
401 else if (errorCode == CM_ERROR_TIMEDOUT) {
402 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_TIMEDOUT");
403 if ( timeLeft > 5 ) {
405 cm_CheckServers(CM_FLAG_CHECKDOWNSERVERS, cellp);
410 else if (errorCode == CM_ERROR_RETRY) {
411 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_RETRY");
415 else if (errorCode == UAEWOULDBLOCK || errorCode == EWOULDBLOCK ||
416 errorCode == UAEAGAIN || errorCode == EAGAIN) {
417 osi_Log0(afsd_logp, "cm_Analyze passed EWOULDBLOCK or EAGAIN.");
418 if ( timeLeft > 5 ) {
424 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
427 /* if there is nosuchvolume, then we have a situation in which a
428 * previously known volume no longer has a set of servers
429 * associated with it. Either the volume has moved or
430 * the volume has been deleted. Try to find a new server list
431 * until the timeout period expires.
433 else if (errorCode == CM_ERROR_NOSUCHVOLUME) {
434 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_NOSUCHVOLUME.");
436 * The VNOVOL or VL_NOENT error has already been translated
437 * to CM_ERROR_NOSUCHVOLUME. There is nothing for us to do.
441 else if (errorCode == CM_ERROR_EMPTY) {
443 * The server list is empty (or all entries have been deleted).
444 * If fidp is NULL, this was a vlServer list and we can attempt
445 * to force a cell lookup. If fidp is not NULL, we can attempt
446 * to refresh the volume location list.
449 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
450 CM_GETVOL_FLAG_NO_LRU_UPDATE,
453 lock_ObtainWrite(&volp->rw);
454 if (cm_UpdateVolumeLocation(cellp, userp, reqp, volp) == 0) {
455 lock_ReleaseWrite(&volp->rw);
456 code = cm_GetVolServerList(volp, fidp->volume, userp, reqp, &replicated, &volServerspp);
458 if (!cm_IsServerListEmpty(*volServerspp))
460 cm_FreeServerList(volServerspp, 0);
463 lock_ReleaseWrite(&volp->rw);
465 lock_ObtainRead(&cm_volumeLock);
467 lock_ReleaseRead(&cm_volumeLock);
471 cm_cell_t * newCellp = cm_UpdateCell( cellp, 0);
476 else if (errorCode == CM_ERROR_ALLDOWN) {
477 /* Servers marked DOWN will be restored by the background daemon
478 * thread as they become available. The volume status is
479 * updated as the server state changes.
482 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_DOWN (FS cell %s vol 0x%x)",
483 cellp->name, fidp->volume);
484 msgID = MSG_ALL_SERVERS_DOWN;
485 format = "All servers are unreachable when accessing cell %s volume %d.";
486 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
488 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLDOWN (VL Server)");
491 else if (errorCode == CM_ERROR_ALLOFFLINE) {
492 /* Volume instances marked offline will be restored by the
493 * background daemon thread as they become available
496 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE (FS cell %s vol 0x%x)",
497 cellp->name, fidp->volume);
498 msgID = MSG_ALL_SERVERS_OFFLINE;
499 format = "All servers are offline when accessing cell %s volume %d.";
500 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
502 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
503 CM_GETVOL_FLAG_NO_LRU_UPDATE,
506 if (volServerspp == NULL) {
507 code = cm_GetVolServerList(volp, fidp->volume, userp, reqp, &replicated, &volServerspp);
512 cm_ResetServerBusyStatus(volServerspp);
514 cm_FreeServerList(volServerspp, 0);
520 * Do not perform a cm_CheckOfflineVolume() if cm_Analyze()
521 * was called by cm_CheckOfflineVolumeState().
523 if (!(reqp->flags & (CM_REQ_OFFLINE_VOL_CHK|CM_REQ_NORETRY)) &&
528 /* cm_CheckOfflineVolume() resets the serverRef state */
529 if (cm_CheckOfflineVolume(volp, fidp->volume))
532 cm_UpdateVolumeStatus(volp, fidp->volume);
534 lock_ObtainRead(&cm_volumeLock);
536 lock_ReleaseRead(&cm_volumeLock);
540 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLOFFLINE (VL Server)");
543 else if (errorCode == CM_ERROR_ALLBUSY) {
544 /* Volumes that are busy cannot be determined to be non-busy
545 * without actually attempting to access them.
547 if (fidp) { /* File Server query */
548 osi_Log2(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY (FS cell %s vol 0x%x)",
549 cellp->name, fidp->volume);
550 msgID = MSG_ALL_SERVERS_BUSY;
551 format = "All servers are busy when accessing cell %s volume %d.";
552 LogEvent(EVENTLOG_WARNING_TYPE, msgID, cellp->name, fidp->volume);
554 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
555 CM_GETVOL_FLAG_NO_LRU_UPDATE,
558 if (volServerspp == NULL) {
559 code = cm_GetVolServerList(volp, fidp->volume, userp, reqp, &replicated, &volServerspp);
564 cm_ResetServerBusyStatus(volServerspp);
566 cm_FreeServerList(volServerspp, 0);
572 * retry all replicas for 5 minutes waiting 15 seconds
575 if (timeLeft > 20 && !(reqp->flags & CM_REQ_NORETRY) &&
576 reqp->volbusyCount++ < 20)
581 cm_UpdateVolumeStatus(volp, fidp->volume);
583 lock_ObtainRead(&cm_volumeLock);
585 lock_ReleaseRead(&cm_volumeLock);
588 } else { /* VL Server query */
589 osi_Log0(afsd_logp, "cm_Analyze passed CM_ERROR_ALLBUSY (VL Server).");
591 if (timeLeft > 7 && !(reqp->flags & CM_REQ_NORETRY) && vlServerspp)
595 cm_ResetServerBusyStatus(vlServerspp);
601 /* special codes: VBUSY and VRESTARTING */
602 else if (errorCode == VBUSY || errorCode == VRESTARTING) {
604 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
607 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
608 CM_GETVOL_FLAG_NO_LRU_UPDATE,
611 if (volServerspp == NULL) {
612 code = cm_GetVolServerList(volp, fidp->volume, userp, reqp, &replicated, &volServerspp);
617 statep = cm_VolumeStateByID(volp, fidp->volume);
620 cm_UpdateVolumeStatus(volp, statep->ID);
622 lock_ObtainRead(&cm_volumeLock);
624 lock_ReleaseRead(&cm_volumeLock);
630 /* Log server being offline for this volume */
631 sprintf(addr, "%d.%d.%d.%d",
632 ((serverp->addr.sin_addr.s_addr & 0xff)),
633 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
634 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
635 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
637 switch ( errorCode ) {
639 if (invalid_status) {
640 msgID = MSG_SERVER_REPLIED_BAD_STATUS;
641 format = "Server %s replied with bad status info when accessing volume %d in cell %s. Data discarded by cache manager.";
643 msgID = MSG_SERVER_REPORTS_VBUSY;
644 format = "Server %s reported busy when accessing volume %d in cell %s.";
648 msgID = MSG_SERVER_REPORTS_VRESTARTING;
649 format = "Server %s reported restarting when accessing volume %d in cell %s.";
653 osi_Log3(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
654 LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume, cellp->name);
657 cm_SetServerBusyStatus(volServerspp, serverp);
661 cm_FreeServerList(volServerspp, 0);
668 /* special codes: missing volumes */
669 else if (errorCode == VNOVOL || errorCode == VMOVED || errorCode == VOFFLINE ||
670 errorCode == VSALVAGE || errorCode == VIO)
673 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
675 /* In case of timeout */
676 reqp->volumeError = errorCode;
678 switch ( errorCode ) {
680 msgID = MSG_SERVER_REPORTS_VNOVOL;
681 format = "Server %s reported volume %d in cell %s as not attached (may have been moved or deleted).";
684 msgID = MSG_SERVER_REPORTS_VMOVED;
685 format = "Server %s reported volume %d in cell %s as moved.";
688 msgID = MSG_SERVER_REPORTS_VOFFLINE;
689 format = "Server %s reported volume %d in cell %s as offline.";
692 msgID = MSG_SERVER_REPORTS_VSALVAGE;
693 format = "Server %s reported volume %d in cell %s as needs salvage.";
696 msgID = MSG_SERVER_REPORTS_VIO;
697 format = "Server %s reported volume %d in cell %s as temporarily unaccessible.";
701 if (fidp) { /* File Server query */
703 /* Log server being unavailable for this volume */
704 sprintf(addr, "%d.%d.%d.%d",
705 ((serverp->addr.sin_addr.s_addr & 0xff)),
706 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
707 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
708 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
710 osi_Log3(afsd_logp, format, osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
711 LogEvent(EVENTLOG_WARNING_TYPE, msgID, addr, fidp->volume, cellp->name);
714 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
715 CM_GETVOL_FLAG_NO_LRU_UPDATE,
718 statep = cm_VolumeStateByID(volp, fidp->volume);
720 if ((errorCode == VMOVED || errorCode == VNOVOL || errorCode == VOFFLINE) &&
721 !(reqp->flags & CM_REQ_VOLUME_UPDATED))
723 LONG_PTR oldSum, newSum;
725 oldSum = cm_ChecksumVolumeServerList(fidp, userp, reqp);
727 code = cm_ForceUpdateVolume(fidp, userp, reqp);
729 location_updated = 1;
730 newSum = cm_ChecksumVolumeServerList(fidp, userp, reqp);
734 * Even if the update fails, there might still be another replica.
735 * If the volume location list changed, permit another update on
736 * a subsequent error.
738 if (code || oldSum == newSum)
739 reqp->flags |= CM_REQ_VOLUME_UPDATED;
741 osi_Log3(afsd_logp, "cm_Analyze called cm_ForceUpdateVolume cell %u vol %u code 0x%x",
742 fidp->cell, fidp->volume, code);
746 cm_UpdateVolumeStatus(volp, statep->ID);
747 osi_Log3(afsd_logp, "cm_Analyze NewVolState cell %u vol %u state %u",
748 fidp->cell, fidp->volume, statep->state);
752 lock_ObtainRead(&cm_volumeLock);
754 lock_ReleaseRead(&cm_volumeLock);
759 * Mark server offline for this volume or delete the volume
760 * from the server list if it was moved or is not present.
762 if (volServerspp == NULL || location_updated) {
763 code = cm_GetServerList(fidp, userp, reqp, &replicated, &volServerspp);
771 lock_ObtainWrite(&cm_serverLock);
772 for (tsrp = *volServerspp; tsrp; tsrp=tsrp->next) {
773 if (tsrp->status == srv_deleted)
776 sprintf(addr, "%d.%d.%d.%d",
777 ((tsrp->server->addr.sin_addr.s_addr & 0xff)),
778 ((tsrp->server->addr.sin_addr.s_addr & 0xff00)>> 8),
779 ((tsrp->server->addr.sin_addr.s_addr & 0xff0000)>> 16),
780 ((tsrp->server->addr.sin_addr.s_addr & 0xff000000)>> 24));
782 if (cm_ServerEqual(tsrp->server, serverp)) {
786 osi_Log2(afsd_logp, "volume %u moved from server %s",
787 fidp->volume, osi_LogSaveString(afsd_logp,addr));
788 tsrp->status = srv_deleted;
790 cm_RemoveVolumeFromServer(serverp, fidp->volume);
794 * The 1.6.0 and 1.6.1 file servers send transient VNOVOL errors which
795 * are no indicative of the volume not being present. For example,
796 * VNOVOL can be sent during a transition to a VBUSY state prior to
797 * salvaging or when cloning a .backup volume instance. As a result
798 * the cache manager must attempt at least one retry when a VNOVOL is
799 * receive but there are no changes to the volume location information.
801 if (reqp->vnovolError > 0 && cm_ServerEqual(reqp->errorServp, serverp)) {
802 osi_Log2(afsd_logp, "volume %u not present on server %s",
803 fidp->volume, osi_LogSaveString(afsd_logp,addr));
804 tsrp->status = srv_deleted;
806 cm_RemoveVolumeFromServer(serverp, fidp->volume);
808 osi_Log2(afsd_logp, "VNOVOL received for volume %u from server %s",
809 fidp->volume, osi_LogSaveString(afsd_logp,addr));
811 if (tsrp->status == srv_not_busy)
812 tsrp->status = srv_busy;
819 osi_Log2(afsd_logp, "VOFFLINE received for volume %u from server %s",
820 fidp->volume, osi_LogSaveString(afsd_logp,addr));
821 tsrp->status = srv_offline;
824 osi_Log3(afsd_logp, "volume %u exists on server %s with status %u",
825 fidp->volume, osi_LogSaveString(afsd_logp,addr), tsrp->status);
829 lock_ReleaseWrite(&cm_serverLock);
832 /* Remember that the VNOVOL error occurred */
833 if (errorCode == VNOVOL) {
834 reqp->errorServp = serverp;
838 /* Remember that the VIO error occurred */
839 if (errorCode == VIO) {
840 reqp->errorServp = serverp;
844 /* Free the server list before cm_ForceUpdateVolume is called */
846 cm_FreeServerList(volServerspp, 0);
851 if ( timeLeft > 2 && reqp->vioCount < 100)
853 } else if ( errorCode == VNOVNODE ) {
855 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
858 osi_Log4(afsd_logp, "cm_Analyze passed VNOVNODE cell %u vol %u vn %u uniq %u.",
859 fidp->cell, fidp->volume, fidp->vnode, fidp->unique);
861 scp = cm_FindSCache(fidp);
863 cm_scache_t *pscp = NULL;
865 if (scp->fileType != CM_SCACHETYPE_DIRECTORY)
866 pscp = cm_FindSCacheParent(scp);
868 lock_ObtainWrite(&scp->rw);
869 _InterlockedOr(&scp->flags, CM_SCACHEFLAG_DELETED);
870 lock_ObtainWrite(&cm_scacheLock);
871 cm_AdjustScacheLRU(scp);
872 lock_ReleaseWrite(&cm_scacheLock);
873 cm_LockMarkSCacheLost(scp);
874 lock_ReleaseWrite(&scp->rw);
876 RDR_InvalidateObject(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
877 scp->fid.hash, scp->fileType, AFS_INVALIDATE_DELETED);
878 cm_ReleaseSCache(scp);
881 if (cm_HaveCallback(pscp)) {
882 lock_ObtainWrite(&pscp->rw);
883 cm_DiscardSCache(pscp);
884 lock_ReleaseWrite(&pscp->rw);
887 RDR_InvalidateObject(pscp->fid.cell, pscp->fid.volume, pscp->fid.vnode, pscp->fid.unique,
888 pscp->fid.hash, pscp->fileType, AFS_INVALIDATE_EXPIRED);
891 cm_ReleaseSCache(pscp);
895 osi_Log0(afsd_logp, "cm_Analyze passed VNOVNODE unknown fid.");
900 else if (errorCode == RX_CALL_TIMEOUT) {
901 /* RPC took longer than hardDeadTime or the server
902 * reported idle for longer than idleDeadTime
903 * don't mark server as down but don't retry
904 * this is to prevent the SMB session from timing out
905 * In addition, we log an event to the event log
909 sprintf(addr, "%d.%d.%d.%d",
910 ((serverp->addr.sin_addr.s_addr & 0xff)),
911 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
912 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
913 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
915 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_HARD_DEAD_TIME_EXCEEDED, addr);
916 osi_Log1(afsd_logp, "cm_Analyze: hardDeadTime or idleDeadtime exceeded addr[%s]",
917 osi_LogSaveString(afsd_logp,addr));
918 reqp->errorServp = serverp;
923 scp = cm_FindSCache(fidp);
925 if (cm_HaveCallback(scp)) {
926 lock_ObtainWrite(&scp->rw);
927 cm_DiscardSCache(scp);
928 lock_ReleaseWrite(&scp->rw);
931 * We really should notify the redirector that we discarded
932 * the status information but doing so in this case is not
933 * safe as it can result in a deadlock with extent release
937 cm_ReleaseSCache(scp);
941 if (!fidp) { /* vldb */
944 cm_volume_t *volp = cm_FindVolumeByFID(fidp, userp, reqp);
946 if (fidp->volume == cm_GetROVolumeID(volp))
953 else if (errorCode == RX_MSGSIZE) {
955 * RPC failed because a transmitted rx packet
956 * may have grown larger than the path mtu.
957 * Force a retry and the Rx library will try
958 * with a smaller mtu size.
962 sprintf(addr, "%d.%d.%d.%d",
963 ((serverp->addr.sin_addr.s_addr & 0xff)),
964 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
965 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
966 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
968 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_MSGSIZE_EXCEEDED, addr);
969 osi_Log1(afsd_logp, "cm_Analyze: Path MTU may have been exceeded addr[%s]",
970 osi_LogSaveString(afsd_logp,addr));
974 else if (errorCode == RX_CALL_BUSY) {
976 * RPC failed because the selected call channel
977 * is currently busy on the server. Unconditionally
978 * retry the request so an alternate call channel can be used.
981 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
984 sprintf(addr, "%d.%d.%d.%d",
985 ((serverp->addr.sin_addr.s_addr & 0xff)),
986 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
987 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
988 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
990 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_BUSY_CALL_CHANNEL, addr);
991 osi_Log1(afsd_logp, "cm_Analyze: Retry RPC due to busy call channel addr[%s]",
992 osi_LogSaveString(afsd_logp,addr));
995 else if (errorCode == VNOSERVICE) {
997 * The server did not service the RPC.
998 * If this was a file server RPC it means that for at
999 * least the file server's idle dead timeout period the
1000 * file server did not receive any new data packets from
1003 * The RPC was not serviced so it can be retried and any
1004 * existing status information is still valid.
1007 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
1011 sprintf(addr, "%d.%d.%d.%d",
1012 ((serverp->addr.sin_addr.s_addr & 0xff)),
1013 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
1014 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
1015 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
1017 LogEvent(EVENTLOG_WARNING_TYPE, MSG_SERVER_REPORTS_VNOSERVICE,
1018 addr, fidp->volume, cellp->name);
1019 osi_Log3(afsd_logp, "Server %s reported rpc to volume %d in cell %s as not serviced.",
1020 osi_LogSaveString(afsd_logp,addr), fidp->volume, cellp->name);
1025 else if (errorCode == RX_CALL_IDLE) {
1027 * RPC failed because the server failed to respond with data
1028 * within the idle dead timeout period. This could be for a variety
1030 * 1. The server could have a bad partition such as a failed
1031 * disk or iSCSI target and all I/O to that partition is
1032 * blocking on the server and will never complete.
1034 * 2. The server vnode may be locked by another client request
1035 * that is taking a very long time.
1037 * 3. The server may have a very long queue of requests
1038 * pending and is unable to process this request.
1040 * 4. The server could be malicious and is performing a denial
1041 * of service attack against the client.
1043 * If this is a request against a .readonly with alternate sites
1044 * the server should be marked down for this request and the
1045 * client should fail over to another server. If this is a
1046 * request against a single source, the client may retry once.
1049 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
1052 sprintf(addr, "%d.%d.%d.%d",
1053 ((serverp->addr.sin_addr.s_addr & 0xff)),
1054 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
1055 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
1056 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
1059 code = cm_FindVolumeByID(cellp, fidp->volume, userp, reqp,
1060 CM_GETVOL_FLAG_NO_LRU_UPDATE,
1063 statep = cm_VolumeStateByID(volp, fidp->volume);
1066 replicated = (statep->flags & CM_VOL_STATE_FLAG_REPLICATED);
1068 lock_ObtainRead(&cm_volumeLock);
1070 lock_ReleaseRead(&cm_volumeLock);
1075 scp = cm_FindSCache(fidp);
1077 if (cm_HaveCallback(scp)) {
1078 lock_ObtainWrite(&scp->rw);
1079 cm_DiscardSCache(scp);
1080 lock_ReleaseWrite(&scp->rw);
1083 * We really should notify the redirector that we discarded
1084 * the status information but doing so in this case is not
1085 * safe as it can result in a deadlock with extent release
1089 cm_ReleaseSCache(scp);
1093 if (replicated && serverp) {
1094 reqp->errorServp = serverp;
1095 reqp->tokenError = errorCode;
1100 LogEvent(EVENTLOG_WARNING_TYPE, MSG_RX_IDLE_DEAD_TIMEOUT, addr, retry);
1101 osi_Log2(afsd_logp, "cm_Analyze: RPC failed due to idle dead timeout addr[%s] retry=%u",
1102 osi_LogSaveString(afsd_logp,addr), retry);
1104 else if (errorCode == RX_CALL_DEAD) {
1105 /* mark server as down */
1107 sprintf(addr, "%d.%d.%d.%d",
1108 ((serverp->addr.sin_addr.s_addr & 0xff)),
1109 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
1110 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
1111 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
1113 osi_Log2(afsd_logp, "cm_Analyze: Rx Call Dead addr[%s] forcedNew[%s]",
1114 osi_LogSaveString(afsd_logp,addr),
1115 (reqp->flags & CM_REQ_NEW_CONN_FORCED ? "yes" : "no"));
1118 if ((connp->flags & CM_CONN_FLAG_NEW) ||
1119 (reqp->flags & CM_REQ_NEW_CONN_FORCED)) {
1120 lock_ObtainMutex(&serverp->mx);
1121 if (!(serverp->flags & CM_SERVERFLAG_DOWN)) {
1122 _InterlockedOr(&serverp->flags, CM_SERVERFLAG_DOWN);
1123 serverp->downTime = time(NULL);
1125 lock_ReleaseMutex(&serverp->mx);
1127 reqp->flags |= CM_REQ_NEW_CONN_FORCED;
1129 cm_ForceNewConnections(serverp);
1133 if (fidp && storeOp)
1134 scp = cm_FindSCache(fidp);
1136 if (cm_HaveCallback(scp)) {
1137 lock_ObtainWrite(&scp->rw);
1138 cm_DiscardSCache(scp);
1139 lock_ReleaseWrite(&scp->rw);
1142 * We really should notify the redirector that we discarded
1143 * the status information but doing so in this case is not
1144 * safe as it can result in a deadlock with extent release
1148 cm_ReleaseSCache(scp);
1154 else if (errorCode >= -64 && errorCode < 0) {
1155 /* mark server as down */
1157 sprintf(addr, "%d.%d.%d.%d",
1158 ((serverp->addr.sin_addr.s_addr & 0xff)),
1159 ((serverp->addr.sin_addr.s_addr & 0xff00)>> 8),
1160 ((serverp->addr.sin_addr.s_addr & 0xff0000)>> 16),
1161 ((serverp->addr.sin_addr.s_addr & 0xff000000)>> 24));
1163 osi_Log3(afsd_logp, "cm_Analyze: Rx Misc Error[%d] addr[%s] forcedNew[%s]",
1165 osi_LogSaveString(afsd_logp,addr),
1166 (reqp->flags & CM_REQ_NEW_CONN_FORCED ? "yes" : "no"));
1169 if ((connp->flags & CM_CONN_FLAG_NEW) ||
1170 (reqp->flags & CM_REQ_NEW_CONN_FORCED)) {
1171 reqp->errorServp = serverp;
1172 reqp->tokenError = errorCode;
1174 reqp->flags |= CM_REQ_NEW_CONN_FORCED;
1176 cm_ForceNewConnections(serverp);
1183 else if (errorCode == RXKADEXPIRED) {
1184 osi_Log1(afsd_logp, "cm_Analyze: rxkad error code 0x%x (RXKADEXPIRED)",
1186 if (!dead_session) {
1187 lock_ObtainMutex(&userp->mx);
1188 ucellp = cm_GetUCell(userp, cellp);
1189 if (ucellp->ticketp) {
1190 free(ucellp->ticketp);
1191 ucellp->ticketp = NULL;
1193 _InterlockedAnd(&ucellp->flags, ~CM_UCELLFLAG_RXKAD);
1195 lock_ReleaseMutex(&userp->mx);
1197 reqp->flags |= CM_REQ_NEW_CONN_FORCED;
1199 cm_ForceNewConnections(serverp);
1204 } else if (errorCode >= ERROR_TABLE_BASE_RXK && errorCode < ERROR_TABLE_BASE_RXK + 256) {
1205 char * s = "unknown error";
1206 switch ( errorCode ) {
1207 case RXKADINCONSISTENCY: s = "RXKADINCONSISTENCY"; break;
1208 case RXKADPACKETSHORT : s = "RXKADPACKETSHORT"; break;
1209 case RXKADLEVELFAIL : s = "RXKADLEVELFAIL"; break;
1210 case RXKADTICKETLEN : s = "RXKADTICKETLEN"; break;
1211 case RXKADOUTOFSEQUENCE: s = "RXKADOUTOFSEQUENCE"; break;
1212 case RXKADNOAUTH : s = "RXKADNOAUTH"; break;
1213 case RXKADBADKEY : s = "RXKADBADKEY"; break;
1214 case RXKADBADTICKET : s = "RXKADBADTICKET"; break;
1215 case RXKADUNKNOWNKEY : s = "RXKADUNKNOWNKEY"; break;
1216 case RXKADEXPIRED : s = "RXKADEXPIRED"; break;
1217 case RXKADSEALEDINCON : s = "RXKADSEALEDINCON"; break;
1218 case RXKADDATALEN : s = "RXKADDATALEN"; break;
1219 case RXKADILLEGALLEVEL : s = "RXKADILLEGALLEVEL"; break;
1221 osi_Log2(afsd_logp, "cm_Analyze: rxkad error code 0x%x (%s)",
1225 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
1228 reqp->errorServp = serverp;
1229 reqp->tokenError = errorCode;
1232 } else if (errorCode >= ERROR_TABLE_BASE_U && errorCode < ERROR_TABLE_BASE_U + 256) {
1234 * We received a ubik error. its possible that the server we are
1235 * communicating with has a corrupted database or is partitioned
1236 * from the rest of the servers and another server might be able
1237 * to answer our query. Therefore, we will retry the request
1238 * and force the use of another server.
1241 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
1244 reqp->errorServp = serverp;
1245 reqp->tokenError = errorCode;
1248 } else if (errorCode == VICECONNBAD || errorCode == VICETOKENDEAD) {
1249 reqp->flags |= CM_REQ_NEW_CONN_FORCED;
1251 cm_ForceNewConnections(serverp);
1255 _InterlockedAnd(&connp->flags, ~CM_CONN_FLAG_NEW);
1258 char * s = "unknown error";
1259 switch ( errorCode ) {
1260 case VSALVAGE : s = "VSALVAGE"; break;
1261 case VNOVNODE : s = "VNOVNODE"; break;
1262 case VNOVOL : s = "VNOVOL"; break;
1263 case VVOLEXISTS : s = "VVOLEXISTS"; break;
1264 case VNOSERVICE : s = "VNOSERVICE"; break;
1265 case VOFFLINE : s = "VOFFLINE"; break;
1266 case VONLINE : s = "VONLINE"; break;
1267 case VDISKFULL : s = "VDISKFULL"; break;
1268 case VOVERQUOTA : s = "VOVERQUOTA"; break;
1269 case VBUSY : s = "VBUSY"; break;
1270 case VMOVED : s = "VMOVED"; break;
1271 case VIO : s = "VIO"; break;
1272 case VRESTRICTED : s = "VRESTRICTED"; break;
1273 case VRESTARTING : s = "VRESTARTING"; break;
1274 case VREADONLY : s = "VREADONLY"; break;
1275 case EAGAIN : s = "EAGAIN"; break;
1276 case UAEAGAIN : s = "UAEAGAIN"; break;
1277 case EINVAL : s = "EINVAL"; break;
1278 case UAEINVAL : s = "UAEINVAL"; break;
1279 case EACCES : s = "EACCES"; break;
1280 case UAEACCES : s = "UAEACCES"; break;
1281 case ENOENT : s = "ENOENT"; break;
1282 case UAENOENT : s = "UAENOENT"; break;
1283 case EEXIST : s = "EEXIST"; break;
1284 case UAEEXIST : s = "UAEEXIST"; break;
1285 case VICECONNBAD : s = "VICECONNBAD"; break;
1286 case VICETOKENDEAD : s = "VICETOKENDEAD"; break;
1287 case WSAEWOULDBLOCK : s = "WSAEWOULDBLOCK"; break;
1288 case UAEWOULDBLOCK : s = "UAEWOULDBLOCK"; break;
1289 case VL_IDEXIST : s = "VL_IDEXIST"; break;
1290 case VL_IO : s = "VL_IO"; break;
1291 case VL_NAMEEXIST : s = "VL_NAMEEXIST"; break;
1292 case VL_CREATEFAIL : s = "VL_CREATEFAIL"; break;
1293 case VL_NOENT : s = "VL_NOENT"; break;
1294 case VL_EMPTY : s = "VL_EMPTY"; break;
1295 case VL_ENTDELETED : s = "VL_ENTDELETED"; break;
1296 case VL_BADNAME : s = "VL_BADNAME"; break;
1297 case VL_BADINDEX : s = "VL_BADINDEX"; break;
1298 case VL_BADVOLTYPE : s = "VL_BADVOLTYPE"; break;
1299 case VL_BADSERVER : s = "VL_BADSERVER"; break;
1300 case VL_BADPARTITION : s = "VL_BADPARTITION"; break;
1301 case VL_REPSFULL : s = "VL_REPSFULL"; break;
1302 case VL_NOREPSERVER : s = "VL_NOREPSERVER"; break;
1303 case VL_DUPREPSERVER : s = "VL_DUPREPSERVER"; break;
1304 case VL_RWNOTFOUND : s = "VL_RWNOTFOUND"; break;
1305 case VL_BADREFCOUNT : s = "VL_BADREFCOUNT"; break;
1306 case VL_SIZEEXCEEDED : s = "VL_SIZEEXCEEDED"; break;
1307 case VL_BADENTRY : s = "VL_BADENTRY"; break;
1308 case VL_BADVOLIDBUMP : s = "VL_BADVOLIDBUMP"; break;
1309 case VL_IDALREADYHASHED: s = "VL_IDALREADYHASHED"; break;
1310 case VL_ENTRYLOCKED : s = "VL_ENTRYLOCKED"; break;
1311 case VL_BADVOLOPER : s = "VL_BADVOLOPER"; break;
1312 case VL_BADRELLOCKTYPE : s = "VL_BADRELLOCKTYPE"; break;
1313 case VL_RERELEASE : s = "VL_RERELEASE"; break;
1314 case VL_BADSERVERFLAG : s = "VL_BADSERVERFLAG"; break;
1315 case VL_PERM : s = "VL_PERM"; break;
1316 case VL_NOMEM : s = "VL_NOMEM"; break;
1317 case VL_BADVERSION : s = "VL_BADVERSION"; break;
1318 case VL_INDEXERANGE : s = "VL_INDEXERANGE"; break;
1319 case VL_MULTIPADDR : s = "VL_MULTIPADDR"; break;
1320 case VL_BADMASK : s = "VL_BADMASK"; break;
1321 case CM_ERROR_NOSUCHCELL : s = "CM_ERROR_NOSUCHCELL"; break;
1322 case CM_ERROR_NOSUCHVOLUME : s = "CM_ERROR_NOSUCHVOLUME"; break;
1323 case CM_ERROR_NOACCESS : s = "CM_ERROR_NOACCESS"; break;
1324 case CM_ERROR_NOSUCHFILE : s = "CM_ERROR_NOSUCHFILE"; break;
1325 case CM_ERROR_STOPNOW : s = "CM_ERROR_STOPNOW"; break;
1326 case CM_ERROR_TOOBIG : s = "CM_ERROR_TOOBIG"; break;
1327 case CM_ERROR_INVAL : s = "CM_ERROR_INVAL"; break;
1328 case CM_ERROR_BADFD : s = "CM_ERROR_BADFD"; break;
1329 case CM_ERROR_BADFDOP : s = "CM_ERROR_BADFDOP"; break;
1330 case CM_ERROR_EXISTS : s = "CM_ERROR_EXISTS"; break;
1331 case CM_ERROR_CROSSDEVLINK : s = "CM_ERROR_CROSSDEVLINK"; break;
1332 case CM_ERROR_BADOP : s = "CM_ERROR_BADOP"; break;
1333 case CM_ERROR_BADPASSWORD : s = "CM_ERROR_BADPASSWORD"; break;
1334 case CM_ERROR_NOTDIR : s = "CM_ERROR_NOTDIR"; break;
1335 case CM_ERROR_ISDIR : s = "CM_ERROR_ISDIR"; break;
1336 case CM_ERROR_READONLY : s = "CM_ERROR_READONLY"; break;
1337 case CM_ERROR_WOULDBLOCK : s = "CM_ERROR_WOULDBLOCK"; break;
1338 case CM_ERROR_QUOTA : s = "CM_ERROR_QUOTA"; break;
1339 case CM_ERROR_SPACE : s = "CM_ERROR_SPACE"; break;
1340 case CM_ERROR_BADSHARENAME : s = "CM_ERROR_BADSHARENAME"; break;
1341 case CM_ERROR_BADTID : s = "CM_ERROR_BADTID"; break;
1342 case CM_ERROR_UNKNOWN : s = "CM_ERROR_UNKNOWN"; break;
1343 case CM_ERROR_NOMORETOKENS : s = "CM_ERROR_NOMORETOKENS"; break;
1344 case CM_ERROR_NOTEMPTY : s = "CM_ERROR_NOTEMPTY"; break;
1345 case CM_ERROR_USESTD : s = "CM_ERROR_USESTD"; break;
1346 case CM_ERROR_REMOTECONN : s = "CM_ERROR_REMOTECONN"; break;
1347 case CM_ERROR_ATSYS : s = "CM_ERROR_ATSYS"; break;
1348 case CM_ERROR_NOSUCHPATH : s = "CM_ERROR_NOSUCHPATH"; break;
1349 case CM_ERROR_CLOCKSKEW : s = "CM_ERROR_CLOCKSKEW"; break;
1350 case CM_ERROR_BADSMB : s = "CM_ERROR_BADSMB"; break;
1351 case CM_ERROR_ALLBUSY : s = "CM_ERROR_ALLBUSY"; break;
1352 case CM_ERROR_NOFILES : s = "CM_ERROR_NOFILES"; break;
1353 case CM_ERROR_PARTIALWRITE : s = "CM_ERROR_PARTIALWRITE"; break;
1354 case CM_ERROR_NOIPC : s = "CM_ERROR_NOIPC"; break;
1355 case CM_ERROR_BADNTFILENAME : s = "CM_ERROR_BADNTFILENAME"; break;
1356 case CM_ERROR_BUFFERTOOSMALL : s = "CM_ERROR_BUFFERTOOSMALL"; break;
1357 case CM_ERROR_RENAME_IDENTICAL : s = "CM_ERROR_RENAME_IDENTICAL"; break;
1358 case CM_ERROR_ALLOFFLINE : s = "CM_ERROR_ALLOFFLINE"; break;
1359 case CM_ERROR_AMBIGUOUS_FILENAME: s = "CM_ERROR_AMBIGUOUS_FILENAME"; break;
1360 case CM_ERROR_BADLOGONTYPE : s = "CM_ERROR_BADLOGONTYPE"; break;
1361 case CM_ERROR_GSSCONTINUE : s = "CM_ERROR_GSSCONTINUE"; break;
1362 case CM_ERROR_TIDIPC : s = "CM_ERROR_TIDIPC"; break;
1363 case CM_ERROR_TOO_MANY_SYMLINKS : s = "CM_ERROR_TOO_MANY_SYMLINKS"; break;
1364 case CM_ERROR_PATH_NOT_COVERED : s = "CM_ERROR_PATH_NOT_COVERED"; break;
1365 case CM_ERROR_LOCK_CONFLICT : s = "CM_ERROR_LOCK_CONFLICT"; break;
1366 case CM_ERROR_SHARING_VIOLATION : s = "CM_ERROR_SHARING_VIOLATION"; break;
1367 case CM_ERROR_ALLDOWN : s = "CM_ERROR_ALLDOWN"; break;
1368 case CM_ERROR_TOOFEWBUFS : s = "CM_ERROR_TOOFEWBUFS"; break;
1369 case CM_ERROR_TOOMANYBUFS : s = "CM_ERROR_TOOMANYBUFS"; break;
1370 case UAEIO : s = "UAEIO"; break;
1371 case EIO : s = "EIO"; break;
1373 osi_Log2(afsd_logp, "cm_Analyze: ignoring error code 0x%x (%s)",
1379 /* If not allowed to retry, don't */
1381 !forcing_new && (reqp->flags & CM_REQ_NORETRY) &&
1382 !(errorCode > -64 && errorCode <= RX_INVALID_OPERATION))
1385 /* drop this on the way out */
1391 * clear the volume updated flag if we succeed.
1392 * this way the flag will not prevent a subsequent volume
1393 * from being updated if necessary.
1397 reqp->flags &= ~CM_REQ_VOLUME_UPDATED;
1401 errorCode != VBUSY &&
1402 errorCode != VRESTARTING &&
1403 errorCode != CM_ERROR_ALLBUSY)
1405 cm_ResetServerBusyStatus(vlServerspp);
1408 /* retry until we fail to find a connection */
1412 long cm_ConnByMServers(cm_serverRef_t *serversp, afs_uint32 replicated, cm_user_t *usersp,
1413 cm_req_t *reqp, cm_conn_t **connpp)
1416 cm_serverRef_t *tsrp;
1418 long firstError = 0;
1419 int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1, allDeleted = 1;
1420 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1421 long timeUsed, timeLeft, hardTimeLeft;
1425 if (serversp == NULL) {
1426 osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", CM_ERROR_EMPTY);
1427 return CM_ERROR_EMPTY;
1430 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1431 timeUsed = (GetTickCount() - reqp->startTime) / 1000;
1433 /* leave 5 seconds margin of safety */
1434 timeLeft = ConnDeadtimeout - timeUsed - 5;
1435 hardTimeLeft = HardDeadtimeout - timeUsed - 5;
1438 lock_ObtainRead(&cm_serverLock);
1439 for (tsrp = serversp; tsrp; tsrp=tsrp->next) {
1440 if (tsrp->status == srv_deleted)
1446 if (reqp->errorServp) {
1448 * search the list until we find the server
1449 * that failed last time. When we find it
1450 * clear the error, skip it and try the next one
1453 if (tsp == reqp->errorServp)
1454 reqp->errorServp = NULL;
1458 cm_GetServerNoLock(tsp);
1459 lock_ReleaseRead(&cm_serverLock);
1460 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1462 if (tsrp->status == srv_busy) {
1465 } else if (tsrp->status == srv_offline) {
1471 code = cm_ConnByServer(tsp, usersp, replicated, connpp);
1472 if (code == 0) { /* cm_CBS only returns 0 */
1474 #ifdef SET_RX_TIMEOUTS_TO_TIMELEFT
1475 /* Set RPC timeout */
1476 if (timeLeft > ConnDeadtimeout)
1477 timeLeft = ConnDeadtimeout;
1479 if (hardTimeLeft > HardDeadtimeout)
1480 hardTimeLeft = HardDeadtimeout;
1482 lock_ObtainMutex(&(*connpp)->mx);
1483 rx_SetConnDeadTime((*connpp)->rxconnp, timeLeft);
1484 rx_SetConnHardDeadTime((*connpp)->rxconnp, (u_short) hardTimeLeft);
1485 lock_ReleaseMutex(&(*connpp)->mx);
1490 /* therefore, this code is never executed */
1491 if (firstError == 0)
1495 lock_ObtainRead(&cm_serverLock);
1496 cm_PutServerNoLock(tsp);
1499 lock_ReleaseRead(&cm_serverLock);
1501 if (firstError == 0) {
1503 firstError = CM_ERROR_EMPTY;
1504 } else if (allDown) {
1505 firstError = (reqp->tokenError ? reqp->tokenError :
1506 (reqp->idleError ? RX_CALL_TIMEOUT : CM_ERROR_ALLDOWN));
1508 * if we experienced either a token error or and idle dead time error
1509 * and now all of the servers are down, we have either tried them
1510 * all or lost connectivity. Clear the error we are returning so
1511 * we will not return it indefinitely if the request is retried.
1513 reqp->idleError = reqp->tokenError = 0;
1514 } else if (allBusy) {
1515 firstError = CM_ERROR_ALLBUSY;
1516 } else if (allOffline || (someBusy && someOffline)) {
1517 firstError = CM_ERROR_ALLOFFLINE;
1519 osi_Log0(afsd_logp, "cm_ConnByMServers returning impossible error TIMEDOUT");
1520 firstError = CM_ERROR_TIMEDOUT;
1524 osi_Log1(afsd_logp, "cm_ConnByMServers returning 0x%x", firstError);
1528 /* called with a held server to GC all bad connections hanging off of the server */
1529 void cm_GCConnections(cm_server_t *serverp)
1535 lock_ObtainWrite(&cm_connLock);
1536 lcpp = &serverp->connsp;
1537 for (tcp = *lcpp; tcp; tcp = *lcpp) {
1539 if (userp && tcp->refCount == 0 && (userp->vcRefs == 0)) {
1540 /* do the deletion of this guy */
1541 cm_PutServer(tcp->serverp);
1542 cm_ReleaseUser(userp);
1544 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, 0);
1545 rx_DestroyConnection(tcp->rxconnp);
1546 lock_FinalizeMutex(&tcp->mx);
1550 /* just advance to the next */
1554 lock_ReleaseWrite(&cm_connLock);
1557 static void cm_NewRXConnection(cm_conn_t *tcp, cm_ucell_t *ucellp,
1558 cm_server_t *serverp, afs_uint32 replicated)
1560 unsigned short port;
1563 struct rx_securityClass *secObjp;
1565 port = serverp->addr.sin_port;
1566 switch (serverp->type) {
1567 case CM_SERVER_VLDB:
1572 case CM_SERVER_FILE:
1578 osi_panic("unknown server type", __FILE__, __LINE__);
1581 if (ucellp->flags & CM_UCELLFLAG_RXKAD) {
1585 tcp->cryptlevel = rxkad_clear;
1588 tcp->cryptlevel = rxkad_auth;
1591 tcp->cryptlevel = rxkad_crypt;
1593 secObjp = rxkad_NewClientSecurityObject(tcp->cryptlevel,
1594 &ucellp->sessionKey, ucellp->kvno,
1595 ucellp->ticketLen, ucellp->ticketp);
1599 tcp->cryptlevel = rxkad_clear;
1600 secObjp = rxnull_NewClientSecurityObject();
1602 osi_assertx(secObjp != NULL, "null rx_securityClass");
1603 tcp->rxconnp = rx_NewConnection(serverp->addr.sin_addr.s_addr,
1608 rx_SetConnDeadTime(tcp->rxconnp, ConnDeadtimeout);
1609 if (smb_Enabled || tcp->serverp->type == CM_SERVER_VLDB)
1610 rx_SetConnHardDeadTime(tcp->rxconnp, HardDeadtimeout);
1613 * Setting idle dead timeout to a non-zero value activates RX_CALL_IDLE errors
1616 _InterlockedOr(&tcp->flags, CM_CONN_FLAG_REPLICATION);
1617 rx_SetConnIdleDeadTime(tcp->rxconnp, ReplicaIdleDeadtimeout);
1619 rx_SetConnIdleDeadTime(tcp->rxconnp, IdleDeadtimeout);
1623 * Let the Rx library know that we can auto-retry if an
1624 * RX_MSGSIZE error is returned.
1626 if (rx_pmtu_discovery)
1627 rx_SetMsgsizeRetryErr(tcp->rxconnp, RX_MSGSIZE);
1630 * Attempt to limit NAT pings to the anonymous file server connections.
1631 * Only file servers implement client callbacks and we only need one ping
1632 * to be sent to each server.
1634 if (NatPingInterval && serverp->type == CM_SERVER_FILE &&
1635 (ucellp->flags & CM_UCELLFLAG_ROOTUSER)) {
1636 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, NatPingInterval);
1639 tcp->ucgen = ucellp->gen;
1641 rxs_Release(secObjp); /* Decrement the initial refCount */
1643 _InterlockedAnd(&tcp->flags, ~CM_CONN_FLAG_FORCE_NEW);
1644 _InterlockedOr(&tcp->flags, CM_CONN_FLAG_NEW);
1647 long cm_ConnByServer(cm_server_t *serverp, cm_user_t *userp, afs_uint32 replicated, cm_conn_t **connpp)
1654 if (cm_anonvldb && serverp->type == CM_SERVER_VLDB)
1655 userp = cm_rootUserp;
1657 lock_ObtainMutex(&userp->mx);
1658 /* find ucell structure */
1659 ucellp = cm_GetUCell(userp, serverp->cellp);
1661 lock_ObtainRead(&cm_connLock);
1662 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1663 if (tcp->userp == userp &&
1664 (replicated && (tcp->flags & CM_CONN_FLAG_REPLICATION) ||
1665 !replicated && !(tcp->flags & CM_CONN_FLAG_REPLICATION)))
1670 lock_ConvertRToW(&cm_connLock);
1671 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1672 if (tcp->userp == userp &&
1673 (replicated && (tcp->flags & CM_CONN_FLAG_REPLICATION) ||
1674 !replicated && !(tcp->flags & CM_CONN_FLAG_REPLICATION)))
1678 InterlockedIncrement(&tcp->refCount);
1679 lock_ReleaseWrite(&cm_connLock);
1682 cm_GetServer(serverp);
1683 tcp = malloc(sizeof(*tcp));
1684 memset(tcp, 0, sizeof(*tcp));
1687 lock_InitializeMutex(&tcp->mx, "cm_conn_t mutex", LOCK_HIERARCHY_CONN);
1688 tcp->serverp = serverp;
1689 tcp->cryptlevel = rxkad_clear;
1690 cm_NewRXConnection(tcp, ucellp, serverp, replicated);
1692 tcp->nextp = serverp->connsp;
1693 serverp->connsp = tcp;
1694 lock_ReleaseWrite(&cm_connLock);
1695 lock_ReleaseMutex(&userp->mx);
1697 InterlockedIncrement(&tcp->refCount);
1698 lock_ReleaseRead(&cm_connLock);
1700 lock_ReleaseMutex(&userp->mx);
1702 lock_ObtainMutex(&tcp->mx);
1703 if ((tcp->flags & CM_CONN_FLAG_FORCE_NEW) ||
1704 (tcp->ucgen < ucellp->gen) ||
1705 (tcp->cryptlevel != (ucellp->flags & CM_UCELLFLAG_RXKAD ? (cryptall == 1 ? rxkad_crypt : (cryptall == 2 ? rxkad_auth : rxkad_clear)) : rxkad_clear)))
1707 if (tcp->ucgen < ucellp->gen)
1708 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to token update");
1710 osi_Log0(afsd_logp, "cm_ConnByServer replace connection due to crypt change");
1711 rx_SetConnSecondsUntilNatPing(tcp->rxconnp, 0);
1712 rx_DestroyConnection(tcp->rxconnp);
1713 cm_NewRXConnection(tcp, ucellp, serverp, replicated);
1715 lock_ReleaseMutex(&tcp->mx);
1718 /* return this pointer to our caller */
1719 osi_Log1(afsd_logp, "cm_ConnByServer returning conn 0x%p", tcp);
1725 long cm_ServerAvailable(struct cm_fid *fidp, struct cm_user *userp)
1729 cm_serverRef_t **serverspp;
1730 cm_serverRef_t *tsrp;
1732 int someBusy = 0, someOffline = 0, allOffline = 1, allBusy = 1, allDown = 1;
1733 afs_uint32 replicated;
1737 code = cm_GetServerList(fidp, userp, &req, &replicated, &serverspp);
1741 lock_ObtainRead(&cm_serverLock);
1742 for (tsrp = *serverspp; tsrp; tsrp=tsrp->next) {
1743 if (tsrp->status == srv_deleted)
1746 if (!(tsp->flags & CM_SERVERFLAG_DOWN)) {
1748 if (tsrp->status == srv_busy) {
1751 } else if (tsrp->status == srv_offline) {
1760 lock_ReleaseRead(&cm_serverLock);
1761 cm_FreeServerList(serverspp, 0);
1767 else if (allOffline || (someBusy && someOffline))
1774 * The returned cm_conn_t ** object is released in the subsequent call
1777 long cm_ConnFromFID(struct cm_fid *fidp, struct cm_user *userp, cm_req_t *reqp,
1781 cm_serverRef_t **serverspp;
1782 afs_uint32 replicated;
1786 code = cm_GetServerList(fidp, userp, reqp, &replicated, &serverspp);
1790 code = cm_ConnByMServers(*serverspp, replicated, userp, reqp, connpp);
1791 cm_FreeServerList(serverspp, 0);
1796 long cm_ConnFromVolume(struct cm_volume *volp, unsigned long volid, struct cm_user *userp, cm_req_t *reqp,
1800 cm_serverRef_t **serverspp;
1801 afs_uint32 replicated;
1805 code = cm_GetVolServerList(volp, volid, userp, reqp, &replicated, &serverspp);
1809 code = cm_ConnByMServers(*serverspp, replicated, userp, reqp, connpp);
1810 cm_FreeServerList(serverspp, 0);
1815 extern struct rx_connection *
1816 cm_GetRxConn(cm_conn_t *connp)
1818 struct rx_connection * rxconnp;
1819 lock_ObtainMutex(&connp->mx);
1820 rxconnp = connp->rxconnp;
1821 rx_GetConnection(rxconnp);
1822 lock_ReleaseMutex(&connp->mx);
1826 void cm_ForceNewConnections(cm_server_t *serverp)
1830 if (serverp == NULL)
1833 lock_ObtainWrite(&cm_connLock);
1834 for (tcp = serverp->connsp; tcp; tcp=tcp->nextp) {
1835 lock_ObtainMutex(&tcp->mx);
1836 _InterlockedOr(&tcp->flags, CM_CONN_FLAG_FORCE_NEW);
1837 lock_ReleaseMutex(&tcp->mx);
1839 lock_ReleaseWrite(&cm_connLock);