fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / linux / vs_limit.h
index 4078538..25d6756 100644 (file)
@@ -1,9 +1,12 @@
-#ifndef _VX_VS_LIMIT_H
-#define _VX_VS_LIMIT_H
-
+#ifndef _VS_LIMIT_H
+#define _VS_LIMIT_H
 
 #include "vserver/limit.h"
+#include "vserver/base.h"
+#include "vserver/context.h"
 #include "vserver/debug.h"
+#include "vserver/context.h"
+#include "vserver/limit_int.h"
 
 
 #define vx_acc_cres(v,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, 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),
-                       (dir>0)?"++":"--", _data, _file, _line);
-       if (vxi) {
-               if (dir > 0)
-                       atomic_inc(&vxi->limit.rcur[res]);
-               else
-                       atomic_dec(&vxi->limit.rcur[res]);
-       }
-}
 
 #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_sub_cres(v,a,p,r)           vx_add_cres(v,-(a),p,r)
 
 #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]);
-}
+#define vx_sub_cres_cond(x,a,p,r)      vx_add_cres_cond(x,-(a),p,r)
 
 
 /* process and file limits */
@@ -88,32 +57,6 @@ static inline void __vx_add_cres(struct vx_info *vxi,
 #define vx_cres_avail(v,n,r) \
        __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)
-{
-       unsigned long value;
-
-       if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
-               VXD_RLIMIT(res, RLIMIT_NPROC) ||
-               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),
-                       (vxi?atomic_read(&vxi->limit.rcur[res]):0),
-                       num, _file, _line);
-       if (!vxi)
-               return 1;
-       value = atomic_read(&vxi->limit.rcur[res]);
-       if (value > vxi->limit.rmax[res])
-               vxi->limit.rmax[res] = value;
-       if (vxi->limit.rlim[res] == RLIM_INFINITY)
-               return 1;
-       if (value + num <= vxi->limit.rlim[res])
-               return 1;
-       atomic_inc(&vxi->limit.lhit[res]);
-       return 0;
-}
 
 #define vx_nproc_avail(n) \
        vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
@@ -128,6 +71,22 @@ static inline int __vx_cres_avail(struct vx_info *vxi,
        vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
 
 
+/* dentry limits */
+
+#define vx_dentry_inc(d) do {                                          \
+       if (atomic_read(&d->d_count) == 1)                              \
+               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
+       } while (0)
+
+#define vx_dentry_dec(d) do {                                          \
+       if (atomic_read(&d->d_count) == 0)                              \
+               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
+       } while (0)
+
+#define vx_dentry_avail(n) \
+       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
+
+
 /* socket limits */
 
 #define vx_sock_inc(s) \
@@ -162,6 +121,20 @@ static inline int __vx_cres_avail(struct vx_info *vxi,
        vx_cres_avail(v, a, VLIMIT_SHMEM)
 
 
+#define vx_semary_inc(a) \
+       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
+
+#define vx_semary_dec(a) \
+       vx_acc_cres(current->vx_info,-1, a, VLIMIT_SEMARY)
+
+
+#define vx_nsems_add(a,n) \
+       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
+
+#define vx_nsems_sub(a,n) \
+       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
+
+
 #else
 #warning duplicate inclusion
 #endif