initial checkin
[util-vserver.git] / util-vserver / kernel / 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 struct _vx_limit {
9         atomic_t ticks;
10
11         unsigned long rlim[RLIM_NLIMITS];       /* Per context limit */
12         atomic_t res[RLIM_NLIMITS];             /* Current value */
13 };
14
15 static inline void vx_info_init_limit(struct _vx_limit *limit)
16 {
17         int lim;
18
19         for (lim=0; lim<RLIM_NLIMITS; lim++)
20                 limit->rlim[lim] = RLIM_INFINITY;
21 }
22
23 static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
24 {
25         return sprintf(buffer,
26                 "PROC:\t%8d/%ld\n"
27                 "VM:\t%8d/%ld\n"
28                 "VML:\t%8d/%ld\n"               
29                 "RSS:\t%8d/%ld\n"
30                 ,atomic_read(&limit->res[RLIMIT_NPROC])
31                 ,limit->rlim[RLIMIT_NPROC]
32                 ,atomic_read(&limit->res[RLIMIT_AS])
33                 ,limit->rlim[RLIMIT_AS]
34                 ,atomic_read(&limit->res[RLIMIT_MEMLOCK])
35                 ,limit->rlim[RLIMIT_MEMLOCK]
36                 ,atomic_read(&limit->res[RLIMIT_RSS])
37                 ,limit->rlim[RLIMIT_RSS]
38                 );
39 }
40
41 #else   /* _VX_INFO_DEF_ */
42 #ifndef _VX_LIMIT_H
43 #define _VX_LIMIT_H
44
45 #include "switch.h"
46
47 /*  rlimit vserver commands */
48
49 #define VCMD_get_rlimit         VC_CMD(RLIMIT, 1, 0)
50 #define VCMD_set_rlimit         VC_CMD(RLIMIT, 2, 0)
51 #define VCMD_get_rlimit_mask    VC_CMD(RLIMIT, 3, 0)
52
53 struct  vcmd_ctx_rlimit_v0 {
54         uint32_t id;
55         uint64_t minimum;
56         uint64_t softlimit;
57         uint64_t maximum;
58 };
59
60 struct  vcmd_ctx_rlimit_mask_v0 {
61         uint32_t minimum;
62         uint32_t softlimit;
63         uint32_t maximum;
64 };
65
66 #define CRLIM_UNSET             (0ULL)
67 #define CRLIM_INFINITY          (~0ULL)
68 #define CRLIM_KEEP              (~1ULL)
69
70 #ifdef  __KERNEL__
71 extern int vc_get_rlimit(uint32_t, void *);
72 extern int vc_set_rlimit(uint32_t, void *);
73 extern int vc_get_rlimit_mask(uint32_t, void *);
74
75 struct sysinfo;
76
77 void vx_vsi_meminfo(struct sysinfo *);
78 void vx_vsi_swapinfo(struct sysinfo *);
79
80 #endif  /* __KERNEL__ */
81
82 #endif  /* _VX_LIMIT_H */
83 #endif