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_nproc_inc(p) \
38 vx_acc_cres(current->vx_info, 1, (p), RLIMIT_NPROC)
39 #define vx_nproc_dec(p) \
40 vx_acc_cres(current->vx_info,-1, (p), RLIMIT_NPROC)
42 #define vx_files_inc(f) \
43 vx_acc_cres(current->vx_info, 1, (f), RLIMIT_NOFILE)
44 #define vx_files_dec(f) \
45 vx_acc_cres(current->vx_info,-1, (f), RLIMIT_NOFILE)
48 #define vx_openfd_inc(f) do { \
49 vx_acc_cres(current->vx_info, 1, RLIMIT_OPENFD); \
50 printk("vx_openfd_inc: %d[#%d] in %s:%d\n", \
51 f, current->xid, __FILE__, __LINE__); \
54 #define vx_openfd_dec(f) do { \
55 vx_acc_cres(current->vx_info,-1, RLIMIT_OPENFD); \
56 printk("vx_openfd_dec: %d[#%d] in %s:%d\n", \
57 f, current->xid, __FILE__, __LINE__); \
61 #define vx_cres_avail(v,n,r) \
62 __vx_cres_avail((v), (r), (n), __FILE__, __LINE__)
64 static inline int __vx_cres_avail(struct vx_info *vxi,
65 int res, int num, char *_file, int _line)
69 if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
70 VXD_RLIMIT(res, RLIMIT_NPROC) ||
71 VXD_RLIMIT(res, VLIMIT_NSOCK))
72 vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d",
73 (vxi?vxi->vx_id:-1), vlimit_name[res], res,
74 (vxi?vxi->limit.rlim[res]:1),
75 (vxi?atomic_read(&vxi->limit.rcur[res]):0),
79 value = atomic_read(&vxi->limit.rcur[res]);
80 if (value > vxi->limit.rmax[res])
81 vxi->limit.rmax[res] = value;
82 if (vxi->limit.rlim[res] == RLIM_INFINITY)
84 if (value + num <= vxi->limit.rlim[res])
86 atomic_inc(&vxi->limit.lhit[res]);
90 #define vx_nproc_avail(n) \
91 vx_cres_avail(current->vx_info, (n), RLIMIT_NPROC)
93 #define vx_files_avail(n) \
94 vx_cres_avail(current->vx_info, (n), RLIMIT_NOFILE)
99 #define vx_sock_inc(s) \
100 vx_acc_cres((s)->sk_vx_info, 1, (s), VLIMIT_NSOCK)
101 #define vx_sock_dec(s) \
102 vx_acc_cres((s)->sk_vx_info,-1, (s), VLIMIT_NSOCK)
104 #define vx_sock_avail(n) \
105 vx_cres_avail(current->vx_info, (n), VLIMIT_NSOCK)
108 #warning duplicate inclusion