Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / include / linux / vs_context.h
1 #ifndef _VX_VS_CONTEXT_H
2 #define _VX_VS_CONTEXT_H
3
4 #include <linux/kernel.h>
5 #include "vserver/debug.h"
6
7
8 #define get_vx_info(i)  __get_vx_info(i,__FILE__,__LINE__,__HERE__)
9
10 static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
11         const char *_file, int _line, void *_here)
12 {
13         if (!vxi)
14                 return NULL;
15
16         vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
17                 vxi, vxi?vxi->vx_id:0, vxi?atomic_read(&vxi->vx_usecnt):0,
18                 _file, _line);
19         __vxh_get_vx_info(vxi, _here);
20
21         atomic_inc(&vxi->vx_usecnt);
22         return vxi;
23 }
24
25
26 extern void free_vx_info(struct vx_info *);
27
28 #define put_vx_info(i)  __put_vx_info(i,__FILE__,__LINE__,__HERE__)
29
30 static inline void __put_vx_info(struct vx_info *vxi,
31         const char *_file, int _line, void *_here)
32 {
33         if (!vxi)
34                 return;
35
36         vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
37                 vxi, vxi?vxi->vx_id:0, vxi?atomic_read(&vxi->vx_usecnt):0,
38                 _file, _line);
39         __vxh_put_vx_info(vxi, _here);
40
41         if (atomic_dec_and_test(&vxi->vx_usecnt))
42                 free_vx_info(vxi);
43 }
44
45
46 #define init_vx_info(p,i) __init_vx_info(p,i,__FILE__,__LINE__,__HERE__)
47
48 static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
49         const char *_file, int _line, void *_here)
50 {
51         if (vxi) {
52                 vxlprintk(VXD_CBIT(xid, 3),
53                         "init_vx_info(%p[#%d.%d])",
54                         vxi, vxi?vxi->vx_id:0,
55                         vxi?atomic_read(&vxi->vx_usecnt):0,
56                         _file, _line);
57                 __vxh_init_vx_info(vxi, vxp, _here);
58
59                 atomic_inc(&vxi->vx_usecnt);
60         }
61         *vxp = vxi;
62 }
63
64
65 #define set_vx_info(p,i) __set_vx_info(p,i,__FILE__,__LINE__,__HERE__)
66
67 static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
68         const char *_file, int _line, void *_here)
69 {
70         struct vx_info *vxo;
71
72         if (!vxi)
73                 return;
74
75         vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
76                 vxi, vxi?vxi->vx_id:0,
77                 vxi?atomic_read(&vxi->vx_usecnt):0,
78                 _file, _line);
79         __vxh_set_vx_info(vxi, vxp, _here);
80
81         atomic_inc(&vxi->vx_usecnt);
82         vxo = xchg(vxp, vxi);
83         BUG_ON(vxo);
84 }
85
86
87 #define clr_vx_info(p) __clr_vx_info(p,__FILE__,__LINE__,__HERE__)
88
89 static inline void __clr_vx_info(struct vx_info **vxp,
90         const char *_file, int _line, void *_here)
91 {
92         struct vx_info *vxo;
93
94         vxo = xchg(vxp, NULL);
95         if (!vxo)
96                 return;
97
98         vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
99                 vxo, vxo?vxo->vx_id:0,
100                 vxo?atomic_read(&vxo->vx_usecnt):0,
101                 _file, _line);
102         __vxh_clr_vx_info(vxo, vxp, _here);
103
104         if (atomic_dec_and_test(&vxo->vx_usecnt))
105                 free_vx_info(vxo);
106 }
107
108
109 #define claim_vx_info(v,p) \
110         __claim_vx_info(v,p,__FILE__,__LINE__,__HERE__)
111
112 static inline void __claim_vx_info(struct vx_info *vxi,
113         struct task_struct *task,
114         const char *_file, int _line, void *_here)
115 {
116         vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
117                 vxi, vxi?vxi->vx_id:0,
118                 vxi?atomic_read(&vxi->vx_usecnt):0,
119                 vxi?atomic_read(&vxi->vx_tasks):0,
120                 task, _file, _line);
121         __vxh_claim_vx_info(vxi, task, _here);
122
123         atomic_inc(&vxi->vx_tasks);
124 }
125
126
127 extern void unhash_vx_info(struct vx_info *);
128
129 #define release_vx_info(v,p) \
130         __release_vx_info(v,p,__FILE__,__LINE__,__HERE__)
131
132 static inline void __release_vx_info(struct vx_info *vxi,
133         struct task_struct *task,
134         const char *_file, int _line, void *_here)
135 {
136         vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
137                 vxi, vxi?vxi->vx_id:0,
138                 vxi?atomic_read(&vxi->vx_usecnt):0,
139                 vxi?atomic_read(&vxi->vx_tasks):0,
140                 task, _file, _line);
141         __vxh_release_vx_info(vxi, task, _here);
142
143         might_sleep();
144
145         if (atomic_dec_and_test(&vxi->vx_tasks))
146                 unhash_vx_info(vxi);
147 }
148
149
150 #define task_get_vx_info(p) \
151         __task_get_vx_info(p,__FILE__,__LINE__,__HERE__)
152
153 static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
154         const char *_file, int _line, void *_here)
155 {
156         struct vx_info *vxi;
157
158         task_lock(p);
159         vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
160                 p, _file, _line);
161         vxi = __get_vx_info(p->vx_info, _file, _line, _here);
162         task_unlock(p);
163         return vxi;
164 }
165
166
167 static inline void __wakeup_vx_info(struct vx_info *vxi)
168 {
169         if (waitqueue_active(&vxi->vx_wait))
170                 wake_up_interruptible(&vxi->vx_wait);
171 }
172
173
174 #define enter_vx_info(v,s)      __enter_vx_info(v,s,__FILE__,__LINE__)
175
176 static inline void __enter_vx_info(struct vx_info *vxi,
177         struct vx_info_save *vxis, const char *_file, int _line)
178 {
179         vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
180                 vxi, vxi ? vxi->vx_id : 0, vxis, current,
181                 current->xid, current->vx_info, _file, _line);
182         vxis->vxi = xchg(&current->vx_info, vxi);
183         vxis->xid = current->xid;
184         current->xid = vxi ? vxi->vx_id : 0;
185 }
186
187 #define leave_vx_info(s)        __leave_vx_info(s,__FILE__,__LINE__)
188
189 static inline void __leave_vx_info(struct vx_info_save *vxis,
190         const char *_file, int _line)
191 {
192         vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
193                 vxis, vxis->xid, vxis->vxi, current,
194                 current->xid, current->vx_info, _file, _line);
195         (void)xchg(&current->vx_info, vxis->vxi);
196         current->xid = vxis->xid;
197 }
198
199
200 static inline void __enter_vx_admin(struct vx_info_save *vxis)
201 {
202         vxis->vxi = xchg(&current->vx_info, NULL);
203         vxis->xid = xchg(&current->xid, (xid_t)0);
204 }
205
206 static inline void __leave_vx_admin(struct vx_info_save *vxis)
207 {
208         (void)xchg(&current->xid, vxis->xid);
209         (void)xchg(&current->vx_info, vxis->vxi);
210 }
211
212 extern void exit_vx_info(struct task_struct *, int);
213 extern void exit_vx_info_early(struct task_struct *, int);
214
215
216 static inline
217 struct task_struct *vx_child_reaper(struct task_struct *p)
218 {
219         struct vx_info *vxi = p->vx_info;
220         struct task_struct *reaper = child_reaper;
221
222         if (!vxi)
223                 goto out;
224
225         BUG_ON(!p->vx_info->vx_reaper);
226
227         /* child reaper for the guest reaper */
228         if (vxi->vx_reaper == p)
229                 goto out;
230
231         reaper = vxi->vx_reaper;
232 out:
233         vxdprintk(VXD_CBIT(xid, 3),
234                 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]\n",
235                 p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
236         return reaper;
237 }
238
239
240 #else
241 #warning duplicate inclusion
242 #endif