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/slab.h>
35#include <linux/in.h>
36
37#include "rds_single_path.h"
38#include "rds.h"
39#include "loop.h"
40
41static DEFINE_SPINLOCK(loop_conns_lock);
42static LIST_HEAD(loop_conns);
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61static int rds_loop_xmit(struct rds_connection *conn, struct rds_message *rm,
62 unsigned int hdr_off, unsigned int sg,
63 unsigned int off)
64{
65 struct scatterlist *sgp = &rm->data.op_sg[sg];
66 int ret = sizeof(struct rds_header) +
67 be32_to_cpu(rm->m_inc.i_hdr.h_len);
68
69
70 if (rm->m_inc.i_hdr.h_flags & RDS_FLAG_CONG_BITMAP) {
71 rds_cong_map_updated(conn->c_fcong, ~(u64) 0);
72 ret = min_t(int, ret, sgp->length - conn->c_xmit_data_off);
73 goto out;
74 }
75
76 BUG_ON(hdr_off || sg || off);
77
78 rds_inc_init(&rm->m_inc, conn, conn->c_laddr);
79
80 rds_message_addref(rm);
81
82 rds_recv_incoming(conn, conn->c_laddr, conn->c_faddr, &rm->m_inc,
83 GFP_KERNEL);
84
85 rds_send_drop_acked(conn, be64_to_cpu(rm->m_inc.i_hdr.h_sequence),
86 NULL);
87
88 rds_inc_put(&rm->m_inc);
89out:
90 return ret;
91}
92
93
94
95
96
97static void rds_loop_inc_free(struct rds_incoming *inc)
98{
99 struct rds_message *rm = container_of(inc, struct rds_message, m_inc);
100
101 rds_message_put(rm);
102}
103
104
105static int rds_loop_recv_path(struct rds_conn_path *cp)
106{
107 return 0;
108}
109
110struct rds_loop_connection {
111 struct list_head loop_node;
112 struct rds_connection *conn;
113};
114
115
116
117
118
119
120
121static int rds_loop_conn_alloc(struct rds_connection *conn, gfp_t gfp)
122{
123 struct rds_loop_connection *lc;
124 unsigned long flags;
125
126 lc = kzalloc(sizeof(struct rds_loop_connection), gfp);
127 if (!lc)
128 return -ENOMEM;
129
130 INIT_LIST_HEAD(&lc->loop_node);
131 lc->conn = conn;
132 conn->c_transport_data = lc;
133
134 spin_lock_irqsave(&loop_conns_lock, flags);
135 list_add_tail(&lc->loop_node, &loop_conns);
136 spin_unlock_irqrestore(&loop_conns_lock, flags);
137
138 return 0;
139}
140
141static void rds_loop_conn_free(void *arg)
142{
143 struct rds_loop_connection *lc = arg;
144 unsigned long flags;
145
146 rdsdebug("lc %p\n", lc);
147 spin_lock_irqsave(&loop_conns_lock, flags);
148 list_del(&lc->loop_node);
149 spin_unlock_irqrestore(&loop_conns_lock, flags);
150 kfree(lc);
151}
152
153static int rds_loop_conn_path_connect(struct rds_conn_path *cp)
154{
155 rds_connect_complete(cp->cp_conn);
156 return 0;
157}
158
159static void rds_loop_conn_path_shutdown(struct rds_conn_path *cp)
160{
161}
162
163void rds_loop_exit(void)
164{
165 struct rds_loop_connection *lc, *_lc;
166 LIST_HEAD(tmp_list);
167
168
169 spin_lock_irq(&loop_conns_lock);
170 list_splice(&loop_conns, &tmp_list);
171 INIT_LIST_HEAD(&loop_conns);
172 spin_unlock_irq(&loop_conns_lock);
173
174 list_for_each_entry_safe(lc, _lc, &tmp_list, loop_node) {
175 WARN_ON(lc->conn->c_passive);
176 rds_conn_destroy(lc->conn);
177 }
178}
179
180
181
182
183
184
185
186struct rds_transport rds_loop_transport = {
187 .xmit = rds_loop_xmit,
188 .recv_path = rds_loop_recv_path,
189 .conn_alloc = rds_loop_conn_alloc,
190 .conn_free = rds_loop_conn_free,
191 .conn_path_connect = rds_loop_conn_path_connect,
192 .conn_path_shutdown = rds_loop_conn_path_shutdown,
193 .inc_copy_to_user = rds_message_inc_copy_to_user,
194 .inc_free = rds_loop_inc_free,
195 .t_name = "loopback",
196};
197