5 #include "vserver/limit.h"
6 #include "vserver/debug.h"
9 #define vx_acc_cres(v,d,p,r) \
10 __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
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__)
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, 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);
30 atomic_inc(&vxi->limit.rcur[res]);
32 atomic_dec(&vxi->limit.rcur[res]);
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)
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)
46 static inline void __vx_add_cres(struct vx_info *vxi,
47 int res, int amount, void *_data, char *_file, int _line)
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);
57 atomic_add(amount, &vxi->limit.rcur[res]);
61 /* process and file limits */
63 #define vx_nproc_inc(p) \
64 vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
66 #define vx_nproc_dec(p) \
67 vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
69 #define vx_files_inc(f) \
70 vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
72 #define vx_files_dec(f) \
73 vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
75 #define vx_locks_inc(l) \
76 vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
78 #define vx_locks_dec(l) \
79 vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
81 #define vx_openfd_inc(f) \
82 vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
84 #define vx_openfd_dec(f) \
85 vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
88 #define vx_cres_avail(v,n,r) \
89 __vx_cres_avail(v, r, n, __FILE__, __LINE__)
91 static inline int __vx_cres_avail(struct vx_info *vxi,
92 int res, int num, char *_file, int _line)
96 if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
97 VXD_RLIMIT(res, RLIMIT_NPROC) ||
98 VXD_RLIMIT(res, VLIMIT_NSOCK) ||
99 VXD_RLIMIT(res, VLIMIT_OPENFD))
100 vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d",
101 (vxi?vxi->vx_id:-1), vlimit_name[res], res,
102 (vxi?vxi->limit.rlim[res]:1),
103 (vxi?atomic_read(&vxi->limit.rcur[res]):0),
107 value = atomic_read(&vxi->limit.rcur[res]);
108 if (value > vxi->limit.rmax[res])
109 vxi->limit.rmax[res] = value;
110 if (vxi->limit.rlim[res] == RLIM_INFINITY)
112 if (value + num <= vxi->limit.rlim[res])
114 atomic_inc(&vxi->limit.lhit[res]);
118 #define vx_nproc_avail(n) \
119 vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
121 #define vx_files_avail(n) \
122 vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
124 #define vx_locks_avail(n) \
125 vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
127 #define vx_openfd_avail(n) \
128 vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
133 #define vx_sock_inc(s) \
134 vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
136 #define vx_sock_dec(s) \
137 vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
139 #define vx_sock_avail(n) \
140 vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
143 /* ipc resource limits */
145 #define vx_ipcmsg_add(v,u,a) \
146 vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
148 #define vx_ipcmsg_sub(v,u,a) \
149 vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
151 #define vx_ipcmsg_avail(v,a) \
152 vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
155 #define vx_ipcshm_add(v,k,a) \
156 vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
158 #define vx_ipcshm_sub(v,k,a) \
159 vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
161 #define vx_ipcshm_avail(v,a) \
162 vx_cres_avail(v, a, VLIMIT_SHMEM)
166 #warning duplicate inclusion