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 "../afs/param.h" /* Should be always first */
14 #include "../afs/stds.h"
15 #include "../afs/sysincludes.h" /* Standard vendor system headers */
18 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
20 #include <netinet/in.h>
24 #include "../h/hashing.h"
26 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
27 #include <netinet/in_var.h>
31 #include "../afs/afsincludes.h" /* Afs-based standard headers */
32 #include "../afs/afs_stats.h" /* afs statistics */
33 #include "../afs/afs_util.h"
34 #include "../afs/afs_prototypes.h"
36 #if defined(AFS_SUN56_ENV)
38 #include <inet/common.h>
39 #if defined(AFS_SUN58_ENV)
40 #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 /* same hack for vlserver error base as for ubik error base */
52 #ifndef ERROR_TABLE_BASE_vl
53 #define ERROR_TABLE_BASE_vl (363520L)
54 #define VL_NOENT (363524L)
55 #endif /* vlserver error base define */
58 int afs_BusyWaitPeriod = 15; /* poll every 15 seconds */
61 afs_int32 hm_retry_RO=0; /* don't wait */
62 afs_int32 hm_retry_RW=0; /* don't wait */
63 afs_int32 hm_retry_int=0; /* don't wait */
65 void afs_CopyError(afrom, ato)
66 register struct vrequest *afrom;
67 register struct vrequest *ato;
70 AFS_STATCNT(afs_CopyError);
74 if (afrom->accessError)
76 if (afrom->volumeError)
78 if (afrom->networkError)
79 ato->networkError = 1;
80 if (afrom->permWriteError)
81 ato->permWriteError = 1;
86 void afs_FinalizeReq(areq)
87 register struct vrequest *areq;
90 AFS_STATCNT(afs_FinalizeReq);
94 areq->accessError = 0;
95 areq->volumeError = 0;
96 areq->networkError = 0;
97 areq->permWriteError = 0;
100 } /*afs_FinalizeReq*/
103 afs_CheckCode(acode, areq, where)
105 struct vrequest *areq;
109 AFS_STATCNT(afs_CheckCode);
111 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKCODE,
112 ICL_TYPE_INT32, acode, ICL_TYPE_INT32, where);
114 if (!areq || !areq->initd)
116 if (areq->networkError)
120 if (areq->accessError)
122 if (areq->volumeError == VOLMISSING)
124 if (areq->volumeError == VOLBUSY)
126 if (acode == VNOVNODE)
133 #define VSleep(at) afs_osi_Wait((at)*1000, 0, 0)
138 * 0 if the vldb record for a specific volume is different from what
139 * we have cached -- perhaps the volume has moved.
140 * 1 if the vldb record is the same
141 * 2 if we can't tell if it's the same or not.
143 * If 0, the caller will probably start over at the beginning of our
144 * list of servers for this volume and try to find one that is up. If
145 * not 0, we will probably just keep plugging with what we have
146 * cached. If we fail to contact the VL server, we should just keep
147 * trying with the information we have, rather than failing. */
151 static int VLDB_Same (afid, areq)
152 struct VenusFid *afid;
153 struct vrequest *areq;
155 struct vrequest treq;
159 struct vldbentry tve;
160 struct nvldbentry ntve;
161 struct uvldbentry utve;
165 char *bp, tbuf[CVBS]; /* biggest volume id is 2^32, ~ 4*10^9 */
166 unsigned int changed;
167 struct server *(oldhosts[NMAXNSERVERS]);
169 AFS_STATCNT(CheckVLDB);
170 afs_FinalizeReq(areq);
172 if (i = afs_InitReq(&treq, &afs_osi_cred)) return DUNNO;
173 tcell = afs_GetCell(afid->Cell, READ_LOCK);
174 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
176 VSleep(2); /* Better safe than sorry. */
177 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
178 tcell->cell, &treq, SHARED_LOCK);
180 if (tconn->srvr->server->flags & SNO_LHOSTS) {
182 #ifdef RX_ENABLE_LOCKS
184 #endif /* RX_ENABLE_LOCKS */
185 i = VL_GetEntryByNameO(tconn->id, bp, &v.tve);
186 #ifdef RX_ENABLE_LOCKS
188 #endif /* RX_ENABLE_LOCKS */
189 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
191 #ifdef RX_ENABLE_LOCKS
193 #endif /* RX_ENABLE_LOCKS */
194 i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve);
195 #ifdef RX_ENABLE_LOCKS
197 #endif /* RX_ENABLE_LOCKS */
200 #ifdef RX_ENABLE_LOCKS
202 #endif /* RX_ENABLE_LOCKS */
203 i = VL_GetEntryByNameU(tconn->id, bp, &v.utve);
204 #ifdef RX_ENABLE_LOCKS
206 #endif /* RX_ENABLE_LOCKS */
207 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
208 if (i == RXGEN_OPCODE) {
210 #ifdef RX_ENABLE_LOCKS
212 #endif /* RX_ENABLE_LOCKS */
213 i = VL_GetEntryByNameN(tconn->id, bp, &v.ntve);
214 #ifdef RX_ENABLE_LOCKS
216 #endif /* RX_ENABLE_LOCKS */
217 if (i == RXGEN_OPCODE) {
219 tconn->srvr->server->flags |= SNO_LHOSTS;
220 #ifdef RX_ENABLE_LOCKS
222 #endif /* RX_ENABLE_LOCKS */
223 i = VL_GetEntryByNameO(tconn->id, bp, &v.tve);
224 #ifdef RX_ENABLE_LOCKS
226 #endif /* RX_ENABLE_LOCKS */
228 tconn->srvr->server->flags |= SYES_LHOSTS;
230 tconn->srvr->server->flags |= SVLSRV_UUID;
236 } while (afs_Analyze(tconn, i, (struct VenusFid *) 0, &treq,
237 -1, /* no op code for this */
238 SHARED_LOCK, tcell));
240 afs_PutCell(tcell, READ_LOCK);
241 afs_Trace2(afs_iclSetp, CM_TRACE_CHECKVLDB, ICL_TYPE_FID, &afid,
247 /* have info, copy into serverHost array */
249 tvp = afs_FindVolume(afid, WRITE_LOCK);
251 ObtainWriteLock(&tvp->lock,107);
252 for (i=0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) {
253 oldhosts[i] = tvp->serverHost[i];
257 InstallUVolumeEntry(tvp, &v.utve, afid->Cell, tcell, &treq);
259 else if (type == 1) {
260 InstallNVolumeEntry(tvp, &v.ntve, afid->Cell);
263 InstallVolumeEntry(tvp, &v.tve, afid->Cell);
266 if (i < NMAXNSERVERS && tvp->serverHost[i]) {
269 for (--i;!changed && i >= 0; i--) {
270 if (tvp->serverHost[i] != oldhosts[i]) {
271 changed = 1; /* also happens if prefs change. big deal. */
275 ReleaseWriteLock(&tvp->lock);
276 afs_PutVolume(tvp, WRITE_LOCK);
278 else { /* can't find volume */
279 tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
281 afs_PutVolume(tvp, WRITE_LOCK);
287 return (changed ? DIFFERENT : SAME);
291 /*------------------------------------------------------------------------
292 * EXPORTED afs_Analyze
295 * Analyze the outcome of an RPC operation, taking whatever support
296 * actions are necessary.
299 * aconn : Ptr to the relevant connection on which the call was made.
300 * acode : The return code experienced by the RPC.
301 * afid : The FID of the file involved in the action. This argument
302 * may be null if none was involved.
303 * areq : The request record associated with this operation.
304 * op : which RPC we are analyzing.
305 * cellp : pointer to a cell struct. Must provide either fid or cell.
308 * Non-zero value if the related RPC operation should be retried,
312 * This routine is typically called in a do-while loop, causing the
313 * embedded RPC operation to be called repeatedly if appropriate
314 * until whatever error condition (if any) is intolerable.
320 * The retry return value is used by afs_StoreAllSegments to determine
321 * if this is a temporary or permanent error.
322 *------------------------------------------------------------------------*/
323 int afs_Analyze(aconn, acode, afid, areq, op, locktype, cellp)
324 register struct conn *aconn;
326 register struct vrequest *areq;
327 struct VenusFid *afid;
337 afs_int32 shouldRetry = 0;
338 struct afs_stats_RPCErrors *aerrP;
341 AFS_STATCNT(afs_Analyze);
342 afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
343 ICL_TYPE_POINTER, aconn,
344 ICL_TYPE_INT32, acode, ICL_TYPE_LONG, areq->uid);
346 aerrP = (struct afs_stats_RPCErrors *) 0;
348 if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
349 aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
351 afs_FinalizeReq(areq);
352 if (!aconn && areq->busyCount) { /* one RPC or more got VBUSY/VRESTARTING */
354 tvp = afs_FindVolume(afid, READ_LOCK);
356 afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
357 (afid ? afid->Fid.Volume : 0),
358 (tvp->name ? tvp->name : ""),
359 ((tvp->serverHost[0] && tvp->serverHost[0]->cell) ?
360 tvp->serverHost[0]->cell->cellName : ""));
362 for (i=0; i < MAXHOSTS; i++) {
363 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
364 tvp->status[i] = not_busy;
366 if (tvp->status[i] == not_busy)
369 afs_PutVolume(tvp, READ_LOCK);
371 afs_warnuser("afs: Waiting for busy volume %u\n",
372 (afid ? afid->Fid.Volume : 0));
375 if (areq->busyCount > 100) {
377 (aerrP->err_Volume)++;
378 areq->volumeError = VOLBUSY;
381 VSleep(afs_BusyWaitPeriod); /* poll periodically */
383 return shouldRetry; /* should retry */
387 if (!areq->volumeError) {
389 (aerrP->err_Network)++;
390 if (hm_retry_int && !(areq->flags & O_NONBLOCK) && /* "hard" mount */
391 ((afid && afid->Cell == LOCALCELL) ||
392 (cellp && cellp->cell == LOCALCELL))) {
394 afs_warnuser("afs: hard-mount waiting for a vlserver to return to service\n");
395 VSleep(hm_retry_int);
396 afs_CheckServers(1,cellp);
399 tvp = afs_FindVolume(afid, READ_LOCK);
400 if (!tvp || (tvp->states & VRO)) {
401 shouldRetry = hm_retry_RO;
403 shouldRetry = hm_retry_RW;
406 afs_PutVolume(tvp, READ_LOCK);
408 afs_warnuser("afs: hard-mount waiting for volume %u\n",
410 VSleep(hm_retry_int);
411 afs_CheckServers(1,cellp);
414 } /* if (hm_retry_int ... */
416 areq->networkError = 1;
422 /* Find server associated with this connection. */
427 /* If we previously took an error, mark this volume not busy */
428 if (areq->volumeError) {
429 tvp = afs_FindVolume(afid, READ_LOCK);
431 for (i=0; i<MAXHOSTS ; i++) {
432 if (tvp->serverHost[i] == tsp) {
433 tvp->status[i] = not_busy ;
436 afs_PutVolume(tvp, READ_LOCK);
440 afs_PutConn(aconn, locktype);
444 /* If network troubles, mark server as having bogued out again. */
445 /* VRESTARTING is < 0 because of backward compatibility issues
446 * with 3.4 file servers and older cache managers */
447 if ((acode < 0) && (acode != VRESTARTING)) {
449 ForceNewConnections(sa); /*multi homed clients lock:afs_xsrvAddr?*/
451 (aerrP->err_Server)++;
454 if (acode == VBUSY || acode == VRESTARTING) {
455 if (acode == VBUSY) {
458 (aerrP->err_VolumeBusies)++;
460 else areq->busyCount = 1;
462 tvp = afs_FindVolume(afid, READ_LOCK);
464 for (i=0; i < MAXHOSTS ; i++ ) {
465 if (tvp->serverHost[i] == tsp) {
466 tvp->status[i] = rdwr_busy ; /* can't tell which yet */
467 /* to tell which, have to look at the op code. */
470 afs_PutVolume(tvp, READ_LOCK);
473 afs_warnuser("afs: Waiting for busy volume %u in cell %s\n",
474 (afid? afid->Fid.Volume : 0), tsp->cell->cellName);
475 VSleep(afs_BusyWaitPeriod); /* poll periodically */
480 else if (acode == VICETOKENDEAD || (acode & ~0xff) == ERROR_TABLE_BASE_rxk) {
481 /* any rxkad error is treated as token expiration */
485 * I'm calling these errors protection errors, since they involve
486 * faulty authentication.
489 (aerrP->err_Protection)++;
491 tu = afs_FindUser(areq->uid, tsp->cell->cell, READ_LOCK);
493 if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED))
494 afs_warnuser("afs: Tokens for user of AFS id %d for cell %s have expired\n",
495 tu->vid, aconn->srvr->server->cell->cellName);
497 afs_warnuser("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d)\n",
498 tu->vid, aconn->srvr->server->cell->cellName, acode);
499 afs_PutUser(tu, READ_LOCK);
501 /* The else case shouldn't be possible and should probably be replaced by a panic? */
502 if ((acode == VICETOKENDEAD) || (acode == RXKADEXPIRED))
503 afs_warnuser("afs: Tokens for user %d for cell %s have expired\n",
504 areq->uid, aconn->srvr->server->cell->cellName);
506 afs_warnuser("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d)\n",
507 areq->uid, aconn->srvr->server->cell->cellName, acode);
509 aconn->forceConnectFS = 0; /* don't check until new tokens set */
510 aconn->user->states |= UTokensBad;
511 shouldRetry = 1; /* Try again (as root). */
513 /* Check for access violation. */
514 else if (acode == EACCES) {
515 /* should mark access error in non-existent per-user global structure */
517 (aerrP->err_Protection)++;
518 areq->accessError = 1;
519 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
520 areq->permWriteError = 1;
523 /* check for ubik errors; treat them like crashed servers */
524 else if (acode >= ERROR_TABLE_BASE_u && acode < ERROR_TABLE_BASE_u+255) {
527 (aerrP->err_Server)++;
528 shouldRetry = 1; /* retryable (maybe one is working) */
529 VSleep(1); /* just in case */
531 /* Check for bad volume data base / missing volume. */
532 else if (acode == VSALVAGE || acode == VOFFLINE
533 || acode == VNOVOL || acode == VNOSERVICE || acode == VMOVED) {
538 areq->volumeError = VOLMISSING;
540 (aerrP->err_Volume)++;
541 if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
542 same = VLDB_Same(afid, areq);
543 tvp = afs_FindVolume(afid, READ_LOCK);
545 for (i=0; i < MAXHOSTS && tvp->serverHost[i]; i++ ) {
546 if (tvp->serverHost[i] == tsp) {
547 if (tvp->status[i] == end_not_busy)
548 tvp->status[i] = offline ;
553 tvp->status[i] = not_busy; /* reset the others */
556 afs_PutVolume(tvp, READ_LOCK);
560 else if (acode >= ERROR_TABLE_BASE_vl
561 && acode <= ERROR_TABLE_BASE_vl + 255) /* vlserver errors */ {
563 areq->volumeError = VOLMISSING;
565 else if (acode >= 0) {
567 (aerrP->err_Other)++;
568 if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
569 areq->permWriteError = 1;
570 shouldRetry = 0; /* Other random Vice error. */
571 } else if (acode == RX_MSGSIZE) { /* same meaning as EMSGSIZE... */
572 VSleep(1); /* Just a hack for desperate times. */
574 (aerrP->err_Other)++;
575 shouldRetry = 1; /* packet was too big, please retry call */
578 if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
579 /* If we get here, code < 0 and we have network/Server troubles.
580 * areq->networkError is not set here, since we always
581 * retry in case there is another server. However, if we find
582 * no connection (aconn == 0) we set the networkError flag.
584 afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
586 (aerrP->err_Server)++;
587 VSleep(1); /* Just a hack for desperate times. */
591 /* now unlock the connection and return */
592 afs_PutConn(aconn, locktype);
593 return (shouldRetry);