vserver 1.9.5.x5
[linux-2.6.git] / include / linux / vs_cvirt.h
1 #ifndef _VX_VS_CVIRT_H
2 #define _VX_VS_CVIRT_H
3
4
5 #include "vserver/cvirt.h"
6 #include "vserver/debug.h"
7
8
9 /* utsname virtualization */
10
11 static inline struct new_utsname *vx_new_utsname(void)
12 {
13         if (current->vx_info)
14                 return &current->vx_info->cvirt.utsname;
15         return &system_utsname;
16 }
17
18 #define vx_new_uts(x)           ((vx_new_utsname())->x)
19
20
21 /* pid faking stuff */
22
23
24 #define vx_info_map_pid(v,p) \
25         __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
26 #define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
27 #define vx_map_pid(p)   vx_info_map_pid(current->vx_info, p)
28 #define vx_map_tgid(p) vx_map_pid(p)
29
30 static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
31         const char *func, const char *file, int line)
32 {
33         if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
34                 vxfprintk(VXD_CBIT(cvirt, 2),
35                         "vx_map_tgid: %p/%llx: %d -> %d",
36                         vxi, (long long)vxi->vx_flags, pid,
37                         (pid && pid == vxi->vx_initpid)?1:pid,
38                         func, file, line);
39                 if (pid == 0)
40                         return 0;
41                 if (pid == vxi->vx_initpid)
42                         return 1;
43         }
44         return pid;
45 }
46
47 #define vx_info_rmap_pid(v,p) \
48         __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
49 #define vx_rmap_pid(p)  vx_info_rmap_pid(current->vx_info, p)
50 #define vx_rmap_tgid(p) vx_rmap_pid(p)
51
52 static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
53         const char *func, const char *file, int line)
54 {
55         if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
56                 vxfprintk(VXD_CBIT(cvirt, 2),
57                         "vx_rmap_tgid: %p/%llx: %d -> %d",
58                         vxi, (long long)vxi->vx_flags, pid,
59                         (pid == 1)?vxi->vx_initpid:pid,
60                         func, file, line);
61                 if ((pid == 1) && vxi->vx_initpid)
62                         return vxi->vx_initpid;
63                 if (pid == vxi->vx_initpid)
64                         return ~0U;
65         }
66         return pid;
67 }
68
69
70 static inline void vx_activate_task(struct task_struct *p)
71 {
72         struct vx_info *vxi;
73
74         if ((vxi = p->vx_info)) {
75                 vx_update_load(vxi);
76                 atomic_inc(&vxi->cvirt.nr_running);
77         }
78 }
79
80 static inline void vx_deactivate_task(struct task_struct *p)
81 {
82         struct vx_info *vxi;
83
84         if ((vxi = p->vx_info)) {
85                 vx_update_load(vxi);
86                 atomic_dec(&vxi->cvirt.nr_running);
87         }
88 }
89
90 static inline void vx_uninterruptible_inc(struct task_struct *p)
91 {
92         struct vx_info *vxi;
93
94         if ((vxi = p->vx_info))
95                 atomic_inc(&vxi->cvirt.nr_uninterruptible);
96 }
97
98 static inline void vx_uninterruptible_dec(struct task_struct *p)
99 {
100         struct vx_info *vxi;
101
102         if ((vxi = p->vx_info))
103                 atomic_dec(&vxi->cvirt.nr_uninterruptible);
104 }
105
106
107 #else
108 #warning duplicate inclusion
109 #endif