From b6332b5c0dfe28d6b574e206ae651262337a8309 Mon Sep 17 00:00:00 2001 From: Oleg Drokin Date: Sun, 1 Jun 2014 15:52:23 -0400 Subject: [PATCH] LU-4423 lnet: switch to kernel_sendmsg() Upstream commit by Al Viro: lustre: switch to kernel_sendmsg() (casts are due to misannotations in lustre; it uses iovec where kvec would be correct type; too much noise to properly annotate right now). Linux-commit: 480f40de91e74190281309fd0ecb2d0414603c2e Change-Id: I1f6e27cd158bd3e15d06b88d3e973dc7f99a5e60 Signed-off-by: Oleg Drokin Signed-off-by: James Simmons Reviewed-on: http://review.whamcloud.com/10125 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Liang Zhen Reviewed-by: Isaac Huang --- libcfs/libcfs/linux/linux-tcpip.c | 30 ++++----- lnet/klnds/socklnd/socklnd_lib-linux.c | 117 ++++++++++++++------------------- 2 files changed, 59 insertions(+), 88 deletions(-) diff --git a/libcfs/libcfs/linux/linux-tcpip.c b/libcfs/libcfs/linux/linux-tcpip.c index 288ad84..dd609c0 100644 --- a/libcfs/libcfs/linux/linux-tcpip.c +++ b/libcfs/libcfs/linux/linux-tcpip.c @@ -300,20 +300,14 @@ libcfs_sock_write (struct socket *sock, void *buffer, int nob, int timeout) /* Caller may pass a zero timeout if she thinks the socket buffer is * empty enough to take the whole message immediately */ - for (;;) { - struct iovec iov = { - .iov_base = buffer, - .iov_len = nob - }; - struct msghdr msg = { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = &iov, - .msg_iovlen = 1, - .msg_control = NULL, - .msg_controllen = 0, - .msg_flags = (timeout == 0) ? MSG_DONTWAIT : 0 - }; + for (;;) { + struct kvec iov = { + .iov_base = buffer, + .iov_len = nob + }; + struct msghdr msg = { + .msg_flags = (timeout == 0) ? MSG_DONTWAIT : 0 + }; if (timeout != 0) { /* Set send timeout to remaining time */ @@ -333,11 +327,9 @@ libcfs_sock_write (struct socket *sock, void *buffer, int nob, int timeout) } } - set_fs (KERNEL_DS); - then = jiffies; - rc = sock_sendmsg (sock, &msg, iov.iov_len); - ticks -= jiffies - then; - set_fs (oldmm); + then = jiffies; + rc = kernel_sendmsg(sock, &msg, &iov, 1, nob); + ticks -= jiffies - then; if (rc == nob) return 0; diff --git a/lnet/klnds/socklnd/socklnd_lib-linux.c b/lnet/klnds/socklnd/socklnd_lib-linux.c index df56998..33ad490 100644 --- a/lnet/klnds/socklnd/socklnd_lib-linux.c +++ b/lnet/klnds/socklnd/socklnd_lib-linux.c @@ -381,60 +381,50 @@ ksocknal_lib_zc_capable(ksock_conn_t *conn) } int -ksocknal_lib_send_iov (ksock_conn_t *conn, ksock_tx_t *tx) +ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx) { - struct socket *sock = conn->ksnc_sock; - int nob; - int rc; + struct socket *sock = conn->ksnc_sock; + int nob; + int rc; - if (*ksocknal_tunables.ksnd_enable_csum && /* checksum enabled */ - conn->ksnc_proto == &ksocknal_protocol_v2x && /* V2.x connection */ - tx->tx_nob == tx->tx_resid && /* frist sending */ - tx->tx_msg.ksm_csum == 0) /* not checksummed */ - ksocknal_lib_csum_tx(tx); + if (*ksocknal_tunables.ksnd_enable_csum && /* checksum enabled */ + conn->ksnc_proto == &ksocknal_protocol_v2x && /* V2.x connection */ + tx->tx_nob == tx->tx_resid && /* frist sending */ + tx->tx_msg.ksm_csum == 0) /* not checksummed */ + ksocknal_lib_csum_tx(tx); - /* NB we can't trust socket ops to either consume our iovs - * or leave them alone. */ + /* NB we can't trust socket ops to either consume our iovs + * or leave them alone. */ - { + { #if SOCKNAL_SINGLE_FRAG_TX - struct iovec scratch; - struct iovec *scratchiov = &scratch; - unsigned int niov = 1; + struct iovec scratch; + struct iovec *scratchiov = &scratch; + unsigned int niov = 1; #else struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov; - unsigned int niov = tx->tx_niov; + unsigned int niov = tx->tx_niov; #endif - struct msghdr msg = { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = scratchiov, - .msg_iovlen = niov, - .msg_control = NULL, - .msg_controllen = 0, - .msg_flags = MSG_DONTWAIT - }; - mm_segment_t oldmm = get_fs(); + struct msghdr msg = { .msg_flags = MSG_DONTWAIT }; int i; - for (nob = i = 0; i < niov; i++) { - scratchiov[i] = tx->tx_iov[i]; - nob += scratchiov[i].iov_len; - } + for (nob = i = 0; i < niov; i++) { + scratchiov[i] = tx->tx_iov[i]; + nob += scratchiov[i].iov_len; + } if (!list_empty(&conn->ksnc_tx_queue) || - nob < tx->tx_resid) - msg.msg_flags |= MSG_MORE; + nob < tx->tx_resid) + msg.msg_flags |= MSG_MORE; - set_fs (KERNEL_DS); - rc = sock_sendmsg(sock, &msg, nob); - set_fs (oldmm); - } - return rc; + rc = kernel_sendmsg(sock, &msg, (struct kvec *)scratchiov, + niov, nob); + } + return rc; } int -ksocknal_lib_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx) +ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx) { struct socket *sock = conn->ksnc_sock; lnet_kiov_t *kiov = tx->tx_kiov; @@ -470,46 +460,35 @@ ksocknal_lib_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx) } } else { #if SOCKNAL_SINGLE_FRAG_TX || !SOCKNAL_RISK_KMAP_DEADLOCK - struct iovec scratch; - struct iovec *scratchiov = &scratch; - unsigned int niov = 1; + struct iovec scratch; + struct iovec *scratchiov = &scratch; + unsigned int niov = 1; #else #ifdef CONFIG_HIGHMEM #warning "XXX risk of kmap deadlock on multiple frags..." #endif - struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov; - unsigned int niov = tx->tx_nkiov; + struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov; + unsigned int niov = tx->tx_nkiov; #endif - struct msghdr msg = { - .msg_name = NULL, - .msg_namelen = 0, - .msg_iov = scratchiov, - .msg_iovlen = niov, - .msg_control = NULL, - .msg_controllen = 0, - .msg_flags = MSG_DONTWAIT - }; - mm_segment_t oldmm = get_fs(); - int i; - - for (nob = i = 0; i < niov; i++) { - scratchiov[i].iov_base = kmap(kiov[i].kiov_page) + - kiov[i].kiov_offset; - nob += scratchiov[i].iov_len = kiov[i].kiov_len; - } + struct msghdr msg = { .msg_flags = MSG_DONTWAIT }; + int i; + + for (nob = i = 0; i < niov; i++) { + scratchiov[i].iov_base = kmap(kiov[i].kiov_page) + + kiov[i].kiov_offset; + nob += scratchiov[i].iov_len = kiov[i].kiov_len; + } if (!list_empty(&conn->ksnc_tx_queue) || - nob < tx->tx_resid) - msg.msg_flags |= MSG_MORE; + nob < tx->tx_resid) + msg.msg_flags |= MSG_MORE; - set_fs (KERNEL_DS); - rc = sock_sendmsg(sock, &msg, nob); - set_fs (oldmm); + rc = kernel_sendmsg(sock, &msg, (struct kvec *)scratchiov, niov, nob); - for (i = 0; i < niov; i++) - kunmap(kiov[i].kiov_page); - } - return rc; + for (i = 0; i < niov; i++) + kunmap(kiov[i].kiov_page); + } + return rc; } void -- 1.8.3.1