diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2017-09-25 13:58:39 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2017-10-11 22:37:49 -0400 |
commit | 8ececffa12f5555171075ce52e1226f570836b26 (patch) | |
tree | 2830c2aacbf0a9c8a3cbe322939fe92a6ed81a6e | |
parent | 33ec9c5cae2526ee2ef4f8224ddd2d7779b64e89 (diff) |
switch ksocknal_lib_recv_...() to use of iov_iter_for_each_range()
... and fold kvec and bio_vec variants in one
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h | 3 | ||||
-rw-r--r-- | drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 44 | ||||
-rw-r--r-- | drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c | 87 |
3 files changed, 25 insertions, 109 deletions
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h index 694d45b45976..a18a57c4de81 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h | |||
@@ -696,8 +696,7 @@ int ksocknal_lib_setup_sock(struct socket *so); | |||
696 | int ksocknal_lib_send_iov(struct ksock_conn *conn, struct ksock_tx *tx); | 696 | int ksocknal_lib_send_iov(struct ksock_conn *conn, struct ksock_tx *tx); |
697 | int ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx); | 697 | int ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx); |
698 | void ksocknal_lib_eager_ack(struct ksock_conn *conn); | 698 | void ksocknal_lib_eager_ack(struct ksock_conn *conn); |
699 | int ksocknal_lib_recv_iov(struct ksock_conn *conn); | 699 | int ksocknal_lib_recv(struct ksock_conn *conn); |
700 | int ksocknal_lib_recv_kiov(struct ksock_conn *conn); | ||
701 | int ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem, | 700 | int ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem, |
702 | int *rxmem, int *nagle); | 701 | int *rxmem, int *nagle); |
703 | 702 | ||
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c index c79aeb463a5c..b12c3b0f39e1 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | |||
@@ -249,16 +249,16 @@ ksocknal_transmit(struct ksock_conn *conn, struct ksock_tx *tx) | |||
249 | } | 249 | } |
250 | 250 | ||
251 | static int | 251 | static int |
252 | ksocknal_recv_iov(struct ksock_conn *conn) | 252 | ksocknal_recv_iter(struct ksock_conn *conn) |
253 | { | 253 | { |
254 | int nob; | 254 | int nob; |
255 | int rc; | 255 | int rc; |
256 | 256 | ||
257 | /* | 257 | /* |
258 | * Never touch conn->ksnc_rx_to or change connection | 258 | * Never touch conn->ksnc_rx_to or change connection |
259 | * status inside ksocknal_lib_recv_iov | 259 | * status inside ksocknal_lib_recv |
260 | */ | 260 | */ |
261 | rc = ksocknal_lib_recv_iov(conn); | 261 | rc = ksocknal_lib_recv(conn); |
262 | 262 | ||
263 | if (rc <= 0) | 263 | if (rc <= 0) |
264 | return rc; | 264 | return rc; |
@@ -278,38 +278,6 @@ ksocknal_recv_iov(struct ksock_conn *conn) | |||
278 | if (iov_iter_count(&conn->ksnc_rx_to)) | 278 | if (iov_iter_count(&conn->ksnc_rx_to)) |
279 | return -EAGAIN; | 279 | return -EAGAIN; |
280 | 280 | ||
281 | return rc; | ||
282 | } | ||
283 | |||
284 | static int | ||
285 | ksocknal_recv_kiov(struct ksock_conn *conn) | ||
286 | { | ||
287 | int nob; | ||
288 | int rc; | ||
289 | |||
290 | /* | ||
291 | * Never touch conn->ksnc_rx_to or change connection | ||
292 | * status inside ksocknal_lib_recv_iov | ||
293 | */ | ||
294 | rc = ksocknal_lib_recv_kiov(conn); | ||
295 | |||
296 | if (rc <= 0) | ||
297 | return rc; | ||
298 | |||
299 | /* received something... */ | ||
300 | nob = rc; | ||
301 | |||
302 | conn->ksnc_peer->ksnp_last_alive = cfs_time_current(); | ||
303 | conn->ksnc_rx_deadline = | ||
304 | cfs_time_shift(*ksocknal_tunables.ksnd_timeout); | ||
305 | mb(); /* order with setting rx_started */ | ||
306 | conn->ksnc_rx_started = 1; | ||
307 | |||
308 | conn->ksnc_rx_nob_left -= nob; | ||
309 | iov_iter_advance(&conn->ksnc_rx_to, nob); | ||
310 | if (iov_iter_count(&conn->ksnc_rx_to)) | ||
311 | return -EAGAIN; | ||
312 | |||
313 | return 1; | 281 | return 1; |
314 | } | 282 | } |
315 | 283 | ||
@@ -335,11 +303,7 @@ ksocknal_receive(struct ksock_conn *conn) | |||
335 | } | 303 | } |
336 | 304 | ||
337 | for (;;) { | 305 | for (;;) { |
338 | if (conn->ksnc_rx_to.type & ITER_KVEC) | 306 | rc = ksocknal_recv_iter(conn); |
339 | rc = ksocknal_recv_iov(conn); | ||
340 | else | ||
341 | rc = ksocknal_recv_kiov(conn); | ||
342 | |||
343 | if (rc <= 0) { | 307 | if (rc <= 0) { |
344 | /* error/EOF or partial receive */ | 308 | /* error/EOF or partial receive */ |
345 | if (rc == -EAGAIN) { | 309 | if (rc == -EAGAIN) { |
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c index 0ec032373497..2e3e2dd70baa 100644 --- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c +++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c | |||
@@ -161,86 +161,39 @@ ksocknal_lib_eager_ack(struct ksock_conn *conn) | |||
161 | sizeof(opt)); | 161 | sizeof(opt)); |
162 | } | 162 | } |
163 | 163 | ||
164 | int | 164 | static int lustre_csum(struct kvec *v, void *context) |
165 | ksocknal_lib_recv_iov(struct ksock_conn *conn) | ||
166 | { | 165 | { |
167 | unsigned int niov = conn->ksnc_rx_to.nr_segs; | 166 | struct ksock_conn *conn = context; |
168 | const struct iovec *iov = conn->ksnc_rx_to.iov; | 167 | conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum, |
169 | struct msghdr msg = { | 168 | v->iov_base, v->iov_len); |
170 | .msg_flags = 0 | 169 | return 0; |
171 | }; | ||
172 | int i; | ||
173 | int rc; | ||
174 | int fragnob; | ||
175 | int sum; | ||
176 | __u32 saved_csum; | ||
177 | int off = conn->ksnc_rx_to.iov_offset; | ||
178 | |||
179 | msg.msg_iter = conn->ksnc_rx_to; | ||
180 | rc = sock_recvmsg(conn->ksnc_sock, &msg, MSG_DONTWAIT); | ||
181 | |||
182 | saved_csum = 0; | ||
183 | if (conn->ksnc_proto == &ksocknal_protocol_v2x) { | ||
184 | saved_csum = conn->ksnc_msg.ksm_csum; | ||
185 | conn->ksnc_msg.ksm_csum = 0; | ||
186 | } | ||
187 | |||
188 | if (saved_csum) { | ||
189 | /* accumulate checksum */ | ||
190 | for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) { | ||
191 | LASSERT(i < niov); | ||
192 | |||
193 | fragnob = iov[i].iov_len - off; | ||
194 | if (fragnob > sum) | ||
195 | fragnob = sum; | ||
196 | |||
197 | conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum, | ||
198 | iov[i].iov_base + off, | ||
199 | fragnob); | ||
200 | off = 0; | ||
201 | } | ||
202 | conn->ksnc_msg.ksm_csum = saved_csum; | ||
203 | } | ||
204 | |||
205 | return rc; | ||
206 | } | 170 | } |
207 | 171 | ||
208 | int | 172 | int |
209 | ksocknal_lib_recv_kiov(struct ksock_conn *conn) | 173 | ksocknal_lib_recv(struct ksock_conn *conn) |
210 | { | 174 | { |
211 | unsigned int niov = conn->ksnc_rx_to.nr_segs; | 175 | struct msghdr msg = { .msg_iter = conn->ksnc_rx_to }; |
212 | const struct bio_vec *kiov = conn->ksnc_rx_to.bvec; | 176 | __u32 saved_csum; |
213 | int off = conn->ksnc_rx_to.iov_offset; | ||
214 | struct msghdr msg = { | ||
215 | .msg_flags = 0 | ||
216 | }; | ||
217 | int i; | ||
218 | int rc; | 177 | int rc; |
219 | void *base; | ||
220 | int sum; | ||
221 | int fragnob; | ||
222 | 178 | ||
223 | msg.msg_iter = conn->ksnc_rx_to; | ||
224 | rc = sock_recvmsg(conn->ksnc_sock, &msg, MSG_DONTWAIT); | 179 | rc = sock_recvmsg(conn->ksnc_sock, &msg, MSG_DONTWAIT); |
225 | if (rc <= 0) | 180 | if (rc <= 0) |
226 | return rc; | 181 | return rc; |
227 | 182 | ||
228 | if (conn->ksnc_msg.ksm_csum) { | 183 | saved_csum = conn->ksnc_msg.ksm_csum; |
229 | for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) { | 184 | if (!saved_csum) |
230 | LASSERT(i < niov); | 185 | return rc; |
231 | |||
232 | base = kmap(kiov[i].bv_page) + kiov[i].bv_offset + off; | ||
233 | fragnob = kiov[i].bv_len - off; | ||
234 | if (fragnob > sum) | ||
235 | fragnob = sum; | ||
236 | 186 | ||
237 | conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum, | 187 | /* header is included only in V2 - V3 checksums only the bulk data */ |
238 | base, fragnob); | 188 | if (!(conn->ksnc_rx_to.type & ITER_BVEC) && |
189 | conn->ksnc_proto != &ksocknal_protocol_v2x) | ||
190 | return rc; | ||
191 | |||
192 | /* accumulate checksum */ | ||
193 | conn->ksnc_msg.ksm_csum = 0; | ||
194 | iov_iter_for_each_range(&conn->ksnc_rx_to, rc, lustre_csum, conn); | ||
195 | conn->ksnc_msg.ksm_csum = saved_csum; | ||
239 | 196 | ||
240 | kunmap(kiov[i].bv_page); | ||
241 | off = 0; | ||
242 | } | ||
243 | } | ||
244 | return rc; | 197 | return rc; |
245 | } | 198 | } |
246 | 199 | ||