2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * Portions Copyright (c) 2006 Sine Nomine Associates
13 * NEW callback package callback.c (replaces vicecb.c)
14 * Updated call back routines, NOW with:
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
24 * Strict limit on number of call backs.
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
32 * time = AddCallBack(host, fid)
34 * Returns the expiration time at the workstation.
36 * BreakCallBack(host, fid)
37 * Break all call backs for fid, except for the specified host.
40 * BreakVolumeCallBacksLater(volume)
41 * Break all call backs on volume, using single call to each host
42 * Delete all the call backs.
44 * DeleteCallBack(host,fid)
45 * Delete (do not break) single call back for fid.
47 * DeleteFileCallBacks(fid)
48 * Delete (do not break) all call backs for fid.
50 * DeleteAllCallBacks(host)
51 * Delete (do not break) all call backs for host.
53 * CleanupTimedOutCallBacks()
54 * Delete all timed out call back entries
55 * Must be called periodically by file server.
57 * BreakDelayedCallBacks(host)
58 * Break all delayed call backs for host.
59 * Returns 1: one or more failed, 0: success.
61 * PrintCallBackStats()
62 * Print statistics about call backs to stdout.
64 * DumpCallBacks() ---wishful thinking---
65 * Dump call back state to /tmp/callback.state.
66 * This is separately interpretable by the program pcb.
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.
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).
80 * CleanupCallBacks MUST be called periodically by the file server for
81 * this package to work correctly. Every 5 minutes is suggested.
84 #include <afsconfig.h>
85 #include <afs/param.h>
89 #include <stdlib.h> /* for malloc() */
90 #include <time.h> /* ANSI standard location for time stuff */
100 #include <afs/afs_assert.h>
102 #include <afs/stds.h>
104 #include <afs/nfs.h> /* yuck. This is an abomination. */
107 #include <afs/afscbint.h>
108 #include <afs/afsutil.h>
110 #include <afs/ihandle.h>
111 #include <afs/vnode.h>
112 #include <afs/volume.h>
113 #include "viced_prototypes.h"
116 #include <afs/ptclient.h> /* need definition of prlist for host.h */
118 #include "callback.h"
119 #ifdef AFS_DEMAND_ATTACH_FS
120 #include "../tviced/serialize_state.h"
121 #endif /* AFS_DEMAND_ATTACH_FS */
124 extern afsUUID FS_HostUUID;
125 extern int hostCount;
127 #ifndef INTERPRET_DUMP
128 static int ShowProblems = 1;
131 struct cbcounters cbstuff;
133 static struct FileEntry * FE = NULL; /* don't use FE[0] */
134 static struct CallBack * CB = NULL; /* don't use CB[0] */
136 static struct CallBack * CBfree = NULL;
137 static struct FileEntry * FEfree = NULL;
140 /* Time to live for call backs depends upon number of users of the file.
141 * TimeOuts is indexed by this number/8 (using TimeOut macro). Times
142 * in this table are for the workstation; server timeouts, add
145 static int TimeOuts[] = {
146 /* Note: don't make the first entry larger than 4 hours (see above) */
147 4 * 60 * 60, /* 0-7 users */
148 1 * 60 * 60, /* 8-15 users */
149 30 * 60, /* 16-23 users */
150 15 * 60, /* 24-31 users */
151 15 * 60, /* 32-39 users */
152 10 * 60, /* 40-47 users */
153 10 * 60, /* 48-55 users */
154 10 * 60, /* 56-63 users */
155 }; /* Anything more: MinTimeOut */
157 /* minimum time given for a call back */
158 #ifndef INTERPRET_DUMP
159 static int MinTimeOut = (7 * 60);
162 /* Heads of CB queues; a timeout index is 1+index into this array */
163 static afs_uint32 timeout[CB_NUM_TIMEOUT_QUEUES];
165 static afs_int32 tfirst; /* cbtime of oldest unexpired call back time queue */
168 /* 16 byte object get/free routines */
173 /* Prototypes for static routines */
174 static struct FileEntry *FindFE(AFSFid * fid);
176 #ifndef INTERPRET_DUMP
177 static struct CallBack *iGetCB(int *nused);
178 static int iFreeCB(struct CallBack *cb, int *nused);
179 static struct FileEntry *iGetFE(int *nused);
180 static int iFreeFE(struct FileEntry *fe, int *nused);
181 static int TAdd(struct CallBack *cb, afs_uint32 * thead);
182 static int TDel(struct CallBack *cb);
183 static int HAdd(struct CallBack *cb, struct host *host);
184 static int HDel(struct CallBack *cb);
185 static int CDel(struct CallBack *cb, int deletefe);
186 static int CDelPtr(struct FileEntry *fe, afs_uint32 * cbp,
188 static afs_uint32 *FindCBPtr(struct FileEntry *fe, struct host *host);
189 static int FDel(struct FileEntry *fe);
190 static int AddCallBack1_r(struct host *host, AFSFid * fid, afs_uint32 * thead,
191 int type, int locked);
192 static void MultiBreakCallBack_r(struct cbstruct cba[], int ncbas,
193 struct AFSCBFids *afidp, struct host *xhost);
194 static int MultiBreakVolumeCallBack_r(struct host *host, int isheld,
195 struct VCBParams *parms, int deletefe);
196 static int MultiBreakVolumeLaterCallBack(struct host *host, int isheld,
198 static int GetSomeSpace_r(struct host *hostp, int locked);
199 static int ClearHostCallbacks_r(struct host *hp, int locked);
200 static int DumpCallBackState_r(void);
203 #define GetCB() ((struct CallBack *)iGetCB(&cbstuff.nCBs))
204 #define GetFE() ((struct FileEntry *)iGetFE(&cbstuff.nFEs))
205 #define FreeCB(cb) iFreeCB((struct CallBack *)cb, &cbstuff.nCBs)
206 #define FreeFE(fe) iFreeFE((struct FileEntry *)fe, &cbstuff.nFEs)
209 /* Other protos - move out sometime */
210 void PrintCB(struct CallBack *cb, afs_uint32 now);
212 static afs_uint32 HashTable[FEHASH_SIZE]; /* File entry hash table */
214 static struct FileEntry *
219 struct FileEntry *fe;
221 hash = FEHash(fid->Volume, fid->Unique);
222 for (fei = HashTable[hash]; fei; fei = fe->fnext) {
224 if (fe->volid == fid->Volume && fe->unique == fid->Unique
225 && fe->vnode == fid->Vnode && (fe->status & FE_LATER) != FE_LATER)
231 #ifndef INTERPRET_DUMP
233 static struct CallBack *
236 struct CallBack *ret;
238 if ((ret = CBfree)) {
239 CBfree = (struct CallBack *)(((struct object *)ret)->next);
246 iFreeCB(struct CallBack *cb, int *nused)
248 ((struct object *)cb)->next = (struct object *)CBfree;
254 static struct FileEntry *
257 struct FileEntry *ret;
259 if ((ret = FEfree)) {
260 FEfree = (struct FileEntry *)(((struct object *)ret)->next);
267 iFreeFE(struct FileEntry *fe, int *nused)
269 ((struct object *)fe)->next = (struct object *)FEfree;
275 /* Add cb to end of specified timeout list */
277 TAdd(struct CallBack *cb, afs_uint32 * thead)
280 (*thead) = cb->tnext = cb->tprev = cbtoi(cb);
282 struct CallBack *thp = itocb(*thead);
284 cb->tprev = thp->tprev;
288 thp->tprev = (itocb(thp->tprev)->tnext = cbtoi(cb));
290 thp->tprev = cbtoi(cb);
293 cb->thead = ttoi(thead);
297 /* Delete call back entry from timeout list */
299 TDel(struct CallBack *cb)
301 afs_uint32 *thead = itot(cb->thead);
303 if (*thead == cbtoi(cb))
304 *thead = (*thead == cb->tnext ? 0 : cb->tnext);
305 if (itocb(cb->tprev))
306 itocb(cb->tprev)->tnext = cb->tnext;
307 if (itocb(cb->tnext))
308 itocb(cb->tnext)->tprev = cb->tprev;
312 /* Add cb to end of specified host list */
314 HAdd(struct CallBack *cb, struct host *host)
316 cb->hhead = h_htoi(host);
318 host->cblist = cb->hnext = cb->hprev = cbtoi(cb);
320 struct CallBack *fcb = itocb(host->cblist);
322 cb->hprev = fcb->hprev;
323 cb->hnext = cbtoi(fcb);
324 fcb->hprev = (itocb(fcb->hprev)->hnext = cbtoi(cb));
329 /* Delete call back entry from host list */
331 HDel(struct CallBack *cb)
333 afs_uint32 *hhead = &h_itoh(cb->hhead)->cblist;
335 if (*hhead == cbtoi(cb))
336 *hhead = (*hhead == cb->hnext ? 0 : cb->hnext);
337 itocb(cb->hprev)->hnext = cb->hnext;
338 itocb(cb->hnext)->hprev = cb->hprev;
342 /* Delete call back entry from fid's chain of cb's */
343 /* N.B. This one also deletes the CB, and also possibly parent FE, so
344 * make sure that it is not on any other list before calling this
347 CDel(struct CallBack *cb, int deletefe)
350 struct FileEntry *fe = itofe(cb->fhead);
354 for (safety = 0, cbp = &fe->firstcb; *cbp && *cbp != cbi;
355 cbp = &itocb(*cbp)->cnext, safety++) {
356 if (safety > cbstuff.nblks + 10) {
359 ("CDel: Internal Error -- shutting down: wanted %d from %d, now at %d\n",
360 cbi, fe->firstcb, *cbp));
361 DumpCallBackState_r();
362 ShutDownAndCore(PANIC);
365 CDelPtr(fe, cbp, deletefe);
369 /* Same as CDel, but pointer to parent pointer to CB entry is passed,
370 * as well as file entry */
371 /* N.B. This one also deletes the CB, and also possibly parent FE, so
372 * make sure that it is not on any other list before calling this
374 static int Ccdelpt = 0, CcdelB = 0;
377 CDelPtr(struct FileEntry *fe, afs_uint32 * cbp,
390 if ((--fe->ncbs == 0) && deletefe)
396 FindCBPtr(struct FileEntry *fe, struct host *host)
398 afs_uint32 hostindex = h_htoi(host);
403 for (safety = 0, cbp = &fe->firstcb; *cbp; cbp = &cb->cnext, safety++) {
404 if (safety > cbstuff.nblks) {
405 ViceLog(0, ("FindCBPtr: Internal Error -- shutting down.\n"));
406 DumpCallBackState_r();
407 ShutDownAndCore(PANIC);
410 if (cb->hhead == hostindex)
416 /* Delete file entry from hash table */
418 FDel(struct FileEntry *fe)
421 afs_uint32 *p = &HashTable[FEHash(fe->volid, fe->unique)];
423 while (*p && *p != fei)
424 p = &itofe(*p)->fnext;
431 /* initialize the callback package */
433 InitCallBack(int nblks)
436 tfirst = CBtime(FT_ApproxTime());
437 /* N.B. The "-1", below, is because
438 * FE[0] and CB[0] are not used--and not allocated */
439 FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry))));
441 ViceLog(0, ("Failed malloc in InitCallBack\n"));
444 FE--; /* FE[0] is supposed to point to junk */
445 cbstuff.nFEs = nblks;
447 FreeFE(&FE[cbstuff.nFEs]); /* This is correct */
448 CB = ((struct CallBack *)(calloc(nblks, sizeof(struct CallBack))));
450 ViceLog(0, ("Failed malloc in InitCallBack\n"));
453 CB--; /* CB[0] is supposed to point to junk */
454 cbstuff.nCBs = nblks;
456 FreeCB(&CB[cbstuff.nCBs]); /* This is correct */
457 cbstuff.nblks = nblks;
458 cbstuff.nbreakers = 0;
464 XCallBackBulk_r(struct host * ahost, struct AFSFid * fids, afs_int32 nfids)
466 struct AFSCallBack tcbs[AFSCBMAX];
472 struct rx_connection *cb_conn = NULL;
475 rx_SetConnDeadTime(ahost->callback_rxcon, 4);
476 rx_SetConnHardDeadTime(ahost->callback_rxcon, AFS_HARDDEADTIME);
483 for (i = 0; i < nfids && i < AFSCBMAX; i++) {
484 tcbs[i].CallBackVersion = CALLBACK_VERSION;
485 tcbs[i].ExpirationTime = 0;
486 tcbs[i].CallBackType = CB_DROPPED;
488 tf.AFSCBFids_len = i;
489 tf.AFSCBFids_val = &(fids[j]);
493 tc.AFSCBs_val = tcbs;
495 cb_conn = ahost->callback_rxcon;
496 rx_GetConnection(cb_conn);
498 code |= RXAFSCB_CallBack(cb_conn, &tf, &tc);
499 rx_PutConnection(cb_conn);
507 /* the locked flag tells us if the host entry has already been locked
508 * by our parent. I don't think anybody actually calls us with the
509 * host locked, but here's how to make that work: GetSomeSpace has to
510 * change so that it doesn't attempt to lock any hosts < "host". That
511 * means that it might be unable to free any objects, so it has to
512 * return an exit status. If it fails, then AddCallBack1 might fail,
513 * as well. If so, the host->ResetDone should probably be set to 0,
514 * and we probably don't want to return a callback promise to the
515 * cache manager, either. */
517 AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
525 if (!(host->hostFlags & HOSTDELETED))
526 retVal = AddCallBack1_r(host, fid, thead, type, 1);
536 AddCallBack1_r(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
539 struct FileEntry *fe;
540 struct CallBack *cb = 0, *lastcb = 0;
541 struct FileEntry *newfe = 0;
542 afs_uint32 time_out = 0;
543 afs_uint32 *Thead = thead;
544 struct CallBack *newcb = 0;
547 cbstuff.AddCallBacks++;
551 /* allocate these guys first, since we can't call the allocator with
552 * the host structure locked -- or we might deadlock. However, we have
553 * to avoid races with FindFE... */
554 while (!(newcb = GetCB())) {
555 GetSomeSpace_r(host, locked);
557 while (!(newfe = GetFE())) { /* Get it now, so we don't have to call */
558 /* GetSomeSpace with the host locked, later. This might turn out to */
559 /* have been unneccessary, but that's actually kind of unlikely, since */
560 /* most files are not shared. */
561 GetSomeSpace_r(host, locked);
565 h_Lock_r(host); /* this can yield, so do it before we get any */
567 if (host->hostFlags & HOSTDELETED) {
575 if (type == CB_NORMAL) {
577 TimeCeiling(FT_ApproxTime() + TimeOut(fe ? fe->ncbs : 0) +
579 Thead = THead(CBtime(time_out));
580 } else if (type == CB_VOLUME) {
581 time_out = TimeCeiling((60 * 120 + FT_ApproxTime()) + ServerBias);
582 Thead = THead(CBtime(time_out));
583 } else if (type == CB_BULK) {
584 /* bulk status can get so many callbacks all at once, and most of them
585 * are probably not for things that will be used for long.
588 TimeCeiling(FT_ApproxTime() + ServerBias +
589 TimeOut(22 + (fe ? fe->ncbs : 0)));
590 Thead = THead(CBtime(time_out));
601 fe->volid = fid->Volume;
602 fe->vnode = fid->Vnode;
603 fe->unique = fid->Unique;
606 hash = FEHash(fid->Volume, fid->Unique);
607 fe->fnext = HashTable[hash];
608 HashTable[hash] = fetoi(fe);
610 for (safety = 0, lastcb = cb = itocb(fe->firstcb); cb;
611 lastcb = cb, cb = itocb(cb->cnext), safety++) {
612 if (safety > cbstuff.nblks) {
613 ViceLog(0, ("AddCallBack1: Internal Error -- shutting down.\n"));
614 DumpCallBackState_r();
615 ShutDownAndCore(PANIC);
617 if (cb->hhead == h_htoi(host))
620 if (cb) { /* Already have call back: move to new timeout list */
621 /* don't change delayed callbacks back to normal ones */
622 if (cb->status != CB_DELAYED)
624 /* Only move if new timeout is longer */
625 if (TNorm(ttoi(Thead)) > TNorm(cb->thead)) {
629 if (newfe == NULL) { /* we are using the new FE */
630 fe->firstcb = cbtoi(cb);
632 cb->fhead = fetoi(fe);
637 *(lastcb ? &lastcb->cnext : &fe->firstcb) = cbtoi(cb);
640 cb->fhead = fetoi(fe);
646 /* now free any still-unused callback or host entries */
652 if (!locked) /* freecb and freefe might(?) yield */
655 if (type == CB_NORMAL || type == CB_VOLUME || type == CB_BULK)
656 return time_out - ServerBias; /* Expires sooner at workstation */
662 CompareCBA(const void *e1, const void *e2)
664 const struct cbstruct *cba1 = (const struct cbstruct *)e1;
665 const struct cbstruct *cba2 = (const struct cbstruct *)e2;
666 return ((cba1->hp)->index - (cba2->hp)->index);
669 /* Take an array full of hosts, all held. Break callbacks to them, and
670 * release the holds once you're done, except don't release xhost. xhost
671 * may be NULL. Currently only works for a single Fid in afidp array.
672 * If you want to make this work with multiple fids, you need to fix
673 * the error handling. One approach would be to force a reset if a
674 * multi-fid call fails, or you could add delayed callbacks for each
675 * fid. You probably also need to sort and remove duplicate hosts.
676 * When this is called from the BreakVolumeCallBacks path, it does NOT
677 * force a reset if the RPC fails, it just marks the host down and tries
678 * to create a delayed callback. */
679 /* N.B. be sure that code works when ncbas == 0 */
680 /* N.B. requires all the cba[*].hp pointers to be valid... */
681 /* This routine does not hold a lock on the host for the duration of
682 * the BreakCallBack RPC, which is a significant deviation from tradition.
683 * It _does_ get a lock on the host before setting VenusDown = 1,
684 * which is sufficient only if VenusDown = 0 only happens when the
685 * lock is held over the RPC and the subsequent VenusDown == 0
686 * wherever that is done. */
688 MultiBreakCallBack_r(struct cbstruct cba[], int ncbas,
689 struct AFSCBFids *afidp, struct host *xhost)
692 struct rx_connection *conns[MAX_CB_HOSTS];
693 static struct AFSCBs tc = { 0, 0 };
694 int multi_to_cba_map[MAX_CB_HOSTS];
696 assert(ncbas <= MAX_CB_HOSTS);
698 /* sort cba list to avoid makecall issues */
699 qsort(cba, ncbas, sizeof(struct cbstruct), CompareCBA);
701 /* set up conns for multi-call */
702 for (i = 0, j = 0; i < ncbas; i++) {
703 struct host *thishost = cba[i].hp;
704 if (!thishost || (thishost->hostFlags & HOSTDELETED)) {
707 rx_GetConnection(thishost->callback_rxcon);
708 multi_to_cba_map[j] = i;
709 conns[j++] = thishost->callback_rxcon;
712 rx_SetConnDeadTime(thishost->callback_rxcon, 4);
713 rx_SetConnHardDeadTime(thishost->callback_rxcon, AFS_HARDDEADTIME);
717 if (j) { /* who knows what multi would do with 0 conns? */
721 multi_RXAFSCB_CallBack(afidp, &tc);
727 i = multi_to_cba_map[multi_i];
733 ("BCB: INTERNAL ERROR: hp=%p, cba=%p, thead=%u\n",
737 ** try breaking callbacks on alternate interface addresses
739 if (MultiBreakCallBackAlternateAddress(hp, afidp)) {
742 ("BCB: Failed on file %u.%u.%u, "
743 "Host %p (%s:%d) is down\n",
744 afidp->AFSCBFids_val->Volume,
745 afidp->AFSCBFids_val->Vnode,
746 afidp->AFSCBFids_val->Unique,
748 afs_inet_ntoa_r(hp->host, hoststr),
754 if (!(hp->hostFlags & HOSTDELETED)) {
755 hp->hostFlags |= VENUSDOWN;
757 * We always go into AddCallBack1_r with the host locked
759 AddCallBack1_r(hp, afidp->AFSCBFids_val, itot(idx),
773 for (i = 0; i < ncbas; i++) {
776 if (hp && xhost != hp) {
781 /* H_UNLOCK around this so h_FreeConnection does not deadlock.
782 h_FreeConnection should *never* be called on a callback connection,
783 but on 10/27/04 a deadlock occurred where it was, when we know why,
784 this should be reverted. -- shadow */
786 for (i = 0; i < j; i++) {
787 rx_PutConnection(conns[i]);
795 * Break all call backs for fid, except for the specified host (unless flag
796 * is true, in which case all get a callback message. Assumption: the specified
797 * host is h_Held, by the caller; the others aren't.
798 * Specified host may be bogus, that's ok. This used to check to see if the
799 * host was down in two places, once right after the host was h_held, and
800 * again after it was locked. That race condition is incredibly rare and
801 * relatively harmless even when it does occur, so we don't check for it now.
803 /* if flag is true, send a break callback msg to "host", too */
805 BreakCallBack(struct host *xhost, AFSFid * fid, int flag)
807 struct FileEntry *fe;
808 struct CallBack *cb, *nextcb;
809 struct cbstruct cba[MAX_CB_HOSTS];
816 ("BCB: BreakCallBack(Host %p all but %s:%d, (%u,%u,%u))\n",
817 xhost, afs_inet_ntoa_r(xhost->host, hoststr), ntohs(xhost->port),
818 fid->Volume, fid->Vnode, fid->Unique));
821 cbstuff.BreakCallBacks++;
826 hostindex = h_htoi(xhost);
827 cb = itocb(fe->firstcb);
828 if (!cb || ((fe->ncbs == 1) && (cb->hhead == hostindex) && !flag)) {
829 /* the most common case is what follows the || */
832 tf.AFSCBFids_len = 1;
833 tf.AFSCBFids_val = fid;
836 for (ncbas = 0; cb && ncbas < MAX_CB_HOSTS; cb = nextcb) {
837 nextcb = itocb(cb->cnext);
838 if ((cb->hhead != hostindex || flag)
839 && (cb->status == CB_BULK || cb->status == CB_NORMAL
840 || cb->status == CB_VOLUME)) {
841 struct host *thishost = h_itoh(cb->hhead);
843 ViceLog(0, ("BCB: BOGUS! cb->hhead is NULL!\n"));
844 } else if (thishost->hostFlags & VENUSDOWN) {
846 ("BCB: %p (%s:%d) is down; delaying break call back\n",
847 thishost, afs_inet_ntoa_r(thishost->host, hoststr),
848 ntohs(thishost->port)));
849 cb->status = CB_DELAYED;
851 if (!(thishost->hostFlags & HOSTDELETED)) {
853 cba[ncbas].hp = thishost;
854 cba[ncbas].thead = cb->thead;
859 CDel(cb, 1); /* Usually first; so this delete
860 * is reasonably inexpensive */
866 MultiBreakCallBack_r(cba, ncbas, &tf, xhost);
868 /* we need to to all these initializations again because MultiBreakCallBack may block */
873 cb = itocb(fe->firstcb);
874 if (!cb || ((fe->ncbs == 1) && (cb->hhead == hostindex) && !flag)) {
875 /* the most common case is what follows the || */
886 /* Delete (do not break) single call back for fid */
888 DeleteCallBack(struct host *host, AFSFid * fid)
890 struct FileEntry *fe;
895 cbstuff.DeleteCallBacks++;
898 /* do not care if the host has been HOSTDELETED */
904 ("DCB: No call backs for fid (%u, %u, %u)\n", fid->Volume,
905 fid->Vnode, fid->Unique));
908 pcb = FindCBPtr(fe, host);
911 ("DCB: No call back for host %p (%s:%d), (%u, %u, %u)\n",
912 host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
913 fid->Volume, fid->Vnode, fid->Unique));
927 * Delete (do not break) all call backs for fid. This call doesn't
928 * set all of the various host locks, but it shouldn't really matter
929 * since we're not adding callbacks, but deleting them. I'm not sure
930 * why it doesn't set the lock, however; perhaps it should.
933 DeleteFileCallBacks(AFSFid * fid)
935 struct FileEntry *fe;
941 cbstuff.DeleteFiles++;
946 ("DF: No fid (%u,%u,%u) to delete\n", fid->Volume, fid->Vnode,
950 for (n = 0, cbi = fe->firstcb; cbi; n++) {
963 /* Delete (do not break) all call backs for host. The host should be
966 DeleteAllCallBacks_r(struct host *host, int deletefe)
971 cbstuff.DeleteAllCallBacks++;
972 cbi = first = host->cblist;
974 ViceLog(8, ("DV: no call backs\n"));
982 } while (cbi != first);
988 * Break all delayed call backs for host. Returns 1 if all call backs
989 * successfully broken; 0 otherwise. Assumes host is h_Held and h_Locked.
990 * Must be called with VenusDown set for this host
993 BreakDelayedCallBacks(struct host *host)
997 retVal = BreakDelayedCallBacks_r(host);
1003 BreakDelayedCallBacks_r(struct host *host)
1005 struct AFSFid fids[AFSCBMAX];
1006 int cbi, first, nfids;
1007 struct CallBack *cb;
1010 struct rx_connection *cb_conn;
1012 cbstuff.nbreakers++;
1013 if (!(host->hostFlags & RESETDONE) && !(host->hostFlags & HOSTDELETED)) {
1014 host->hostFlags &= ~ALTADDR; /* alternate addresses are invalid */
1015 cb_conn = host->callback_rxcon;
1016 rx_GetConnection(cb_conn);
1017 if (host->interface) {
1020 RXAFSCB_InitCallBackState3(cb_conn, &FS_HostUUID);
1023 code = RXAFSCB_InitCallBackState(cb_conn);
1025 rx_PutConnection(cb_conn);
1028 host->hostFlags |= ALTADDR; /* alternate addresses are valid */
1032 ("CB: Call back connect back failed (in break delayed) "
1033 "for Host %p (%s:%d)\n",
1034 host, afs_inet_ntoa_r(host->host, hoststr),
1035 ntohs(host->port)));
1037 host->hostFlags |= VENUSDOWN;
1040 ("InitCallBackState success on %p (%s:%d)\n",
1041 host, afs_inet_ntoa_r(host->host, hoststr),
1042 ntohs(host->port)));
1043 /* reset was done successfully */
1044 host->hostFlags |= RESETDONE;
1045 host->hostFlags &= ~VENUSDOWN;
1048 while (!(host->hostFlags & HOSTDELETED)) {
1050 host->hostFlags &= ~VENUSDOWN; /* presume up */
1051 cbi = first = host->cblist;
1055 first = host->cblist;
1058 if (cb->status == CB_DELAYED) {
1059 struct FileEntry *fe = itofe(cb->fhead);
1060 fids[nfids].Volume = fe->volid;
1061 fids[nfids].Vnode = fe->vnode;
1062 fids[nfids].Unique = fe->unique;
1068 } while (cbi && cbi != first && nfids < AFSCBMAX);
1074 if (XCallBackBulk_r(host, fids, nfids)) {
1075 /* Failed, again: put them back, probably with old
1080 ("CB: XCallBackBulk failed, Host %p (%s:%d); "
1081 "callback list follows:\n",
1082 host, afs_inet_ntoa_r(host->host, hoststr),
1083 ntohs(host->port)));
1085 for (i = 0; i < nfids; i++) {
1088 ("CB: Host %p (%s:%d), file %u.%u.%u "
1089 "(part of bulk callback)\n",
1090 host, afs_inet_ntoa_r(host->host, hoststr),
1091 ntohs(host->port), fids[i].Volume,
1092 fids[i].Vnode, fids[i].Unique));
1095 * AddCallBack1_r(host, &fids[i], itot(thead[i]), CB_DELAYED, 1);
1096 * * but it turns out to cause too many tricky locking problems.
1097 * * now, if break delayed fails, screw it. */
1099 host->hostFlags |= VENUSDOWN; /* Failed */
1100 ClearHostCallbacks_r(host, 1 /* locked */ );
1104 if (nfids < AFSCBMAX)
1108 cbstuff.nbreakers--;
1109 /* If we succeeded it's always ok to unset HFE_LATER */
1110 if (!(host->hostFlags & VENUSDOWN))
1111 host->hostFlags &= ~HFE_LATER;
1112 return (host->hostFlags & VENUSDOWN);
1116 ** isheld is 0 if the host is held in h_Enumerate
1117 ** isheld is 1 if the host is held in BreakVolumeCallBacks
1120 MultiBreakVolumeCallBack_r(struct host *host, int isheld,
1121 struct VCBParams *parms, int deletefe)
1125 if (host->hostFlags & HOSTDELETED)
1126 return 0; /* host is deleted, release hold */
1128 if (!(host->hostFlags & HCBREAK))
1129 return 0; /* host is not flagged to notify */
1131 if (host->hostFlags & VENUSDOWN) {
1133 /* Do not care if the host is now HOSTDELETED */
1136 ("BVCB: volume callback for Host %p (%s:%d) failed\n",
1137 host, afs_inet_ntoa_r(host->host, hoststr),
1138 ntohs(host->port)));
1140 DeleteAllCallBacks_r(host, deletefe); /* Delete all callback state
1141 * rather than attempting to
1142 * selectively remember to
1143 * delete the volume callbacks
1145 host->hostFlags &= ~(RESETDONE|HCBREAK); /* Do InitCallBackState when host returns */
1147 return 0; /* parent will release hold */
1149 assert(parms->ncbas <= MAX_CB_HOSTS);
1151 /* Do not call MultiBreakCallBack on the current host structure
1152 ** because it would prematurely release the hold on the host
1154 if (parms->ncbas == MAX_CB_HOSTS) {
1155 struct AFSCBFids tf;
1157 tf.AFSCBFids_len = 1;
1158 tf.AFSCBFids_val = parms->fid;
1160 /* this releases all the hosts */
1161 MultiBreakCallBack_r(parms->cba, parms->ncbas, &tf, 0 /* xhost */ );
1165 parms->cba[parms->ncbas].hp = host;
1166 parms->cba[(parms->ncbas)++].thead = parms->thead;
1167 host->hostFlags &= ~HCBREAK;
1168 return 1; /* parent shouldn't release hold, more work to do */
1172 ** isheld is 0 if the host is held in h_Enumerate
1173 ** isheld is 1 if the host is held in BreakVolumeCallBacks
1176 MultiBreakVolumeLaterCallBack(struct host *host, int isheld, void *rock)
1178 struct VCBParams *parms = (struct VCBParams *)rock;
1181 retval = MultiBreakVolumeCallBack_r(host, isheld, parms, 0);
1187 * Break all call backs on a single volume. Don't call this with any
1188 * hosts h_held. Note that this routine clears the callbacks before
1189 * actually breaking them, and that the vnode isn't locked during this
1190 * operation, so that people might see temporary callback loss while
1191 * this function is executing. It is just a temporary state, however,
1192 * since the callback will be broken later by this same function.
1194 * Now uses multi-RX for CallBack RPC in a different thread,
1195 * only marking them here.
1197 #ifdef AFS_PTHREAD_ENV
1198 extern pthread_cond_t fsync_cond;
1200 extern char fsync_wait[];
1204 BreakVolumeCallBacksLater(afs_uint32 volume)
1208 struct FileEntry *fe;
1209 struct CallBack *cb;
1213 ViceLog(25, ("Setting later on volume %u\n", volume));
1215 for (hash = 0; hash < FEHASH_SIZE; hash++) {
1216 for (feip = &HashTable[hash]; (fe = itofe(*feip)) != NULL; ) {
1217 if (fe->volid == volume) {
1218 struct CallBack *cbnext;
1219 for (cb = itocb(fe->firstcb); cb; cb = cbnext) {
1220 host = h_itoh(cb->hhead);
1221 host->hostFlags |= HFE_LATER;
1222 cb->status = CB_DELAYED;
1223 cbnext = itocb(cb->cnext);
1226 fe->status |= FE_LATER;
1235 /* didn't find any callbacks, so return right away. */
1239 ViceLog(25, ("Fsync thread wakeup\n"));
1240 #ifdef AFS_PTHREAD_ENV
1242 assert(pthread_cond_broadcast(&fsync_cond) == 0);
1245 LWP_NoYieldSignal(fsync_wait);
1251 BreakLaterCallBacks(void)
1256 struct CallBack *cb;
1257 struct FileEntry *fe = NULL;
1258 struct FileEntry *myfe = NULL;
1260 struct VCBParams henumParms;
1261 unsigned short tthead = 0; /* zero is illegal value */
1265 ViceLog(25, ("Looking for FileEntries to unchain\n"));
1268 /* Pick the first volume we see to clean up */
1269 fid.Volume = fid.Vnode = fid.Unique = 0;
1271 for (hash = 0; hash < FEHASH_SIZE; hash++) {
1272 for (feip = &HashTable[hash]; (fe = itofe(*feip)) != NULL; ) {
1273 if (fe && (fe->status & FE_LATER)
1274 && (fid.Volume == 0 || fid.Volume == fe->volid)) {
1275 /* Ugly, but used to avoid left side casting */
1276 struct object *tmpfe;
1278 ("Unchaining for %u:%u:%u\n", fe->vnode, fe->unique,
1280 fid.Volume = fe->volid;
1282 fe->status &= ~FE_LATER; /* not strictly needed */
1283 /* Works since volid is deeper than the largest pointer */
1284 tmpfe = (struct object *)fe;
1285 tmpfe->next = (struct object *)myfe;
1298 /* loop over FEs from myfe and free/break */
1300 for (fe = myfe; fe;) {
1301 struct CallBack *cbnext;
1302 for (cb = itocb(fe->firstcb); cb; cb = cbnext) {
1303 cbnext = itocb(cb->cnext);
1304 host = h_itoh(cb->hhead);
1305 if (cb->status == CB_DELAYED) {
1306 if (!(host->hostFlags & HOSTDELETED)) {
1307 /* mark this host for notification */
1308 host->hostFlags |= HCBREAK;
1309 if (!tthead || (TNorm(tthead) < TNorm(cb->thead))) {
1315 CDel(cb, 0); /* Don't let CDel clean up the fe */
1316 /* leave flag for MultiBreakVolumeCallBack to clear */
1319 ("Found host %p (%s:%d) non-DELAYED cb for %u:%u:%u\n",
1320 host, afs_inet_ntoa_r(host->host, hoststr),
1321 ntohs(host->port), fe->vnode, fe->unique, fe->volid));
1325 fe = (struct FileEntry *)((struct object *)fe)->next;
1330 ViceLog(125, ("Breaking volume %u\n", fid.Volume));
1331 henumParms.ncbas = 0;
1332 henumParms.fid = &fid;
1333 henumParms.thead = tthead;
1335 h_Enumerate(MultiBreakVolumeLaterCallBack, (char *)&henumParms);
1337 if (henumParms.ncbas) { /* do left-overs */
1338 struct AFSCBFids tf;
1339 tf.AFSCBFids_len = 1;
1340 tf.AFSCBFids_val = &fid;
1342 MultiBreakCallBack_r(henumParms.cba, henumParms.ncbas, &tf, 0);
1343 henumParms.ncbas = 0;
1348 /* Arrange to be called again */
1353 * Delete all timed-out call back entries (to be called periodically by file
1357 CleanupTimedOutCallBacks(void)
1360 CleanupTimedOutCallBacks_r();
1366 CleanupTimedOutCallBacks_r(void)
1368 afs_uint32 now = CBtime(FT_ApproxTime());
1370 struct CallBack *cb;
1374 while (tfirst <= now) {
1376 cbi = *(thead = THead(tfirst));
1382 ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n",
1383 h_itoh(cb->hhead)->host,
1384 afs_inet_ntoa_r(h_itoh(cb->hhead)->host, hoststr),
1385 h_itoh(cb->hhead)->port, itofe(cb->fhead)->volid,
1386 itofe(cb->fhead)->vnode, itofe(cb->fhead)->unique));
1390 if (ntimedout > cbstuff.nblks) {
1391 ViceLog(0, ("CCB: Internal Error -- shutting down...\n"));
1392 DumpCallBackState_r();
1393 ShutDownAndCore(PANIC);
1395 } while (cbi != *thead);
1400 cbstuff.CBsTimedOut += ntimedout;
1401 ViceLog(7, ("CCB: deleted %d timed out callbacks\n", ntimedout));
1402 return (ntimedout > 0);
1406 * parameters to pass to lih*_r from h_Enumerate_r when trying to find a host
1407 * from which to clear callbacks.
1411 * Points to the least interesting host found; try to clear callbacks on
1412 * this host after h_Enumerate_r(lih*_r)'ing.
1417 * The last host we got from lih*_r, but we couldn't clear its callbacks
1418 * for some reason. Choose the next-best host after this one (with the
1419 * current lih*_r, this means to only select hosts that have an ActiveCall
1420 * newer than lastlih).
1422 struct host *lastlih;
1425 /* Value of host->refCount that allows us to reliably infer that
1426 * host may be held by some other thread */
1427 #define OTHER_MUSTHOLD_LIH 2
1429 /* This version does not allow 'host' to be selected unless its ActiveCall
1430 * is newer than 'params->lastlih' which is the host with the oldest
1431 * ActiveCall from the last pass (if it is provided). We filter out any hosts
1432 * that are are held by other threads.
1434 * There is a small problem here, but it may not be easily fixable. Say we
1435 * select some host A, and give it back to GetSomeSpace_r. GSS_r for some
1436 * reason cannot clear the callbacks on A, and so calls us again with
1437 * lastlih = A. Suppose there is another host B that has the same ActiveCall
1438 * time as A. We will now skip over host B, since
1439 * 'hostB->ActiveCall > hostA->ActiveCall' is not true. This could result in
1440 * us prematurely going to the GSS_r 2nd or 3rd pass, and making us a little
1441 * inefficient. This should be pretty rare, though, except perhaps in cases
1442 * with very small numbers of hosts.
1444 * Also filter out any hosts with HOSTDELETED set. h_Enumerate_r should in
1445 * theory not give these to us anyway, but be paranoid.
1448 lih0_r(struct host *host, int flags, void *rock)
1450 struct lih_params *params = (struct lih_params *)rock;
1452 /* OTHER_MUSTHOLD_LIH is because the h_Enum loop holds us once */
1454 && (!(host->hostFlags & HOSTDELETED))
1455 && (host->refCount < OTHER_MUSTHOLD_LIH)
1456 && (!params->lih || host->ActiveCall < params->lih->ActiveCall)
1457 && (!params->lastlih || host->ActiveCall > params->lastlih->ActiveCall)) {
1460 h_Release_r(params->lih); /* release prev host */
1469 /* same as lih0_r, except we do not prevent held hosts from being selected. */
1471 lih1_r(struct host *host, int flags, void *rock)
1473 struct lih_params *params = (struct lih_params *)rock;
1476 && (!(host->hostFlags & HOSTDELETED))
1477 && (!params->lih || host->ActiveCall < params->lih->ActiveCall)
1478 && (!params->lastlih || host->ActiveCall > params->lastlih->ActiveCall)) {
1481 h_Release_r(params->lih); /* release prev host */
1490 /* This could be upgraded to get more space each time */
1491 /* first pass: sequentially find the oldest host which isn't held by
1492 anyone for which we can clear callbacks;
1494 /* second pass: sequentially find the oldest host regardless of
1495 whether or not the host is held; skipping 'hostp' */
1496 /* third pass: attempt to clear callbacks from 'hostp' */
1497 /* always called with hostp unlocked */
1499 /* Note: hostlist is ordered most recently created host first and
1500 * its order has no relationship to the most recently used. */
1501 extern struct host *hostList;
1503 GetSomeSpace_r(struct host *hostp, int locked)
1506 struct lih_params params;
1509 cbstuff.GotSomeSpaces++;
1511 ("GSS: First looking for timed out call backs via CleanupCallBacks\n"));
1512 if (CleanupTimedOutCallBacks_r()) {
1518 params.lastlih = NULL;
1523 h_Enumerate_r(i == 0 ? lih0_r : lih1_r, hostList, ¶ms);
1526 if (params.lastlih) {
1527 h_Release_r(params.lastlih);
1528 params.lastlih = NULL;
1532 /* note that 'hp' was held by lih*_r; we will need to release it */
1534 if ((hp != hostp) && !ClearHostCallbacks_r(hp, 0 /* not locked or held */ )) {
1539 params.lastlih = hp;
1540 /* params.lastlih will be released on the next iteration, after
1545 * Next time try getting callbacks from any host even if
1546 * it's held, since the only other option is starvation for
1547 * the file server (i.e. until the callback timeout arrives).
1550 params.lastlih = NULL;
1553 ("GSS: Try harder for longest inactive host cnt= %d\n",
1558 /* Could not obtain space from other hosts, clear hostp's callback state */
1563 ClearHostCallbacks_r(hostp, 1 /*already locked */ );
1570 /* locked - set if caller has already locked the host */
1572 ClearHostCallbacks_r(struct host *hp, int locked)
1576 struct rx_connection *cb_conn = NULL;
1579 ("GSS: Delete longest inactive host %p (%s:%d)\n",
1580 hp, afs_inet_ntoa_r(hp->host, hoststr), ntohs(hp->port)));
1582 if ((hp->hostFlags & HOSTDELETED)) {
1583 /* hp could go away after reacquiring H_LOCK in h_NBLock_r, so we can't
1584 * really use it; its callbacks will get cleared anyway when
1585 * h_TossStuff_r gets its hands on it */
1591 /** Try a non-blocking lock. If the lock is already held return
1592 * after releasing hold on hp
1595 if (h_NBLock_r(hp)) {
1600 if (hp->Console & 2) {
1602 * If the special console field is set it means that a thread
1603 * is waiting in AddCallBack1 after it set pointers to the
1604 * file entry and/or callback entry. Because of the bogus
1605 * usage of h_hold it won't prevent from another thread, this
1606 * one, to remove all the callbacks so just to be safe we keep
1607 * a reference. NOTE, on the last phase we'll free the calling
1608 * host's callbacks but that's ok...
1612 DeleteAllCallBacks_r(hp, 1);
1613 if (hp->hostFlags & VENUSDOWN) {
1614 hp->hostFlags &= ~RESETDONE; /* remember that we must do a reset */
1615 } else if (!(hp->hostFlags & HOSTDELETED)) {
1616 /* host is up, try a call */
1617 hp->hostFlags &= ~ALTADDR; /* alternate addresses are invalid */
1618 cb_conn = hp->callback_rxcon;
1619 rx_GetConnection(hp->callback_rxcon);
1620 if (hp->interface) {
1623 RXAFSCB_InitCallBackState3(cb_conn, &FS_HostUUID);
1626 code = RXAFSCB_InitCallBackState(cb_conn);
1628 rx_PutConnection(cb_conn);
1631 hp->hostFlags |= ALTADDR; /* alternate addresses are valid */
1633 /* failed, mark host down and need reset */
1634 hp->hostFlags |= VENUSDOWN;
1635 hp->hostFlags &= ~RESETDONE;
1637 /* reset succeeded, we're done */
1638 hp->hostFlags |= RESETDONE;
1647 #endif /* INTERPRET_DUMP */
1651 PrintCallBackStats(void)
1654 "%d add CB, %d break CB, %d del CB, %d del FE, %d CB's timed out, %d space reclaim, %d del host\n",
1655 cbstuff.AddCallBacks, cbstuff.BreakCallBacks,
1656 cbstuff.DeleteCallBacks, cbstuff.DeleteFiles, cbstuff.CBsTimedOut,
1657 cbstuff.GotSomeSpaces, cbstuff.DeleteAllCallBacks);
1658 fprintf(stderr, "%d CBs, %d FEs, (%d of total of %d 16-byte blocks)\n",
1659 cbstuff.nCBs, cbstuff.nFEs, cbstuff.nCBs + cbstuff.nFEs,
1661 fprintf(stderr, "%d GSS1, %d GSS2, %d GSS3, %d GSS4, %d GSS5 (internal counters)\n",
1662 cbstuff.GSS1, cbstuff.GSS2, cbstuff.GSS3, cbstuff.GSS4, cbstuff.GSS5);
1667 #define MAGIC 0x12345678 /* To check byte ordering of dump when it is read in */
1668 #define MAGICV2 0x12345679 /* To check byte ordering & version of dump when it is read in */
1671 #ifndef INTERPRET_DUMP
1673 #ifdef AFS_DEMAND_ATTACH_FS
1676 * callback state serialization
1678 static int cb_stateSaveTimeouts(struct fs_dump_state * state);
1679 static int cb_stateSaveFEHash(struct fs_dump_state * state);
1680 static int cb_stateSaveFEs(struct fs_dump_state * state);
1681 static int cb_stateSaveFE(struct fs_dump_state * state, struct FileEntry * fe);
1682 static int cb_stateRestoreTimeouts(struct fs_dump_state * state);
1683 static int cb_stateRestoreFEHash(struct fs_dump_state * state);
1684 static int cb_stateRestoreFEs(struct fs_dump_state * state);
1685 static int cb_stateRestoreFE(struct fs_dump_state * state);
1686 static int cb_stateRestoreCBs(struct fs_dump_state * state, struct FileEntry * fe,
1687 struct iovec * iov, int niovecs);
1689 static int cb_stateVerifyFEHash(struct fs_dump_state * state);
1690 static int cb_stateVerifyFE(struct fs_dump_state * state, struct FileEntry * fe);
1691 static int cb_stateVerifyFCBList(struct fs_dump_state * state, struct FileEntry * fe);
1692 static int cb_stateVerifyTimeoutQueues(struct fs_dump_state * state);
1694 static int cb_stateFEToDiskEntry(struct FileEntry *, struct FEDiskEntry *);
1695 static int cb_stateDiskEntryToFE(struct fs_dump_state * state,
1696 struct FEDiskEntry *, struct FileEntry *);
1698 static int cb_stateCBToDiskEntry(struct CallBack *, struct CBDiskEntry *);
1699 static int cb_stateDiskEntryToCB(struct fs_dump_state * state,
1700 struct CBDiskEntry *, struct CallBack *);
1702 static int cb_stateFillHeader(struct callback_state_header * hdr);
1703 static int cb_stateCheckHeader(struct callback_state_header * hdr);
1705 static int cb_stateAllocMap(struct fs_dump_state * state);
1708 cb_stateSave(struct fs_dump_state * state)
1712 AssignInt64(state->eof_offset, &state->hdr->cb_offset);
1714 /* invalidate callback state header */
1715 memset(state->cb_hdr, 0, sizeof(struct callback_state_header));
1716 if (fs_stateWriteHeader(state, &state->hdr->cb_offset, state->cb_hdr,
1717 sizeof(struct callback_state_header))) {
1722 fs_stateIncEOF(state, sizeof(struct callback_state_header));
1724 /* dump timeout state */
1725 if (cb_stateSaveTimeouts(state)) {
1730 /* dump fe hashtable state */
1731 if (cb_stateSaveFEHash(state)) {
1736 /* dump callback state */
1737 if (cb_stateSaveFEs(state)) {
1742 /* write the callback state header to disk */
1743 cb_stateFillHeader(state->cb_hdr);
1744 if (fs_stateWriteHeader(state, &state->hdr->cb_offset, state->cb_hdr,
1745 sizeof(struct callback_state_header))) {
1755 cb_stateRestore(struct fs_dump_state * state)
1759 if (fs_stateReadHeader(state, &state->hdr->cb_offset, state->cb_hdr,
1760 sizeof(struct callback_state_header))) {
1765 if (cb_stateCheckHeader(state->cb_hdr)) {
1770 if (cb_stateAllocMap(state)) {
1775 if (cb_stateRestoreTimeouts(state)) {
1780 if (cb_stateRestoreFEHash(state)) {
1785 /* restore FEs and CBs from disk */
1786 if (cb_stateRestoreFEs(state)) {
1791 /* restore the timeout queue heads */
1792 tfirst = state->cb_hdr->tfirst;
1799 cb_stateRestoreIndices(struct fs_dump_state * state)
1802 struct FileEntry * fe;
1803 struct CallBack * cb;
1805 /* restore indices in the FileEntry structures */
1806 for (i = 1; i < state->fe_map.len; i++) {
1807 if (state->fe_map.entries[i].new_idx) {
1808 fe = itofe(state->fe_map.entries[i].new_idx);
1810 /* restore the fe->fnext entry */
1811 if (fe_OldToNew(state, fe->fnext, &fe->fnext)) {
1816 /* restore the fe->firstcb entry */
1817 if (cb_OldToNew(state, fe->firstcb, &fe->firstcb)) {
1824 /* restore indices in the CallBack structures */
1825 for (i = 1; i < state->cb_map.len; i++) {
1826 if (state->cb_map.entries[i].new_idx) {
1827 cb = itocb(state->cb_map.entries[i].new_idx);
1829 /* restore the cb->cnext entry */
1830 if (cb_OldToNew(state, cb->cnext, &cb->cnext)) {
1835 /* restore the cb->fhead entry */
1836 if (fe_OldToNew(state, cb->fhead, &cb->fhead)) {
1841 /* restore the cb->hhead entry */
1842 if (h_OldToNew(state, cb->hhead, &cb->hhead)) {
1847 /* restore the cb->tprev entry */
1848 if (cb_OldToNew(state, cb->tprev, &cb->tprev)) {
1853 /* restore the cb->tnext entry */
1854 if (cb_OldToNew(state, cb->tnext, &cb->tnext)) {
1859 /* restore the cb->hprev entry */
1860 if (cb_OldToNew(state, cb->hprev, &cb->hprev)) {
1865 /* restore the cb->hnext entry */
1866 if (cb_OldToNew(state, cb->hnext, &cb->hnext)) {
1873 /* restore the timeout queue head indices */
1874 for (i = 0; i < state->cb_timeout_hdr->records; i++) {
1875 if (cb_OldToNew(state, timeout[i], &timeout[i])) {
1881 /* restore the FE hash table queue heads */
1882 for (i = 0; i < state->cb_fehash_hdr->records; i++) {
1883 if (fe_OldToNew(state, HashTable[i], &HashTable[i])) {
1894 cb_stateVerify(struct fs_dump_state * state)
1898 if (cb_stateVerifyFEHash(state)) {
1902 if (cb_stateVerifyTimeoutQueues(state)) {
1910 cb_stateVerifyFEHash(struct fs_dump_state * state)
1913 struct FileEntry * fe;
1914 afs_uint32 fei, chain_len;
1916 for (i = 0; i < FEHASH_SIZE; i++) {
1918 for (fei = HashTable[i], fe = itofe(fei);
1920 fei = fe->fnext, fe = itofe(fei)) {
1921 if (fei > cbstuff.nblks) {
1922 ViceLog(0, ("cb_stateVerifyFEHash: error: index out of range (fei=%d)\n", fei));
1926 if (cb_stateVerifyFE(state, fe)) {
1929 if (chain_len > FS_STATE_FE_MAX_HASH_CHAIN_LEN) {
1930 ViceLog(0, ("cb_stateVerifyFEHash: error: hash chain %d length exceeds %d; assuming there's a loop\n",
1931 i, FS_STATE_FE_MAX_HASH_CHAIN_LEN));
1943 cb_stateVerifyFE(struct fs_dump_state * state, struct FileEntry * fe)
1947 if ((fe->firstcb && !fe->ncbs) ||
1948 (!fe->firstcb && fe->ncbs)) {
1949 ViceLog(0, ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%lu, fe->firstcb=%lu, fe->ncbs=%lu)\n",
1950 afs_printable_uint32_lu(fetoi(fe)),
1951 afs_printable_uint32_lu(fe->firstcb),
1952 afs_printable_uint32_lu(fe->ncbs)));
1955 if (cb_stateVerifyFCBList(state, fe)) {
1956 ViceLog(0, ("cb_stateVerifyFE: error: FCBList failed verification (fei=%lu)\n",
1957 afs_printable_uint32_lu(fetoi(fe))));
1965 cb_stateVerifyFCBList(struct fs_dump_state * state, struct FileEntry * fe)
1968 afs_uint32 cbi, fei, chain_len = 0;
1969 struct CallBack * cb;
1973 for (cbi = fe->firstcb, cb = itocb(cbi);
1975 cbi = cb->cnext, cb = itocb(cbi)) {
1976 if (cbi > cbstuff.nblks) {
1977 ViceLog(0, ("cb_stateVerifyFCBList: error: list index out of range (cbi=%d, ncbs=%d)\n",
1978 cbi, cbstuff.nblks));
1982 if (cb->fhead != fei) {
1983 ViceLog(0, ("cb_stateVerifyFCBList: error: cb->fhead != fei (fei=%d, cb->fhead=%d)\n",
1987 if (chain_len > FS_STATE_FCB_MAX_LIST_LEN) {
1988 ViceLog(0, ("cb_stateVerifyFCBList: error: list length exceeds %d (fei=%d); assuming there's a loop\n",
1989 FS_STATE_FCB_MAX_LIST_LEN, fei));
1996 if (fe->ncbs != chain_len) {
1997 ViceLog(0, ("cb_stateVerifyFCBList: error: list length mismatch (len=%d, fe->ncbs=%d)\n",
1998 chain_len, fe->ncbs));
2007 cb_stateVerifyHCBList(struct fs_dump_state * state, struct host * host)
2010 afs_uint32 hi, chain_len, cbi;
2011 struct CallBack *cb, *ncb;
2016 for (cbi = host->cblist, cb = itocb(cbi);
2018 cbi = cb->hnext, cb = ncb) {
2019 if (chain_len && (host->cblist == cbi)) {
2020 /* we've wrapped around the circular list, and everything looks ok */
2023 if (cb->hhead != hi) {
2024 ViceLog(0, ("cb_stateVerifyHCBList: error: incorrect cb->hhead (cbi=%d, h->index=%d, cb->hhead=%d)\n",
2025 cbi, hi, cb->hhead));
2028 if (!cb->hprev || !cb->hnext) {
2029 ViceLog(0, ("cb_stateVerifyHCBList: error: null index in circular list (cbi=%d, h->index=%d)\n",
2034 if ((cb->hprev > cbstuff.nblks) ||
2035 (cb->hnext > cbstuff.nblks)) {
2036 ViceLog(0, ("cb_stateVerifyHCBList: error: list index out of range (cbi=%d, h->index=%d, cb->hprev=%d, cb->hnext=%d, nCBs=%d)\n",
2037 cbi, hi, cb->hprev, cb->hnext, cbstuff.nblks));
2041 ncb = itocb(cb->hnext);
2042 if (cbi != ncb->hprev) {
2043 ViceLog(0, ("cb_stateVerifyHCBList: error: corrupt linked list (cbi=%d, h->index=%d)\n",
2048 if (chain_len > FS_STATE_HCB_MAX_LIST_LEN) {
2049 ViceLog(0, ("cb_stateVerifyFCBList: error: list length exceeds %d (h->index=%d); assuming there's a loop\n",
2050 FS_STATE_HCB_MAX_LIST_LEN, hi));
2062 cb_stateVerifyTimeoutQueues(struct fs_dump_state * state)
2065 afs_uint32 cbi, chain_len;
2066 struct CallBack *cb, *ncb;
2068 for (i = 0; i < CB_NUM_TIMEOUT_QUEUES; i++) {
2070 for (cbi = timeout[i], cb = itocb(cbi);
2072 cbi = cb->tnext, cb = ncb) {
2073 if (chain_len && (cbi == timeout[i])) {
2074 /* we've wrapped around the circular list, and everything looks ok */
2077 if (cbi > cbstuff.nblks) {
2078 ViceLog(0, ("cb_stateVerifyTimeoutQueues: error: list index out of range (cbi=%d, tindex=%d)\n",
2083 if (itot(cb->thead) != &timeout[i]) {
2084 ViceLog(0, ("cb_stateVerifyTimeoutQueues: error: cb->thead points to wrong timeout queue (tindex=%d, cbi=%d, cb->thead=%d)\n",
2085 i, cbi, cb->thead));
2088 if (!cb->tprev || !cb->tnext) {
2089 ViceLog(0, ("cb_stateVerifyTimeoutQueues: null index in circular list (cbi=%d, tindex=%d)\n",
2094 if ((cb->tprev > cbstuff.nblks) ||
2095 (cb->tnext > cbstuff.nblks)) {
2096 ViceLog(0, ("cb_stateVerifyTimeoutQueues: list index out of range (cbi=%d, tindex=%d, cb->tprev=%d, cb->tnext=%d, nCBs=%d)\n",
2097 cbi, i, cb->tprev, cb->tnext, cbstuff.nblks));
2101 ncb = itocb(cb->tnext);
2102 if (cbi != ncb->tprev) {
2103 ViceLog(0, ("cb_stateVerifyTimeoutQueues: corrupt linked list (cbi=%d, tindex=%d)\n",
2108 if (chain_len > FS_STATE_TCB_MAX_LIST_LEN) {
2109 ViceLog(0, ("cb_stateVerifyTimeoutQueues: list length exceeds %d (tindex=%d); assuming there's a loop\n",
2110 FS_STATE_TCB_MAX_LIST_LEN, i));
2122 cb_stateSaveTimeouts(struct fs_dump_state * state)
2125 struct iovec iov[2];
2127 AssignInt64(state->eof_offset, &state->cb_hdr->timeout_offset);
2129 memset(state->cb_timeout_hdr, 0, sizeof(struct callback_state_fehash_header));
2130 state->cb_timeout_hdr->magic = CALLBACK_STATE_TIMEOUT_MAGIC;
2131 state->cb_timeout_hdr->records = CB_NUM_TIMEOUT_QUEUES;
2132 state->cb_timeout_hdr->len = sizeof(struct callback_state_timeout_header) +
2133 (state->cb_timeout_hdr->records * sizeof(afs_uint32));
2135 iov[0].iov_base = (char *)state->cb_timeout_hdr;
2136 iov[0].iov_len = sizeof(struct callback_state_timeout_header);
2137 iov[1].iov_base = (char *)timeout;
2138 iov[1].iov_len = sizeof(timeout);
2140 if (fs_stateSeek(state, &state->cb_hdr->timeout_offset)) {
2145 if (fs_stateWriteV(state, iov, 2)) {
2150 fs_stateIncEOF(state, state->cb_timeout_hdr->len);
2157 cb_stateRestoreTimeouts(struct fs_dump_state * state)
2161 if (fs_stateReadHeader(state, &state->cb_hdr->timeout_offset,
2162 state->cb_timeout_hdr,
2163 sizeof(struct callback_state_timeout_header))) {
2168 if (state->cb_timeout_hdr->magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
2172 if (state->cb_timeout_hdr->records != CB_NUM_TIMEOUT_QUEUES) {
2177 len = state->cb_timeout_hdr->records * sizeof(afs_uint32);
2179 if (state->cb_timeout_hdr->len !=
2180 (sizeof(struct callback_state_timeout_header) + len)) {
2185 if (fs_stateRead(state, timeout, len)) {
2195 cb_stateSaveFEHash(struct fs_dump_state * state)
2198 struct iovec iov[2];
2200 AssignInt64(state->eof_offset, &state->cb_hdr->fehash_offset);
2202 memset(state->cb_fehash_hdr, 0, sizeof(struct callback_state_fehash_header));
2203 state->cb_fehash_hdr->magic = CALLBACK_STATE_FEHASH_MAGIC;
2204 state->cb_fehash_hdr->records = FEHASH_SIZE;
2205 state->cb_fehash_hdr->len = sizeof(struct callback_state_fehash_header) +
2206 (state->cb_fehash_hdr->records * sizeof(afs_uint32));
2208 iov[0].iov_base = (char *)state->cb_fehash_hdr;
2209 iov[0].iov_len = sizeof(struct callback_state_fehash_header);
2210 iov[1].iov_base = (char *)HashTable;
2211 iov[1].iov_len = sizeof(HashTable);
2213 if (fs_stateSeek(state, &state->cb_hdr->fehash_offset)) {
2218 if (fs_stateWriteV(state, iov, 2)) {
2223 fs_stateIncEOF(state, state->cb_fehash_hdr->len);
2230 cb_stateRestoreFEHash(struct fs_dump_state * state)
2234 if (fs_stateReadHeader(state, &state->cb_hdr->fehash_offset,
2235 state->cb_fehash_hdr,
2236 sizeof(struct callback_state_fehash_header))) {
2241 if (state->cb_fehash_hdr->magic != CALLBACK_STATE_FEHASH_MAGIC) {
2245 if (state->cb_fehash_hdr->records != FEHASH_SIZE) {
2250 len = state->cb_fehash_hdr->records * sizeof(afs_uint32);
2252 if (state->cb_fehash_hdr->len !=
2253 (sizeof(struct callback_state_fehash_header) + len)) {
2258 if (fs_stateRead(state, HashTable, len)) {
2268 cb_stateSaveFEs(struct fs_dump_state * state)
2272 struct FileEntry *fe;
2274 AssignInt64(state->eof_offset, &state->cb_hdr->fe_offset);
2276 for (hash = 0; hash < FEHASH_SIZE ; hash++) {
2277 for (fei = HashTable[hash]; fei; fei = fe->fnext) {
2279 if (cb_stateSaveFE(state, fe)) {
2291 cb_stateRestoreFEs(struct fs_dump_state * state)
2293 int count, nFEs, ret = 0;
2295 nFEs = state->cb_hdr->nFEs;
2297 for (count = 0; count < nFEs; count++) {
2298 if (cb_stateRestoreFE(state)) {
2309 cb_stateSaveFE(struct fs_dump_state * state, struct FileEntry * fe)
2311 int ret = 0, iovcnt, cbi, written = 0;
2313 struct callback_state_entry_header hdr;
2314 struct FEDiskEntry fedsk;
2315 struct CBDiskEntry cbdsk[16];
2316 struct iovec iov[16];
2317 struct CallBack *cb;
2320 if (fei > state->cb_hdr->fe_max) {
2321 state->cb_hdr->fe_max = fei;
2324 memset(&hdr, 0, sizeof(struct callback_state_entry_header));
2326 if (cb_stateFEToDiskEntry(fe, &fedsk)) {
2331 iov[0].iov_base = (char *)&hdr;
2332 iov[0].iov_len = sizeof(hdr);
2333 iov[1].iov_base = (char *)&fedsk;
2334 iov[1].iov_len = sizeof(struct FEDiskEntry);
2337 for (cbi = fe->firstcb, cb = itocb(cbi);
2339 cbi = cb->cnext, cb = itocb(cbi), hdr.nCBs++) {
2340 if (cbi > state->cb_hdr->cb_max) {
2341 state->cb_hdr->cb_max = cbi;
2343 if (cb_stateCBToDiskEntry(cb, &cbdsk[iovcnt])) {
2347 cbdsk[iovcnt].index = cbi;
2348 iov[iovcnt].iov_base = (char *)&cbdsk[iovcnt];
2349 iov[iovcnt].iov_len = sizeof(struct CBDiskEntry);
2351 if ((iovcnt == 16) || (!cb->cnext)) {
2352 if (fs_stateWriteV(state, iov, iovcnt)) {
2361 hdr.magic = CALLBACK_STATE_ENTRY_MAGIC;
2362 hdr.len = sizeof(hdr) + sizeof(struct FEDiskEntry) +
2363 (hdr.nCBs * sizeof(struct CBDiskEntry));
2366 if (fs_stateWriteV(state, iov, iovcnt)) {
2371 if (fs_stateWriteHeader(state, &state->eof_offset, &hdr, sizeof(hdr))) {
2377 fs_stateIncEOF(state, hdr.len);
2380 if (fs_stateSeek(state, &state->eof_offset)) {
2386 state->cb_hdr->nFEs++;
2387 state->cb_hdr->nCBs += hdr.nCBs;
2394 cb_stateRestoreFE(struct fs_dump_state * state)
2396 int ret = 0, iovcnt, nCBs;
2397 struct callback_state_entry_header hdr;
2398 struct FEDiskEntry fedsk;
2399 struct CBDiskEntry cbdsk[16];
2400 struct iovec iov[16];
2401 struct FileEntry * fe;
2403 iov[0].iov_base = (char *)&hdr;
2404 iov[0].iov_len = sizeof(hdr);
2405 iov[1].iov_base = (char *)&fedsk;
2406 iov[1].iov_len = sizeof(fedsk);
2409 if (fs_stateReadV(state, iov, iovcnt)) {
2414 if (hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
2421 ViceLog(0, ("cb_stateRestoreFE: ran out of free FileEntry structures\n"));
2426 if (cb_stateDiskEntryToFE(state, &fedsk, fe)) {
2432 for (iovcnt = 0, nCBs = 0;
2435 iov[iovcnt].iov_base = (char *)&cbdsk[iovcnt];
2436 iov[iovcnt].iov_len = sizeof(struct CBDiskEntry);
2438 if ((iovcnt == 16) || (nCBs == hdr.nCBs - 1)) {
2439 if (fs_stateReadV(state, iov, iovcnt)) {
2443 if (cb_stateRestoreCBs(state, fe, iov, iovcnt)) {
2457 cb_stateRestoreCBs(struct fs_dump_state * state, struct FileEntry * fe,
2458 struct iovec * iov, int niovecs)
2461 struct CallBack * cb;
2462 struct CBDiskEntry * cbdsk;
2464 for (idx = 0; idx < niovecs; idx++) {
2465 cbdsk = (struct CBDiskEntry *) iov[idx].iov_base;
2466 if ((cb = GetCB()) == NULL) {
2467 ViceLog(0, ("cb_stateRestoreCBs: ran out of free CallBack structures\n"));
2471 if (cb_stateDiskEntryToCB(state, cbdsk, cb)) {
2472 ViceLog(0, ("cb_stateRestoreCBs: corrupt CallBack disk entry\n"));
2484 cb_stateFillHeader(struct callback_state_header * hdr)
2486 hdr->stamp.magic = CALLBACK_STATE_MAGIC;
2487 hdr->stamp.version = CALLBACK_STATE_VERSION;
2488 hdr->tfirst = tfirst;
2493 cb_stateCheckHeader(struct callback_state_header * hdr)
2497 if (hdr->stamp.magic != CALLBACK_STATE_MAGIC) {
2499 } else if (hdr->stamp.version != CALLBACK_STATE_VERSION) {
2501 } else if ((hdr->nFEs > cbstuff.nblks) || (hdr->nCBs > cbstuff.nblks)) {
2502 ViceLog(0, ("cb_stateCheckHeader: saved callback state larger than callback memory allocation\n"));
2508 /* disk entry conversion routines */
2510 cb_stateFEToDiskEntry(struct FileEntry * in, struct FEDiskEntry * out)
2512 memcpy(&out->fe, in, sizeof(struct FileEntry));
2513 out->index = fetoi(in);
2518 cb_stateDiskEntryToFE(struct fs_dump_state * state,
2519 struct FEDiskEntry * in, struct FileEntry * out)
2523 memcpy(out, &in->fe, sizeof(struct FileEntry));
2525 /* setup FE map entry */
2526 if (!in->index || (in->index >= state->fe_map.len)) {
2527 ViceLog(0, ("cb_stateDiskEntryToFE: index (%d) out of range",
2532 state->fe_map.entries[in->index].old_idx = in->index;
2533 state->fe_map.entries[in->index].new_idx = fetoi(out);
2540 cb_stateCBToDiskEntry(struct CallBack * in, struct CBDiskEntry * out)
2542 memcpy(&out->cb, in, sizeof(struct CallBack));
2543 out->index = cbtoi(in);
2548 cb_stateDiskEntryToCB(struct fs_dump_state * state,
2549 struct CBDiskEntry * in, struct CallBack * out)
2553 memcpy(out, &in->cb, sizeof(struct CallBack));
2555 /* setup CB map entry */
2556 if (!in->index || (in->index >= state->cb_map.len)) {
2557 ViceLog(0, ("cb_stateDiskEntryToCB: index (%d) out of range\n",
2562 state->cb_map.entries[in->index].old_idx = in->index;
2563 state->cb_map.entries[in->index].new_idx = cbtoi(out);
2569 /* index map routines */
2571 cb_stateAllocMap(struct fs_dump_state * state)
2573 state->fe_map.len = state->cb_hdr->fe_max + 1;
2574 state->cb_map.len = state->cb_hdr->cb_max + 1;
2575 state->fe_map.entries = (struct idx_map_entry_t *)
2576 calloc(state->fe_map.len, sizeof(struct idx_map_entry_t));
2577 state->cb_map.entries = (struct idx_map_entry_t *)
2578 calloc(state->cb_map.len, sizeof(struct idx_map_entry_t));
2579 return ((state->fe_map.entries != NULL) && (state->cb_map.entries != NULL)) ? 0 : 1;
2583 fe_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new)
2587 /* FEs use a one-based indexing system, so old==0 implies no mapping */
2593 if (old >= state->fe_map.len) {
2594 ViceLog(0, ("fe_OldToNew: index %d is out of range\n", old));
2596 } else if (state->fe_map.entries[old].old_idx != old) { /* sanity check */
2597 ViceLog(0, ("fe_OldToNew: index %d points to an invalid FileEntry record\n", old));
2600 *new = state->fe_map.entries[old].new_idx;
2608 cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new)
2612 /* CBs use a one-based indexing system, so old==0 implies no mapping */
2618 if (old >= state->cb_map.len) {
2619 ViceLog(0, ("cb_OldToNew: index %d is out of range\n", old));
2621 } else if (state->cb_map.entries[old].old_idx != old) { /* sanity check */
2622 ViceLog(0, ("cb_OldToNew: index %d points to an invalid CallBack record\n", old));
2625 *new = state->cb_map.entries[old].new_idx;
2631 #endif /* AFS_DEMAND_ATTACH_FS */
2634 DumpCallBackState_r(void)
2637 afs_uint32 magic = MAGICV2, now = (afs_int32) FT_ApproxTime(), freelisthead;
2639 oflag = O_WRONLY | O_CREAT | O_TRUNC;
2643 fd = open(AFSDIR_SERVER_CBKDUMP_FILEPATH, oflag, 0666);
2646 ("Couldn't create callback dump file %s\n",
2647 AFSDIR_SERVER_CBKDUMP_FILEPATH));
2650 (void)write(fd, &magic, sizeof(magic));
2651 (void)write(fd, &now, sizeof(now));
2652 (void)write(fd, &cbstuff, sizeof(cbstuff));
2653 (void)write(fd, TimeOuts, sizeof(TimeOuts));
2654 (void)write(fd, timeout, sizeof(timeout));
2655 (void)write(fd, &tfirst, sizeof(tfirst));
2656 freelisthead = cbtoi((struct CallBack *)CBfree);
2657 (void)write(fd, &freelisthead, sizeof(freelisthead)); /* This is a pointer */
2658 freelisthead = fetoi((struct FileEntry *)FEfree);
2659 (void)write(fd, &freelisthead, sizeof(freelisthead)); /* This is a pointer */
2660 (void)write(fd, HashTable, sizeof(HashTable));
2661 (void)write(fd, &CB[1], sizeof(CB[1]) * cbstuff.nblks); /* CB stuff */
2662 (void)write(fd, &FE[1], sizeof(FE[1]) * cbstuff.nblks); /* FE stuff */
2669 DumpCallBackState(void) {
2673 rc = DumpCallBackState_r();
2679 #endif /* !INTERPRET_DUMP */
2681 #ifdef INTERPRET_DUMP
2683 /* This is only compiled in for the callback analyzer program */
2684 /* Returns the time of the dump */
2686 ReadDump(char *file, int timebits)
2689 afs_uint32 magic, freelisthead;
2697 fd = open(file, oflag);
2699 fprintf(stderr, "Couldn't read dump file %s\n", file);
2702 read(fd, &magic, sizeof(magic));
2703 if (magic == MAGICV2) {
2706 if (magic != MAGIC) {
2708 "Magic number of %s is invalid. You might be trying to\n",
2711 "run this program on a machine type with a different byte ordering.\n");
2715 if (timebits == 64) {
2716 read(fd, &now64, sizeof(afs_int64));
2717 now = (afs_int32) now64;
2719 read(fd, &now, sizeof(afs_int32));
2721 read(fd, &cbstuff, sizeof(cbstuff));
2722 read(fd, TimeOuts, sizeof(TimeOuts));
2723 read(fd, timeout, sizeof(timeout));
2724 read(fd, &tfirst, sizeof(tfirst));
2725 read(fd, &freelisthead, sizeof(freelisthead));
2726 CB = ((struct CallBack
2727 *)(calloc(cbstuff.nblks, sizeof(struct CallBack)))) - 1;
2728 FE = ((struct FileEntry
2729 *)(calloc(cbstuff.nblks, sizeof(struct FileEntry)))) - 1;
2730 CBfree = (struct CallBack *)itocb(freelisthead);
2731 read(fd, &freelisthead, sizeof(freelisthead));
2732 FEfree = (struct FileEntry *)itofe(freelisthead);
2733 read(fd, HashTable, sizeof(HashTable));
2734 read(fd, &CB[1], sizeof(CB[1]) * cbstuff.nblks); /* CB stuff */
2735 read(fd, &FE[1], sizeof(FE[1]) * cbstuff.nblks); /* FE stuff */
2737 perror("Error reading dumpfile");
2744 #include "AFS_component_version_number.h"
2746 #include "AFS_component_version_number.c"
2749 static afs_uint32 *cbTrack;
2752 main(int argc, char **argv)
2754 int err = 0, cbi = 0, stats = 0, noptions = 0, all = 0, vol = 0, raw = 0;
2756 struct FileEntry *fe;
2757 struct CallBack *cb;
2761 memset(&fid, 0, sizeof(fid));
2764 while (argc && **argv == '-') {
2767 if (!strcmp(*argv, "-host")) {
2773 cbi = atoi(*++argv);
2774 } else if (!strcmp(*argv, "-fid")) {
2780 fid.Volume = atoi(*++argv);
2781 fid.Vnode = atoi(*++argv);
2782 fid.Unique = atoi(*++argv);
2783 } else if (!strcmp(*argv, "-time")) {
2784 fprintf(stderr, "-time not supported\n");
2786 } else if (!strcmp(*argv, "-stats")) {
2788 } else if (!strcmp(*argv, "-all")) {
2790 } else if (!strcmp(*argv, "-raw")) {
2792 } else if (!strcmp(*argv, "-timebits")) {
2798 timebits = atoi(*++argv);
2799 if ((timebits != 32)
2803 } else if (!strcmp(*argv, "-volume")) {
2809 vol = atoi(*++argv);
2814 if (err || argc != 1) {
2816 "Usage: cbd [-host cbid] [-fid volume vnode] [-stats] [-all] [-timebits 32"
2818 "] callbackdumpfile\n");
2820 "[cbid is shown for each host in the hosts.dump file]\n");
2823 now = ReadDump(*argv, timebits);
2824 if (stats || noptions == 0) {
2825 time_t uxtfirst = UXtime(tfirst), tnow = now;
2826 printf("The time of the dump was %u %s", (unsigned int) now, ctime(&tnow));
2827 printf("The last time cleanup ran was %u %s", (unsigned int) uxtfirst,
2829 PrintCallBackStats();
2832 cbTrack = calloc(cbstuff.nblks, sizeof(cbTrack[0]));
2837 struct CallBack *cb;
2838 struct FileEntry *fe;
2840 for (hash = 0; hash < FEHASH_SIZE; hash++) {
2841 for (feip = &HashTable[hash]; (fe = itofe(*feip));) {
2842 if (!vol || (fe->volid == vol)) {
2843 afs_uint32 fe_i = fetoi(fe);
2845 for (cb = itocb(fe->firstcb); cb; cb = itocb(cb->cnext)) {
2846 afs_uint32 cb_i = cbtoi(cb);
2848 if (cb_i > cbstuff.nblks) {
2849 printf("CB index out of range (%u > %d), stopped for this FE\n",
2850 cb_i, cbstuff.nblks);
2854 if (cbTrack[cb_i]) {
2855 printf("CB entry already claimed for FE[%u] (this is FE[%u]), stopped\n",
2856 cbTrack[cb_i], fe_i);
2859 cbTrack[cb_i] = fe_i;
2871 afs_uint32 cfirst = cbi;
2876 } while (cbi != cfirst);
2881 printf("No callback entries for %u.%u\n", fid.Volume, fid.Vnode);
2884 cb = itocb(fe->firstcb);
2887 cb = itocb(cb->cnext);
2892 for (i = 1; i < cbstuff.nblks; i++) {
2893 p = (afs_int32 *) & FE[i];
2894 printf("%d:%12x%12x%12x%12x\n", i, p[0], p[1], p[2], p[3]);
2903 PrintCB(struct CallBack *cb, afs_uint32 now)
2905 struct FileEntry *fe = itofe(cb->fhead);
2906 time_t expires = TIndexToTime(cb->thead);
2911 printf("vol=%u vn=%u cbs=%d hi=%d st=%d fest=%d, exp in %lu secs at %s",
2912 fe->volid, fe->vnode, fe->ncbs, cb->hhead, cb->status, fe->status,
2913 expires - now, ctime(&expires));
2918 #if !defined(INTERPRET_DUMP)
2920 ** try breaking calbacks on afidp from host. Use multi_rx.
2921 ** return 0 on success, non-zero on failure
2924 MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp)
2928 retVal = MultiBreakCallBackAlternateAddress_r(host, afidp);
2934 MultiBreakCallBackAlternateAddress_r(struct host *host,
2935 struct AFSCBFids *afidp)
2938 struct rx_connection **conns;
2939 struct rx_connection *connSuccess = 0;
2940 struct AddrPort *interfaces;
2941 static struct rx_securityClass *sc = 0;
2942 static struct AFSCBs tc = { 0, 0 };
2945 /* nothing more can be done */
2946 if (!host->interface)
2947 return 1; /* failure */
2949 /* the only address is the primary interface */
2950 if (host->interface->numberOfInterfaces <= 1)
2951 return 1; /* failure */
2953 /* initialise a security object only once */
2955 sc = rxnull_NewClientSecurityObject();
2957 i = host->interface->numberOfInterfaces;
2958 interfaces = calloc(i, sizeof(struct AddrPort));
2959 conns = calloc(i, sizeof(struct rx_connection *));
2960 if (!interfaces || !conns) {
2962 ("Failed malloc in MultiBreakCallBackAlternateAddress_r\n"));
2966 /* initialize alternate rx connections */
2967 for (i = 0, j = 0; i < host->interface->numberOfInterfaces; i++) {
2968 /* this is the current primary address */
2969 if (host->host == host->interface->interface[i].addr &&
2970 host->port == host->interface->interface[i].port)
2973 interfaces[j] = host->interface->interface[i];
2975 rx_NewConnection(interfaces[j].addr,
2976 interfaces[j].port, 1, sc, 0);
2977 rx_SetConnDeadTime(conns[j], 2);
2978 rx_SetConnHardDeadTime(conns[j], AFS_HARDDEADTIME);
2982 assert(j); /* at least one alternate address */
2984 ("Starting multibreakcall back on all addr for host %p (%s:%d)\n",
2985 host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
2987 multi_Rx(conns, j) {
2988 multi_RXAFSCB_CallBack(afidp, &tc);
2992 if (host->callback_rxcon)
2993 rx_DestroyConnection(host->callback_rxcon);
2994 host->callback_rxcon = conns[multi_i];
2995 h_DeleteHostFromAddrHashTable_r(host->host, host->port, host);
2996 host->host = interfaces[multi_i].addr;
2997 host->port = interfaces[multi_i].port;
2998 h_AddHostToAddrHashTable_r(host->host, host->port, host);
2999 connSuccess = conns[multi_i];
3000 rx_SetConnDeadTime(host->callback_rxcon, 50);
3001 rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
3003 ("multibreakcall success with addr %s:%d\n",
3004 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),
3005 ntohs(interfaces[multi_i].port)));
3012 /* Destroy all connections except the one on which we succeeded */
3013 for (i = 0; i < j; i++)
3014 if (conns[i] != connSuccess)
3015 rx_DestroyConnection(conns[i]);
3021 return 0; /* success */
3023 return 1; /* failure */
3028 ** try multi_RX probes to host.
3029 ** return 0 on success, non-0 on failure
3032 MultiProbeAlternateAddress_r(struct host *host)
3035 struct rx_connection **conns;
3036 struct rx_connection *connSuccess = 0;
3037 struct AddrPort *interfaces;
3038 static struct rx_securityClass *sc = 0;
3041 /* nothing more can be done */
3042 if (!host->interface)
3043 return 1; /* failure */
3045 /* the only address is the primary interface */
3046 if (host->interface->numberOfInterfaces <= 1)
3047 return 1; /* failure */
3049 /* initialise a security object only once */
3051 sc = rxnull_NewClientSecurityObject();
3053 i = host->interface->numberOfInterfaces;
3054 interfaces = calloc(i, sizeof(struct AddrPort));
3055 conns = calloc(i, sizeof(struct rx_connection *));
3056 if (!interfaces || !conns) {
3057 ViceLog(0, ("Failed malloc in MultiProbeAlternateAddress_r\n"));
3061 /* initialize alternate rx connections */
3062 for (i = 0, j = 0; i < host->interface->numberOfInterfaces; i++) {
3063 /* this is the current primary address */
3064 if (host->host == host->interface->interface[i].addr &&
3065 host->port == host->interface->interface[i].port)
3068 interfaces[j] = host->interface->interface[i];
3070 rx_NewConnection(interfaces[j].addr,
3071 interfaces[j].port, 1, sc, 0);
3072 rx_SetConnDeadTime(conns[j], 2);
3073 rx_SetConnHardDeadTime(conns[j], AFS_HARDDEADTIME);
3077 assert(j); /* at least one alternate address */
3079 ("Starting multiprobe on all addr for host %p (%s:%d)\n",
3080 host, afs_inet_ntoa_r(host->host, hoststr),
3081 ntohs(host->port)));
3083 multi_Rx(conns, j) {
3084 multi_RXAFSCB_ProbeUuid(&host->interface->uuid);
3088 if (host->callback_rxcon)
3089 rx_DestroyConnection(host->callback_rxcon);
3090 host->callback_rxcon = conns[multi_i];
3091 h_DeleteHostFromAddrHashTable_r(host->host, host->port, host);
3092 host->host = interfaces[multi_i].addr;
3093 host->port = interfaces[multi_i].port;
3094 h_AddHostToAddrHashTable_r(host->host, host->port, host);
3095 connSuccess = conns[multi_i];
3096 rx_SetConnDeadTime(host->callback_rxcon, 50);
3097 rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
3099 ("multiprobe success with addr %s:%d\n",
3100 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),
3101 ntohs(interfaces[multi_i].port)));
3106 ("multiprobe failure with addr %s:%d\n",
3107 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),
3108 ntohs(interfaces[multi_i].port)));
3110 /* This is less than desirable but its the best we can do.
3111 * The AFS Cache Manager will return either 0 for a Uuid
3112 * match and a 1 for a non-match. If the error is 1 we
3113 * therefore know that our mapping of IP address to Uuid
3114 * is wrong. We should attempt to find the correct
3115 * Uuid and fix the host tables.
3117 if (multi_error == 1) {
3118 /* remove the current alternate address from this host */
3120 removeInterfaceAddr_r(host, interfaces[multi_i].addr, interfaces[multi_i].port);
3124 #ifdef AFS_DEMAND_ATTACH_FS
3125 /* try to bail ASAP if the fileserver is shutting down */
3127 if (fs_state.mode == FS_MODE_SHUTDOWN) {
3136 /* Destroy all connections except the one on which we succeeded */
3137 for (i = 0; i < j; i++)
3138 if (conns[i] != connSuccess)
3139 rx_DestroyConnection(conns[i]);
3145 return 0; /* success */
3147 return 1; /* failure */
3150 #endif /* !defined(INTERPRET_DUMP) */