4 #include <linux/kernel.h>
5 #include <linux/rcupdate.h>
6 #include <linux/sched.h>
8 #include "vserver/context.h"
9 #include "vserver/limit.h"
10 #include "vserver/debug.h"
16 static inline void __vx_acc_cres(struct vx_info *vxi,
17 int res, int dir, void *_data, char *_file, int _line)
19 if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
20 VXD_RLIMIT(res, RLIMIT_NPROC) ||
21 VXD_RLIMIT(res, VLIMIT_NSOCK))
22 vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5d%s (%p)",
23 (vxi?vxi->vx_id:-1), vlimit_name[res], res,
24 (vxi?atomic_read(&vxi->limit.rcur[res]):0),
25 (dir>0)?"++":"--", _data, _file, _line);
28 atomic_inc(&vxi->limit.rcur[res]);
30 atomic_dec(&vxi->limit.rcur[res]);
34 #define vx_acc_cres(v,d,p,r) \
35 __vx_acc_cres((v), (r), (d), (p), __FILE__, __LINE__)
37 #define vx_acc_cres_cond(x,d,p,r) \
38 __vx_acc_cres(((x) == current->xid) ? current->vx_info : 0,\
39 (r), (d), (p), __FILE__, __LINE__)
41 #define vx_nproc_inc(p) \
42 vx_acc_cres((p)->vx_info, 1, (p), RLIMIT_NPROC)
44 #define vx_nproc_dec(p) \
45 vx_acc_cres((p)->vx_info,-1, (p), RLIMIT_NPROC)
47 #define vx_files_inc(f) \
48 vx_acc_cres_cond((f)->f_xid, 1, (f), RLIMIT_NOFILE)
50 #define vx_files_dec(f) \
51 vx_acc_cres_cond((f)->f_xid,-1, (f), RLIMIT_NOFILE)
54 #define vx_cres_avail(v,n,r) \
55 __vx_cres_avail((v), (r), (n), __FILE__, __LINE__)
57 static inline int __vx_cres_avail(struct vx_info *vxi,
58 int res, int num, char *_file, int _line)
62 if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
63 VXD_RLIMIT(res, RLIMIT_NPROC) ||
64 VXD_RLIMIT(res, VLIMIT_NSOCK))
65 vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d",
66 (vxi?vxi->vx_id:-1), vlimit_name[res], res,
67 (vxi?vxi->limit.rlim[res]:1),
68 (vxi?atomic_read(&vxi->limit.rcur[res]):0),
72 value = atomic_read(&vxi->limit.rcur[res]);
73 if (value > vxi->limit.rmax[res])
74 vxi->limit.rmax[res] = value;
75 if (vxi->limit.rlim[res] == RLIM_INFINITY)
77 if (value + num <= vxi->limit.rlim[res])
79 atomic_inc(&vxi->limit.lhit[res]);
83 #define vx_nproc_avail(n) \
84 vx_cres_avail(current->vx_info, (n), RLIMIT_NPROC)
86 #define vx_files_avail(n) \
87 vx_cres_avail(current->vx_info, (n), RLIMIT_NOFILE)
92 #define vx_sock_inc(s) \
93 vx_acc_cres((s)->sk_vx_info, 1, (s), VLIMIT_NSOCK)
94 #define vx_sock_dec(s) \
95 vx_acc_cres((s)->sk_vx_info,-1, (s), VLIMIT_NSOCK)
97 #define vx_sock_avail(n) \
98 vx_cres_avail(current->vx_info, (n), VLIMIT_NSOCK)
101 #warning duplicate inclusion