3158d5a84ebefc84f9ad7cf0a3236e587842023c
[linux-2.6.git] / include / linux / vs_cvirt.h
1 #ifndef _VX_VS_CVIRT_H
2 #define _VX_VS_CVIRT_H
3
4 #include "vserver/cvirt.h"
5 #include "vserver/debug.h"
6
7
8 /* utsname virtualization */
9
10 static inline struct new_utsname *vx_new_utsname(void)
11 {
12         if (current->vx_info)
13                 return &current->vx_info->cvirt.utsname;
14         return &system_utsname;
15 }
16
17 #define vx_new_uts(x)           ((vx_new_utsname())->x)
18
19
20 /* pid faking stuff */
21
22
23 #define vx_info_map_pid(v,p) \
24         __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
25 #define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
26 #define vx_map_pid(p)   vx_info_map_pid(current->vx_info, p)
27 #define vx_map_tgid(p) vx_map_pid(p)
28
29 static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
30         const char *func, const char *file, int line)
31 {
32         if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
33                 vxfprintk(VXD_CBIT(cvirt, 2),
34                         "vx_map_tgid: %p/%llx: %d -> %d",
35                         vxi, (long long)vxi->vx_flags, pid,
36                         (pid && pid == vxi->vx_initpid)?1:pid,
37                         func, file, line);
38                 if (pid == 0)
39                         return 0;
40                 if (pid == vxi->vx_initpid)
41                         return 1;
42         }
43         return pid;
44 }
45
46 #define vx_info_rmap_pid(v,p) \
47         __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
48 #define vx_rmap_pid(p)  vx_info_rmap_pid(current->vx_info, p)
49 #define vx_rmap_tgid(p) vx_rmap_pid(p)
50
51 static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
52         const char *func, const char *file, int line)
53 {
54         if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
55                 vxfprintk(VXD_CBIT(cvirt, 2),
56                         "vx_rmap_tgid: %p/%llx: %d -> %d",
57                         vxi, (long long)vxi->vx_flags, pid,
58                         (pid == 1)?vxi->vx_initpid:pid,
59                         func, file, line);
60                 if ((pid == 1) && vxi->vx_initpid)
61                         return vxi->vx_initpid;
62                 if (pid == vxi->vx_initpid)
63                         return ~0U;
64         }
65         return pid;
66 }
67
68
69 static inline void vx_activate_task(struct task_struct *p)
70 {
71         struct vx_info *vxi;
72
73         if ((vxi = p->vx_info)) {
74                 vx_update_load(vxi);
75                 atomic_inc(&vxi->cvirt.nr_running);
76         }
77 }
78
79 static inline void vx_deactivate_task(struct task_struct *p)
80 {
81         struct vx_info *vxi;
82
83         if ((vxi = p->vx_info)) {
84                 vx_update_load(vxi);
85                 atomic_dec(&vxi->cvirt.nr_running);
86         }
87 }
88
89 static inline void vx_uninterruptible_inc(struct task_struct *p)
90 {
91         struct vx_info *vxi;
92
93         if ((vxi = p->vx_info))
94                 atomic_inc(&vxi->cvirt.nr_uninterruptible);
95 }
96
97 static inline void vx_uninterruptible_dec(struct task_struct *p)
98 {
99         struct vx_info *vxi;
100
101         if ((vxi = p->vx_info))
102                 atomic_dec(&vxi->cvirt.nr_uninterruptible);
103 }
104
105
106 struct inode;
107
108 #define VXF_FAKE_INIT   (VXF_INFO_INIT|VXF_STATE_INIT)
109
110 static inline
111 int proc_pid_visible(struct task_struct *task, int pid)
112 {
113         if ((pid == 1) &&
114                 !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
115                 /* show a blend through init */
116                 goto visible;
117         if (vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
118                 goto visible;
119         return 0;
120 visible:
121         return 1;
122 }
123
124 static inline
125 struct task_struct *find_proc_task_by_pid(int pid)
126 {
127         struct task_struct *task = find_task_by_pid(pid);
128
129         if (task && !proc_pid_visible(task, pid)) {
130                 vxdprintk(VXD_CBIT(misc, 6),
131                         "dropping task %p[#%u,%u] for %p[#%u,%u]",
132                         task, task->xid, task->pid,
133                         current, current->xid, current->pid);
134                 task = NULL;
135         }
136         return task;
137 }
138
139 static inline
140 struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
141 {
142         struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
143
144         if (task && !proc_pid_visible(task, pid->nr)) {
145                 vxdprintk(VXD_CBIT(misc, 6),
146                         "dropping task %p[#%u,%u] for %p[#%u,%u]",
147                         task, task->xid, task->pid,
148                         current, current->xid, current->pid);
149                 task = NULL;
150         }
151         return task;
152 }
153
154 #else
155 #warning duplicate inclusion
156 #endif