This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / linux / vserver / limit_int.h
1 #ifndef _VX_LIMIT_INT_H
2 #define _VX_LIMIT_INT_H
3
4
5 #ifdef  __KERNEL__
6
7 #define VXD_RCRES(r)    VXD_CBIT(cres, (r))
8 #define VXD_RLIMIT(r)   VXD_CBIT(limit, (r))
9
10 extern const char *vlimit_name[NUM_LIMITS];
11
12 static inline void __vx_acc_cres(struct vx_info *vxi,
13         int res, int dir, void *_data, char *_file, int _line)
14 {
15         if (VXD_RCRES(res))
16                 vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5d%s (%p)",
17                         (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
18                         (vxi ? atomic_read(&vxi->limit.rcur[res]) : 0),
19                         (dir > 0) ? "++" : "--", _data, _file, _line);
20         if (!vxi)
21                 return;
22
23         if (dir > 0)
24                 atomic_inc(&vxi->limit.rcur[res]);
25         else
26                 atomic_dec(&vxi->limit.rcur[res]);
27 }
28
29 static inline void __vx_add_cres(struct vx_info *vxi,
30         int res, int amount, void *_data, char *_file, int _line)
31 {
32         if (VXD_RCRES(res))
33                 vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5d += %5d (%p)",
34                         (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
35                         (vxi ? atomic_read(&vxi->limit.rcur[res]) : 0),
36                         amount, _data, _file, _line);
37         if (amount == 0)
38                 return;
39         if (!vxi)
40                 return;
41         atomic_add(amount, &vxi->limit.rcur[res]);
42 }
43
44 static inline int __vx_cres_avail(struct vx_info *vxi,
45                 int res, int num, char *_file, int _line)
46 {
47         unsigned long value;
48
49         if (VXD_RLIMIT(res))
50                 vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d",
51                         (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
52                         (vxi ? vxi->limit.rlim[res] : 1),
53                         (vxi ? atomic_read(&vxi->limit.rcur[res]) : 0),
54                         num, _file, _line);
55         if (num == 0)
56                 return 1;
57         if (!vxi)
58                 return 1;
59
60         value = atomic_read(&vxi->limit.rcur[res]);
61
62         if (value > vxi->limit.rmax[res])
63                 vxi->limit.rmax[res] = value;
64
65         if (vxi->limit.rlim[res] == RLIM_INFINITY)
66                 return 1;
67
68         if (value + num <= vxi->limit.rlim[res])
69                 return 1;
70
71         atomic_inc(&vxi->limit.lhit[res]);
72         return 0;
73 }
74
75 #endif  /* __KERNEL__ */
76 #endif  /* _VX_LIMIT_H */