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];
177 InstallUVolumeEntry(tvp, &v->utve, afid->Cell, tcell, &treq);
178 } else if (type == 1) {
179 InstallNVolumeEntry(tvp, &v->ntve, afid->Cell);
181 InstallVolumeEntry(tvp, &v->tve, afid->Cell);
184 if (i < NMAXNSERVERS && tvp->serverHost[i]) {
187 for (--i; !changed && i >= 0; i--) {
188 if (tvp->serverHost[i] != oldhosts[i]) {
189 changed = 1; /* also happens if prefs change. big deal. */
193 ReleaseWriteLock(&tvp->lock);
194 afs_PutVolume(tvp, WRITE_LOCK);
195 } else { /* can't find volume */
196 tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
198 afs_PutVolume(tvp, WRITE_LOCK);
199 afs_osi_Free(v, sizeof(*v));
202 afs_osi_Free(v, sizeof(*v));
207 afs_osi_Free(v, sizeof(*v));
208 return (changed ? DIFFERENT : SAME);
211 /*------------------------------------------------------------------------
215 * Mark a server as invalid for further attempts of this request only.
218 * areq : The request record associated with this operation.
219 * afid : The FID of the file involved in the action. This argument
220 * may be null if none was involved.
221 * tsp : pointer to a server struct for the server we wish to
225 * Non-zero value if further servers are available to try,
229 * This routine is typically called in situations where we believe
230 * one server out of a pool may have an error condition.
236 * The afs_Conn* routines use the list of invalidated servers to
237 * avoid reusing a server marked as invalid for this request.
238 *------------------------------------------------------------------------*/
240 afs_BlackListOnce(struct vrequest *areq, struct VenusFid *afid,
245 afs_int32 serversleft = 0;
248 tvp = afs_FindVolume(afid, READ_LOCK);
250 for (i = 0; i < AFS_MAXHOSTS; i++) {
251 if (tvp->serverHost[i] == tsp) {
252 areq->skipserver[i] = 1;
254 if (tvp->serverHost[i] &&
255 (tvp->serverHost[i]->addr->sa_flags &
257 areq->skipserver[i] = 1;
260 afs_PutVolume(tvp, READ_LOCK);
261 for (i = 0; i < AFS_MAXHOSTS; i++) {
262 if (tvp->serverHost[i] && areq->skipserver[i] == 0) {
274 /*------------------------------------------------------------------------
275 * EXPORTED afs_Analyze
278 * Analyze the outcome of an RPC operation, taking whatever support
279 * actions are necessary.
282 * aconn : Ptr to the relevant connection on which the call was made.
283 * acode : The return code experienced by the RPC.
284 * afid : The FID of the file involved in the action. This argument
285 * may be null if none was involved.
286 * areq : The request record associated with this operation.
287 * op : which RPC we are analyzing.
288 * cellp : pointer to a cell struct. Must provide either fid or cell.
291 * Non-zero value if the related RPC operation should be retried,
295 * This routine is typically called in a do-while loop, causing the
296 * embedded RPC operation to be called repeatedly if appropriate
297 * until whatever error condition (if any) is intolerable.
303 * The retry return value is used by afs_StoreAllSegments to determine
304 * if this is a temporary or permanent error.
305 *------------------------------------------------------------------------*/
307 afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
308 afs_int32 acode, struct VenusFid *afid, struct vrequest *areq,
309 int op, afs_int32 locktype, struct cell *cellp)
314 struct volume *tvp = NULL;
315 afs_int32 shouldRetry = 0;
316 afs_int32 serversleft = 1;
317 struct afs_stats_RPCErrors *aerrP;
320 if (AFS_IS_DISCONNECTED && !AFS_IN_SYNC) {
321 /* On reconnection, act as connected. XXX: for now.... */
322 /* SXW - This may get very tired after a while. We should try and
323 * intercept all RPCs before they get here ... */
324 /*printf("afs_Analyze: disconnected\n");*/
325 afs_FinalizeReq(areq);
327 /* SXW - I suspect that this will _never_ happen - we shouldn't
328 * get a connection because we're disconnected !!!*/
329 afs_PutConn(aconn, rxconn, locktype);
334 AFS_STATCNT(afs_Analyze);
335 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
336 ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
339 aerrP = (struct afs_stats_RPCErrors *)0;
341 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
342 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
344 afs_FinalizeReq(areq);
345 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
347 tvp = afs_FindVolume(afid, READ_LOCK);
349 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
350 (afid ? afid->Fid.Volume : 0),
351 (tvp->name ? tvp->name : ""),
353 && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
354 cell->cellName : ""));
356 for (i = 0; i < AFS_MAXHOSTS; i++) {
357 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
358 tvp->status[i] = not_busy;
360 if (tvp->status[i] == not_busy)
363 afs_PutVolume(tvp, READ_LOCK);
365 afs_warnuser("afs: Waiting for busy volume %u\n",
366 (afid ? afid->Fid.Volume : 0));
369 if (areq->busyCount > 100) {
371 (aerrP->err_Volume)++;
372 areq->volumeError = VOLBUSY;
375 VSleep(afs_BusyWaitPeriod); /* poll periodically */
377 if (shouldRetry != 0)
380 return shouldRetry; /* should retry */
383 if (!aconn || !aconn->parent->srvr) {
384 if (!areq->volumeError) {
386 (aerrP->err_Network)++;
387 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
388 ((afid && afs_IsPrimaryCellNum(afid->Cell))
389 || (cellp && afs_IsPrimaryCell(cellp)))) {
391 static int afs_vl_hm = 0;
394 afs_vl_hm = warn = 1;
398 ("afs: hard-mount waiting for a vlserver to return to service\n");
400 VSleep(hm_retry_int);
401 afs_CheckServers(1, cellp);
408 static int afs_unknown_vhm = 0;
409 int warn = 0, vp_vhm = 0;
411 tvp = afs_FindVolume(afid, READ_LOCK);
412 if (!tvp || (tvp->states & VRO)) {
413 shouldRetry = hm_retry_RO;
415 shouldRetry = hm_retry_RW;
418 /* Set 'warn' if we should afs_warnuser. Only let one
419 * caller call afs_warnuser per hm_retry_int interval per
423 if (!(tvp->states & VHardMount)) {
424 tvp->states |= VHardMount;
428 if (!afs_unknown_vhm) {
436 afs_PutVolume(tvp, READ_LOCK);
441 ("afs: hard-mount waiting for volume %u\n",
445 VSleep(hm_retry_int);
446 afs_CheckServers(1, cellp);
449 tvp = afs_FindVolume(afid, READ_LOCK);
451 tvp->states &= ~VHardMount;
452 afs_PutVolume(tvp, READ_LOCK);
459 } /* if (hm_retry_int ... */
461 if (acode == RX_MSGSIZE)
464 areq->networkError = 1;
470 /* Find server associated with this connection. */
471 sa = aconn->parent->srvr;
473 address = ntohl(sa->sa_ip);
475 /* Before we do anything with acode, make sure we translate it back to
477 if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
478 acode = et_to_sys_error(acode);
481 /* If we previously took an error, mark this volume not busy */
482 if (areq->volumeError) {
483 tvp = afs_FindVolume(afid, READ_LOCK);
485 for (i = 0; i < AFS_MAXHOSTS; i++) {
486 if (tvp->serverHost[i] == tsp) {
487 tvp->status[i] = not_busy;
490 afs_PutVolume(tvp, READ_LOCK);
494 afs_PutConn(aconn, rxconn, locktype);
498 /* If network troubles, mark server as having bogued out again. */
499 /* VRESTARTING is < 0 because of backward compatibility issues
500 * with 3.4 file servers and older cache managers */
501 #ifdef AFS_64BIT_CLIENT
504 #endif /* AFS_64BIT_CLIENT */
505 if ((acode < 0) && (acode != VRESTARTING)) {
506 if (acode == RX_MSGSIZE) {
510 if (acode == RX_CALL_TIMEOUT) {
511 serversleft = afs_BlackListOnce(areq, afid, tsp);
513 tvp = afs_FindVolume(afid, READ_LOCK);
514 if (!afid || !tvp || (tvp->states & VRO))
516 if ((serversleft == 0) && tvp &&
517 ((tvp->states & VRO) || (tvp->states & VBackup))) {
523 afs_PutVolume(tvp, READ_LOCK);
524 /* By doing this, we avoid ever marking a server down
525 * in an idle timeout case. That's because the server is
526 * still responding and may only be letting a single vnode
527 * time out. We otherwise risk having the server continually
528 * be marked down, then up, then down again...
533 ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
535 (aerrP->err_Server)++;
538 if (acode == VBUSY || acode == VRESTARTING) {
539 if (acode == VBUSY) {
542 (aerrP->err_VolumeBusies)++;
546 tvp = afs_FindVolume(afid, READ_LOCK);
548 for (i = 0; i < AFS_MAXHOSTS; i++) {
549 if (tvp->serverHost[i] == tsp) {
550 tvp->status[i] = rdwr_busy; /* can't tell which yet */
551 /* to tell which, have to look at the op code. */
554 afs_PutVolume(tvp, READ_LOCK);
556 afs_warnuser("afs: Waiting for busy volume %u in cell %s (server %d.%d.%d.%d)\n",
557 (afid ? afid->Fid.Volume : 0), tsp->cell->cellName,
558 (address >> 24), (address >> 16) & 0xff,
559 (address >> 8) & 0xff, (address) & 0xff);
560 VSleep(afs_BusyWaitPeriod); /* poll periodically */
564 } else if (acode == VICETOKENDEAD
565 || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
566 /* any rxkad error is treated as token expiration */
569 * I'm calling these errors protection errors, since they involve
570 * faulty authentication.
573 (aerrP->err_Protection)++;
575 tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
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->parent->user->states |= UTokensBad;
582 afs_NotifyUser(tu, UTokensDropped);
584 ("afs: Tokens for user of AFS id %d for cell %s have expired (server %d.%d.%d.%d)\n",
585 tu->viceId, aconn->parent->srvr->server->cell->cellName,
586 (address >> 24), (address >> 16) & 0xff,
587 (address >> 8) & 0xff, (address) & 0xff);
589 serversleft = afs_BlackListOnce(areq, afid, tsp);
594 ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d (server %d.%d.%d.%d)\n",
595 tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
596 (address >> 24), (address >> 16) & 0xff,
597 (address >> 8) & 0xff, (address) & 0xff);
600 areq->tokenError = 0;
601 aconn->forceConnectFS = 0; /* don't check until new tokens set */
602 aconn->parent->user->states |= UTokensBad;
603 afs_NotifyUser(tu, UTokensDropped);
605 ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d, server %d.%d.%d.%d)\n",
606 tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
607 (address >> 24), (address >> 16) & 0xff,
608 (address >> 8) & 0xff, (address) & 0xff);
611 afs_PutUser(tu, READ_LOCK);
613 /* The else case shouldn't be possible and should probably be replaced by a panic? */
614 if (acode == VICETOKENDEAD) {
615 aconn->forceConnectFS = 1;
616 } else if (acode == RXKADEXPIRED) {
617 aconn->forceConnectFS = 0; /* don't check until new tokens set */
618 aconn->parent->user->states |= UTokensBad;
619 afs_NotifyUser(tu, UTokensDropped);
621 ("afs: Tokens for user %d for cell %s have expired (server %d.%d.%d.%d)\n",
622 areq->uid, aconn->parent->srvr->server->cell->cellName,
623 (address >> 24), (address >> 16) & 0xff,
624 (address >> 8) & 0xff, (address) & 0xff);
626 aconn->forceConnectFS = 0; /* don't check until new tokens set */
627 aconn->parent->user->states |= UTokensBad;
628 afs_NotifyUser(tu, UTokensDropped);
630 ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d, server %d.%d.%d.%d)\n",
631 areq->uid, aconn->parent->srvr->server->cell->cellName,
633 (address >> 24), (address >> 16) & 0xff,
634 (address >> 8) & 0xff, (address) & 0xff);
638 shouldRetry = 1; /* Try again (as root). */
640 /* Check for access violation. */
641 else if (acode == EACCES) {
642 /* should mark access error in non-existent per-user global structure */
644 (aerrP->err_Protection)++;
645 areq->accessError = 1;
646 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
647 areq->permWriteError = 1;
650 /* check for ubik errors; treat them like crashed servers */
651 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
654 (aerrP->err_Server)++;
655 shouldRetry = 1; /* retryable (maybe one is working) */
656 VSleep(1); /* just in case */
658 /* Check for bad volume data base / missing volume. */
659 else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
660 || acode == VNOSERVICE || acode == VMOVED) {
665 areq->volumeError = VOLMISSING;
667 (aerrP->err_Volume)++;
668 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
669 same = VLDB_Same(afid, areq);
670 tvp = afs_FindVolume(afid, READ_LOCK);
672 for (i = 0; i < AFS_MAXHOSTS && tvp->serverHost[i]; i++) {
673 if (tvp->serverHost[i] == tsp) {
674 if (tvp->status[i] == end_not_busy)
675 tvp->status[i] = offline;
679 tvp->status[i] = not_busy; /* reset the others */
682 afs_PutVolume(tvp, READ_LOCK);
685 } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) { /* vlserver errors */
687 areq->volumeError = VOLMISSING;
688 } else if (acode >= 0) {
690 (aerrP->err_Other)++;
691 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
692 areq->permWriteError = 1;
693 shouldRetry = 0; /* Other random Vice error. */
694 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
696 ("afs: Path MTU may have been exceeded, retrying (server %d.%d.%d.%d)\n",
697 (address >> 24), (address >> 16) & 0xff,
698 (address >> 8) & 0xff, (address) & 0xff);
700 VSleep(1); /* Just a hack for desperate times. */
702 (aerrP->err_Other)++;
703 shouldRetry = 1; /* packet was too big, please retry call */
706 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
707 /* If we get here, code < 0 and we have network/Server troubles.
708 * areq->networkError is not set here, since we always
709 * retry in case there is another server. However, if we find
710 * no connection (aconn == 0) we set the networkError flag.
712 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
714 (aerrP->err_Server)++;
715 VSleep(1); /* Just a hack for desperate times. */
719 /* now unlock the connection and return */
720 afs_PutConn(aconn, rxconn, locktype);
721 return (shouldRetry);