This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / linux / vserver / limit.h
1 #if     defined(__KERNEL__) && defined(_VX_INFO_DEF_)
2
3 #include <asm/atomic.h>
4 #include <asm/resource.h>
5
6 /* context sub struct */
7
8 #define RLIMIT_OPENFD   12
9
10 #define NUM_RLIMITS     16
11
12 #define VLIMIT_SOCK     16
13
14
15 struct _vx_limit {
16         atomic_t ticks;
17
18         unsigned long rlim[NUM_RLIMITS];        /* Per context limit */
19         atomic_t res[NUM_RLIMITS];              /* Current value */
20 };
21
22 static inline void vx_info_init_limit(struct _vx_limit *limit)
23 {
24         int lim;
25
26         for (lim=0; lim<NUM_RLIMITS; lim++) {
27                 limit->rlim[lim] = RLIM_INFINITY;
28                 atomic_set(&limit->res[lim], 0);
29         }
30 }
31
32 extern unsigned int vx_debug_limit;
33
34 static inline void vx_info_exit_limit(struct _vx_limit *limit)
35 {
36         int lim, value;
37
38         for (lim=0; lim<NUM_RLIMITS; lim++) {
39                 value = atomic_read(&limit->res[lim]);
40                 if (value && vx_debug_limit)
41                         printk("!!! limit: %p[%d] = %d on exit.\n",
42                                 limit, lim, value);
43         }
44 }
45
46
47 static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
48 {
49         return sprintf(buffer,
50                 "PROC:\t%8d/%ld\n"
51                 "VM:\t%8d/%ld\n"
52                 "VML:\t%8d/%ld\n"               
53                 "RSS:\t%8d/%ld\n"
54                 "FILES:\t%8d/%ld\n"
55                 "OFD:\t%8d/%ld\n"
56                 ,atomic_read(&limit->res[RLIMIT_NPROC])
57                 ,limit->rlim[RLIMIT_NPROC]
58                 ,atomic_read(&limit->res[RLIMIT_AS])
59                 ,limit->rlim[RLIMIT_AS]
60                 ,atomic_read(&limit->res[RLIMIT_MEMLOCK])
61                 ,limit->rlim[RLIMIT_MEMLOCK]
62                 ,atomic_read(&limit->res[RLIMIT_RSS])
63                 ,limit->rlim[RLIMIT_RSS]
64                 ,atomic_read(&limit->res[RLIMIT_NOFILE])
65                 ,limit->rlim[RLIMIT_NOFILE]
66                 ,atomic_read(&limit->res[RLIMIT_OPENFD])
67                 ,limit->rlim[RLIMIT_OPENFD]
68                 );
69 }
70
71 #else   /* _VX_INFO_DEF_ */
72 #ifndef _VX_LIMIT_H
73 #define _VX_LIMIT_H
74
75 #include "switch.h"
76
77 /*  rlimit vserver commands */
78
79 #define VCMD_get_rlimit         VC_CMD(RLIMIT, 1, 0)
80 #define VCMD_set_rlimit         VC_CMD(RLIMIT, 2, 0)
81 #define VCMD_get_rlimit_mask    VC_CMD(RLIMIT, 3, 0)
82
83 struct  vcmd_ctx_rlimit_v0 {
84         uint32_t id;
85         uint64_t minimum;
86         uint64_t softlimit;
87         uint64_t maximum;
88 };
89
90 struct  vcmd_ctx_rlimit_mask_v0 {
91         uint32_t minimum;
92         uint32_t softlimit;
93         uint32_t maximum;
94 };
95
96 #define CRLIM_UNSET             (0ULL)
97 #define CRLIM_INFINITY          (~0ULL)
98 #define CRLIM_KEEP              (~1ULL)
99
100 #ifdef  __KERNEL__
101
102 #include <linux/compiler.h>
103
104 extern int vc_get_rlimit(uint32_t, void __user *);
105 extern int vc_set_rlimit(uint32_t, void __user *);
106 extern int vc_get_rlimit_mask(uint32_t, void __user *);
107
108 struct sysinfo;
109
110 void vx_vsi_meminfo(struct sysinfo *);
111 void vx_vsi_swapinfo(struct sysinfo *);
112
113
114 #endif  /* __KERNEL__ */
115
116 #endif  /* _VX_LIMIT_H */
117 #endif