Bug Summary

File:dviced/./../viced/callback.c
Location:line 1058, column 28
Description:Access to field 'volid' results in a dereference of a null pointer (loaded from variable 'fe')

Annotated Source Code

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 * Portions Copyright (c) 2006 Sine Nomine Associates
10 */
11
12/*
13 * NEW callback package callback.c (replaces vicecb.c)
14 * Updated call back routines, NOW with:
15 *
16 * Faster DeleteVenus (Now called DeleteAllCallBacks)
17 * Call back breaking for volumes
18 * Adaptive timeouts on call backs
19 * Architected for Multi RPC
20 * No locks (currently implicit vnode locks--these will go, to)
21 * Delayed call back when rpc connection down.
22 * Bulk break of delayed call backs when rpc connection
23 * reestablished
24 * Strict limit on number of call backs.
25 *
26 * InitCallBack(nblocks)
27 * Initialize: nblocks is max number # of file entries + # of callback entries
28 * nblocks must be < 65536
29 * Space used is nblocks*16 bytes
30 * Note that space will be reclaimed by breaking callbacks of old hosts
31 *
32 * time = AddCallBack(host, fid)
33 * Add a call back.
34 * Returns the expiration time at the workstation.
35 *
36 * BreakCallBack(host, fid)
37 * Break all call backs for fid, except for the specified host.
38 * Delete all of them.
39 *
40 * BreakVolumeCallBacksLater(volume)
41 * Break all call backs on volume, using single call to each host
42 * Delete all the call backs.
43 *
44 * DeleteCallBack(host,fid)
45 * Delete (do not break) single call back for fid.
46 *
47 * DeleteFileCallBacks(fid)
48 * Delete (do not break) all call backs for fid.
49 *
50 * DeleteAllCallBacks(host)
51 * Delete (do not break) all call backs for host.
52 *
53 * CleanupTimedOutCallBacks()
54 * Delete all timed out call back entries
55 * Must be called periodically by file server.
56 *
57 * BreakDelayedCallBacks(host)
58 * Break all delayed call backs for host.
59 * Returns 1: one or more failed, 0: success.
60 *
61 * PrintCallBackStats()
62 * Print statistics about call backs to stdout.
63 *
64 * DumpCallBacks() ---wishful thinking---
65 * Dump call back state to /tmp/callback.state.
66 * This is separately interpretable by the program pcb.
67 *
68 * Notes: In general, if a call back to a host doesn't get through,
69 * then HostDown, supplied elsewhere, is called. BreakDelayedCallBacks,
70 * however, does not call HostDown, but instead returns an indication of
71 * success if all delayed call backs were finally broken.
72 *
73 * BreakDelayedCallBacks MUST be called at the first sign of activity
74 * from the host after HostDown has been called (or a previous
75 * BreakDelayedCallBacks failed). The BreakDelayedCallBacks must be
76 * allowed to complete before any requests from that host are handled.
77 * If BreakDelayedCallBacks fails, then the host should remain
78 * down (and the request should be failed).
79
80 * CleanupCallBacks MUST be called periodically by the file server for
81 * this package to work correctly. Every 5 minutes is suggested.
82 */
83
84#include <afsconfig.h>
85#include <afs/param.h>
86#include <afs/stds.h>
87
88#include <roken.h>
89
90#ifdef HAVE_SYS_FILE_H1
91#include <sys/file.h>
92#endif
93
94#include <afs/afs_assert.h>
95
96#include <afs/nfs.h> /* yuck. This is an abomination. */
97#include <lwp.h>
98#include <rx/rx.h>
99#include <afs/afscbint.h>
100#include <afs/afsutil.h>
101#include <lock.h>
102#include <afs/ihandle.h>
103#include <afs/vnode.h>
104#include <afs/volume.h>
105#include "viced_prototypes.h"
106#include "viced.h"
107
108#include <afs/ptclient.h> /* need definition of prlist for host.h */
109#include "host.h"
110#include "callback.h"
111#ifdef AFS_DEMAND_ATTACH_FS1
112#include "../tviced/serialize_state.h"
113#endif /* AFS_DEMAND_ATTACH_FS */
114
115
116extern afsUUID FS_HostUUID;
117extern int hostCount;
118
119#ifndef INTERPRET_DUMP
120static int ShowProblems = 1;
121#endif
122
123struct cbcounters cbstuff;
124
125static struct FileEntry * FE = NULL((void *)0); /* don't use FE[0] */
126static struct CallBack * CB = NULL((void *)0); /* don't use CB[0] */
127
128static struct CallBack * CBfree = NULL((void *)0);
129static struct FileEntry * FEfree = NULL((void *)0);
130
131
132/* Time to live for call backs depends upon number of users of the file.
133 * TimeOuts is indexed by this number/8 (using TimeOut macro). Times
134 * in this table are for the workstation; server timeouts, add
135 * ServerBias */
136
137static int TimeOuts[] = {
138/* Note: don't make the first entry larger than 4 hours (see above) */
139 4 * 60 * 60, /* 0-7 users */
140 1 * 60 * 60, /* 8-15 users */
141 30 * 60, /* 16-23 users */
142 15 * 60, /* 24-31 users */
143 15 * 60, /* 32-39 users */
144 10 * 60, /* 40-47 users */
145 10 * 60, /* 48-55 users */
146 10 * 60, /* 56-63 users */
147}; /* Anything more: MinTimeOut */
148
149/* minimum time given for a call back */
150#ifndef INTERPRET_DUMP
151static int MinTimeOut = (7 * 60);
152#endif
153
154/* Heads of CB queues; a timeout index is 1+index into this array */
155static afs_uint32 timeout[CB_NUM_TIMEOUT_QUEUES128];
156
157static afs_int32 tfirst; /* cbtime of oldest unexpired call back time queue */
158
159
160/* 16 byte object get/free routines */
161struct object {
162 struct object *next;
163};
164
165/* Prototypes for static routines */
166static struct FileEntry *FindFE(AFSFid * fid);
167
168#ifndef INTERPRET_DUMP
169static struct CallBack *iGetCB(int *nused);
170static int iFreeCB(struct CallBack *cb, int *nused);
171static struct FileEntry *iGetFE(int *nused);
172static int iFreeFE(struct FileEntry *fe, int *nused);
173static int TAdd(struct CallBack *cb, afs_uint32 * thead);
174static int TDel(struct CallBack *cb);
175static int HAdd(struct CallBack *cb, struct host *host);
176static int HDel(struct CallBack *cb);
177static int CDel(struct CallBack *cb, int deletefe);
178static int CDelPtr(struct FileEntry *fe, afs_uint32 * cbp,
179 int deletefe);
180static afs_uint32 *FindCBPtr(struct FileEntry *fe, struct host *host);
181static int FDel(struct FileEntry *fe);
182static int AddCallBack1_r(struct host *host, AFSFid * fid, afs_uint32 * thead,
183 int type, int locked);
184static void MultiBreakCallBack_r(struct cbstruct cba[], int ncbas,
185 struct AFSCBFids *afidp);
186static int MultiBreakVolumeCallBack_r(struct host *host,
187 struct VCBParams *parms, int deletefe);
188static int MultiBreakVolumeLaterCallBack(struct host *host, void *rock);
189static int GetSomeSpace_r(struct host *hostp, int locked);
190static int ClearHostCallbacks_r(struct host *hp, int locked);
191static int DumpCallBackState_r(void);
192#endif
193
194#define GetCB()((struct CallBack *)iGetCB(&cbstuff.nCBs)) ((struct CallBack *)iGetCB(&cbstuff.nCBs))
195#define GetFE()((struct FileEntry *)iGetFE(&cbstuff.nFEs)) ((struct FileEntry *)iGetFE(&cbstuff.nFEs))
196#define FreeCB(cb)iFreeCB((struct CallBack *)cb, &cbstuff.nCBs) iFreeCB((struct CallBack *)cb, &cbstuff.nCBs)
197#define FreeFE(fe)iFreeFE((struct FileEntry *)fe, &cbstuff.nFEs) iFreeFE((struct FileEntry *)fe, &cbstuff.nFEs)
198
199
200/* Other protos - move out sometime */
201void PrintCB(struct CallBack *cb, afs_uint32 now);
202
203static afs_uint32 HashTable[FEHASH_SIZE512]; /* File entry hash table */
204
205static struct FileEntry *
206FindFE(AFSFid * fid)
207{
208 int hash;
209 int fei;
210 struct FileEntry *fe;
211
212 hash = FEHash(fid->Volume, fid->Unique)(((fid->Volume)+(fid->Unique))&((512 -1)));
213 for (fei = HashTable[hash]; fei; fei = fe->fnext) {
214 fe = itofe(fei)((fei)?FE+(fei):0);
215 if (fe->volid == fid->Volume && fe->unique == fid->Unique
216 && fe->vnode == fid->Vnode && (fe->status & FE_LATER0x1) != FE_LATER0x1)
217 return fe;
218 }
219 return 0;
220}
221
222#ifndef INTERPRET_DUMP
223
224static struct CallBack *
225iGetCB(int *nused)
226{
227 struct CallBack *ret;
228
229 if ((ret = CBfree)) {
230 CBfree = (struct CallBack *)(((struct object *)ret)->next);
231 (*nused)++;
232 }
233 return ret;
234}
235
236static int
237iFreeCB(struct CallBack *cb, int *nused)
238{
239 ((struct object *)cb)->next = (struct object *)CBfree;
240 CBfree = cb;
241 (*nused)--;
242 return 0;
243}
244
245static struct FileEntry *
246iGetFE(int *nused)
247{
248 struct FileEntry *ret;
249
250 if ((ret = FEfree)) {
251 FEfree = (struct FileEntry *)(((struct object *)ret)->next);
252 (*nused)++;
253 }
254 return ret;
255}
256
257static int
258iFreeFE(struct FileEntry *fe, int *nused)
259{
260 ((struct object *)fe)->next = (struct object *)FEfree;
261 FEfree = fe;
262 (*nused)--;
263 return 0;
264}
265
266/* Add cb to end of specified timeout list */
267static int
268TAdd(struct CallBack *cb, afs_uint32 * thead)
269{
270 if (!*thead) {
271 (*thead) = cb->tnext = cb->tprev = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB));
272 } else {
273 struct CallBack *thp = itocb(*thead)((*thead)?CB+(*thead):0);
274
275 cb->tprev = thp->tprev;
276 cb->tnext = *thead;
277 if (thp) {
278 if (thp->tprev)
279 thp->tprev = (itocb(thp->tprev)((thp->tprev)?CB+(thp->tprev):0)->tnext = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB)));
280 else
281 thp->tprev = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB));
282 }
283 }
284 cb->thead = ttoi(thead)((thead-timeout)+1);
285 return 0;
286}
287
288/* Delete call back entry from timeout list */
289static int
290TDel(struct CallBack *cb)
291{
292 afs_uint32 *thead = itot(cb->thead)((timeout)+(cb->thead-1));
293
294 if (*thead == cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB)))
295 *thead = (*thead == cb->tnext ? 0 : cb->tnext);
296 if (itocb(cb->tprev)((cb->tprev)?CB+(cb->tprev):0))
297 itocb(cb->tprev)((cb->tprev)?CB+(cb->tprev):0)->tnext = cb->tnext;
298 if (itocb(cb->tnext)((cb->tnext)?CB+(cb->tnext):0))
299 itocb(cb->tnext)((cb->tnext)?CB+(cb->tnext):0)->tprev = cb->tprev;
300 return 0;
301}
302
303/* Add cb to end of specified host list */
304static int
305HAdd(struct CallBack *cb, struct host *host)
306{
307 cb->hhead = h_htoi(host)((host)->index);
308 if (!host->cblist) {
309 host->cblist = cb->hnext = cb->hprev = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB));
310 } else {
311 struct CallBack *fcb = itocb(host->cblist)((host->cblist)?CB+(host->cblist):0);
312
313 cb->hprev = fcb->hprev;
314 cb->hnext = cbtoi(fcb)((afs_uint32)(!(fcb)?0:(fcb)-CB));
315 fcb->hprev = (itocb(fcb->hprev)((fcb->hprev)?CB+(fcb->hprev):0)->hnext = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB)));
316 }
317 return 0;
318}
319
320/* Delete call back entry from host list */
321static int
322HDel(struct CallBack *cb)
323{
324 afs_uint32 *hhead = &h_itoh(cb->hhead)(hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&(
512 -1)))
->cblist;
325
326 if (*hhead == cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB)))
327 *hhead = (*hhead == cb->hnext ? 0 : cb->hnext);
328 itocb(cb->hprev)((cb->hprev)?CB+(cb->hprev):0)->hnext = cb->hnext;
329 itocb(cb->hnext)((cb->hnext)?CB+(cb->hnext):0)->hprev = cb->hprev;
330 return 0;
331}
332
333/* Delete call back entry from fid's chain of cb's */
334/* N.B. This one also deletes the CB, and also possibly parent FE, so
335 * make sure that it is not on any other list before calling this
336 * routine */
337static int
338CDel(struct CallBack *cb, int deletefe)
339{
340 int cbi = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB));
341 struct FileEntry *fe = itofe(cb->fhead)((cb->fhead)?FE+(cb->fhead):0);
342 afs_uint32 *cbp;
343 int safety;
344
345 for (safety = 0, cbp = &fe->firstcb; *cbp && *cbp != cbi;
346 cbp = &itocb(*cbp)((*cbp)?CB+(*cbp):0)->cnext, safety++) {
347 if (safety > cbstuff.nblks + 10) {
348 ViceLogThenPanic(0, ("CDel: Internal Error -- shutting down: "do { do { if ((0) <= LogLevel) (FSLog ("CDel: Internal Error -- shutting down: "
"wanted %d from %d, now at %d\n", cbi, fe->firstcb, *cbp)
); } while (0); osi_Panic ("CDel: Internal Error -- shutting down: "
"wanted %d from %d, now at %d\n", cbi, fe->firstcb, *cbp)
; } while(0);
349 "wanted %d from %d, now at %d\n",do { do { if ((0) <= LogLevel) (FSLog ("CDel: Internal Error -- shutting down: "
"wanted %d from %d, now at %d\n", cbi, fe->firstcb, *cbp)
); } while (0); osi_Panic ("CDel: Internal Error -- shutting down: "
"wanted %d from %d, now at %d\n", cbi, fe->firstcb, *cbp)
; } while(0);
350 cbi, fe->firstcb, *cbp))do { do { if ((0) <= LogLevel) (FSLog ("CDel: Internal Error -- shutting down: "
"wanted %d from %d, now at %d\n", cbi, fe->firstcb, *cbp)
); } while (0); osi_Panic ("CDel: Internal Error -- shutting down: "
"wanted %d from %d, now at %d\n", cbi, fe->firstcb, *cbp)
; } while(0);
;
351 DumpCallBackState_r();
352 ShutDownAndCore(PANIC1);
353 }
354 }
355 CDelPtr(fe, cbp, deletefe);
356 return 0;
357}
358
359/* Same as CDel, but pointer to parent pointer to CB entry is passed,
360 * as well as file entry */
361/* N.B. This one also deletes the CB, and also possibly parent FE, so
362 * make sure that it is not on any other list before calling this
363 * routine */
364static int Ccdelpt = 0, CcdelB = 0;
365
366static int
367CDelPtr(struct FileEntry *fe, afs_uint32 * cbp,
368 int deletefe)
369{
370 struct CallBack *cb;
371
372 if (!*cbp)
373 return 0;
374 Ccdelpt++;
375 cb = itocb(*cbp)((*cbp)?CB+(*cbp):0);
376 if (cb != &CB[*cbp])
377 CcdelB++;
378 *cbp = cb->cnext;
379 FreeCB(cb)iFreeCB((struct CallBack *)cb, &cbstuff.nCBs);
380 if ((--fe->ncbs == 0) && deletefe)
381 FDel(fe);
382 return 0;
383}
384
385static afs_uint32 *
386FindCBPtr(struct FileEntry *fe, struct host *host)
387{
388 afs_uint32 hostindex = h_htoi(host)((host)->index);
389 struct CallBack *cb;
390 afs_uint32 *cbp;
391 int safety;
392
393 for (safety = 0, cbp = &fe->firstcb; *cbp; cbp = &cb->cnext, safety++) {
394 if (safety > cbstuff.nblks) {
395 ViceLog(0, ("FindCBPtr: Internal Error -- shutting down.\n"))do { if ((0) <= LogLevel) (FSLog ("FindCBPtr: Internal Error -- shutting down.\n"
)); } while (0)
;
396 DumpCallBackState_r();
397 ShutDownAndCore(PANIC1);
398 }
399 cb = itocb(*cbp)((*cbp)?CB+(*cbp):0);
400 if (cb->hhead == hostindex)
401 break;
402 }
403 return cbp;
404}
405
406/* Delete file entry from hash table */
407static int
408FDel(struct FileEntry *fe)
409{
410 int fei = fetoi(fe)((afs_uint32)(!(fe)?0:(fe)-FE));
411 afs_uint32 *p = &HashTable[FEHash(fe->volid, fe->unique)(((fe->volid)+(fe->unique))&((512 -1)))];
412
413 while (*p && *p != fei)
414 p = &itofe(*p)((*p)?FE+(*p):0)->fnext;
415 osi_Assert(*p)(void)((*p) || (osi_AssertFailU("*p", "./../viced/callback.c"
, 415), 0))
;
416 *p = fe->fnext;
417 FreeFE(fe)iFreeFE((struct FileEntry *)fe, &cbstuff.nFEs);
418 return 0;
419}
420
421/* initialize the callback package */
422int
423InitCallBack(int nblks)
424{
425 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 425), 0));
;
426 tfirst = CBtime(FT_ApproxTime())((FT_ApproxTime())>>7);
427 /* N.B. The "-1", below, is because
428 * FE[0] and CB[0] are not used--and not allocated */
429 FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry))));
430 if (!FE) {
431 ViceLogThenPanic(0, ("Failed malloc in InitCallBack\n"))do { do { if ((0) <= LogLevel) (FSLog ("Failed malloc in InitCallBack\n"
)); } while (0); osi_Panic ("Failed malloc in InitCallBack\n"
); } while(0);
;
432 }
433 FE--; /* FE[0] is supposed to point to junk */
434 cbstuff.nFEs = nblks;
435 while (cbstuff.nFEs)
436 FreeFE(&FE[cbstuff.nFEs])iFreeFE((struct FileEntry *)&FE[cbstuff.nFEs], &cbstuff
.nFEs)
; /* This is correct */
437 CB = ((struct CallBack *)(calloc(nblks, sizeof(struct CallBack))));
438 if (!CB) {
439 ViceLogThenPanic(0, ("Failed malloc in InitCallBack\n"))do { do { if ((0) <= LogLevel) (FSLog ("Failed malloc in InitCallBack\n"
)); } while (0); osi_Panic ("Failed malloc in InitCallBack\n"
); } while(0);
;
440 }
441 CB--; /* CB[0] is supposed to point to junk */
442 cbstuff.nCBs = nblks;
443 while (cbstuff.nCBs)
444 FreeCB(&CB[cbstuff.nCBs])iFreeCB((struct CallBack *)&CB[cbstuff.nCBs], &cbstuff
.nCBs)
; /* This is correct */
445 cbstuff.nblks = nblks;
446 cbstuff.nbreakers = 0;
447 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 447), 0));
;
448 return 0;
449}
450
451afs_int32
452XCallBackBulk_r(struct host * ahost, struct AFSFid * fids, afs_int32 nfids)
453{
454 struct AFSCallBack tcbs[AFSCBMAX50];
455 int i;
456 struct AFSCBFids tf;
457 struct AFSCBs tc;
458 int code;
459 int j;
460 struct rx_connection *cb_conn = NULL((void *)0);
461
462#ifdef ADAPT_MTU
463 rx_SetConnDeadTime(ahost->callback_rxcon, 4);
464 rx_SetConnHardDeadTime(ahost->callback_rxcon, AFS_HARDDEADTIME120);
465#endif
466
467 code = 0;
468 j = 0;
469 while (nfids > 0) {
470
471 for (i = 0; i < nfids && i < AFSCBMAX50; i++) {
472 tcbs[i].CallBackVersion = CALLBACK_VERSION1;
473 tcbs[i].ExpirationTime = 0;
474 tcbs[i].CallBackType = CB_DROPPED3;
475 }
476 tf.AFSCBFids_len = i;
477 tf.AFSCBFids_val = &(fids[j]);
478 nfids -= i;
479 j += i;
480 tc.AFSCBs_len = i;
481 tc.AFSCBs_val = tcbs;
482
483 cb_conn = ahost->callback_rxcon;
484 rx_GetConnection(cb_conn);
485 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 485), 0));
;
486 code |= RXAFSCB_CallBack(cb_conn, &tf, &tc);
487 rx_PutConnection(cb_conn)rx_DestroyConnection(cb_conn);
488 cb_conn = NULL((void *)0);
489 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 489), 0));
;
490 }
491
492 return code;
493}
494
495/* the locked flag tells us if the host entry has already been locked
496 * by our parent. I don't think anybody actually calls us with the
497 * host locked, but here's how to make that work: GetSomeSpace has to
498 * change so that it doesn't attempt to lock any hosts < "host". That
499 * means that it might be unable to free any objects, so it has to
500 * return an exit status. If it fails, then AddCallBack1 might fail,
501 * as well. If so, the host->ResetDone should probably be set to 0,
502 * and we probably don't want to return a callback promise to the
503 * cache manager, either. */
504int
505AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
506 int locked)
507{
508 int retVal = 0;
509 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 509), 0));
;
510 if (!locked) {
511 h_Lock_r(host);
512 }
513 if (!(host->hostFlags & HOSTDELETED0x10))
514 retVal = AddCallBack1_r(host, fid, thead, type, 1);
515
516 if (!locked) {
517 h_Unlock_r(host)do { (void)((pthread_mutex_lock(&(&(host)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 517), 0));; (&(host)->lock)
->excl_locked &= ~2; if ((&(host)->lock)->wait_states
) Afs_Lock_ReleaseR(&(host)->lock); (void)((pthread_mutex_unlock
(&(&(host)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 517), 0));; } while (0)
;
518 }
519 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 519), 0));
;
520 return retVal;
521}
522
523static int
524AddCallBack1_r(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
525 int locked)
526{
527 struct FileEntry *fe;
528 struct CallBack *cb = 0, *lastcb = 0;
529 struct FileEntry *newfe = 0;
530 afs_uint32 time_out = 0;
531 afs_uint32 *Thead = thead;
532 struct CallBack *newcb = 0;
533 int safety;
534
535 cbstuff.AddCallBacks++;
536
537 host->Console |= 2;
538
539 /* allocate these guys first, since we can't call the allocator with
540 * the host structure locked -- or we might deadlock. However, we have
541 * to avoid races with FindFE... */
542 while (!(newcb = GetCB()((struct CallBack *)iGetCB(&cbstuff.nCBs)))) {
543 GetSomeSpace_r(host, locked);
544 }
545 while (!(newfe = GetFE()((struct FileEntry *)iGetFE(&cbstuff.nFEs)))) { /* Get it now, so we don't have to call */
546 /* GetSomeSpace with the host locked, later. This might turn out to */
547 /* have been unneccessary, but that's actually kind of unlikely, since */
548 /* most files are not shared. */
549 GetSomeSpace_r(host, locked);
550 }
551
552 if (!locked) {
553 h_Lock_r(host); /* this can yield, so do it before we get any */
554 /* fragile info */
555 if (host->hostFlags & HOSTDELETED0x10) {
556 host->Console &= ~2;
557 h_Unlock_r(host)do { (void)((pthread_mutex_lock(&(&(host)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 557), 0));; (&(host)->lock)
->excl_locked &= ~2; if ((&(host)->lock)->wait_states
) Afs_Lock_ReleaseR(&(host)->lock); (void)((pthread_mutex_unlock
(&(&(host)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 557), 0));; } while (0)
;
558 return 0;
559 }
560 }
561
562 fe = FindFE(fid);
563 if (type == CB_NORMAL1) {
564 time_out =
565 TimeCeiling(FT_ApproxTime() + TimeOut(fe ? fe->ncbs : 0) +(((FT_ApproxTime() + ((fe ? fe->ncbs : 0)>=((sizeof(TimeOuts
)/sizeof(TimeOuts[0]))*8)? MinTimeOut: TimeOuts[(fe ? fe->
ncbs : 0)>>3]) + (3*60))+127)&~127)
566 ServerBias)(((FT_ApproxTime() + ((fe ? fe->ncbs : 0)>=((sizeof(TimeOuts
)/sizeof(TimeOuts[0]))*8)? MinTimeOut: TimeOuts[(fe ? fe->
ncbs : 0)>>3]) + (3*60))+127)&~127)
;
567 Thead = THead(CBtime(time_out))(&timeout[(((((time_out)>>7))&127)+1)-1]);
568 } else if (type == CB_VOLUME3) {
569 time_out = TimeCeiling((60 * 120 + FT_ApproxTime()) + ServerBias)((((60 * 120 + FT_ApproxTime()) + (3*60))+127)&~127);
570 Thead = THead(CBtime(time_out))(&timeout[(((((time_out)>>7))&127)+1)-1]);
571 } else if (type == CB_BULK4) {
572 /* bulk status can get so many callbacks all at once, and most of them
573 * are probably not for things that will be used for long.
574 */
575 time_out =
576 TimeCeiling(FT_ApproxTime() + ServerBias +(((FT_ApproxTime() + (3*60) + ((22 + (fe ? fe->ncbs : 0))>=
((sizeof(TimeOuts)/sizeof(TimeOuts[0]))*8)? MinTimeOut: TimeOuts
[(22 + (fe ? fe->ncbs : 0))>>3]))+127)&~127)
577 TimeOut(22 + (fe ? fe->ncbs : 0)))(((FT_ApproxTime() + (3*60) + ((22 + (fe ? fe->ncbs : 0))>=
((sizeof(TimeOuts)/sizeof(TimeOuts[0]))*8)? MinTimeOut: TimeOuts
[(22 + (fe ? fe->ncbs : 0))>>3]))+127)&~127)
;
578 Thead = THead(CBtime(time_out))(&timeout[(((((time_out)>>7))&127)+1)-1]);
579 }
580
581 host->Console &= ~2;
582
583 if (!fe) {
584 afs_uint32 hash;
585
586 fe = newfe;
587 newfe = NULL((void *)0);
588 fe->firstcb = 0;
589 fe->volid = fid->Volume;
590 fe->vnode = fid->Vnode;
591 fe->unique = fid->Unique;
592 fe->ncbs = 0;
593 fe->status = 0;
594 hash = FEHash(fid->Volume, fid->Unique)(((fid->Volume)+(fid->Unique))&((512 -1)));
595 fe->fnext = HashTable[hash];
596 HashTable[hash] = fetoi(fe)((afs_uint32)(!(fe)?0:(fe)-FE));
597 }
598 for (safety = 0, lastcb = cb = itocb(fe->firstcb)((fe->firstcb)?CB+(fe->firstcb):0); cb;
599 lastcb = cb, cb = itocb(cb->cnext)((cb->cnext)?CB+(cb->cnext):0), safety++) {
600 if (safety > cbstuff.nblks) {
601 ViceLog(0, ("AddCallBack1: Internal Error -- shutting down.\n"))do { if ((0) <= LogLevel) (FSLog ("AddCallBack1: Internal Error -- shutting down.\n"
)); } while (0)
;
602 DumpCallBackState_r();
603 ShutDownAndCore(PANIC1);
604 }
605 if (cb->hhead == h_htoi(host)((host)->index))
606 break;
607 }
608 if (cb) { /* Already have call back: move to new timeout list */
609 /* don't change delayed callbacks back to normal ones */
610 if (cb->status != CB_DELAYED2)
611 cb->status = type;
612 /* Only move if new timeout is longer */
613 if (TNorm(ttoi(Thead))((((Thead-timeout)+1))<(((tfirst)&127)+1)?(((Thead-timeout
)+1))+128:(((Thead-timeout)+1)))
> TNorm(cb->thead)((cb->thead)<(((tfirst)&127)+1)?(cb->thead)+128:
(cb->thead))
) {
614 TDel(cb);
615 TAdd(cb, Thead);
616 }
617 if (newfe == NULL((void *)0)) { /* we are using the new FE */
618 fe->firstcb = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB));
619 fe->ncbs++;
620 cb->fhead = fetoi(fe)((afs_uint32)(!(fe)?0:(fe)-FE));
621 }
622 } else {
623 cb = newcb;
624 newcb = NULL((void *)0);
625 *(lastcb ? &lastcb->cnext : &fe->firstcb) = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB));
626 fe->ncbs++;
627 cb->cnext = 0;
628 cb->fhead = fetoi(fe)((afs_uint32)(!(fe)?0:(fe)-FE));
629 cb->status = type;
630 HAdd(cb, host);
631 TAdd(cb, Thead);
632 }
633
634 /* now free any still-unused callback or host entries */
635 if (newcb)
636 FreeCB(newcb)iFreeCB((struct CallBack *)newcb, &cbstuff.nCBs);
637 if (newfe)
638 FreeFE(newfe)iFreeFE((struct FileEntry *)newfe, &cbstuff.nFEs);
639
640 if (!locked) /* freecb and freefe might(?) yield */
641 h_Unlock_r(host)do { (void)((pthread_mutex_lock(&(&(host)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 641), 0));; (&(host)->lock)
->excl_locked &= ~2; if ((&(host)->lock)->wait_states
) Afs_Lock_ReleaseR(&(host)->lock); (void)((pthread_mutex_unlock
(&(&(host)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 641), 0));; } while (0)
;
642
643 if (type == CB_NORMAL1 || type == CB_VOLUME3 || type == CB_BULK4)
644 return time_out - ServerBias(3*60); /* Expires sooner at workstation */
645
646 return 0;
647}
648
649static int
650CompareCBA(const void *e1, const void *e2)
651{
652 const struct cbstruct *cba1 = (const struct cbstruct *)e1;
653 const struct cbstruct *cba2 = (const struct cbstruct *)e2;
654 return ((cba1->hp)->index - (cba2->hp)->index);
655}
656
657/* Take an array full of hosts, all held. Break callbacks to them, and
658 * release the holds once you're done.
659 * Currently only works for a single Fid in afidp array.
660 * If you want to make this work with multiple fids, you need to fix
661 * the error handling. One approach would be to force a reset if a
662 * multi-fid call fails, or you could add delayed callbacks for each
663 * fid. You probably also need to sort and remove duplicate hosts.
664 * When this is called from the BreakVolumeCallBacks path, it does NOT
665 * force a reset if the RPC fails, it just marks the host down and tries
666 * to create a delayed callback. */
667/* N.B. be sure that code works when ncbas == 0 */
668/* N.B. requires all the cba[*].hp pointers to be valid... */
669/* This routine does not hold a lock on the host for the duration of
670 * the BreakCallBack RPC, which is a significant deviation from tradition.
671 * It _does_ get a lock on the host before setting VenusDown = 1,
672 * which is sufficient only if VenusDown = 0 only happens when the
673 * lock is held over the RPC and the subsequent VenusDown == 0
674 * wherever that is done. */
675static void
676MultiBreakCallBack_r(struct cbstruct cba[], int ncbas,
677 struct AFSCBFids *afidp)
678{
679 int i, j;
680 struct rx_connection *conns[MAX_CB_HOSTS1024];
681 static struct AFSCBs tc = { 0, 0 };
682 int multi_to_cba_map[MAX_CB_HOSTS1024];
683
684 osi_Assert(ncbas <= MAX_CB_HOSTS)(void)((ncbas <= 1024) || (osi_AssertFailU("ncbas <= MAX_CB_HOSTS"
, "./../viced/callback.c", 684), 0))
;
685
686 /* sort cba list to avoid makecall issues */
687 qsort(cba, ncbas, sizeof(struct cbstruct), CompareCBA);
688
689 /* set up conns for multi-call */
690 for (i = 0, j = 0; i < ncbas; i++) {
691 struct host *thishost = cba[i].hp;
692 if (!thishost || (thishost->hostFlags & HOSTDELETED0x10)) {
693 continue;
694 }
695 rx_GetConnection(thishost->callback_rxcon);
696 multi_to_cba_map[j] = i;
697 conns[j++] = thishost->callback_rxcon;
698
699#ifdef ADAPT_MTU
700 rx_SetConnDeadTime(thishost->callback_rxcon, 4);
701 rx_SetConnHardDeadTime(thishost->callback_rxcon, AFS_HARDDEADTIME120);
702#endif
703 }
704
705 if (j) { /* who knows what multi would do with 0 conns? */
706 cbstuff.nbreakers++;
707 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 707), 0));
;
708 multi_Rx(conns, j)do { struct multi_handle *multi_h; int multi_i; int multi_i0;
afs_int32 multi_error; struct rx_call *multi_call; multi_h =
multi_Init(conns, j); for (multi_i0 = multi_i = 0; ; multi_i
= multi_i0 )
{
709 multi_RXAFSCB_CallBack(afidp, &tc)if (multi_h->nextReady == multi_h->firstNotReady &&
multi_i < multi_h->nConns) { multi_call = multi_h->
calls[multi_i]; if (multi_call) { StartRXAFSCB_CallBack(multi_call
, afidp, &tc); rx_FlushWrite(multi_call); } multi_i0++; continue
; } if ((multi_i = multi_Select(multi_h)) < 0) break; multi_call
= multi_h->calls[multi_i]; multi_error = rx_EndCall(multi_call
, EndRXAFSCB_CallBack(multi_call)); multi_h->calls[multi_i
] = (struct rx_call *) 0
;
710 if (multi_error) {
711 afs_uint32 idx;
712 struct host *hp;
713 char hoststr[16];
714
715 i = multi_to_cba_map[multi_i];
716 hp = cba[i].hp;
717 idx = cba[i].thead;
718
719 if (!hp || !idx) {
720 ViceLog(0,do { if ((0) <= LogLevel) (FSLog ("BCB: INTERNAL ERROR: hp=%p, cba=%p, thead=%u\n"
, hp, cba, idx)); } while (0)
721 ("BCB: INTERNAL ERROR: hp=%p, cba=%p, thead=%u\n",do { if ((0) <= LogLevel) (FSLog ("BCB: INTERNAL ERROR: hp=%p, cba=%p, thead=%u\n"
, hp, cba, idx)); } while (0)
722 hp, cba, idx))do { if ((0) <= LogLevel) (FSLog ("BCB: INTERNAL ERROR: hp=%p, cba=%p, thead=%u\n"
, hp, cba, idx)); } while (0)
;
723 } else {
724 /*
725 ** try breaking callbacks on alternate interface addresses
726 */
727 if (MultiBreakCallBackAlternateAddress(hp, afidp)) {
728 if (ShowProblems) {
729 ViceLog(7,do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
730 ("BCB: Failed on file %u.%u.%u, "do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
731 "Host %p (%s:%d) is down\n",do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
732 afidp->AFSCBFids_val->Volume,do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
733 afidp->AFSCBFids_val->Vnode,do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
734 afidp->AFSCBFids_val->Unique,do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
735 hp,do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
736 afs_inet_ntoa_r(hp->host, hoststr),do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
737 ntohs(hp->port)))do { if ((7) <= LogLevel) (FSLog ("BCB: Failed on file %u.%u.%u, "
"Host %p (%s:%d) is down\n", afidp->AFSCBFids_val->Volume
, afidp->AFSCBFids_val->Vnode, afidp->AFSCBFids_val->
Unique, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
;
738 }
739
740 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 740), 0));
;
741 h_Lock_r(hp);
742 if (!(hp->hostFlags & HOSTDELETED0x10)) {
743 hp->hostFlags |= VENUSDOWN0x08;
744 /**
745 * We always go into AddCallBack1_r with the host locked
746 */
747 AddCallBack1_r(hp, afidp->AFSCBFids_val, itot(idx)((timeout)+(idx-1)),
748 CB_DELAYED2, 1);
749 }
750 h_Unlock_r(hp)do { (void)((pthread_mutex_lock(&(&(hp)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(hp)->lock)->mutex) == 0"
, "./../viced/callback.c", 750), 0));; (&(hp)->lock)->
excl_locked &= ~2; if ((&(hp)->lock)->wait_states
) Afs_Lock_ReleaseR(&(hp)->lock); (void)((pthread_mutex_unlock
(&(&(hp)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(hp)->lock)->mutex) == 0"
, "./../viced/callback.c", 750), 0));; } while (0)
;
751 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 751), 0));
;
752 }
753 }
754 }
755 }
756 multi_Endmulti_Finalize(multi_h); } while (0);
757 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 757), 0));
;
758 cbstuff.nbreakers--;
759 }
760
761 for (i = 0; i < ncbas; i++) {
762 struct host *hp;
763 hp = cba[i].hp;
764 if (hp) {
765 h_Release_r(hp)do { do { --((hp)->refCount); } while (0); if (((hp)->refCount
< 1) && (((hp)->hostFlags & 0x10) || ((hp)
->hostFlags & 0x20))) h_TossStuff_r((hp)); } while(0)
;
766 }
767 }
768
769 /* H_UNLOCK around this so h_FreeConnection does not deadlock.
770 h_FreeConnection should *never* be called on a callback connection,
771 but on 10/27/04 a deadlock occurred where it was, when we know why,
772 this should be reverted. -- shadow */
773 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 773), 0));
;
774 for (i = 0; i < j; i++) {
775 rx_PutConnection(conns[i])rx_DestroyConnection(conns[i]);
776 }
777 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 777), 0));
;
778
779 return;
780}
781
782/*
783 * Break all call backs for fid, except for the specified host (unless flag
784 * is true, in which case all get a callback message. Assumption: the specified
785 * host is h_Held, by the caller; the others aren't.
786 * Specified host may be bogus, that's ok. This used to check to see if the
787 * host was down in two places, once right after the host was h_held, and
788 * again after it was locked. That race condition is incredibly rare and
789 * relatively harmless even when it does occur, so we don't check for it now.
790 */
791/* if flag is true, send a break callback msg to "host", too */
792int
793BreakCallBack(struct host *xhost, AFSFid * fid, int flag)
794{
795 struct FileEntry *fe;
796 struct CallBack *cb, *nextcb;
797 struct cbstruct cbaDef[MAX_CB_HOSTS1024], *cba = cbaDef;
798 unsigned int ncbas, cbaAlloc = MAX_CB_HOSTS1024;
799 struct AFSCBFids tf;
800 int hostindex;
801 char hoststr[16];
802
803 ViceLog(7,do { if ((7) <= LogLevel) (FSLog ("BCB: BreakCallBack(Host %p all but %s:%d, (%u,%u,%u))\n"
, xhost, afs_inet_ntoa_r(xhost->host, hoststr), (__builtin_constant_p
(xhost->port) ? (__uint16_t)(((__uint16_t)(xhost->port)
) << 8 | ((__uint16_t)(xhost->port)) >> 8) : __bswap16_var
(xhost->port)), fid->Volume, fid->Vnode, fid->Unique
)); } while (0)
804 ("BCB: BreakCallBack(Host %p all but %s:%d, (%u,%u,%u))\n",do { if ((7) <= LogLevel) (FSLog ("BCB: BreakCallBack(Host %p all but %s:%d, (%u,%u,%u))\n"
, xhost, afs_inet_ntoa_r(xhost->host, hoststr), (__builtin_constant_p
(xhost->port) ? (__uint16_t)(((__uint16_t)(xhost->port)
) << 8 | ((__uint16_t)(xhost->port)) >> 8) : __bswap16_var
(xhost->port)), fid->Volume, fid->Vnode, fid->Unique
)); } while (0)
805 xhost, afs_inet_ntoa_r(xhost->host, hoststr), ntohs(xhost->port),do { if ((7) <= LogLevel) (FSLog ("BCB: BreakCallBack(Host %p all but %s:%d, (%u,%u,%u))\n"
, xhost, afs_inet_ntoa_r(xhost->host, hoststr), (__builtin_constant_p
(xhost->port) ? (__uint16_t)(((__uint16_t)(xhost->port)
) << 8 | ((__uint16_t)(xhost->port)) >> 8) : __bswap16_var
(xhost->port)), fid->Volume, fid->Vnode, fid->Unique
)); } while (0)
806 fid->Volume, fid->Vnode, fid->Unique))do { if ((7) <= LogLevel) (FSLog ("BCB: BreakCallBack(Host %p all but %s:%d, (%u,%u,%u))\n"
, xhost, afs_inet_ntoa_r(xhost->host, hoststr), (__builtin_constant_p
(xhost->port) ? (__uint16_t)(((__uint16_t)(xhost->port)
) << 8 | ((__uint16_t)(xhost->port)) >> 8) : __bswap16_var
(xhost->port)), fid->Volume, fid->Vnode, fid->Unique
)); } while (0)
;
807
808 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 808), 0));
;
809 cbstuff.BreakCallBacks++;
810 fe = FindFE(fid);
811 if (!fe) {
812 goto done;
813 }
814 hostindex = h_htoi(xhost)((xhost)->index);
815 cb = itocb(fe->firstcb)((fe->firstcb)?CB+(fe->firstcb):0);
816 if (!cb || ((fe->ncbs == 1) && (cb->hhead == hostindex) && !flag)) {
817 /* the most common case is what follows the || */
818 goto done;
819 }
820 tf.AFSCBFids_len = 1;
821 tf.AFSCBFids_val = fid;
822
823 for (ncbas = 0; cb ; cb = nextcb) {
824 nextcb = itocb(cb->cnext)((cb->cnext)?CB+(cb->cnext):0);
825 if ((cb->hhead != hostindex || flag)
826 && (cb->status == CB_BULK4 || cb->status == CB_NORMAL1
827 || cb->status == CB_VOLUME3)) {
828 struct host *thishost = h_itoh(cb->hhead)(hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&(
512 -1)))
;
829 if (!thishost) {
830 ViceLog(0, ("BCB: BOGUS! cb->hhead is NULL!\n"))do { if ((0) <= LogLevel) (FSLog ("BCB: BOGUS! cb->hhead is NULL!\n"
)); } while (0)
;
831 } else if (thishost->hostFlags & VENUSDOWN0x08) {
832 ViceLog(7,do { if ((7) <= LogLevel) (FSLog ("BCB: %p (%s:%d) is down; delaying break call back\n"
, thishost, afs_inet_ntoa_r(thishost->host, hoststr), (__builtin_constant_p
(thishost->port) ? (__uint16_t)(((__uint16_t)(thishost->
port)) << 8 | ((__uint16_t)(thishost->port)) >>
8) : __bswap16_var(thishost->port)))); } while (0)
833 ("BCB: %p (%s:%d) is down; delaying break call back\n",do { if ((7) <= LogLevel) (FSLog ("BCB: %p (%s:%d) is down; delaying break call back\n"
, thishost, afs_inet_ntoa_r(thishost->host, hoststr), (__builtin_constant_p
(thishost->port) ? (__uint16_t)(((__uint16_t)(thishost->
port)) << 8 | ((__uint16_t)(thishost->port)) >>
8) : __bswap16_var(thishost->port)))); } while (0)
834 thishost, afs_inet_ntoa_r(thishost->host, hoststr),do { if ((7) <= LogLevel) (FSLog ("BCB: %p (%s:%d) is down; delaying break call back\n"
, thishost, afs_inet_ntoa_r(thishost->host, hoststr), (__builtin_constant_p
(thishost->port) ? (__uint16_t)(((__uint16_t)(thishost->
port)) << 8 | ((__uint16_t)(thishost->port)) >>
8) : __bswap16_var(thishost->port)))); } while (0)
835 ntohs(thishost->port)))do { if ((7) <= LogLevel) (FSLog ("BCB: %p (%s:%d) is down; delaying break call back\n"
, thishost, afs_inet_ntoa_r(thishost->host, hoststr), (__builtin_constant_p
(thishost->port) ? (__uint16_t)(((__uint16_t)(thishost->
port)) << 8 | ((__uint16_t)(thishost->port)) >>
8) : __bswap16_var(thishost->port)))); } while (0)
;
836 cb->status = CB_DELAYED2;
837 } else {
838 if (!(thishost->hostFlags & HOSTDELETED0x10)) {
839 h_Hold_r(thishost)do { ++((thishost)->refCount); } while(0);
840 if (ncbas == cbaAlloc) { /* Need more space */
841 int curLen = cbaAlloc*sizeof(cba[0]);
842 struct cbstruct *cbaOld = (cba == cbaDef) ? NULL((void *)0) : cba;
843
844 /* There are logical contraints elsewhere that the number of hosts
845 (i.e. h_HTSPERBLOCK*h_MAXHOSTTABLES) remains in the realm of a signed "int".
846 cbaAlloc is defined unsigned int hence doubling below cannot overflow
847 */
848 cbaAlloc = cbaAlloc<<1; /* double */
849 cba = realloc(cbaOld, cbaAlloc * sizeof(cba[0]));
850
851 if (cbaOld == NULL((void *)0)) { /* realloc wouldn't have copied from cbaDef */
852 memcpy(cba, cbaDef, curLen);
853 }
854 }
855 cba[ncbas].hp = thishost;
856 cba[ncbas].thead = cb->thead;
857 ncbas++;
858 }
859 TDel(cb);
860 HDel(cb);
861 CDel(cb, 1); /* Usually first; so this delete
862 * is reasonably inexpensive */
863 }
864 }
865 }
866
867 if (ncbas) {
868 struct cbstruct *cba2;
869 int num;
870
871 for (cba2 = cba, num = ncbas; ncbas > 0; cba2 += num, ncbas -= num) {
872 num = (ncbas > MAX_CB_HOSTS1024) ? MAX_CB_HOSTS1024 : ncbas;
873 MultiBreakCallBack_r(cba2, num, &tf);
874 }
875 }
876
877 if (cba != cbaDef) free(cba);
878
879 done:
880 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 880), 0));
;
881 return 0;
882}
883
884/* Delete (do not break) single call back for fid */
885int
886DeleteCallBack(struct host *host, AFSFid * fid)
887{
888 struct FileEntry *fe;
889 afs_uint32 *pcb;
890 char hoststr[16];
891
892 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 892), 0));
;
893 cbstuff.DeleteCallBacks++;
894
895 h_Lock_r(host);
896 /* do not care if the host has been HOSTDELETED */
897 fe = FindFE(fid);
898 if (!fe) {
899 h_Unlock_r(host)do { (void)((pthread_mutex_lock(&(&(host)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 899), 0));; (&(host)->lock)
->excl_locked &= ~2; if ((&(host)->lock)->wait_states
) Afs_Lock_ReleaseR(&(host)->lock); (void)((pthread_mutex_unlock
(&(&(host)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 899), 0));; } while (0)
;
900 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 900), 0));
;
901 ViceLog(8,do { if ((8) <= LogLevel) (FSLog ("DCB: No call backs for fid (%u, %u, %u)\n"
, fid->Volume, fid->Vnode, fid->Unique)); } while (0
)
902 ("DCB: No call backs for fid (%u, %u, %u)\n", fid->Volume,do { if ((8) <= LogLevel) (FSLog ("DCB: No call backs for fid (%u, %u, %u)\n"
, fid->Volume, fid->Vnode, fid->Unique)); } while (0
)
903 fid->Vnode, fid->Unique))do { if ((8) <= LogLevel) (FSLog ("DCB: No call backs for fid (%u, %u, %u)\n"
, fid->Volume, fid->Vnode, fid->Unique)); } while (0
)
;
904 return 0;
905 }
906 pcb = FindCBPtr(fe, host);
907 if (!*pcb) {
908 ViceLog(8,do { if ((8) <= LogLevel) (FSLog ("DCB: No call back for host %p (%s:%d), (%u, %u, %u)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)), fid->Volume, fid->Vnode, fid->Unique
)); } while (0)
909 ("DCB: No call back for host %p (%s:%d), (%u, %u, %u)\n",do { if ((8) <= LogLevel) (FSLog ("DCB: No call back for host %p (%s:%d), (%u, %u, %u)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)), fid->Volume, fid->Vnode, fid->Unique
)); } while (0)
910 host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),do { if ((8) <= LogLevel) (FSLog ("DCB: No call back for host %p (%s:%d), (%u, %u, %u)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)), fid->Volume, fid->Vnode, fid->Unique
)); } while (0)
911 fid->Volume, fid->Vnode, fid->Unique))do { if ((8) <= LogLevel) (FSLog ("DCB: No call back for host %p (%s:%d), (%u, %u, %u)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)), fid->Volume, fid->Vnode, fid->Unique
)); } while (0)
;
912 h_Unlock_r(host)do { (void)((pthread_mutex_lock(&(&(host)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 912), 0));; (&(host)->lock)
->excl_locked &= ~2; if ((&(host)->lock)->wait_states
) Afs_Lock_ReleaseR(&(host)->lock); (void)((pthread_mutex_unlock
(&(&(host)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 912), 0));; } while (0)
;
913 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 913), 0));
;
914 return 0;
915 }
916 HDel(itocb(*pcb)((*pcb)?CB+(*pcb):0));
917 TDel(itocb(*pcb)((*pcb)?CB+(*pcb):0));
918 CDelPtr(fe, pcb, 1);
919 h_Unlock_r(host)do { (void)((pthread_mutex_lock(&(&(host)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 919), 0));; (&(host)->lock)
->excl_locked &= ~2; if ((&(host)->lock)->wait_states
) Afs_Lock_ReleaseR(&(host)->lock); (void)((pthread_mutex_unlock
(&(&(host)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 919), 0));; } while (0)
;
920 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 920), 0));
;
921 return 0;
922}
923
924/*
925 * Delete (do not break) all call backs for fid. This call doesn't
926 * set all of the various host locks, but it shouldn't really matter
927 * since we're not adding callbacks, but deleting them. I'm not sure
928 * why it doesn't set the lock, however; perhaps it should.
929 */
930int
931DeleteFileCallBacks(AFSFid * fid)
932{
933 struct FileEntry *fe;
934 struct CallBack *cb;
935 afs_uint32 cbi;
936 int n;
937
938 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 938), 0));
;
939 cbstuff.DeleteFiles++;
940 fe = FindFE(fid);
941 if (!fe) {
942 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 942), 0));
;
943 ViceLog(8,do { if ((8) <= LogLevel) (FSLog ("DF: No fid (%u,%u,%u) to delete\n"
, fid->Volume, fid->Vnode, fid->Unique)); } while (0
)
944 ("DF: No fid (%u,%u,%u) to delete\n", fid->Volume, fid->Vnode,do { if ((8) <= LogLevel) (FSLog ("DF: No fid (%u,%u,%u) to delete\n"
, fid->Volume, fid->Vnode, fid->Unique)); } while (0
)
945 fid->Unique))do { if ((8) <= LogLevel) (FSLog ("DF: No fid (%u,%u,%u) to delete\n"
, fid->Volume, fid->Vnode, fid->Unique)); } while (0
)
;
946 return 0;
947 }
948 for (n = 0, cbi = fe->firstcb; cbi; n++) {
949 cb = itocb(cbi)((cbi)?CB+(cbi):0);
950 cbi = cb->cnext;
951 TDel(cb);
952 HDel(cb);
953 FreeCB(cb)iFreeCB((struct CallBack *)cb, &cbstuff.nCBs);
954 fe->ncbs--;
955 }
956 FDel(fe);
957 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 957), 0));
;
958 return 0;
959}
960
961/* Delete (do not break) all call backs for host. The host should be
962 * locked. */
963int
964DeleteAllCallBacks_r(struct host *host, int deletefe)
965{
966 struct CallBack *cb;
967 int cbi, first;
968
969 cbstuff.DeleteAllCallBacks++;
970 cbi = first = host->cblist;
971 if (!cbi) {
972 ViceLog(8, ("DV: no call backs\n"))do { if ((8) <= LogLevel) (FSLog ("DV: no call backs\n"));
} while (0)
;
973 return 0;
974 }
975 do {
976 cb = itocb(cbi)((cbi)?CB+(cbi):0);
977 cbi = cb->hnext;
978 TDel(cb);
979 CDel(cb, deletefe);
980 } while (cbi != first);
981 host->cblist = 0;
982 return 0;
983}
984
985/*
986 * Break all delayed call backs for host. Returns 1 if all call backs
987 * successfully broken; 0 otherwise. Assumes host is h_Held and h_Locked.
988 * Must be called with VenusDown set for this host
989 */
990int
991BreakDelayedCallBacks(struct host *host)
992{
993 int retVal;
994 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 994), 0));
;
995 retVal = BreakDelayedCallBacks_r(host);
996 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 996), 0));
;
997 return retVal;
998}
999
1000int
1001BreakDelayedCallBacks_r(struct host *host)
1002{
1003 struct AFSFid fids[AFSCBMAX50];
1004 int cbi, first, nfids;
1005 struct CallBack *cb;
1006 int code;
1007 char hoststr[16];
1008 struct rx_connection *cb_conn;
1009
1010 cbstuff.nbreakers++;
1011 if (!(host->hostFlags & RESETDONE0x40) && !(host->hostFlags & HOSTDELETED0x10)) {
1
Taking false branch
1012 host->hostFlags &= ~ALTADDR0x04; /* alternate addresses are invalid */
1013 cb_conn = host->callback_rxcon;
1014 rx_GetConnection(cb_conn);
1015 if (host->interface) {
1016 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1016), 0));
;
1017 code =
1018 RXAFSCB_InitCallBackState3(cb_conn, &FS_HostUUID);
1019 } else {
1020 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1020), 0));
;
1021 code = RXAFSCB_InitCallBackState(cb_conn);
1022 }
1023 rx_PutConnection(cb_conn)rx_DestroyConnection(cb_conn);
1024 cb_conn = NULL((void *)0);
1025 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 1025), 0));
;
1026 host->hostFlags |= ALTADDR0x04; /* alternate addresses are valid */
1027 if (code) {
1028 if (ShowProblems) {
1029 ViceLog(0,do { if ((0) <= LogLevel) (FSLog ("CB: Call back connect back failed (in break delayed) "
"for Host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
1030 ("CB: Call back connect back failed (in break delayed) "do { if ((0) <= LogLevel) (FSLog ("CB: Call back connect back failed (in break delayed) "
"for Host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
1031 "for Host %p (%s:%d)\n",do { if ((0) <= LogLevel) (FSLog ("CB: Call back connect back failed (in break delayed) "
"for Host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
1032 host, afs_inet_ntoa_r(host->host, hoststr),do { if ((0) <= LogLevel) (FSLog ("CB: Call back connect back failed (in break delayed) "
"for Host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
1033 ntohs(host->port)))do { if ((0) <= LogLevel) (FSLog ("CB: Call back connect back failed (in break delayed) "
"for Host %p (%s:%d)\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
;
1034 }
1035 host->hostFlags |= VENUSDOWN0x08;
1036 } else {
1037 ViceLog(25,do { if ((25) <= LogLevel) (FSLog ("InitCallBackState success on %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
1038 ("InitCallBackState success on %p (%s:%d)\n",do { if ((25) <= LogLevel) (FSLog ("InitCallBackState success on %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
1039 host, afs_inet_ntoa_r(host->host, hoststr),do { if ((25) <= LogLevel) (FSLog ("InitCallBackState success on %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
1040 ntohs(host->port)))do { if ((25) <= LogLevel) (FSLog ("InitCallBackState success on %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
;
1041 /* reset was done successfully */
1042 host->hostFlags |= RESETDONE0x40;
1043 host->hostFlags &= ~VENUSDOWN0x08;
1044 }
1045 } else
1046 while (!(host->hostFlags & HOSTDELETED0x10)) {
2
Loop condition is true. Entering loop body
1047 nfids = 0;
1048 host->hostFlags &= ~VENUSDOWN0x08; /* presume up */
1049 cbi = first = host->cblist;
1050 if (!cbi)
3
Taking false branch
1051 break;
1052 do {
1053 first = host->cblist;
1054 cb = itocb(cbi)((cbi)?CB+(cbi):0);
1055 cbi = cb->hnext;
1056 if (cb->status == CB_DELAYED2) {
4
Taking true branch
1057 struct FileEntry *fe = itofe(cb->fhead)((cb->fhead)?FE+(cb->fhead):0);
1058 fids[nfids].Volume = fe->volid;
5
Access to field 'volid' results in a dereference of a null pointer (loaded from variable 'fe')
1059 fids[nfids].Vnode = fe->vnode;
1060 fids[nfids].Unique = fe->unique;
1061 nfids++;
1062 HDel(cb);
1063 TDel(cb);
1064 CDel(cb, 1);
1065 }
1066 } while (cbi && cbi != first && nfids < AFSCBMAX50);
1067
1068 if (nfids == 0) {
1069 break;
1070 }
1071
1072 if (XCallBackBulk_r(host, fids, nfids)) {
1073 /* Failed, again: put them back, probably with old
1074 * timeout values */
1075 int i;
1076 if (ShowProblems) {
1077 ViceLog(0,do { if ((0) <= LogLevel) (FSLog ("CB: XCallBackBulk failed, Host %p (%s:%d); "
"callback list follows:\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
1078 ("CB: XCallBackBulk failed, Host %p (%s:%d); "do { if ((0) <= LogLevel) (FSLog ("CB: XCallBackBulk failed, Host %p (%s:%d); "
"callback list follows:\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
1079 "callback list follows:\n",do { if ((0) <= LogLevel) (FSLog ("CB: XCallBackBulk failed, Host %p (%s:%d); "
"callback list follows:\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
1080 host, afs_inet_ntoa_r(host->host, hoststr),do { if ((0) <= LogLevel) (FSLog ("CB: XCallBackBulk failed, Host %p (%s:%d); "
"callback list follows:\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
1081 ntohs(host->port)))do { if ((0) <= LogLevel) (FSLog ("CB: XCallBackBulk failed, Host %p (%s:%d); "
"callback list follows:\n", host, afs_inet_ntoa_r(host->host
, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)))); } while
(0)
;
1082 }
1083 for (i = 0; i < nfids; i++) {
1084 if (ShowProblems) {
1085 ViceLog(0,do { if ((0) <= LogLevel) (FSLog ("CB: Host %p (%s:%d), file %u.%u.%u "
"(part of bulk callback)\n", host, afs_inet_ntoa_r(host->
host, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)), fids
[i].Volume, fids[i].Vnode, fids[i].Unique)); } while (0)
1086 ("CB: Host %p (%s:%d), file %u.%u.%u "do { if ((0) <= LogLevel) (FSLog ("CB: Host %p (%s:%d), file %u.%u.%u "
"(part of bulk callback)\n", host, afs_inet_ntoa_r(host->
host, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)), fids
[i].Volume, fids[i].Vnode, fids[i].Unique)); } while (0)
1087 "(part of bulk callback)\n",do { if ((0) <= LogLevel) (FSLog ("CB: Host %p (%s:%d), file %u.%u.%u "
"(part of bulk callback)\n", host, afs_inet_ntoa_r(host->
host, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)), fids
[i].Volume, fids[i].Vnode, fids[i].Unique)); } while (0)
1088 host, afs_inet_ntoa_r(host->host, hoststr),do { if ((0) <= LogLevel) (FSLog ("CB: Host %p (%s:%d), file %u.%u.%u "
"(part of bulk callback)\n", host, afs_inet_ntoa_r(host->
host, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)), fids
[i].Volume, fids[i].Vnode, fids[i].Unique)); } while (0)
1089 ntohs(host->port), fids[i].Volume,do { if ((0) <= LogLevel) (FSLog ("CB: Host %p (%s:%d), file %u.%u.%u "
"(part of bulk callback)\n", host, afs_inet_ntoa_r(host->
host, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)), fids
[i].Volume, fids[i].Vnode, fids[i].Unique)); } while (0)
1090 fids[i].Vnode, fids[i].Unique))do { if ((0) <= LogLevel) (FSLog ("CB: Host %p (%s:%d), file %u.%u.%u "
"(part of bulk callback)\n", host, afs_inet_ntoa_r(host->
host, hoststr), (__builtin_constant_p(host->port) ? (__uint16_t
)(((__uint16_t)(host->port)) << 8 | ((__uint16_t)(host
->port)) >> 8) : __bswap16_var(host->port)), fids
[i].Volume, fids[i].Vnode, fids[i].Unique)); } while (0)
;
1091 }
1092 /* used to do this:
1093 * AddCallBack1_r(host, &fids[i], itot(thead[i]), CB_DELAYED, 1);
1094 * * but it turns out to cause too many tricky locking problems.
1095 * * now, if break delayed fails, screw it. */
1096 }
1097 host->hostFlags |= VENUSDOWN0x08; /* Failed */
1098 ClearHostCallbacks_r(host, 1 /* locked */ );
1099 nfids = 0;
1100 break;
1101 }
1102 if (nfids < AFSCBMAX50)
1103 break;
1104 }
1105
1106 cbstuff.nbreakers--;
1107 /* If we succeeded it's always ok to unset HFE_LATER */
1108 if (!(host->hostFlags & VENUSDOWN0x08))
1109 host->hostFlags &= ~HFE_LATER0x80;
1110 return (host->hostFlags & VENUSDOWN0x08);
1111}
1112
1113static int
1114MultiBreakVolumeCallBack_r(struct host *host,
1115 struct VCBParams *parms, int deletefe)
1116{
1117 char hoststr[16];
1118
1119 if (host->hostFlags & HOSTDELETED0x10)
1120 return 0;
1121
1122 if (!(host->hostFlags & HCBREAK0x400))
1123 return 0; /* host is not flagged to notify */
1124
1125 if (host->hostFlags & VENUSDOWN0x08) {
1126 h_Lock_r(host);
1127 /* Do not care if the host is now HOSTDELETED */
1128 if (ShowProblems) {
1129 ViceLog(0,do { if ((0) <= LogLevel) (FSLog ("BVCB: volume callback for Host %p (%s:%d) failed\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
1130 ("BVCB: volume callback for Host %p (%s:%d) failed\n",do { if ((0) <= LogLevel) (FSLog ("BVCB: volume callback for Host %p (%s:%d) failed\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
1131 host, afs_inet_ntoa_r(host->host, hoststr),do { if ((0) <= LogLevel) (FSLog ("BVCB: volume callback for Host %p (%s:%d) failed\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
1132 ntohs(host->port)))do { if ((0) <= LogLevel) (FSLog ("BVCB: volume callback for Host %p (%s:%d) failed\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
;
1133 }
1134 DeleteAllCallBacks_r(host, deletefe); /* Delete all callback state
1135 * rather than attempting to
1136 * selectively remember to
1137 * delete the volume callbacks
1138 * later */
1139 host->hostFlags &= ~(RESETDONE0x40|HCBREAK0x400); /* Do InitCallBackState when host returns */
1140 h_Unlock_r(host)do { (void)((pthread_mutex_lock(&(&(host)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 1140), 0));; (&(host)->lock
)->excl_locked &= ~2; if ((&(host)->lock)->wait_states
) Afs_Lock_ReleaseR(&(host)->lock); (void)((pthread_mutex_unlock
(&(&(host)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(host)->lock)->mutex) == 0"
, "./../viced/callback.c", 1140), 0));; } while (0)
;
1141 return 0;
1142 }
1143 osi_Assert(parms->ncbas <= MAX_CB_HOSTS)(void)((parms->ncbas <= 1024) || (osi_AssertFailU("parms->ncbas <= MAX_CB_HOSTS"
, "./../viced/callback.c", 1143), 0))
;
1144
1145 /* Do not call MultiBreakCallBack on the current host structure
1146 ** because it would prematurely release the hold on the host
1147 */
1148 if (parms->ncbas == MAX_CB_HOSTS1024) {
1149 struct AFSCBFids tf;
1150
1151 tf.AFSCBFids_len = 1;
1152 tf.AFSCBFids_val = parms->fid;
1153
1154 /* this releases all the hosts */
1155 MultiBreakCallBack_r(parms->cba, parms->ncbas, &tf);
1156
1157 parms->ncbas = 0;
1158 }
1159 parms->cba[parms->ncbas].hp = host;
1160 parms->cba[(parms->ncbas)++].thead = parms->thead;
1161 host->hostFlags &= ~HCBREAK0x400;
1162
1163 /* we have more work to do on this host, so make sure we keep a reference
1164 * to it */
1165 h_Hold_r(host)do { ++((host)->refCount); } while(0);
1166
1167 return 0;
1168}
1169
1170static int
1171MultiBreakVolumeLaterCallBack(struct host *host, void *rock)
1172{
1173 struct VCBParams *parms = (struct VCBParams *)rock;
1174 int retval;
1175 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 1175), 0));
;
1176 retval = MultiBreakVolumeCallBack_r(host, parms, 0);
1177 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1177), 0));
;
1178 return retval;
1179}
1180
1181/*
1182 * Break all call backs on a single volume. Don't call this with any
1183 * hosts h_held. Note that this routine clears the callbacks before
1184 * actually breaking them, and that the vnode isn't locked during this
1185 * operation, so that people might see temporary callback loss while
1186 * this function is executing. It is just a temporary state, however,
1187 * since the callback will be broken later by this same function.
1188 *
1189 * Now uses multi-RX for CallBack RPC in a different thread,
1190 * only marking them here.
1191 */
1192#ifdef AFS_PTHREAD_ENV1
1193extern pthread_cond_t fsync_cond;
1194#else
1195extern char fsync_wait[];
1196#endif
1197
1198int
1199BreakVolumeCallBacksLater(afs_uint32 volume)
1200{
1201 int hash;
1202 afs_uint32 *feip;
1203 struct FileEntry *fe;
1204 struct CallBack *cb;
1205 struct host *host;
1206 int found = 0;
1207
1208 ViceLog(25, ("Setting later on volume %u\n", volume))do { if ((25) <= LogLevel) (FSLog ("Setting later on volume %u\n"
, volume)); } while (0)
;
1209 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 1209), 0));
;
1210 for (hash = 0; hash < FEHASH_SIZE512; hash++) {
1211 for (feip = &HashTable[hash]; (fe = itofe(*feip)((*feip)?FE+(*feip):0)) != NULL((void *)0); ) {
1212 if (fe->volid == volume) {
1213 struct CallBack *cbnext;
1214 for (cb = itocb(fe->firstcb)((fe->firstcb)?CB+(fe->firstcb):0); cb; cb = cbnext) {
1215 host = h_itoh(cb->hhead)(hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&(
512 -1)))
;
1216 host->hostFlags |= HFE_LATER0x80;
1217 cb->status = CB_DELAYED2;
1218 cbnext = itocb(cb->cnext)((cb->cnext)?CB+(cb->cnext):0);
1219 }
1220 FSYNC_LOCK(void)((pthread_mutex_lock(&fsync_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_lock(&fsync_glock_mutex) == 0"
, "./../viced/callback.c", 1220), 0));
;
1221 fe->status |= FE_LATER0x1;
1222 FSYNC_UNLOCK(void)((pthread_mutex_unlock(&fsync_glock_mutex) == 0) ||
(osi_AssertFailU("pthread_mutex_unlock(&fsync_glock_mutex) == 0"
, "./../viced/callback.c", 1222), 0));
;
1223 found = 1;
1224 }
1225 feip = &fe->fnext;
1226 }
1227 }
1228 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1228), 0));
;
1229 if (!found) {
1230 /* didn't find any callbacks, so return right away. */
1231 return 0;
1232 }
1233
1234 ViceLog(25, ("Fsync thread wakeup\n"))do { if ((25) <= LogLevel) (FSLog ("Fsync thread wakeup\n"
)); } while (0)
;
1235#ifdef AFS_PTHREAD_ENV1
1236 FSYNC_LOCK(void)((pthread_mutex_lock(&fsync_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_lock(&fsync_glock_mutex) == 0"
, "./../viced/callback.c", 1236), 0));
;
1237 CV_BROADCAST(&fsync_cond)(void)((pthread_cond_broadcast(&fsync_cond) == 0) || (osi_AssertFailU
("pthread_cond_broadcast(&fsync_cond) == 0", "./../viced/callback.c"
, 1237), 0))
;
1238 FSYNC_UNLOCK(void)((pthread_mutex_unlock(&fsync_glock_mutex) == 0) ||
(osi_AssertFailU("pthread_mutex_unlock(&fsync_glock_mutex) == 0"
, "./../viced/callback.c", 1238), 0));
;
1239#else
1240 LWP_NoYieldSignal(fsync_wait);
1241#endif
1242 return 0;
1243}
1244
1245int
1246BreakLaterCallBacks(void)
1247{
1248 struct AFSFid fid;
1249 int hash;
1250 afs_uint32 *feip;
1251 struct CallBack *cb;
1252 struct FileEntry *fe = NULL((void *)0);
1253 struct FileEntry *myfe = NULL((void *)0);
1254 struct host *host;
1255 struct VCBParams henumParms;
1256 unsigned short tthead = 0; /* zero is illegal value */
1257 char hoststr[16];
1258
1259 /* Unchain first */
1260 ViceLog(25, ("Looking for FileEntries to unchain\n"))do { if ((25) <= LogLevel) (FSLog ("Looking for FileEntries to unchain\n"
)); } while (0)
;
1261 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 1261), 0));
;
1262 FSYNC_LOCK(void)((pthread_mutex_lock(&fsync_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_lock(&fsync_glock_mutex) == 0"
, "./../viced/callback.c", 1262), 0));
;
1263 /* Pick the first volume we see to clean up */
1264 fid.Volume = fid.Vnode = fid.Unique = 0;
1265
1266 for (hash = 0; hash < FEHASH_SIZE512; hash++) {
1267 for (feip = &HashTable[hash]; (fe = itofe(*feip)((*feip)?FE+(*feip):0)) != NULL((void *)0); ) {
1268 if (fe && (fe->status & FE_LATER0x1)
1269 && (fid.Volume == 0 || fid.Volume == fe->volid)) {
1270 /* Ugly, but used to avoid left side casting */
1271 struct object *tmpfe;
1272 ViceLog(125,do { if ((125) <= LogLevel) (FSLog ("Unchaining for %u:%u:%u\n"
, fe->vnode, fe->unique, fe->volid)); } while (0)
1273 ("Unchaining for %u:%u:%u\n", fe->vnode, fe->unique,do { if ((125) <= LogLevel) (FSLog ("Unchaining for %u:%u:%u\n"
, fe->vnode, fe->unique, fe->volid)); } while (0)
1274 fe->volid))do { if ((125) <= LogLevel) (FSLog ("Unchaining for %u:%u:%u\n"
, fe->vnode, fe->unique, fe->volid)); } while (0)
;
1275 fid.Volume = fe->volid;
1276 *feip = fe->fnext;
1277 fe->status &= ~FE_LATER0x1; /* not strictly needed */
1278 /* Works since volid is deeper than the largest pointer */
1279 tmpfe = (struct object *)fe;
1280 tmpfe->next = (struct object *)myfe;
1281 myfe = fe;
1282 } else
1283 feip = &fe->fnext;
1284 }
1285 }
1286 FSYNC_UNLOCK(void)((pthread_mutex_unlock(&fsync_glock_mutex) == 0) ||
(osi_AssertFailU("pthread_mutex_unlock(&fsync_glock_mutex) == 0"
, "./../viced/callback.c", 1286), 0));
;
1287
1288 if (!myfe) {
1289 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1289), 0));
;
1290 return 0;
1291 }
1292
1293 /* loop over FEs from myfe and free/break */
1294 tthead = 0;
1295 for (fe = myfe; fe;) {
1296 struct CallBack *cbnext;
1297 for (cb = itocb(fe->firstcb)((fe->firstcb)?CB+(fe->firstcb):0); cb; cb = cbnext) {
1298 cbnext = itocb(cb->cnext)((cb->cnext)?CB+(cb->cnext):0);
1299 host = h_itoh(cb->hhead)(hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&(
512 -1)))
;
1300 if (cb->status == CB_DELAYED2) {
1301 if (!(host->hostFlags & HOSTDELETED0x10)) {
1302 /* mark this host for notification */
1303 host->hostFlags |= HCBREAK0x400;
1304 if (!tthead || (TNorm(tthead)((tthead)<(((tfirst)&127)+1)?(tthead)+128:(tthead)) < TNorm(cb->thead)((cb->thead)<(((tfirst)&127)+1)?(cb->thead)+128:
(cb->thead))
)) {
1305 tthead = cb->thead;
1306 }
1307 }
1308 TDel(cb);
1309 HDel(cb);
1310 CDel(cb, 0); /* Don't let CDel clean up the fe */
1311 /* leave flag for MultiBreakVolumeCallBack to clear */
1312 } else {
1313 ViceLog(125,do { if ((125) <= LogLevel) (FSLog ("Found host %p (%s:%d) non-DELAYED cb for %u:%u:%u\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)), fe->vnode, fe->unique, fe->volid))
; } while (0)
1314 ("Found host %p (%s:%d) non-DELAYED cb for %u:%u:%u\n",do { if ((125) <= LogLevel) (FSLog ("Found host %p (%s:%d) non-DELAYED cb for %u:%u:%u\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)), fe->vnode, fe->unique, fe->volid))
; } while (0)
1315 host, afs_inet_ntoa_r(host->host, hoststr),do { if ((125) <= LogLevel) (FSLog ("Found host %p (%s:%d) non-DELAYED cb for %u:%u:%u\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)), fe->vnode, fe->unique, fe->volid))
; } while (0)
1316 ntohs(host->port), fe->vnode, fe->unique, fe->volid))do { if ((125) <= LogLevel) (FSLog ("Found host %p (%s:%d) non-DELAYED cb for %u:%u:%u\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)), fe->vnode, fe->unique, fe->volid))
; } while (0)
;
1317 }
1318 }
1319 myfe = fe;
1320 fe = (struct FileEntry *)((struct object *)fe)->next;
1321 FreeFE(myfe)iFreeFE((struct FileEntry *)myfe, &cbstuff.nFEs);
1322 }
1323
1324 if (tthead) {
1325 ViceLog(125, ("Breaking volume %u\n", fid.Volume))do { if ((125) <= LogLevel) (FSLog ("Breaking volume %u\n"
, fid.Volume)); } while (0)
;
1326 henumParms.ncbas = 0;
1327 henumParms.fid = &fid;
1328 henumParms.thead = tthead;
1329 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1329), 0));
;
1330 h_Enumerate(MultiBreakVolumeLaterCallBack, (char *)&henumParms);
1331 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 1331), 0));
;
1332 if (henumParms.ncbas) { /* do left-overs */
1333 struct AFSCBFids tf;
1334 tf.AFSCBFids_len = 1;
1335 tf.AFSCBFids_val = &fid;
1336
1337 MultiBreakCallBack_r(henumParms.cba, henumParms.ncbas, &tf);
1338 henumParms.ncbas = 0;
1339 }
1340 }
1341 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1341), 0));
;
1342
1343 /* Arrange to be called again */
1344 return 1;
1345}
1346
1347/*
1348 * Delete all timed-out call back entries (to be called periodically by file
1349 * server)
1350 */
1351int
1352CleanupTimedOutCallBacks(void)
1353{
1354 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 1354), 0));
;
1355 CleanupTimedOutCallBacks_r();
1356 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1356), 0));
;
1357 return 0;
1358}
1359
1360int
1361CleanupTimedOutCallBacks_r(void)
1362{
1363 afs_uint32 now = CBtime(FT_ApproxTime())((FT_ApproxTime())>>7);
1364 afs_uint32 *thead;
1365 struct CallBack *cb;
1366 int ntimedout = 0;
1367 char hoststr[16];
1368
1369 while (tfirst <= now) {
1370 int cbi;
1371 cbi = *(thead = THead(tfirst)(&timeout[(((tfirst)&127)+1)-1]));
1372 if (cbi) {
1373 do {
1374 cb = itocb(cbi)((cbi)?CB+(cbi):0);
1375 cbi = cb->tnext;
1376 ViceLog(8,do { if ((8) <= LogLevel) (FSLog ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n"
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->host, afs_inet_ntoa_r((hosttableptrs[(cb->hhead
)>>9]+((cb->hhead)&(512 -1)))->host, hoststr)
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->port, ((cb->fhead)?FE+(cb->fhead):0)->
volid, ((cb->fhead)?FE+(cb->fhead):0)->vnode, ((cb->
fhead)?FE+(cb->fhead):0)->unique)); } while (0)
1377 ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n",do { if ((8) <= LogLevel) (FSLog ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n"
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->host, afs_inet_ntoa_r((hosttableptrs[(cb->hhead
)>>9]+((cb->hhead)&(512 -1)))->host, hoststr)
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->port, ((cb->fhead)?FE+(cb->fhead):0)->
volid, ((cb->fhead)?FE+(cb->fhead):0)->vnode, ((cb->
fhead)?FE+(cb->fhead):0)->unique)); } while (0)
1378 h_itoh(cb->hhead)->host,do { if ((8) <= LogLevel) (FSLog ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n"
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->host, afs_inet_ntoa_r((hosttableptrs[(cb->hhead
)>>9]+((cb->hhead)&(512 -1)))->host, hoststr)
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->port, ((cb->fhead)?FE+(cb->fhead):0)->
volid, ((cb->fhead)?FE+(cb->fhead):0)->vnode, ((cb->
fhead)?FE+(cb->fhead):0)->unique)); } while (0)
1379 afs_inet_ntoa_r(h_itoh(cb->hhead)->host, hoststr),do { if ((8) <= LogLevel) (FSLog ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n"
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->host, afs_inet_ntoa_r((hosttableptrs[(cb->hhead
)>>9]+((cb->hhead)&(512 -1)))->host, hoststr)
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->port, ((cb->fhead)?FE+(cb->fhead):0)->
volid, ((cb->fhead)?FE+(cb->fhead):0)->vnode, ((cb->
fhead)?FE+(cb->fhead):0)->unique)); } while (0)
1380 h_itoh(cb->hhead)->port, itofe(cb->fhead)->volid,do { if ((8) <= LogLevel) (FSLog ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n"
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->host, afs_inet_ntoa_r((hosttableptrs[(cb->hhead
)>>9]+((cb->hhead)&(512 -1)))->host, hoststr)
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->port, ((cb->fhead)?FE+(cb->fhead):0)->
volid, ((cb->fhead)?FE+(cb->fhead):0)->vnode, ((cb->
fhead)?FE+(cb->fhead):0)->unique)); } while (0)
1381 itofe(cb->fhead)->vnode, itofe(cb->fhead)->unique))do { if ((8) <= LogLevel) (FSLog ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n"
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->host, afs_inet_ntoa_r((hosttableptrs[(cb->hhead
)>>9]+((cb->hhead)&(512 -1)))->host, hoststr)
, (hosttableptrs[(cb->hhead)>>9]+((cb->hhead)&
(512 -1)))->port, ((cb->fhead)?FE+(cb->fhead):0)->
volid, ((cb->fhead)?FE+(cb->fhead):0)->vnode, ((cb->
fhead)?FE+(cb->fhead):0)->unique)); } while (0)
;
1382 HDel(cb);
1383 CDel(cb, 1);
1384 ntimedout++;
1385 if (ntimedout > cbstuff.nblks) {
1386 ViceLog(0, ("CCB: Internal Error -- shutting down...\n"))do { if ((0) <= LogLevel) (FSLog ("CCB: Internal Error -- shutting down...\n"
)); } while (0)
;
1387 DumpCallBackState_r();
1388 ShutDownAndCore(PANIC1);
1389 }
1390 } while (cbi != *thead);
1391 *thead = 0;
1392 }
1393 tfirst++;
1394 }
1395 cbstuff.CBsTimedOut += ntimedout;
1396 ViceLog(7, ("CCB: deleted %d timed out callbacks\n", ntimedout))do { if ((7) <= LogLevel) (FSLog ("CCB: deleted %d timed out callbacks\n"
, ntimedout)); } while (0)
;
1397 return (ntimedout > 0);
1398}
1399
1400/**
1401 * parameters to pass to lih*_r from h_Enumerate_r when trying to find a host
1402 * from which to clear callbacks.
1403 */
1404struct lih_params {
1405 /**
1406 * Points to the least interesting host found; try to clear callbacks on
1407 * this host after h_Enumerate_r(lih*_r)'ing.
1408 */
1409 struct host *lih;
1410
1411 /**
1412 * The last host we got from lih*_r, but we couldn't clear its callbacks
1413 * for some reason. Choose the next-best host after this one (with the
1414 * current lih*_r, this means to only select hosts that have an ActiveCall
1415 * newer than lastlih).
1416 */
1417 struct host *lastlih;
1418};
1419
1420/* Value of host->refCount that allows us to reliably infer that
1421 * host may be held by some other thread */
1422#define OTHER_MUSTHOLD_LIH2 2
1423
1424/* This version does not allow 'host' to be selected unless its ActiveCall
1425 * is newer than 'params->lastlih' which is the host with the oldest
1426 * ActiveCall from the last pass (if it is provided). We filter out any hosts
1427 * that are are held by other threads.
1428 *
1429 * There is a small problem here, but it may not be easily fixable. Say we
1430 * select some host A, and give it back to GetSomeSpace_r. GSS_r for some
1431 * reason cannot clear the callbacks on A, and so calls us again with
1432 * lastlih = A. Suppose there is another host B that has the same ActiveCall
1433 * time as A. We will now skip over host B, since
1434 * 'hostB->ActiveCall > hostA->ActiveCall' is not true. This could result in
1435 * us prematurely going to the GSS_r 2nd or 3rd pass, and making us a little
1436 * inefficient. This should be pretty rare, though, except perhaps in cases
1437 * with very small numbers of hosts.
1438 *
1439 * Also filter out any hosts with HOSTDELETED set. h_Enumerate_r should in
1440 * theory not give these to us anyway, but be paranoid.
1441 */
1442static int
1443lih0_r(struct host *host, void *rock)
1444{
1445 struct lih_params *params = (struct lih_params *)rock;
1446
1447 /* OTHER_MUSTHOLD_LIH is because the h_Enum loop holds us once */
1448 if (host->cblist
1449 && (!(host->hostFlags & HOSTDELETED0x10))
1450 && (host->refCount < OTHER_MUSTHOLD_LIH2)
1451 && (!params->lih || host->ActiveCall < params->lih->ActiveCall)
1452 && (!params->lastlih || host->ActiveCall > params->lastlih->ActiveCall)) {
1453
1454 if (params->lih) {
1455 h_Release_r(params->lih)do { do { --((params->lih)->refCount); } while (0); if (
((params->lih)->refCount < 1) && (((params->
lih)->hostFlags & 0x10) || ((params->lih)->hostFlags
& 0x20))) h_TossStuff_r((params->lih)); } while(0)
; /* release prev host */
1456 }
1457
1458 h_Hold_r(host)do { ++((host)->refCount); } while(0);
1459 params->lih = host;
1460 }
1461 return 0;
1462}
1463
1464/* same as lih0_r, except we do not prevent held hosts from being selected. */
1465static int
1466lih1_r(struct host *host, void *rock)
1467{
1468 struct lih_params *params = (struct lih_params *)rock;
1469
1470 if (host->cblist
1471 && (!(host->hostFlags & HOSTDELETED0x10))
1472 && (!params->lih || host->ActiveCall < params->lih->ActiveCall)
1473 && (!params->lastlih || host->ActiveCall > params->lastlih->ActiveCall)) {
1474
1475 if (params->lih) {
1476 h_Release_r(params->lih)do { do { --((params->lih)->refCount); } while (0); if (
((params->lih)->refCount < 1) && (((params->
lih)->hostFlags & 0x10) || ((params->lih)->hostFlags
& 0x20))) h_TossStuff_r((params->lih)); } while(0)
; /* release prev host */
1477 }
1478
1479 h_Hold_r(host)do { ++((host)->refCount); } while(0);
1480 params->lih = host;
1481 }
1482 return 0;
1483}
1484
1485/* This could be upgraded to get more space each time */
1486/* first pass: sequentially find the oldest host which isn't held by
1487 anyone for which we can clear callbacks;
1488 skipping 'hostp' */
1489/* second pass: sequentially find the oldest host regardless of
1490 whether or not the host is held; skipping 'hostp' */
1491/* third pass: attempt to clear callbacks from 'hostp' */
1492/* always called with hostp unlocked */
1493
1494/* Note: hostlist is ordered most recently created host first and
1495 * its order has no relationship to the most recently used. */
1496extern struct host *hostList;
1497static int
1498GetSomeSpace_r(struct host *hostp, int locked)
1499{
1500 struct host *hp;
1501 struct lih_params params;
1502 int i = 0;
1503
1504 cbstuff.GotSomeSpaces++;
1505 ViceLog(5,do { if ((5) <= LogLevel) (FSLog ("GSS: First looking for timed out call backs via CleanupCallBacks\n"
)); } while (0)
1506 ("GSS: First looking for timed out call backs via CleanupCallBacks\n"))do { if ((5) <= LogLevel) (FSLog ("GSS: First looking for timed out call backs via CleanupCallBacks\n"
)); } while (0)
;
1507 if (CleanupTimedOutCallBacks_r()) {
1508 cbstuff.GSS3++;
1509 return 0;
1510 }
1511
1512 i = 0;
1513 params.lastlih = NULL((void *)0);
1514
1515 do {
1516 params.lih = NULL((void *)0);
1517
1518 h_Enumerate_r(i == 0 ? lih0_r : lih1_r, hostList, &params);
1519
1520 hp = params.lih;
1521 if (params.lastlih) {
1522 h_Release_r(params.lastlih)do { do { --((params.lastlih)->refCount); } while (0); if (
((params.lastlih)->refCount < 1) && (((params.lastlih
)->hostFlags & 0x10) || ((params.lastlih)->hostFlags
& 0x20))) h_TossStuff_r((params.lastlih)); } while(0)
;
1523 params.lastlih = NULL((void *)0);
1524 }
1525
1526 if (hp) {
1527 /* note that 'hp' was held by lih*_r; we will need to release it */
1528 cbstuff.GSS4++;
1529 if ((hp != hostp) && !ClearHostCallbacks_r(hp, 0 /* not locked or held */ )) {
1530 h_Release_r(hp)do { do { --((hp)->refCount); } while (0); if (((hp)->refCount
< 1) && (((hp)->hostFlags & 0x10) || ((hp)
->hostFlags & 0x20))) h_TossStuff_r((hp)); } while(0)
;
1531 return 0;
1532 }
1533
1534 params.lastlih = hp;
1535 /* params.lastlih will be released on the next iteration, after
1536 * h_Enumerate_r */
1537
1538 } else {
1539 /*
1540 * Next time try getting callbacks from any host even if
1541 * it's held, since the only other option is starvation for
1542 * the file server (i.e. until the callback timeout arrives).
1543 */
1544 i++;
1545 params.lastlih = NULL((void *)0);
1546 cbstuff.GSS1++;
1547 ViceLog(5,do { if ((5) <= LogLevel) (FSLog ("GSS: Try harder for longest inactive host cnt= %d\n"
, i)); } while (0)
1548 ("GSS: Try harder for longest inactive host cnt= %d\n",do { if ((5) <= LogLevel) (FSLog ("GSS: Try harder for longest inactive host cnt= %d\n"
, i)); } while (0)
1549 i))do { if ((5) <= LogLevel) (FSLog ("GSS: Try harder for longest inactive host cnt= %d\n"
, i)); } while (0)
;
1550 }
1551 } while (i < 2);
1552
1553 /* Could not obtain space from other hosts, clear hostp's callback state */
1554 cbstuff.GSS2++;
1555 if (!locked) {
1556 h_Lock_r(hostp);
1557 }
1558 ClearHostCallbacks_r(hostp, 1 /*already locked */ );
1559 if (!locked) {
1560 h_Unlock_r(hostp)do { (void)((pthread_mutex_lock(&(&(hostp)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(hostp)->lock)->mutex) == 0"
, "./../viced/callback.c", 1560), 0));; (&(hostp)->lock
)->excl_locked &= ~2; if ((&(hostp)->lock)->
wait_states) Afs_Lock_ReleaseR(&(hostp)->lock); (void)
((pthread_mutex_unlock(&(&(hostp)->lock)->mutex
) == 0) || (osi_AssertFailU("pthread_mutex_unlock(&(&(hostp)->lock)->mutex) == 0"
, "./../viced/callback.c", 1560), 0));; } while (0)
;
1561 }
1562 return 0;
1563}
1564
1565/* locked - set if caller has already locked the host */
1566static int
1567ClearHostCallbacks_r(struct host *hp, int locked)
1568{
1569 int code;
1570 char hoststr[16];
1571 struct rx_connection *cb_conn = NULL((void *)0);
1572
1573 ViceLog(5,do { if ((5) <= LogLevel) (FSLog ("GSS: Delete longest inactive host %p (%s:%d)\n"
, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
1574 ("GSS: Delete longest inactive host %p (%s:%d)\n",do { if ((5) <= LogLevel) (FSLog ("GSS: Delete longest inactive host %p (%s:%d)\n"
, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
1575 hp, afs_inet_ntoa_r(hp->host, hoststr), ntohs(hp->port)))do { if ((5) <= LogLevel) (FSLog ("GSS: Delete longest inactive host %p (%s:%d)\n"
, hp, afs_inet_ntoa_r(hp->host, hoststr), (__builtin_constant_p
(hp->port) ? (__uint16_t)(((__uint16_t)(hp->port)) <<
8 | ((__uint16_t)(hp->port)) >> 8) : __bswap16_var(
hp->port)))); } while (0)
;
1576
1577 if ((hp->hostFlags & HOSTDELETED0x10)) {
1578 /* hp could go away after reacquiring H_LOCK in h_NBLock_r, so we can't
1579 * really use it; its callbacks will get cleared anyway when
1580 * h_TossStuff_r gets its hands on it */
1581 return 1;
1582 }
1583
1584 h_Hold_r(hp)do { ++((hp)->refCount); } while(0);
1585
1586 /** Try a non-blocking lock. If the lock is already held return
1587 * after releasing hold on hp
1588 */
1589 if (!locked) {
1590 if (h_NBLock_r(hp)) {
1591 h_Release_r(hp)do { do { --((hp)->refCount); } while (0); if (((hp)->refCount
< 1) && (((hp)->hostFlags & 0x10) || ((hp)
->hostFlags & 0x20))) h_TossStuff_r((hp)); } while(0)
;
1592 return 1;
1593 }
1594 }
1595 if (hp->Console & 2) {
1596 /*
1597 * If the special console field is set it means that a thread
1598 * is waiting in AddCallBack1 after it set pointers to the
1599 * file entry and/or callback entry. Because of the bogus
1600 * usage of h_hold it won't prevent from another thread, this
1601 * one, to remove all the callbacks so just to be safe we keep
1602 * a reference. NOTE, on the last phase we'll free the calling
1603 * host's callbacks but that's ok...
1604 */
1605 cbstuff.GSS5++;
1606 }
1607 DeleteAllCallBacks_r(hp, 1);
1608 if (hp->hostFlags & VENUSDOWN0x08) {
1609 hp->hostFlags &= ~RESETDONE0x40; /* remember that we must do a reset */
1610 } else if (!(hp->hostFlags & HOSTDELETED0x10)) {
1611 /* host is up, try a call */
1612 hp->hostFlags &= ~ALTADDR0x04; /* alternate addresses are invalid */
1613 cb_conn = hp->callback_rxcon;
1614 rx_GetConnection(hp->callback_rxcon);
1615 if (hp->interface) {
1616 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1616), 0));
;
1617 code =
1618 RXAFSCB_InitCallBackState3(cb_conn, &FS_HostUUID);
1619 } else {
1620 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 1620), 0));
;
1621 code = RXAFSCB_InitCallBackState(cb_conn);
1622 }
1623 rx_PutConnection(cb_conn)rx_DestroyConnection(cb_conn);
1624 cb_conn = NULL((void *)0);
1625 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 1625), 0));
;
1626 hp->hostFlags |= ALTADDR0x04; /* alternate addresses are valid */
1627 if (code) {
1628 /* failed, mark host down and need reset */
1629 hp->hostFlags |= VENUSDOWN0x08;
1630 hp->hostFlags &= ~RESETDONE0x40;
1631 } else {
1632 /* reset succeeded, we're done */
1633 hp->hostFlags |= RESETDONE0x40;
1634 }
1635 }
1636 if (!locked)
1637 h_Unlock_r(hp)do { (void)((pthread_mutex_lock(&(&(hp)->lock)->
mutex) == 0) || (osi_AssertFailU("pthread_mutex_lock(&(&(hp)->lock)->mutex) == 0"
, "./../viced/callback.c", 1637), 0));; (&(hp)->lock)->
excl_locked &= ~2; if ((&(hp)->lock)->wait_states
) Afs_Lock_ReleaseR(&(hp)->lock); (void)((pthread_mutex_unlock
(&(&(hp)->lock)->mutex) == 0) || (osi_AssertFailU
("pthread_mutex_unlock(&(&(hp)->lock)->mutex) == 0"
, "./../viced/callback.c", 1637), 0));; } while (0)
;
1638 h_Release_r(hp)do { do { --((hp)->refCount); } while (0); if (((hp)->refCount
< 1) && (((hp)->hostFlags & 0x10) || ((hp)
->hostFlags & 0x20))) h_TossStuff_r((hp)); } while(0)
;
1639
1640 return 0;
1641}
1642#endif /* INTERPRET_DUMP */
1643
1644
1645int
1646PrintCallBackStats(void)
1647{
1648 fprintf(stderr__stderrp,
1649 "%d add CB, %d break CB, %d del CB, %d del FE, %d CB's timed out, %d space reclaim, %d del host\n",
1650 cbstuff.AddCallBacks, cbstuff.BreakCallBacks,
1651 cbstuff.DeleteCallBacks, cbstuff.DeleteFiles, cbstuff.CBsTimedOut,
1652 cbstuff.GotSomeSpaces, cbstuff.DeleteAllCallBacks);
1653 fprintf(stderr__stderrp, "%d CBs, %d FEs, (%d of total of %d 16-byte blocks)\n",
1654 cbstuff.nCBs, cbstuff.nFEs, cbstuff.nCBs + cbstuff.nFEs,
1655 cbstuff.nblks);
1656 fprintf(stderr__stderrp, "%d GSS1, %d GSS2, %d GSS3, %d GSS4, %d GSS5 (internal counters)\n",
1657 cbstuff.GSS1, cbstuff.GSS2, cbstuff.GSS3, cbstuff.GSS4, cbstuff.GSS5);
1658
1659 return 0;
1660}
1661
1662#define MAGIC0x12345678 0x12345678 /* To check byte ordering of dump when it is read in */
1663#define MAGICV20x12345679 0x12345679 /* To check byte ordering & version of dump when it is read in */
1664
1665
1666#ifndef INTERPRET_DUMP
1667
1668#ifdef AFS_DEMAND_ATTACH_FS1
1669/*
1670 * demand attach fs
1671 * callback state serialization
1672 */
1673static int cb_stateSaveTimeouts(struct fs_dump_state * state);
1674static int cb_stateSaveFEHash(struct fs_dump_state * state);
1675static int cb_stateSaveFEs(struct fs_dump_state * state);
1676static int cb_stateSaveFE(struct fs_dump_state * state, struct FileEntry * fe);
1677static int cb_stateRestoreTimeouts(struct fs_dump_state * state);
1678static int cb_stateRestoreFEHash(struct fs_dump_state * state);
1679static int cb_stateRestoreFEs(struct fs_dump_state * state);
1680static int cb_stateRestoreFE(struct fs_dump_state * state);
1681static int cb_stateRestoreCBs(struct fs_dump_state * state, struct FileEntry * fe,
1682 struct iovec * iov, int niovecs);
1683
1684static int cb_stateVerifyFEHash(struct fs_dump_state * state);
1685static int cb_stateVerifyFE(struct fs_dump_state * state, struct FileEntry * fe);
1686static int cb_stateVerifyFCBList(struct fs_dump_state * state, struct FileEntry * fe);
1687static int cb_stateVerifyTimeoutQueues(struct fs_dump_state * state);
1688
1689static int cb_stateFEToDiskEntry(struct FileEntry *, struct FEDiskEntry *);
1690static int cb_stateDiskEntryToFE(struct fs_dump_state * state,
1691 struct FEDiskEntry *, struct FileEntry *);
1692
1693static int cb_stateCBToDiskEntry(struct CallBack *, struct CBDiskEntry *);
1694static int cb_stateDiskEntryToCB(struct fs_dump_state * state,
1695 struct CBDiskEntry *, struct CallBack *);
1696
1697static int cb_stateFillHeader(struct callback_state_header * hdr);
1698static int cb_stateCheckHeader(struct callback_state_header * hdr);
1699
1700static int cb_stateAllocMap(struct fs_dump_state * state);
1701
1702int
1703cb_stateSave(struct fs_dump_state * state)
1704{
1705 int ret = 0;
1706
1707 AssignInt64(state->eof_offset, &state->hdr->cb_offset)*(&state->hdr->cb_offset) = (state->eof_offset);
1708
1709 /* invalidate callback state header */
1710 memset(state->cb_hdr, 0, sizeof(struct callback_state_header));
1711 if (fs_stateWriteHeader(state, &state->hdr->cb_offset, state->cb_hdr,
1712 sizeof(struct callback_state_header))) {
1713 ret = 1;
1714 goto done;
1715 }
1716
1717 fs_stateIncEOF(state, sizeof(struct callback_state_header));
1718
1719 /* dump timeout state */
1720 if (cb_stateSaveTimeouts(state)) {
1721 ret = 1;
1722 goto done;
1723 }
1724
1725 /* dump fe hashtable state */
1726 if (cb_stateSaveFEHash(state)) {
1727 ret = 1;
1728 goto done;
1729 }
1730
1731 /* dump callback state */
1732 if (cb_stateSaveFEs(state)) {
1733 ret = 1;
1734 goto done;
1735 }
1736
1737 /* write the callback state header to disk */
1738 cb_stateFillHeader(state->cb_hdr);
1739 if (fs_stateWriteHeader(state, &state->hdr->cb_offset, state->cb_hdr,
1740 sizeof(struct callback_state_header))) {
1741 ret = 1;
1742 goto done;
1743 }
1744
1745 done:
1746 return ret;
1747}
1748
1749int
1750cb_stateRestore(struct fs_dump_state * state)
1751{
1752 int ret = 0;
1753
1754 if (fs_stateReadHeader(state, &state->hdr->cb_offset, state->cb_hdr,
1755 sizeof(struct callback_state_header))) {
1756 ret = 1;
1757 goto done;
1758 }
1759
1760 if (cb_stateCheckHeader(state->cb_hdr)) {
1761 ret = 1;
1762 goto done;
1763 }
1764
1765 if (cb_stateAllocMap(state)) {
1766 ret = 1;
1767 goto done;
1768 }
1769
1770 if (cb_stateRestoreTimeouts(state)) {
1771 ret = 1;
1772 goto done;
1773 }
1774
1775 if (cb_stateRestoreFEHash(state)) {
1776 ret = 1;
1777 goto done;
1778 }
1779
1780 /* restore FEs and CBs from disk */
1781 if (cb_stateRestoreFEs(state)) {
1782 ret = 1;
1783 goto done;
1784 }
1785
1786 /* restore the timeout queue heads */
1787 tfirst = state->cb_hdr->tfirst;
1788
1789 done:
1790 return ret;
1791}
1792
1793int
1794cb_stateRestoreIndices(struct fs_dump_state * state)
1795{
1796 int i, ret = 0;
1797 struct FileEntry * fe;
1798 struct CallBack * cb;
1799
1800 /* restore indices in the FileEntry structures */
1801 for (i = 1; i < state->fe_map.len; i++) {
1802 if (state->fe_map.entries[i].new_idx) {
1803 fe = itofe(state->fe_map.entries[i].new_idx)((state->fe_map.entries[i].new_idx)?FE+(state->fe_map.entries
[i].new_idx):0)
;
1804
1805 /* restore the fe->fnext entry */
1806 if (fe_OldToNew(state, fe->fnext, &fe->fnext)) {
1807 ret = 1;
1808 goto done;
1809 }
1810
1811 /* restore the fe->firstcb entry */
1812 if (cb_OldToNew(state, fe->firstcb, &fe->firstcb)) {
1813 ret = 1;
1814 goto done;
1815 }
1816 }
1817 }
1818
1819 /* restore indices in the CallBack structures */
1820 for (i = 1; i < state->cb_map.len; i++) {
1821 if (state->cb_map.entries[i].new_idx) {
1822 cb = itocb(state->cb_map.entries[i].new_idx)((state->cb_map.entries[i].new_idx)?CB+(state->cb_map.entries
[i].new_idx):0)
;
1823
1824 /* restore the cb->cnext entry */
1825 if (cb_OldToNew(state, cb->cnext, &cb->cnext)) {
1826 ret = 1;
1827 goto done;
1828 }
1829
1830 /* restore the cb->fhead entry */
1831 if (fe_OldToNew(state, cb->fhead, &cb->fhead)) {
1832 ret = 1;
1833 goto done;
1834 }
1835
1836 /* restore the cb->hhead entry */
1837 if (h_OldToNew(state, cb->hhead, &cb->hhead)) {
1838 ret = 1;
1839 goto done;
1840 }
1841
1842 /* restore the cb->tprev entry */
1843 if (cb_OldToNew(state, cb->tprev, &cb->tprev)) {
1844 ret = 1;
1845 goto done;
1846 }
1847
1848 /* restore the cb->tnext entry */
1849 if (cb_OldToNew(state, cb->tnext, &cb->tnext)) {
1850 ret = 1;
1851 goto done;
1852 }
1853
1854 /* restore the cb->hprev entry */
1855 if (cb_OldToNew(state, cb->hprev, &cb->hprev)) {
1856 ret = 1;
1857 goto done;
1858 }
1859
1860 /* restore the cb->hnext entry */
1861 if (cb_OldToNew(state, cb->hnext, &cb->hnext)) {
1862 ret = 1;
1863 goto done;
1864 }
1865 }
1866 }
1867
1868 /* restore the timeout queue head indices */
1869 for (i = 0; i < state->cb_timeout_hdr->records; i++) {
1870 if (cb_OldToNew(state, timeout[i], &timeout[i])) {
1871 ret = 1;
1872 goto done;
1873 }
1874 }
1875
1876 /* restore the FE hash table queue heads */
1877 for (i = 0; i < state->cb_fehash_hdr->records; i++) {
1878 if (fe_OldToNew(state, HashTable[i], &HashTable[i])) {
1879 ret = 1;
1880 goto done;
1881 }
1882 }
1883
1884 done:
1885 return ret;
1886}
1887
1888int
1889cb_stateVerify(struct fs_dump_state * state)
1890{
1891 int ret = 0;
1892
1893 if (cb_stateVerifyFEHash(state)) {
1894 ret = 1;
1895 }
1896
1897 if (cb_stateVerifyTimeoutQueues(state)) {
1898 ret = 1;
1899 }
1900
1901 return ret;
1902}
1903
1904static int
1905cb_stateVerifyFEHash(struct fs_dump_state * state)
1906{
1907 int ret = 0, i;
1908 struct FileEntry * fe;
1909 afs_uint32 fei, chain_len;
1910
1911 for (i = 0; i < FEHASH_SIZE512; i++) {
1912 chain_len = 0;
1913 for (fei = HashTable[i], fe = itofe(fei)((fei)?FE+(fei):0);
1914 fe;
1915 fei = fe->fnext, fe = itofe(fei)((fei)?FE+(fei):0)) {
1916 if (fei > cbstuff.nblks) {
1917 ViceLog(0, ("cb_stateVerifyFEHash: error: index out of range (fei=%d)\n", fei))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFEHash: error: index out of range (fei=%d)\n"
, fei)); } while (0)
;
1918 ret = 1;
1919 break;
1920 }
1921 if (cb_stateVerifyFE(state, fe)) {
1922 ret = 1;
1923 }
1924 if (chain_len > FS_STATE_FE_MAX_HASH_CHAIN_LEN100000) {
1925 ViceLog(0, ("cb_stateVerifyFEHash: error: hash chain %d length exceeds %d; assuming there's a loop\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFEHash: error: hash chain %d length exceeds %d; assuming there's a loop\n"
, i, 100000)); } while (0)
1926 i, FS_STATE_FE_MAX_HASH_CHAIN_LEN))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFEHash: error: hash chain %d length exceeds %d; assuming there's a loop\n"
, i, 100000)); } while (0)
;
1927 ret = 1;
1928 break;
1929 }
1930 chain_len++;
1931 }
1932 }
1933
1934 return ret;
1935}
1936
1937static int
1938cb_stateVerifyFE(struct fs_dump_state * state, struct FileEntry * fe)
1939{
1940 int ret = 0;
1941
1942 if ((fe->firstcb && !fe->ncbs) ||
1943 (!fe->firstcb && fe->ncbs)) {
1944 ViceLog(0, ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%lu, fe->firstcb=%lu, fe->ncbs=%lu)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%lu, fe->firstcb=%lu, fe->ncbs=%lu)\n"
, afs_printable_uint32_lu(((afs_uint32)(!(fe)?0:(fe)-FE))), afs_printable_uint32_lu
(fe->firstcb), afs_printable_uint32_lu(fe->ncbs))); } while
(0)
1945 afs_printable_uint32_lu(fetoi(fe)),do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%lu, fe->firstcb=%lu, fe->ncbs=%lu)\n"
, afs_printable_uint32_lu(((afs_uint32)(!(fe)?0:(fe)-FE))), afs_printable_uint32_lu
(fe->firstcb), afs_printable_uint32_lu(fe->ncbs))); } while
(0)
1946 afs_printable_uint32_lu(fe->firstcb),do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%lu, fe->firstcb=%lu, fe->ncbs=%lu)\n"
, afs_printable_uint32_lu(((afs_uint32)(!(fe)?0:(fe)-FE))), afs_printable_uint32_lu
(fe->firstcb), afs_printable_uint32_lu(fe->ncbs))); } while
(0)
1947 afs_printable_uint32_lu(fe->ncbs)))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%lu, fe->firstcb=%lu, fe->ncbs=%lu)\n"
, afs_printable_uint32_lu(((afs_uint32)(!(fe)?0:(fe)-FE))), afs_printable_uint32_lu
(fe->firstcb), afs_printable_uint32_lu(fe->ncbs))); } while
(0)
;
1948 ret = 1;
1949 }
1950 if (cb_stateVerifyFCBList(state, fe)) {
1951 ViceLog(0, ("cb_stateVerifyFE: error: FCBList failed verification (fei=%lu)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFE: error: FCBList failed verification (fei=%lu)\n"
, afs_printable_uint32_lu(((afs_uint32)(!(fe)?0:(fe)-FE)))));
} while (0)
1952 afs_printable_uint32_lu(fetoi(fe))))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFE: error: FCBList failed verification (fei=%lu)\n"
, afs_printable_uint32_lu(((afs_uint32)(!(fe)?0:(fe)-FE)))));
} while (0)
;
1953 ret = 1;
1954 }
1955
1956 return ret;
1957}
1958
1959static int
1960cb_stateVerifyFCBList(struct fs_dump_state * state, struct FileEntry * fe)
1961{
1962 int ret = 0;
1963 afs_uint32 cbi, fei, chain_len = 0;
1964 struct CallBack * cb;
1965
1966 fei = fetoi(fe)((afs_uint32)(!(fe)?0:(fe)-FE));
1967
1968 for (cbi = fe->firstcb, cb = itocb(cbi)((cbi)?CB+(cbi):0);
1969 cb;
1970 cbi = cb->cnext, cb = itocb(cbi)((cbi)?CB+(cbi):0)) {
1971 if (cbi > cbstuff.nblks) {
1972 ViceLog(0, ("cb_stateVerifyFCBList: error: list index out of range (cbi=%d, ncbs=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: list index out of range (cbi=%d, ncbs=%d)\n"
, cbi, cbstuff.nblks)); } while (0)
1973 cbi, cbstuff.nblks))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: list index out of range (cbi=%d, ncbs=%d)\n"
, cbi, cbstuff.nblks)); } while (0)
;
1974 ret = 1;
1975 goto done;
1976 }
1977 if (cb->fhead != fei) {
1978 ViceLog(0, ("cb_stateVerifyFCBList: error: cb->fhead != fei (fei=%d, cb->fhead=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: cb->fhead != fei (fei=%d, cb->fhead=%d)\n"
, fei, cb->fhead)); } while (0)
1979 fei, cb->fhead))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: cb->fhead != fei (fei=%d, cb->fhead=%d)\n"
, fei, cb->fhead)); } while (0)
;
1980 ret = 1;
1981 }
1982 if (chain_len > FS_STATE_FCB_MAX_LIST_LEN100000) {
1983 ViceLog(0, ("cb_stateVerifyFCBList: error: list length exceeds %d (fei=%d); assuming there's a loop\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: list length exceeds %d (fei=%d); assuming there's a loop\n"
, 100000, fei)); } while (0)
1984 FS_STATE_FCB_MAX_LIST_LEN, fei))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: list length exceeds %d (fei=%d); assuming there's a loop\n"
, 100000, fei)); } while (0)
;
1985 ret = 1;
1986 goto done;
1987 }
1988 chain_len++;
1989 }
1990
1991 if (fe->ncbs != chain_len) {
1992 ViceLog(0, ("cb_stateVerifyFCBList: error: list length mismatch (len=%d, fe->ncbs=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: list length mismatch (len=%d, fe->ncbs=%d)\n"
, chain_len, fe->ncbs)); } while (0)
1993 chain_len, fe->ncbs))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: list length mismatch (len=%d, fe->ncbs=%d)\n"
, chain_len, fe->ncbs)); } while (0)
;
1994 ret = 1;
1995 }
1996
1997 done:
1998 return ret;
1999}
2000
2001int
2002cb_stateVerifyHCBList(struct fs_dump_state * state, struct host * host)
2003{
2004 int ret = 0;
2005 afs_uint32 hi, chain_len, cbi;
2006 struct CallBack *cb, *ncb;
2007
2008 hi = h_htoi(host)((host)->index);
2009 chain_len = 0;
2010
2011 for (cbi = host->cblist, cb = itocb(cbi)((cbi)?CB+(cbi):0);
2012 cb;
2013 cbi = cb->hnext, cb = ncb) {
2014 if (chain_len && (host->cblist == cbi)) {
2015 /* we've wrapped around the circular list, and everything looks ok */
2016 break;
2017 }
2018 if (cb->hhead != hi) {
2019 ViceLog(0, ("cb_stateVerifyHCBList: error: incorrect cb->hhead (cbi=%d, h->index=%d, cb->hhead=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyHCBList: error: incorrect cb->hhead (cbi=%d, h->index=%d, cb->hhead=%d)\n"
, cbi, hi, cb->hhead)); } while (0)
2020 cbi, hi, cb->hhead))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyHCBList: error: incorrect cb->hhead (cbi=%d, h->index=%d, cb->hhead=%d)\n"
, cbi, hi, cb->hhead)); } while (0)
;
2021 ret = 1;
2022 }
2023 if (!cb->hprev || !cb->hnext) {
2024 ViceLog(0, ("cb_stateVerifyHCBList: error: null index in circular list (cbi=%d, h->index=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyHCBList: error: null index in circular list (cbi=%d, h->index=%d)\n"
, cbi, hi)); } while (0)
2025 cbi, hi))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyHCBList: error: null index in circular list (cbi=%d, h->index=%d)\n"
, cbi, hi)); } while (0)
;
2026 ret = 1;
2027 goto done;
2028 }
2029 if ((cb->hprev > cbstuff.nblks) ||
2030 (cb->hnext > cbstuff.nblks)) {
2031 ViceLog(0, ("cb_stateVerifyHCBList: error: list index out of range (cbi=%d, h->index=%d, cb->hprev=%d, cb->hnext=%d, nCBs=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyHCBList: error: list index out of range (cbi=%d, h->index=%d, cb->hprev=%d, cb->hnext=%d, nCBs=%d)\n"
, cbi, hi, cb->hprev, cb->hnext, cbstuff.nblks)); } while
(0)
2032 cbi, hi, cb->hprev, cb->hnext, cbstuff.nblks))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyHCBList: error: list index out of range (cbi=%d, h->index=%d, cb->hprev=%d, cb->hnext=%d, nCBs=%d)\n"
, cbi, hi, cb->hprev, cb->hnext, cbstuff.nblks)); } while
(0)
;
2033 ret = 1;
2034 goto done;
2035 }
2036 ncb = itocb(cb->hnext)((cb->hnext)?CB+(cb->hnext):0);
2037 if (cbi != ncb->hprev) {
2038 ViceLog(0, ("cb_stateVerifyHCBList: error: corrupt linked list (cbi=%d, h->index=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyHCBList: error: corrupt linked list (cbi=%d, h->index=%d)\n"
, cbi, hi)); } while (0)
2039 cbi, hi))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyHCBList: error: corrupt linked list (cbi=%d, h->index=%d)\n"
, cbi, hi)); } while (0)
;
2040 ret = 1;
2041 goto done;
2042 }
2043 if (chain_len > FS_STATE_HCB_MAX_LIST_LEN100000) {
2044 ViceLog(0, ("cb_stateVerifyFCBList: error: list length exceeds %d (h->index=%d); assuming there's a loop\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: list length exceeds %d (h->index=%d); assuming there's a loop\n"
, 100000, hi)); } while (0)
2045 FS_STATE_HCB_MAX_LIST_LEN, hi))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyFCBList: error: list length exceeds %d (h->index=%d); assuming there's a loop\n"
, 100000, hi)); } while (0)
;
2046 ret = 1;
2047 goto done;
2048 }
2049 chain_len++;
2050 }
2051
2052 done:
2053 return ret;
2054}
2055
2056static int
2057cb_stateVerifyTimeoutQueues(struct fs_dump_state * state)
2058{
2059 int ret = 0, i;
2060 afs_uint32 cbi, chain_len;
2061 struct CallBack *cb, *ncb;
2062
2063 for (i = 0; i < CB_NUM_TIMEOUT_QUEUES128; i++) {
2064 chain_len = 0;
2065 for (cbi = timeout[i], cb = itocb(cbi)((cbi)?CB+(cbi):0);
2066 cb;
2067 cbi = cb->tnext, cb = ncb) {
2068 if (chain_len && (cbi == timeout[i])) {
2069 /* we've wrapped around the circular list, and everything looks ok */
2070 break;
2071 }
2072 if (cbi > cbstuff.nblks) {
2073 ViceLog(0, ("cb_stateVerifyTimeoutQueues: error: list index out of range (cbi=%d, tindex=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: error: list index out of range (cbi=%d, tindex=%d)\n"
, cbi, i)); } while (0)
2074 cbi, i))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: error: list index out of range (cbi=%d, tindex=%d)\n"
, cbi, i)); } while (0)
;
2075 ret = 1;
2076 break;
2077 }
2078 if (itot(cb->thead)((timeout)+(cb->thead-1)) != &timeout[i]) {
2079 ViceLog(0, ("cb_stateVerifyTimeoutQueues: error: cb->thead points to wrong timeout queue (tindex=%d, cbi=%d, cb->thead=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: error: cb->thead points to wrong timeout queue (tindex=%d, cbi=%d, cb->thead=%d)\n"
, i, cbi, cb->thead)); } while (0)
2080 i, cbi, cb->thead))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: error: cb->thead points to wrong timeout queue (tindex=%d, cbi=%d, cb->thead=%d)\n"
, i, cbi, cb->thead)); } while (0)
;
2081 ret = 1;
2082 }
2083 if (!cb->tprev || !cb->tnext) {
2084 ViceLog(0, ("cb_stateVerifyTimeoutQueues: null index in circular list (cbi=%d, tindex=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: null index in circular list (cbi=%d, tindex=%d)\n"
, cbi, i)); } while (0)
2085 cbi, i))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: null index in circular list (cbi=%d, tindex=%d)\n"
, cbi, i)); } while (0)
;
2086 ret = 1;
2087 break;
2088 }
2089 if ((cb->tprev > cbstuff.nblks) ||
2090 (cb->tnext > cbstuff.nblks)) {
2091 ViceLog(0, ("cb_stateVerifyTimeoutQueues: list index out of range (cbi=%d, tindex=%d, cb->tprev=%d, cb->tnext=%d, nCBs=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: list index out of range (cbi=%d, tindex=%d, cb->tprev=%d, cb->tnext=%d, nCBs=%d)\n"
, cbi, i, cb->tprev, cb->tnext, cbstuff.nblks)); } while
(0)
2092 cbi, i, cb->tprev, cb->tnext, cbstuff.nblks))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: list index out of range (cbi=%d, tindex=%d, cb->tprev=%d, cb->tnext=%d, nCBs=%d)\n"
, cbi, i, cb->tprev, cb->tnext, cbstuff.nblks)); } while
(0)
;
2093 ret = 1;
2094 break;
2095 }
2096 ncb = itocb(cb->tnext)((cb->tnext)?CB+(cb->tnext):0);
2097 if (cbi != ncb->tprev) {
2098 ViceLog(0, ("cb_stateVerifyTimeoutQueues: corrupt linked list (cbi=%d, tindex=%d)\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: corrupt linked list (cbi=%d, tindex=%d)\n"
, cbi, i)); } while (0)
2099 cbi, i))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: corrupt linked list (cbi=%d, tindex=%d)\n"
, cbi, i)); } while (0)
;
2100 ret = 1;
2101 break;
2102 }
2103 if (chain_len > FS_STATE_TCB_MAX_LIST_LEN100000) {
2104 ViceLog(0, ("cb_stateVerifyTimeoutQueues: list length exceeds %d (tindex=%d); assuming there's a loop\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: list length exceeds %d (tindex=%d); assuming there's a loop\n"
, 100000, i)); } while (0)
2105 FS_STATE_TCB_MAX_LIST_LEN, i))do { if ((0) <= LogLevel) (FSLog ("cb_stateVerifyTimeoutQueues: list length exceeds %d (tindex=%d); assuming there's a loop\n"
, 100000, i)); } while (0)
;
2106 ret = 1;
2107 break;
2108 }
2109 chain_len++;
2110 }
2111 }
2112
2113 return ret;
2114}
2115
2116static int
2117cb_stateSaveTimeouts(struct fs_dump_state * state)
2118{
2119 int ret = 0;
2120 struct iovec iov[2];
2121
2122 AssignInt64(state->eof_offset, &state->cb_hdr->timeout_offset)*(&state->cb_hdr->timeout_offset) = (state->eof_offset
)
;
2123
2124 memset(state->cb_timeout_hdr, 0, sizeof(struct callback_state_fehash_header));
2125 state->cb_timeout_hdr->magic = CALLBACK_STATE_TIMEOUT_MAGIC0x99DD5511;
2126 state->cb_timeout_hdr->records = CB_NUM_TIMEOUT_QUEUES128;
2127 state->cb_timeout_hdr->len = sizeof(struct callback_state_timeout_header) +
2128 (state->cb_timeout_hdr->records * sizeof(afs_uint32));
2129
2130 iov[0].iov_base = (char *)state->cb_timeout_hdr;
2131 iov[0].iov_len = sizeof(struct callback_state_timeout_header);
2132 iov[1].iov_base = (char *)timeout;
2133 iov[1].iov_len = sizeof(timeout);
2134
2135 if (fs_stateSeek(state, &state->cb_hdr->timeout_offset)) {
2136 ret = 1;
2137 goto done;
2138 }
2139
2140 if (fs_stateWriteV(state, iov, 2)) {
2141 ret = 1;
2142 goto done;
2143 }
2144
2145 fs_stateIncEOF(state, state->cb_timeout_hdr->len);
2146
2147 done:
2148 return ret;
2149}
2150
2151static int
2152cb_stateRestoreTimeouts(struct fs_dump_state * state)
2153{
2154 int ret = 0, len;
2155
2156 if (fs_stateReadHeader(state, &state->cb_hdr->timeout_offset,
2157 state->cb_timeout_hdr,
2158 sizeof(struct callback_state_timeout_header))) {
2159 ret = 1;
2160 goto done;
2161 }
2162
2163 if (state->cb_timeout_hdr->magic != CALLBACK_STATE_TIMEOUT_MAGIC0x99DD5511) {
2164 ret = 1;
2165 goto done;
2166 }
2167 if (state->cb_timeout_hdr->records != CB_NUM_TIMEOUT_QUEUES128) {
2168 ret = 1;
2169 goto done;
2170 }
2171
2172 len = state->cb_timeout_hdr->records * sizeof(afs_uint32);
2173
2174 if (state->cb_timeout_hdr->len !=
2175 (sizeof(struct callback_state_timeout_header) + len)) {
2176 ret = 1;
2177 goto done;
2178 }
2179
2180 if (fs_stateRead(state, timeout, len)) {
2181 ret = 1;
2182 goto done;
2183 }
2184
2185 done:
2186 return ret;
2187}
2188
2189static int
2190cb_stateSaveFEHash(struct fs_dump_state * state)
2191{
2192 int ret = 0;
2193 struct iovec iov[2];
2194
2195 AssignInt64(state->eof_offset, &state->cb_hdr->fehash_offset)*(&state->cb_hdr->fehash_offset) = (state->eof_offset
)
;
2196
2197 memset(state->cb_fehash_hdr, 0, sizeof(struct callback_state_fehash_header));
2198 state->cb_fehash_hdr->magic = CALLBACK_STATE_FEHASH_MAGIC0x77BB33FF;
2199 state->cb_fehash_hdr->records = FEHASH_SIZE512;
2200 state->cb_fehash_hdr->len = sizeof(struct callback_state_fehash_header) +
2201 (state->cb_fehash_hdr->records * sizeof(afs_uint32));
2202
2203 iov[0].iov_base = (char *)state->cb_fehash_hdr;
2204 iov[0].iov_len = sizeof(struct callback_state_fehash_header);
2205 iov[1].iov_base = (char *)HashTable;
2206 iov[1].iov_len = sizeof(HashTable);
2207
2208 if (fs_stateSeek(state, &state->cb_hdr->fehash_offset)) {
2209 ret = 1;
2210 goto done;
2211 }
2212
2213 if (fs_stateWriteV(state, iov, 2)) {
2214 ret = 1;
2215 goto done;
2216 }
2217
2218 fs_stateIncEOF(state, state->cb_fehash_hdr->len);
2219
2220 done:
2221 return ret;
2222}
2223
2224static int
2225cb_stateRestoreFEHash(struct fs_dump_state * state)
2226{
2227 int ret = 0, len;
2228
2229 if (fs_stateReadHeader(state, &state->cb_hdr->fehash_offset,
2230 state->cb_fehash_hdr,
2231 sizeof(struct callback_state_fehash_header))) {
2232 ret = 1;
2233 goto done;
2234 }
2235
2236 if (state->cb_fehash_hdr->magic != CALLBACK_STATE_FEHASH_MAGIC0x77BB33FF) {
2237 ret = 1;
2238 goto done;
2239 }
2240 if (state->cb_fehash_hdr->records != FEHASH_SIZE512) {
2241 ret = 1;
2242 goto done;
2243 }
2244
2245 len = state->cb_fehash_hdr->records * sizeof(afs_uint32);
2246
2247 if (state->cb_fehash_hdr->len !=
2248 (sizeof(struct callback_state_fehash_header) + len)) {
2249 ret = 1;
2250 goto done;
2251 }
2252
2253 if (fs_stateRead(state, HashTable, len)) {
2254 ret = 1;
2255 goto done;
2256 }
2257
2258 done:
2259 return ret;
2260}
2261
2262static int
2263cb_stateSaveFEs(struct fs_dump_state * state)
2264{
2265 int ret = 0;
2266 int fei, hash;
2267 struct FileEntry *fe;
2268
2269 AssignInt64(state->eof_offset, &state->cb_hdr->fe_offset)*(&state->cb_hdr->fe_offset) = (state->eof_offset
)
;
2270
2271 for (hash = 0; hash < FEHASH_SIZE512 ; hash++) {
2272 for (fei = HashTable[hash]; fei; fei = fe->fnext) {
2273 fe = itofe(fei)((fei)?FE+(fei):0);
2274 if (cb_stateSaveFE(state, fe)) {
2275 ret = 1;
2276 goto done;
2277 }
2278 }
2279 }
2280
2281 done:
2282 return ret;
2283}
2284
2285static int
2286cb_stateRestoreFEs(struct fs_dump_state * state)
2287{
2288 int count, nFEs, ret = 0;
2289
2290 nFEs = state->cb_hdr->nFEs;
2291
2292 for (count = 0; count < nFEs; count++) {
2293 if (cb_stateRestoreFE(state)) {
2294 ret = 1;
2295 goto done;
2296 }
2297 }
2298
2299 done:
2300 return ret;
2301}
2302
2303static int
2304cb_stateSaveFE(struct fs_dump_state * state, struct FileEntry * fe)
2305{
2306 int ret = 0, iovcnt, cbi, written = 0;
2307 afs_uint32 fei;
2308 struct callback_state_entry_header hdr;
2309 struct FEDiskEntry fedsk;
2310 struct CBDiskEntry cbdsk[16];
2311 struct iovec iov[16];
2312 struct CallBack *cb;
2313
2314 fei = fetoi(fe)((afs_uint32)(!(fe)?0:(fe)-FE));
2315 if (fei > state->cb_hdr->fe_max) {
2316 state->cb_hdr->fe_max = fei;
2317 }
2318
2319 memset(&hdr, 0, sizeof(struct callback_state_entry_header));
2320
2321 if (cb_stateFEToDiskEntry(fe, &fedsk)) {
2322 ret = 1;
2323 goto done;
2324 }
2325
2326 iov[0].iov_base = (char *)&hdr;
2327 iov[0].iov_len = sizeof(hdr);
2328 iov[1].iov_base = (char *)&fedsk;
2329 iov[1].iov_len = sizeof(struct FEDiskEntry);
2330 iovcnt = 2;
2331
2332 for (cbi = fe->firstcb, cb = itocb(cbi)((cbi)?CB+(cbi):0);
2333 cb != NULL((void *)0);
2334 cbi = cb->cnext, cb = itocb(cbi)((cbi)?CB+(cbi):0), hdr.nCBs++) {
2335 if (cbi > state->cb_hdr->cb_max) {
2336 state->cb_hdr->cb_max = cbi;
2337 }
2338 if (cb_stateCBToDiskEntry(cb, &cbdsk[iovcnt])) {
2339 ret = 1;
2340 goto done;
2341 }
2342 cbdsk[iovcnt].index = cbi;
2343 iov[iovcnt].iov_base = (char *)&cbdsk[iovcnt];
2344 iov[iovcnt].iov_len = sizeof(struct CBDiskEntry);
2345 iovcnt++;
2346 if ((iovcnt == 16) || (!cb->cnext)) {
2347 if (fs_stateWriteV(state, iov, iovcnt)) {
2348 ret = 1;
2349 goto done;
2350 }
2351 written = 1;
2352 iovcnt = 0;
2353 }
2354 }
2355
2356 hdr.magic = CALLBACK_STATE_ENTRY_MAGIC0x54637281;
2357 hdr.len = sizeof(hdr) + sizeof(struct FEDiskEntry) +
2358 (hdr.nCBs * sizeof(struct CBDiskEntry));
2359
2360 if (!written) {
2361 if (fs_stateWriteV(state, iov, iovcnt)) {
2362 ret = 1;
2363 goto done;
2364 }
2365 } else {
2366 if (fs_stateWriteHeader(state, &state->eof_offset, &hdr, sizeof(hdr))) {
2367 ret = 1;
2368 goto done;
2369 }
2370 }
2371
2372 fs_stateIncEOF(state, hdr.len);
2373
2374 if (written) {
2375 if (fs_stateSeek(state, &state->eof_offset)) {
2376 ret = 1;
2377 goto done;
2378 }
2379 }
2380
2381 state->cb_hdr->nFEs++;
2382 state->cb_hdr->nCBs += hdr.nCBs;
2383
2384 done:
2385 return ret;
2386}
2387
2388static int
2389cb_stateRestoreFE(struct fs_dump_state * state)
2390{
2391 int ret = 0, iovcnt, nCBs;
2392 struct callback_state_entry_header hdr;
2393 struct FEDiskEntry fedsk;
2394 struct CBDiskEntry cbdsk[16];
2395 struct iovec iov[16];
2396 struct FileEntry * fe;
2397
2398 iov[0].iov_base = (char *)&hdr;
2399 iov[0].iov_len = sizeof(hdr);
2400 iov[1].iov_base = (char *)&fedsk;
2401 iov[1].iov_len = sizeof(fedsk);
2402 iovcnt = 2;
2403
2404 if (fs_stateReadV(state, iov, iovcnt)) {
2405 ret = 1;
2406 goto done;
2407 }
2408
2409 if (hdr.magic != CALLBACK_STATE_ENTRY_MAGIC0x54637281) {
2410 ret = 1;
2411 goto done;
2412 }
2413
2414 fe = GetFE()((struct FileEntry *)iGetFE(&cbstuff.nFEs));
2415 if (fe == NULL((void *)0)) {
2416 ViceLog(0, ("cb_stateRestoreFE: ran out of free FileEntry structures\n"))do { if ((0) <= LogLevel) (FSLog ("cb_stateRestoreFE: ran out of free FileEntry structures\n"
)); } while (0)
;
2417 ret = 1;
2418 goto done;
2419 }
2420
2421 if (cb_stateDiskEntryToFE(state, &fedsk, fe)) {
2422 ret = 1;
2423 goto done;
2424 }
2425
2426 if (hdr.nCBs) {
2427 for (iovcnt = 0, nCBs = 0;
2428 nCBs < hdr.nCBs;
2429 nCBs++) {
2430 iov[iovcnt].iov_base = (char *)&cbdsk[iovcnt];
2431 iov[iovcnt].iov_len = sizeof(struct CBDiskEntry);
2432 iovcnt++;
2433 if ((iovcnt == 16) || (nCBs == hdr.nCBs - 1)) {
2434 if (fs_stateReadV(state, iov, iovcnt)) {
2435 ret = 1;
2436 goto done;
2437 }
2438 if (cb_stateRestoreCBs(state, fe, iov, iovcnt)) {
2439 ret = 1;
2440 goto done;
2441 }
2442 iovcnt = 0;
2443 }
2444 }
2445 }
2446
2447 done:
2448 return ret;
2449}
2450
2451static int
2452cb_stateRestoreCBs(struct fs_dump_state * state, struct FileEntry * fe,
2453 struct iovec * iov, int niovecs)
2454{
2455 int ret = 0, idx;
2456 struct CallBack * cb;
2457 struct CBDiskEntry * cbdsk;
2458
2459 for (idx = 0; idx < niovecs; idx++) {
2460 cbdsk = (struct CBDiskEntry *) iov[idx].iov_base;
2461 if ((cb = GetCB()((struct CallBack *)iGetCB(&cbstuff.nCBs))) == NULL((void *)0)) {
2462 ViceLog(0, ("cb_stateRestoreCBs: ran out of free CallBack structures\n"))do { if ((0) <= LogLevel) (FSLog ("cb_stateRestoreCBs: ran out of free CallBack structures\n"
)); } while (0)
;
2463 ret = 1;
2464 goto done;
2465 }
2466 if (cb_stateDiskEntryToCB(state, cbdsk, cb)) {
2467 ViceLog(0, ("cb_stateRestoreCBs: corrupt CallBack disk entry\n"))do { if ((0) <= LogLevel) (FSLog ("cb_stateRestoreCBs: corrupt CallBack disk entry\n"
)); } while (0)
;
2468 ret = 1;
2469 goto done;
2470 }
2471 }
2472
2473 done:
2474 return ret;
2475}
2476
2477
2478static int
2479cb_stateFillHeader(struct callback_state_header * hdr)
2480{
2481 hdr->stamp.magic = CALLBACK_STATE_MAGIC0x89DE67BC;
2482 hdr->stamp.version = CALLBACK_STATE_VERSION1;
2483 hdr->tfirst = tfirst;
2484 return 0;
2485}
2486
2487static int
2488cb_stateCheckHeader(struct callback_state_header * hdr)
2489{
2490 int ret = 0;
2491
2492 if (hdr->stamp.magic != CALLBACK_STATE_MAGIC0x89DE67BC) {
2493 ret = 1;
2494 } else if (hdr->stamp.version != CALLBACK_STATE_VERSION1) {
2495 ret = 1;
2496 } else if ((hdr->nFEs > cbstuff.nblks) || (hdr->nCBs > cbstuff.nblks)) {
2497 ViceLog(0, ("cb_stateCheckHeader: saved callback state larger than callback memory allocation\n"))do { if ((0) <= LogLevel) (FSLog ("cb_stateCheckHeader: saved callback state larger than callback memory allocation\n"
)); } while (0)
;
2498 ret = 1;
2499 }
2500 return ret;
2501}
2502
2503/* disk entry conversion routines */
2504static int
2505cb_stateFEToDiskEntry(struct FileEntry * in, struct FEDiskEntry * out)
2506{
2507 memcpy(&out->fe, in, sizeof(struct FileEntry));
2508 out->index = fetoi(in)((afs_uint32)(!(in)?0:(in)-FE));
2509 return 0;
2510}
2511
2512static int
2513cb_stateDiskEntryToFE(struct fs_dump_state * state,
2514 struct FEDiskEntry * in, struct FileEntry * out)
2515{
2516 int ret = 0;
2517
2518 memcpy(out, &in->fe, sizeof(struct FileEntry));
2519
2520 /* setup FE map entry */
2521 if (!in->index || (in->index >= state->fe_map.len)) {
2522 ViceLog(0, ("cb_stateDiskEntryToFE: index (%d) out of range",do { if ((0) <= LogLevel) (FSLog ("cb_stateDiskEntryToFE: index (%d) out of range"
, in->index)); } while (0)
2523 in->index))do { if ((0) <= LogLevel) (FSLog ("cb_stateDiskEntryToFE: index (%d) out of range"
, in->index)); } while (0)
;
2524 ret = 1;
2525 goto done;
2526 }
2527 state->fe_map.entries[in->index].old_idx = in->index;
2528 state->fe_map.entries[in->index].new_idx = fetoi(out)((afs_uint32)(!(out)?0:(out)-FE));
2529
2530 done:
2531 return ret;
2532}
2533
2534static int
2535cb_stateCBToDiskEntry(struct CallBack * in, struct CBDiskEntry * out)
2536{
2537 memcpy(&out->cb, in, sizeof(struct CallBack));
2538 out->index = cbtoi(in)((afs_uint32)(!(in)?0:(in)-CB));
2539 return 0;
2540}
2541
2542static int
2543cb_stateDiskEntryToCB(struct fs_dump_state * state,
2544 struct CBDiskEntry * in, struct CallBack * out)
2545{
2546 int ret = 0;
2547
2548 memcpy(out, &in->cb, sizeof(struct CallBack));
2549
2550 /* setup CB map entry */
2551 if (!in->index || (in->index >= state->cb_map.len)) {
2552 ViceLog(0, ("cb_stateDiskEntryToCB: index (%d) out of range\n",do { if ((0) <= LogLevel) (FSLog ("cb_stateDiskEntryToCB: index (%d) out of range\n"
, in->index)); } while (0)
2553 in->index))do { if ((0) <= LogLevel) (FSLog ("cb_stateDiskEntryToCB: index (%d) out of range\n"
, in->index)); } while (0)
;
2554 ret = 1;
2555 goto done;
2556 }
2557 state->cb_map.entries[in->index].old_idx = in->index;
2558 state->cb_map.entries[in->index].new_idx = cbtoi(out)((afs_uint32)(!(out)?0:(out)-CB));
2559
2560 done:
2561 return ret;
2562}
2563
2564/* index map routines */
2565static int
2566cb_stateAllocMap(struct fs_dump_state * state)
2567{
2568 state->fe_map.len = state->cb_hdr->fe_max + 1;
2569 state->cb_map.len = state->cb_hdr->cb_max + 1;
2570 state->fe_map.entries = (struct idx_map_entry_t *)
2571 calloc(state->fe_map.len, sizeof(struct idx_map_entry_t));
2572 state->cb_map.entries = (struct idx_map_entry_t *)
2573 calloc(state->cb_map.len, sizeof(struct idx_map_entry_t));
2574 return ((state->fe_map.entries != NULL((void *)0)) && (state->cb_map.entries != NULL((void *)0))) ? 0 : 1;
2575}
2576
2577int
2578fe_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new)
2579{
2580 int ret = 0;
2581
2582 /* FEs use a one-based indexing system, so old==0 implies no mapping */
2583 if (!old) {
2584 *new = 0;
2585 goto done;
2586 }
2587
2588 if (old >= state->fe_map.len) {
2589 ViceLog(0, ("fe_OldToNew: index %d is out of range\n", old))do { if ((0) <= LogLevel) (FSLog ("fe_OldToNew: index %d is out of range\n"
, old)); } while (0)
;
2590 ret = 1;
2591 } else if (state->fe_map.entries[old].old_idx != old) { /* sanity check */
2592 ViceLog(0, ("fe_OldToNew: index %d points to an invalid FileEntry record\n", old))do { if ((0) <= LogLevel) (FSLog ("fe_OldToNew: index %d points to an invalid FileEntry record\n"
, old)); } while (0)
;
2593 ret = 1;
2594 } else {
2595 *new = state->fe_map.entries[old].new_idx;
2596 }
2597
2598 done:
2599 return ret;
2600}
2601
2602int
2603cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new)
2604{
2605 int ret = 0;
2606
2607 /* CBs use a one-based indexing system, so old==0 implies no mapping */
2608 if (!old) {
2609 *new = 0;
2610 goto done;
2611 }
2612
2613 if (old >= state->cb_map.len) {
2614 ViceLog(0, ("cb_OldToNew: index %d is out of range\n", old))do { if ((0) <= LogLevel) (FSLog ("cb_OldToNew: index %d is out of range\n"
, old)); } while (0)
;
2615 ret = 1;
2616 } else if (state->cb_map.entries[old].old_idx != old) { /* sanity check */
2617 ViceLog(0, ("cb_OldToNew: index %d points to an invalid CallBack record\n", old))do { if ((0) <= LogLevel) (FSLog ("cb_OldToNew: index %d points to an invalid CallBack record\n"
, old)); } while (0)
;
2618 ret = 1;
2619 } else {
2620 *new = state->cb_map.entries[old].new_idx;
2621 }
2622
2623 done:
2624 return ret;
2625}
2626#endif /* AFS_DEMAND_ATTACH_FS */
2627
2628static int
2629DumpCallBackState_r(void)
2630{
2631 int fd, oflag;
2632 afs_uint32 magic = MAGICV20x12345679, now = (afs_int32) FT_ApproxTime(), freelisthead;
2633
2634 oflag = O_WRONLY0x0001 | O_CREAT0x0200 | O_TRUNC0x0400;
2635#ifdef AFS_NT40_ENV
2636 oflag |= O_BINARY;
2637#endif
2638 fd = open(AFSDIR_SERVER_CBKDUMP_FILEPATHgetDirPath(AFSDIR_SERVER_CBKDUMP_FILEPATH_ID), oflag, 0666);
2639 if (fd < 0) {
2640 ViceLog(0,do { if ((0) <= LogLevel) (FSLog ("Couldn't create callback dump file %s\n"
, getDirPath(AFSDIR_SERVER_CBKDUMP_FILEPATH_ID))); } while (0
)
2641 ("Couldn't create callback dump file %s\n",do { if ((0) <= LogLevel) (FSLog ("Couldn't create callback dump file %s\n"
, getDirPath(AFSDIR_SERVER_CBKDUMP_FILEPATH_ID))); } while (0
)
2642 AFSDIR_SERVER_CBKDUMP_FILEPATH))do { if ((0) <= LogLevel) (FSLog ("Couldn't create callback dump file %s\n"
, getDirPath(AFSDIR_SERVER_CBKDUMP_FILEPATH_ID))); } while (0
)
;
2643 return 0;
2644 }
2645 (void)write(fd, &magic, sizeof(magic));
2646 (void)write(fd, &now, sizeof(now));
2647 (void)write(fd, &cbstuff, sizeof(cbstuff));
2648 (void)write(fd, TimeOuts, sizeof(TimeOuts));
2649 (void)write(fd, timeout, sizeof(timeout));
2650 (void)write(fd, &tfirst, sizeof(tfirst));
2651 freelisthead = cbtoi((struct CallBack *)CBfree)((afs_uint32)(!((struct CallBack *)CBfree)?0:((struct CallBack
*)CBfree)-CB))
;
2652 (void)write(fd, &freelisthead, sizeof(freelisthead)); /* This is a pointer */
2653 freelisthead = fetoi((struct FileEntry *)FEfree)((afs_uint32)(!((struct FileEntry *)FEfree)?0:((struct FileEntry
*)FEfree)-FE))
;
2654 (void)write(fd, &freelisthead, sizeof(freelisthead)); /* This is a pointer */
2655 (void)write(fd, HashTable, sizeof(HashTable));
2656 (void)write(fd, &CB[1], sizeof(CB[1]) * cbstuff.nblks); /* CB stuff */
2657 (void)write(fd, &FE[1], sizeof(FE[1]) * cbstuff.nblks); /* FE stuff */
2658 close(fd);
2659
2660 return 0;
2661}
2662
2663int
2664DumpCallBackState(void) {
2665 int rc;
2666
2667 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 2667), 0));
;
2668 rc = DumpCallBackState_r();
2669 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 2669), 0));
;
2670
2671 return(rc);
2672}
2673
2674#endif /* !INTERPRET_DUMP */
2675
2676#ifdef INTERPRET_DUMP
2677
2678/* This is only compiled in for the callback analyzer program */
2679/* Returns the time of the dump */
2680time_t
2681ReadDump(char *file, int timebits)
2682{
2683 int fd, oflag;
2684 afs_uint32 magic, freelisthead;
2685 afs_uint32 now;
2686 afs_int64 now64;
2687
2688 oflag = O_RDONLY0x0000;
2689#ifdef AFS_NT40_ENV
2690 oflag |= O_BINARY;
2691#endif
2692 fd = open(file, oflag);
2693 if (fd < 0) {
2694 fprintf(stderr__stderrp, "Couldn't read dump file %s\n", file);
2695 exit(1);
2696 }
2697 read(fd, &magic, sizeof(magic));
2698 if (magic == MAGICV20x12345679) {
2699 timebits = 32;
2700 } else {
2701 if (magic != MAGIC0x12345678) {
2702 fprintf(stderr__stderrp,
2703 "Magic number of %s is invalid. You might be trying to\n",
2704 file);
2705 fprintf(stderr__stderrp,
2706 "run this program on a machine type with a different byte ordering.\n");
2707 exit(1);
2708 }
2709 }
2710 if (timebits == 64) {
2711 read(fd, &now64, sizeof(afs_int64));
2712 now = (afs_int32) now64;
2713 } else
2714 read(fd, &now, sizeof(afs_int32));
2715
2716 read(fd, &cbstuff, sizeof(cbstuff));
2717 read(fd, TimeOuts, sizeof(TimeOuts));
2718 read(fd, timeout, sizeof(timeout));
2719 read(fd, &tfirst, sizeof(tfirst));
2720 read(fd, &freelisthead, sizeof(freelisthead));
2721 CB = ((struct CallBack
2722 *)(calloc(cbstuff.nblks, sizeof(struct CallBack)))) - 1;
2723 FE = ((struct FileEntry
2724 *)(calloc(cbstuff.nblks, sizeof(struct FileEntry)))) - 1;
2725 CBfree = (struct CallBack *)itocb(freelisthead)((freelisthead)?CB+(freelisthead):0);
2726 read(fd, &freelisthead, sizeof(freelisthead));
2727 FEfree = (struct FileEntry *)itofe(freelisthead)((freelisthead)?FE+(freelisthead):0);
2728 read(fd, HashTable, sizeof(HashTable));
2729 read(fd, &CB[1], sizeof(CB[1]) * cbstuff.nblks); /* CB stuff */
2730 read(fd, &FE[1], sizeof(FE[1]) * cbstuff.nblks); /* FE stuff */
2731 if (close(fd)) {
2732 perror("Error reading dumpfile");
2733 exit(1);
2734 }
2735 return now;
2736}
2737
2738#ifdef AFS_NT40_ENV
2739#include "AFS_component_version_number.h"
2740#else
2741#include "AFS_component_version_number.c"
2742#endif
2743
2744static afs_uint32 *cbTrack;
2745
2746int
2747main(int argc, char **argv)
2748{
2749 int err = 0, cbi = 0, stats = 0, noptions = 0, all = 0, vol = 0, raw = 0;
2750 static AFSFid fid;
2751 struct FileEntry *fe;
2752 struct CallBack *cb;
2753 time_t now;
2754 int timebits = 32;
2755
2756 memset(&fid, 0, sizeof(fid));
2757 argc--;
2758 argv++;
2759 while (argc && **argv == '-') {
2760 noptions++;
2761 argc--;
2762 if (!strcmp(*argv, "-host")) {
2763 if (argc < 1) {
2764 err++;
2765 break;
2766 }
2767 argc--;
2768 cbi = atoi(*++argv);
2769 } else if (!strcmp(*argv, "-fid")) {
2770 if (argc < 2) {
2771 err++;
2772 break;
2773 }
2774 argc -= 3;
2775 fid.Volume = atoi(*++argv);
2776 fid.Vnode = atoi(*++argv);
2777 fid.Unique = atoi(*++argv);
2778 } else if (!strcmp(*argv, "-time")) {
2779 fprintf(stderr__stderrp, "-time not supported\n");
2780 exit(1);
2781 } else if (!strcmp(*argv, "-stats")) {
2782 stats = 1;
2783 } else if (!strcmp(*argv, "-all")) {
2784 all = 1;
2785 } else if (!strcmp(*argv, "-raw")) {
2786 raw = 1;
2787 } else if (!strcmp(*argv, "-timebits")) {
2788 if (argc < 1) {
2789 err++;
2790 break;
2791 }
2792 argc--;
2793 timebits = atoi(*++argv);
2794 if ((timebits != 32)
2795 && (timebits != 64)
2796 )
2797 err++;
2798 } else if (!strcmp(*argv, "-volume")) {
2799 if (argc < 1) {
2800 err++;
2801 break;
2802 }
2803 argc--;
2804 vol = atoi(*++argv);
2805 } else
2806 err++;
2807 argv++;
2808 }
2809 if (err || argc != 1) {
2810 fprintf(stderr__stderrp,
2811 "Usage: cbd [-host cbid] [-fid volume vnode] [-stats] [-all] [-timebits 32"
2812 "|64"
2813 "] callbackdumpfile\n");
2814 fprintf(stderr__stderrp,
2815 "[cbid is shown for each host in the hosts.dump file]\n");
2816 exit(1);
2817 }
2818 now = ReadDump(*argv, timebits);
2819 if (stats || noptions == 0) {
2820 time_t uxtfirst = UXtime(tfirst)((tfirst)<<7), tnow = now;
2821 printf("The time of the dump was %u %s", (unsigned int) now, ctime(&tnow));
2822 printf("The last time cleanup ran was %u %s", (unsigned int) uxtfirst,
2823 ctime(&uxtfirst));
2824 PrintCallBackStats();
2825 }
2826
2827 cbTrack = calloc(cbstuff.nblks, sizeof(cbTrack[0]));
2828
2829 if (all || vol) {
2830 int hash;
2831 afs_uint32 *feip;
2832 struct CallBack *cb;
2833 struct FileEntry *fe;
2834
2835 for (hash = 0; hash < FEHASH_SIZE512; hash++) {
2836 for (feip = &HashTable[hash]; (fe = itofe(*feip)((*feip)?FE+(*feip):0));) {
2837 if (!vol || (fe->volid == vol)) {
2838 afs_uint32 fe_i = fetoi(fe)((afs_uint32)(!(fe)?0:(fe)-FE));
2839
2840 for (cb = itocb(fe->firstcb)((fe->firstcb)?CB+(fe->firstcb):0); cb; cb = itocb(cb->cnext)((cb->cnext)?CB+(cb->cnext):0)) {
2841 afs_uint32 cb_i = cbtoi(cb)((afs_uint32)(!(cb)?0:(cb)-CB));
2842
2843 if (cb_i > cbstuff.nblks) {
2844 printf("CB index out of range (%u > %d), stopped for this FE\n",
2845 cb_i, cbstuff.nblks);
2846 break;
2847 }
2848
2849 if (cbTrack[cb_i]) {
2850 printf("CB entry already claimed for FE[%u] (this is FE[%u]), stopped\n",
2851 cbTrack[cb_i], fe_i);
2852 break;
2853 }
2854 cbTrack[cb_i] = fe_i;
2855
2856 PrintCB(cb, now);
2857 }
2858 *feip = fe->fnext;
2859 } else {
2860 feip = &fe->fnext;
2861 }
2862 }
2863 }
2864 }
2865 if (cbi) {
2866 afs_uint32 cfirst = cbi;
2867 do {
2868 cb = itocb(cbi)((cbi)?CB+(cbi):0);
2869 PrintCB(cb, now);
2870 cbi = cb->hnext;
2871 } while (cbi != cfirst);
2872 }
2873 if (fid.Volume) {
2874 fe = FindFE(&fid);
2875 if (!fe) {
2876 printf("No callback entries for %u.%u\n", fid.Volume, fid.Vnode);
2877 exit(1);
2878 }
2879 cb = itocb(fe->firstcb)((fe->firstcb)?CB+(fe->firstcb):0);
2880 while (cb) {
2881 PrintCB(cb, now);
2882 cb = itocb(cb->cnext)((cb->cnext)?CB+(cb->cnext):0);
2883 }
2884 }
2885 if (raw) {
2886 afs_int32 *p, i;
2887 for (i = 1; i < cbstuff.nblks; i++) {
2888 p = (afs_int32 *) & FE[i];
2889 printf("%d:%12x%12x%12x%12x\n", i, p[0], p[1], p[2], p[3]);
2890 }
2891 }
2892
2893 free(cbTrack);
2894 exit(0);
2895}
2896
2897void
2898PrintCB(struct CallBack *cb, afs_uint32 now)
2899{
2900 struct FileEntry *fe = itofe(cb->fhead)((cb->fhead)?FE+(cb->fhead):0);
2901 time_t expires = TIndexToTime(cb->thead)(((((cb->thead)<(((tfirst)&127)+1)?(cb->thead)+128
:(cb->thead)) - (((tfirst)&127)+1) + tfirst)<<7)
)
;
2902
2903 if (fe == NULL((void *)0))
2904 return;
2905
2906 printf("vol=%u vn=%u cbs=%d hi=%d st=%d fest=%d, exp in %lu secs at %s",
2907 fe->volid, fe->vnode, fe->ncbs, cb->hhead, cb->status, fe->status,
2908 expires - now, ctime(&expires));
2909}
2910
2911#endif
2912
2913#if !defined(INTERPRET_DUMP)
2914/*
2915** try breaking calbacks on afidp from host. Use multi_rx.
2916** return 0 on success, non-zero on failure
2917*/
2918int
2919MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp)
2920{
2921 int retVal;
2922 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 2922), 0));
;
2923 retVal = MultiBreakCallBackAlternateAddress_r(host, afidp);
2924 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 2924), 0));
;
2925 return retVal;
2926}
2927
2928int
2929MultiBreakCallBackAlternateAddress_r(struct host *host,
2930 struct AFSCBFids *afidp)
2931{
2932 int i, j;
2933 struct rx_connection **conns;
2934 struct rx_connection *connSuccess = 0;
2935 struct AddrPort *interfaces;
2936 static struct rx_securityClass *sc = 0;
2937 static struct AFSCBs tc = { 0, 0 };
2938 char hoststr[16];
2939
2940 /* nothing more can be done */
2941 if (!host->interface)
2942 return 1; /* failure */
2943
2944 /* the only address is the primary interface */
2945 if (host->interface->numberOfInterfaces <= 1)
2946 return 1; /* failure */
2947
2948 /* initialise a security object only once */
2949 if (!sc)
2950 sc = rxnull_NewClientSecurityObject();
2951
2952 i = host->interface->numberOfInterfaces;
2953 interfaces = calloc(i, sizeof(struct AddrPort));
2954 conns = calloc(i, sizeof(struct rx_connection *));
2955 if (!interfaces || !conns) {
2956 ViceLogThenPanic(0, ("Failed malloc in "do { do { if ((0) <= LogLevel) (FSLog ("Failed malloc in "
"MultiBreakCallBackAlternateAddress_r\n")); } while (0); osi_Panic
("Failed malloc in " "MultiBreakCallBackAlternateAddress_r\n"
); } while(0);
2957 "MultiBreakCallBackAlternateAddress_r\n"))do { do { if ((0) <= LogLevel) (FSLog ("Failed malloc in "
"MultiBreakCallBackAlternateAddress_r\n")); } while (0); osi_Panic
("Failed malloc in " "MultiBreakCallBackAlternateAddress_r\n"
); } while(0);
;
2958 }
2959
2960 /* initialize alternate rx connections */
2961 for (i = 0, j = 0; i < host->interface->numberOfInterfaces; i++) {
2962 /* this is the current primary address */
2963 if (host->host == host->interface->interface[i].addr &&
2964 host->port == host->interface->interface[i].port)
2965 continue;
2966
2967 interfaces[j] = host->interface->interface[i];
2968 conns[j] =
2969 rx_NewConnection(interfaces[j].addr,
2970 interfaces[j].port, 1, sc, 0);
2971 rx_SetConnDeadTime(conns[j], 2);
2972 rx_SetConnHardDeadTime(conns[j], AFS_HARDDEADTIME120);
2973 j++;
2974 }
2975
2976 osi_Assert(j)(void)((j) || (osi_AssertFailU("j", "./../viced/callback.c", 2976
), 0))
; /* at least one alternate address */
2977 ViceLog(125,do { if ((125) <= LogLevel) (FSLog ("Starting multibreakcall back on all addr for host %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
2978 ("Starting multibreakcall back on all addr for host %p (%s:%d)\n",do { if ((125) <= LogLevel) (FSLog ("Starting multibreakcall back on all addr for host %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
2979 host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)))do { if ((125) <= LogLevel) (FSLog ("Starting multibreakcall back on all addr for host %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
;
2980 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 2980), 0));
;
2981 multi_Rx(conns, j)do { struct multi_handle *multi_h; int multi_i; int multi_i0;
afs_int32 multi_error; struct rx_call *multi_call; multi_h =
multi_Init(conns, j); for (multi_i0 = multi_i = 0; ; multi_i
= multi_i0 )
{
2982 multi_RXAFSCB_CallBack(afidp, &tc)if (multi_h->nextReady == multi_h->firstNotReady &&
multi_i < multi_h->nConns) { multi_call = multi_h->
calls[multi_i]; if (multi_call) { StartRXAFSCB_CallBack(multi_call
, afidp, &tc); rx_FlushWrite(multi_call); } multi_i0++; continue
; } if ((multi_i = multi_Select(multi_h)) < 0) break; multi_call
= multi_h->calls[multi_i]; multi_error = rx_EndCall(multi_call
, EndRXAFSCB_CallBack(multi_call)); multi_h->calls[multi_i
] = (struct rx_call *) 0
;
2983 if (!multi_error) {
2984 /* first success */
2985 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 2985), 0));
;
2986 if (host->callback_rxcon)
2987 rx_DestroyConnection(host->callback_rxcon);
2988 host->callback_rxcon = conns[multi_i];
2989 h_DeleteHostFromAddrHashTable_r(host->host, host->port, host);
2990 host->host = interfaces[multi_i].addr;
2991 host->port = interfaces[multi_i].port;
2992 h_AddHostToAddrHashTable_r(host->host, host->port, host);
2993 connSuccess = conns[multi_i];
2994 rx_SetConnDeadTime(host->callback_rxcon, 50);
2995 rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME120);
2996 ViceLog(125,do { if ((125) <= LogLevel) (FSLog ("multibreakcall success with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
2997 ("multibreakcall success with addr %s:%d\n",do { if ((125) <= LogLevel) (FSLog ("multibreakcall success with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
2998 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),do { if ((125) <= LogLevel) (FSLog ("multibreakcall success with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
2999 ntohs(interfaces[multi_i].port)))do { if ((125) <= LogLevel) (FSLog ("multibreakcall success with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
;
3000 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 3000), 0));
;
3001 multi_Abortbreak;
3002 }
3003 }
3004 multi_End_Ignoremulti_Finalize_Ignore(multi_h); } while (0);
3005 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 3005), 0));
;
3006 /* Destroy all connections except the one on which we succeeded */
3007 for (i = 0; i < j; i++)
3008 if (conns[i] != connSuccess)
3009 rx_DestroyConnection(conns[i]);
3010
3011 free(interfaces);
3012 free(conns);
3013
3014 if (connSuccess)
3015 return 0; /* success */
3016 else
3017 return 1; /* failure */
3018}
3019
3020
3021/*
3022** try multi_RX probes to host.
3023** return 0 on success, non-0 on failure
3024*/
3025int
3026MultiProbeAlternateAddress_r(struct host *host)
3027{
3028 int i, j;
3029 struct rx_connection **conns;
3030 struct rx_connection *connSuccess = 0;
3031 struct AddrPort *interfaces;
3032 static struct rx_securityClass *sc = 0;
3033 char hoststr[16];
3034
3035 /* nothing more can be done */
3036 if (!host->interface)
3037 return 1; /* failure */
3038
3039 /* the only address is the primary interface */
3040 if (host->interface->numberOfInterfaces <= 1)
3041 return 1; /* failure */
3042
3043 /* initialise a security object only once */
3044 if (!sc)
3045 sc = rxnull_NewClientSecurityObject();
3046
3047 i = host->interface->numberOfInterfaces;
3048 interfaces = calloc(i, sizeof(struct AddrPort));
3049 conns = calloc(i, sizeof(struct rx_connection *));
3050 if (!interfaces || !conns) {
3051 ViceLogThenPanic(0, ("Failed malloc in "do { do { if ((0) <= LogLevel) (FSLog ("Failed malloc in "
"MultiProbeAlternateAddress_r\n")); } while (0); osi_Panic (
"Failed malloc in " "MultiProbeAlternateAddress_r\n"); } while
(0);
3052 "MultiProbeAlternateAddress_r\n"))do { do { if ((0) <= LogLevel) (FSLog ("Failed malloc in "
"MultiProbeAlternateAddress_r\n")); } while (0); osi_Panic (
"Failed malloc in " "MultiProbeAlternateAddress_r\n"); } while
(0);
;
3053 }
3054
3055 /* initialize alternate rx connections */
3056 for (i = 0, j = 0; i < host->interface->numberOfInterfaces; i++) {
3057 /* this is the current primary address */
3058 if (host->host == host->interface->interface[i].addr &&
3059 host->port == host->interface->interface[i].port)
3060 continue;
3061
3062 interfaces[j] = host->interface->interface[i];
3063 conns[j] =
3064 rx_NewConnection(interfaces[j].addr,
3065 interfaces[j].port, 1, sc, 0);
3066 rx_SetConnDeadTime(conns[j], 2);
3067 rx_SetConnHardDeadTime(conns[j], AFS_HARDDEADTIME120);
3068 j++;
3069 }
3070
3071 osi_Assert(j)(void)((j) || (osi_AssertFailU("j", "./../viced/callback.c", 3071
), 0))
; /* at least one alternate address */
3072 ViceLog(125,do { if ((125) <= LogLevel) (FSLog ("Starting multiprobe on all addr for host %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
3073 ("Starting multiprobe on all addr for host %p (%s:%d)\n",do { if ((125) <= LogLevel) (FSLog ("Starting multiprobe on all addr for host %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
3074 host, afs_inet_ntoa_r(host->host, hoststr),do { if ((125) <= LogLevel) (FSLog ("Starting multiprobe on all addr for host %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
3075 ntohs(host->port)))do { if ((125) <= LogLevel) (FSLog ("Starting multiprobe on all addr for host %p (%s:%d)\n"
, host, afs_inet_ntoa_r(host->host, hoststr), (__builtin_constant_p
(host->port) ? (__uint16_t)(((__uint16_t)(host->port)) <<
8 | ((__uint16_t)(host->port)) >> 8) : __bswap16_var
(host->port)))); } while (0)
;
3076 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 3076), 0));
;
3077 multi_Rx(conns, j)do { struct multi_handle *multi_h; int multi_i; int multi_i0;
afs_int32 multi_error; struct rx_call *multi_call; multi_h =
multi_Init(conns, j); for (multi_i0 = multi_i = 0; ; multi_i
= multi_i0 )
{
3078 multi_RXAFSCB_ProbeUuid(&host->interface->uuid)if (multi_h->nextReady == multi_h->firstNotReady &&
multi_i < multi_h->nConns) { multi_call = multi_h->
calls[multi_i]; if (multi_call) { StartRXAFSCB_ProbeUuid(multi_call
, &host->interface->uuid); rx_FlushWrite(multi_call
); } multi_i0++; continue; } if ((multi_i = multi_Select(multi_h
)) < 0) break; multi_call = multi_h->calls[multi_i]; multi_error
= rx_EndCall(multi_call, EndRXAFSCB_ProbeUuid(multi_call)); multi_h
->calls[multi_i] = (struct rx_call *) 0
;
3079 if (!multi_error) {
3080 /* first success */
3081 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 3081), 0));
;
3082 if (host->callback_rxcon)
3083 rx_DestroyConnection(host->callback_rxcon);
3084 host->callback_rxcon = conns[multi_i];
3085 h_DeleteHostFromAddrHashTable_r(host->host, host->port, host);
3086 host->host = interfaces[multi_i].addr;
3087 host->port = interfaces[multi_i].port;
3088 h_AddHostToAddrHashTable_r(host->host, host->port, host);
3089 connSuccess = conns[multi_i];
3090 rx_SetConnDeadTime(host->callback_rxcon, 50);
3091 rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME120);
3092 ViceLog(125,do { if ((125) <= LogLevel) (FSLog ("multiprobe success with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
3093 ("multiprobe success with addr %s:%d\n",do { if ((125) <= LogLevel) (FSLog ("multiprobe success with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
3094 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),do { if ((125) <= LogLevel) (FSLog ("multiprobe success with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
3095 ntohs(interfaces[multi_i].port)))do { if ((125) <= LogLevel) (FSLog ("multiprobe success with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
;
3096 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 3096), 0));
;
3097 multi_Abortbreak;
3098 } else {
3099 ViceLog(125,do { if ((125) <= LogLevel) (FSLog ("multiprobe failure with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
3100 ("multiprobe failure with addr %s:%d\n",do { if ((125) <= LogLevel) (FSLog ("multiprobe failure with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
3101 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),do { if ((125) <= LogLevel) (FSLog ("multiprobe failure with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
3102 ntohs(interfaces[multi_i].port)))do { if ((125) <= LogLevel) (FSLog ("multiprobe failure with addr %s:%d\n"
, afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr), (__builtin_constant_p
(interfaces[multi_i].port) ? (__uint16_t)(((__uint16_t)(interfaces
[multi_i].port)) << 8 | ((__uint16_t)(interfaces[multi_i
].port)) >> 8) : __bswap16_var(interfaces[multi_i].port
)))); } while (0)
;
3103
3104 /* This is less than desirable but its the best we can do.
3105 * The AFS Cache Manager will return either 0 for a Uuid
3106 * match and a 1 for a non-match. If the error is 1 we
3107 * therefore know that our mapping of IP address to Uuid
3108 * is wrong. We should attempt to find the correct
3109 * Uuid and fix the host tables.
3110 */
3111 if (multi_error == 1) {
3112 /* remove the current alternate address from this host */
3113 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 3113), 0));
;
3114 removeInterfaceAddr_r(host, interfaces[multi_i].addr, interfaces[multi_i].port);
3115 H_UNLOCK(void)((pthread_mutex_unlock(&host_glock_mutex) == 0) || (
osi_AssertFailU("pthread_mutex_unlock(&host_glock_mutex) == 0"
, "./../viced/callback.c", 3115), 0));
;
3116 }
3117 }
3118#ifdef AFS_DEMAND_ATTACH_FS1
3119 /* try to bail ASAP if the fileserver is shutting down */
3120 FS_STATE_RDLOCK(void)((pthread_rwlock_rdlock(&fs_state.state_lock) == 0)
|| (osi_AssertFailU("pthread_rwlock_rdlock(&fs_state.state_lock) == 0"
, "./../viced/callback.c", 3120), 0))
;
3121 if (fs_state.mode == FS_MODE_SHUTDOWN1) {
3122 FS_STATE_UNLOCK(void)((pthread_rwlock_unlock(&fs_state.state_lock) == 0)
|| (osi_AssertFailU("pthread_rwlock_unlock(&fs_state.state_lock) == 0"
, "./../viced/callback.c", 3122), 0))
;
3123 multi_Abortbreak;
3124 }
3125 FS_STATE_UNLOCK(void)((pthread_rwlock_unlock(&fs_state.state_lock) == 0)
|| (osi_AssertFailU("pthread_rwlock_unlock(&fs_state.state_lock) == 0"
, "./../viced/callback.c", 3125), 0))
;
3126#endif
3127 }
3128 multi_End_Ignoremulti_Finalize_Ignore(multi_h); } while (0);
3129 H_LOCK(void)((pthread_mutex_lock(&host_glock_mutex) == 0) || (osi_AssertFailU
("pthread_mutex_lock(&host_glock_mutex) == 0", "./../viced/callback.c"
, 3129), 0));
;
3130 /* Destroy all connections except the one on which we succeeded */
3131 for (i = 0; i < j; i++)
3132 if (conns[i] != connSuccess)
3133 rx_DestroyConnection(conns[i]);
3134
3135 free(interfaces);
3136 free(conns);
3137
3138 if (connSuccess)
3139 return 0; /* success */
3140 else
3141 return 1; /* failure */
3142}
3143
3144#endif /* !defined(INTERPRET_DUMP) */