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(struct afs_conn *aconn, afs_int32 acode,
309 struct VenusFid *afid, 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;
322 if (AFS_IS_DISCONNECTED && !AFS_IN_SYNC) {
323 /* On reconnection, act as connected. XXX: for now.... */
324 /* SXW - This may get very tired after a while. We should try and
325 * intercept all RPCs before they get here ... */
326 /*printf("afs_Analyze: disconnected\n");*/
327 afs_FinalizeReq(areq);
329 /* SXW - I suspect that this will _never_ happen - we shouldn't
330 * get a connection because we're disconnected !!!*/
331 afs_PutConn(aconn, locktype);
336 AFS_STATCNT(afs_Analyze);
337 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
338 ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
341 aerrP = (struct afs_stats_RPCErrors *)0;
343 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
344 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
346 afs_FinalizeReq(areq);
347 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
349 tvp = afs_FindVolume(afid, READ_LOCK);
351 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
352 (afid ? afid->Fid.Volume : 0),
353 (tvp->name ? tvp->name : ""),
355 && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
356 cell->cellName : ""));
358 for (i = 0; i < AFS_MAXHOSTS; i++) {
359 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
360 tvp->status[i] = not_busy;
362 if (tvp->status[i] == not_busy)
365 afs_PutVolume(tvp, READ_LOCK);
367 afs_warnuser("afs: Waiting for busy volume %u\n",
368 (afid ? afid->Fid.Volume : 0));
371 if (areq->busyCount > 100) {
373 (aerrP->err_Volume)++;
374 areq->volumeError = VOLBUSY;
377 VSleep(afs_BusyWaitPeriod); /* poll periodically */
379 if (shouldRetry != 0)
382 return shouldRetry; /* should retry */
385 if (!aconn || !aconn->srvr) {
386 if (!areq->volumeError) {
388 (aerrP->err_Network)++;
389 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
390 ((afid && afs_IsPrimaryCellNum(afid->Cell))
391 || (cellp && afs_IsPrimaryCell(cellp)))) {
394 ("afs: hard-mount waiting for a vlserver to return to service\n");
395 VSleep(hm_retry_int);
396 afs_CheckServers(1, cellp);
399 tvp = afs_FindVolume(afid, READ_LOCK);
400 if (!tvp || (tvp->states & VRO)) {
401 shouldRetry = hm_retry_RO;
403 shouldRetry = hm_retry_RW;
406 afs_PutVolume(tvp, READ_LOCK);
409 ("afs: hard-mount waiting for volume %u\n",
411 VSleep(hm_retry_int);
412 afs_CheckServers(1, cellp);
415 } /* if (hm_retry_int ... */
417 if (acode == RX_MSGSIZE)
420 areq->networkError = 1;
426 /* Find server associated with this connection. */
429 address = ntohl(sa->sa_ip);
431 /* Before we do anything with acode, make sure we translate it back to
433 if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
434 acode = et_to_sys_error(acode);
437 /* If we previously took an error, mark this volume not busy */
438 if (areq->volumeError) {
439 tvp = afs_FindVolume(afid, READ_LOCK);
441 for (i = 0; i < AFS_MAXHOSTS; i++) {
442 if (tvp->serverHost[i] == tsp) {
443 tvp->status[i] = not_busy;
446 afs_PutVolume(tvp, READ_LOCK);
450 afs_PutConn(aconn, locktype);
454 /* If network troubles, mark server as having bogued out again. */
455 /* VRESTARTING is < 0 because of backward compatibility issues
456 * with 3.4 file servers and older cache managers */
457 #ifdef AFS_64BIT_CLIENT
460 #endif /* AFS_64BIT_CLIENT */
461 if ((acode < 0) && (acode != VRESTARTING)) {
462 if (acode == RX_MSGSIZE) {
466 if (acode == RX_CALL_TIMEOUT) {
467 serversleft = afs_BlackListOnce(areq, afid, tsp);
469 tvp = afs_FindVolume(afid, READ_LOCK);
470 if (!afid || !tvp || (tvp->states & VRO))
472 if ((serversleft == 0) && tvp &&
473 ((tvp->states & VRO) || (tvp->states & VBackup))) {
479 afs_PutVolume(tvp, READ_LOCK);
480 /* By doing this, we avoid ever marking a server down
481 * in an idle timeout case. That's because the server is
482 * still responding and may only be letting a single vnode
483 * time out. We otherwise risk having the server continually
484 * be marked down, then up, then down again...
488 markeddown = afs_ServerDown(sa);
489 ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
491 (aerrP->err_Server)++;
493 /* retry *once* when the server is timed out in case of NAT */
494 if (markeddown && acode == RX_CALL_DEAD) {
495 aconn->forceConnectFS = 1;
501 if (acode == VBUSY || acode == VRESTARTING) {
502 if (acode == VBUSY) {
505 (aerrP->err_VolumeBusies)++;
509 tvp = afs_FindVolume(afid, READ_LOCK);
511 for (i = 0; i < AFS_MAXHOSTS; i++) {
512 if (tvp->serverHost[i] == tsp) {
513 tvp->status[i] = rdwr_busy; /* can't tell which yet */
514 /* to tell which, have to look at the op code. */
517 afs_PutVolume(tvp, READ_LOCK);
519 afs_warnuser("afs: Waiting for busy volume %u in cell %s (server %d.%d.%d.%d)\n",
520 (afid ? afid->Fid.Volume : 0), tsp->cell->cellName,
521 (address >> 24), (address >> 16) & 0xff,
522 (address >> 8) & 0xff, (address) & 0xff);
523 VSleep(afs_BusyWaitPeriod); /* poll periodically */
527 } else if (acode == VICETOKENDEAD
528 || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
529 /* any rxkad error is treated as token expiration */
532 * I'm calling these errors protection errors, since they involve
533 * faulty authentication.
536 (aerrP->err_Protection)++;
538 tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
540 if (acode == VICETOKENDEAD) {
541 aconn->forceConnectFS = 1;
542 } else if (acode == RXKADEXPIRED) {
543 aconn->forceConnectFS = 0; /* don't check until new tokens set */
544 aconn->user->states |= UTokensBad;
545 afs_NotifyUser(tu, UTokensDropped);
547 ("afs: Tokens for user of AFS id %d for cell %s have expired (server %d.%d.%d.%d)\n",
548 tu->viceId, aconn->srvr->server->cell->cellName,
549 (address >> 24), (address >> 16) & 0xff,
550 (address >> 8) & 0xff, (address) & 0xff);
552 serversleft = afs_BlackListOnce(areq, afid, tsp);
557 ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d (server %d.%d.%d.%d)\n",
558 tu->viceId, aconn->srvr->server->cell->cellName, acode,
559 (address >> 24), (address >> 16) & 0xff,
560 (address >> 8) & 0xff, (address) & 0xff);
563 areq->tokenError = 0;
564 aconn->forceConnectFS = 0; /* don't check until new tokens set */
565 aconn->user->states |= UTokensBad;
566 afs_NotifyUser(tu, UTokensDropped);
568 ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d, server %d.%d.%d.%d)\n",
569 tu->viceId, aconn->srvr->server->cell->cellName, acode,
570 (address >> 24), (address >> 16) & 0xff,
571 (address >> 8) & 0xff, (address) & 0xff);
574 afs_PutUser(tu, READ_LOCK);
576 /* The else case shouldn't be possible and should probably be replaced by a panic? */
577 if (acode == VICETOKENDEAD) {
578 aconn->forceConnectFS = 1;
579 } else if (acode == RXKADEXPIRED) {
580 aconn->forceConnectFS = 0; /* don't check until new tokens set */
581 aconn->user->states |= UTokensBad;
582 afs_NotifyUser(tu, UTokensDropped);
584 ("afs: Tokens for user %d for cell %s have expired (server %d.%d.%d.%d)\n",
585 areq->uid, aconn->srvr->server->cell->cellName,
586 (address >> 24), (address >> 16) & 0xff,
587 (address >> 8) & 0xff, (address) & 0xff);
589 aconn->forceConnectFS = 0; /* don't check until new tokens set */
590 aconn->user->states |= UTokensBad;
591 afs_NotifyUser(tu, UTokensDropped);
593 ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d, server %d.%d.%d.%d)\n",
594 areq->uid, aconn->srvr->server->cell->cellName, acode,
595 (address >> 24), (address >> 16) & 0xff,
596 (address >> 8) & 0xff, (address) & 0xff);
600 shouldRetry = 1; /* Try again (as root). */
602 /* Check for access violation. */
603 else if (acode == EACCES) {
604 /* should mark access error in non-existent per-user global structure */
606 (aerrP->err_Protection)++;
607 areq->accessError = 1;
608 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
609 areq->permWriteError = 1;
612 /* check for ubik errors; treat them like crashed servers */
613 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
616 (aerrP->err_Server)++;
617 shouldRetry = 1; /* retryable (maybe one is working) */
618 VSleep(1); /* just in case */
620 /* Check for bad volume data base / missing volume. */
621 else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
622 || acode == VNOSERVICE || acode == VMOVED) {
627 areq->volumeError = VOLMISSING;
629 (aerrP->err_Volume)++;
630 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
631 same = VLDB_Same(afid, areq);
632 tvp = afs_FindVolume(afid, READ_LOCK);
634 for (i = 0; i < AFS_MAXHOSTS && tvp->serverHost[i]; i++) {
635 if (tvp->serverHost[i] == tsp) {
636 if (tvp->status[i] == end_not_busy)
637 tvp->status[i] = offline;
641 tvp->status[i] = not_busy; /* reset the others */
644 afs_PutVolume(tvp, READ_LOCK);
647 } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) { /* vlserver errors */
649 areq->volumeError = VOLMISSING;
650 } else if (acode >= 0) {
652 (aerrP->err_Other)++;
653 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
654 areq->permWriteError = 1;
655 shouldRetry = 0; /* Other random Vice error. */
656 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
658 ("afs: Path MTU may have been exceeded, retrying (server %d.%d.%d.%d)\n",
659 (address >> 24), (address >> 16) & 0xff,
660 (address >> 8) & 0xff, (address) & 0xff);
662 VSleep(1); /* Just a hack for desperate times. */
664 (aerrP->err_Other)++;
665 shouldRetry = 1; /* packet was too big, please retry call */
668 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
669 /* If we get here, code < 0 and we have network/Server troubles.
670 * areq->networkError is not set here, since we always
671 * retry in case there is another server. However, if we find
672 * no connection (aconn == 0) we set the networkError flag.
674 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
676 (aerrP->err_Server)++;
677 VSleep(1); /* Just a hack for desperate times. */
681 /* now unlock the connection and return */
682 afs_PutConn(aconn, locktype);
683 return (shouldRetry);