fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / linux / vs_socket.h
1 #ifndef _VS_SOCKET_H
2 #define _VS_SOCKET_H
3
4 #include "vserver/debug.h"
5 #include "vserver/base.h"
6 #include "vserver/cacct.h"
7 #include "vserver/context.h"
8
9
10 /* socket accounting */
11
12 #include <linux/socket.h>
13
14 static inline int vx_sock_type(int family)
15 {
16         switch (family) {
17         case PF_UNSPEC:
18                 return VXA_SOCK_UNSPEC;
19         case PF_UNIX:
20                 return VXA_SOCK_UNIX;
21         case PF_INET:
22                 return VXA_SOCK_INET;
23         case PF_INET6:
24                 return VXA_SOCK_INET6;
25         case PF_PACKET:
26                 return VXA_SOCK_PACKET;
27         default:
28                 return VXA_SOCK_OTHER;
29         }
30 }
31
32 #define vx_acc_sock(v,f,p,s) \
33         __vx_acc_sock((v), (f), (p), (s), __FILE__, __LINE__)
34
35 static inline void __vx_acc_sock(struct vx_info *vxi,
36         int family, int pos, int size, char *file, int line)
37 {
38         if (vxi) {
39                 int type = vx_sock_type(family);
40
41                 atomic_long_inc(&vxi->cacct.sock[type][pos].count);
42                 atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
43         }
44 }
45
46 #define vx_sock_recv(sk,s) \
47         vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, (s))
48 #define vx_sock_send(sk,s) \
49         vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, (s))
50 #define vx_sock_fail(sk,s) \
51         vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, (s))
52
53
54 #define sock_vx_init(s) do {            \
55         (s)->sk_xid = 0;                \
56         (s)->sk_vx_info = NULL;         \
57         } while (0)
58
59 #define sock_nx_init(s) do {            \
60         (s)->sk_nid = 0;                \
61         (s)->sk_nx_info = NULL;         \
62         } while (0)
63
64
65 #else
66 #warning duplicate inclusion
67 #endif