Unix CM: reset blacklist on hard-mount retry
[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                         /* clear the black listed servers on this request. */
449                         memset(areq->skipserver, 0, sizeof(areq->skipserver));
450
451                         if (vp_vhm) {
452                             tvp = afs_FindVolume(afid, READ_LOCK);
453                             if (tvp) {
454                                 tvp->states &= ~VHardMount;
455                                 afs_PutVolume(tvp, READ_LOCK);
456                             }
457                         } else if (warn) {
458                             afs_unknown_vhm = 0;
459                         }
460                     }
461                 }
462             } /* if (hm_retry_int ... */
463             else {
464                 if (acode == RX_MSGSIZE)
465                     shouldRetry = 1;
466                 else
467                     areq->networkError = 1;
468             }
469         }
470         return shouldRetry;
471     }
472
473     /* Find server associated with this connection. */
474     sa = aconn->parent->srvr;
475     tsp = sa->server;
476     address = ntohl(sa->sa_ip);
477
478     /* Before we do anything with acode, make sure we translate it back to
479      * a system error */
480     if ((acode & ~0xff) == ERROR_TABLE_BASE_uae)
481         acode = et_to_sys_error(acode);
482
483     if (acode == 0) {
484         /* If we previously took an error, mark this volume not busy */
485         if (areq->volumeError) {
486             tvp = afs_FindVolume(afid, READ_LOCK);
487             if (tvp) {
488                 for (i = 0; i < AFS_MAXHOSTS; i++) {
489                     if (tvp->serverHost[i] == tsp) {
490                         tvp->status[i] = not_busy;
491                     }
492                 }
493                 afs_PutVolume(tvp, READ_LOCK);
494             }
495         }
496
497         afs_PutConn(aconn, rxconn, locktype);
498         return 0;
499     }
500
501     /* If network troubles, mark server as having bogued out again. */
502     /* VRESTARTING is < 0 because of backward compatibility issues
503      * with 3.4 file servers and older cache managers */
504 #ifdef AFS_64BIT_CLIENT
505     if (acode == -455)
506         acode = 455;
507 #endif /* AFS_64BIT_CLIENT */
508     if ((acode < 0) && (acode != VRESTARTING)) {
509         if (acode == RX_MSGSIZE) {
510             shouldRetry = 1;
511             goto out;
512         }
513         if (acode == RX_CALL_TIMEOUT) {
514             serversleft = afs_BlackListOnce(areq, afid, tsp);
515             if (afid)
516                 tvp = afs_FindVolume(afid, READ_LOCK);
517             if (!afid || !tvp || (tvp->states & VRO))
518                 areq->idleError++;
519             if ((serversleft == 0) && tvp &&
520                 ((tvp->states & VRO) || (tvp->states & VBackup))) {
521                 shouldRetry = 0;
522             } else {
523                 shouldRetry = 1;
524             }
525             if (tvp)
526                 afs_PutVolume(tvp, READ_LOCK);
527             /* By doing this, we avoid ever marking a server down
528              * in an idle timeout case. That's because the server is
529              * still responding and may only be letting a single vnode
530              * time out. We otherwise risk having the server continually
531              * be marked down, then up, then down again...
532              */
533             goto out;
534         }
535         afs_ServerDown(sa, acode);
536         ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
537         if (aerrP)
538             (aerrP->err_Server)++;
539     }
540
541     if (acode == VBUSY || acode == VRESTARTING) {
542         if (acode == VBUSY) {
543             areq->busyCount++;
544             if (aerrP)
545                 (aerrP->err_VolumeBusies)++;
546         } else
547             areq->busyCount = 1;
548
549         tvp = afs_FindVolume(afid, READ_LOCK);
550         if (tvp) {
551             for (i = 0; i < AFS_MAXHOSTS; i++) {
552                 if (tvp->serverHost[i] == tsp) {
553                     tvp->status[i] = rdwr_busy; /* can't tell which yet */
554                     /* to tell which, have to look at the op code. */
555                 }
556             }
557             afs_PutVolume(tvp, READ_LOCK);
558         } else {
559             afs_warnuser("afs: Waiting for busy volume %u in cell %s (server %d.%d.%d.%d)\n",
560                          (afid ? afid->Fid.Volume : 0), tsp->cell->cellName,
561                          (address >> 24), (address >> 16) & 0xff,
562                          (address >> 8) & 0xff, (address) & 0xff);
563             VSleep(afs_BusyWaitPeriod); /* poll periodically */
564         }
565         shouldRetry = 1;
566         acode = 0;
567     } else if (acode == VICETOKENDEAD
568                || (acode & ~0xff) == ERROR_TABLE_BASE_RXK) {
569         /* any rxkad error is treated as token expiration */
570         struct unixuser *tu;
571         /*
572          * I'm calling these errors protection errors, since they involve
573          * faulty authentication.
574          */
575         if (aerrP)
576             (aerrP->err_Protection)++;
577
578         tu = afs_FindUser(areq->uid, tsp->cell->cellNum, READ_LOCK);
579         if (tu) {
580             if (acode == VICETOKENDEAD) {
581                 aconn->forceConnectFS = 1;
582             } else if (acode == RXKADEXPIRED) {
583                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
584                 aconn->parent->user->states |= UTokensBad;
585                 afs_NotifyUser(tu, UTokensDropped);
586                 afs_warnuser
587                     ("afs: Tokens for user of AFS id %d for cell %s have expired (server %d.%d.%d.%d)\n",
588                      tu->viceId, aconn->parent->srvr->server->cell->cellName,
589                      (address >> 24), (address >> 16) & 0xff,
590                      (address >> 8) & 0xff, (address) & 0xff);
591             } else {
592                 serversleft = afs_BlackListOnce(areq, afid, tsp);
593                 areq->tokenError++;
594
595                 if (serversleft) {
596                     afs_warnuser
597                         ("afs: Tokens for user of AFS id %d for cell %s: rxkad error=%d (server %d.%d.%d.%d)\n",
598                          tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
599                          (address >> 24), (address >> 16) & 0xff,
600                          (address >> 8) & 0xff, (address) & 0xff);
601                     shouldRetry = 1;
602                 } else {
603                     areq->tokenError = 0;
604                     aconn->forceConnectFS = 0;  /* don't check until new tokens set */
605                     aconn->parent->user->states |= UTokensBad;
606                     afs_NotifyUser(tu, UTokensDropped);
607                     afs_warnuser
608                         ("afs: Tokens for user of AFS id %d for cell %s are discarded (rxkad error=%d, server %d.%d.%d.%d)\n",
609                          tu->viceId, aconn->parent->srvr->server->cell->cellName, acode,
610                          (address >> 24), (address >> 16) & 0xff,
611                          (address >> 8) & 0xff, (address) & 0xff);
612                 }
613             }
614             afs_PutUser(tu, READ_LOCK);
615         } else {
616             /* The else case shouldn't be possible and should probably be replaced by a panic? */
617             if (acode == VICETOKENDEAD) {
618                 aconn->forceConnectFS = 1;
619             } else if (acode == RXKADEXPIRED) {
620                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
621                 aconn->parent->user->states |= UTokensBad;
622                 afs_NotifyUser(tu, UTokensDropped);
623                 afs_warnuser
624                     ("afs: Tokens for user %d for cell %s have expired (server %d.%d.%d.%d)\n",
625                      areq->uid, aconn->parent->srvr->server->cell->cellName,
626                      (address >> 24), (address >> 16) & 0xff,
627                      (address >> 8) & 0xff, (address) & 0xff);
628             } else {
629                 aconn->forceConnectFS = 0;      /* don't check until new tokens set */
630                 aconn->parent->user->states |= UTokensBad;
631                 afs_NotifyUser(tu, UTokensDropped);
632                 afs_warnuser
633                     ("afs: Tokens for user %d for cell %s are discarded (rxkad error = %d, server %d.%d.%d.%d)\n",
634                      areq->uid, aconn->parent->srvr->server->cell->cellName,
635                      acode,
636                      (address >> 24), (address >> 16) & 0xff,
637                      (address >> 8) & 0xff, (address) & 0xff);
638
639             }
640         }
641         shouldRetry = 1;        /* Try again (as root). */
642     }
643     /* Check for access violation. */
644     else if (acode == EACCES) {
645         /* should mark access error in non-existent per-user global structure */
646         if (aerrP)
647             (aerrP->err_Protection)++;
648         areq->accessError = 1;
649         if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
650             areq->permWriteError = 1;
651         shouldRetry = 0;
652     }
653     /* check for ubik errors; treat them like crashed servers */
654     else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
655         afs_ServerDown(sa, acode);
656         if (aerrP)
657             (aerrP->err_Server)++;
658         shouldRetry = 1;        /* retryable (maybe one is working) */
659         VSleep(1);              /* just in case */
660     }
661     /* Check for bad volume data base / missing volume. */
662     else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
663              || acode == VNOSERVICE || acode == VMOVED) {
664         struct cell *tcell;
665         int same;
666
667         shouldRetry = 1;
668         areq->volumeError = VOLMISSING;
669         if (aerrP)
670             (aerrP->err_Volume)++;
671         if (afid && (tcell = afs_GetCell(afid->Cell, 0))) {
672             same = VLDB_Same(afid, areq);
673             tvp = afs_FindVolume(afid, READ_LOCK);
674             if (tvp) {
675                 for (i = 0; i < AFS_MAXHOSTS && tvp->serverHost[i]; i++) {
676                     if (tvp->serverHost[i] == tsp) {
677                         if (tvp->status[i] == end_not_busy)
678                             tvp->status[i] = offline;
679                         else
680                             tvp->status[i]++;
681                     } else if (!same) {
682                         tvp->status[i] = not_busy;      /* reset the others */
683                     }
684                 }
685                 afs_PutVolume(tvp, READ_LOCK);
686             }
687         }
688     } else if (acode >= ERROR_TABLE_BASE_VL && acode <= ERROR_TABLE_BASE_VL + 255) {    /* vlserver errors */
689         shouldRetry = 0;
690         areq->volumeError = VOLMISSING;
691     } else if (acode >= 0) {
692         if (aerrP)
693             (aerrP->err_Other)++;
694         if (op == AFS_STATS_FS_RPCIDX_STOREDATA)
695             areq->permWriteError = 1;
696         shouldRetry = 0;        /* Other random Vice error. */
697     } else if (acode == RX_MSGSIZE) {   /* same meaning as EMSGSIZE... */
698         afs_warnuser
699             ("afs: Path MTU may have been exceeded, retrying (server %d.%d.%d.%d)\n",
700              (address >> 24), (address >> 16) & 0xff,
701              (address >> 8) & 0xff, (address) & 0xff);
702
703         VSleep(1);              /* Just a hack for desperate times. */
704         if (aerrP)
705             (aerrP->err_Other)++;
706         shouldRetry = 1;        /* packet was too big, please retry call */
707     }
708
709     if (acode < 0 && acode != RX_MSGSIZE && acode != VRESTARTING) {
710         /* If we get here, code < 0 and we have network/Server troubles.
711          * areq->networkError is not set here, since we always
712          * retry in case there is another server.  However, if we find
713          * no connection (aconn == 0) we set the networkError flag.
714          */
715         afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
716         if (aerrP)
717             (aerrP->err_Server)++;
718         VSleep(1);              /* Just a hack for desperate times. */
719         shouldRetry = 1;
720     }
721 out:
722     /* now unlock the connection and return */
723     afs_PutConn(aconn, rxconn, locktype);
724     return (shouldRetry);
725 }                               /*afs_Analyze */