This source file includes following definitions.
- rds_trans_register
- rds_trans_unregister
- rds_trans_put
- rds_trans_get_preferred
- rds_trans_get
- rds_trans_stats_info_copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/in.h>
36 #include <linux/ipv6.h>
37
38 #include "rds.h"
39 #include "loop.h"
40
41 static struct rds_transport *transports[RDS_TRANS_COUNT];
42 static DECLARE_RWSEM(rds_trans_sem);
43
44 void rds_trans_register(struct rds_transport *trans)
45 {
46 BUG_ON(strlen(trans->t_name) + 1 > TRANSNAMSIZ);
47
48 down_write(&rds_trans_sem);
49
50 if (transports[trans->t_type])
51 printk(KERN_ERR "RDS Transport type %d already registered\n",
52 trans->t_type);
53 else {
54 transports[trans->t_type] = trans;
55 printk(KERN_INFO "Registered RDS/%s transport\n", trans->t_name);
56 }
57
58 up_write(&rds_trans_sem);
59 }
60 EXPORT_SYMBOL_GPL(rds_trans_register);
61
62 void rds_trans_unregister(struct rds_transport *trans)
63 {
64 down_write(&rds_trans_sem);
65
66 transports[trans->t_type] = NULL;
67 printk(KERN_INFO "Unregistered RDS/%s transport\n", trans->t_name);
68
69 up_write(&rds_trans_sem);
70 }
71 EXPORT_SYMBOL_GPL(rds_trans_unregister);
72
73 void rds_trans_put(struct rds_transport *trans)
74 {
75 if (trans)
76 module_put(trans->t_owner);
77 }
78
79 struct rds_transport *rds_trans_get_preferred(struct net *net,
80 const struct in6_addr *addr,
81 __u32 scope_id)
82 {
83 struct rds_transport *ret = NULL;
84 struct rds_transport *trans;
85 unsigned int i;
86
87 if (ipv6_addr_v4mapped(addr)) {
88 if (*(u_int8_t *)&addr->s6_addr32[3] == IN_LOOPBACKNET)
89 return &rds_loop_transport;
90 } else if (ipv6_addr_loopback(addr)) {
91 return &rds_loop_transport;
92 }
93
94 down_read(&rds_trans_sem);
95 for (i = 0; i < RDS_TRANS_COUNT; i++) {
96 trans = transports[i];
97
98 if (trans && (trans->laddr_check(net, addr, scope_id) == 0) &&
99 (!trans->t_owner || try_module_get(trans->t_owner))) {
100 ret = trans;
101 break;
102 }
103 }
104 up_read(&rds_trans_sem);
105
106 return ret;
107 }
108
109 struct rds_transport *rds_trans_get(int t_type)
110 {
111 struct rds_transport *ret = NULL;
112 struct rds_transport *trans;
113 unsigned int i;
114
115 down_read(&rds_trans_sem);
116 for (i = 0; i < RDS_TRANS_COUNT; i++) {
117 trans = transports[i];
118
119 if (trans && trans->t_type == t_type &&
120 (!trans->t_owner || try_module_get(trans->t_owner))) {
121 ret = trans;
122 break;
123 }
124 }
125 up_read(&rds_trans_sem);
126
127 return ret;
128 }
129
130
131
132
133
134
135
136 unsigned int rds_trans_stats_info_copy(struct rds_info_iterator *iter,
137 unsigned int avail)
138
139 {
140 struct rds_transport *trans;
141 unsigned int total = 0;
142 unsigned int part;
143 int i;
144
145 rds_info_iter_unmap(iter);
146 down_read(&rds_trans_sem);
147
148 for (i = 0; i < RDS_TRANS_COUNT; i++) {
149 trans = transports[i];
150 if (!trans || !trans->stats_info_copy)
151 continue;
152
153 part = trans->stats_info_copy(iter, avail);
154 avail -= min(avail, part);
155 total += part;
156 }
157
158 up_read(&rds_trans_sem);
159
160 return total;
161 }