VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / linux / vserver / cvirt.h
1 /* _VX_CVIRT_H defined below */
2
3 #if     defined(__KERNEL__) && defined(_VX_INFO_DEF_)
4
5 #include <linux/utsname.h>
6 #include <linux/rwsem.h>
7 #include <linux/jiffies.h>
8 #include <linux/time.h>
9 #include <asm/atomic.h>
10
11 /* context sub struct */
12
13 struct _vx_cvirt {
14         int max_threads;
15
16         struct timespec bias_idle;
17         uint64_t bias_jiffies;
18
19         struct new_utsname utsname;
20 };
21
22 struct sock_acc {
23         atomic_t count;
24         atomic_t total;
25 };
26
27 struct _vx_cacct {
28         atomic_t nr_threads;
29         int nr_running;
30
31         unsigned long total_forks;
32
33         struct sock_acc sock[5][3];
34 };
35
36
37 static inline long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
38 {
39         return atomic_read(&cacct->sock[type][pos].count);
40 }
41
42
43 static inline long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
44 {
45         return atomic_read(&cacct->sock[type][pos].total);
46 }
47
48
49 extern uint64_t vx_idle_jiffies(void);
50
51 static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
52 {
53         uint64_t idle_jiffies = vx_idle_jiffies();
54
55         cvirt->bias_jiffies = get_jiffies_64();
56         jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
57
58         down_read(&uts_sem);
59         cvirt->utsname = system_utsname;
60         up_read(&uts_sem);
61 }
62
63 static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
64 {
65         return;
66 }
67
68 static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
69 {
70         int i,j;
71
72         atomic_set(&cacct->nr_threads, 1);
73         for (i=0; i<5; i++) {
74                 for (j=0; j<3; j++) {
75                         atomic_set(&cacct->sock[i][j].count, 0);
76                         atomic_set(&cacct->sock[i][j].total, 0);
77                 }
78         }
79 }
80
81 static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
82 {
83         return;
84 }
85
86 static inline int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
87 {
88         int length = 0;
89         length += sprintf(buffer + length,
90                 "BiasJiffies:\t%lld\n", (long long int)cvirt->bias_jiffies);
91         length += sprintf(buffer + length,
92                 "SysName:\t%.*s\n"
93                 "NodeName:\t%.*s\n"
94                 "Release:\t%.*s\n"
95                 "Version:\t%.*s\n"
96                 "Machine:\t%.*s\n"
97                 "DomainName:\t%.*s\n"
98                 ,__NEW_UTS_LEN, cvirt->utsname.sysname
99                 ,__NEW_UTS_LEN, cvirt->utsname.nodename
100                 ,__NEW_UTS_LEN, cvirt->utsname.release
101                 ,__NEW_UTS_LEN, cvirt->utsname.version
102                 ,__NEW_UTS_LEN, cvirt->utsname.machine
103                 ,__NEW_UTS_LEN, cvirt->utsname.domainname
104                 );
105         return length;
106 }
107
108 static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
109 {
110         int i,j, length = 0;
111         static char *type[] = { "UNSPEC", "UNIX", "INET", "INET6", "OTHER" };
112
113         for (i=0; i<5; i++) {
114                 length += sprintf(buffer + length,
115                         "%s:", type[i]);
116                 for (j=0; j<3; j++) {
117                         length += sprintf(buffer + length,
118                                 "\t%12lu/%-12lu"
119                                 ,vx_sock_count(cacct, i, j)
120                                 ,vx_sock_total(cacct, i, j)
121                                 );
122                 }       
123                 buffer[length++] = '\n';
124         }
125         return length;
126 }
127
128 #else   /* _VX_INFO_DEF_ */
129 #ifndef _VX_CVIRT_H
130 #define _VX_CVIRT_H
131
132 #include "switch.h"
133
134 /*  cvirt vserver commands */
135
136
137 #ifdef  __KERNEL__
138
139 struct timespec;
140
141 void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle);
142
143 #endif  /* __KERNEL__ */
144
145 #endif  /* _VX_CVIRT_H */
146 #endif