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]);
60 /* process and file limits */
62 #define vx_nproc_inc(p) \
63 vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
65 #define vx_nproc_dec(p) \
66 vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
68 #define vx_files_inc(f) \
69 vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
71 #define vx_files_dec(f) \
72 vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
74 #define vx_locks_inc(l) \
75 vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
77 #define vx_locks_dec(l) \
78 vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
80 #define vx_openfd_inc(f) \
81 vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
83 #define vx_openfd_dec(f) \
84 vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
87 #define vx_cres_avail(v,n,r) \
88 __vx_cres_avail(v, r, n, __FILE__, __LINE__)
90 static inline int __vx_cres_avail(struct vx_info *vxi,
91 int res, int num, char *_file, int _line)
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),
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)
111 if (value + num <= vxi->limit.rlim[res])
113 atomic_inc(&vxi->limit.lhit[res]);
117 #define vx_nproc_avail(n) \
118 vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
120 #define vx_files_avail(n) \
121 vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
123 #define vx_locks_avail(n) \
124 vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
126 #define vx_openfd_avail(n) \
127 vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
131 #define vx_sock_inc(s) \
132 vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
134 #define vx_sock_dec(s) \
135 vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
137 #define vx_sock_avail(n) \
138 vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
141 /* ipc resource limits */
143 #define vx_ipcmsg_add(v,u,a) \
144 vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
146 #define vx_ipcmsg_sub(v,u,a) \
147 vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
149 #define vx_ipcmsg_avail(v,a) \
150 vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
153 #define vx_ipcshm_add(v,k,a) \
154 vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
156 #define vx_ipcshm_sub(v,k,a) \
157 vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
159 #define vx_ipcshm_avail(v,a) \
160 vx_cres_avail(v, a, VLIMIT_SHMEM)
164 #warning duplicate inclusion