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) {
187 i = VL_GetEntryByNameO(tconn->id, bp, &v.tve);
189 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
192 i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve);
197 i = VL_GetEntryByNameU(tconn->id, bp, &v.utve);
199 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
200 if (i == RXGEN_OPCODE) {
203 i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve);
205 if (i == RXGEN_OPCODE) {
207 tconn->srvr->server->flags |= SNO_LHOSTS;
209 i = VL_GetEntryByNameO(tconn->id, bp, &v.tve);
212 tconn->srvr->server->flags |= SYES_LHOSTS;
214 tconn->srvr->server->flags |= SVLSRV_UUID;
220 } while (afs_Analyze(tconn, i, (struct VenusFid *) 0, &treq,
221 -1, /* no op code for this */
222 SHARED_LOCK, tcell));
224 afs_PutCell(tcell, READ_LOCK);
225 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKVLDB, ICL_TYPE_FID, &afid,
231 /* have info, copy into serverHost array */
233 tvp = afs_FindVolume(afid, WRITE_LOCK);
235 ObtainWriteLock(&tvp->lock,107);
236 for (i=0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) {
237 oldhosts[i] = tvp->serverHost[i];
241 InstallUVolumeEntry(tvp, &v.utve, afid->Cell, tcell, &treq);
243 else if (type == 1) {
244 InstallNVolumeEntry(tvp, &v.ntve, afid->Cell);
247 InstallVolumeEntry(tvp, &v.tve, afid->Cell);
250 if (i < NMAXNSERVERS && tvp->serverHost[i]) {
253 for (--i;!changed && i >= 0; i--) {
254 if (tvp->serverHost[i] != oldhosts[i]) {
255 changed = 1; /* also happens if prefs change. big deal. */
259 ReleaseWriteLock(&tvp->lock);
260 afs_PutVolume(tvp, WRITE_LOCK);
262 else { /* can't find volume */
263 tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
265 afs_PutVolume(tvp, WRITE_LOCK);
271 return (changed ? DIFFERENT : SAME);
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 *------------------------------------------------------------------------*/
307 int afs_Analyze(aconn, acode, afid, areq, op, locktype, cellp)
308 register struct conn *aconn;
310 register struct vrequest *areq;
311 struct VenusFid *afid;
321 afs_int32 shouldRetry = 0;
322 struct afs_stats_RPCErrors *aerrP;
325 AFS_STATCNT(afs_Analyze);
326 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
327 ICL_TYPE_POINTER, aconn,
328 ICL_TYPE_INT32, acode, ICL_TYPE_LONG, areq->uid);
330 aerrP = (struct afs_stats_RPCErrors *) 0;
332 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
333 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
335 afs_FinalizeReq(areq);
336 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
338 tvp = afs_FindVolume(afid, READ_LOCK);
340 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
341 (afid ? afid->Fid.Volume : 0),
342 (tvp->name ? tvp->name : ""),
343 ((tvp->serverHost[0] && tvp->serverHost[0]->cell) ?
344 tvp->serverHost[0]->cell->cellName : ""));
346 for (i=0; i < MAXHOSTS; i++) {
347 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
348 tvp->status[i] = not_busy;
350 if (tvp->status[i] == not_busy)
353 afs_PutVolume(tvp, READ_LOCK);
355 afs_warnuser("afs: Waiting for busy volume %u\n",
356 (afid ? afid->Fid.Volume : 0));
359 if (areq->busyCount > 100) {
361 (aerrP->err_Volume)++;
362 areq->volumeError = VOLBUSY;
365 VSleep(afs_BusyWaitPeriod); /* poll periodically */
367 return shouldRetry; /* should retry */
371 if (!areq->volumeError) {
373 (aerrP->err_Network)++;
374 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
375 ((afid && afid->Cell == LOCALCELL) ||
376 (cellp && cellp->cell == LOCALCELL))) {
378 afs_warnuser("afs: hard-mount waiting for a vlserver to return to service\n");
379 VSleep(hm_retry_int);
380 afs_CheckServers(1,cellp);
383 tvp = afs_FindVolume(afid, READ_LOCK);
384 if (!tvp || (tvp->states & VRO)) {
385 shouldRetry = hm_retry_RO;
387 shouldRetry = hm_retry_RW;
390 afs_PutVolume(tvp, READ_LOCK);
392 afs_warnuser("afs: hard-mount waiting for volume %u\n",
394 VSleep(hm_retry_int);
395 afs_CheckServers(1,cellp);
398 } /* if (hm_retry_int ... */
400 areq->networkError = 1;
406 /* Find server associated with this connection. */
411 /* If we previously took an error, mark this volume not busy */
412 if (areq->volumeError) {
413 tvp = afs_FindVolume(afid, READ_LOCK);
415 for (i=0; i<MAXHOSTS ; i++) {
416 if (tvp->serverHost[i] == tsp) {
417 tvp->status[i] = not_busy ;
420 afs_PutVolume(tvp, READ_LOCK);
424 afs_PutConn(aconn, locktype);
428 /* If network troubles, mark server as having bogued out again. */
429 /* VRESTARTING is < 0 because of backward compatibility issues
430 * with 3.4 file servers and older cache managers */
431 #ifdef AFS_64BIT_CLIENT
434 #endif /* AFS_64BIT_CLIENT */
435 if ((acode < 0) && (acode != VRESTARTING)) {
437 ForceNewConnections(sa); /*multi homed clients lock:afs_xsrvAddr?*/
439 (aerrP->err_Server)++;
442 if (acode == VBUSY || acode == VRESTARTING) {
443 if (acode == VBUSY) {
446 (aerrP->err_VolumeBusies)++;
448 else areq->busyCount = 1;
450 tvp = afs_FindVolume(afid, READ_LOCK);
452 for (i=0; i < MAXHOSTS ; i++ ) {
453 if (tvp->serverHost[i] == tsp) {
454 tvp->status[i] = rdwr_busy ; /* can't tell which yet */
455 /* to tell which, have to look at the op code. */
458 afs_PutVolume(tvp, READ_LOCK);
461 afs_warnuser("afs: Waiting for busy volume %u in cell %s\n",
462 (afid? afid->Fid.Volume : 0), tsp->cell->cellName);
463 VSleep(afs_BusyWaitPeriod); /* poll periodically */
468 else if (acode == VICETOKENDEAD || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
469 /* any rxkad error is treated as token expiration */
473 * I'm calling these errors protection errors, since they involve
474 * faulty authentication.
477 (aerrP->err_Protection)++;
479 tu = afs_FindUser(areq->uid, tsp->cell->cell, READ_LOCK);
481 if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED))
482 afs_warnuser("afs: Tokens for user of AFS id %d for cell %s have expired\n",
483 tu->vid, aconn->srvr->server->cell->cellName);
485 afs_warnuser("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d)\n",
486 tu->vid, aconn->srvr->server->cell->cellName, acode);
487 afs_PutUser(tu, READ_LOCK);
489 /* The else case shouldn't be possible and should probably be replaced by a panic? */
490 if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED))
491 afs_warnuser("afs: Tokens for user %d for cell %s have expired\n",
492 areq->uid, aconn->srvr->server->cell->cellName);
494 afs_warnuser("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d)\n",
495 areq->uid, aconn->srvr->server->cell->cellName, acode);
497 aconn->forceConnectFS = 0; /* don't check until new tokens set */
498 aconn->user->states |= UTokensBad;
499 shouldRetry = 1; /* Try again (as root). */
501 /* Check for access violation. */
502 else if (acode == EACCES) {
503 /* should mark access error in non-existent per-user global structure */
505 (aerrP->err_Protection)++;
506 areq->accessError = 1;
507 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
508 areq->permWriteError = 1;
511 /* check for ubik errors; treat them like crashed servers */
512 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U+255) {
515 (aerrP->err_Server)++;
516 shouldRetry = 1; /* retryable (maybe one is working) */
517 VSleep(1); /* just in case */
519 /* Check for bad volume data base / missing volume. */
520 else if (acode == VSALVAGE || acode == VOFFLINE
521 || acode == VNOVOL || acode == VNOSERVICE || acode == VMOVED) {
526 areq->volumeError = VOLMISSING;
528 (aerrP->err_Volume)++;
529 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
530 same = VLDB_Same(afid, areq);
531 tvp = afs_FindVolume(afid, READ_LOCK);
533 for (i=0; i < MAXHOSTS && tvp->serverHost[i]; i++ ) {
534 if (tvp->serverHost[i] == tsp) {
535 if (tvp->status[i] == end_not_busy)
536 tvp->status[i] = offline ;
541 tvp->status[i] = not_busy; /* reset the others */
544 afs_PutVolume(tvp, READ_LOCK);
548 else if (acode >= ERROR_TABLE_BASE_VL
549 && acode <= ERROR_TABLE_BASE_VL + 255) /* vlserver errors */ {
551 areq->volumeError = VOLMISSING;
553 else if (acode >= 0) {
555 (aerrP->err_Other)++;
556 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
557 areq->permWriteError = 1;
558 shouldRetry = 0; /* Other random Vice error. */
559 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
560 VSleep(1); /* Just a hack for desperate times. */
562 (aerrP->err_Other)++;
563 shouldRetry = 1; /* packet was too big, please retry call */
566 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
567 /* If we get here, code < 0 and we have network/Server troubles.
568 * areq->networkError is not set here, since we always
569 * retry in case there is another server. However, if we find
570 * no connection (aconn == 0) we set the networkError flag.
572 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
574 (aerrP->err_Server)++;
575 VSleep(1); /* Just a hack for desperate times. */
579 /* now unlock the connection and return */
580 afs_PutConn(aconn, locktype);
581 return (shouldRetry);