9a2087c8778ec7f7e11e3bcd795b50328cce8255
[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, 0, &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  * afs_ClearStatus
276  *
277  * Description:
278  *      Analyze the outcome of an RPC operation, taking whatever support
279  *      actions are necessary.
280  *
281  * Arguments:
282  *      afid  : The FID of the file involved in the action.  This argument
283  *              may be null if none was involved.
284  *      op    : which RPC we are analyzing.
285  *      avp   : A pointer to the struct volume, if we already have one.
286  *
287  * Returns:
288  *      Non-zero value if the related RPC operation can be retried,
289  *      zero otherwise.
290  *
291  * Environment:
292  *      This routine is called when we got a network error,
293  *      and discards state if the operation was a data-mutating
294  *      operation.
295  *------------------------------------------------------------------------*/
296 static int
297 afs_ClearStatus(struct VenusFid *afid, int op, struct volume *avp)
298 {
299     struct volume *tvp = NULL;
300
301     /* if it's not a write op, we have nothing to veto and shouldn't clear. */
302     if (!AFS_STATS_FS_RPCIDXES_ISWRITE(op)) {
303         return 1;
304     }
305
306     if (avp)
307         tvp = avp;
308     else if (afid)
309         tvp = afs_FindVolume(afid, READ_LOCK);
310
311     /* don't assume just discarding will fix if no cached volume */
312     if (tvp) {
313         struct vcache *tvc;
314         ObtainReadLock(&afs_xvcache);
315         if ((tvc = afs_FindVCache(afid, 0, 0))) {
316             ReleaseReadLock(&afs_xvcache);
317             tvc->f.states &= ~(CStatd | CUnique);
318             afs_PutVCache(tvc);
319         } else {
320             ReleaseReadLock(&afs_xvcache);
321         }
322         if (!avp)
323             afs_PutVolume(tvp, READ_LOCK);
324     }
325
326     if (AFS_STATS_FS_RPCIDXES_WRITE_RETRIABLE(op))
327         return 1;
328
329     /* not retriable: we may have raced ourselves */
330     return 0;
331 }
332
333 /*------------------------------------------------------------------------
334  * EXPORTED afs_Analyze
335  *
336  * Description:
337  *      Analyze the outcome of an RPC operation, taking whatever support
338  *      actions are necessary.
339  *
340  * Arguments:
341  *      aconn : Ptr to the relevant connection on which the call was made.
342  *      acode : The return code experienced by the RPC.
343  *      afid  : The FID of the file involved in the action.  This argument
344  *              may be null if none was involved.
345  *      areq  : The request record associated with this operation.
346  *      op    : which RPC we are analyzing.
347  *      cellp : pointer to a cell struct.  Must provide either fid or cell.
348  *
349  * Returns:
350  *      Non-zero value if the related RPC operation should be retried,
351  *      zero otherwise.
352  *
353  * Environment:
354  *      This routine is typically called in a do-while loop, causing the
355  *      embedded RPC operation to be called repeatedly if appropriate
356  *      until whatever error condition (if any) is intolerable.
357  *
358  * Side Effects:
359  *      As advertised.
360  *
361  * NOTE:
362  *      The retry return value is used by afs_StoreAllSegments to determine
363  *      if this is a temporary or permanent error.
364  *------------------------------------------------------------------------*/
365 int
366 afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
367             afs_int32 acode, struct VenusFid *afid, struct vrequest *areq,
368             int op, afs_int32 locktype, struct cell *cellp)
369 {
370     afs_int32 i;
371     struct srvAddr *sa;
372     struct server *tsp;
373     struct volume *tvp = NULL;
374     afs_int32 shouldRetry = 0;
375     afs_int32 serversleft = 1;
376     struct afs_stats_RPCErrors *aerrP;
377     afs_uint32 address;
378
379     if (AFS_IS_DISCONNECTED && !AFS_IN_SYNC) {
380         /* On reconnection, act as connected. XXX: for now.... */
381         /* SXW - This may get very tired after a while. We should try and
382          *       intercept all RPCs before they get here ... */
383         /*printf("afs_Analyze: disconnected\n");*/
384         afs_FinalizeReq(areq);
385         if (aconn) {
386             /* SXW - I suspect that this will _never_ happen - we shouldn't
387              *       get a connection because we're disconnected !!!*/
388             afs_PutConn(aconn, rxconn, locktype);
389         }
390         return 0;
391     }
392
393     AFS_STATCNT(afs_Analyze);
394     afs_Trace4(afs_iclSetp, CM_TRACE_ANALYZE, ICL_TYPE_INT32, op,
395                ICL_TYPE_POINTER, aconn, ICL_TYPE_INT32, acode, ICL_TYPE_LONG,
396                areq->uid);
397
398     aerrP = (struct afs_stats_RPCErrors *)0;
399
400     if ((op >= 0) && (op < AFS_STATS_NUM_FS_RPC_OPS))
401         aerrP = &(afs_stats_cmfullperf.rpc.fsRPCErrors[op]);
402
403     afs_FinalizeReq(areq);
404     if (!aconn && areq->busyCount) {    /* one RPC or more got VBUSY/VRESTARTING */
405
406         tvp = afs_FindVolume(afid, READ_LOCK);
407         if (tvp) {
408             afs_warnuser("afs: Waiting for busy volume %u (%s) in cell %s\n",
409                          (afid ? afid->Fid.Volume : 0),
410                          (tvp->name ? tvp->name : ""),
411                          ((tvp->serverHost[0]
412                            && tvp->serverHost[0]->cell) ? tvp->serverHost[0]->
413                           cell->cellName : ""));
414
415             for (i = 0; i < AFS_MAXHOSTS; i++) {
416                 if (tvp->status[i] != not_busy && tvp->status[i] != offline) {
417                     tvp->status[i] = not_busy;
418                 }
419                 if (tvp->status[i] == not_busy)
420                     shouldRetry = 1;
421             }
422             afs_PutVolume(tvp, READ_LOCK);
423         } else {
424             afs_warnuser("afs: Waiting for busy volume %u\n",
425                          (afid ? afid->Fid.Volume : 0));
426         }
427
428         if (areq->busyCount > 100) {
429             if (aerrP)
430                 (aerrP->err_Volume)++;
431             areq->volumeError = VOLBUSY;
432             shouldRetry = 0;
433         } else {
434             VSleep(afs_BusyWaitPeriod); /* poll periodically */
435         }
436         if (shouldRetry != 0)
437             areq->busyCount++;
438
439         return shouldRetry;     /* should retry */
440     }
441
442     if (!aconn || !aconn->parent->srvr) {
443         if (!areq->volumeError) {
444             if (aerrP)
445                 (aerrP->err_Network)++;
446             if (hm_retry_int && !(areq->flags & O_NONBLOCK) &&  /* "hard" mount */
447                 ((afid && afs_IsPrimaryCellNum(afid->Cell))
448                  || (cellp && afs_IsPrimaryCell(cellp)))) {
449                 if (!afid) {
450                     static int afs_vl_hm = 0;
451                     int warn = 0;
452                     if (!afs_vl_hm) {
453                         afs_vl_hm = warn = 1;
454                     }
455                     if (warn) {
456                         afs_warnuser
457                             ("afs: hard-mount waiting for a vlserver to return to service\n");
458                     }
459                     VSleep(hm_retry_int);
460                     afs_CheckServers(1, cellp);
461                     shouldRetry = 1;
462
463                     if (warn) {
464                         afs_vl_hm = 0;
465                     }
466                 } else {
467                     static int afs_unknown_vhm = 0;
468                     int warn = 0, vp_vhm = 0;
469
470                     tvp = afs_FindVolume(afid, READ_LOCK);
471                     if (!tvp || (tvp->states & VRO)) {
472                         shouldRetry = hm_retry_RO;
473                     } else {
474                         shouldRetry = hm_retry_RW;
475                     }
476
477                     /* Set 'warn' if we should afs_warnuser. Only let one
478                      * caller call afs_warnuser per hm_retry_int interval per
479                      * volume. */
480                     if (shouldRetry) {
481                         if (tvp) {
482                             if (!(tvp->states & VHardMount)) {
483                                 tvp->states |= VHardMount;
484                                 warn = vp_vhm = 1;
485                             }
486                         } else {
487                             if (!afs_unknown_vhm) {
488                                 afs_unknown_vhm = 1;
489                                 warn = 1;
490                             }
491                         }
492                     }
493
494                     if (tvp)
495                         afs_PutVolume(tvp, READ_LOCK);
496
497                     if (shouldRetry) {
498                         if (warn) {
499                             afs_warnuser
500                                 ("afs: hard-mount waiting for volume %u\n",
501                                  afid->Fid.Volume);
502                         }
503
504                         VSleep(hm_retry_int);
505                         afs_CheckServers(1, cellp);
506                         /* clear the black listed servers on this request. */
507                         memset(areq->skipserver, 0, sizeof(areq->skipserver));
508
509                         if (vp_vhm) {
510                             tvp = afs_FindVolume(afid, READ_LOCK);
511                             if (tvp) {
512                                 tvp->states &= ~VHardMount;
513                                 afs_PutVolume(tvp, READ_LOCK);
514                             }
515                         } else if (warn) {
516                             afs_unknown_vhm = 0;
517                         }
518                     }
519                 }
520             } /* if (hm_retry_int ... */
521             else {
522                 if (acode == RX_MSGSIZE)
523                     shouldRetry = 1;
524                 else {
525                     areq->networkError = 1;
526                     /* do not promote to shouldRetry if not already */
527                     if (afs_ClearStatus(afid, op, NULL) == 0)
528                         shouldRetry = 0;
529                 }
530             }
531         }
532         return shouldRetry;
533     }
534
535     /* Find server associated with this connection. */
536     sa = aconn->parent->srvr;
537     tsp = sa->server;
538     address = ntohl(sa->sa_ip);
539
540     /* Before we do anything with acode, make sure we translate it back to
541      * a system error */
542     if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
543         acode = et_to_sys_error(acode);
544
545     if (acode == 0) {
546         /* If we previously took an error, mark this volume not busy */
547         if (areq->volumeError) {
548             tvp = afs_FindVolume(afid, READ_LOCK);
549             if (tvp) {
550                 for (i = 0; i < AFS_MAXHOSTS; i++) {
551                     if (tvp->serverHost[i] == tsp) {
552                         tvp->status[i] = not_busy;
553                     }
554                 }
555                 afs_PutVolume(tvp, READ_LOCK);
556             }
557         }
558
559         afs_PutConn(aconn, rxconn, locktype);
560         return 0;
561     }
562
563     /* If network troubles, mark server as having bogued out again. */
564     /* VRESTARTING is < 0 because of backward compatibility issues
565      * with 3.4 file servers and older cache managers */
566 #ifdef AFS_64BIT_CLIENT
567     if (acode == -455)
568         acode = 455;
569 #endif /* AFS_64BIT_CLIENT */
570     if ((acode < 0) && (acode != VRESTARTING)) {
571         if (acode == RX_MSGSIZE || acode == RX_CALL_BUSY) {
572             shouldRetry = 1;
573             goto out;
574         }
575         if (acode == RX_CALL_TIMEOUT || acode == RX_CALL_IDLE) {
576             serversleft = afs_BlackListOnce(areq, afid, tsp);
577             if (afid)
578                 tvp = afs_FindVolume(afid, READ_LOCK);
579             if ((serversleft == 0) && tvp &&
580                 ((tvp->states & VRO) || (tvp->states & VBackup))) {
581                 shouldRetry = 0;
582             } else {
583                 shouldRetry = 1;
584             }
585             if (!afid || !tvp || (tvp->states & VRO))
586                 areq->idleError++;
587             else if (afs_ClearStatus(afid, op, tvp) == 0)
588                 shouldRetry = 0;
589
590             if (tvp)
591                 afs_PutVolume(tvp, READ_LOCK);
592             /* By doing this, we avoid ever marking a server down
593              * in an idle timeout case. That's because the server is
594              * still responding and may only be letting a single vnode
595              * time out. We otherwise risk having the server continually
596              * be marked down, then up, then down again...
597              */
598             goto out;
599         }
600         afs_ServerDown(sa, acode);
601         ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
602         if (aerrP)
603             (aerrP->err_Server)++;
604     }
605
606     if (acode == VBUSY || acode == VRESTARTING) {
607         if (acode == VBUSY) {
608             areq->busyCount++;
609             if (aerrP)
610                 (aerrP->err_VolumeBusies)++;
611         } else
612             areq->busyCount = 1;
613
614         tvp = afs_FindVolume(afid, READ_LOCK);
615         if (tvp) {
616             for (i = 0; i < AFS_MAXHOSTS; i++) {
617                 if (tvp->serverHost[i] == tsp) {
618                     tvp->status[i] = rdwr_busy; /* can't tell which yet */
619                     /* to tell which, have to look at the op code. */
620                 }
621             }
622             afs_PutVolume(tvp, READ_LOCK);
623         } else {
624             afs_warnuser("afs: Waiting for busy volume %u in cell %s (server %d.%d.%d.%d)\n",
625                          (afid ? afid->Fid.Volume : 0), tsp->cell->cellName,
626                          (address >> 24), (address >> 16) & 0xff,
627                          (address >> 8) & 0xff, (address) & 0xff);
628             VSleep(afs_BusyWaitPeriod); /* poll periodically */
629         }
630         shouldRetry = 1;
631         acode = 0;
632     } else if (acode == VICETOKENDEAD
633                || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
634         /* any rxkad error is treated as token expiration */
635         struct unixuser *tu;
636         /*
637          * I'm calling these errors protection errors, since they involve
638          * faulty authentication.
639          */
640         if (aerrP)
641             (aerrP->err_Protection)++;
642
643         tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
644         if (tu) {
645             if (acode == VICETOKENDEAD) {
646                 aconn->forceConnectFS = 1;
647             } else if (acode == RXKADEXPIRED) {
648                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
649                 aconn->parent->user->states |= UTokensBad;
650                 afs_NotifyUser(tu, UTokensDropped);
651                 afs_warnuser
652                     ("afs: Tokens for user of AFS id %d for cell %s have expired (server %d.%d.%d.%d)\n",
653                      tu->viceId, aconn->parent->srvr->server->cell->cellName,
654                      (address >> 24), (address >> 16) & 0xff,
655                      (address >> 8) & 0xff, (address) & 0xff);
656             } else {
657                 serversleft = afs_BlackListOnce(areq, afid, tsp);
658                 areq->tokenError++;
659
660                 if (serversleft) {
661                     afs_warnuser
662                         ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d (server %d.%d.%d.%d)\n",
663                          tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
664                          (address >> 24), (address >> 16) & 0xff,
665                          (address >> 8) & 0xff, (address) & 0xff);
666                     shouldRetry = 1;
667                 } else {
668                     areq->tokenError = 0;
669                     aconn->forceConnectFS = 0;  /* don't check until new tokens set */
670                     aconn->parent->user->states |= UTokensBad;
671                     afs_NotifyUser(tu, UTokensDropped);
672                     afs_warnuser
673                         ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d, server %d.%d.%d.%d)\n",
674                          tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
675                          (address >> 24), (address >> 16) & 0xff,
676                          (address >> 8) & 0xff, (address) & 0xff);
677                 }
678             }
679             afs_PutUser(tu, READ_LOCK);
680         } else {
681             /* The else case shouldn't be possible and should probably be replaced by a panic? */
682             if (acode == VICETOKENDEAD) {
683                 aconn->forceConnectFS = 1;
684             } else if (acode == RXKADEXPIRED) {
685                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
686                 aconn->parent->user->states |= UTokensBad;
687                 afs_NotifyUser(tu, UTokensDropped);
688                 afs_warnuser
689                     ("afs: Tokens for user %d for cell %s have expired (server %d.%d.%d.%d)\n",
690                      areq->uid, aconn->parent->srvr->server->cell->cellName,
691                      (address >> 24), (address >> 16) & 0xff,
692                      (address >> 8) & 0xff, (address) & 0xff);
693             } else {
694                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
695                 aconn->parent->user->states |= UTokensBad;
696                 afs_NotifyUser(tu, UTokensDropped);
697                 afs_warnuser
698                     ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d, server %d.%d.%d.%d)\n",
699                      areq->uid, aconn->parent->srvr->server->cell->cellName,
700                      acode,
701                      (address >> 24), (address >> 16) & 0xff,
702                      (address >> 8) & 0xff, (address) & 0xff);
703
704             }
705         }
706         shouldRetry = 1;        /* Try again (as root). */
707     }
708     /* Check for access violation. */
709     else if (acode == EACCES) {
710         /* should mark access error in non-existent per-user global structure */
711         if (aerrP)
712             (aerrP->err_Protection)++;
713         areq->accessError = 1;
714         if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
715             areq->permWriteError = 1;
716         shouldRetry = 0;
717     }
718     /* check for ubik errors; treat them like crashed servers */
719     else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
720         afs_ServerDown(sa, acode);
721         if (aerrP)
722             (aerrP->err_Server)++;
723         shouldRetry = 1;        /* retryable (maybe one is working) */
724         VSleep(1);              /* just in case */
725     }
726     /* Check for bad volume data base / missing volume. */
727     else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
728              || acode == VNOSERVICE || acode == VMOVED) {
729         struct cell *tcell;
730         int same;
731
732         shouldRetry = 1;
733         areq->volumeError = VOLMISSING;
734         if (aerrP)
735             (aerrP->err_Volume)++;
736         if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
737             same = VLDB_Same(afid, areq);
738             tvp = afs_FindVolume(afid, READ_LOCK);
739             if (tvp) {
740                 for (i = 0; i < AFS_MAXHOSTS && tvp->serverHost[i]; i++) {
741                     if (tvp->serverHost[i] == tsp) {
742                         if (tvp->status[i] == end_not_busy)
743                             tvp->status[i] = offline;
744                         else
745                             tvp->status[i]++;
746                     } else if (!same) {
747                         tvp->status[i] = not_busy;      /* reset the others */
748                     }
749                 }
750                 afs_PutVolume(tvp, READ_LOCK);
751             }
752         }
753     } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) {    /* vlserver errors */
754         shouldRetry = 0;
755         areq->volumeError = VOLMISSING;
756     } else if (acode >= 0) {
757         if (aerrP)
758             (aerrP->err_Other)++;
759         if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
760             areq->permWriteError = 1;
761         shouldRetry = 0;        /* Other random Vice error. */
762     } else if (acode == RX_MSGSIZE) {   /* same meaning as EMSGSIZE... */
763         afs_warnuser
764             ("afs: Path MTU may have been exceeded, retrying (server %d.%d.%d.%d)\n",
765              (address >> 24), (address >> 16) & 0xff,
766              (address >> 8) & 0xff, (address) & 0xff);
767
768         VSleep(1);              /* Just a hack for desperate times. */
769         if (aerrP)
770             (aerrP->err_Other)++;
771         shouldRetry = 1;        /* packet was too big, please retry call */
772     }
773
774     if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
775         /* If we get here, code < 0 and we have network/Server troubles.
776          * areq->networkError is not set here, since we always
777          * retry in case there is another server.  However, if we find
778          * no connection (aconn == 0) we set the networkError flag.
779          */
780         afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
781         if (aerrP)
782             (aerrP->err_Server)++;
783         VSleep(1);              /* Just a hack for desperate times. */
784         shouldRetry = 1;
785     }
786 out:
787     /* now unlock the connection and return */
788     afs_PutConn(aconn, rxconn, locktype);
789     return (shouldRetry);
790 }                               /*afs_Analyze */