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);
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, struct rx_connection *rxconn,
309 afs_int32 acode, struct VenusFid *afid, struct vrequest *areq,
310 int op, 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;
321 if (AFS_IS_DISCONNECTED && !AFS_IN_SYNC) {
322 /* On reconnection, act as connected. XXX: for now.... */
323 /* SXW - This may get very tired after a while. We should try and
324 * intercept all RPCs before they get here ... */
325 /*printf("afs_Analyze: disconnected\n");*/
326 afs_FinalizeReq(areq);
328 /* SXW - I suspect that this will _never_ happen - we shouldn't
329 * get a connection because we're disconnected !!!*/
330 afs_PutConn(aconn, rxconn, locktype);
335 AFS_STATCNT(afs_Analyze);
336 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
337 ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
340 aerrP = (struct afs_stats_RPCErrors *)0;
342 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
343 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
345 afs_FinalizeReq(areq);
346 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
348 tvp = afs_FindVolume(afid, READ_LOCK);
350 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
351 (afid ? afid->Fid.Volume : 0),
352 (tvp->name ? tvp->name : ""),
354 && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
355 cell->cellName : ""));
357 for (i = 0; i < AFS_MAXHOSTS; i++) {
358 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
359 tvp->status[i] = not_busy;
361 if (tvp->status[i] == not_busy)
364 afs_PutVolume(tvp, READ_LOCK);
366 afs_warnuser("afs: Waiting for busy volume %u\n",
367 (afid ? afid->Fid.Volume : 0));
370 if (areq->busyCount > 100) {
372 (aerrP->err_Volume)++;
373 areq->volumeError = VOLBUSY;
376 VSleep(afs_BusyWaitPeriod); /* poll periodically */
378 if (shouldRetry != 0)
381 return shouldRetry; /* should retry */
384 if (!aconn || !aconn->parent->srvr) {
385 if (!areq->volumeError) {
387 (aerrP->err_Network)++;
388 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
389 ((afid && afs_IsPrimaryCellNum(afid->Cell))
390 || (cellp && afs_IsPrimaryCell(cellp)))) {
392 static int afs_vl_hm = 0;
395 afs_vl_hm = warn = 1;
399 ("afs: hard-mount waiting for a vlserver to return to service\n");
401 VSleep(hm_retry_int);
402 afs_CheckServers(1, cellp);
409 static int afs_unknown_vhm = 0;
410 int warn = 0, vp_vhm = 0;
412 tvp = afs_FindVolume(afid, READ_LOCK);
413 if (!tvp || (tvp->states & VRO)) {
414 shouldRetry = hm_retry_RO;
416 shouldRetry = hm_retry_RW;
419 /* Set 'warn' if we should afs_warnuser. Only let one
420 * caller call afs_warnuser per hm_retry_int interval per
424 if (!(tvp->states & VHardMount)) {
425 tvp->states |= VHardMount;
429 if (!afs_unknown_vhm) {
437 afs_PutVolume(tvp, READ_LOCK);
442 ("afs: hard-mount waiting for volume %u\n",
446 VSleep(hm_retry_int);
447 afs_CheckServers(1, cellp);
448 /* clear the black listed servers on this request. */
449 memset(areq->skipserver, 0, sizeof(areq->skipserver));
452 tvp = afs_FindVolume(afid, READ_LOCK);
454 tvp->states &= ~VHardMount;
455 afs_PutVolume(tvp, READ_LOCK);
462 } /* if (hm_retry_int ... */
464 if (acode == RX_MSGSIZE)
467 areq->networkError = 1;
473 /* Find server associated with this connection. */
474 sa = aconn->parent->srvr;
476 address = ntohl(sa->sa_ip);
478 /* Before we do anything with acode, make sure we translate it back to
480 if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
481 acode = et_to_sys_error(acode);
484 /* If we previously took an error, mark this volume not busy */
485 if (areq->volumeError) {
486 tvp = afs_FindVolume(afid, READ_LOCK);
488 for (i = 0; i < AFS_MAXHOSTS; i++) {
489 if (tvp->serverHost[i] == tsp) {
490 tvp->status[i] = not_busy;
493 afs_PutVolume(tvp, READ_LOCK);
497 afs_PutConn(aconn, rxconn, locktype);
501 /* If network troubles, mark server as having bogued out again. */
502 /* VRESTARTING is < 0 because of backward compatibility issues
503 * with 3.4 file servers and older cache managers */
504 #ifdef AFS_64BIT_CLIENT
507 #endif /* AFS_64BIT_CLIENT */
508 if ((acode < 0) && (acode != VRESTARTING)) {
509 if (acode == RX_MSGSIZE) {
513 if (acode == RX_CALL_TIMEOUT) {
514 serversleft = afs_BlackListOnce(areq, afid, tsp);
516 tvp = afs_FindVolume(afid, READ_LOCK);
517 if (!afid || !tvp || (tvp->states & VRO))
519 if ((serversleft == 0) && tvp &&
520 ((tvp->states & VRO) || (tvp->states & VBackup))) {
526 afs_PutVolume(tvp, READ_LOCK);
527 /* By doing this, we avoid ever marking a server down
528 * in an idle timeout case. That's because the server is
529 * still responding and may only be letting a single vnode
530 * time out. We otherwise risk having the server continually
531 * be marked down, then up, then down again...
535 afs_ServerDown(sa, acode);
536 ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
538 (aerrP->err_Server)++;
541 if (acode == VBUSY || acode == VRESTARTING) {
542 if (acode == VBUSY) {
545 (aerrP->err_VolumeBusies)++;
549 tvp = afs_FindVolume(afid, READ_LOCK);
551 for (i = 0; i < AFS_MAXHOSTS; i++) {
552 if (tvp->serverHost[i] == tsp) {
553 tvp->status[i] = rdwr_busy; /* can't tell which yet */
554 /* to tell which, have to look at the op code. */
557 afs_PutVolume(tvp, READ_LOCK);
559 afs_warnuser("afs: Waiting for busy volume %u in cell %s (server %d.%d.%d.%d)\n",
560 (afid ? afid->Fid.Volume : 0), tsp->cell->cellName,
561 (address >> 24), (address >> 16) & 0xff,
562 (address >> 8) & 0xff, (address) & 0xff);
563 VSleep(afs_BusyWaitPeriod); /* poll periodically */
567 } else if (acode == VICETOKENDEAD
568 || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
569 /* any rxkad error is treated as token expiration */
572 * I'm calling these errors protection errors, since they involve
573 * faulty authentication.
576 (aerrP->err_Protection)++;
578 tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
580 if (acode == VICETOKENDEAD) {
581 aconn->forceConnectFS = 1;
582 } else if (acode == RXKADEXPIRED) {
583 aconn->forceConnectFS = 0; /* don't check until new tokens set */
584 aconn->parent->user->states |= UTokensBad;
585 afs_NotifyUser(tu, UTokensDropped);
587 ("afs: Tokens for user of AFS id %d for cell %s have expired (server %d.%d.%d.%d)\n",
588 tu->viceId, aconn->parent->srvr->server->cell->cellName,
589 (address >> 24), (address >> 16) & 0xff,
590 (address >> 8) & 0xff, (address) & 0xff);
592 serversleft = afs_BlackListOnce(areq, afid, tsp);
597 ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d (server %d.%d.%d.%d)\n",
598 tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
599 (address >> 24), (address >> 16) & 0xff,
600 (address >> 8) & 0xff, (address) & 0xff);
603 areq->tokenError = 0;
604 aconn->forceConnectFS = 0; /* don't check until new tokens set */
605 aconn->parent->user->states |= UTokensBad;
606 afs_NotifyUser(tu, UTokensDropped);
608 ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d, server %d.%d.%d.%d)\n",
609 tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
610 (address >> 24), (address >> 16) & 0xff,
611 (address >> 8) & 0xff, (address) & 0xff);
614 afs_PutUser(tu, READ_LOCK);
616 /* The else case shouldn't be possible and should probably be replaced by a panic? */
617 if (acode == VICETOKENDEAD) {
618 aconn->forceConnectFS = 1;
619 } else if (acode == RXKADEXPIRED) {
620 aconn->forceConnectFS = 0; /* don't check until new tokens set */
621 aconn->parent->user->states |= UTokensBad;
622 afs_NotifyUser(tu, UTokensDropped);
624 ("afs: Tokens for user %d for cell %s have expired (server %d.%d.%d.%d)\n",
625 areq->uid, aconn->parent->srvr->server->cell->cellName,
626 (address >> 24), (address >> 16) & 0xff,
627 (address >> 8) & 0xff, (address) & 0xff);
629 aconn->forceConnectFS = 0; /* don't check until new tokens set */
630 aconn->parent->user->states |= UTokensBad;
631 afs_NotifyUser(tu, UTokensDropped);
633 ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d, server %d.%d.%d.%d)\n",
634 areq->uid, aconn->parent->srvr->server->cell->cellName,
636 (address >> 24), (address >> 16) & 0xff,
637 (address >> 8) & 0xff, (address) & 0xff);
641 shouldRetry = 1; /* Try again (as root). */
643 /* Check for access violation. */
644 else if (acode == EACCES) {
645 /* should mark access error in non-existent per-user global structure */
647 (aerrP->err_Protection)++;
648 areq->accessError = 1;
649 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
650 areq->permWriteError = 1;
653 /* check for ubik errors; treat them like crashed servers */
654 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
655 afs_ServerDown(sa, acode);
657 (aerrP->err_Server)++;
658 shouldRetry = 1; /* retryable (maybe one is working) */
659 VSleep(1); /* just in case */
661 /* Check for bad volume data base / missing volume. */
662 else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
663 || acode == VNOSERVICE || acode == VMOVED) {
668 areq->volumeError = VOLMISSING;
670 (aerrP->err_Volume)++;
671 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
672 same = VLDB_Same(afid, areq);
673 tvp = afs_FindVolume(afid, READ_LOCK);
675 for (i = 0; i < AFS_MAXHOSTS && tvp->serverHost[i]; i++) {
676 if (tvp->serverHost[i] == tsp) {
677 if (tvp->status[i] == end_not_busy)
678 tvp->status[i] = offline;
682 tvp->status[i] = not_busy; /* reset the others */
685 afs_PutVolume(tvp, READ_LOCK);
688 } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) { /* vlserver errors */
690 areq->volumeError = VOLMISSING;
691 } else if (acode >= 0) {
693 (aerrP->err_Other)++;
694 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
695 areq->permWriteError = 1;
696 shouldRetry = 0; /* Other random Vice error. */
697 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
699 ("afs: Path MTU may have been exceeded, retrying (server %d.%d.%d.%d)\n",
700 (address >> 24), (address >> 16) & 0xff,
701 (address >> 8) & 0xff, (address) & 0xff);
703 VSleep(1); /* Just a hack for desperate times. */
705 (aerrP->err_Other)++;
706 shouldRetry = 1; /* packet was too big, please retry call */
709 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
710 /* If we get here, code < 0 and we have network/Server troubles.
711 * areq->networkError is not set here, since we always
712 * retry in case there is another server. However, if we find
713 * no connection (aconn == 0) we set the networkError flag.
715 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
717 (aerrP->err_Server)++;
718 VSleep(1); /* Just a hack for desperate times. */
722 /* now unlock the connection and return */
723 afs_PutConn(aconn, rxconn, locktype);
724 return (shouldRetry);