vserver 1.9.5.x5
[linux-2.6.git] / include / linux / vs_limit.h
index 3098797..4078538 100644 (file)
@@ -1,24 +1,26 @@
 #ifndef _VX_VS_LIMIT_H
 #define _VX_VS_LIMIT_H
 
-#include <linux/kernel.h>
-#include <linux/rcupdate.h>
-#include <linux/sched.h>
 
-#include "vserver/context.h"
 #include "vserver/limit.h"
 #include "vserver/debug.h"
 
 
-/* file limits */
+#define vx_acc_cres(v,d,p,r) \
+       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
 
+#define vx_acc_cres_cond(x,d,p,r) \
+       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
+       r, d, p, __FILE__, __LINE__)
 
 static inline void __vx_acc_cres(struct vx_info *vxi,
        int res, int dir, void *_data, char *_file, int _line)
 {
        if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
                VXD_RLIMIT(res, RLIMIT_NPROC) ||
-               VXD_RLIMIT(res, VLIMIT_NSOCK))
+               VXD_RLIMIT(res, RLIMIT_LOCKS) ||
+               VXD_RLIMIT(res, VLIMIT_NSOCK) ||
+               VXD_RLIMIT(res, VLIMIT_OPENFD))
                vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5d%s (%p)",
                        (vxi?vxi->vx_id:-1), vlimit_name[res], res,
                        (vxi?atomic_read(&vxi->limit.rcur[res]):0),
@@ -31,28 +33,60 @@ static inline void __vx_acc_cres(struct vx_info *vxi,
        }
 }
 
-#define vx_acc_cres(v,d,p,r) \
-       __vx_acc_cres((v), (r), (d), (p), __FILE__, __LINE__)
+#define vx_add_cres(v,a,p,r) \
+       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
+#define        vx_sub_cres(v,a,p,r)            vx_add_cres(v,-(a),p,r)
 
-#define vx_acc_cres_cond(x,d,p,r) \
-       __vx_acc_cres(((x) == current->xid) ? current->vx_info : 0,\
-       (r), (d), (p), __FILE__, __LINE__)
+#define vx_add_cres_cond(x,a,p,r) \
+       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
+       r, a, p, __FILE__, __LINE__)
+#define        vx_sub_cres_cond(x,a,p,r)       vx_add_cres_cond(x,-(a),p,r)
+
+
+static inline void __vx_add_cres(struct vx_info *vxi,
+       int res, int amount, void *_data, char *_file, int _line)
+{
+       if (VXD_RLIMIT(res, RLIMIT_MSGQUEUE))
+               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5d += %5d (%p)",
+                       (vxi?vxi->vx_id:-1), vlimit_name[res], res,
+                       (vxi?atomic_read(&vxi->limit.rcur[res]):0),
+                       amount, _data, _file, _line);
+       if (amount == 0)
+               return;
+       if (vxi)
+               atomic_add(amount, &vxi->limit.rcur[res]);
+}
+
+
+/* process and file limits */
 
 #define vx_nproc_inc(p) \
-       vx_acc_cres((p)->vx_info, 1, (p), RLIMIT_NPROC)
+       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
 
 #define vx_nproc_dec(p) \
-       vx_acc_cres((p)->vx_info,-1, (p), RLIMIT_NPROC)
+       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
 
 #define vx_files_inc(f) \
-       vx_acc_cres_cond((f)->f_xid, 1, (f), RLIMIT_NOFILE)
+       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
 
 #define vx_files_dec(f) \
-       vx_acc_cres_cond((f)->f_xid,-1, (f), RLIMIT_NOFILE)
+       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
+
+#define vx_locks_inc(l) \
+       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
+
+#define vx_locks_dec(l) \
+       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
+
+#define vx_openfd_inc(f) \
+       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
+
+#define vx_openfd_dec(f) \
+       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
 
 
 #define vx_cres_avail(v,n,r) \
-       __vx_cres_avail((v), (r), (n), __FILE__, __LINE__)
+       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
 
 static inline int __vx_cres_avail(struct vx_info *vxi,
                int res, int num, char *_file, int _line)
@@ -61,7 +95,8 @@ static inline int __vx_cres_avail(struct vx_info *vxi,
 
        if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
                VXD_RLIMIT(res, RLIMIT_NPROC) ||
-               VXD_RLIMIT(res, VLIMIT_NSOCK))
+               VXD_RLIMIT(res, VLIMIT_NSOCK) ||
+               VXD_RLIMIT(res, VLIMIT_OPENFD))
                vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d",
                        (vxi?vxi->vx_id:-1), vlimit_name[res], res,
                        (vxi?vxi->limit.rlim[res]:1),
@@ -81,21 +116,51 @@ static inline int __vx_cres_avail(struct vx_info *vxi,
 }
 
 #define vx_nproc_avail(n) \
-       vx_cres_avail(current->vx_info, (n), RLIMIT_NPROC)
+       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
 
 #define vx_files_avail(n) \
-       vx_cres_avail(current->vx_info, (n), RLIMIT_NOFILE)
+       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
+
+#define vx_locks_avail(n) \
+       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
+
+#define vx_openfd_avail(n) \
+       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
 
 
 /* socket limits */
 
 #define vx_sock_inc(s) \
-       vx_acc_cres((s)->sk_vx_info, 1, (s), VLIMIT_NSOCK)
+       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
+
 #define vx_sock_dec(s) \
-       vx_acc_cres((s)->sk_vx_info,-1, (s), VLIMIT_NSOCK)
+       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
 
 #define vx_sock_avail(n) \
-       vx_cres_avail(current->vx_info, (n), VLIMIT_NSOCK)
+       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
+
+
+/* ipc resource limits */
+
+#define vx_ipcmsg_add(v,u,a) \
+       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
+
+#define vx_ipcmsg_sub(v,u,a) \
+       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
+
+#define vx_ipcmsg_avail(v,a) \
+       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
+
+
+#define vx_ipcshm_add(v,k,a) \
+       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
+
+#define vx_ipcshm_sub(v,k,a) \
+       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
+
+#define vx_ipcshm_avail(v,a) \
+       vx_cres_avail(v, a, VLIMIT_SHMEM)
+
 
 #else
 #warning duplicate inclusion