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