aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2006-12-05 16:35:41 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-12-06 10:46:52 -0500
commit9d29231690925915015c21c1fff73c7118099843 (patch)
treeac1018a80198a7e493296f5fc8e9fbd8dac7d0f0 /net/sunrpc
parent7559c7a28fbcaa0bca028eeebd5f251b09befe6b (diff)
SUNRPC: skb_read_bits is the same as xs_tcp_copy_data
Clean-up: eliminate xs_tcp_copy_data -- it's exactly the same logic as the common routine skb_read_bits. The UDP and TCP socket read code now share the same routine for copying data into an xdr_buf. Now that skb_read_bits() is exported, rename it to avoid confusing it with a generic skb_* function. As these functions are XDR-specific, they should not have names that suggest they are of generic use. Also rename skb_read_and_csum_bits() to be consistent. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net/sunrpc')
-rw-r--r--net/sunrpc/socklib.c14
-rw-r--r--net/sunrpc/xprtsock.c24
2 files changed, 11 insertions, 27 deletions
diff --git a/net/sunrpc/socklib.c b/net/sunrpc/socklib.c
index 2635c543ba06..9c40d67c1ffb 100644
--- a/net/sunrpc/socklib.c
+++ b/net/sunrpc/socklib.c
@@ -16,7 +16,7 @@
16 16
17 17
18/** 18/**
19 * skb_read_bits - copy some data bits from skb to internal buffer 19 * xdr_skb_read_bits - copy some data bits from skb to internal buffer
20 * @desc: sk_buff copy helper 20 * @desc: sk_buff copy helper
21 * @to: copy destination 21 * @to: copy destination
22 * @len: number of bytes to copy 22 * @len: number of bytes to copy
@@ -24,11 +24,11 @@
24 * Possibly called several times to iterate over an sk_buff and copy 24 * Possibly called several times to iterate over an sk_buff and copy
25 * data out of it. 25 * data out of it.
26 */ 26 */
27static size_t skb_read_bits(skb_reader_t *desc, void *to, size_t len) 27size_t xdr_skb_read_bits(skb_reader_t *desc, void *to, size_t len)
28{ 28{
29 if (len > desc->count) 29 if (len > desc->count)
30 len = desc->count; 30 len = desc->count;
31 if (skb_copy_bits(desc->skb, desc->offset, to, len)) 31 if (unlikely(skb_copy_bits(desc->skb, desc->offset, to, len)))
32 return 0; 32 return 0;
33 desc->count -= len; 33 desc->count -= len;
34 desc->offset += len; 34 desc->offset += len;
@@ -36,14 +36,14 @@ static size_t skb_read_bits(skb_reader_t *desc, void *to, size_t len)
36} 36}
37 37
38/** 38/**
39 * skb_read_and_csum_bits - copy and checksum from skb to buffer 39 * xdr_skb_read_and_csum_bits - copy and checksum from skb to buffer
40 * @desc: sk_buff copy helper 40 * @desc: sk_buff copy helper
41 * @to: copy destination 41 * @to: copy destination
42 * @len: number of bytes to copy 42 * @len: number of bytes to copy
43 * 43 *
44 * Same as skb_read_bits, but calculate a checksum at the same time. 44 * Same as skb_read_bits, but calculate a checksum at the same time.
45 */ 45 */
46static size_t skb_read_and_csum_bits(skb_reader_t *desc, void *to, size_t len) 46static size_t xdr_skb_read_and_csum_bits(skb_reader_t *desc, void *to, size_t len)
47{ 47{
48 unsigned int pos; 48 unsigned int pos;
49 __wsum csum2; 49 __wsum csum2;
@@ -158,7 +158,7 @@ int csum_partial_copy_to_xdr(struct xdr_buf *xdr, struct sk_buff *skb)
158 goto no_checksum; 158 goto no_checksum;
159 159
160 desc.csum = csum_partial(skb->data, desc.offset, skb->csum); 160 desc.csum = csum_partial(skb->data, desc.offset, skb->csum);
161 if (xdr_partial_copy_from_skb(xdr, 0, &desc, skb_read_and_csum_bits) < 0) 161 if (xdr_partial_copy_from_skb(xdr, 0, &desc, xdr_skb_read_and_csum_bits) < 0)
162 return -1; 162 return -1;
163 if (desc.offset != skb->len) { 163 if (desc.offset != skb->len) {
164 __wsum csum2; 164 __wsum csum2;
@@ -173,7 +173,7 @@ int csum_partial_copy_to_xdr(struct xdr_buf *xdr, struct sk_buff *skb)
173 netdev_rx_csum_fault(skb->dev); 173 netdev_rx_csum_fault(skb->dev);
174 return 0; 174 return 0;
175no_checksum: 175no_checksum:
176 if (xdr_partial_copy_from_skb(xdr, 0, &desc, skb_read_bits) < 0) 176 if (xdr_partial_copy_from_skb(xdr, 0, &desc, xdr_skb_read_bits) < 0)
177 return -1; 177 return -1;
178 if (desc.count) 178 if (desc.count)
179 return -1; 179 return -1;
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index a94aff42d08c..450c350a0c62 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -651,22 +651,6 @@ static void xs_udp_data_ready(struct sock *sk, int len)
651 read_unlock(&sk->sk_callback_lock); 651 read_unlock(&sk->sk_callback_lock);
652} 652}
653 653
654static inline size_t xs_tcp_copy_data(skb_reader_t *desc, void *p, size_t len)
655{
656 if (len > desc->count)
657 len = desc->count;
658 if (skb_copy_bits(desc->skb, desc->offset, p, len)) {
659 dprintk("RPC: failed to copy %zu bytes from skb. %zu bytes remain\n",
660 len, desc->count);
661 return 0;
662 }
663 desc->offset += len;
664 desc->count -= len;
665 dprintk("RPC: copied %zu bytes from skb. %zu bytes remain\n",
666 len, desc->count);
667 return len;
668}
669
670static inline void xs_tcp_read_fraghdr(struct rpc_xprt *xprt, skb_reader_t *desc) 654static inline void xs_tcp_read_fraghdr(struct rpc_xprt *xprt, skb_reader_t *desc)
671{ 655{
672 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); 656 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
@@ -675,7 +659,7 @@ static inline void xs_tcp_read_fraghdr(struct rpc_xprt *xprt, skb_reader_t *desc
675 659
676 p = ((char *) &transport->tcp_fraghdr) + transport->tcp_offset; 660 p = ((char *) &transport->tcp_fraghdr) + transport->tcp_offset;
677 len = sizeof(transport->tcp_fraghdr) - transport->tcp_offset; 661 len = sizeof(transport->tcp_fraghdr) - transport->tcp_offset;
678 used = xs_tcp_copy_data(desc, p, len); 662 used = xdr_skb_read_bits(desc, p, len);
679 transport->tcp_offset += used; 663 transport->tcp_offset += used;
680 if (used != len) 664 if (used != len)
681 return; 665 return;
@@ -721,7 +705,7 @@ static inline void xs_tcp_read_xid(struct sock_xprt *transport, skb_reader_t *de
721 len = sizeof(transport->tcp_xid) - transport->tcp_offset; 705 len = sizeof(transport->tcp_xid) - transport->tcp_offset;
722 dprintk("RPC: reading XID (%Zu bytes)\n", len); 706 dprintk("RPC: reading XID (%Zu bytes)\n", len);
723 p = ((char *) &transport->tcp_xid) + transport->tcp_offset; 707 p = ((char *) &transport->tcp_xid) + transport->tcp_offset;
724 used = xs_tcp_copy_data(desc, p, len); 708 used = xdr_skb_read_bits(desc, p, len);
725 transport->tcp_offset += used; 709 transport->tcp_offset += used;
726 if (used != len) 710 if (used != len)
727 return; 711 return;
@@ -761,12 +745,12 @@ static inline void xs_tcp_read_request(struct rpc_xprt *xprt, skb_reader_t *desc
761 memcpy(&my_desc, desc, sizeof(my_desc)); 745 memcpy(&my_desc, desc, sizeof(my_desc));
762 my_desc.count = len; 746 my_desc.count = len;
763 r = xdr_partial_copy_from_skb(rcvbuf, transport->tcp_copied, 747 r = xdr_partial_copy_from_skb(rcvbuf, transport->tcp_copied,
764 &my_desc, xs_tcp_copy_data); 748 &my_desc, xdr_skb_read_bits);
765 desc->count -= r; 749 desc->count -= r;
766 desc->offset += r; 750 desc->offset += r;
767 } else 751 } else
768 r = xdr_partial_copy_from_skb(rcvbuf, transport->tcp_copied, 752 r = xdr_partial_copy_from_skb(rcvbuf, transport->tcp_copied,
769 desc, xs_tcp_copy_data); 753 desc, xdr_skb_read_bits);
770 754
771 if (r > 0) { 755 if (r > 0) {
772 transport->tcp_copied += r; 756 transport->tcp_copied += r;