viced: Check vnode length on Rename and Link
[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 /* With revised multi_Rx, responses get handled as early as they tickle in, so try big */
23 #define MAX_CB_HOSTS    1024
24
25 /* max time to break a callback, otherwise client is dead or net is hosed */
26 #define MAXCBT 25
27
28 #define u_byte  unsigned char
29
30 struct cbcounters {
31     afs_int32 DeleteFiles;
32     afs_int32 DeleteCallBacks;
33     afs_int32 BreakCallBacks;
34     afs_int32 AddCallBacks;
35     afs_int32 GotSomeSpaces;
36     afs_int32 DeleteAllCallBacks;
37     afs_int32 nFEs, nCBs, nblks;
38     afs_int32 CBsTimedOut;
39     afs_int32 nbreakers;
40     afs_int32 GSS1, GSS2, GSS3, GSS4, GSS5;
41 };
42 extern struct cbcounters cbstuff;
43
44 struct cbstruct {
45     struct host *hp;
46     afs_uint32 thead;
47 };
48
49 /* structure MUST be multiple of 8 bytes, otherwise the casts to
50  * struct object will have alignment issues on *P64 userspaces */
51 struct FileEntry {
52     afs_uint32 vnode;
53     afs_uint32 unique;
54     afs_uint32 volid;
55     afs_uint32 fnext;           /* index of next FE in hash chain */
56     afs_uint32 ncbs;            /* number of callbacks for this FE */
57     afs_uint32 firstcb;         /* index of first cb in per-FE list */
58     afs_uint32 status;          /* status bits for this FE */
59     afs_uint32 spare;
60 };
61 #define FE_LATER 0x1
62
63 /* structure MUST be multiple of 8 bytes, otherwise the casts to
64  * struct object will have alignment issues on *P64 userspaces */
65 struct CallBack {
66     afs_uint32 cnext;           /* index of next cb in per-FE list */
67     afs_uint32 fhead;           /* index of associated FE */
68     u_byte thead;               /* Head of timeout chain */
69     u_byte status;              /* Call back status; see definitions, below */
70     unsigned short spare;       /* ensure proper alignment */
71     afs_uint32 hhead;           /* Head of host table chain */
72     afs_uint32 tprev, tnext;    /* per-timeout circular list of callbacks */
73     afs_uint32 hprev, hnext;    /* per-host circular list of callbacks */
74 };
75
76 struct VCBParams {
77     struct cbstruct cba[MAX_CB_HOSTS];  /* re-entrant storage */
78     unsigned int ncbas;
79     afs_uint32 thead;           /* head of timeout queue for youngest callback */
80     struct AFSFid *fid;
81 };
82
83
84 /* callback hash macros */
85 #define FEHASH_SIZE 512         /* Power of 2 */
86 #define FEHASH_MASK (FEHASH_SIZE-1)
87 #define FEHash(volume, unique) (((volume)+(unique))&(FEHASH_MASK))
88
89 #define CB_NUM_TIMEOUT_QUEUES 128
90
91
92 /* status values for status field of CallBack structure */
93 #define CB_NORMAL   1           /* Normal call back */
94 #define CB_DELAYED  2           /* Delayed call back due to rpc problems.
95                                  * The call back entry will be added back to the
96                                  * host list at the END of the list, so that
97                                  * searching backwards in the list will find all
98                                  * the (consecutive)host. delayed call back entries */
99 #define CB_VOLUME   3           /* Callback for a volume */
100 #define CB_BULK     4           /* Normal callbacks, handed out from FetchBulkStatus */
101
102 /* call back indices to pointers, and vice-versa */
103 #define itocb(i)    ((i)?CB+(i):0)
104 #define cbtoi(cbp)  ((afs_uint32)(!(cbp)?0:(cbp)-CB))
105
106 /* file entry indices to pointers, and vice-versa */
107 #define itofe(i)    ((i)?FE+(i):0)
108 #define fetoi(fep)  ((afs_uint32)(!(fep)?0:(fep)-FE))
109
110 /* Timeouts:  there are 128 possible timeout values in effect at any
111  * given time.  Each timeout represents timeouts in an interval of 128
112  * seconds.  So the maximum timeout for a call back is 128*128=16384
113  * seconds, or 4 1/2 hours.  The timeout cleanup stuff is called only
114  * if space runs out or by the file server every 5 minutes.  This 5
115  * minute slack should be allowed for--so a maximum time of 4 hours
116  * is safer.
117  *
118  * Timeouts must be chosen to correspond to an exact multiple
119  * of 128, because all times are truncated to a 128 multiple, and
120  * timed out if the current truncated time is <= to the truncated time
121  * corresponding to the timeout queue.
122  */
123
124 /* Unix time to Call Back time, and vice-versa.  Call back time is
125    in units of 128 seconds, corresponding to time queues. */
126 #define CBtime(uxtime)  ((uxtime)>>7)
127 #define UXtime(cbtime)  ((cbtime)<<7)
128
129 /* Given a Unix time, compute the closest Unix time that corresponds to
130    a time queue, rounding up */
131 #define TimeCeiling(uxtime)     (((uxtime)+127)&~127)
132
133 #define TimeOutCutoff   ((sizeof(TimeOuts)/sizeof(TimeOuts[0]))*8)
134 #define TimeOut(nusers)  ((nusers)>=TimeOutCutoff? MinTimeOut: TimeOuts[(nusers)>>3])
135
136 /* time out at server is 3 minutes more than ws */
137 #define ServerBias        (3*60)
138
139 /* Convert cbtime to timeout queue index */
140 #define TIndex(cbtime)  (((cbtime)&127)+1)
141
142 /* Convert cbtime to pointer to timeout queue head */
143 #define THead(cbtime)   (&timeout[TIndex(cbtime)-1])
144
145 /* Normalize index into timeout array so that two such indices will be
146    ordered correctly, so that they can be compared to see which times
147    sooner, or so that the difference in time out times between them
148    can be computed. */
149 #define TNorm(index)   ((index)<TIndex(tfirst)?(index)+128:(index))
150
151 /* This converts a timeout index into the actual time it will expire */
152 #define TIndexToTime(index) (UXtime(TNorm(index) - TIndex(tfirst) + tfirst))
153
154
155 /* Convert pointer to timeout queue head to index, and vice versa */
156 #define ttoi(t)         ((t-timeout)+1)
157 #define itot(i)         ((timeout)+(i-1))
158
159 #endif /* _AFS_VICED_CALLBACK_H */