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 * BreakVolumeCallBacks(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>
91 #include <stdlib.h> /* for malloc() */
92 #include <time.h> /* ANSI standard location for time stuff */
101 #include <afs/assert.h>
103 #include <afs/stds.h>
105 #include <afs/nfs.h> /* yuck. This is an abomination. */
108 #include <afscbint.h>
109 #include <afs/afsutil.h>
111 #include <afs/ihandle.h>
112 #include <afs/vnode.h>
113 #include <afs/volume.h>
114 #include "viced_prototypes.h"
117 #include <afs/ptclient.h> /* need definition of prlist for host.h */
119 #include "callback.h"
120 #ifdef AFS_DEMAND_ATTACH_FS
121 #include "../tviced/serialize_state.h"
122 #endif /* AFS_DEMAND_ATTACH_FS */
125 extern afsUUID FS_HostUUID;
126 extern int hostCount;
127 static int ShowProblems = 1;
129 struct cbcounters cbstuff;
131 static struct FileEntry * FE = NULL; /* don't use FE[0] */
132 static struct CallBack * CB = NULL; /* don't use CB[0] */
134 static struct CallBack * CBfree = NULL;
135 static struct FileEntry * FEfree = NULL;
138 /* Time to live for call backs depends upon number of users of the file.
139 * TimeOuts is indexed by this number/8 (using TimeOut macro). Times
140 * in this table are for the workstation; server timeouts, add
143 static int TimeOuts[] = {
144 /* Note: don't make the first entry larger than 4 hours (see above) */
145 4 * 60 * 60, /* 0-7 users */
146 1 * 60 * 60, /* 8-15 users */
147 30 * 60, /* 16-23 users */
148 15 * 60, /* 24-31 users */
149 15 * 60, /* 32-39 users */
150 10 * 60, /* 40-47 users */
151 10 * 60, /* 48-55 users */
152 10 * 60, /* 56-63 users */
153 }; /* Anything more: MinTimeOut */
155 /* minimum time given for a call back */
156 static int MinTimeOut = (7 * 60);
158 /* Heads of CB queues; a timeout index is 1+index into this array */
159 static afs_uint32 timeout[CB_NUM_TIMEOUT_QUEUES];
161 static afs_int32 tfirst; /* cbtime of oldest unexpired call back time queue */
164 /* 16 byte object get/free routines */
169 /* Prototypes for static routines */
170 static struct FileEntry *FindFE(register AFSFid * fid);
171 static struct CallBack *iGetCB(register int *nused);
172 static int iFreeCB(register struct CallBack *cb, register int *nused);
173 static struct FileEntry *iGetFE(register int *nused);
174 static int iFreeFE(register struct FileEntry *fe, register int *nused);
175 static int TAdd(register struct CallBack *cb, register afs_uint32 * thead);
176 static int TDel(register struct CallBack *cb);
177 static int HAdd(register struct CallBack *cb, register struct host *host);
178 static int HDel(register struct CallBack *cb);
179 static int CDel(struct CallBack *cb, int deletefe);
180 static int CDelPtr(register struct FileEntry *fe, register afs_uint32 * cbp,
182 static afs_uint32 *FindCBPtr(struct FileEntry *fe, struct host *host);
183 static int FDel(register struct FileEntry *fe);
184 static int AddCallBack1_r(struct host *host, AFSFid * fid, afs_uint32 * thead,
185 int type, int locked);
186 static void MultiBreakCallBack_r(struct cbstruct cba[], int ncbas,
187 struct AFSCBFids *afidp, struct host *xhost);
188 static int MultiBreakVolumeCallBack_r(struct host *host, int isheld,
189 struct VCBParams *parms, int deletefe);
190 static int MultiBreakVolumeCallBack(struct host *host, int isheld,
191 struct VCBParams *parms);
192 static int MultiBreakVolumeLaterCallBack(struct host *host, int isheld,
193 struct VCBParams *parms);
194 static int GetSomeSpace_r(struct host *hostp, int locked);
195 static int ClearHostCallbacks_r(struct host *hp, int locked);
197 #define GetCB() ((struct CallBack *)iGetCB(&cbstuff.nCBs))
198 #define GetFE() ((struct FileEntry *)iGetFE(&cbstuff.nFEs))
199 #define FreeCB(cb) iFreeCB((struct CallBack *)cb, &cbstuff.nCBs)
200 #define FreeFE(fe) iFreeFE((struct FileEntry *)fe, &cbstuff.nFEs)
203 /* Other protos - move out sometime */
204 void PrintCB(register struct CallBack *cb, afs_uint32 now);
206 static afs_uint32 HashTable[FEHASH_SIZE]; /* File entry hash table */
208 static struct FileEntry *
209 FindFE(register AFSFid * fid)
213 register struct FileEntry *fe;
215 hash = FEHash(fid->Volume, fid->Unique);
216 for (fei = HashTable[hash]; fei; fei = fe->fnext) {
218 if (fe->volid == fid->Volume && fe->unique == fid->Unique
219 && fe->vnode == fid->Vnode && (fe->status & FE_LATER) != FE_LATER)
225 #ifndef INTERPRET_DUMP
227 static struct CallBack *
228 iGetCB(register int *nused)
230 register struct CallBack *ret;
232 if ((ret = CBfree)) {
233 CBfree = (struct CallBack *)(((struct object *)ret)->next);
240 iFreeCB(register struct CallBack *cb, register int *nused)
242 ((struct object *)cb)->next = (struct object *)CBfree;
248 static struct FileEntry *
249 iGetFE(register int *nused)
251 register struct FileEntry *ret;
253 if ((ret = FEfree)) {
254 FEfree = (struct FileEntry *)(((struct object *)ret)->next);
261 iFreeFE(register struct FileEntry *fe, register int *nused)
263 ((struct object *)fe)->next = (struct object *)FEfree;
269 /* Add cb to end of specified timeout list */
271 TAdd(register struct CallBack *cb, register afs_uint32 * thead)
274 (*thead) = cb->tnext = cb->tprev = cbtoi(cb);
276 register struct CallBack *thp = itocb(*thead);
278 cb->tprev = thp->tprev;
282 thp->tprev = (itocb(thp->tprev)->tnext = cbtoi(cb));
284 thp->tprev = cbtoi(cb);
287 cb->thead = ttoi(thead);
291 /* Delete call back entry from timeout list */
293 TDel(register struct CallBack *cb)
295 register afs_uint32 *thead = itot(cb->thead);
297 if (*thead == cbtoi(cb))
298 *thead = (*thead == cb->tnext ? 0 : cb->tnext);
299 if (itocb(cb->tprev))
300 itocb(cb->tprev)->tnext = cb->tnext;
301 if (itocb(cb->tnext))
302 itocb(cb->tnext)->tprev = cb->tprev;
306 /* Add cb to end of specified host list */
308 HAdd(register struct CallBack *cb, register struct host *host)
310 cb->hhead = h_htoi(host);
312 host->cblist = cb->hnext = cb->hprev = cbtoi(cb);
314 register struct CallBack *fcb = itocb(host->cblist);
316 cb->hprev = fcb->hprev;
317 cb->hnext = cbtoi(fcb);
318 fcb->hprev = (itocb(fcb->hprev)->hnext = cbtoi(cb));
323 /* Delete call back entry from host list */
325 HDel(register struct CallBack *cb)
327 register afs_uint32 *hhead = &h_itoh(cb->hhead)->cblist;
329 if (*hhead == cbtoi(cb))
330 *hhead = (*hhead == cb->hnext ? 0 : cb->hnext);
331 itocb(cb->hprev)->hnext = cb->hnext;
332 itocb(cb->hnext)->hprev = cb->hprev;
336 /* Delete call back entry from fid's chain of cb's */
337 /* N.B. This one also deletes the CB, and also possibly parent FE, so
338 * make sure that it is not on any other list before calling this
341 CDel(struct CallBack *cb, int deletefe)
344 struct FileEntry *fe = itofe(cb->fhead);
345 register afs_uint32 *cbp;
348 for (safety = 0, cbp = &fe->firstcb; *cbp && *cbp != cbi;
349 cbp = &itocb(*cbp)->cnext, safety++) {
350 if (safety > cbstuff.nblks + 10) {
353 ("CDel: Internal Error -- shutting down: wanted %d from %d, now at %d\n",
354 cbi, fe->firstcb, *cbp));
356 ShutDownAndCore(PANIC);
359 CDelPtr(fe, cbp, deletefe);
363 /* Same as CDel, but pointer to parent pointer to CB entry is passed,
364 * as well as file entry */
365 /* N.B. This one also deletes the CB, and also possibly parent FE, so
366 * make sure that it is not on any other list before calling this
368 static int Ccdelpt = 0, CcdelB = 0;
371 CDelPtr(register struct FileEntry *fe, register afs_uint32 * cbp,
374 register struct CallBack *cb;
384 if (deletefe && (--fe->ncbs == 0))
390 FindCBPtr(struct FileEntry *fe, struct host *host)
392 register afs_uint32 hostindex = h_htoi(host);
393 register struct CallBack *cb;
394 register afs_uint32 *cbp;
397 for (safety = 0, cbp = &fe->firstcb; *cbp; cbp = &cb->cnext, safety++) {
398 if (safety > cbstuff.nblks) {
399 ViceLog(0, ("FindCBPtr: Internal Error -- shutting down.\n"));
401 ShutDownAndCore(PANIC);
404 if (cb->hhead == hostindex)
410 /* Delete file entry from hash table */
412 FDel(register struct FileEntry *fe)
414 register int fei = fetoi(fe);
415 register afs_uint32 *p = &HashTable[FEHash(fe->volid, fe->unique)];
417 while (*p && *p != fei)
418 p = &itofe(*p)->fnext;
425 /* initialize the callback package */
427 InitCallBack(int nblks)
430 tfirst = CBtime(FT_ApproxTime());
431 /* N.B. The "-1", below, is because
432 * FE[0] and CB[0] are not used--and not allocated */
433 FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry))));
435 ViceLog(0, ("Failed malloc in InitCallBack\n"));
438 FE--; /* FE[0] is supposed to point to junk */
439 cbstuff.nFEs = nblks;
441 FreeFE(&FE[cbstuff.nFEs]); /* This is correct */
442 CB = ((struct CallBack *)(calloc(nblks, sizeof(struct CallBack))));
444 ViceLog(0, ("Failed malloc in InitCallBack\n"));
447 CB--; /* CB[0] is supposed to point to junk */
448 cbstuff.nCBs = nblks;
450 FreeCB(&CB[cbstuff.nCBs]); /* This is correct */
451 cbstuff.nblks = nblks;
452 cbstuff.nbreakers = 0;
458 XCallBackBulk_r(struct host * ahost, struct AFSFid * fids, afs_int32 nfids)
460 struct AFSCallBack tcbs[AFSCBMAX];
466 struct rx_connection *cb_conn = NULL;
469 rx_SetConnDeadTime(ahost->callback_rxcon, 4);
470 rx_SetConnHardDeadTime(ahost->callback_rxcon, AFS_HARDDEADTIME);
477 for (i = 0; i < nfids && i < AFSCBMAX; i++) {
478 tcbs[i].CallBackVersion = CALLBACK_VERSION;
479 tcbs[i].ExpirationTime = 0;
480 tcbs[i].CallBackType = CB_DROPPED;
482 tf.AFSCBFids_len = i;
483 tf.AFSCBFids_val = &(fids[j]);
487 tc.AFSCBs_val = tcbs;
489 cb_conn = ahost->callback_rxcon;
490 rx_GetConnection(cb_conn);
492 code |= RXAFSCB_CallBack(cb_conn, &tf, &tc);
493 rx_PutConnection(cb_conn);
501 /* the locked flag tells us if the host entry has already been locked
502 * by our parent. I don't think anybody actually calls us with the
503 * host locked, but here's how to make that work: GetSomeSpace has to
504 * change so that it doesn't attempt to lock any hosts < "host". That
505 * means that it might be unable to free any objects, so it has to
506 * return an exit status. If it fails, then AddCallBack1 might fail,
507 * as well. If so, the host->ResetDone should probably be set to 0,
508 * and we probably don't want to return a callback promise to the
509 * cache manager, either. */
511 AddCallBack1(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
519 retVal = AddCallBack1_r(host, fid, thead, type, 1);
529 AddCallBack1_r(struct host *host, AFSFid * fid, afs_uint32 * thead, int type,
532 struct FileEntry *fe;
533 struct CallBack *cb = 0, *lastcb = 0;
534 struct FileEntry *newfe = 0;
536 afs_uint32 *Thead = thead;
537 struct CallBack *newcb = 0;
542 /* allocate these guys first, since we can't call the allocator with
543 * the host structure locked -- or we might deadlock. However, we have
544 * to avoid races with FindFE... */
545 while (!(newcb = GetCB())) {
546 GetSomeSpace_r(host, locked);
548 while (!(newfe = GetFE())) { /* Get it now, so we don't have to call */
549 /* GetSomeSpace with the host locked, later. This might turn out to */
550 /* have been unneccessary, but that's actually kind of unlikely, since */
551 /* most files are not shared. */
552 GetSomeSpace_r(host, locked);
556 h_Lock_r(host); /* this can yield, so do it before we get any */
561 if (type == CB_NORMAL) {
563 TimeCeiling(FT_ApproxTime() + TimeOut(fe ? fe->ncbs : 0) +
565 Thead = THead(CBtime(time_out));
566 } else if (type == CB_VOLUME) {
567 time_out = TimeCeiling((60 * 120 + FT_ApproxTime()) + ServerBias);
568 Thead = THead(CBtime(time_out));
569 } else if (type == CB_BULK) {
570 /* bulk status can get so many callbacks all at once, and most of them
571 * are probably not for things that will be used for long.
574 TimeCeiling(FT_ApproxTime() + ServerBias +
575 TimeOut(22 + (fe ? fe->ncbs : 0)));
576 Thead = THead(CBtime(time_out));
582 register afs_uint32 hash;
587 fe->volid = fid->Volume;
588 fe->vnode = fid->Vnode;
589 fe->unique = fid->Unique;
592 hash = FEHash(fid->Volume, fid->Unique);
593 fe->fnext = HashTable[hash];
594 HashTable[hash] = fetoi(fe);
596 for (safety = 0, lastcb = cb = itocb(fe->firstcb); cb;
597 lastcb = cb, cb = itocb(cb->cnext), safety++) {
598 if (safety > cbstuff.nblks) {
599 ViceLog(0, ("AddCallBack1: Internal Error -- shutting down.\n"));
601 ShutDownAndCore(PANIC);
603 if (cb->hhead == h_htoi(host))
606 if (cb) { /* Already have call back: move to new timeout list */
607 /* don't change delayed callbacks back to normal ones */
608 if (cb->status != CB_DELAYED)
610 /* Only move if new timeout is longer */
611 if (TNorm(ttoi(Thead)) > TNorm(cb->thead)) {
615 if (newfe == NULL) { /* we are using the new FE */
616 fe->firstcb = cbtoi(cb);
618 cb->fhead = fetoi(fe);
623 *(lastcb ? &lastcb->cnext : &fe->firstcb) = cbtoi(cb);
626 cb->fhead = fetoi(fe);
632 /* now free any still-unused callback or host entries */
638 if (!locked) /* freecb and freefe might(?) yield */
641 if (type == CB_NORMAL || type == CB_VOLUME || type == CB_BULK)
642 return time_out - ServerBias; /* Expires sooner at workstation */
647 /* Take an array full of hosts, all held. Break callbacks to them, and
648 * release the holds once you're done, except don't release xhost. xhost
649 * may be NULL. Currently only works for a single Fid in afidp array.
650 * If you want to make this work with multiple fids, you need to fix
651 * the error handling. One approach would be to force a reset if a
652 * multi-fid call fails, or you could add delayed callbacks for each
653 * fid. You probably also need to sort and remove duplicate hosts.
654 * When this is called from the BreakVolumeCallBacks path, it does NOT
655 * force a reset if the RPC fails, it just marks the host down and tries
656 * to create a delayed callback. */
657 /* N.B. be sure that code works when ncbas == 0 */
658 /* N.B. requires all the cba[*].hp pointers to be valid... */
659 /* This routine does not hold a lock on the host for the duration of
660 * the BreakCallBack RPC, which is a significant deviation from tradition.
661 * It _does_ get a lock on the host before setting VenusDown = 1,
662 * which is sufficient only if VenusDown = 0 only happens when the
663 * lock is held over the RPC and the subsequent VenusDown == 0
664 * wherever that is done. */
666 MultiBreakCallBack_r(struct cbstruct cba[], int ncbas,
667 struct AFSCBFids *afidp, struct host *xhost)
670 struct rx_connection *conns[MAX_CB_HOSTS];
671 static struct AFSCBs tc = { 0, 0 };
672 int multi_to_cba_map[MAX_CB_HOSTS];
674 assert(ncbas <= MAX_CB_HOSTS);
676 /* set up conns for multi-call */
677 for (i = 0, j = 0; i < ncbas; i++) {
678 struct host *thishost = cba[i].hp;
679 if (!thishost || (thishost->hostFlags & HOSTDELETED)) {
682 rx_GetConnection(thishost->callback_rxcon);
683 multi_to_cba_map[j] = i;
684 conns[j++] = thishost->callback_rxcon;
687 rx_SetConnDeadTime(thishost->callback_rxcon, 4);
688 rx_SetConnHardDeadTime(thishost->callback_rxcon, AFS_HARDDEADTIME);
692 if (j) { /* who knows what multi would do with 0 conns? */
696 multi_RXAFSCB_CallBack(afidp, &tc);
702 i = multi_to_cba_map[multi_i];
708 ("BCB: INTERNAL ERROR: hp=%x, cba=%x, thead=%u\n",
712 ** try breaking callbacks on alternate interface addresses
714 if (MultiBreakCallBackAlternateAddress(hp, afidp)) {
717 ("BCB: Failed on file %u.%u.%u, Host %x (%s:%d) is down\n",
718 afidp->AFSCBFids_val->Volume,
719 afidp->AFSCBFids_val->Vnode,
720 afidp->AFSCBFids_val->Unique,
722 afs_inet_ntoa_r(hp->host, hoststr),
728 hp->hostFlags |= VENUSDOWN;
730 * We always go into AddCallBack1_r with the host locked
732 AddCallBack1_r(hp, afidp->AFSCBFids_val, itot(idx),
745 for (i = 0; i < ncbas; i++) {
748 if (hp && xhost != hp) {
753 /* H_UNLOCK around this so h_FreeConnection does not deadlock.
754 h_FreeConnection should *never* be called on a callback connection,
755 but on 10/27/04 a deadlock occurred where it was, when we know why,
756 this should be reverted. -- shadow */
758 for (i = 0; i < j; i++) {
759 rx_PutConnection(conns[i]);
767 * Break all call backs for fid, except for the specified host (unless flag
768 * is true, in which case all get a callback message. Assumption: the specified
769 * host is h_Held, by the caller; the others aren't.
770 * Specified host may be bogus, that's ok. This used to check to see if the
771 * host was down in two places, once right after the host was h_held, and
772 * again after it was locked. That race condition is incredibly rare and
773 * relatively harmless even when it does occur, so we don't check for it now.
775 /* if flag is true, send a break callback msg to "host", too */
777 BreakCallBack(struct host *xhost, AFSFid * fid, int flag)
779 struct FileEntry *fe;
780 struct CallBack *cb, *nextcb;
781 struct cbstruct cba[MAX_CB_HOSTS];
788 ("BCB: BreakCallBack(Host %x all but %s:%d, (%u,%u,%u))\n",
789 xhost, afs_inet_ntoa_r(xhost->host, hoststr), ntohs(xhost->port),
790 fid->Volume, fid->Vnode, fid->Unique));
793 cbstuff.BreakCallBacks++;
798 hostindex = h_htoi(xhost);
799 cb = itocb(fe->firstcb);
800 if (!cb || ((fe->ncbs == 1) && (cb->hhead == hostindex) && !flag)) {
801 /* the most common case is what follows the || */
804 tf.AFSCBFids_len = 1;
805 tf.AFSCBFids_val = fid;
808 for (ncbas = 0; cb && ncbas < MAX_CB_HOSTS; cb = nextcb) {
809 nextcb = itocb(cb->cnext);
810 if ((cb->hhead != hostindex || flag)
811 && (cb->status == CB_BULK || cb->status == CB_NORMAL
812 || cb->status == CB_VOLUME)) {
813 struct host *thishost = h_itoh(cb->hhead);
815 ViceLog(0, ("BCB: BOGUS! cb->hhead is NULL!\n"));
816 } else if (thishost->hostFlags & VENUSDOWN) {
818 ("BCB: %x (%s:%d) is down; delaying break call back\n",
819 thishost, afs_inet_ntoa_r(thishost->host, hoststr),
820 ntohs(thishost->port)));
821 cb->status = CB_DELAYED;
824 cba[ncbas].hp = thishost;
825 cba[ncbas].thead = cb->thead;
829 CDel(cb, 1); /* Usually first; so this delete
830 * is reasonably inexpensive */
836 MultiBreakCallBack_r(cba, ncbas, &tf, xhost);
838 /* we need to to all these initializations again because MultiBreakCallBack may block */
843 cb = itocb(fe->firstcb);
844 if (!cb || ((fe->ncbs == 1) && (cb->hhead == hostindex) && !flag)) {
845 /* the most common case is what follows the || */
856 /* Delete (do not break) single call back for fid */
858 DeleteCallBack(struct host *host, AFSFid * fid)
860 register struct FileEntry *fe;
861 register afs_uint32 *pcb;
864 cbstuff.DeleteCallBacks++;
873 ("DCB: No call backs for fid (%u, %u, %u)\n", fid->Volume,
874 fid->Vnode, fid->Unique));
877 pcb = FindCBPtr(fe, host);
880 ("DCB: No call back for host %x (%s:%d), (%u, %u, %u)\n",
881 host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port),
882 fid->Volume, fid->Vnode, fid->Unique));
896 * Delete (do not break) all call backs for fid. This call doesn't
897 * set all of the various host locks, but it shouldn't really matter
898 * since we're not adding callbacks, but deleting them. I'm not sure
899 * why it doesn't set the lock, however; perhaps it should.
902 DeleteFileCallBacks(AFSFid * fid)
904 register struct FileEntry *fe;
905 register struct CallBack *cb;
906 register afs_uint32 cbi;
910 cbstuff.DeleteFiles++;
915 ("DF: No fid (%u,%u,%u) to delete\n", fid->Volume, fid->Vnode,
919 for (n = 0, cbi = fe->firstcb; cbi; n++) {
931 /* Delete (do not break) all call backs for host. The host should be
934 DeleteAllCallBacks_r(struct host *host, int deletefe)
936 register struct CallBack *cb;
937 register int cbi, first;
939 cbstuff.DeleteAllCallBacks++;
940 cbi = first = host->cblist;
942 ViceLog(8, ("DV: no call backs\n"));
950 } while (cbi != first);
956 * Break all delayed call backs for host. Returns 1 if all call backs
957 * successfully broken; 0 otherwise. Assumes host is h_Held and h_Locked.
958 * Must be called with VenusDown set for this host
961 BreakDelayedCallBacks(struct host *host)
965 retVal = BreakDelayedCallBacks_r(host);
971 BreakDelayedCallBacks_r(struct host *host)
973 struct AFSFid fids[AFSCBMAX];
974 u_byte thead[AFSCBMAX]; /* This should match thead in struct Callback */
975 int cbi, first, nfids;
979 struct rx_connection *cb_conn;
982 if (!(host->hostFlags & RESETDONE) && !(host->hostFlags & HOSTDELETED)) {
983 host->hostFlags &= ~ALTADDR; /* alternate addresses are invalid */
984 cb_conn = host->callback_rxcon;
985 rx_GetConnection(cb_conn);
986 if (host->interface) {
989 RXAFSCB_InitCallBackState3(cb_conn, &FS_HostUUID);
992 code = RXAFSCB_InitCallBackState(cb_conn);
994 rx_PutConnection(cb_conn);
997 host->hostFlags |= ALTADDR; /* alternate addresses are valid */
1001 ("CB: Call back connect back failed (in break delayed) for Host %x (%s:%d)\n",
1002 host, afs_inet_ntoa_r(host->host, hoststr),
1003 ntohs(host->port)));
1005 host->hostFlags |= VENUSDOWN;
1008 ("InitCallBackState success on %x (%s:%d)\n",
1009 host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
1010 /* reset was done successfully */
1011 host->hostFlags |= RESETDONE;
1012 host->hostFlags &= ~VENUSDOWN;
1015 while (!(host->hostFlags & HOSTDELETED)) {
1017 host->hostFlags &= ~VENUSDOWN; /* presume up */
1018 cbi = first = host->cblist;
1022 first = host->cblist;
1025 if (cb->status == CB_DELAYED) {
1026 register struct FileEntry *fe = itofe(cb->fhead);
1027 thead[nfids] = cb->thead;
1028 fids[nfids].Volume = fe->volid;
1029 fids[nfids].Vnode = fe->vnode;
1030 fids[nfids].Unique = fe->unique;
1036 } while (cbi && cbi != first && nfids < AFSCBMAX);
1042 if (XCallBackBulk_r(host, fids, nfids)) {
1043 /* Failed, again: put them back, probably with old
1048 ("CB: XCallBackBulk failed, Host %x (%s:%d); callback list follows:\n",
1049 host, afs_inet_ntoa_r(host->host, hoststr),
1050 ntohs(host->port)));
1052 for (i = 0; i < nfids; i++) {
1055 ("CB: Host %x (%s:%d), file %u.%u.%u (part of bulk callback)\n",
1056 host, afs_inet_ntoa_r(host->host, hoststr),
1057 ntohs(host->port), fids[i].Volume,
1058 fids[i].Vnode, fids[i].Unique));
1061 * AddCallBack1_r(host, &fids[i], itot(thead[i]), CB_DELAYED, 1);
1062 * * but it turns out to cause too many tricky locking problems.
1063 * * now, if break delayed fails, screw it. */
1065 host->hostFlags |= VENUSDOWN; /* Failed */
1066 ClearHostCallbacks_r(host, 1 /* locked */ );
1070 if (nfids < AFSCBMAX)
1074 cbstuff.nbreakers--;
1075 /* If we succeeded it's always ok to unset HFE_LATER */
1076 if (!(host->hostFlags & VENUSDOWN))
1077 host->hostFlags &= ~HFE_LATER;
1078 return (host->hostFlags & VENUSDOWN);
1082 ** isheld is 0 if the host is held in h_Enumerate
1083 ** isheld is 1 if the host is held in BreakVolumeCallBacks
1086 MultiBreakVolumeCallBack_r(struct host *host, int isheld,
1087 struct VCBParams *parms, int deletefe)
1092 return isheld; /* host is held only by h_Enumerate, do nothing */
1093 if (host->hostFlags & HOSTDELETED)
1094 return 0; /* host is deleted, release hold */
1096 if (host->hostFlags & VENUSDOWN) {
1098 if (host->hostFlags & HOSTDELETED) {
1100 return 0; /* Release hold */
1103 ("BVCB: volume call back for Host %x (%s:%d) failed\n",
1104 host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
1107 ("CB: volume callback for Host %x (%s:%d) failed\n",
1108 host, afs_inet_ntoa_r(host->host, hoststr),
1109 ntohs(host->port)));
1111 DeleteAllCallBacks_r(host, deletefe); /* Delete all callback state
1112 * rather than attempting to
1113 * selectively remember to
1114 * delete the volume callbacks
1116 host->hostFlags &= ~RESETDONE; /* Do InitCallBackState when host returns */
1118 return 0; /* release hold */
1120 assert(parms->ncbas <= MAX_CB_HOSTS);
1122 /* Do not call MultiBreakCallBack on the current host structure
1123 ** because it would prematurely release the hold on the host
1125 if (parms->ncbas == MAX_CB_HOSTS) {
1126 struct AFSCBFids tf;
1128 tf.AFSCBFids_len = 1;
1129 tf.AFSCBFids_val = parms->fid;
1131 /* this releases all the hosts */
1132 MultiBreakCallBack_r(parms->cba, parms->ncbas, &tf, 0 /* xhost */ );
1136 parms->cba[parms->ncbas].hp = host;
1137 parms->cba[(parms->ncbas)++].thead = parms->thead;
1138 return 1; /* DON'T release hold, because we still need it. */
1142 ** isheld is 0 if the host is held in h_Enumerate
1143 ** isheld is 1 if the host is held in BreakVolumeCallBacks
1146 MultiBreakVolumeCallBack(struct host *host, int isheld,
1147 struct VCBParams *parms)
1151 retval = MultiBreakVolumeCallBack_r(host, isheld, parms, 1);
1157 ** isheld is 0 if the host is held in h_Enumerate
1158 ** isheld is 1 if the host is held in BreakVolumeCallBacks
1161 MultiBreakVolumeLaterCallBack(struct host *host, int isheld,
1162 struct VCBParams *parms)
1166 retval = MultiBreakVolumeCallBack_r(host, isheld, parms, 0);
1172 * Break all call backs on a single volume. Don't call this with any
1173 * hosts h_held. Note that this routine clears the callbacks before
1174 * actually breaking them, and that the vnode isn't locked during this
1175 * operation, so that people might see temporary callback loss while
1176 * this function is executing. It is just a temporary state, however,
1177 * since the callback will be broken later by this same function.
1179 * Now uses multi-RX for CallBack RPC. Note that the
1180 * multiBreakCallBacks routine does not force a reset if the RPC
1181 * fails, unlike the previous version of this routine, but does create
1182 * a delayed callback. Resets will be forced if the host is
1183 * determined to be down before the RPC is executed.
1186 BreakVolumeCallBacks(afs_uint32 volume)
1191 struct CallBack *cb;
1192 struct FileEntry *fe;
1194 struct VCBParams henumParms;
1195 afs_uint32 tthead = 0; /* zero is illegal value */
1198 fid.Volume = volume, fid.Vnode = fid.Unique = 0;
1199 for (hash = 0; hash < FEHASH_SIZE; hash++) {
1200 for (feip = &HashTable[hash]; (fe = itofe(*feip));) {
1201 if (fe->volid == volume) {
1202 register struct CallBack *cbnext;
1203 for (cb = itocb(fe->firstcb); cb; cb = cbnext) {
1204 host = h_itoh(cb->hhead);
1206 cbnext = itocb(cb->cnext);
1207 if (!tthead || (TNorm(tthead) < TNorm(cb->thead))) {
1213 /* leave hold for MultiBreakVolumeCallBack to clear */
1224 /* didn't find any callbacks, so return right away. */
1228 henumParms.ncbas = 0;
1229 henumParms.fid = &fid;
1230 henumParms.thead = tthead;
1232 h_Enumerate(MultiBreakVolumeCallBack, (char *)&henumParms);
1234 if (henumParms.ncbas) { /* do left-overs */
1235 struct AFSCBFids tf;
1236 tf.AFSCBFids_len = 1;
1237 tf.AFSCBFids_val = &fid;
1239 MultiBreakCallBack_r(henumParms.cba, henumParms.ncbas, &tf, 0);
1241 henumParms.ncbas = 0;
1247 #ifdef AFS_PTHREAD_ENV
1248 extern pthread_cond_t fsync_cond;
1250 extern char fsync_wait[];
1254 BreakVolumeCallBacksLater(afs_uint32 volume)
1258 struct FileEntry *fe;
1259 struct CallBack *cb;
1263 ViceLog(25, ("Setting later on volume %u\n", volume));
1265 for (hash = 0; hash < FEHASH_SIZE; hash++) {
1266 for (feip = &HashTable[hash]; (fe = itofe(*feip)) != NULL; ) {
1267 if (fe->volid == volume) {
1268 register struct CallBack *cbnext;
1269 for (cb = itocb(fe->firstcb); cb; cb = cbnext) {
1270 host = h_itoh(cb->hhead);
1271 host->hostFlags |= HFE_LATER;
1272 cb->status = CB_DELAYED;
1273 cbnext = itocb(cb->cnext);
1276 fe->status |= FE_LATER;
1285 /* didn't find any callbacks, so return right away. */
1289 ViceLog(25, ("Fsync thread wakeup\n"));
1290 #ifdef AFS_PTHREAD_ENV
1292 assert(pthread_cond_broadcast(&fsync_cond) == 0);
1295 LWP_NoYieldSignal(fsync_wait);
1301 BreakLaterCallBacks(void)
1306 struct CallBack *cb;
1307 struct FileEntry *fe = NULL;
1308 struct FileEntry *myfe = NULL;
1310 struct VCBParams henumParms;
1311 unsigned short tthead = 0; /* zero is illegal value */
1315 ViceLog(25, ("Looking for FileEntries to unchain\n"));
1318 /* Pick the first volume we see to clean up */
1319 fid.Volume = fid.Vnode = fid.Unique = 0;
1321 for (hash = 0; hash < FEHASH_SIZE; hash++) {
1322 for (feip = &HashTable[hash]; (fe = itofe(*feip)) != NULL; ) {
1323 if (fe && (fe->status & FE_LATER)
1324 && (fid.Volume == 0 || fid.Volume == fe->volid)) {
1325 /* Ugly, but used to avoid left side casting */
1326 struct object *tmpfe;
1328 ("Unchaining for %u:%u:%u\n", fe->vnode, fe->unique,
1330 fid.Volume = fe->volid;
1332 /* Works since volid is deeper than the largest pointer */
1333 tmpfe = (struct object *)fe;
1334 tmpfe->next = (struct object *)myfe;
1347 /* loop over FEs from myfe and free/break */
1349 for (fe = myfe; fe;) {
1350 register struct CallBack *cbnext;
1351 for (cb = itocb(fe->firstcb); cb; cb = cbnext) {
1352 cbnext = itocb(cb->cnext);
1353 host = h_itoh(cb->hhead);
1354 if (cb->status == CB_DELAYED) {
1356 if (!tthead || (TNorm(tthead) < TNorm(cb->thead))) {
1361 CDel(cb, 0); /* Don't let CDel clean up the fe */
1362 /* leave hold for MultiBreakVolumeCallBack to clear */
1365 ("Found host %x (%s:%d) non-DELAYED cb for %u:%u:%u\n",
1366 host, afs_inet_ntoa_r(host->host, hoststr),
1367 ntohs(host->port), fe->vnode, fe->unique, fe->volid));
1371 fe = (struct FileEntry *)((struct object *)fe)->next;
1376 ViceLog(125, ("Breaking volume %u\n", fid.Volume));
1377 henumParms.ncbas = 0;
1378 henumParms.fid = &fid;
1379 henumParms.thead = tthead;
1381 h_Enumerate(MultiBreakVolumeLaterCallBack, (char *)&henumParms);
1383 if (henumParms.ncbas) { /* do left-overs */
1384 struct AFSCBFids tf;
1385 tf.AFSCBFids_len = 1;
1386 tf.AFSCBFids_val = &fid;
1388 MultiBreakCallBack_r(henumParms.cba, henumParms.ncbas, &tf, 0);
1389 henumParms.ncbas = 0;
1394 /* Arrange to be called again */
1399 * Delete all timed-out call back entries (to be called periodically by file
1403 CleanupTimedOutCallBacks(void)
1406 CleanupTimedOutCallBacks_r();
1412 CleanupTimedOutCallBacks_r(void)
1414 afs_uint32 now = CBtime(FT_ApproxTime());
1415 register afs_uint32 *thead;
1416 register struct CallBack *cb;
1417 register int ntimedout = 0;
1420 while (tfirst <= now) {
1422 cbi = *(thead = THead(tfirst));
1428 ("CCB: deleting timed out call back %x (%s:%d), (%u,%u,%u)\n",
1429 h_itoh(cb->hhead)->host,
1430 afs_inet_ntoa_r(h_itoh(cb->hhead)->host, hoststr),
1431 h_itoh(cb->hhead)->port, itofe(cb->fhead)->volid,
1432 itofe(cb->fhead)->vnode, itofe(cb->fhead)->unique));
1436 if (ntimedout > cbstuff.nblks) {
1437 ViceLog(0, ("CCB: Internal Error -- shutting down...\n"));
1438 DumpCallBackState();
1439 ShutDownAndCore(PANIC);
1441 } while (cbi != *thead);
1446 cbstuff.CBsTimedOut += ntimedout;
1447 ViceLog(7, ("CCB: deleted %d timed out callbacks\n", ntimedout));
1448 return (ntimedout > 0);
1451 static struct host *lih_host;
1452 static int lih_host_held;
1454 /* This version does not allow 'host' to be selected unless its ActiveCall
1455 * is newer than 'hostp' which is the host with the oldest ActiveCall from
1456 * the last pass (if it is provided). We filter out any hosts that are
1457 * are held by other threads.
1460 lih0_r(register struct host *host, register int held,
1461 register struct host *hostp)
1464 && (hostp && host != hostp)
1465 && (!held && !h_OtherHolds_r(host))
1466 && (!lih_host || host->ActiveCall < lih_host->ActiveCall)
1467 && (!hostp || host->ActiveCall > hostp->ActiveCall)) {
1468 if (lih_host != NULL && lih_host_held) {
1469 h_Release_r(lih_host);
1472 lih_host_held = !held;
1478 /* This version does not allow 'host' to be selected unless its ActiveCall
1479 * is newer than 'hostp' which is the host with the oldest ActiveCall from
1480 * the last pass (if it is provided). In this second varient, we do not
1481 * prevent held hosts from being selected.
1484 lih1_r(register struct host *host, register int held,
1485 register struct host *hostp)
1488 && (hostp && host != hostp)
1489 && (!lih_host || host->ActiveCall < lih_host->ActiveCall)
1490 && (!hostp || host->ActiveCall > hostp->ActiveCall)) {
1491 if (lih_host != NULL && lih_host_held) {
1492 h_Release_r(lih_host);
1495 lih_host_held = !held;
1501 /* This could be upgraded to get more space each time */
1502 /* first pass: sequentially find the oldest host which isn't held by
1503 anyone for which we can clear callbacks;
1505 /* second pass: sequentially find the oldest host regardless of
1506 whether or not the host is held; skipping 'hostp' */
1507 /* third pass: attempt to clear callbacks from 'hostp' */
1508 /* always called with hostp unlocked */
1510 /* Note: hostlist is ordered most recently created host first and
1511 * its order has no relationship to the most recently used. */
1512 extern struct host *hostList;
1514 GetSomeSpace_r(struct host *hostp, int locked)
1516 register struct host *hp, *hp1, *hp2;
1519 cbstuff.GotSomeSpaces++;
1521 ("GSS: First looking for timed out call backs via CleanupCallBacks\n"));
1522 if (CleanupTimedOutCallBacks_r()) {
1532 h_Enumerate_r(i == 0 ? lih0_r : lih1_r, hp2, (char *)hp1);
1535 /* set in lih_r! private copy before giving up H_LOCK */
1536 int lih_host_held2=lih_host_held;
1538 if ((hp != hostp) && !ClearHostCallbacks_r(hp, 0 /* not locked or held */ )) {
1549 * Next time try getting callbacks from any host even if
1550 * it's deleted (that's actually great since we can freely
1551 * remove its callbacks) or it's held since the only other
1552 * option is starvation for the file server (i.e. until the
1553 * callback timeout arrives).
1560 ("GSS: Try harder for longest inactive host cnt= %d\n",
1565 /* Could not obtain space from other hosts, clear hostp's callback state */
1570 ClearHostCallbacks_r(hostp, 1 /*already locked */ );
1577 /* locked - set if caller has already locked the host */
1579 ClearHostCallbacks_r(struct host *hp, int locked)
1584 struct rx_connection *cb_conn = NULL;
1587 ("GSS: Delete longest inactive host %x (%s:%d)\n",
1588 hp, afs_inet_ntoa_r(hp->host, hoststr), ntohs(hp->port)));
1589 if (!(held = h_Held_r(hp)))
1592 /** Try a non-blocking lock. If the lock is already held return
1593 * after releasing hold on hp
1596 if (h_NBLock_r(hp)) {
1602 if (hp->Console & 2) {
1604 * If the special console field is set it means that a thread
1605 * is waiting in AddCallBack1 after it set pointers to the
1606 * file entry and/or callback entry. Because of the bogus
1607 * usage of h_hold it won't prevent from another thread, this
1608 * one, to remove all the callbacks so just to be safe we keep
1609 * a reference. NOTE, on the last phase we'll free the calling
1610 * host's callbacks but that's ok...
1614 DeleteAllCallBacks_r(hp, 1);
1615 if (hp->hostFlags & VENUSDOWN) {
1616 hp->hostFlags &= ~RESETDONE; /* remember that we must do a reset */
1618 /* host is up, try a call */
1619 hp->hostFlags &= ~ALTADDR; /* alternate addresses are invalid */
1620 cb_conn = hp->callback_rxcon;
1621 rx_GetConnection(hp->callback_rxcon);
1622 if (hp->interface) {
1625 RXAFSCB_InitCallBackState3(cb_conn, &FS_HostUUID);
1628 code = RXAFSCB_InitCallBackState(cb_conn);
1630 rx_PutConnection(cb_conn);
1633 hp->hostFlags |= ALTADDR; /* alternate addresses are valid */
1635 /* failed, mark host down and need reset */
1636 hp->hostFlags |= VENUSDOWN;
1637 hp->hostFlags &= ~RESETDONE;
1639 /* reset succeeded, we're done */
1640 hp->hostFlags |= RESETDONE;
1651 #endif /* INTERPRET_DUMP */
1655 PrintCallBackStats(void)
1658 "%d add CB, %d break CB, %d del CB, %d del FE, %d CB's timed out, %d space reclaim, %d del host\n",
1659 cbstuff.AddCallBacks, cbstuff.BreakCallBacks,
1660 cbstuff.DeleteCallBacks, cbstuff.DeleteFiles, cbstuff.CBsTimedOut,
1661 cbstuff.GotSomeSpaces, cbstuff.DeleteAllCallBacks);
1662 fprintf(stderr, "%d CBs, %d FEs, (%d of total of %d 16-byte blocks)\n",
1663 cbstuff.nCBs, cbstuff.nFEs, cbstuff.nCBs + cbstuff.nFEs,
1669 #define MAGIC 0x12345678 /* To check byte ordering 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)) {
1911 cb_stateVerifyFEHash(struct fs_dump_state * state)
1914 struct FileEntry * fe;
1915 afs_uint32 fei, chain_len;
1917 for (i = 0; i < FEHASH_SIZE; i++) {
1919 for (fei = HashTable[i], fe = itofe(fei);
1921 fei = fe->fnext, fe = itofe(fei)) {
1922 if (fei > cbstuff.nblks) {
1923 ViceLog(0, ("cb_stateVerifyFEHash: error: index out of range (fei=%d)\n", fei));
1927 if (cb_stateVerifyFE(state, fe)) {
1930 if (chain_len > FS_STATE_FE_MAX_HASH_CHAIN_LEN) {
1931 ViceLog(0, ("cb_stateVerifyFEHash: error: hash chain %d length exceeds %d; assuming there's a loop\n",
1932 i, FS_STATE_FE_MAX_HASH_CHAIN_LEN));
1945 cb_stateVerifyFE(struct fs_dump_state * state, struct FileEntry * fe)
1949 if ((fe->firstcb && !fe->ncbs) ||
1950 (!fe->firstcb && fe->ncbs)) {
1951 ViceLog(0, ("cb_stateVerifyFE: error: fe->firstcb does not agree with fe->ncbs (fei=%d, fe->firstcb=%d, fe->ncbs=%d)\n",
1952 fetoi(fe), fe->firstcb, fe->ncbs));
1955 if (cb_stateVerifyFCBList(state, fe)) {
1956 ViceLog(0, ("cb_stateVerifyFE: error: FCBList failed verification (fei=%d)\n", 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));
2123 cb_stateSaveTimeouts(struct fs_dump_state * state)
2126 struct iovec iov[2];
2128 AssignInt64(state->eof_offset, &state->cb_hdr->timeout_offset);
2130 memset(state->cb_timeout_hdr, 0, sizeof(struct callback_state_fehash_header));
2131 state->cb_timeout_hdr->magic = CALLBACK_STATE_TIMEOUT_MAGIC;
2132 state->cb_timeout_hdr->records = CB_NUM_TIMEOUT_QUEUES;
2133 state->cb_timeout_hdr->len = sizeof(struct callback_state_timeout_header) +
2134 (state->cb_timeout_hdr->records * sizeof(afs_uint32));
2136 iov[0].iov_base = (char *)state->cb_timeout_hdr;
2137 iov[0].iov_len = sizeof(struct callback_state_timeout_header);
2138 iov[1].iov_base = (char *)timeout;
2139 iov[1].iov_len = sizeof(timeout);
2141 if (fs_stateSeek(state, &state->cb_hdr->timeout_offset)) {
2146 if (fs_stateWriteV(state, iov, 2)) {
2151 fs_stateIncEOF(state, state->cb_timeout_hdr->len);
2158 cb_stateRestoreTimeouts(struct fs_dump_state * state)
2162 if (fs_stateReadHeader(state, &state->cb_hdr->timeout_offset,
2163 state->cb_timeout_hdr,
2164 sizeof(struct callback_state_timeout_header))) {
2169 if (state->cb_timeout_hdr->magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
2173 if (state->cb_timeout_hdr->records != CB_NUM_TIMEOUT_QUEUES) {
2178 len = state->cb_timeout_hdr->records * sizeof(afs_uint32);
2180 if (state->cb_timeout_hdr->len !=
2181 (sizeof(struct callback_state_timeout_header) + len)) {
2186 if (fs_stateRead(state, timeout, len)) {
2196 cb_stateSaveFEHash(struct fs_dump_state * state)
2199 struct iovec iov[2];
2201 AssignInt64(state->eof_offset, &state->cb_hdr->fehash_offset);
2203 memset(state->cb_fehash_hdr, 0, sizeof(struct callback_state_fehash_header));
2204 state->cb_fehash_hdr->magic = CALLBACK_STATE_FEHASH_MAGIC;
2205 state->cb_fehash_hdr->records = FEHASH_SIZE;
2206 state->cb_fehash_hdr->len = sizeof(struct callback_state_fehash_header) +
2207 (state->cb_fehash_hdr->records * sizeof(afs_uint32));
2209 iov[0].iov_base = (char *)state->cb_fehash_hdr;
2210 iov[0].iov_len = sizeof(struct callback_state_fehash_header);
2211 iov[1].iov_base = (char *)HashTable;
2212 iov[1].iov_len = sizeof(HashTable);
2214 if (fs_stateSeek(state, &state->cb_hdr->fehash_offset)) {
2219 if (fs_stateWriteV(state, iov, 2)) {
2224 fs_stateIncEOF(state, state->cb_fehash_hdr->len);
2231 cb_stateRestoreFEHash(struct fs_dump_state * state)
2235 if (fs_stateReadHeader(state, &state->cb_hdr->fehash_offset,
2236 state->cb_fehash_hdr,
2237 sizeof(struct callback_state_fehash_header))) {
2242 if (state->cb_fehash_hdr->magic != CALLBACK_STATE_FEHASH_MAGIC) {
2246 if (state->cb_fehash_hdr->records != FEHASH_SIZE) {
2251 len = state->cb_fehash_hdr->records * sizeof(afs_uint32);
2253 if (state->cb_fehash_hdr->len !=
2254 (sizeof(struct callback_state_fehash_header) + len)) {
2259 if (fs_stateRead(state, HashTable, len)) {
2269 cb_stateSaveFEs(struct fs_dump_state * state)
2272 register int fei, hash;
2273 register struct FileEntry *fe;
2275 AssignInt64(state->eof_offset, &state->cb_hdr->fe_offset);
2277 for (hash = 0; hash < FEHASH_SIZE ; hash++) {
2278 for (fei = HashTable[hash]; fei; fei = fe->fnext) {
2280 if (cb_stateSaveFE(state, fe)) {
2292 cb_stateRestoreFEs(struct fs_dump_state * state)
2294 int count, nFEs, ret = 0;
2296 nFEs = state->cb_hdr->nFEs;
2298 for (count = 0; count < nFEs; count++) {
2299 if (cb_stateRestoreFE(state)) {
2310 cb_stateSaveFE(struct fs_dump_state * state, struct FileEntry * fe)
2312 int ret = 0, iovcnt, cbi, written = 0;
2314 struct callback_state_entry_header hdr;
2315 struct FEDiskEntry fedsk;
2316 struct CBDiskEntry cbdsk[16];
2317 struct iovec iov[16];
2318 struct CallBack *cb;
2321 if (fei > state->cb_hdr->fe_max) {
2322 state->cb_hdr->fe_max = fei;
2325 memset(&hdr, 0, sizeof(struct callback_state_entry_header));
2327 if (cb_stateFEToDiskEntry(fe, &fedsk)) {
2332 iov[0].iov_base = (char *)&hdr;
2333 iov[0].iov_len = sizeof(hdr);
2334 iov[1].iov_base = (char *)&fedsk;
2335 iov[1].iov_len = sizeof(struct FEDiskEntry);
2338 for (cbi = fe->firstcb, cb = itocb(cbi);
2340 cbi = cb->cnext, cb = itocb(cbi), hdr.nCBs++) {
2341 if (cbi > state->cb_hdr->cb_max) {
2342 state->cb_hdr->cb_max = cbi;
2344 if (cb_stateCBToDiskEntry(cb, &cbdsk[iovcnt])) {
2348 cbdsk[iovcnt].index = cbi;
2349 iov[iovcnt].iov_base = (char *)&cbdsk[iovcnt];
2350 iov[iovcnt].iov_len = sizeof(struct CBDiskEntry);
2352 if ((iovcnt == 16) || (!cb->cnext)) {
2353 if (fs_stateWriteV(state, iov, iovcnt)) {
2362 hdr.magic = CALLBACK_STATE_ENTRY_MAGIC;
2363 hdr.len = sizeof(hdr) + sizeof(struct FEDiskEntry) +
2364 (hdr.nCBs * sizeof(struct CBDiskEntry));
2367 if (fs_stateWriteV(state, iov, iovcnt)) {
2372 if (fs_stateWriteHeader(state, &state->eof_offset, &hdr, sizeof(hdr))) {
2378 fs_stateIncEOF(state, hdr.len);
2381 if (fs_stateSeek(state, &state->eof_offset)) {
2387 state->cb_hdr->nFEs++;
2388 state->cb_hdr->nCBs += hdr.nCBs;
2395 cb_stateRestoreFE(struct fs_dump_state * state)
2397 int ret = 0, iovcnt, nCBs;
2398 struct callback_state_entry_header hdr;
2399 struct FEDiskEntry fedsk;
2400 struct CBDiskEntry cbdsk[16];
2401 struct iovec iov[16];
2402 struct FileEntry * fe;
2403 struct CallBack * cb;
2405 iov[0].iov_base = (char *)&hdr;
2406 iov[0].iov_len = sizeof(hdr);
2407 iov[1].iov_base = (char *)&fedsk;
2408 iov[1].iov_len = sizeof(fedsk);
2411 if (fs_stateReadV(state, iov, iovcnt)) {
2416 if (hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
2423 ViceLog(0, ("cb_stateRestoreFE: ran out of free FileEntry structures\n"));
2428 if (cb_stateDiskEntryToFE(state, &fedsk, fe)) {
2434 for (iovcnt = 0, nCBs = 0;
2437 iov[iovcnt].iov_base = (char *)&cbdsk[iovcnt];
2438 iov[iovcnt].iov_len = sizeof(struct CBDiskEntry);
2440 if ((iovcnt == 16) || (nCBs == hdr.nCBs - 1)) {
2441 if (fs_stateReadV(state, iov, iovcnt)) {
2445 if (cb_stateRestoreCBs(state, fe, iov, iovcnt)) {
2459 cb_stateRestoreCBs(struct fs_dump_state * state, struct FileEntry * fe,
2460 struct iovec * iov, int niovecs)
2463 register struct CallBack * cb;
2464 struct CBDiskEntry * cbdsk;
2469 for (idx = 0; idx < niovecs; idx++) {
2470 cbdsk = (struct CBDiskEntry *) iov[idx].iov_base;
2471 if ((cb = GetCB()) == NULL) {
2472 ViceLog(0, ("cb_stateRestoreCBs: ran out of free CallBack structures\n"));
2476 if (cb_stateDiskEntryToCB(state, cbdsk, cb)) {
2477 ViceLog(0, ("cb_stateRestoreCBs: corrupt CallBack disk entry\n"));
2489 cb_stateFillHeader(struct callback_state_header * hdr)
2491 hdr->stamp.magic = CALLBACK_STATE_MAGIC;
2492 hdr->stamp.version = CALLBACK_STATE_VERSION;
2493 hdr->tfirst = tfirst;
2498 cb_stateCheckHeader(struct callback_state_header * hdr)
2502 if (hdr->stamp.magic != CALLBACK_STATE_MAGIC) {
2504 } else if (hdr->stamp.version != CALLBACK_STATE_VERSION) {
2506 } else if ((hdr->nFEs > cbstuff.nblks) || (hdr->nCBs > cbstuff.nblks)) {
2507 ViceLog(0, ("cb_stateCheckHeader: saved callback state larger than callback memory allocation\n"));
2513 /* disk entry conversion routines */
2515 cb_stateFEToDiskEntry(struct FileEntry * in, struct FEDiskEntry * out)
2517 memcpy(&out->fe, in, sizeof(struct FileEntry));
2518 out->index = fetoi(in);
2523 cb_stateDiskEntryToFE(struct fs_dump_state * state,
2524 struct FEDiskEntry * in, struct FileEntry * out)
2528 memcpy(out, &in->fe, sizeof(struct FileEntry));
2530 /* setup FE map entry */
2531 if (!in->index || (in->index >= state->fe_map.len)) {
2532 ViceLog(0, ("cb_stateDiskEntryToFE: index (%d) out of range",
2537 state->fe_map.entries[in->index].old_idx = in->index;
2538 state->fe_map.entries[in->index].new_idx = fetoi(out);
2545 cb_stateCBToDiskEntry(struct CallBack * in, struct CBDiskEntry * out)
2547 memcpy(&out->cb, in, sizeof(struct CallBack));
2548 out->index = cbtoi(in);
2553 cb_stateDiskEntryToCB(struct fs_dump_state * state,
2554 struct CBDiskEntry * in, struct CallBack * out)
2558 memcpy(out, &in->cb, sizeof(struct CallBack));
2560 /* setup CB map entry */
2561 if (!in->index || (in->index >= state->cb_map.len)) {
2562 ViceLog(0, ("cb_stateDiskEntryToCB: index (%d) out of range\n",
2567 state->cb_map.entries[in->index].old_idx = in->index;
2568 state->cb_map.entries[in->index].new_idx = cbtoi(out);
2574 /* index map routines */
2576 cb_stateAllocMap(struct fs_dump_state * state)
2578 state->fe_map.len = state->cb_hdr->fe_max + 1;
2579 state->cb_map.len = state->cb_hdr->cb_max + 1;
2580 state->fe_map.entries = (struct idx_map_entry_t *)
2581 calloc(state->fe_map.len, sizeof(struct idx_map_entry_t));
2582 state->cb_map.entries = (struct idx_map_entry_t *)
2583 calloc(state->cb_map.len, sizeof(struct idx_map_entry_t));
2584 return ((state->fe_map.entries != NULL) && (state->cb_map.entries != NULL)) ? 0 : 1;
2588 fe_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new)
2592 /* FEs use a one-based indexing system, so old==0 implies no mapping */
2598 if (old >= state->fe_map.len) {
2599 ViceLog(0, ("fe_OldToNew: index %d is out of range\n", old));
2601 } else if (state->fe_map.entries[old].old_idx != old) { /* sanity check */
2602 ViceLog(0, ("fe_OldToNew: index %d points to an invalid FileEntry record\n", old));
2605 *new = state->fe_map.entries[old].new_idx;
2613 cb_OldToNew(struct fs_dump_state * state, afs_uint32 old, afs_uint32 * new)
2617 /* CBs use a one-based indexing system, so old==0 implies no mapping */
2623 if (old >= state->cb_map.len) {
2624 ViceLog(0, ("cb_OldToNew: index %d is out of range\n", old));
2626 } else if (state->cb_map.entries[old].old_idx != old) { /* sanity check */
2627 ViceLog(0, ("cb_OldToNew: index %d points to an invalid CallBack record\n", old));
2630 *new = state->cb_map.entries[old].new_idx;
2636 #endif /* AFS_DEMAND_ATTACH_FS */
2639 DumpCallBackState(void)
2642 afs_uint32 magic = MAGIC, now = FT_ApproxTime(), freelisthead;
2644 fd = open(AFSDIR_SERVER_CBKDUMP_FILEPATH, O_WRONLY | O_CREAT | O_TRUNC,
2648 ("Couldn't create callback dump file %s\n",
2649 AFSDIR_SERVER_CBKDUMP_FILEPATH));
2652 (void)write(fd, &magic, sizeof(magic));
2653 (void)write(fd, &now, sizeof(now));
2654 (void)write(fd, &cbstuff, sizeof(cbstuff));
2655 (void)write(fd, TimeOuts, sizeof(TimeOuts));
2656 (void)write(fd, timeout, sizeof(timeout));
2657 (void)write(fd, &tfirst, sizeof(tfirst));
2658 freelisthead = cbtoi((struct CallBack *)CBfree);
2659 (void)write(fd, &freelisthead, sizeof(freelisthead)); /* This is a pointer */
2660 freelisthead = fetoi((struct FileEntry *)FEfree);
2661 (void)write(fd, &freelisthead, sizeof(freelisthead)); /* This is a pointer */
2662 (void)write(fd, HashTable, sizeof(HashTable));
2663 (void)write(fd, &CB[1], sizeof(CB[1]) * cbstuff.nblks); /* CB stuff */
2664 (void)write(fd, &FE[1], sizeof(FE[1]) * cbstuff.nblks); /* FE stuff */
2670 #endif /* !INTERPRET_DUMP */
2672 #ifdef INTERPRET_DUMP
2674 /* This is only compiled in for the callback analyzer program */
2675 /* Returns the time of the dump */
2677 ReadDump(char *file)
2680 afs_uint32 magic, freelisthead;
2683 fd = open(file, O_RDONLY);
2685 fprintf(stderr, "Couldn't read dump file %s\n", file);
2688 read(fd, &magic, sizeof(magic));
2689 if (magic != MAGIC) {
2691 "Magic number of %s is invalid. You might be trying to\n",
2694 "run this program on a machine type with a different byte ordering.\n");
2697 read(fd, &now, sizeof(now));
2698 read(fd, &cbstuff, sizeof(cbstuff));
2699 read(fd, TimeOuts, sizeof(TimeOuts));
2700 read(fd, timeout, sizeof(timeout));
2701 read(fd, &tfirst, sizeof(tfirst));
2702 read(fd, &freelisthead, sizeof(freelisthead));
2703 CB = ((struct CallBack
2704 *)(calloc(cbstuff.nblks, sizeof(struct FileEntry)))) - 1;
2705 FE = ((struct FileEntry
2706 *)(calloc(cbstuff.nblks, sizeof(struct FileEntry)))) - 1;
2707 CBfree = (struct CallBack *)itocb(freelisthead);
2708 read(fd, &freelisthead, sizeof(freelisthead));
2709 FEfree = (struct FileEntry *)itofe(freelisthead);
2710 read(fd, HashTable, sizeof(HashTable));
2711 read(fd, &CB[1], sizeof(CB[1]) * cbstuff.nblks); /* CB stuff */
2712 read(fd, &FE[1], sizeof(FE[1]) * cbstuff.nblks); /* FE stuff */
2714 perror("Error reading dumpfile");
2721 #include "AFS_component_version_number.h"
2723 #include "AFS_component_version_number.c"
2727 main(int argc, char **argv)
2729 int err = 0, cbi = 0, stats = 0, noptions = 0, all = 0, vol = 0, raw = 0;
2731 register struct FileEntry *fe;
2732 register struct CallBack *cb;
2735 memset(&fid, 0, sizeof(fid));
2738 while (argc && **argv == '-') {
2741 if (!strcmp(*argv, "-host")) {
2747 cbi = atoi(*++argv);
2748 } else if (!strcmp(*argv, "-fid")) {
2754 fid.Volume = atoi(*++argv);
2755 fid.Vnode = atoi(*++argv);
2756 fid.Unique = atoi(*++argv);
2757 } else if (!strcmp(*argv, "-time")) {
2758 fprintf(stderr, "-time not supported\n");
2760 } else if (!strcmp(*argv, "-stats")) {
2762 } else if (!strcmp(*argv, "-all")) {
2764 } else if (!strcmp(*argv, "-raw")) {
2766 } else if (!strcmp(*argv, "-volume")) {
2772 vol = atoi(*++argv);
2777 if (err || argc != 1) {
2779 "Usage: cbd [-host cbid] [-fid volume vnode] [-stats] [-all] callbackdumpfile\n");
2781 "[cbid is shown for each host in the hosts.dump file]\n");
2784 now = ReadDump(*argv);
2785 if (stats || noptions == 0) {
2786 time_t uxtfirst = UXtime(tfirst);
2787 printf("The time of the dump was %u %s", now, ctime(&now));
2788 printf("The last time cleanup ran was %u %s", uxtfirst,
2790 PrintCallBackStats();
2795 struct CallBack *cb;
2796 struct FileEntry *fe;
2798 for (hash = 0; hash < FEHASH_SIZE; hash++) {
2799 for (feip = &HashTable[hash]; fe = itofe(*feip);) {
2800 if (!vol || (fe->volid == vol)) {
2801 register struct CallBack *cbnext;
2802 for (cb = itocb(fe->firstcb); cb; cb = cbnext) {
2804 cbnext = itocb(cb->cnext);
2814 afs_uint32 cfirst = cbi;
2819 } while (cbi != cfirst);
2824 printf("No callback entries for %u.%u\n", fid.Volume, fid.Vnode);
2827 cb = itocb(fe->firstcb);
2830 cb = itocb(cb->cnext);
2835 for (i = 1; i < cbstuff.nblks; i++) {
2836 p = (afs_int32 *) & FE[i];
2837 printf("%d:%12x%12x%12x%12x\n", i, p[0], p[1], p[2], p[3]);
2844 PrintCB(register struct CallBack *cb, afs_uint32 now)
2846 struct FileEntry *fe = itofe(cb->fhead);
2847 time_t expires = TIndexToTime(cb->thead);
2852 printf("vol=%u vn=%u cbs=%d hi=%d st=%d fest=%d, exp in %d secs at %s",
2853 fe->volid, fe->vnode, fe->ncbs, cb->hhead, cb->status, fe->status,
2854 expires - now, ctime(&expires));
2859 #if !defined(INTERPRET_DUMP)
2861 ** try breaking calbacks on afidp from host. Use multi_rx.
2862 ** return 0 on success, non-zero on failure
2865 MultiBreakCallBackAlternateAddress(struct host *host, struct AFSCBFids *afidp)
2869 retVal = MultiBreakCallBackAlternateAddress_r(host, afidp);
2875 MultiBreakCallBackAlternateAddress_r(struct host *host,
2876 struct AFSCBFids *afidp)
2879 struct rx_connection **conns;
2880 struct rx_connection *connSuccess = 0;
2881 struct AddrPort *interfaces;
2882 static struct rx_securityClass *sc = 0;
2883 static struct AFSCBs tc = { 0, 0 };
2886 /* nothing more can be done */
2887 if (!host->interface)
2888 return 1; /* failure */
2890 /* the only address is the primary interface */
2891 if (host->interface->numberOfInterfaces <= 1)
2892 return 1; /* failure */
2894 /* initialise a security object only once */
2896 sc = rxnull_NewClientSecurityObject();
2898 i = host->interface->numberOfInterfaces;
2899 interfaces = calloc(i, sizeof(struct AddrPort));
2900 conns = calloc(i, sizeof(struct rx_connection *));
2901 if (!interfaces || !conns) {
2903 ("Failed malloc in MultiBreakCallBackAlternateAddress_r\n"));
2907 /* initialize alternate rx connections */
2908 for (i = 0, j = 0; i < host->interface->numberOfInterfaces; i++) {
2909 /* this is the current primary address */
2910 if (host->host == host->interface->interface[i].addr &&
2911 host->port == host->interface->interface[i].port)
2914 interfaces[j] = host->interface->interface[i];
2916 rx_NewConnection(interfaces[j].addr,
2917 interfaces[j].port, 1, sc, 0);
2918 rx_SetConnDeadTime(conns[j], 2);
2919 rx_SetConnHardDeadTime(conns[j], AFS_HARDDEADTIME);
2923 assert(j); /* at least one alternate address */
2925 ("Starting multibreakcall back on all addr for host %x (%s:%d)\n",
2926 host, afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
2928 multi_Rx(conns, j) {
2929 multi_RXAFSCB_CallBack(afidp, &tc);
2933 if (host->callback_rxcon)
2934 rx_DestroyConnection(host->callback_rxcon);
2935 host->callback_rxcon = conns[multi_i];
2936 h_DeleteHostFromAddrHashTable_r(host->host, host->port, host);
2937 host->host = interfaces[multi_i].addr;
2938 host->port = interfaces[multi_i].port;
2939 h_AddHostToAddrHashTable_r(host->host, host->port, host);
2940 connSuccess = conns[multi_i];
2941 rx_SetConnDeadTime(host->callback_rxcon, 50);
2942 rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
2944 ("multibreakcall success with addr %s:%d\n",
2945 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),
2946 ntohs(interfaces[multi_i].port)));
2953 /* Destroy all connections except the one on which we succeeded */
2954 for (i = 0; i < j; i++)
2955 if (conns[i] != connSuccess)
2956 rx_DestroyConnection(conns[i]);
2962 return 0; /* success */
2964 return 1; /* failure */
2969 ** try multi_RX probes to host.
2970 ** return 0 on success, non-0 on failure
2973 MultiProbeAlternateAddress_r(struct host *host)
2976 struct rx_connection **conns;
2977 struct rx_connection *connSuccess = 0;
2978 struct AddrPort *interfaces;
2979 static struct rx_securityClass *sc = 0;
2982 /* nothing more can be done */
2983 if (!host->interface)
2984 return 1; /* failure */
2986 /* the only address is the primary interface */
2987 if (host->interface->numberOfInterfaces <= 1)
2988 return 1; /* failure */
2990 /* initialise a security object only once */
2992 sc = rxnull_NewClientSecurityObject();
2994 i = host->interface->numberOfInterfaces;
2995 interfaces = calloc(i, sizeof(struct AddrPort));
2996 conns = calloc(i, sizeof(struct rx_connection *));
2997 if (!interfaces || !conns) {
2998 ViceLog(0, ("Failed malloc in MultiProbeAlternateAddress_r\n"));
3002 /* initialize alternate rx connections */
3003 for (i = 0, j = 0; i < host->interface->numberOfInterfaces; i++) {
3004 /* this is the current primary address */
3005 if (host->host == host->interface->interface[i].addr &&
3006 host->port == host->interface->interface[i].port)
3009 interfaces[j] = host->interface->interface[i];
3011 rx_NewConnection(interfaces[j].addr,
3012 interfaces[j].port, 1, sc, 0);
3013 rx_SetConnDeadTime(conns[j], 2);
3014 rx_SetConnHardDeadTime(conns[j], AFS_HARDDEADTIME);
3018 assert(j); /* at least one alternate address */
3020 ("Starting multiprobe on all addr for host %x (%s:%d)\n",
3021 host, afs_inet_ntoa_r(host->host, hoststr),
3022 ntohs(host->port)));
3024 multi_Rx(conns, j) {
3025 multi_RXAFSCB_ProbeUuid(&host->interface->uuid);
3029 if (host->callback_rxcon)
3030 rx_DestroyConnection(host->callback_rxcon);
3031 host->callback_rxcon = conns[multi_i];
3032 h_DeleteHostFromAddrHashTable_r(host->host, host->port, host);
3033 host->host = interfaces[multi_i].addr;
3034 host->port = interfaces[multi_i].port;
3035 h_AddHostToAddrHashTable_r(host->host, host->port, host);
3036 connSuccess = conns[multi_i];
3037 rx_SetConnDeadTime(host->callback_rxcon, 50);
3038 rx_SetConnHardDeadTime(host->callback_rxcon, AFS_HARDDEADTIME);
3040 ("multiprobe success with addr %s:%d\n",
3041 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),
3042 ntohs(interfaces[multi_i].port)));
3047 ("multiprobe failure with addr %s:%d\n",
3048 afs_inet_ntoa_r(interfaces[multi_i].addr, hoststr),
3049 ntohs(interfaces[multi_i].port)));
3051 /* This is less than desirable but its the best we can do.
3052 * The AFS Cache Manager will return either 0 for a Uuid
3053 * match and a 1 for a non-match. If the error is 1 we
3054 * therefore know that our mapping of IP address to Uuid
3055 * is wrong. We should attempt to find the correct
3056 * Uuid and fix the host tables.
3058 if (multi_error == 1) {
3059 /* remove the current alternate address from this host */
3061 removeInterfaceAddr_r(host, interfaces[multi_i].addr, interfaces[multi_i].port);
3065 #ifdef AFS_DEMAND_ATTACH_FS
3066 /* try to bail ASAP if the fileserver is shutting down */
3068 if (fs_state.mode == FS_MODE_SHUTDOWN) {
3077 /* Destroy all connections except the one on which we succeeded */
3078 for (i = 0; i < j; i++)
3079 if (conns[i] != connSuccess)
3080 rx_DestroyConnection(conns[i]);
3086 return 0; /* success */
3088 return 1; /* failure */
3091 #endif /* !defined(INTERPRET_DUMP) */