fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / linux / vs_limit.h
1 #ifndef _VS_LIMIT_H
2 #define _VS_LIMIT_H
3
4 #include "vserver/limit.h"
5 #include "vserver/base.h"
6 #include "vserver/context.h"
7 #include "vserver/debug.h"
8 #include "vserver/context.h"
9 #include "vserver/limit_int.h"
10
11
12 #define vx_acc_cres(v,d,p,r) \
13         __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
14
15 #define vx_acc_cres_cond(x,d,p,r) \
16         __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
17         r, d, p, __FILE__, __LINE__)
18
19
20 #define vx_add_cres(v,a,p,r) \
21         __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
22 #define vx_sub_cres(v,a,p,r)            vx_add_cres(v,-(a),p,r)
23
24 #define vx_add_cres_cond(x,a,p,r) \
25         __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
26         r, a, p, __FILE__, __LINE__)
27 #define vx_sub_cres_cond(x,a,p,r)       vx_add_cres_cond(x,-(a),p,r)
28
29
30 /* process and file limits */
31
32 #define vx_nproc_inc(p) \
33         vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
34
35 #define vx_nproc_dec(p) \
36         vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
37
38 #define vx_files_inc(f) \
39         vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
40
41 #define vx_files_dec(f) \
42         vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
43
44 #define vx_locks_inc(l) \
45         vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
46
47 #define vx_locks_dec(l) \
48         vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
49
50 #define vx_openfd_inc(f) \
51         vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
52
53 #define vx_openfd_dec(f) \
54         vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
55
56
57 #define vx_cres_avail(v,n,r) \
58         __vx_cres_avail(v, r, n, __FILE__, __LINE__)
59
60
61 #define vx_nproc_avail(n) \
62         vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
63
64 #define vx_files_avail(n) \
65         vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
66
67 #define vx_locks_avail(n) \
68         vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
69
70 #define vx_openfd_avail(n) \
71         vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
72
73
74 /* dentry limits */
75
76 #define vx_dentry_inc(d) do {                                           \
77         if (atomic_read(&d->d_count) == 1)                              \
78                 vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
79         } while (0)
80
81 #define vx_dentry_dec(d) do {                                           \
82         if (atomic_read(&d->d_count) == 0)                              \
83                 vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
84         } while (0)
85
86 #define vx_dentry_avail(n) \
87         vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
88
89
90 /* socket limits */
91
92 #define vx_sock_inc(s) \
93         vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
94
95 #define vx_sock_dec(s) \
96         vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
97
98 #define vx_sock_avail(n) \
99         vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
100
101
102 /* ipc resource limits */
103
104 #define vx_ipcmsg_add(v,u,a) \
105         vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
106
107 #define vx_ipcmsg_sub(v,u,a) \
108         vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
109
110 #define vx_ipcmsg_avail(v,a) \
111         vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
112
113
114 #define vx_ipcshm_add(v,k,a) \
115         vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
116
117 #define vx_ipcshm_sub(v,k,a) \
118         vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
119
120 #define vx_ipcshm_avail(v,a) \
121         vx_cres_avail(v, a, VLIMIT_SHMEM)
122
123
124 #define vx_semary_inc(a) \
125         vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
126
127 #define vx_semary_dec(a) \
128         vx_acc_cres(current->vx_info,-1, a, VLIMIT_SEMARY)
129
130
131 #define vx_nsems_add(a,n) \
132         vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
133
134 #define vx_nsems_sub(a,n) \
135         vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
136
137
138 #else
139 #warning duplicate inclusion
140 #endif