Windows: Build Demand Attach File Service
[openafs.git] / src / viced / callback.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  *
9  * Portions Copyright (c) 2006 Sine Nomine Associates
10  */
11
12 #ifndef _AFS_VICED_CALLBACK_H
13 #define _AFS_VICED_CALLBACK_H
14
15 /* Maximum number of call backs to break at once, single fid
16  * There is some debate as to just how large this value should be
17  * Ideally, it would be very very large, but I am afraid that the
18  * cache managers will all send in their responses simultaneously,
19  * thereby swamping the file server.  As a result, something like
20  * 10 or 15 might be a better bet.
21  */
22 #define MAX_CB_HOSTS    10
23
24 /* max time to break a callback, otherwise client is dead or net is hosed */
25 #define MAXCBT 25
26
27 #define u_byte  unsigned char
28
29 struct cbcounters {
30     afs_int32 DeleteFiles;
31     afs_int32 DeleteCallBacks;
32     afs_int32 BreakCallBacks;
33     afs_int32 AddCallBacks;
34     afs_int32 GotSomeSpaces;
35     afs_int32 DeleteAllCallBacks;
36     afs_int32 nFEs, nCBs, nblks;
37     afs_int32 CBsTimedOut;
38     afs_int32 nbreakers;
39     afs_int32 GSS1, GSS2, GSS3, GSS4, GSS5;
40 };
41 extern struct cbcounters cbstuff;
42
43 struct cbstruct {
44     struct host *hp;
45     afs_uint32 thead;
46 };
47
48 /* structure MUST be multiple of 8 bytes, otherwise the casts to
49  * struct object will have alignment issues on *P64 userspaces */
50 struct FileEntry {
51     afs_uint32 vnode;
52     afs_uint32 unique;
53     afs_uint32 volid;
54     afs_uint32 fnext;           /* index of next FE in hash chain */
55     afs_uint32 ncbs;            /* number of callbacks for this FE */
56     afs_uint32 firstcb;         /* index of first cb in per-FE list */
57     afs_uint32 status;          /* status bits for this FE */
58     afs_uint32 spare;
59 };
60 #define FE_LATER 0x1
61
62 /* structure MUST be multiple of 8 bytes, otherwise the casts to
63  * struct object will have alignment issues on *P64 userspaces */
64 struct CallBack {
65     afs_uint32 cnext;           /* index of next cb in per-FE list */
66     afs_uint32 fhead;           /* index of associated FE */
67     u_byte thead;               /* Head of timeout chain */
68     u_byte status;              /* Call back status; see definitions, below */
69     unsigned short spare;       /* ensure proper alignment */
70     afs_uint32 hhead;           /* Head of host table chain */
71     afs_uint32 tprev, tnext;    /* per-timeout circular list of callbacks */
72     afs_uint32 hprev, hnext;    /* per-host circular list of callbacks */
73 };
74
75 struct VCBParams {
76     struct cbstruct cba[MAX_CB_HOSTS];  /* re-entrant storage */
77     unsigned int ncbas;
78     afs_uint32 thead;           /* head of timeout queue for youngest callback */
79     struct AFSFid *fid;
80 };
81
82
83 /* callback hash macros */
84 #define FEHASH_SIZE 512         /* Power of 2 */
85 #define FEHASH_MASK (FEHASH_SIZE-1)
86 #define FEHash(volume, unique) (((volume)+(unique))&(FEHASH_MASK))
87
88 #define CB_NUM_TIMEOUT_QUEUES 128
89
90
91 /* status values for status field of CallBack structure */
92 #define CB_NORMAL   1           /* Normal call back */
93 #define CB_DELAYED  2           /* Delayed call back due to rpc problems.
94                                  * The call back entry will be added back to the
95                                  * host list at the END of the list, so that
96                                  * searching backwards in the list will find all
97                                  * the (consecutive)host. delayed call back entries */
98 #define CB_VOLUME   3           /* Callback for a volume */
99 #define CB_BULK     4           /* Normal callbacks, handed out from FetchBulkStatus */
100
101 /* call back indices to pointers, and vice-versa */
102 #define itocb(i)    ((i)?CB+(i):0)
103 #define cbtoi(cbp)  ((afs_uint32)(!(cbp)?0:(cbp)-CB))
104
105 /* file entry indices to pointers, and vice-versa */
106 #define itofe(i)    ((i)?FE+(i):0)
107 #define fetoi(fep)  ((afs_uint32)(!(fep)?0:(fep)-FE))
108
109 /* Timeouts:  there are 128 possible timeout values in effect at any
110  * given time.  Each timeout represents timeouts in an interval of 128
111  * seconds.  So the maximum timeout for a call back is 128*128=16384
112  * seconds, or 4 1/2 hours.  The timeout cleanup stuff is called only
113  * if space runs out or by the file server every 5 minutes.  This 5
114  * minute slack should be allowed for--so a maximum time of 4 hours
115  * is safer.
116  *
117  * Timeouts must be chosen to correspond to an exact multiple
118  * of 128, because all times are truncated to a 128 multiple, and
119  * timed out if the current truncated time is <= to the truncated time
120  * corresponding to the timeout queue.
121  */
122
123 /* Unix time to Call Back time, and vice-versa.  Call back time is
124    in units of 128 seconds, corresponding to time queues. */
125 #define CBtime(uxtime)  ((uxtime)>>7)
126 #define UXtime(cbtime)  ((cbtime)<<7)
127
128 /* Given a Unix time, compute the closest Unix time that corresponds to
129    a time queue, rounding up */
130 #define TimeCeiling(uxtime)     (((uxtime)+127)&~127)
131
132 #define TimeOutCutoff   ((sizeof(TimeOuts)/sizeof(TimeOuts[0]))*8)
133 #define TimeOut(nusers)  ((nusers)>=TimeOutCutoff? MinTimeOut: TimeOuts[(nusers)>>3])
134
135 /* time out at server is 3 minutes more than ws */
136 #define ServerBias        (3*60)
137
138 /* Convert cbtime to timeout queue index */
139 #define TIndex(cbtime)  (((cbtime)&127)+1)
140
141 /* Convert cbtime to pointer to timeout queue head */
142 #define THead(cbtime)   (&timeout[TIndex(cbtime)-1])
143
144 /* Normalize index into timeout array so that two such indices will be
145    ordered correctly, so that they can be compared to see which times
146    sooner, or so that the difference in time out times between them
147    can be computed. */
148 #define TNorm(index)   ((index)<TIndex(tfirst)?(index)+128:(index))
149
150 /* This converts a timeout index into the actual time it will expire */
151 #define TIndexToTime(index) (UXtime(TNorm(index) - TIndex(tfirst) + tfirst))
152
153
154 /* Convert pointer to timeout queue head to index, and vice versa */
155 #define ttoi(t)         ((t-timeout)+1)
156 #define itot(i)         ((timeout)+(i-1))
157
158 #endif /* _AFS_VICED_CALLBACK_H */