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
13 #include <afsconfig.h>
14 #include "afs/param.h"
18 #include "afs/sysincludes.h" /* Standard vendor system headers */
21 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
23 #include <netinet/in.h>
27 #include "h/hashing.h"
29 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV) && !defined(AFS_DARWIN_ENV)
30 #include <netinet/in_var.h>
34 #include "afsincludes.h" /* Afs-based standard headers */
35 #include "afs/afs_stats.h" /* afs statistics */
36 #include "afs/afs_util.h"
37 #include "afs/unified_afs.h"
39 #if defined(AFS_SUN56_ENV)
41 #include <inet/common.h>
42 #if defined(AFS_SUN58_ENV)
43 #include <netinet/ip6.h>
49 /* shouldn't do it this way, but for now will do */
50 #ifndef ERROR_TABLE_BASE_U
51 #define ERROR_TABLE_BASE_U (5376L)
52 #endif /* ubik error base define */
54 /* shouldn't do it this way, but for now will do */
55 #ifndef ERROR_TABLE_BASE_uae
56 #define ERROR_TABLE_BASE_uae (49733376L)
57 #endif /* unified afs error base define */
59 /* same hack for vlserver error base as for ubik error base */
60 #ifndef ERROR_TABLE_BASE_VL
61 #define ERROR_TABLE_BASE_VL (363520L)
62 #define VL_NOENT (363524L)
63 #endif /* vlserver error base define */
66 int afs_BusyWaitPeriod = 15; /* poll every 15 seconds */
68 afs_int32 hm_retry_RO = 0; /* don't wait */
69 afs_int32 hm_retry_RW = 0; /* don't wait */
70 afs_int32 hm_retry_int = 0; /* don't wait */
72 #define VSleep(at) afs_osi_Wait((at)*1000, 0, 0)
77 * 0 if the vldb record for a specific volume is different from what
78 * we have cached -- perhaps the volume has moved.
79 * 1 if the vldb record is the same
80 * 2 if we can't tell if it's the same or not.
82 * If 0, the caller will probably start over at the beginning of our
83 * list of servers for this volume and try to find one that is up. If
84 * not 0, we will probably just keep plugging with what we have
85 * cached. If we fail to contact the VL server, we should just keep
86 * trying with the information we have, rather than failing. */
91 VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
94 struct afs_conn *tconn;
98 struct nvldbentry ntve;
99 struct uvldbentry utve;
103 char *bp, tbuf[CVBS]; /* biggest volume id is 2^32, ~ 4*10^9 */
104 unsigned int changed;
105 struct server *(oldhosts[NMAXNSERVERS]);
107 AFS_STATCNT(CheckVLDB);
108 afs_FinalizeReq(areq);
110 if ((i = afs_InitReq(&treq, afs_osi_credp)))
112 v = afs_osi_Alloc(sizeof(*v));
113 tcell = afs_GetCell(afid->Cell, READ_LOCK);
114 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
116 VSleep(2); /* Better safe than sorry. */
118 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
121 if (tconn->srvr->server->flags & SNO_LHOSTS) {
124 i = VL_GetEntryByNameO(tconn->id, bp, &v->tve);
126 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
129 i = VL_GetEntryByNameN(tconn->id, bp, &v->ntve);
134 i = VL_GetEntryByNameU(tconn->id, bp, &v->utve);
136 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
137 if (i == RXGEN_OPCODE) {
140 i = VL_GetEntryByNameN(tconn->id, bp, &v->ntve);
142 if (i == RXGEN_OPCODE) {
144 tconn->srvr->server->flags |= SNO_LHOSTS;
146 i = VL_GetEntryByNameO(tconn->id, bp, &v->tve);
149 tconn->srvr->server->flags |= SYES_LHOSTS;
151 tconn->srvr->server->flags |= SVLSRV_UUID;
157 } while (afs_Analyze(tconn, i, NULL, &treq, -1, /* no op code for this */
158 SHARED_LOCK, tcell));
160 afs_PutCell(tcell, READ_LOCK);
161 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKVLDB, ICL_TYPE_FID, &afid,
165 afs_osi_Free(v, sizeof(*v));
168 /* have info, copy into serverHost array */
170 tvp = afs_FindVolume(afid, WRITE_LOCK);
172 ObtainWriteLock(&tvp->lock, 107);
173 for (i = 0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) {
174 oldhosts[i] = tvp->serverHost[i];
178 InstallUVolumeEntry(tvp, &v->utve, afid->Cell, tcell, &treq);
179 } else if (type == 1) {
180 InstallNVolumeEntry(tvp, &v->ntve, afid->Cell);
182 InstallVolumeEntry(tvp, &v->tve, afid->Cell);
185 if (i < NMAXNSERVERS && tvp->serverHost[i]) {
188 for (--i; !changed && i >= 0; i--) {
189 if (tvp->serverHost[i] != oldhosts[i]) {
190 changed = 1; /* also happens if prefs change. big deal. */
194 ReleaseWriteLock(&tvp->lock);
195 afs_PutVolume(tvp, WRITE_LOCK);
196 } else { /* can't find volume */
197 tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
199 afs_PutVolume(tvp, WRITE_LOCK);
200 afs_osi_Free(v, sizeof(*v));
203 afs_osi_Free(v, sizeof(*v));
208 afs_osi_Free(v, sizeof(*v));
209 return (changed ? DIFFERENT : SAME);
212 /*------------------------------------------------------------------------
216 * Mark a server as invalid for further attempts of this request only.
219 * areq : The request record associated with this operation.
220 * afid : The FID of the file involved in the action. This argument
221 * may be null if none was involved.
222 * tsp : pointer to a server struct for the server we wish to
226 * Non-zero value if further servers are available to try,
230 * This routine is typically called in situations where we believe
231 * one server out of a pool may have an error condition.
237 * The afs_Conn* routines use the list of invalidated servers to
238 * avoid reusing a server marked as invalid for this request.
239 *------------------------------------------------------------------------*/
241 afs_BlackListOnce(struct vrequest *areq, struct VenusFid *afid,
246 afs_int32 serversleft = 0;
249 tvp = afs_FindVolume(afid, READ_LOCK);
251 for (i = 0; i < AFS_MAXHOSTS; i++) {
252 if (tvp->serverHost[i] == tsp) {
253 areq->skipserver[i] = 1;
255 if (tvp->serverHost[i] &&
256 (tvp->serverHost[i]->addr->sa_flags &
258 areq->skipserver[i] = 1;
261 afs_PutVolume(tvp, READ_LOCK);
262 for (i = 0; i < AFS_MAXHOSTS; i++) {
263 if (tvp->serverHost[i] && areq->skipserver[i] == 0) {
275 /*------------------------------------------------------------------------
276 * EXPORTED afs_Analyze
279 * Analyze the outcome of an RPC operation, taking whatever support
280 * actions are necessary.
283 * aconn : Ptr to the relevant connection on which the call was made.
284 * acode : The return code experienced by the RPC.
285 * afid : The FID of the file involved in the action. This argument
286 * may be null if none was involved.
287 * areq : The request record associated with this operation.
288 * op : which RPC we are analyzing.
289 * cellp : pointer to a cell struct. Must provide either fid or cell.
292 * Non-zero value if the related RPC operation should be retried,
296 * This routine is typically called in a do-while loop, causing the
297 * embedded RPC operation to be called repeatedly if appropriate
298 * until whatever error condition (if any) is intolerable.
304 * The retry return value is used by afs_StoreAllSegments to determine
305 * if this is a temporary or permanent error.
306 *------------------------------------------------------------------------*/
308 afs_Analyze(register struct afs_conn *aconn, afs_int32 acode,
309 struct VenusFid *afid, register struct vrequest *areq, int op,
310 afs_int32 locktype, struct cell *cellp)
315 struct volume *tvp = NULL;
316 afs_int32 shouldRetry = 0;
317 afs_int32 serversleft = 1;
318 struct afs_stats_RPCErrors *aerrP;
319 afs_int32 markeddown;
323 if (AFS_IS_DISCONNECTED && !AFS_IN_SYNC) {
324 /* On reconnection, act as connected. XXX: for now.... */
325 /* SXW - This may get very tired after a while. We should try and
326 * intercept all RPCs before they get here ... */
327 /*printf("afs_Analyze: disconnected\n");*/
328 afs_FinalizeReq(areq);
330 /* SXW - I suspect that this will _never_ happen - we shouldn't
331 * get a connection because we're disconnected !!!*/
332 afs_PutConn(aconn, locktype);
337 AFS_STATCNT(afs_Analyze);
338 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
339 ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
342 aerrP = (struct afs_stats_RPCErrors *)0;
344 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
345 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
347 afs_FinalizeReq(areq);
348 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
350 tvp = afs_FindVolume(afid, READ_LOCK);
352 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
353 (afid ? afid->Fid.Volume : 0),
354 (tvp->name ? tvp->name : ""),
356 && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
357 cell->cellName : ""));
359 for (i = 0; i < AFS_MAXHOSTS; i++) {
360 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
361 tvp->status[i] = not_busy;
363 if (tvp->status[i] == not_busy)
366 afs_PutVolume(tvp, READ_LOCK);
368 afs_warnuser("afs: Waiting for busy volume %u\n",
369 (afid ? afid->Fid.Volume : 0));
372 if (areq->busyCount > 100) {
374 (aerrP->err_Volume)++;
375 areq->volumeError = VOLBUSY;
378 VSleep(afs_BusyWaitPeriod); /* poll periodically */
380 if (shouldRetry != 0)
383 return shouldRetry; /* should retry */
386 if (!aconn || !aconn->srvr) {
387 if (!areq->volumeError) {
389 (aerrP->err_Network)++;
390 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
391 ((afid && afs_IsPrimaryCellNum(afid->Cell))
392 || (cellp && afs_IsPrimaryCell(cellp)))) {
395 ("afs: hard-mount waiting for a vlserver to return to service\n");
396 VSleep(hm_retry_int);
397 afs_CheckServers(1, cellp);
400 tvp = afs_FindVolume(afid, READ_LOCK);
401 if (!tvp || (tvp->states & VRO)) {
402 shouldRetry = hm_retry_RO;
404 shouldRetry = hm_retry_RW;
407 afs_PutVolume(tvp, READ_LOCK);
410 ("afs: hard-mount waiting for volume %u\n",
412 VSleep(hm_retry_int);
413 afs_CheckServers(1, cellp);
416 } /* if (hm_retry_int ... */
418 areq->networkError = 1;
424 /* Find server associated with this connection. */
428 /* Before we do anything with acode, make sure we translate it back to
430 if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
431 acode = et_to_sys_error(acode);
434 /* If we previously took an error, mark this volume not busy */
435 if (areq->volumeError) {
436 tvp = afs_FindVolume(afid, READ_LOCK);
438 for (i = 0; i < AFS_MAXHOSTS; i++) {
439 if (tvp->serverHost[i] == tsp) {
440 tvp->status[i] = not_busy;
443 afs_PutVolume(tvp, READ_LOCK);
447 afs_PutConn(aconn, locktype);
451 /* If network troubles, mark server as having bogued out again. */
452 /* VRESTARTING is < 0 because of backward compatibility issues
453 * with 3.4 file servers and older cache managers */
454 #ifdef AFS_64BIT_CLIENT
457 #endif /* AFS_64BIT_CLIENT */
458 if ((acode < 0) && (acode != VRESTARTING)) {
459 if (acode == RX_CALL_TIMEOUT) {
460 serversleft = afs_BlackListOnce(areq, afid, tsp);
462 tvp = afs_FindVolume(afid, READ_LOCK);
463 if (!afid || !tvp || (tvp->states & VRO))
465 if ((serversleft == 0) && tvp &&
466 ((tvp->states & VRO) || (tvp->states & VBackup))) {
472 afs_PutVolume(tvp, READ_LOCK);
473 /* By doing this, we avoid ever marking a server down
474 * in an idle timeout case. That's because the server is
475 * still responding and may only be letting a single vnode
476 * time out. We otherwise risk having the server continually
477 * be marked down, then up, then down again...
481 markeddown = afs_ServerDown(sa);
482 ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
484 (aerrP->err_Server)++;
486 /* retry *once* when the server is timed out in case of NAT */
487 if (markeddown && acode == RX_CALL_DEAD) {
488 aconn->forceConnectFS = 1;
494 if (acode == VBUSY || acode == VRESTARTING) {
495 if (acode == VBUSY) {
498 (aerrP->err_VolumeBusies)++;
502 tvp = afs_FindVolume(afid, READ_LOCK);
504 for (i = 0; i < AFS_MAXHOSTS; i++) {
505 if (tvp->serverHost[i] == tsp) {
506 tvp->status[i] = rdwr_busy; /* can't tell which yet */
507 /* to tell which, have to look at the op code. */
510 afs_PutVolume(tvp, READ_LOCK);
512 afs_warnuser("afs: Waiting for busy volume %u in cell %s\n",
513 (afid ? afid->Fid.Volume : 0), tsp->cell->cellName);
514 VSleep(afs_BusyWaitPeriod); /* poll periodically */
518 } else if (acode == VICETOKENDEAD
519 || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
520 /* any rxkad error is treated as token expiration */
523 * I'm calling these errors protection errors, since they involve
524 * faulty authentication.
527 (aerrP->err_Protection)++;
529 tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
531 if (acode == VICETOKENDEAD) {
532 aconn->forceConnectFS = 1;
533 } else if (acode == RXKADEXPIRED) {
534 aconn->forceConnectFS = 0; /* don't check until new tokens set */
535 aconn->user->states |= UTokensBad;
536 afs_NotifyUser(tu, UTokensDropped);
538 ("afs: Tokens for user of AFS id %d for cell %s have expired\n",
539 tu->vid, aconn->srvr->server->cell->cellName);
541 serversleft = afs_BlackListOnce(areq, afid, tsp);
546 ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d\n",
547 tu->vid, aconn->srvr->server->cell->cellName, acode);
550 areq->tokenError = 0;
551 aconn->forceConnectFS = 0; /* don't check until new tokens set */
552 aconn->user->states |= UTokensBad;
553 afs_NotifyUser(tu, UTokensDropped);
555 ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d)\n",
556 tu->vid, aconn->srvr->server->cell->cellName, acode);
559 afs_PutUser(tu, READ_LOCK);
561 /* The else case shouldn't be possible and should probably be replaced by a panic? */
562 if (acode == VICETOKENDEAD) {
563 aconn->forceConnectFS = 1;
564 } else if (acode == RXKADEXPIRED) {
565 aconn->forceConnectFS = 0; /* don't check until new tokens set */
566 aconn->user->states |= UTokensBad;
567 afs_NotifyUser(tu, UTokensDropped);
569 ("afs: Tokens for user %d for cell %s have expired\n",
570 areq->uid, aconn->srvr->server->cell->cellName);
572 aconn->forceConnectFS = 0; /* don't check until new tokens set */
573 aconn->user->states |= UTokensBad;
574 afs_NotifyUser(tu, UTokensDropped);
576 ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d)\n",
577 areq->uid, aconn->srvr->server->cell->cellName, acode);
580 shouldRetry = 1; /* Try again (as root). */
582 /* Check for access violation. */
583 else if (acode == EACCES) {
584 /* should mark access error in non-existent per-user global structure */
586 (aerrP->err_Protection)++;
587 areq->accessError = 1;
588 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
589 areq->permWriteError = 1;
592 /* check for ubik errors; treat them like crashed servers */
593 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
596 (aerrP->err_Server)++;
597 shouldRetry = 1; /* retryable (maybe one is working) */
598 VSleep(1); /* just in case */
600 /* Check for bad volume data base / missing volume. */
601 else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
602 || acode == VNOSERVICE || acode == VMOVED) {
607 areq->volumeError = VOLMISSING;
609 (aerrP->err_Volume)++;
610 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
611 same = VLDB_Same(afid, areq);
612 tvp = afs_FindVolume(afid, READ_LOCK);
614 for (i = 0; i < AFS_MAXHOSTS && tvp->serverHost[i]; i++) {
615 if (tvp->serverHost[i] == tsp) {
616 if (tvp->status[i] == end_not_busy)
617 tvp->status[i] = offline;
621 tvp->status[i] = not_busy; /* reset the others */
624 afs_PutVolume(tvp, READ_LOCK);
627 } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) { /* vlserver errors */
629 areq->volumeError = VOLMISSING;
630 } else if (acode >= 0) {
632 (aerrP->err_Other)++;
633 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
634 areq->permWriteError = 1;
635 shouldRetry = 0; /* Other random Vice error. */
636 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
637 VSleep(1); /* Just a hack for desperate times. */
639 (aerrP->err_Other)++;
640 shouldRetry = 1; /* packet was too big, please retry call */
643 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
644 /* If we get here, code < 0 and we have network/Server troubles.
645 * areq->networkError is not set here, since we always
646 * retry in case there is another server. However, if we find
647 * no connection (aconn == 0) we set the networkError flag.
649 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
651 (aerrP->err_Server)++;
652 VSleep(1); /* Just a hack for desperate times. */
656 /* now unlock the connection and return */
657 afs_PutConn(aconn, locktype);
658 return (shouldRetry);