Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rpc: move process_xdr_buf

Since process_xdr_buf() is useful outside of the kerberos-specific code, we
move it to net/sunrpc/xdr.c, export it, and rename it in keeping with xdr_*
naming convention of xdr.c.

Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

authored by

Olga Kornievskaia and committed by
Trond Myklebust
37a4e6cb 87d918d6

+74 -69
+2
include/linux/sunrpc/xdr.h
··· 11 11 12 12 #include <linux/uio.h> 13 13 #include <asm/byteorder.h> 14 + #include <linux/scatterlist.h> 14 15 15 16 /* 16 17 * Buffer adjustment ··· 197 196 extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes); 198 197 extern void xdr_read_pages(struct xdr_stream *xdr, unsigned int len); 199 198 extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len); 199 + extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data); 200 200 201 201 #endif /* __KERNEL__ */ 202 202
+4 -69
net/sunrpc/auth_gss/gss_krb5_crypto.c
··· 43 43 #include <linux/highmem.h> 44 44 #include <linux/pagemap.h> 45 45 #include <linux/sunrpc/gss_krb5.h> 46 + #include <linux/sunrpc/xdr.h> 46 47 47 48 #ifdef RPC_DEBUG 48 49 # define RPCDBG_FACILITY RPCDBG_AUTH ··· 121 120 EXPORT_SYMBOL(krb5_decrypt); 122 121 123 122 static int 124 - process_xdr_buf(struct xdr_buf *buf, int offset, int len, 125 - int (*actor)(struct scatterlist *, void *), void *data) 126 - { 127 - int i, page_len, thislen, page_offset, ret = 0; 128 - struct scatterlist sg[1]; 129 - 130 - if (offset >= buf->head[0].iov_len) { 131 - offset -= buf->head[0].iov_len; 132 - } else { 133 - thislen = buf->head[0].iov_len - offset; 134 - if (thislen > len) 135 - thislen = len; 136 - sg_set_buf(sg, buf->head[0].iov_base + offset, thislen); 137 - ret = actor(sg, data); 138 - if (ret) 139 - goto out; 140 - offset = 0; 141 - len -= thislen; 142 - } 143 - if (len == 0) 144 - goto out; 145 - 146 - if (offset >= buf->page_len) { 147 - offset -= buf->page_len; 148 - } else { 149 - page_len = buf->page_len - offset; 150 - if (page_len > len) 151 - page_len = len; 152 - len -= page_len; 153 - page_offset = (offset + buf->page_base) & (PAGE_CACHE_SIZE - 1); 154 - i = (offset + buf->page_base) >> PAGE_CACHE_SHIFT; 155 - thislen = PAGE_CACHE_SIZE - page_offset; 156 - do { 157 - if (thislen > page_len) 158 - thislen = page_len; 159 - sg->page = buf->pages[i]; 160 - sg->offset = page_offset; 161 - sg->length = thislen; 162 - ret = actor(sg, data); 163 - if (ret) 164 - goto out; 165 - page_len -= thislen; 166 - i++; 167 - page_offset = 0; 168 - thislen = PAGE_CACHE_SIZE; 169 - } while (page_len != 0); 170 - offset = 0; 171 - } 172 - if (len == 0) 173 - goto out; 174 - 175 - if (offset < buf->tail[0].iov_len) { 176 - thislen = buf->tail[0].iov_len - offset; 177 - if (thislen > len) 178 - thislen = len; 179 - sg_set_buf(sg, buf->tail[0].iov_base + offset, thislen); 180 - ret = actor(sg, data); 181 - len -= thislen; 182 - } 183 - if (len != 0) 184 - ret = -EINVAL; 185 - out: 186 - return ret; 187 - } 188 - 189 - static int 190 123 checksummer(struct scatterlist *sg, void *data) 191 124 { 192 125 struct hash_desc *desc = data; ··· 160 225 err = crypto_hash_update(&desc, sg, hdrlen); 161 226 if (err) 162 227 goto out; 163 - err = process_xdr_buf(body, body_offset, body->len - body_offset, 228 + err = xdr_process_buf(body, body_offset, body->len - body_offset, 164 229 checksummer, &desc); 165 230 if (err) 166 231 goto out; ··· 258 323 desc.fragno = 0; 259 324 desc.fraglen = 0; 260 325 261 - ret = process_xdr_buf(buf, offset, buf->len - offset, encryptor, &desc); 326 + ret = xdr_process_buf(buf, offset, buf->len - offset, encryptor, &desc); 262 327 return ret; 263 328 } 264 329 ··· 324 389 desc.desc.flags = 0; 325 390 desc.fragno = 0; 326 391 desc.fraglen = 0; 327 - return process_xdr_buf(buf, offset, buf->len - offset, decryptor, &desc); 392 + return xdr_process_buf(buf, offset, buf->len - offset, decryptor, &desc); 328 393 } 329 394 330 395 EXPORT_SYMBOL(gss_decrypt_xdr_buf);
+68
net/sunrpc/xdr.c
··· 1021 1021 1022 1022 return xdr_xcode_array2(buf, base, desc, 1); 1023 1023 } 1024 + 1025 + int 1026 + xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, 1027 + int (*actor)(struct scatterlist *, void *), void *data) 1028 + { 1029 + int i, ret = 0; 1030 + unsigned page_len, thislen, page_offset; 1031 + struct scatterlist sg[1]; 1032 + 1033 + if (offset >= buf->head[0].iov_len) { 1034 + offset -= buf->head[0].iov_len; 1035 + } else { 1036 + thislen = buf->head[0].iov_len - offset; 1037 + if (thislen > len) 1038 + thislen = len; 1039 + sg_set_buf(sg, buf->head[0].iov_base + offset, thislen); 1040 + ret = actor(sg, data); 1041 + if (ret) 1042 + goto out; 1043 + offset = 0; 1044 + len -= thislen; 1045 + } 1046 + if (len == 0) 1047 + goto out; 1048 + 1049 + if (offset >= buf->page_len) { 1050 + offset -= buf->page_len; 1051 + } else { 1052 + page_len = buf->page_len - offset; 1053 + if (page_len > len) 1054 + page_len = len; 1055 + len -= page_len; 1056 + page_offset = (offset + buf->page_base) & (PAGE_CACHE_SIZE - 1); 1057 + i = (offset + buf->page_base) >> PAGE_CACHE_SHIFT; 1058 + thislen = PAGE_CACHE_SIZE - page_offset; 1059 + do { 1060 + if (thislen > page_len) 1061 + thislen = page_len; 1062 + sg->page = buf->pages[i]; 1063 + sg->offset = page_offset; 1064 + sg->length = thislen; 1065 + ret = actor(sg, data); 1066 + if (ret) 1067 + goto out; 1068 + page_len -= thislen; 1069 + i++; 1070 + page_offset = 0; 1071 + thislen = PAGE_CACHE_SIZE; 1072 + } while (page_len != 0); 1073 + offset = 0; 1074 + } 1075 + if (len == 0) 1076 + goto out; 1077 + if (offset < buf->tail[0].iov_len) { 1078 + thislen = buf->tail[0].iov_len - offset; 1079 + if (thislen > len) 1080 + thislen = len; 1081 + sg_set_buf(sg, buf->tail[0].iov_base + offset, thislen); 1082 + ret = actor(sg, data); 1083 + len -= thislen; 1084 + } 1085 + if (len != 0) 1086 + ret = -EINVAL; 1087 + out: 1088 + return ret; 1089 + } 1090 + EXPORT_SYMBOL(xdr_process_buf); 1091 +