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/stds.h"
19 #include "../afs/sysincludes.h" /* Standard vendor system headers */
22 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
24 #include <netinet/in.h>
28 #include "../h/hashing.h"
30 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
31 #include <netinet/in_var.h>
35 #include "../afs/afsincludes.h" /* Afs-based standard headers */
36 #include "../afs/afs_stats.h" /* afs statistics */
37 #include "../afs/afs_util.h"
38 #include "../afs/afs_prototypes.h"
40 #if defined(AFS_SUN56_ENV)
42 #include <inet/common.h>
43 #if defined(AFS_SUN58_ENV)
44 #include <netinet/ip6.h>
50 /* shouldn't do it this way, but for now will do */
51 #ifndef ERROR_TABLE_BASE_U
52 #define ERROR_TABLE_BASE_U (5376L)
53 #endif /* ubik error base define */
55 /* same hack for vlserver error base as for ubik error base */
56 #ifndef ERROR_TABLE_BASE_VL
57 #define ERROR_TABLE_BASE_VL (363520L)
58 #define VL_NOENT (363524L)
59 #endif /* vlserver error base define */
62 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 void afs_CopyError(afrom, ato)
70 register struct vrequest *afrom;
71 register struct vrequest *ato;
74 AFS_STATCNT(afs_CopyError);
78 if (afrom->accessError)
80 if (afrom->volumeError)
82 if (afrom->networkError)
83 ato->networkError = 1;
84 if (afrom->permWriteError)
85 ato->permWriteError = 1;
90 void afs_FinalizeReq(areq)
91 register struct vrequest *areq;
94 AFS_STATCNT(afs_FinalizeReq);
98 areq->accessError = 0;
99 areq->volumeError = 0;
100 areq->networkError = 0;
101 areq->permWriteError = 0;
104 } /*afs_FinalizeReq*/
107 afs_CheckCode(acode, areq, where)
109 struct vrequest *areq;
113 AFS_STATCNT(afs_CheckCode);
115 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKCODE,
116 ICL_TYPE_INT32, acode, ICL_TYPE_INT32, where);
118 if (!areq || !areq->initd)
120 if (areq->networkError)
124 if (areq->accessError)
126 if (areq->volumeError == VOLMISSING)
128 if (areq->volumeError == VOLBUSY)
130 if (acode == VNOVNODE)
137 #define VSleep(at) afs_osi_Wait((at)*1000, 0, 0)
142 * 0 if the vldb record for a specific volume is different from what
143 * we have cached -- perhaps the volume has moved.
144 * 1 if the vldb record is the same
145 * 2 if we can't tell if it's the same or not.
147 * If 0, the caller will probably start over at the beginning of our
148 * list of servers for this volume and try to find one that is up. If
149 * not 0, we will probably just keep plugging with what we have
150 * cached. If we fail to contact the VL server, we should just keep
151 * trying with the information we have, rather than failing. */
155 static int VLDB_Same (afid, areq)
156 struct VenusFid *afid;
157 struct vrequest *areq;
159 struct vrequest treq;
163 struct vldbentry tve;
164 struct nvldbentry ntve;
165 struct uvldbentry utve;
169 char *bp, tbuf[CVBS]; /* biggest volume id is 2^32, ~ 4*10^9 */
170 unsigned int changed;
171 struct server *(oldhosts[NMAXNSERVERS]);
173 AFS_STATCNT(CheckVLDB);
174 afs_FinalizeReq(areq);
176 if (i = afs_InitReq(&treq, &afs_osi_cred)) return DUNNO;
177 tcell = afs_GetCell(afid->Cell, READ_LOCK);
178 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
180 VSleep(2); /* Better safe than sorry. */
181 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
182 tcell->cell, &treq, SHARED_LOCK);
184 if (tconn->srvr->server->flags & SNO_LHOSTS) {
186 #ifdef RX_ENABLE_LOCKS
188 #endif /* RX_ENABLE_LOCKS */
189 i = VL_GetEntryByNameO(tconn->id, bp, &v.tve);
190 #ifdef RX_ENABLE_LOCKS
192 #endif /* RX_ENABLE_LOCKS */
193 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
195 #ifdef RX_ENABLE_LOCKS
197 #endif /* RX_ENABLE_LOCKS */
198 i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve);
199 #ifdef RX_ENABLE_LOCKS
201 #endif /* RX_ENABLE_LOCKS */
204 #ifdef RX_ENABLE_LOCKS
206 #endif /* RX_ENABLE_LOCKS */
207 i = VL_GetEntryByNameU(tconn->id, bp, &v.utve);
208 #ifdef RX_ENABLE_LOCKS
210 #endif /* RX_ENABLE_LOCKS */
211 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
212 if (i == RXGEN_OPCODE) {
214 #ifdef RX_ENABLE_LOCKS
216 #endif /* RX_ENABLE_LOCKS */
217 i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve);
218 #ifdef RX_ENABLE_LOCKS
220 #endif /* RX_ENABLE_LOCKS */
221 if (i == RXGEN_OPCODE) {
223 tconn->srvr->server->flags |= SNO_LHOSTS;
224 #ifdef RX_ENABLE_LOCKS
226 #endif /* RX_ENABLE_LOCKS */
227 i = VL_GetEntryByNameO(tconn->id, bp, &v.tve);
228 #ifdef RX_ENABLE_LOCKS
230 #endif /* RX_ENABLE_LOCKS */
232 tconn->srvr->server->flags |= SYES_LHOSTS;
234 tconn->srvr->server->flags |= SVLSRV_UUID;
240 } while (afs_Analyze(tconn, i, (struct VenusFid *) 0, &treq,
241 -1, /* no op code for this */
242 SHARED_LOCK, tcell));
244 afs_PutCell(tcell, READ_LOCK);
245 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKVLDB, ICL_TYPE_FID, &afid,
251 /* have info, copy into serverHost array */
253 tvp = afs_FindVolume(afid, WRITE_LOCK);
255 ObtainWriteLock(&tvp->lock,107);
256 for (i=0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) {
257 oldhosts[i] = tvp->serverHost[i];
261 InstallUVolumeEntry(tvp, &v.utve, afid->Cell, tcell, &treq);
263 else if (type == 1) {
264 InstallNVolumeEntry(tvp, &v.ntve, afid->Cell);
267 InstallVolumeEntry(tvp, &v.tve, afid->Cell);
270 if (i < NMAXNSERVERS && tvp->serverHost[i]) {
273 for (--i;!changed && i >= 0; i--) {
274 if (tvp->serverHost[i] != oldhosts[i]) {
275 changed = 1; /* also happens if prefs change. big deal. */
279 ReleaseWriteLock(&tvp->lock);
280 afs_PutVolume(tvp, WRITE_LOCK);
282 else { /* can't find volume */
283 tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
285 afs_PutVolume(tvp, WRITE_LOCK);
291 return (changed ? DIFFERENT : SAME);
295 /*------------------------------------------------------------------------
296 * EXPORTED afs_Analyze
299 * Analyze the outcome of an RPC operation, taking whatever support
300 * actions are necessary.
303 * aconn : Ptr to the relevant connection on which the call was made.
304 * acode : The return code experienced by the RPC.
305 * afid : The FID of the file involved in the action. This argument
306 * may be null if none was involved.
307 * areq : The request record associated with this operation.
308 * op : which RPC we are analyzing.
309 * cellp : pointer to a cell struct. Must provide either fid or cell.
312 * Non-zero value if the related RPC operation should be retried,
316 * This routine is typically called in a do-while loop, causing the
317 * embedded RPC operation to be called repeatedly if appropriate
318 * until whatever error condition (if any) is intolerable.
324 * The retry return value is used by afs_StoreAllSegments to determine
325 * if this is a temporary or permanent error.
326 *------------------------------------------------------------------------*/
327 int afs_Analyze(aconn, acode, afid, areq, op, locktype, cellp)
328 register struct conn *aconn;
330 register struct vrequest *areq;
331 struct VenusFid *afid;
341 afs_int32 shouldRetry = 0;
342 struct afs_stats_RPCErrors *aerrP;
345 AFS_STATCNT(afs_Analyze);
346 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
347 ICL_TYPE_POINTER, aconn,
348 ICL_TYPE_INT32, acode, ICL_TYPE_LONG, areq->uid);
350 aerrP = (struct afs_stats_RPCErrors *) 0;
352 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
353 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
355 afs_FinalizeReq(areq);
356 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
358 tvp = afs_FindVolume(afid, READ_LOCK);
360 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
361 (afid ? afid->Fid.Volume : 0),
362 (tvp->name ? tvp->name : ""),
363 ((tvp->serverHost[0] && tvp->serverHost[0]->cell) ?
364 tvp->serverHost[0]->cell->cellName : ""));
366 for (i=0; i < MAXHOSTS; i++) {
367 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
368 tvp->status[i] = not_busy;
370 if (tvp->status[i] == not_busy)
373 afs_PutVolume(tvp, READ_LOCK);
375 afs_warnuser("afs: Waiting for busy volume %u\n",
376 (afid ? afid->Fid.Volume : 0));
379 if (areq->busyCount > 100) {
381 (aerrP->err_Volume)++;
382 areq->volumeError = VOLBUSY;
385 VSleep(afs_BusyWaitPeriod); /* poll periodically */
387 return shouldRetry; /* should retry */
391 if (!areq->volumeError) {
393 (aerrP->err_Network)++;
394 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
395 ((afid && afid->Cell == LOCALCELL) ||
396 (cellp && cellp->cell == LOCALCELL))) {
398 afs_warnuser("afs: hard-mount waiting for a vlserver to return to service\n");
399 VSleep(hm_retry_int);
400 afs_CheckServers(1,cellp);
403 tvp = afs_FindVolume(afid, READ_LOCK);
404 if (!tvp || (tvp->states & VRO)) {
405 shouldRetry = hm_retry_RO;
407 shouldRetry = hm_retry_RW;
410 afs_PutVolume(tvp, READ_LOCK);
412 afs_warnuser("afs: hard-mount waiting for volume %u\n",
414 VSleep(hm_retry_int);
415 afs_CheckServers(1,cellp);
418 } /* if (hm_retry_int ... */
420 areq->networkError = 1;
426 /* Find server associated with this connection. */
431 /* If we previously took an error, mark this volume not busy */
432 if (areq->volumeError) {
433 tvp = afs_FindVolume(afid, READ_LOCK);
435 for (i=0; i<MAXHOSTS ; i++) {
436 if (tvp->serverHost[i] == tsp) {
437 tvp->status[i] = not_busy ;
440 afs_PutVolume(tvp, READ_LOCK);
444 afs_PutConn(aconn, locktype);
448 /* If network troubles, mark server as having bogued out again. */
449 /* VRESTARTING is < 0 because of backward compatibility issues
450 * with 3.4 file servers and older cache managers */
451 #ifdef AFS_64BIT_CLIENT
454 #endif /* AFS_64BIT_CLIENT */
455 if ((acode < 0) && (acode != VRESTARTING)) {
457 ForceNewConnections(sa); /*multi homed clients lock:afs_xsrvAddr?*/
459 (aerrP->err_Server)++;
462 if (acode == VBUSY || acode == VRESTARTING) {
463 if (acode == VBUSY) {
466 (aerrP->err_VolumeBusies)++;
468 else areq->busyCount = 1;
470 tvp = afs_FindVolume(afid, READ_LOCK);
472 for (i=0; i < MAXHOSTS ; i++ ) {
473 if (tvp->serverHost[i] == tsp) {
474 tvp->status[i] = rdwr_busy ; /* can't tell which yet */
475 /* to tell which, have to look at the op code. */
478 afs_PutVolume(tvp, READ_LOCK);
481 afs_warnuser("afs: Waiting for busy volume %u in cell %s\n",
482 (afid? afid->Fid.Volume : 0), tsp->cell->cellName);
483 VSleep(afs_BusyWaitPeriod); /* poll periodically */
488 else if (acode == VICETOKENDEAD || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
489 /* any rxkad error is treated as token expiration */
493 * I'm calling these errors protection errors, since they involve
494 * faulty authentication.
497 (aerrP->err_Protection)++;
499 tu = afs_FindUser(areq->uid, tsp->cell->cell, READ_LOCK);
501 if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED))
502 afs_warnuser("afs: Tokens for user of AFS id %d for cell %s have expired\n",
503 tu->vid, aconn->srvr->server->cell->cellName);
505 afs_warnuser("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d)\n",
506 tu->vid, aconn->srvr->server->cell->cellName, acode);
507 afs_PutUser(tu, READ_LOCK);
509 /* The else case shouldn't be possible and should probably be replaced by a panic? */
510 if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED))
511 afs_warnuser("afs: Tokens for user %d for cell %s have expired\n",
512 areq->uid, aconn->srvr->server->cell->cellName);
514 afs_warnuser("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d)\n",
515 areq->uid, aconn->srvr->server->cell->cellName, acode);
517 aconn->forceConnectFS = 0; /* don't check until new tokens set */
518 aconn->user->states |= UTokensBad;
519 shouldRetry = 1; /* Try again (as root). */
521 /* Check for access violation. */
522 else if (acode == EACCES) {
523 /* should mark access error in non-existent per-user global structure */
525 (aerrP->err_Protection)++;
526 areq->accessError = 1;
527 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
528 areq->permWriteError = 1;
531 /* check for ubik errors; treat them like crashed servers */
532 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U+255) {
535 (aerrP->err_Server)++;
536 shouldRetry = 1; /* retryable (maybe one is working) */
537 VSleep(1); /* just in case */
539 /* Check for bad volume data base / missing volume. */
540 else if (acode == VSALVAGE || acode == VOFFLINE
541 || acode == VNOVOL || acode == VNOSERVICE || acode == VMOVED) {
546 areq->volumeError = VOLMISSING;
548 (aerrP->err_Volume)++;
549 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
550 same = VLDB_Same(afid, areq);
551 tvp = afs_FindVolume(afid, READ_LOCK);
553 for (i=0; i < MAXHOSTS && tvp->serverHost[i]; i++ ) {
554 if (tvp->serverHost[i] == tsp) {
555 if (tvp->status[i] == end_not_busy)
556 tvp->status[i] = offline ;
561 tvp->status[i] = not_busy; /* reset the others */
564 afs_PutVolume(tvp, READ_LOCK);
568 else if (acode >= ERROR_TABLE_BASE_VL
569 && acode <= ERROR_TABLE_BASE_VL + 255) /* vlserver errors */ {
571 areq->volumeError = VOLMISSING;
573 else if (acode >= 0) {
575 (aerrP->err_Other)++;
576 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
577 areq->permWriteError = 1;
578 shouldRetry = 0; /* Other random Vice error. */
579 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
580 VSleep(1); /* Just a hack for desperate times. */
582 (aerrP->err_Other)++;
583 shouldRetry = 1; /* packet was too big, please retry call */
586 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
587 /* If we get here, code < 0 and we have network/Server troubles.
588 * areq->networkError is not set here, since we always
589 * retry in case there is another server. However, if we find
590 * no connection (aconn == 0) we set the networkError flag.
592 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
594 (aerrP->err_Server)++;
595 VSleep(1); /* Just a hack for desperate times. */
599 /* now unlock the connection and return */
600 afs_PutConn(aconn, locktype);
601 return (shouldRetry);