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) && !defined(AFS_DARWIN60_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"
39 #if defined(AFS_SUN56_ENV)
41 #include <inet/common.h>
42 #if defined(AFS_SUN58_ENV)
43 #include <netinet/ip6.h>
49 /* shouldn't do it this way, but for now will do */
50 #ifndef ERROR_TABLE_BASE_U
51 #define ERROR_TABLE_BASE_U (5376L)
52 #endif /* ubik error base define */
54 /* same hack for vlserver error base as for ubik error base */
55 #ifndef ERROR_TABLE_BASE_VL
56 #define ERROR_TABLE_BASE_VL (363520L)
57 #define VL_NOENT (363524L)
58 #endif /* vlserver error base define */
61 int afs_BusyWaitPeriod = 15; /* poll every 15 seconds */
63 afs_int32 hm_retry_RO=0; /* don't wait */
64 afs_int32 hm_retry_RW=0; /* don't wait */
65 afs_int32 hm_retry_int=0; /* don't wait */
67 void afs_CopyError(register struct vrequest *afrom, register struct vrequest *ato)
69 AFS_STATCNT(afs_CopyError);
73 if (afrom->accessError)
75 if (afrom->volumeError)
77 if (afrom->networkError)
78 ato->networkError = 1;
79 if (afrom->permWriteError)
80 ato->permWriteError = 1;
84 void afs_FinalizeReq(register struct vrequest *areq)
86 AFS_STATCNT(afs_FinalizeReq);
90 areq->accessError = 0;
91 areq->volumeError = 0;
92 areq->networkError = 0;
93 areq->permWriteError = 0;
98 int afs_CheckCode(afs_int32 acode, struct vrequest *areq, int where)
100 AFS_STATCNT(afs_CheckCode);
102 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKCODE,
103 ICL_TYPE_INT32, acode, ICL_TYPE_INT32, where);
105 if (!areq || !areq->initd)
107 if (areq->networkError)
111 if (areq->accessError)
113 if (areq->volumeError == VOLMISSING)
115 if (areq->volumeError == VOLBUSY)
117 if (acode == VNOVNODE)
124 #define VSleep(at) afs_osi_Wait((at)*1000, 0, 0)
129 * 0 if the vldb record for a specific volume is different from what
130 * we have cached -- perhaps the volume has moved.
131 * 1 if the vldb record is the same
132 * 2 if we can't tell if it's the same or not.
134 * If 0, the caller will probably start over at the beginning of our
135 * list of servers for this volume and try to find one that is up. If
136 * not 0, we will probably just keep plugging with what we have
137 * cached. If we fail to contact the VL server, we should just keep
138 * trying with the information we have, rather than failing. */
142 static int VLDB_Same (struct VenusFid *afid, struct vrequest *areq)
144 struct vrequest treq;
148 struct vldbentry tve;
149 struct nvldbentry ntve;
150 struct uvldbentry utve;
154 char *bp, tbuf[CVBS]; /* biggest volume id is 2^32, ~ 4*10^9 */
155 unsigned int changed;
156 struct server *(oldhosts[NMAXNSERVERS]);
158 AFS_STATCNT(CheckVLDB);
159 afs_FinalizeReq(areq);
161 if ((i = afs_InitReq(&treq, &afs_osi_cred))) return DUNNO;
162 tcell = afs_GetCell(afid->Cell, READ_LOCK);
163 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
165 VSleep(2); /* Better safe than sorry. */
166 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
167 tcell->cellNum, &treq, SHARED_LOCK);
169 if (tconn->srvr->server->flags & SNO_LHOSTS) {
172 i = VL_GetEntryByNameO(tconn->id, bp, &v.tve);
174 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
177 i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve);
182 i = VL_GetEntryByNameU(tconn->id, bp, &v.utve);
184 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
185 if (i == RXGEN_OPCODE) {
188 i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve);
190 if (i == RXGEN_OPCODE) {
192 tconn->srvr->server->flags |= SNO_LHOSTS;
194 i = VL_GetEntryByNameO(tconn->id, bp, &v.tve);
197 tconn->srvr->server->flags |= SYES_LHOSTS;
199 tconn->srvr->server->flags |= SVLSRV_UUID;
205 } while (afs_Analyze(tconn, i, NULL, &treq,
206 -1, /* no op code for this */
207 SHARED_LOCK, tcell));
209 afs_PutCell(tcell, READ_LOCK);
210 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKVLDB, ICL_TYPE_FID, &afid,
216 /* have info, copy into serverHost array */
218 tvp = afs_FindVolume(afid, WRITE_LOCK);
220 ObtainWriteLock(&tvp->lock,107);
221 for (i=0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) {
222 oldhosts[i] = tvp->serverHost[i];
226 InstallUVolumeEntry(tvp, &v.utve, afid->Cell, tcell, &treq);
228 else if (type == 1) {
229 InstallNVolumeEntry(tvp, &v.ntve, afid->Cell);
232 InstallVolumeEntry(tvp, &v.tve, afid->Cell);
235 if (i < NMAXNSERVERS && tvp->serverHost[i]) {
238 for (--i;!changed && i >= 0; i--) {
239 if (tvp->serverHost[i] != oldhosts[i]) {
240 changed = 1; /* also happens if prefs change. big deal. */
244 ReleaseWriteLock(&tvp->lock);
245 afs_PutVolume(tvp, WRITE_LOCK);
247 else { /* can't find volume */
248 tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
250 afs_PutVolume(tvp, WRITE_LOCK);
256 return (changed ? DIFFERENT : SAME);
260 /*------------------------------------------------------------------------
261 * EXPORTED afs_Analyze
264 * Analyze the outcome of an RPC operation, taking whatever support
265 * actions are necessary.
268 * aconn : Ptr to the relevant connection on which the call was made.
269 * acode : The return code experienced by the RPC.
270 * afid : The FID of the file involved in the action. This argument
271 * may be null if none was involved.
272 * areq : The request record associated with this operation.
273 * op : which RPC we are analyzing.
274 * cellp : pointer to a cell struct. Must provide either fid or cell.
277 * Non-zero value if the related RPC operation should be retried,
281 * This routine is typically called in a do-while loop, causing the
282 * embedded RPC operation to be called repeatedly if appropriate
283 * until whatever error condition (if any) is intolerable.
289 * The retry return value is used by afs_StoreAllSegments to determine
290 * if this is a temporary or permanent error.
291 *------------------------------------------------------------------------*/
292 int afs_Analyze(register struct conn *aconn, afs_int32 acode,
293 struct VenusFid *afid, register struct vrequest *areq, int op,
294 afs_int32 locktype, struct cell *cellp)
300 afs_int32 shouldRetry = 0;
301 struct afs_stats_RPCErrors *aerrP;
303 AFS_STATCNT(afs_Analyze);
304 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
305 ICL_TYPE_POINTER, aconn,
306 ICL_TYPE_INT32, acode, ICL_TYPE_LONG, areq->uid);
308 aerrP = (struct afs_stats_RPCErrors *) 0;
310 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
311 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
313 afs_FinalizeReq(areq);
314 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
316 tvp = afs_FindVolume(afid, READ_LOCK);
318 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
319 (afid ? afid->Fid.Volume : 0),
320 (tvp->name ? tvp->name : ""),
321 ((tvp->serverHost[0] && tvp->serverHost[0]->cell) ?
322 tvp->serverHost[0]->cell->cellName : ""));
324 for (i=0; i < MAXHOSTS; i++) {
325 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
326 tvp->status[i] = not_busy;
328 if (tvp->status[i] == not_busy)
331 afs_PutVolume(tvp, READ_LOCK);
333 afs_warnuser("afs: Waiting for busy volume %u\n",
334 (afid ? afid->Fid.Volume : 0));
337 if (areq->busyCount > 100) {
339 (aerrP->err_Volume)++;
340 areq->volumeError = VOLBUSY;
343 VSleep(afs_BusyWaitPeriod); /* poll periodically */
345 return shouldRetry; /* should retry */
349 if (!areq->volumeError) {
351 (aerrP->err_Network)++;
352 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
353 ((afid && afs_IsPrimaryCellNum(afid->Cell)) ||
354 (cellp && afs_IsPrimaryCell(cellp)))) {
356 afs_warnuser("afs: hard-mount waiting for a vlserver to return to service\n");
357 VSleep(hm_retry_int);
358 afs_CheckServers(1,cellp);
361 tvp = afs_FindVolume(afid, READ_LOCK);
362 if (!tvp || (tvp->states & VRO)) {
363 shouldRetry = hm_retry_RO;
365 shouldRetry = hm_retry_RW;
368 afs_PutVolume(tvp, READ_LOCK);
370 afs_warnuser("afs: hard-mount waiting for volume %u\n",
372 VSleep(hm_retry_int);
373 afs_CheckServers(1,cellp);
376 } /* if (hm_retry_int ... */
378 areq->networkError = 1;
384 /* Find server associated with this connection. */
389 /* If we previously took an error, mark this volume not busy */
390 if (areq->volumeError) {
391 tvp = afs_FindVolume(afid, READ_LOCK);
393 for (i=0; i<MAXHOSTS ; i++) {
394 if (tvp->serverHost[i] == tsp) {
395 tvp->status[i] = not_busy ;
398 afs_PutVolume(tvp, READ_LOCK);
402 afs_PutConn(aconn, locktype);
406 /* If network troubles, mark server as having bogued out again. */
407 /* VRESTARTING is < 0 because of backward compatibility issues
408 * with 3.4 file servers and older cache managers */
409 #ifdef AFS_64BIT_CLIENT
412 #endif /* AFS_64BIT_CLIENT */
413 if ((acode < 0) && (acode != VRESTARTING)) {
415 ForceNewConnections(sa); /*multi homed clients lock:afs_xsrvAddr?*/
417 (aerrP->err_Server)++;
420 if (acode == VBUSY || acode == VRESTARTING) {
421 if (acode == VBUSY) {
424 (aerrP->err_VolumeBusies)++;
426 else areq->busyCount = 1;
428 tvp = afs_FindVolume(afid, READ_LOCK);
430 for (i=0; i < MAXHOSTS ; i++ ) {
431 if (tvp->serverHost[i] == tsp) {
432 tvp->status[i] = rdwr_busy ; /* can't tell which yet */
433 /* to tell which, have to look at the op code. */
436 afs_PutVolume(tvp, READ_LOCK);
439 afs_warnuser("afs: Waiting for busy volume %u in cell %s\n",
440 (afid? afid->Fid.Volume : 0), tsp->cell->cellName);
441 VSleep(afs_BusyWaitPeriod); /* poll periodically */
446 else if (acode == VICETOKENDEAD || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
447 /* any rxkad error is treated as token expiration */
451 * I'm calling these errors protection errors, since they involve
452 * faulty authentication.
455 (aerrP->err_Protection)++;
457 tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
459 if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED))
460 afs_warnuser("afs: Tokens for user of AFS id %d for cell %s have expired\n",
461 tu->vid, aconn->srvr->server->cell->cellName);
463 afs_warnuser("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d)\n",
464 tu->vid, aconn->srvr->server->cell->cellName, acode);
465 afs_PutUser(tu, READ_LOCK);
467 /* The else case shouldn't be possible and should probably be replaced by a panic? */
468 if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED))
469 afs_warnuser("afs: Tokens for user %d for cell %s have expired\n",
470 areq->uid, aconn->srvr->server->cell->cellName);
472 afs_warnuser("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d)\n",
473 areq->uid, aconn->srvr->server->cell->cellName, acode);
475 aconn->forceConnectFS = 0; /* don't check until new tokens set */
476 aconn->user->states |= UTokensBad;
477 shouldRetry = 1; /* Try again (as root). */
479 /* Check for access violation. */
480 else if (acode == EACCES) {
481 /* should mark access error in non-existent per-user global structure */
483 (aerrP->err_Protection)++;
484 areq->accessError = 1;
485 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
486 areq->permWriteError = 1;
489 /* check for ubik errors; treat them like crashed servers */
490 else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U+255) {
493 (aerrP->err_Server)++;
494 shouldRetry = 1; /* retryable (maybe one is working) */
495 VSleep(1); /* just in case */
497 /* Check for bad volume data base / missing volume. */
498 else if (acode == VSALVAGE || acode == VOFFLINE
499 || acode == VNOVOL || acode == VNOSERVICE || acode == VMOVED) {
504 areq->volumeError = VOLMISSING;
506 (aerrP->err_Volume)++;
507 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
508 same = VLDB_Same(afid, areq);
509 tvp = afs_FindVolume(afid, READ_LOCK);
511 for (i=0; i < MAXHOSTS && tvp->serverHost[i]; i++ ) {
512 if (tvp->serverHost[i] == tsp) {
513 if (tvp->status[i] == end_not_busy)
514 tvp->status[i] = offline ;
519 tvp->status[i] = not_busy; /* reset the others */
522 afs_PutVolume(tvp, READ_LOCK);
526 else if (acode >= ERROR_TABLE_BASE_VL
527 && acode <= ERROR_TABLE_BASE_VL + 255) /* vlserver errors */ {
529 areq->volumeError = VOLMISSING;
531 else if (acode >= 0) {
533 (aerrP->err_Other)++;
534 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
535 areq->permWriteError = 1;
536 shouldRetry = 0; /* Other random Vice error. */
537 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
538 VSleep(1); /* Just a hack for desperate times. */
540 (aerrP->err_Other)++;
541 shouldRetry = 1; /* packet was too big, please retry call */
544 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
545 /* If we get here, code < 0 and we have network/Server troubles.
546 * areq->networkError is not set here, since we always
547 * retry in case there is another server. However, if we find
548 * no connection (aconn == 0) we set the networkError flag.
550 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
552 (aerrP->err_Server)++;
553 VSleep(1); /* Just a hack for desperate times. */
557 /* now unlock the connection and return */
558 afs_PutConn(aconn, locktype);
559 return (shouldRetry);