7 #include <linux/kernel.h>
8 #include <linux/rcupdate.h>
9 #include <linux/sched.h>
11 #include "vserver/context.h"
12 #include "vserver/limit.h"
17 #define VX_DEBUG_ACC_FILE 0
18 #define VX_DEBUG_ACC_OPENFD 0
20 #if (VX_DEBUG_ACC_FILE) || (VX_DEBUG_ACC_OPENFD)
21 #define vxdprintk(x...) printk("vxd: " x)
23 #define vxdprintk(x...)
27 #define vx_acc_cres(v,d,r) \
28 __vx_acc_cres((v), (r), (d), __FILE__, __LINE__)
30 static inline void __vx_acc_cres(struct vx_info *vxi,
31 int res, int dir, char *file, int line)
34 if ((res == RLIMIT_NOFILE && VX_DEBUG_ACC_FILE) ||
35 (res == RLIMIT_OPENFD && VX_DEBUG_ACC_OPENFD))
36 printk("vx_acc_cres[%5d,%2d]: %5d%s in %s:%d\n",
37 (vxi?vxi->vx_id:-1), res,
38 (vxi?atomic_read(&vxi->limit.rcur[res]):0),
39 (dir>0)?"++":"--", file, line);
41 atomic_inc(&vxi->limit.rcur[res]);
43 atomic_dec(&vxi->limit.rcur[res]);
47 #define vx_nproc_inc(p) vx_acc_cres(current->vx_info, 1, RLIMIT_NPROC)
48 #define vx_nproc_dec(p) vx_acc_cres(current->vx_info,-1, RLIMIT_NPROC)
50 #define vx_files_inc(f) vx_acc_cres(current->vx_info, 1, RLIMIT_NOFILE)
51 #define vx_files_dec(f) vx_acc_cres(current->vx_info,-1, RLIMIT_NOFILE)
53 #define vx_openfd_inc(f) vx_acc_cres(current->vx_info, 1, RLIMIT_OPENFD)
54 #define vx_openfd_dec(f) vx_acc_cres(current->vx_info,-1, RLIMIT_OPENFD)
57 #define vx_openfd_inc(f) do { \
58 vx_acc_cres(current->vx_info, 1, RLIMIT_OPENFD); \
59 printk("vx_openfd_inc: %d[#%d] in %s:%d\n", \
60 f, current->xid, __FILE__, __LINE__); \
63 #define vx_openfd_dec(f) do { \
64 vx_acc_cres(current->vx_info,-1, RLIMIT_OPENFD); \
65 printk("vx_openfd_dec: %d[#%d] in %s:%d\n", \
66 f, current->xid, __FILE__, __LINE__); \
70 #define vx_cres_avail(v,n,r) \
71 __vx_cres_avail((v), (r), (n), __FILE__, __LINE__)
73 static inline int __vx_cres_avail(struct vx_info *vxi,
74 int res, int num, char *file, int line)
78 if ((res == RLIMIT_NOFILE && VX_DEBUG_ACC_FILE) ||
79 (res == RLIMIT_OPENFD && VX_DEBUG_ACC_OPENFD))
80 printk("vx_cres_avail[%5d,%2d]: %5ld > %5d + %5d in %s:%d\n",
81 (vxi?vxi->vx_id:-1), res,
82 (vxi?vxi->limit.rlim[res]:1),
83 (vxi?atomic_read(&vxi->limit.rcur[res]):0),
87 value = atomic_read(&vxi->limit.rcur[res]);
88 if (value > vxi->limit.rmax[res])
89 vxi->limit.rmax[res] = value;
90 if (vxi->limit.rlim[res] == RLIM_INFINITY)
92 if (value + num <= vxi->limit.rlim[res])
94 atomic_inc(&vxi->limit.lhit[res]);
98 #define vx_nproc_avail(n) \
99 vx_cres_avail(current->vx_info, (n), RLIMIT_NPROC)
101 #define vx_files_avail(n) \
102 vx_cres_avail(current->vx_info, (n), RLIMIT_NOFILE)
104 #define vx_openfd_avail(n) \
105 vx_cres_avail(current->vx_info, (n), RLIMIT_OPENFD)
110 #define vx_sock_inc(f) vx_acc_cres(current->vx_info, 1, VLIMIT_SOCK)
111 #define vx_sock_dec(f) vx_acc_cres(current->vx_info,-1, VLIMIT_SOCK)
113 #define vx_sock_avail(n) \
114 vx_cres_avail(current->vx_info, (n), VLIMIT_SOCK)
118 #warning duplicate inclusion