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>
This commit is contained in:
parent
33ec9c5cae
commit
8ececffa12
|
@ -696,8 +696,7 @@ int ksocknal_lib_setup_sock(struct socket *so);
|
||||||
int ksocknal_lib_send_iov(struct ksock_conn *conn, struct ksock_tx *tx);
|
int ksocknal_lib_send_iov(struct ksock_conn *conn, struct ksock_tx *tx);
|
||||||
int ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx);
|
int ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx);
|
||||||
void ksocknal_lib_eager_ack(struct ksock_conn *conn);
|
void ksocknal_lib_eager_ack(struct ksock_conn *conn);
|
||||||
int ksocknal_lib_recv_iov(struct ksock_conn *conn);
|
int ksocknal_lib_recv(struct ksock_conn *conn);
|
||||||
int ksocknal_lib_recv_kiov(struct ksock_conn *conn);
|
|
||||||
int ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem,
|
int ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem,
|
||||||
int *rxmem, int *nagle);
|
int *rxmem, int *nagle);
|
||||||
|
|
||||||
|
|
|
@ -249,16 +249,16 @@ ksocknal_transmit(struct ksock_conn *conn, struct ksock_tx *tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ksocknal_recv_iov(struct ksock_conn *conn)
|
ksocknal_recv_iter(struct ksock_conn *conn)
|
||||||
{
|
{
|
||||||
int nob;
|
int nob;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Never touch conn->ksnc_rx_to or change connection
|
* Never touch conn->ksnc_rx_to or change connection
|
||||||
* status inside ksocknal_lib_recv_iov
|
* status inside ksocknal_lib_recv
|
||||||
*/
|
*/
|
||||||
rc = ksocknal_lib_recv_iov(conn);
|
rc = ksocknal_lib_recv(conn);
|
||||||
|
|
||||||
if (rc <= 0)
|
if (rc <= 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -274,38 +274,6 @@ ksocknal_recv_iov(struct ksock_conn *conn)
|
||||||
|
|
||||||
conn->ksnc_rx_nob_left -= nob;
|
conn->ksnc_rx_nob_left -= nob;
|
||||||
|
|
||||||
iov_iter_advance(&conn->ksnc_rx_to, nob);
|
|
||||||
if (iov_iter_count(&conn->ksnc_rx_to))
|
|
||||||
return -EAGAIN;
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
ksocknal_recv_kiov(struct ksock_conn *conn)
|
|
||||||
{
|
|
||||||
int nob;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Never touch conn->ksnc_rx_to or change connection
|
|
||||||
* status inside ksocknal_lib_recv_iov
|
|
||||||
*/
|
|
||||||
rc = ksocknal_lib_recv_kiov(conn);
|
|
||||||
|
|
||||||
if (rc <= 0)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
/* received something... */
|
|
||||||
nob = rc;
|
|
||||||
|
|
||||||
conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
|
|
||||||
conn->ksnc_rx_deadline =
|
|
||||||
cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
|
|
||||||
mb(); /* order with setting rx_started */
|
|
||||||
conn->ksnc_rx_started = 1;
|
|
||||||
|
|
||||||
conn->ksnc_rx_nob_left -= nob;
|
|
||||||
iov_iter_advance(&conn->ksnc_rx_to, nob);
|
iov_iter_advance(&conn->ksnc_rx_to, nob);
|
||||||
if (iov_iter_count(&conn->ksnc_rx_to))
|
if (iov_iter_count(&conn->ksnc_rx_to))
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
|
@ -335,11 +303,7 @@ ksocknal_receive(struct ksock_conn *conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (conn->ksnc_rx_to.type & ITER_KVEC)
|
rc = ksocknal_recv_iter(conn);
|
||||||
rc = ksocknal_recv_iov(conn);
|
|
||||||
else
|
|
||||||
rc = ksocknal_recv_kiov(conn);
|
|
||||||
|
|
||||||
if (rc <= 0) {
|
if (rc <= 0) {
|
||||||
/* error/EOF or partial receive */
|
/* error/EOF or partial receive */
|
||||||
if (rc == -EAGAIN) {
|
if (rc == -EAGAIN) {
|
||||||
|
|
|
@ -161,86 +161,39 @@ ksocknal_lib_eager_ack(struct ksock_conn *conn)
|
||||||
sizeof(opt));
|
sizeof(opt));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int lustre_csum(struct kvec *v, void *context)
|
||||||
ksocknal_lib_recv_iov(struct ksock_conn *conn)
|
|
||||||
{
|
{
|
||||||
unsigned int niov = conn->ksnc_rx_to.nr_segs;
|
struct ksock_conn *conn = context;
|
||||||
const struct iovec *iov = conn->ksnc_rx_to.iov;
|
conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum,
|
||||||
struct msghdr msg = {
|
v->iov_base, v->iov_len);
|
||||||
.msg_flags = 0
|
return 0;
|
||||||
};
|
|
||||||
int i;
|
|
||||||
int rc;
|
|
||||||
int fragnob;
|
|
||||||
int sum;
|
|
||||||
__u32 saved_csum;
|
|
||||||
int off = conn->ksnc_rx_to.iov_offset;
|
|
||||||
|
|
||||||
msg.msg_iter = conn->ksnc_rx_to;
|
|
||||||
rc = sock_recvmsg(conn->ksnc_sock, &msg, MSG_DONTWAIT);
|
|
||||||
|
|
||||||
saved_csum = 0;
|
|
||||||
if (conn->ksnc_proto == &ksocknal_protocol_v2x) {
|
|
||||||
saved_csum = conn->ksnc_msg.ksm_csum;
|
|
||||||
conn->ksnc_msg.ksm_csum = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saved_csum) {
|
|
||||||
/* accumulate checksum */
|
|
||||||
for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) {
|
|
||||||
LASSERT(i < niov);
|
|
||||||
|
|
||||||
fragnob = iov[i].iov_len - off;
|
|
||||||
if (fragnob > sum)
|
|
||||||
fragnob = sum;
|
|
||||||
|
|
||||||
conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum,
|
|
||||||
iov[i].iov_base + off,
|
|
||||||
fragnob);
|
|
||||||
off = 0;
|
|
||||||
}
|
|
||||||
conn->ksnc_msg.ksm_csum = saved_csum;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ksocknal_lib_recv_kiov(struct ksock_conn *conn)
|
ksocknal_lib_recv(struct ksock_conn *conn)
|
||||||
{
|
{
|
||||||
unsigned int niov = conn->ksnc_rx_to.nr_segs;
|
struct msghdr msg = { .msg_iter = conn->ksnc_rx_to };
|
||||||
const struct bio_vec *kiov = conn->ksnc_rx_to.bvec;
|
__u32 saved_csum;
|
||||||
int off = conn->ksnc_rx_to.iov_offset;
|
|
||||||
struct msghdr msg = {
|
|
||||||
.msg_flags = 0
|
|
||||||
};
|
|
||||||
int i;
|
|
||||||
int rc;
|
int rc;
|
||||||
void *base;
|
|
||||||
int sum;
|
|
||||||
int fragnob;
|
|
||||||
|
|
||||||
msg.msg_iter = conn->ksnc_rx_to;
|
|
||||||
rc = sock_recvmsg(conn->ksnc_sock, &msg, MSG_DONTWAIT);
|
rc = sock_recvmsg(conn->ksnc_sock, &msg, MSG_DONTWAIT);
|
||||||
if (rc <= 0)
|
if (rc <= 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (conn->ksnc_msg.ksm_csum) {
|
saved_csum = conn->ksnc_msg.ksm_csum;
|
||||||
for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) {
|
if (!saved_csum)
|
||||||
LASSERT(i < niov);
|
return rc;
|
||||||
|
|
||||||
base = kmap(kiov[i].bv_page) + kiov[i].bv_offset + off;
|
/* header is included only in V2 - V3 checksums only the bulk data */
|
||||||
fragnob = kiov[i].bv_len - off;
|
if (!(conn->ksnc_rx_to.type & ITER_BVEC) &&
|
||||||
if (fragnob > sum)
|
conn->ksnc_proto != &ksocknal_protocol_v2x)
|
||||||
fragnob = sum;
|
return rc;
|
||||||
|
|
||||||
|
/* accumulate checksum */
|
||||||
|
conn->ksnc_msg.ksm_csum = 0;
|
||||||
|
iov_iter_for_each_range(&conn->ksnc_rx_to, rc, lustre_csum, conn);
|
||||||
|
conn->ksnc_msg.ksm_csum = saved_csum;
|
||||||
|
|
||||||
conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum,
|
|
||||||
base, fragnob);
|
|
||||||
|
|
||||||
kunmap(kiov[i].bv_page);
|
|
||||||
off = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue