This commit was manufactured by cvs2svn to create tag 'before-xenU'.
[linux-2.6.git] / include / linux / vs_limit.h
1 #ifndef _VX_VS_LIMIT_H
2 #define _VX_VS_LIMIT_H
3
4
5 #include "vserver/limit.h"
6 #include "vserver/debug.h"
7
8
9 #define vx_acc_cres(v,d,p,r) \
10         __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
11
12 #define vx_acc_cres_cond(x,d,p,r) \
13         __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
14         r, d, p, __FILE__, __LINE__)
15
16 static inline void __vx_acc_cres(struct vx_info *vxi,
17         int res, int dir, void *_data, char *_file, int _line)
18 {
19         if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
20                 VXD_RLIMIT(res, RLIMIT_NPROC) ||
21                 VXD_RLIMIT(res, RLIMIT_LOCKS) ||
22                 VXD_RLIMIT(res, VLIMIT_NSOCK) ||
23                 VXD_RLIMIT(res, VLIMIT_OPENFD))
24                 vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5d%s (%p)",
25                         (vxi?vxi->vx_id:-1), vlimit_name[res], res,
26                         (vxi?atomic_read(&vxi->limit.rcur[res]):0),
27                         (dir>0)?"++":"--", _data, _file, _line);
28         if (vxi) {
29                 if (dir > 0)
30                         atomic_inc(&vxi->limit.rcur[res]);
31                 else
32                         atomic_dec(&vxi->limit.rcur[res]);
33         }
34 }
35
36 #define vx_add_cres(v,a,p,r) \
37         __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
38 #define vx_sub_cres(v,a,p,r)            vx_add_cres(v,-(a),p,r)
39
40 #define vx_add_cres_cond(x,a,p,r) \
41         __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
42         r, a, p, __FILE__, __LINE__)
43 #define vx_sub_cres_cond(x,a,p,r)       vx_add_cres_cond(x,-(a),p,r)
44
45
46 static inline void __vx_add_cres(struct vx_info *vxi,
47         int res, int amount, void *_data, char *_file, int _line)
48 {
49         if (VXD_RLIMIT(res, RLIMIT_MSGQUEUE))
50                 vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5d += %5d (%p)",
51                         (vxi?vxi->vx_id:-1), vlimit_name[res], res,
52                         (vxi?atomic_read(&vxi->limit.rcur[res]):0),
53                         amount, _data, _file, _line);
54         if (amount == 0)
55                 return;
56         if (vxi)
57                 atomic_add(amount, &vxi->limit.rcur[res]);
58 }
59
60 /* process and file limits */
61
62 #define vx_nproc_inc(p) \
63         vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
64
65 #define vx_nproc_dec(p) \
66         vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
67
68 #define vx_files_inc(f) \
69         vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
70
71 #define vx_files_dec(f) \
72         vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
73
74 #define vx_locks_inc(l) \
75         vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
76
77 #define vx_locks_dec(l) \
78         vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
79
80 #define vx_openfd_inc(f) \
81         vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
82
83 #define vx_openfd_dec(f) \
84         vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
85
86
87 #define vx_cres_avail(v,n,r) \
88         __vx_cres_avail(v, r, n, __FILE__, __LINE__)
89
90 static inline int __vx_cres_avail(struct vx_info *vxi,
91                 int res, int num, char *_file, int _line)
92 {
93         unsigned long value;
94
95         if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
96                 VXD_RLIMIT(res, RLIMIT_NPROC) ||
97                 VXD_RLIMIT(res, VLIMIT_NSOCK) ||
98                 VXD_RLIMIT(res, VLIMIT_OPENFD))
99                 vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d",
100                         (vxi?vxi->vx_id:-1), vlimit_name[res], res,
101                         (vxi?vxi->limit.rlim[res]:1),
102                         (vxi?atomic_read(&vxi->limit.rcur[res]):0),
103                         num, _file, _line);
104         if (!vxi)
105                 return 1;
106         value = atomic_read(&vxi->limit.rcur[res]);
107         if (value > vxi->limit.rmax[res])
108                 vxi->limit.rmax[res] = value;
109         if (vxi->limit.rlim[res] == RLIM_INFINITY)
110                 return 1;
111         if (value + num <= vxi->limit.rlim[res])
112                 return 1;
113         atomic_inc(&vxi->limit.lhit[res]);
114         return 0;
115 }
116
117 #define vx_nproc_avail(n) \
118         vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
119
120 #define vx_files_avail(n) \
121         vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
122
123 #define vx_locks_avail(n) \
124         vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
125
126 #define vx_openfd_avail(n) \
127         vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
128
129 /* socket limits */
130
131 #define vx_sock_inc(s) \
132         vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
133
134 #define vx_sock_dec(s) \
135         vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
136
137 #define vx_sock_avail(n) \
138         vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
139
140
141 /* ipc resource limits */
142
143 #define vx_ipcmsg_add(v,u,a) \
144         vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
145
146 #define vx_ipcmsg_sub(v,u,a) \
147         vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
148
149 #define vx_ipcmsg_avail(v,a) \
150         vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
151
152
153 #define vx_ipcshm_add(v,k,a) \
154         vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
155
156 #define vx_ipcshm_sub(v,k,a) \
157         vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
158
159 #define vx_ipcshm_avail(v,a) \
160         vx_cres_avail(v, a, VLIMIT_SHMEM)
161
162
163 #else
164 #warning duplicate inclusion
165 #endif