This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / linux / vs_pid.h
1 #ifndef _VS_PID_H
2 #define _VS_PID_H
3
4 #include "vserver/base.h"
5 #include "vserver/context.h"
6 #include "vserver/debug.h"
7 #include <linux/pid_namespace.h>
8
9
10 /* pid faking stuff */
11
12
13 #define vx_info_map_pid(v,p) \
14         __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
15 #define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
16 #define vx_map_pid(p)   vx_info_map_pid(current->vx_info, p)
17 #define vx_map_tgid(p) vx_map_pid(p)
18
19 static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
20         const char *func, const char *file, int line)
21 {
22         if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
23                 vxfprintk(VXD_CBIT(cvirt, 2),
24                         "vx_map_tgid: %p/%llx: %d -> %d",
25                         vxi, (long long)vxi->vx_flags, pid,
26                         (pid && pid == vxi->vx_initpid)?1:pid,
27                         func, file, line);
28                 if (pid == 0)
29                         return 0;
30                 if (pid == vxi->vx_initpid)
31                         return 1;
32         }
33         return pid;
34 }
35
36 #define vx_info_rmap_pid(v,p) \
37         __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
38 #define vx_rmap_pid(p)  vx_info_rmap_pid(current->vx_info, p)
39 #define vx_rmap_tgid(p) vx_rmap_pid(p)
40
41 static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
42         const char *func, const char *file, int line)
43 {
44         if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
45                 vxfprintk(VXD_CBIT(cvirt, 2),
46                         "vx_rmap_tgid: %p/%llx: %d -> %d",
47                         vxi, (long long)vxi->vx_flags, pid,
48                         (pid == 1)?vxi->vx_initpid:pid,
49                         func, file, line);
50                 if ((pid == 1) && vxi->vx_initpid)
51                         return vxi->vx_initpid;
52                 if (pid == vxi->vx_initpid)
53                         return ~0U;
54         }
55         return pid;
56 }
57
58
59 #define VXF_FAKE_INIT   (VXF_INFO_INIT|VXF_STATE_INIT)
60
61 static inline
62 int vx_proc_task_visible(struct task_struct *task)
63 {
64         if ((task->pid == 1) &&
65                 !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
66                 /* show a blend through init */
67                 goto visible;
68         if (vx_check(vx_task_xid(task), VS_WATCH|VS_IDENT))
69                 goto visible;
70         return 0;
71 visible:
72         return 1;
73 }
74
75 static inline
76 struct task_struct *vx_find_proc_task_by_pid(int pid)
77 {
78         struct task_struct *task = find_task_by_real_pid(pid);
79
80         if (task && !vx_proc_task_visible(task)) {
81                 vxdprintk(VXD_CBIT(misc, 6),
82                         "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
83                         task, task->xid, task->pid,
84                         current, current->xid, current->pid);
85                 task = NULL;
86         }
87         return task;
88 }
89
90 static inline
91 struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
92 {
93         struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
94
95         if (task && !vx_proc_task_visible(task)) {
96                 vxdprintk(VXD_CBIT(misc, 6),
97                         "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
98                         task, task->xid, task->pid,
99                         current, current->xid, current->pid);
100                 put_task_struct(task);
101                 task = NULL;
102         }
103         return task;
104 }
105
106
107 static inline
108 struct task_struct *vx_child_reaper(struct task_struct *p)
109 {
110         struct vx_info *vxi = p->vx_info;
111         struct task_struct *reaper = child_reaper(p);
112
113         if (!vxi)
114                 goto out;
115
116         BUG_ON(!p->vx_info->vx_reaper);
117
118         /* child reaper for the guest reaper */
119         if (vxi->vx_reaper == p)
120                 goto out;
121
122         reaper = vxi->vx_reaper;
123 out:
124         vxdprintk(VXD_CBIT(xid, 7),
125                 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
126                 p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
127         return reaper;
128 }
129
130
131 #else
132 #warning duplicate inclusion
133 #endif