upgrade to vserver 1.9.3.17
[linux-2.6.git] / include / linux / vserver / debug.h
1 #ifndef _VX_DEBUG_H
2 #define _VX_DEBUG_H
3
4
5 #define VXD_CBIT(n,m)   (vx_debug_ ## n & (1 << (m)))
6 #define VXD_CMIN(n,m)   (vx_debug_ ## n > (m))
7 #define VXD_MASK(n,m)   (vx_debug_ ## n & (m))
8
9 #define VXD_QPOS(v,p)   (((uint32_t)(v) >> ((p)*8)) & 0xFF)
10 #define VXD_QUAD(v)     VXD_QPOS(v,0), VXD_QPOS(v,1),           \
11                         VXD_QPOS(v,2), VXD_QPOS(v,3)
12
13 #define __FUNC__        __func__
14
15
16 #ifdef  CONFIG_VSERVER_DEBUG
17
18 extern unsigned int vx_debug_switch;
19 extern unsigned int vx_debug_xid;
20 extern unsigned int vx_debug_nid;
21 extern unsigned int vx_debug_net;
22 extern unsigned int vx_debug_limit;
23 extern unsigned int vx_debug_dlim;
24 extern unsigned int vx_debug_cvirt;
25
26
27 #define VX_LOGLEVEL     "vxD: "
28 #define VX_WARNLEVEL    KERN_WARNING "vxW: "
29
30 #define vxdprintk(c,f,x...)                                     \
31         do {                                                    \
32                 if (c)                                          \
33                         printk(VX_LOGLEVEL f "\n" , ##x);       \
34         } while (0)
35
36 #define vxlprintk(c,f,x...)                                     \
37         do {                                                    \
38                 if (c)                                          \
39                         printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
40         } while (0)
41
42 #define vxfprintk(c,f,x...)                                     \
43         do {                                                    \
44                 if (c)                                          \
45                         printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
46         } while (0)
47
48
49 #define vxwprintk(c,f,x...)                                     \
50         do {                                                    \
51                 if (c)                                          \
52                         printk(VX_WARNLEVEL f "\n" , ##x);      \
53         } while (0)
54
55
56 #define vxd_path(d,m)                                           \
57         ({ static char _buffer[PATH_MAX];                       \
58            d_path((d), (m), _buffer, sizeof(_buffer)); })
59
60 #else   /* CONFIG_VSERVER_DEBUG */
61
62 #define vx_debug_switch 0
63 #define vx_debug_xid    0
64 #define vx_debug_nid    0
65 #define vx_debug_net    0
66 #define vx_debug_limit  0
67 #define vx_debug_dlim   0
68 #define vx_debug_cvirt  0
69
70 #define vxdprintk(x...) do { } while (0)
71 #define vxlprintk(x...) do { } while (0)
72 #define vxfprintk(x...) do { } while (0)
73 #define vxwprintk(x...) do { } while (0)
74
75 #define vxd_path        "<none>"
76
77 #endif  /* CONFIG_VSERVER_DEBUG */
78
79
80 /* history stuff */
81
82 #ifdef  CONFIG_VSERVER_HISTORY
83
84
85 extern unsigned volatile int vxh_active;
86
87 struct _vxhe_vxi {
88         struct vx_info *ptr;
89         unsigned xid;
90         unsigned usecnt;
91         unsigned refcnt;
92 };
93
94 struct _vxhe_set_clr {
95         void *data;
96 };
97
98 struct _vxhe_loc_lookup {
99         unsigned arg;
100 };
101
102 enum {
103         VXH_UNUSED=0,
104         VXH_THROW_OOPS=1,
105
106         VXH_GET_VX_INFO,
107         VXH_PUT_VX_INFO,
108         VXH_SET_VX_INFO,
109         VXH_CLR_VX_INFO,
110         VXH_ALLOC_VX_INFO,
111         VXH_DEALLOC_VX_INFO,
112         VXH_HASH_VX_INFO,
113         VXH_UNHASH_VX_INFO,
114         VXH_LOC_VX_INFO,
115         VXH_LOOKUP_VX_INFO,
116 };
117
118 struct _vx_hist_entry {
119         void *loc;
120         unsigned short seq;
121         unsigned short type;
122         struct _vxhe_vxi vxi;
123         union {
124                 struct _vxhe_set_clr sc;
125                 struct _vxhe_loc_lookup ll;
126         };
127 };
128
129 struct _vx_hist_entry *vxh_advance(void *loc);
130
131 #define VXH_HERE()              \
132         ({ __label__ here;      \
133                 here:;          \
134                 &&here; })
135
136
137
138 static inline void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
139 {
140         entry->vxi.ptr = vxi;
141         if (vxi) {
142                 entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
143                 entry->vxi.refcnt = atomic_read(&vxi->vx_refcnt);
144                 entry->vxi.xid = vxi->vx_id;
145         }
146 }
147
148 static inline void vxh_throw_oops(void)
149 {
150         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
151
152         entry->type = VXH_THROW_OOPS;
153
154         /* prevent further acquisition */
155         vxh_active = 0;
156 }
157
158 static inline void vxh_get_vx_info(struct vx_info *vxi)
159 {
160         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
161
162         __vxh_copy_vxi(entry, vxi);
163         entry->type = VXH_GET_VX_INFO;
164 }
165
166 static inline void vxh_put_vx_info(struct vx_info *vxi)
167 {
168         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
169
170         __vxh_copy_vxi(entry, vxi);
171         entry->type = VXH_PUT_VX_INFO;
172 }
173
174 static inline void vxh_set_vx_info(struct vx_info *vxi, void *data)
175 {
176         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
177
178         __vxh_copy_vxi(entry, vxi);
179         entry->sc.data = data;
180         entry->type = VXH_SET_VX_INFO;
181 }
182
183 static inline void vxh_clr_vx_info(struct vx_info *vxi, void *data)
184 {
185         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
186
187         __vxh_copy_vxi(entry, vxi);
188         entry->sc.data = data;
189         entry->type = VXH_CLR_VX_INFO;
190 }
191
192 static inline void vxh_alloc_vx_info(struct vx_info *vxi)
193 {
194         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
195
196         __vxh_copy_vxi(entry, vxi);
197         entry->type = VXH_ALLOC_VX_INFO;
198 }
199
200 static inline void vxh_dealloc_vx_info(struct vx_info *vxi)
201 {
202         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
203
204         __vxh_copy_vxi(entry, vxi);
205         entry->type = VXH_DEALLOC_VX_INFO;
206 }
207
208 static inline void vxh_hash_vx_info(struct vx_info *vxi)
209 {
210         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
211
212         __vxh_copy_vxi(entry, vxi);
213         entry->type = VXH_HASH_VX_INFO;
214 }
215
216 static inline void vxh_unhash_vx_info(struct vx_info *vxi)
217 {
218         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
219
220         __vxh_copy_vxi(entry, vxi);
221         entry->type = VXH_UNHASH_VX_INFO;
222 }
223
224 static inline void vxh_loc_vx_info(unsigned arg, struct vx_info *vxi)
225 {
226         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
227
228         __vxh_copy_vxi(entry, vxi);
229         entry->ll.arg = arg;
230         entry->type = VXH_LOC_VX_INFO;
231 }
232
233 static inline void vxh_lookup_vx_info(unsigned arg, struct vx_info *vxi)
234 {
235         struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
236
237         __vxh_copy_vxi(entry, vxi);
238         entry->ll.arg = arg;
239         entry->type = VXH_LOOKUP_VX_INFO;
240 }
241
242 extern void vxh_dump_history(void);
243
244 #else  /* CONFIG_VSERVER_HISTORY */
245
246 #define vxh_throw_oops()        do { } while (0)
247
248 #define vxh_get_vx_info(v)      do { } while (0)
249 #define vxh_put_vx_info(v)      do { } while (0)
250
251 #define vxh_set_vx_info(v,d)    do { } while (0)
252 #define vxh_clr_vx_info(v,d)    do { } while (0)
253
254 #define vxh_alloc_vx_info(v)    do { } while (0)
255 #define vxh_dealloc_vx_info(v)  do { } while (0)
256
257 #define vxh_hash_vx_info(v)     do { } while (0)
258 #define vxh_unhash_vx_info(v)   do { } while (0)
259
260 #define vxh_loc_vx_info(a,v)    do { } while (0)
261 #define vxh_lookup_vx_info(a,v) do { } while (0)
262
263 #define vxh_dump_history()      do { } while (0)
264
265
266 #endif /* CONFIG_VSERVER_HISTORY */
267
268 #endif /* _VX_DEBUG_H */