mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-21 06:01:23 +00:00
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>
This commit is contained in:
parent
87d918d667
commit
37a4e6cb03
3 changed files with 74 additions and 69 deletions
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <linux/uio.h>
|
#include <linux/uio.h>
|
||||||
#include <asm/byteorder.h>
|
#include <asm/byteorder.h>
|
||||||
|
#include <linux/scatterlist.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Buffer adjustment
|
* Buffer adjustment
|
||||||
|
@ -196,6 +197,7 @@ extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32
|
||||||
extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
|
extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
|
||||||
extern void xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
|
extern void xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
|
||||||
extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
|
extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
|
||||||
|
extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
|
||||||
|
|
||||||
#endif /* __KERNEL__ */
|
#endif /* __KERNEL__ */
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <linux/highmem.h>
|
#include <linux/highmem.h>
|
||||||
#include <linux/pagemap.h>
|
#include <linux/pagemap.h>
|
||||||
#include <linux/sunrpc/gss_krb5.h>
|
#include <linux/sunrpc/gss_krb5.h>
|
||||||
|
#include <linux/sunrpc/xdr.h>
|
||||||
|
|
||||||
#ifdef RPC_DEBUG
|
#ifdef RPC_DEBUG
|
||||||
# define RPCDBG_FACILITY RPCDBG_AUTH
|
# define RPCDBG_FACILITY RPCDBG_AUTH
|
||||||
|
@ -119,72 +120,6 @@ out:
|
||||||
|
|
||||||
EXPORT_SYMBOL(krb5_decrypt);
|
EXPORT_SYMBOL(krb5_decrypt);
|
||||||
|
|
||||||
static int
|
|
||||||
process_xdr_buf(struct xdr_buf *buf, int offset, int len,
|
|
||||||
int (*actor)(struct scatterlist *, void *), void *data)
|
|
||||||
{
|
|
||||||
int i, page_len, thislen, page_offset, ret = 0;
|
|
||||||
struct scatterlist sg[1];
|
|
||||||
|
|
||||||
if (offset >= buf->head[0].iov_len) {
|
|
||||||
offset -= buf->head[0].iov_len;
|
|
||||||
} else {
|
|
||||||
thislen = buf->head[0].iov_len - offset;
|
|
||||||
if (thislen > len)
|
|
||||||
thislen = len;
|
|
||||||
sg_set_buf(sg, buf->head[0].iov_base + offset, thislen);
|
|
||||||
ret = actor(sg, data);
|
|
||||||
if (ret)
|
|
||||||
goto out;
|
|
||||||
offset = 0;
|
|
||||||
len -= thislen;
|
|
||||||
}
|
|
||||||
if (len == 0)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (offset >= buf->page_len) {
|
|
||||||
offset -= buf->page_len;
|
|
||||||
} else {
|
|
||||||
page_len = buf->page_len - offset;
|
|
||||||
if (page_len > len)
|
|
||||||
page_len = len;
|
|
||||||
len -= page_len;
|
|
||||||
page_offset = (offset + buf->page_base) & (PAGE_CACHE_SIZE - 1);
|
|
||||||
i = (offset + buf->page_base) >> PAGE_CACHE_SHIFT;
|
|
||||||
thislen = PAGE_CACHE_SIZE - page_offset;
|
|
||||||
do {
|
|
||||||
if (thislen > page_len)
|
|
||||||
thislen = page_len;
|
|
||||||
sg->page = buf->pages[i];
|
|
||||||
sg->offset = page_offset;
|
|
||||||
sg->length = thislen;
|
|
||||||
ret = actor(sg, data);
|
|
||||||
if (ret)
|
|
||||||
goto out;
|
|
||||||
page_len -= thislen;
|
|
||||||
i++;
|
|
||||||
page_offset = 0;
|
|
||||||
thislen = PAGE_CACHE_SIZE;
|
|
||||||
} while (page_len != 0);
|
|
||||||
offset = 0;
|
|
||||||
}
|
|
||||||
if (len == 0)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (offset < buf->tail[0].iov_len) {
|
|
||||||
thislen = buf->tail[0].iov_len - offset;
|
|
||||||
if (thislen > len)
|
|
||||||
thislen = len;
|
|
||||||
sg_set_buf(sg, buf->tail[0].iov_base + offset, thislen);
|
|
||||||
ret = actor(sg, data);
|
|
||||||
len -= thislen;
|
|
||||||
}
|
|
||||||
if (len != 0)
|
|
||||||
ret = -EINVAL;
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
checksummer(struct scatterlist *sg, void *data)
|
checksummer(struct scatterlist *sg, void *data)
|
||||||
{
|
{
|
||||||
|
@ -225,7 +160,7 @@ make_checksum(s32 cksumtype, char *header, int hdrlen, struct xdr_buf *body,
|
||||||
err = crypto_hash_update(&desc, sg, hdrlen);
|
err = crypto_hash_update(&desc, sg, hdrlen);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
err = process_xdr_buf(body, body_offset, body->len - body_offset,
|
err = xdr_process_buf(body, body_offset, body->len - body_offset,
|
||||||
checksummer, &desc);
|
checksummer, &desc);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -323,7 +258,7 @@ gss_encrypt_xdr_buf(struct crypto_blkcipher *tfm, struct xdr_buf *buf,
|
||||||
desc.fragno = 0;
|
desc.fragno = 0;
|
||||||
desc.fraglen = 0;
|
desc.fraglen = 0;
|
||||||
|
|
||||||
ret = process_xdr_buf(buf, offset, buf->len - offset, encryptor, &desc);
|
ret = xdr_process_buf(buf, offset, buf->len - offset, encryptor, &desc);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +324,7 @@ gss_decrypt_xdr_buf(struct crypto_blkcipher *tfm, struct xdr_buf *buf,
|
||||||
desc.desc.flags = 0;
|
desc.desc.flags = 0;
|
||||||
desc.fragno = 0;
|
desc.fragno = 0;
|
||||||
desc.fraglen = 0;
|
desc.fraglen = 0;
|
||||||
return process_xdr_buf(buf, offset, buf->len - offset, decryptor, &desc);
|
return xdr_process_buf(buf, offset, buf->len - offset, decryptor, &desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_SYMBOL(gss_decrypt_xdr_buf);
|
EXPORT_SYMBOL(gss_decrypt_xdr_buf);
|
||||||
|
|
|
@ -1021,3 +1021,71 @@ xdr_encode_array2(struct xdr_buf *buf, unsigned int base,
|
||||||
|
|
||||||
return xdr_xcode_array2(buf, base, desc, 1);
|
return xdr_xcode_array2(buf, base, desc, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len,
|
||||||
|
int (*actor)(struct scatterlist *, void *), void *data)
|
||||||
|
{
|
||||||
|
int i, ret = 0;
|
||||||
|
unsigned page_len, thislen, page_offset;
|
||||||
|
struct scatterlist sg[1];
|
||||||
|
|
||||||
|
if (offset >= buf->head[0].iov_len) {
|
||||||
|
offset -= buf->head[0].iov_len;
|
||||||
|
} else {
|
||||||
|
thislen = buf->head[0].iov_len - offset;
|
||||||
|
if (thislen > len)
|
||||||
|
thislen = len;
|
||||||
|
sg_set_buf(sg, buf->head[0].iov_base + offset, thislen);
|
||||||
|
ret = actor(sg, data);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
offset = 0;
|
||||||
|
len -= thislen;
|
||||||
|
}
|
||||||
|
if (len == 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (offset >= buf->page_len) {
|
||||||
|
offset -= buf->page_len;
|
||||||
|
} else {
|
||||||
|
page_len = buf->page_len - offset;
|
||||||
|
if (page_len > len)
|
||||||
|
page_len = len;
|
||||||
|
len -= page_len;
|
||||||
|
page_offset = (offset + buf->page_base) & (PAGE_CACHE_SIZE - 1);
|
||||||
|
i = (offset + buf->page_base) >> PAGE_CACHE_SHIFT;
|
||||||
|
thislen = PAGE_CACHE_SIZE - page_offset;
|
||||||
|
do {
|
||||||
|
if (thislen > page_len)
|
||||||
|
thislen = page_len;
|
||||||
|
sg->page = buf->pages[i];
|
||||||
|
sg->offset = page_offset;
|
||||||
|
sg->length = thislen;
|
||||||
|
ret = actor(sg, data);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
page_len -= thislen;
|
||||||
|
i++;
|
||||||
|
page_offset = 0;
|
||||||
|
thislen = PAGE_CACHE_SIZE;
|
||||||
|
} while (page_len != 0);
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
if (len == 0)
|
||||||
|
goto out;
|
||||||
|
if (offset < buf->tail[0].iov_len) {
|
||||||
|
thislen = buf->tail[0].iov_len - offset;
|
||||||
|
if (thislen > len)
|
||||||
|
thislen = len;
|
||||||
|
sg_set_buf(sg, buf->tail[0].iov_base + offset, thislen);
|
||||||
|
ret = actor(sg, data);
|
||||||
|
len -= thislen;
|
||||||
|
}
|
||||||
|
if (len != 0)
|
||||||
|
ret = -EINVAL;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(xdr_process_buf);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue