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_SUN5_ENV)
41 #include <inet/common.h>
42 #include <netinet/ip6.h>
46 /* shouldn't do it this way, but for now will do */
47 #ifndef ERROR_TABLE_BASE_U
48 #define ERROR_TABLE_BASE_U (5376L)
49 #endif /* ubik error base define */
51 /* shouldn't do it this way, but for now will do */
52 #ifndef ERROR_TABLE_BASE_uae
53 #define ERROR_TABLE_BASE_uae (49733376L)
54 #endif /* unified afs error base define */
56 /* same hack for vlserver error base as for ubik error base */
57 #ifndef ERROR_TABLE_BASE_VL
58 #define ERROR_TABLE_BASE_VL (363520L)
59 #define VL_NOENT (363524L)
60 #endif /* vlserver error base define */
63 int afs_BusyWaitPeriod = 15; /* poll every 15 seconds */
65 afs_int32 hm_retry_RO = 0; /* don't wait */
66 afs_int32 hm_retry_RW = 0; /* don't wait */
67 afs_int32 hm_retry_int = 0; /* don't wait */
69 #define VSleep(at) afs_osi_Wait((at)*1000, 0, 0)
74 * 0 if the vldb record for a specific volume is different from what
75 * we have cached -- perhaps the volume has moved.
76 * 1 if the vldb record is the same
77 * 2 if we can't tell if it's the same or not.
79 * If 0, the caller will probably start over at the beginning of our
80 * list of servers for this volume and try to find one that is up. If
81 * not 0, we will probably just keep plugging with what we have
82 * cached. If we fail to contact the VL server, we should just keep
83 * trying with the information we have, rather than failing. */
88 VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
91 struct afs_conn *tconn;
95 struct nvldbentry ntve;
96 struct uvldbentry utve;
100 char *bp, tbuf[CVBS]; /* biggest volume id is 2^32, ~ 4*10^9 */
101 unsigned int changed;
102 struct server *(oldhosts[NMAXNSERVERS]);
103 struct rx_connection *rxconn;
105 AFS_STATCNT(CheckVLDB);
106 afs_FinalizeReq(areq);
108 if ((i = afs_InitReq(&treq, afs_osi_credp)))
110 v = afs_osi_Alloc(sizeof(*v));
111 osi_Assert(v != NULL);
112 tcell = afs_GetCell(afid->Cell, READ_LOCK);
113 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
115 VSleep(2); /* Better safe than sorry. */
117 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
118 &treq, SHARED_LOCK, &rxconn);
120 if ( tconn->parent->srvr->server->flags & SNO_LHOSTS) {
123 i = VL_GetEntryByNameO(rxconn, bp, &v->tve);
125 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
128 i = VL_GetEntryByNameN(rxconn, bp, &v->ntve);
133 i = VL_GetEntryByNameU(rxconn, bp, &v->utve);
135 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
136 if (i == RXGEN_OPCODE) {
139 i = VL_GetEntryByNameN(rxconn, bp, &v->ntve);
141 if (i == RXGEN_OPCODE) {
143 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
145 i = VL_GetEntryByNameO(rxconn, bp, &v->tve);
148 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
150 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
156 } while (afs_Analyze(tconn, rxconn, i, NULL, &treq, -1, /* no op code for this */
157 SHARED_LOCK, tcell));
159 afs_PutCell(tcell, READ_LOCK);
160 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKVLDB, ICL_TYPE_FID, &afid,
164 afs_osi_Free(v, sizeof(*v));
167 /* have info, copy into serverHost array */
169 tvp = afs_FindVolume(afid, WRITE_LOCK);
171 ObtainWriteLock(&tvp->lock, 107);
172 for (i = 0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) {
173 oldhosts[i] = tvp->serverHost[i];
175 ReleaseWriteLock(&tvp->lock);
178 LockAndInstallUVolumeEntry(tvp, &v->utve, afid->Cell, tcell, &treq);
179 } else if (type == 1) {
180 LockAndInstallNVolumeEntry(tvp, &v->ntve, afid->Cell);
182 LockAndInstallVolumeEntry(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 for (i = 0; i < AFS_MAXHOSTS; i++) {
262 if (tvp->serverHost[i] && areq->skipserver[i] == 0) {
267 afs_PutVolume(tvp, READ_LOCK);
274 /*------------------------------------------------------------------------
278 * Analyze the outcome of an RPC operation, taking whatever support
279 * actions are necessary.
282 * afid : The FID of the file involved in the action. This argument
283 * may be null if none was involved.
284 * op : which RPC we are analyzing.
285 * avp : A pointer to the struct volume, if we already have one.
288 * Non-zero value if the related RPC operation can be retried,
292 * This routine is called when we got a network error,
293 * and discards state if the operation was a data-mutating
295 *------------------------------------------------------------------------*/
297 afs_ClearStatus(struct VenusFid *afid, int op, struct volume *avp)
299 struct volume *tvp = NULL;
301 /* if it's not a write op, we have nothing to veto and shouldn't clear. */
302 if (!AFS_STATS_FS_RPCIDXES_ISWRITE(op)) {
309 tvp = afs_FindVolume(afid, READ_LOCK);
311 /* don't assume just discarding will fix if no cached volume */
314 ObtainReadLock(&afs_xvcache);
315 if ((tvc = afs_FindVCache(afid, 0, 0))) {
316 ReleaseReadLock(&afs_xvcache);
317 tvc->f.states &= ~(CStatd | CUnique);
320 ReleaseReadLock(&afs_xvcache);
324 afs_PutVolume(tvp, READ_LOCK);
326 /* not retriable: we may have raced ourselves */
330 /*------------------------------------------------------------------------
331 * EXPORTED afs_Analyze
334 * Analyze the outcome of an RPC operation, taking whatever support
335 * actions are necessary.
338 * aconn : Ptr to the relevant connection on which the call was made.
339 * acode : The return code experienced by the RPC.
340 * afid : The FID of the file involved in the action. This argument
341 * may be null if none was involved.
342 * areq : The request record associated with this operation.
343 * op : which RPC we are analyzing.
344 * cellp : pointer to a cell struct. Must provide either fid or cell.
347 * Non-zero value if the related RPC operation should be retried,
351 * This routine is typically called in a do-while loop, causing the
352 * embedded RPC operation to be called repeatedly if appropriate
353 * until whatever error condition (if any) is intolerable.
359 * The retry return value is used by afs_StoreAllSegments to determine
360 * if this is a temporary or permanent error.
361 *------------------------------------------------------------------------*/
363 afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
364 afs_int32 acode, struct VenusFid *afid, struct vrequest *areq,
365 int op, afs_int32 locktype, struct cell *cellp)
370 struct volume *tvp = NULL;
371 afs_int32 shouldRetry = 0;
372 afs_int32 serversleft = 1;
373 struct afs_stats_RPCErrors *aerrP;
376 if (AFS_IS_DISCONNECTED && !AFS_IN_SYNC) {
377 /* On reconnection, act as connected. XXX: for now.... */
378 /* SXW - This may get very tired after a while. We should try and
379 * intercept all RPCs before they get here ... */
380 /*printf("afs_Analyze: disconnected\n");*/
381 afs_FinalizeReq(areq);
383 /* SXW - I suspect that this will _never_ happen - we shouldn't
384 * get a connection because we're disconnected !!!*/
385 afs_PutConn(aconn, rxconn, locktype);
390 AFS_STATCNT(afs_Analyze);
391 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
392 ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
395 aerrP = (struct afs_stats_RPCErrors *)0;
397 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
398 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
400 afs_FinalizeReq(areq);
401 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
403 tvp = afs_FindVolume(afid, READ_LOCK);
405 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
406 (afid ? afid->Fid.Volume : 0),
407 (tvp->name ? tvp->name : ""),
409 && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
410 cell->cellName : ""));
412 for (i = 0; i < AFS_MAXHOSTS; i++) {
413 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
414 tvp->status[i] = not_busy;
416 if (tvp->status[i] == not_busy)
419 afs_PutVolume(tvp, READ_LOCK);
421 afs_warnuser("afs: Waiting for busy volume %u\n",
422 (afid ? afid->Fid.Volume : 0));
425 if (areq->busyCount > 100) {
427 (aerrP->err_Volume)++;
428 areq->volumeError = VOLBUSY;
431 VSleep(afs_BusyWaitPeriod); /* poll periodically */
433 if (shouldRetry != 0)
436 return shouldRetry; /* should retry */
439 if (!aconn || !aconn->parent->srvr) {
440 if (!areq->volumeError) {
442 (aerrP->err_Network)++;
443 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
444 ((afid && afs_IsPrimaryCellNum(afid->Cell))
445 || (cellp && afs_IsPrimaryCell(cellp)))) {
447 static int afs_vl_hm = 0;
450 afs_vl_hm = warn = 1;
454 ("afs: hard-mount waiting for a vlserver to return to service\n");
456 VSleep(hm_retry_int);
457 afs_CheckServers(1, cellp);
464 static int afs_unknown_vhm = 0;
465 int warn = 0, vp_vhm = 0;
467 tvp = afs_FindVolume(afid, READ_LOCK);
468 if (!tvp || (tvp->states & VRO)) {
469 shouldRetry = hm_retry_RO;
471 shouldRetry = hm_retry_RW;
474 /* Set 'warn' if we should afs_warnuser. Only let one
475 * caller call afs_warnuser per hm_retry_int interval per
479 if (!(tvp->states & VHardMount)) {
480 tvp->states |= VHardMount;
484 if (!afs_unknown_vhm) {
492 afs_PutVolume(tvp, READ_LOCK);
497 ("afs: hard-mount waiting for volume %u\n",
501 VSleep(hm_retry_int);
502 afs_CheckServers(1, cellp);
503 /* clear the black listed servers on this request. */
504 memset(areq->skipserver, 0, sizeof(areq->skipserver));
507 tvp = afs_FindVolume(afid, READ_LOCK);
509 tvp->states &= ~VHardMount;
510 afs_PutVolume(tvp, READ_LOCK);
517 } /* if (hm_retry_int ... */
519 if (acode == RX_MSGSIZE)
522 areq->networkError = 1;
523 /* do not promote to shouldRetry if not already */
524 if (afs_ClearStatus(afid, op, NULL) == 0)
532 /* Find server associated with this connection. */
533 sa = aconn->parent->srvr;
535 address = ntohl(sa->sa_ip);
537 /* Before we do anything with acode, make sure we translate it back to
539 if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
540 acode = et_to_sys_error(acode);
543 /* If we previously took an error, mark this volume not busy */
544 if (areq->volumeError) {
545 tvp = afs_FindVolume(afid, READ_LOCK);
547 for (i = 0; i < AFS_MAXHOSTS; i++) {
548 if (tvp->serverHost[i] == tsp) {
549 tvp->status[i] = not_busy;
552 afs_PutVolume(tvp, READ_LOCK);
556 afs_PutConn(aconn, rxconn, locktype);
560 /* If network troubles, mark server as having bogued out again. */
561 /* VRESTARTING is < 0 because of backward compatibility issues
562 * with 3.4 file servers and older cache managers */
563 #ifdef AFS_64BIT_CLIENT
566 #endif /* AFS_64BIT_CLIENT */
567 if ((acode < 0) && (acode != VRESTARTING)) {
568 if (acode == RX_MSGSIZE) {
572 if (acode == RX_CALL_TIMEOUT) {
573 serversleft = afs_BlackListOnce(areq, afid, tsp);
575 tvp = afs_FindVolume(afid, READ_LOCK);
576 if ((serversleft == 0) && tvp &&
577 ((tvp->states & VRO) || (tvp->states & VBackup))) {
582 if (!afid || !tvp || (tvp->states & VRO))
584 else if (afs_ClearStatus(afid, op, tvp) == 0)
588 afs_PutVolume(tvp, READ_LOCK);
589 /* By doing this, we avoid ever marking a server down
590 * in an idle timeout case. That's because the server is
591 * still responding and may only be letting a single vnode
592 * time out. We otherwise risk having the server continually
593 * be marked down, then up, then down again...
597 afs_ServerDown(sa, acode);
598 ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
600 (aerrP->err_Server)++;
603 if (acode == VBUSY || acode == VRESTARTING) {
604 if (acode == VBUSY) {
607 (aerrP->err_VolumeBusies)++;
611 tvp = afs_FindVolume(afid, READ_LOCK);
613 for (i = 0; i < AFS_MAXHOSTS; i++) {
614 if (tvp->serverHost[i] == tsp) {
615 tvp->status[i] = rdwr_busy; /* can't tell which yet */
616 /* to tell which, have to look at the op code. */
619 afs_PutVolume(tvp, READ_LOCK);
621 afs_warnuser("afs: Waiting for busy volume %u in cell %s (server %d.%d.%d.%d)\n",
622 (afid ? afid->Fid.Volume : 0), tsp->cell->cellName,
623 (address >> 24), (address >> 16) & 0xff,
624 (address >> 8) & 0xff, (address) & 0xff);
625 VSleep(afs_BusyWaitPeriod); /* poll periodically */
629 } else if (acode == VICETOKENDEAD
630 || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
631 /* any rxkad error is treated as token expiration */
634 * I'm calling these errors protection errors, since they involve
635 * faulty authentication.
638 (aerrP->err_Protection)++;
640 tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
642 if (acode == VICETOKENDEAD) {
643 aconn->forceConnectFS = 1;
644 } else if (acode == RXKADEXPIRED) {
645 aconn->forceConnectFS = 0; /* don't check until new tokens set */
646 aconn->parent->user->states |= UTokensBad;
647 afs_NotifyUser(tu, UTokensDropped);
649 ("afs: Tokens for user of AFS id %d for cell %s have expired (server %d.%d.%d.%d)\n",
650 tu->viceId, aconn->parent->srvr->server->cell->cellName,
651 (address >> 24), (address >> 16) & 0xff,
652 (address >> 8) & 0xff, (address) & 0xff);
654 serversleft = afs_BlackListOnce(areq, afid, tsp);
659 ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d (server %d.%d.%d.%d)\n",
660 tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
661 (address >> 24), (address >> 16) & 0xff,
662 (address >> 8) & 0xff, (address) & 0xff);
665 areq->tokenError = 0;
666 aconn->forceConnectFS = 0; /* don't check until new tokens set */
667 aconn->parent->user->states |= UTokensBad;
668 afs_NotifyUser(tu, UTokensDropped);
670 ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d, server %d.%d.%d.%d)\n",
671 tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
672 (address >> 24), (address >> 16) & 0xff,
673 (address >> 8) & 0xff, (address) & 0xff);
676 afs_PutUser(tu, READ_LOCK);
678 /* The else case shouldn't be possible and should probably be replaced by a panic? */
679 if (acode == VICETOKENDEAD) {
680 aconn->forceConnectFS = 1;
681 } else if (acode == RXKADEXPIRED) {
682 aconn->forceConnectFS = 0; /* don't check until new tokens set */
683 aconn->parent->user->states |= UTokensBad;
684 afs_NotifyUser(tu, UTokensDropped);
686 ("afs: Tokens for user %d for cell %s have expired (server %d.%d.%d.%d)\n",
687 areq->uid, aconn->parent->srvr->server->cell->cellName,
688 (address >> 24), (address >> 16) & 0xff,
689 (address >> 8) & 0xff, (address) & 0xff);
691 aconn->forceConnectFS = 0; /* don't check until new tokens set */
692 aconn->parent->user->states |= UTokensBad;
693 afs_NotifyUser(tu, UTokensDropped);
695 ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d, server %d.%d.%d.%d)\n",
696 areq->uid, aconn->parent->srvr->server->cell->cellName,
698 (address >> 24), (address >> 16) & 0xff,
699 (address >> 8) & 0xff, (address) & 0xff);
703 shouldRetry = 1; /* Try again (as root). */
705 /* Check for access violation. */
706 else if (acode == EACCES) {
707 /* should mark access error in non-existent per-user global structure */
709 (aerrP->err_Protection)++;
710 areq->accessError = 1;
711 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
712 areq->permWriteError = 1;
715 /* check for ubik errors; treat them like crashed servers */
716 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
717 afs_ServerDown(sa, acode);
719 (aerrP->err_Server)++;
720 shouldRetry = 1; /* retryable (maybe one is working) */
721 VSleep(1); /* just in case */
723 /* Check for bad volume data base / missing volume. */
724 else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
725 || acode == VNOSERVICE || acode == VMOVED) {
730 areq->volumeError = VOLMISSING;
732 (aerrP->err_Volume)++;
733 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
734 same = VLDB_Same(afid, areq);
735 tvp = afs_FindVolume(afid, READ_LOCK);
737 for (i = 0; i < AFS_MAXHOSTS && tvp->serverHost[i]; i++) {
738 if (tvp->serverHost[i] == tsp) {
739 if (tvp->status[i] == end_not_busy)
740 tvp->status[i] = offline;
744 tvp->status[i] = not_busy; /* reset the others */
747 afs_PutVolume(tvp, READ_LOCK);
750 } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) { /* vlserver errors */
752 areq->volumeError = VOLMISSING;
753 } else if (acode >= 0) {
755 (aerrP->err_Other)++;
756 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
757 areq->permWriteError = 1;
758 shouldRetry = 0; /* Other random Vice error. */
759 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
761 ("afs: Path MTU may have been exceeded, retrying (server %d.%d.%d.%d)\n",
762 (address >> 24), (address >> 16) & 0xff,
763 (address >> 8) & 0xff, (address) & 0xff);
765 VSleep(1); /* Just a hack for desperate times. */
767 (aerrP->err_Other)++;
768 shouldRetry = 1; /* packet was too big, please retry call */
771 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
772 /* If we get here, code < 0 and we have network/Server troubles.
773 * areq->networkError is not set here, since we always
774 * retry in case there is another server. However, if we find
775 * no connection (aconn == 0) we set the networkError flag.
777 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
779 (aerrP->err_Server)++;
780 VSleep(1); /* Just a hack for desperate times. */
784 /* now unlock the connection and return */
785 afs_PutConn(aconn, rxconn, locktype);
786 return (shouldRetry);