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"
20 #include "afs/sysincludes.h" /* Standard vendor system headers */
23 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
25 #include <netinet/in.h>
29 #include "h/hashing.h"
31 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV) && !defined(AFS_DARWIN60_ENV)
32 #include <netinet/in_var.h>
36 #include "afsincludes.h" /* Afs-based standard headers */
37 #include "afs/afs_stats.h" /* afs statistics */
38 #include "afs/afs_util.h"
39 #include "afs/unified_afs.h"
41 #if defined(AFS_SUN56_ENV)
43 #include <inet/common.h>
44 #if defined(AFS_SUN58_ENV)
45 #include <netinet/ip6.h>
51 /* shouldn't do it this way, but for now will do */
52 #ifndef ERROR_TABLE_BASE_U
53 #define ERROR_TABLE_BASE_U (5376L)
54 #endif /* ubik error base define */
56 /* shouldn't do it this way, but for now will do */
57 #ifndef ERROR_TABLE_BASE_uae
58 #define ERROR_TABLE_BASE_uae (49733376L)
59 #endif /* unified afs error base define */
61 /* same hack for vlserver error base as for ubik error base */
62 #ifndef ERROR_TABLE_BASE_VL
63 #define ERROR_TABLE_BASE_VL (363520L)
64 #define VL_NOENT (363524L)
65 #endif /* vlserver error base define */
68 int afs_BusyWaitPeriod = 15; /* poll every 15 seconds */
70 afs_int32 hm_retry_RO = 0; /* don't wait */
71 afs_int32 hm_retry_RW = 0; /* don't wait */
72 afs_int32 hm_retry_int = 0; /* don't wait */
74 #define VSleep(at) afs_osi_Wait((at)*1000, 0, 0)
79 * 0 if the vldb record for a specific volume is different from what
80 * we have cached -- perhaps the volume has moved.
81 * 1 if the vldb record is the same
82 * 2 if we can't tell if it's the same or not.
84 * If 0, the caller will probably start over at the beginning of our
85 * list of servers for this volume and try to find one that is up. If
86 * not 0, we will probably just keep plugging with what we have
87 * cached. If we fail to contact the VL server, we should just keep
88 * trying with the information we have, rather than failing. */
93 VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
100 struct nvldbentry ntve;
101 struct uvldbentry utve;
105 char *bp, tbuf[CVBS]; /* biggest volume id is 2^32, ~ 4*10^9 */
106 unsigned int changed;
107 struct server *(oldhosts[NMAXNSERVERS]);
109 AFS_STATCNT(CheckVLDB);
110 afs_FinalizeReq(areq);
112 if ((i = afs_InitReq(&treq, afs_osi_credp)))
114 v = afs_osi_Alloc(sizeof(*v));
115 tcell = afs_GetCell(afid->Cell, READ_LOCK);
116 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
118 VSleep(2); /* Better safe than sorry. */
120 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
123 if (tconn->srvr->server->flags & SNO_LHOSTS) {
126 i = VL_GetEntryByNameO(tconn->id, bp, &v->tve);
128 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
131 i = VL_GetEntryByNameN(tconn->id, bp, &v->ntve);
136 i = VL_GetEntryByNameU(tconn->id, bp, &v->utve);
138 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
139 if (i == RXGEN_OPCODE) {
142 i = VL_GetEntryByNameN(tconn->id, bp, &v->ntve);
144 if (i == RXGEN_OPCODE) {
146 tconn->srvr->server->flags |= SNO_LHOSTS;
148 i = VL_GetEntryByNameO(tconn->id, bp, &v->tve);
151 tconn->srvr->server->flags |= SYES_LHOSTS;
153 tconn->srvr->server->flags |= SVLSRV_UUID;
159 } while (afs_Analyze(tconn, i, NULL, &treq, -1, /* no op code for this */
160 SHARED_LOCK, tcell));
162 afs_PutCell(tcell, READ_LOCK);
163 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKVLDB, ICL_TYPE_FID, &afid,
167 afs_osi_Free(v, sizeof(*v));
170 /* have info, copy into serverHost array */
172 tvp = afs_FindVolume(afid, WRITE_LOCK);
174 ObtainWriteLock(&tvp->lock, 107);
175 for (i = 0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) {
176 oldhosts[i] = tvp->serverHost[i];
180 InstallUVolumeEntry(tvp, &v->utve, afid->Cell, tcell, &treq);
181 } else if (type == 1) {
182 InstallNVolumeEntry(tvp, &v->ntve, afid->Cell);
184 InstallVolumeEntry(tvp, &v->tve, afid->Cell);
187 if (i < NMAXNSERVERS && tvp->serverHost[i]) {
190 for (--i; !changed && i >= 0; i--) {
191 if (tvp->serverHost[i] != oldhosts[i]) {
192 changed = 1; /* also happens if prefs change. big deal. */
196 ReleaseWriteLock(&tvp->lock);
197 afs_PutVolume(tvp, WRITE_LOCK);
198 } else { /* can't find volume */
199 tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
201 afs_PutVolume(tvp, WRITE_LOCK);
202 afs_osi_Free(v, sizeof(*v));
205 afs_osi_Free(v, sizeof(*v));
210 afs_osi_Free(v, sizeof(*v));
211 return (changed ? DIFFERENT : SAME);
214 /*------------------------------------------------------------------------
218 * Mark a server as invalid for further attempts of this request only.
221 * areq : The request record associated with this operation.
222 * afid : The FID of the file involved in the action. This argument
223 * may be null if none was involved.
224 * tsp : pointer to a server struct for the server we wish to
228 * Non-zero value if further servers are available to try,
232 * This routine is typically called in situations where we believe
233 * one server out of a pool may have an error condition.
239 * The afs_Conn* routines use the list of invalidated servers to
240 * avoid reusing a server marked as invalid for this request.
241 *------------------------------------------------------------------------*/
243 afs_BlackListOnce(struct vrequest *areq, struct VenusFid *afid,
248 afs_int32 serversleft = 0;
251 tvp = afs_FindVolume(afid, READ_LOCK);
253 for (i = 0; i < MAXHOSTS; i++) {
254 if (tvp->serverHost[i] == tsp) {
255 areq->skipserver[i] = 1;
257 if (tvp->serverHost[i] &&
258 (tvp->serverHost[i]->addr->sa_flags &
260 areq->skipserver[i] = 1;
263 afs_PutVolume(tvp, READ_LOCK);
266 for (i = 0; i < MAXHOSTS; i++) {
267 if (areq->skipserver[i] == 0) {
276 /*------------------------------------------------------------------------
277 * EXPORTED afs_Analyze
280 * Analyze the outcome of an RPC operation, taking whatever support
281 * actions are necessary.
284 * aconn : Ptr to the relevant connection on which the call was made.
285 * acode : The return code experienced by the RPC.
286 * afid : The FID of the file involved in the action. This argument
287 * may be null if none was involved.
288 * areq : The request record associated with this operation.
289 * op : which RPC we are analyzing.
290 * cellp : pointer to a cell struct. Must provide either fid or cell.
293 * Non-zero value if the related RPC operation should be retried,
297 * This routine is typically called in a do-while loop, causing the
298 * embedded RPC operation to be called repeatedly if appropriate
299 * until whatever error condition (if any) is intolerable.
305 * The retry return value is used by afs_StoreAllSegments to determine
306 * if this is a temporary or permanent error.
307 *------------------------------------------------------------------------*/
309 afs_Analyze(register struct conn *aconn, afs_int32 acode,
310 struct VenusFid *afid, register struct vrequest *areq, int op,
311 afs_int32 locktype, struct cell *cellp)
317 afs_int32 shouldRetry = 0;
318 afs_int32 serversleft = 1;
319 struct afs_stats_RPCErrors *aerrP;
320 afs_int32 markeddown;
324 if (AFS_IS_DISCONNECTED && !AFS_IN_SYNC) {
325 /* On reconnection, act as connected. XXX: for now.... */
326 /* SXW - This may get very tired after a while. We should try and
327 * intercept all RPCs before they get here ... */
328 /*printf("afs_Analyze: disconnected\n");*/
329 afs_FinalizeReq(areq);
331 /* SXW - I suspect that this will _never_ happen - we shouldn't
332 * get a connection because we're disconnected !!!*/
333 afs_PutConn(aconn, locktype);
338 AFS_STATCNT(afs_Analyze);
339 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
340 ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
343 aerrP = (struct afs_stats_RPCErrors *)0;
345 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
346 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
348 afs_FinalizeReq(areq);
349 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
351 tvp = afs_FindVolume(afid, READ_LOCK);
353 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
354 (afid ? afid->Fid.Volume : 0),
355 (tvp->name ? tvp->name : ""),
357 && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
358 cell->cellName : ""));
360 for (i = 0; i < MAXHOSTS; i++) {
361 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
362 tvp->status[i] = not_busy;
364 if (tvp->status[i] == not_busy)
367 afs_PutVolume(tvp, READ_LOCK);
369 afs_warnuser("afs: Waiting for busy volume %u\n",
370 (afid ? afid->Fid.Volume : 0));
373 if (areq->busyCount > 100) {
375 (aerrP->err_Volume)++;
376 areq->volumeError = VOLBUSY;
379 VSleep(afs_BusyWaitPeriod); /* poll periodically */
381 if (shouldRetry != 0)
384 return shouldRetry; /* should retry */
387 if (!aconn || !aconn->srvr) {
388 if (!areq->volumeError) {
390 (aerrP->err_Network)++;
391 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
392 ((afid && afs_IsPrimaryCellNum(afid->Cell))
393 || (cellp && afs_IsPrimaryCell(cellp)))) {
396 ("afs: hard-mount waiting for a vlserver to return to service\n");
397 VSleep(hm_retry_int);
398 afs_CheckServers(1, cellp);
401 tvp = afs_FindVolume(afid, READ_LOCK);
402 if (!tvp || (tvp->states & VRO)) {
403 shouldRetry = hm_retry_RO;
405 shouldRetry = hm_retry_RW;
408 afs_PutVolume(tvp, READ_LOCK);
411 ("afs: hard-mount waiting for volume %u\n",
413 VSleep(hm_retry_int);
414 afs_CheckServers(1, cellp);
417 } /* if (hm_retry_int ... */
419 areq->networkError = 1;
425 /* Find server associated with this connection. */
429 /* Before we do anything with acode, make sure we translate it back to
431 if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
432 acode = et_to_sys_error(acode);
435 /* If we previously took an error, mark this volume not busy */
436 if (areq->volumeError) {
437 tvp = afs_FindVolume(afid, READ_LOCK);
439 for (i = 0; i < MAXHOSTS; i++) {
440 if (tvp->serverHost[i] == tsp) {
441 tvp->status[i] = not_busy;
444 afs_PutVolume(tvp, READ_LOCK);
448 afs_PutConn(aconn, locktype);
452 /* If network troubles, mark server as having bogued out again. */
453 /* VRESTARTING is < 0 because of backward compatibility issues
454 * with 3.4 file servers and older cache managers */
455 #ifdef AFS_64BIT_CLIENT
458 #endif /* AFS_64BIT_CLIENT */
459 if ((acode < 0) && (acode != VRESTARTING)) {
460 if (acode == RX_CALL_TIMEOUT) {
461 serversleft = afs_BlackListOnce(areq, afid, tsp);
468 /* By doing this, we avoid ever marking a server down
469 * in an idle timeout case. That's because the server is
470 * still responding and may only be letting a single vnode
471 * time out. We otherwise risk having the server continually
472 * be marked down, then up, then down again...
476 markeddown = afs_ServerDown(sa);
477 ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
479 (aerrP->err_Server)++;
481 /* retry *once* when the server is timed out in case of NAT */
482 if (markeddown && acode == RX_CALL_DEAD) {
483 aconn->forceConnectFS = 1;
489 if (acode == VBUSY || acode == VRESTARTING) {
490 if (acode == VBUSY) {
493 (aerrP->err_VolumeBusies)++;
497 tvp = afs_FindVolume(afid, READ_LOCK);
499 for (i = 0; i < MAXHOSTS; i++) {
500 if (tvp->serverHost[i] == tsp) {
501 tvp->status[i] = rdwr_busy; /* can't tell which yet */
502 /* to tell which, have to look at the op code. */
505 afs_PutVolume(tvp, READ_LOCK);
507 afs_warnuser("afs: Waiting for busy volume %u in cell %s\n",
508 (afid ? afid->Fid.Volume : 0), tsp->cell->cellName);
509 VSleep(afs_BusyWaitPeriod); /* poll periodically */
513 } else if (acode == VICETOKENDEAD
514 || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
515 /* any rxkad error is treated as token expiration */
518 * I'm calling these errors protection errors, since they involve
519 * faulty authentication.
522 (aerrP->err_Protection)++;
524 tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
526 if (acode == VICETOKENDEAD) {
527 aconn->forceConnectFS = 1;
528 } else if (acode == RXKADEXPIRED) {
529 aconn->forceConnectFS = 0; /* don't check until new tokens set */
530 aconn->user->states |= UTokensBad;
532 ("afs: Tokens for user of AFS id %d for cell %s have expired\n",
533 tu->vid, aconn->srvr->server->cell->cellName);
535 serversleft = afs_BlackListOnce(areq, afid, tsp);
540 ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d\n",
541 tu->vid, aconn->srvr->server->cell->cellName, acode);
544 areq->tokenError = 0;
545 aconn->forceConnectFS = 0; /* don't check until new tokens set */
546 aconn->user->states |= UTokensBad;
548 ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d)\n",
549 tu->vid, aconn->srvr->server->cell->cellName, acode);
552 afs_PutUser(tu, READ_LOCK);
554 /* The else case shouldn't be possible and should probably be replaced by a panic? */
555 if (acode == VICETOKENDEAD) {
556 aconn->forceConnectFS = 1;
557 } else if (acode == RXKADEXPIRED) {
558 aconn->forceConnectFS = 0; /* don't check until new tokens set */
559 aconn->user->states |= UTokensBad;
561 ("afs: Tokens for user %d for cell %s have expired\n",
562 areq->uid, aconn->srvr->server->cell->cellName);
564 aconn->forceConnectFS = 0; /* don't check until new tokens set */
565 aconn->user->states |= UTokensBad;
567 ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d)\n",
568 areq->uid, aconn->srvr->server->cell->cellName, acode);
571 shouldRetry = 1; /* Try again (as root). */
573 /* Check for access violation. */
574 else if (acode == EACCES) {
575 /* should mark access error in non-existent per-user global structure */
577 (aerrP->err_Protection)++;
578 areq->accessError = 1;
579 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
580 areq->permWriteError = 1;
583 /* check for ubik errors; treat them like crashed servers */
584 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
587 (aerrP->err_Server)++;
588 shouldRetry = 1; /* retryable (maybe one is working) */
589 VSleep(1); /* just in case */
591 /* Check for bad volume data base / missing volume. */
592 else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
593 || acode == VNOSERVICE || acode == VMOVED) {
598 areq->volumeError = VOLMISSING;
600 (aerrP->err_Volume)++;
601 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
602 same = VLDB_Same(afid, areq);
603 tvp = afs_FindVolume(afid, READ_LOCK);
605 for (i = 0; i < MAXHOSTS && tvp->serverHost[i]; i++) {
606 if (tvp->serverHost[i] == tsp) {
607 if (tvp->status[i] == end_not_busy)
608 tvp->status[i] = offline;
612 tvp->status[i] = not_busy; /* reset the others */
615 afs_PutVolume(tvp, READ_LOCK);
618 } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) { /* vlserver errors */
620 areq->volumeError = VOLMISSING;
621 } else if (acode >= 0) {
623 (aerrP->err_Other)++;
624 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
625 areq->permWriteError = 1;
626 shouldRetry = 0; /* Other random Vice error. */
627 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
628 VSleep(1); /* Just a hack for desperate times. */
630 (aerrP->err_Other)++;
631 shouldRetry = 1; /* packet was too big, please retry call */
634 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
635 /* If we get here, code < 0 and we have network/Server troubles.
636 * areq->networkError is not set here, since we always
637 * retry in case there is another server. However, if we find
638 * no connection (aconn == 0) we set the networkError flag.
640 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
642 (aerrP->err_Server)++;
643 VSleep(1); /* Just a hack for desperate times. */
647 /* now unlock the connection and return */
648 afs_PutConn(aconn, locktype);
649 return (shouldRetry);