Unix CM: Fix PutVolume in afs_BlackListOnce
[openafs.git] / src / afs / afs_analyze.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 /*
11  * Implements:
12  */
13 #include <afsconfig.h>
14 #include "afs/param.h"
15
16
17 #include "afs/stds.h"
18 #include "afs/sysincludes.h"    /* Standard vendor system headers */
19
20 #ifndef UKERNEL
21 #if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
22 #include <net/if.h>
23 #include <netinet/in.h>
24 #endif
25
26 #ifdef AFS_SGI62_ENV
27 #include "h/hashing.h"
28 #endif
29 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV) && !defined(AFS_DARWIN_ENV)
30 #include <netinet/in_var.h>
31 #endif
32 #endif /* !UKERNEL */
33
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"
38
39 #if     defined(AFS_SUN5_ENV)
40 #include <inet/led.h>
41 #include <inet/common.h>
42 #include <netinet/ip6.h>
43 #include <inet/ip.h>
44 #endif
45
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 */
50
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 */
55
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 */
61
62
63 int afs_BusyWaitPeriod = 15;    /* poll every 15 seconds */
64
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 */
68
69 #define VSleep(at)      afs_osi_Wait((at)*1000, 0, 0)
70
71
72 int lastcode;
73 /* returns:
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.
78  *
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. */
84 #define DIFFERENT 0
85 #define SAME 1
86 #define DUNNO 2
87 static int
88 VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
89 {
90     struct vrequest treq;
91     struct afs_conn *tconn;
92     int i, type = 0;
93     union {
94         struct vldbentry tve;
95         struct nvldbentry ntve;
96         struct uvldbentry utve;
97     } *v;
98     struct volume *tvp;
99     struct cell *tcell;
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;
104
105     AFS_STATCNT(CheckVLDB);
106     afs_FinalizeReq(areq);
107
108     if ((i = afs_InitReq(&treq, afs_osi_credp)))
109         return DUNNO;
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);
114     do {
115         VSleep(2);              /* Better safe than sorry. */
116         tconn =
117             afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
118                              &treq, SHARED_LOCK, &rxconn);
119         if (tconn) {
120             if ( tconn->parent->srvr->server->flags & SNO_LHOSTS) {
121                 type = 0;
122                 RX_AFS_GUNLOCK();
123                 i = VL_GetEntryByNameO(rxconn, bp, &v->tve);
124                 RX_AFS_GLOCK();
125             } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
126                 type = 1;
127                 RX_AFS_GUNLOCK();
128                 i = VL_GetEntryByNameN(rxconn, bp, &v->ntve);
129                 RX_AFS_GLOCK();
130             } else {
131                 type = 2;
132                 RX_AFS_GUNLOCK();
133                 i = VL_GetEntryByNameU(rxconn, bp, &v->utve);
134                 RX_AFS_GLOCK();
135                 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
136                     if (i == RXGEN_OPCODE) {
137                         type = 1;
138                         RX_AFS_GUNLOCK();
139                         i = VL_GetEntryByNameN(rxconn, bp, &v->ntve);
140                         RX_AFS_GLOCK();
141                         if (i == RXGEN_OPCODE) {
142                             type = 0;
143                             tconn->parent->srvr->server->flags |= SNO_LHOSTS;
144                             RX_AFS_GUNLOCK();
145                             i = VL_GetEntryByNameO(rxconn, bp, &v->tve);
146                             RX_AFS_GLOCK();
147                         } else if (!i)
148                             tconn->parent->srvr->server->flags |= SYES_LHOSTS;
149                     } else if (!i)
150                         tconn->parent->srvr->server->flags |= SVLSRV_UUID;
151                 }
152                 lastcode = i;
153             }
154         } else
155             i = -1;
156     } while (afs_Analyze(tconn, rxconn, i, NULL, &treq, -1,     /* no op code for this */
157                          SHARED_LOCK, tcell));
158
159     afs_PutCell(tcell, READ_LOCK);
160     afs_Trace2(afs_iclSetp, CM_TRACE_CHECKVLDB, ICL_TYPE_FID, &afid,
161                ICL_TYPE_INT32, i);
162
163     if (i) {
164         afs_osi_Free(v, sizeof(*v));
165         return DUNNO;
166     }
167     /* have info, copy into serverHost array */
168     changed = 0;
169     tvp = afs_FindVolume(afid, WRITE_LOCK);
170     if (tvp) {
171         ObtainWriteLock(&tvp->lock, 107);
172         for (i = 0; i < NMAXNSERVERS && tvp->serverHost[i]; i++) {
173             oldhosts[i] = tvp->serverHost[i];
174         }
175         ReleaseWriteLock(&tvp->lock);
176
177         if (type == 2) {
178             LockAndInstallUVolumeEntry(tvp, &v->utve, afid->Cell, tcell, &treq);
179         } else if (type == 1) {
180             LockAndInstallNVolumeEntry(tvp, &v->ntve, afid->Cell);
181         } else {
182             LockAndInstallVolumeEntry(tvp, &v->tve, afid->Cell);
183         }
184
185         if (i < NMAXNSERVERS && tvp->serverHost[i]) {
186             changed = 1;
187         }
188         for (--i; !changed && i >= 0; i--) {
189             if (tvp->serverHost[i] != oldhosts[i]) {
190                 changed = 1;    /* also happens if prefs change.  big deal. */
191             }
192         }
193
194         ReleaseWriteLock(&tvp->lock);
195         afs_PutVolume(tvp, WRITE_LOCK);
196     } else {                    /* can't find volume */
197         tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
198         if (tvp) {
199             afs_PutVolume(tvp, WRITE_LOCK);
200             afs_osi_Free(v, sizeof(*v));
201             return DIFFERENT;
202         } else {
203             afs_osi_Free(v, sizeof(*v));
204             return DUNNO;
205         }
206     }
207
208     afs_osi_Free(v, sizeof(*v));
209     return (changed ? DIFFERENT : SAME);
210 }                               /*VLDB_Same */
211
212 /*------------------------------------------------------------------------
213  * afs_BlackListOnce
214  *
215  * Description:
216  *      Mark a server as invalid for further attempts of this request only.
217  *
218  * Arguments:
219  *      areq  : The request record associated with this operation.
220  *      afid  : The FID of the file involved in the action.  This argument
221  *              may be null if none was involved.
222  *      tsp   : pointer to a server struct for the server we wish to
223  *              blacklist.
224  *
225  * Returns:
226  *      Non-zero value if further servers are available to try,
227  *      zero otherwise.
228  *
229  * Environment:
230  *      This routine is typically called in situations where we believe
231  *      one server out of a pool may have an error condition.
232  *
233  * Side Effects:
234  *      As advertised.
235  *
236  * NOTE:
237  *      The afs_Conn* routines use the list of invalidated servers to
238  *      avoid reusing a server marked as invalid for this request.
239  *------------------------------------------------------------------------*/
240 static afs_int32
241 afs_BlackListOnce(struct vrequest *areq, struct VenusFid *afid,
242                   struct server *tsp)
243 {
244     struct volume *tvp;
245     afs_int32 i;
246     afs_int32 serversleft = 0;
247
248     if (afid) {
249         tvp = afs_FindVolume(afid, READ_LOCK);
250         if (tvp) {
251             for (i = 0; i < AFS_MAXHOSTS; i++) {
252                 if (tvp->serverHost[i] == tsp) {
253                     areq->skipserver[i] = 1;
254                 }
255                 if (tvp->serverHost[i] &&
256                     (tvp->serverHost[i]->addr->sa_flags &
257                       SRVR_ISDOWN)) {
258                     areq->skipserver[i] = 1;
259                 }
260             }
261             for (i = 0; i < AFS_MAXHOSTS; i++) {
262                 if (tvp->serverHost[i] && areq->skipserver[i] == 0) {
263                     serversleft = 1;
264                     break;
265                 }
266             }
267             afs_PutVolume(tvp, READ_LOCK);
268             return serversleft;
269         }
270     }
271     return serversleft;
272 }
273
274
275 /*------------------------------------------------------------------------
276  * EXPORTED afs_Analyze
277  *
278  * Description:
279  *      Analyze the outcome of an RPC operation, taking whatever support
280  *      actions are necessary.
281  *
282  * Arguments:
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.
290  *
291  * Returns:
292  *      Non-zero value if the related RPC operation should be retried,
293  *      zero otherwise.
294  *
295  * Environment:
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.
299  *
300  * Side Effects:
301  *      As advertised.
302  *
303  * NOTE:
304  *      The retry return value is used by afs_StoreAllSegments to determine
305  *      if this is a temporary or permanent error.
306  *------------------------------------------------------------------------*/
307 int
308 afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
309             afs_int32 acode, struct VenusFid *afid, struct vrequest *areq,
310             int op, afs_int32 locktype, struct cell *cellp)
311 {
312     afs_int32 i;
313     struct srvAddr *sa;
314     struct server *tsp;
315     struct volume *tvp = NULL;
316     afs_int32 shouldRetry = 0;
317     afs_int32 serversleft = 1;
318     struct afs_stats_RPCErrors *aerrP;
319     afs_uint32 address;
320
321     if (AFS_IS_DISCONNECTED && !AFS_IN_SYNC) {
322         /* On reconnection, act as connected. XXX: for now.... */
323         /* SXW - This may get very tired after a while. We should try and
324          *       intercept all RPCs before they get here ... */
325         /*printf("afs_Analyze: disconnected\n");*/
326         afs_FinalizeReq(areq);
327         if (aconn) {
328             /* SXW - I suspect that this will _never_ happen - we shouldn't
329              *       get a connection because we're disconnected !!!*/
330             afs_PutConn(aconn, rxconn, locktype);
331         }
332         return 0;
333     }
334
335     AFS_STATCNT(afs_Analyze);
336     afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
337                ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
338                areq->uid);
339
340     aerrP = (struct afs_stats_RPCErrors *)0;
341
342     if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
343         aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
344
345     afs_FinalizeReq(areq);
346     if (!aconn && areq->busyCount) {    /* one RPC or more got VBUSY/VRESTARTING */
347
348         tvp = afs_FindVolume(afid, READ_LOCK);
349         if (tvp) {
350             afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
351                          (afid ? afid->Fid.Volume : 0),
352                          (tvp->name ? tvp->name : ""),
353                          ((tvp->serverHost[0]
354                            && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
355                           cell->cellName : ""));
356
357             for (i = 0; i < AFS_MAXHOSTS; i++) {
358                 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
359                     tvp->status[i] = not_busy;
360                 }
361                 if (tvp->status[i] == not_busy)
362                     shouldRetry = 1;
363             }
364             afs_PutVolume(tvp, READ_LOCK);
365         } else {
366             afs_warnuser("afs: Waiting for busy volume %u\n",
367                          (afid ? afid->Fid.Volume : 0));
368         }
369
370         if (areq->busyCount > 100) {
371             if (aerrP)
372                 (aerrP->err_Volume)++;
373             areq->volumeError = VOLBUSY;
374             shouldRetry = 0;
375         } else {
376             VSleep(afs_BusyWaitPeriod); /* poll periodically */
377         }
378         if (shouldRetry != 0)
379             areq->busyCount++;
380
381         return shouldRetry;     /* should retry */
382     }
383
384     if (!aconn || !aconn->parent->srvr) {
385         if (!areq->volumeError) {
386             if (aerrP)
387                 (aerrP->err_Network)++;
388             if (hm_retry_int && !(areq->flags & O_NONBLOCK) &&  /* "hard" mount */
389                 ((afid && afs_IsPrimaryCellNum(afid->Cell))
390                  || (cellp && afs_IsPrimaryCell(cellp)))) {
391                 if (!afid) {
392                     static int afs_vl_hm = 0;
393                     int warn = 0;
394                     if (!afs_vl_hm) {
395                         afs_vl_hm = warn = 1;
396                     }
397                     if (warn) {
398                         afs_warnuser
399                             ("afs: hard-mount waiting for a vlserver to return to service\n");
400                     }
401                     VSleep(hm_retry_int);
402                     afs_CheckServers(1, cellp);
403                     shouldRetry = 1;
404
405                     if (warn) {
406                         afs_vl_hm = 0;
407                     }
408                 } else {
409                     static int afs_unknown_vhm = 0;
410                     int warn = 0, vp_vhm = 0;
411
412                     tvp = afs_FindVolume(afid, READ_LOCK);
413                     if (!tvp || (tvp->states & VRO)) {
414                         shouldRetry = hm_retry_RO;
415                     } else {
416                         shouldRetry = hm_retry_RW;
417                     }
418
419                     /* Set 'warn' if we should afs_warnuser. Only let one
420                      * caller call afs_warnuser per hm_retry_int interval per
421                      * volume. */
422                     if (shouldRetry) {
423                         if (tvp) {
424                             if (!(tvp->states & VHardMount)) {
425                                 tvp->states |= VHardMount;
426                                 warn = vp_vhm = 1;
427                             }
428                         } else {
429                             if (!afs_unknown_vhm) {
430                                 afs_unknown_vhm = 1;
431                                 warn = 1;
432                             }
433                         }
434                     }
435
436                     if (tvp)
437                         afs_PutVolume(tvp, READ_LOCK);
438
439                     if (shouldRetry) {
440                         if (warn) {
441                             afs_warnuser
442                                 ("afs: hard-mount waiting for volume %u\n",
443                                  afid->Fid.Volume);
444                         }
445
446                         VSleep(hm_retry_int);
447                         afs_CheckServers(1, cellp);
448
449                         if (vp_vhm) {
450                             tvp = afs_FindVolume(afid, READ_LOCK);
451                             if (tvp) {
452                                 tvp->states &= ~VHardMount;
453                                 afs_PutVolume(tvp, READ_LOCK);
454                             }
455                         } else if (warn) {
456                             afs_unknown_vhm = 0;
457                         }
458                     }
459                 }
460             } /* if (hm_retry_int ... */
461             else {
462                 if (acode == RX_MSGSIZE)
463                     shouldRetry = 1;
464                 else
465                     areq->networkError = 1;
466             }
467         }
468         return shouldRetry;
469     }
470
471     /* Find server associated with this connection. */
472     sa = aconn->parent->srvr;
473     tsp = sa->server;
474     address = ntohl(sa->sa_ip);
475
476     /* Before we do anything with acode, make sure we translate it back to
477      * a system error */
478     if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
479         acode = et_to_sys_error(acode);
480
481     if (acode == 0) {
482         /* If we previously took an error, mark this volume not busy */
483         if (areq->volumeError) {
484             tvp = afs_FindVolume(afid, READ_LOCK);
485             if (tvp) {
486                 for (i = 0; i < AFS_MAXHOSTS; i++) {
487                     if (tvp->serverHost[i] == tsp) {
488                         tvp->status[i] = not_busy;
489                     }
490                 }
491                 afs_PutVolume(tvp, READ_LOCK);
492             }
493         }
494
495         afs_PutConn(aconn, rxconn, locktype);
496         return 0;
497     }
498
499     /* If network troubles, mark server as having bogued out again. */
500     /* VRESTARTING is < 0 because of backward compatibility issues
501      * with 3.4 file servers and older cache managers */
502 #ifdef AFS_64BIT_CLIENT
503     if (acode == -455)
504         acode = 455;
505 #endif /* AFS_64BIT_CLIENT */
506     if ((acode < 0) && (acode != VRESTARTING)) {
507         if (acode == RX_MSGSIZE) {
508             shouldRetry = 1;
509             goto out;
510         }
511         if (acode == RX_CALL_TIMEOUT) {
512             serversleft = afs_BlackListOnce(areq, afid, tsp);
513             if (afid)
514                 tvp = afs_FindVolume(afid, READ_LOCK);
515             if (!afid || !tvp || (tvp->states & VRO))
516                 areq->idleError++;
517             if ((serversleft == 0) && tvp &&
518                 ((tvp->states & VRO) || (tvp->states & VBackup))) {
519                 shouldRetry = 0;
520             } else {
521                 shouldRetry = 1;
522             }
523             if (tvp)
524                 afs_PutVolume(tvp, READ_LOCK);
525             /* By doing this, we avoid ever marking a server down
526              * in an idle timeout case. That's because the server is
527              * still responding and may only be letting a single vnode
528              * time out. We otherwise risk having the server continually
529              * be marked down, then up, then down again...
530              */
531             goto out;
532         }
533         afs_ServerDown(sa);
534         ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
535         if (aerrP)
536             (aerrP->err_Server)++;
537     }
538
539     if (acode == VBUSY || acode == VRESTARTING) {
540         if (acode == VBUSY) {
541             areq->busyCount++;
542             if (aerrP)
543                 (aerrP->err_VolumeBusies)++;
544         } else
545             areq->busyCount = 1;
546
547         tvp = afs_FindVolume(afid, READ_LOCK);
548         if (tvp) {
549             for (i = 0; i < AFS_MAXHOSTS; i++) {
550                 if (tvp->serverHost[i] == tsp) {
551                     tvp->status[i] = rdwr_busy; /* can't tell which yet */
552                     /* to tell which, have to look at the op code. */
553                 }
554             }
555             afs_PutVolume(tvp, READ_LOCK);
556         } else {
557             afs_warnuser("afs: Waiting for busy volume %u in cell %s (server %d.%d.%d.%d)\n",
558                          (afid ? afid->Fid.Volume : 0), tsp->cell->cellName,
559                          (address >> 24), (address >> 16) & 0xff,
560                          (address >> 8) & 0xff, (address) & 0xff);
561             VSleep(afs_BusyWaitPeriod); /* poll periodically */
562         }
563         shouldRetry = 1;
564         acode = 0;
565     } else if (acode == VICETOKENDEAD
566                || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
567         /* any rxkad error is treated as token expiration */
568         struct unixuser *tu;
569         /*
570          * I'm calling these errors protection errors, since they involve
571          * faulty authentication.
572          */
573         if (aerrP)
574             (aerrP->err_Protection)++;
575
576         tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
577         if (tu) {
578             if (acode == VICETOKENDEAD) {
579                 aconn->forceConnectFS = 1;
580             } else if (acode == RXKADEXPIRED) {
581                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
582                 aconn->parent->user->states |= UTokensBad;
583                 afs_NotifyUser(tu, UTokensDropped);
584                 afs_warnuser
585                     ("afs: Tokens for user of AFS id %d for cell %s have expired (server %d.%d.%d.%d)\n",
586                      tu->viceId, aconn->parent->srvr->server->cell->cellName,
587                      (address >> 24), (address >> 16) & 0xff,
588                      (address >> 8) & 0xff, (address) & 0xff);
589             } else {
590                 serversleft = afs_BlackListOnce(areq, afid, tsp);
591                 areq->tokenError++;
592
593                 if (serversleft) {
594                     afs_warnuser
595                         ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d (server %d.%d.%d.%d)\n",
596                          tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
597                          (address >> 24), (address >> 16) & 0xff,
598                          (address >> 8) & 0xff, (address) & 0xff);
599                     shouldRetry = 1;
600                 } else {
601                     areq->tokenError = 0;
602                     aconn->forceConnectFS = 0;  /* don't check until new tokens set */
603                     aconn->parent->user->states |= UTokensBad;
604                     afs_NotifyUser(tu, UTokensDropped);
605                     afs_warnuser
606                         ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d, server %d.%d.%d.%d)\n",
607                          tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
608                          (address >> 24), (address >> 16) & 0xff,
609                          (address >> 8) & 0xff, (address) & 0xff);
610                 }
611             }
612             afs_PutUser(tu, READ_LOCK);
613         } else {
614             /* The else case shouldn't be possible and should probably be replaced by a panic? */
615             if (acode == VICETOKENDEAD) {
616                 aconn->forceConnectFS = 1;
617             } else if (acode == RXKADEXPIRED) {
618                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
619                 aconn->parent->user->states |= UTokensBad;
620                 afs_NotifyUser(tu, UTokensDropped);
621                 afs_warnuser
622                     ("afs: Tokens for user %d for cell %s have expired (server %d.%d.%d.%d)\n",
623                      areq->uid, aconn->parent->srvr->server->cell->cellName,
624                      (address >> 24), (address >> 16) & 0xff,
625                      (address >> 8) & 0xff, (address) & 0xff);
626             } else {
627                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
628                 aconn->parent->user->states |= UTokensBad;
629                 afs_NotifyUser(tu, UTokensDropped);
630                 afs_warnuser
631                     ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d, server %d.%d.%d.%d)\n",
632                      areq->uid, aconn->parent->srvr->server->cell->cellName,
633                      acode,
634                      (address >> 24), (address >> 16) & 0xff,
635                      (address >> 8) & 0xff, (address) & 0xff);
636
637             }
638         }
639         shouldRetry = 1;        /* Try again (as root). */
640     }
641     /* Check for access violation. */
642     else if (acode == EACCES) {
643         /* should mark access error in non-existent per-user global structure */
644         if (aerrP)
645             (aerrP->err_Protection)++;
646         areq->accessError = 1;
647         if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
648             areq->permWriteError = 1;
649         shouldRetry = 0;
650     }
651     /* check for ubik errors; treat them like crashed servers */
652     else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
653         afs_ServerDown(sa);
654         if (aerrP)
655             (aerrP->err_Server)++;
656         shouldRetry = 1;        /* retryable (maybe one is working) */
657         VSleep(1);              /* just in case */
658     }
659     /* Check for bad volume data base / missing volume. */
660     else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
661              || acode == VNOSERVICE || acode == VMOVED) {
662         struct cell *tcell;
663         int same;
664
665         shouldRetry = 1;
666         areq->volumeError = VOLMISSING;
667         if (aerrP)
668             (aerrP->err_Volume)++;
669         if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
670             same = VLDB_Same(afid, areq);
671             tvp = afs_FindVolume(afid, READ_LOCK);
672             if (tvp) {
673                 for (i = 0; i < AFS_MAXHOSTS && tvp->serverHost[i]; i++) {
674                     if (tvp->serverHost[i] == tsp) {
675                         if (tvp->status[i] == end_not_busy)
676                             tvp->status[i] = offline;
677                         else
678                             tvp->status[i]++;
679                     } else if (!same) {
680                         tvp->status[i] = not_busy;      /* reset the others */
681                     }
682                 }
683                 afs_PutVolume(tvp, READ_LOCK);
684             }
685         }
686     } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) {    /* vlserver errors */
687         shouldRetry = 0;
688         areq->volumeError = VOLMISSING;
689     } else if (acode >= 0) {
690         if (aerrP)
691             (aerrP->err_Other)++;
692         if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
693             areq->permWriteError = 1;
694         shouldRetry = 0;        /* Other random Vice error. */
695     } else if (acode == RX_MSGSIZE) {   /* same meaning as EMSGSIZE... */
696         afs_warnuser
697             ("afs: Path MTU may have been exceeded, retrying (server %d.%d.%d.%d)\n",
698              (address >> 24), (address >> 16) & 0xff,
699              (address >> 8) & 0xff, (address) & 0xff);
700
701         VSleep(1);              /* Just a hack for desperate times. */
702         if (aerrP)
703             (aerrP->err_Other)++;
704         shouldRetry = 1;        /* packet was too big, please retry call */
705     }
706
707     if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
708         /* If we get here, code < 0 and we have network/Server troubles.
709          * areq->networkError is not set here, since we always
710          * retry in case there is another server.  However, if we find
711          * no connection (aconn == 0) we set the networkError flag.
712          */
713         afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
714         if (aerrP)
715             (aerrP->err_Server)++;
716         VSleep(1);              /* Just a hack for desperate times. */
717         shouldRetry = 1;
718     }
719 out:
720     /* now unlock the connection and return */
721     afs_PutConn(aconn, rxconn, locktype);
722     return (shouldRetry);
723 }                               /*afs_Analyze */