2019-05-19 15:08:55 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* linux/net/sunrpc/xdr.c
|
|
|
|
*
|
|
|
|
* Generic XDR support.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
|
|
|
|
*/
|
|
|
|
|
2005-08-12 00:25:23 +04:00
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/sunrpc/xdr.h>
|
|
|
|
#include <linux/sunrpc/msg_prot.h>
|
2018-09-13 19:22:04 +03:00
|
|
|
#include <linux/bvec.h>
|
2019-02-11 19:24:10 +03:00
|
|
|
#include <trace/events/sunrpc.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XDR functions for basic NFS types
|
|
|
|
*/
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 *
|
|
|
|
xdr_encode_netobj(__be32 *p, const struct xdr_netobj *obj)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int quadlen = XDR_QUADLEN(obj->len);
|
|
|
|
|
|
|
|
p[quadlen] = 0; /* zero trailing bytes */
|
2009-08-14 18:18:44 +04:00
|
|
|
*p++ = cpu_to_be32(obj->len);
|
2005-04-17 02:20:36 +04:00
|
|
|
memcpy(p, obj->data, obj->len);
|
|
|
|
return p + XDR_QUADLEN(obj->len);
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_encode_netobj);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 *
|
|
|
|
xdr_decode_netobj(__be32 *p, struct xdr_netobj *obj)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
|
2009-08-14 18:18:49 +04:00
|
|
|
if ((len = be32_to_cpu(*p++)) > XDR_MAX_NETOBJ)
|
2005-04-17 02:20:36 +04:00
|
|
|
return NULL;
|
|
|
|
obj->len = len;
|
|
|
|
obj->data = (u8 *) p;
|
|
|
|
return p + XDR_QUADLEN(len);
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_decode_netobj);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* xdr_encode_opaque_fixed - Encode fixed length opaque data
|
2005-05-01 19:59:25 +04:00
|
|
|
* @p: pointer to current position in XDR buffer.
|
|
|
|
* @ptr: pointer to data to encode (or NULL)
|
|
|
|
* @nbytes: size of data.
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Copy the array of data of length nbytes at ptr to the XDR buffer
|
|
|
|
* at position p, then align to the next 32-bit boundary by padding
|
|
|
|
* with zero bytes (see RFC1832).
|
|
|
|
* Note: if ptr is NULL, only the padding is performed.
|
|
|
|
*
|
|
|
|
* Returns the updated current XDR buffer position
|
|
|
|
*
|
|
|
|
*/
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 *xdr_encode_opaque_fixed(__be32 *p, const void *ptr, unsigned int nbytes)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
if (likely(nbytes != 0)) {
|
|
|
|
unsigned int quadlen = XDR_QUADLEN(nbytes);
|
|
|
|
unsigned int padding = (quadlen << 2) - nbytes;
|
|
|
|
|
|
|
|
if (ptr != NULL)
|
|
|
|
memcpy(p, ptr, nbytes);
|
|
|
|
if (padding != 0)
|
|
|
|
memset((char *)p + nbytes, 0, padding);
|
|
|
|
p += quadlen;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_encode_opaque_fixed);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* xdr_encode_opaque - Encode variable length opaque data
|
2005-05-01 19:59:25 +04:00
|
|
|
* @p: pointer to current position in XDR buffer.
|
|
|
|
* @ptr: pointer to data to encode (or NULL)
|
|
|
|
* @nbytes: size of data.
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Returns the updated current XDR buffer position
|
|
|
|
*/
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int nbytes)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2009-08-14 18:18:44 +04:00
|
|
|
*p++ = cpu_to_be32(nbytes);
|
2005-04-17 02:20:36 +04:00
|
|
|
return xdr_encode_opaque_fixed(p, ptr, nbytes);
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_encode_opaque);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 *
|
|
|
|
xdr_encode_string(__be32 *p, const char *string)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
return xdr_encode_array(p, string, strlen(string));
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_encode_string);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 *
|
2007-11-01 23:56:47 +03:00
|
|
|
xdr_decode_string_inplace(__be32 *p, char **sp,
|
|
|
|
unsigned int *lenp, unsigned int maxlen)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-11-01 23:56:47 +03:00
|
|
|
u32 len;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-08-14 18:18:49 +04:00
|
|
|
len = be32_to_cpu(*p++);
|
2007-11-01 23:56:47 +03:00
|
|
|
if (len > maxlen)
|
2005-04-17 02:20:36 +04:00
|
|
|
return NULL;
|
|
|
|
*lenp = len;
|
|
|
|
*sp = (char *) p;
|
|
|
|
return p + XDR_QUADLEN(len);
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_decode_string_inplace);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2010-09-22 00:55:48 +04:00
|
|
|
/**
|
|
|
|
* xdr_terminate_string - '\0'-terminate a string residing in an xdr_buf
|
|
|
|
* @buf: XDR buffer where string resides
|
|
|
|
* @len: length of string, in bytes
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xdr_terminate_string(struct xdr_buf *buf, const u32 len)
|
|
|
|
{
|
|
|
|
char *kaddr;
|
|
|
|
|
2011-11-25 19:14:40 +04:00
|
|
|
kaddr = kmap_atomic(buf->pages[0]);
|
2010-09-22 00:55:48 +04:00
|
|
|
kaddr[buf->page_base + len] = '\0';
|
2011-11-25 19:14:40 +04:00
|
|
|
kunmap_atomic(kaddr);
|
2010-09-22 00:55:48 +04:00
|
|
|
}
|
2011-07-14 03:24:15 +04:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_terminate_string);
|
2010-09-22 00:55:48 +04:00
|
|
|
|
2018-09-13 19:22:04 +03:00
|
|
|
size_t
|
|
|
|
xdr_buf_pagecount(struct xdr_buf *buf)
|
|
|
|
{
|
|
|
|
if (!buf->page_len)
|
|
|
|
return 0;
|
|
|
|
return (buf->page_base + buf->page_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp)
|
|
|
|
{
|
|
|
|
size_t i, n = xdr_buf_pagecount(buf);
|
|
|
|
|
|
|
|
if (n != 0 && buf->bvec == NULL) {
|
|
|
|
buf->bvec = kmalloc_array(n, sizeof(buf->bvec[0]), gfp);
|
|
|
|
if (!buf->bvec)
|
|
|
|
return -ENOMEM;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
buf->bvec[i].bv_page = buf->pages[i];
|
|
|
|
buf->bvec[i].bv_len = PAGE_SIZE;
|
|
|
|
buf->bvec[i].bv_offset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xdr_free_bvec(struct xdr_buf *buf)
|
|
|
|
{
|
|
|
|
kfree(buf->bvec);
|
|
|
|
buf->bvec = NULL;
|
|
|
|
}
|
|
|
|
|
2019-02-11 19:25:20 +03:00
|
|
|
/**
|
|
|
|
* xdr_inline_pages - Prepare receive buffer for a large reply
|
|
|
|
* @xdr: xdr_buf into which reply will be placed
|
|
|
|
* @offset: expected offset where data payload will start, in bytes
|
|
|
|
* @pages: vector of struct page pointers
|
|
|
|
* @base: offset in first page where receive should start, in bytes
|
|
|
|
* @len: expected size of the upper layer data payload, in bytes
|
|
|
|
*
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
void
|
|
|
|
xdr_inline_pages(struct xdr_buf *xdr, unsigned int offset,
|
|
|
|
struct page **pages, unsigned int base, unsigned int len)
|
|
|
|
{
|
|
|
|
struct kvec *head = xdr->head;
|
|
|
|
struct kvec *tail = xdr->tail;
|
|
|
|
char *buf = (char *)head->iov_base;
|
|
|
|
unsigned int buflen = head->iov_len;
|
|
|
|
|
|
|
|
head->iov_len = offset;
|
|
|
|
|
|
|
|
xdr->pages = pages;
|
|
|
|
xdr->page_base = base;
|
|
|
|
xdr->page_len = len;
|
|
|
|
|
|
|
|
tail->iov_base = buf + offset;
|
|
|
|
tail->iov_len = buflen - offset;
|
2019-02-11 19:25:25 +03:00
|
|
|
if ((xdr->page_len & 3) == 0)
|
|
|
|
tail->iov_len -= sizeof(__be32);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
xdr->buflen += len;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_inline_pages);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper routines for doing 'memmove' like operations on a struct xdr_buf
|
2012-07-10 14:55:09 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2005-04-17 02:20:36 +04:00
|
|
|
* _shift_data_right_pages
|
|
|
|
* @pages: vector of pages containing both the source and dest memory area.
|
|
|
|
* @pgto_base: page vector address of destination
|
|
|
|
* @pgfrom_base: page vector address of source
|
|
|
|
* @len: number of bytes to copy
|
|
|
|
*
|
|
|
|
* Note: the addresses pgto_base and pgfrom_base are both calculated in
|
|
|
|
* the same way:
|
|
|
|
* if a memory area starts at byte 'base' in page 'pages[i]',
|
2016-04-01 15:29:48 +03:00
|
|
|
* then its address is given as (i << PAGE_SHIFT) + base
|
2005-04-17 02:20:36 +04:00
|
|
|
* Also note: pgfrom_base must be < pgto_base, but the memory areas
|
|
|
|
* they point to may overlap.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_shift_data_right_pages(struct page **pages, size_t pgto_base,
|
|
|
|
size_t pgfrom_base, size_t len)
|
|
|
|
{
|
|
|
|
struct page **pgfrom, **pgto;
|
|
|
|
char *vfrom, *vto;
|
|
|
|
size_t copy;
|
|
|
|
|
|
|
|
BUG_ON(pgto_base <= pgfrom_base);
|
|
|
|
|
|
|
|
pgto_base += len;
|
|
|
|
pgfrom_base += len;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
pgto = pages + (pgto_base >> PAGE_SHIFT);
|
|
|
|
pgfrom = pages + (pgfrom_base >> PAGE_SHIFT);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
pgto_base &= ~PAGE_MASK;
|
|
|
|
pgfrom_base &= ~PAGE_MASK;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
/* Are any pointers crossing a page boundary? */
|
|
|
|
if (pgto_base == 0) {
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
pgto_base = PAGE_SIZE;
|
2005-04-17 02:20:36 +04:00
|
|
|
pgto--;
|
|
|
|
}
|
|
|
|
if (pgfrom_base == 0) {
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
pgfrom_base = PAGE_SIZE;
|
2005-04-17 02:20:36 +04:00
|
|
|
pgfrom--;
|
|
|
|
}
|
|
|
|
|
|
|
|
copy = len;
|
|
|
|
if (copy > pgto_base)
|
|
|
|
copy = pgto_base;
|
|
|
|
if (copy > pgfrom_base)
|
|
|
|
copy = pgfrom_base;
|
|
|
|
pgto_base -= copy;
|
|
|
|
pgfrom_base -= copy;
|
|
|
|
|
2011-11-25 19:14:40 +04:00
|
|
|
vto = kmap_atomic(*pgto);
|
2013-08-28 21:35:13 +04:00
|
|
|
if (*pgto != *pgfrom) {
|
|
|
|
vfrom = kmap_atomic(*pgfrom);
|
|
|
|
memcpy(vto + pgto_base, vfrom + pgfrom_base, copy);
|
|
|
|
kunmap_atomic(vfrom);
|
|
|
|
} else
|
|
|
|
memmove(vto + pgto_base, vto + pgfrom_base, copy);
|
2006-07-05 21:17:12 +04:00
|
|
|
flush_dcache_page(*pgto);
|
2011-11-25 19:14:40 +04:00
|
|
|
kunmap_atomic(vto);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
} while ((len -= copy) != 0);
|
|
|
|
}
|
|
|
|
|
2012-07-10 14:55:09 +04:00
|
|
|
/**
|
2005-04-17 02:20:36 +04:00
|
|
|
* _copy_to_pages
|
|
|
|
* @pages: array of pages
|
|
|
|
* @pgbase: page vector address of destination
|
|
|
|
* @p: pointer to source data
|
|
|
|
* @len: length
|
|
|
|
*
|
|
|
|
* Copies data from an arbitrary memory location into an array of pages
|
|
|
|
* The copy is assumed to be non-overlapping.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_copy_to_pages(struct page **pages, size_t pgbase, const char *p, size_t len)
|
|
|
|
{
|
|
|
|
struct page **pgto;
|
|
|
|
char *vto;
|
|
|
|
size_t copy;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
pgto = pages + (pgbase >> PAGE_SHIFT);
|
|
|
|
pgbase &= ~PAGE_MASK;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-04-01 01:02:02 +04:00
|
|
|
for (;;) {
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
copy = PAGE_SIZE - pgbase;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy > len)
|
|
|
|
copy = len;
|
|
|
|
|
2011-11-25 19:14:40 +04:00
|
|
|
vto = kmap_atomic(*pgto);
|
2005-04-17 02:20:36 +04:00
|
|
|
memcpy(vto + pgbase, p, copy);
|
2011-11-25 19:14:40 +04:00
|
|
|
kunmap_atomic(vto);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2008-04-01 01:02:02 +04:00
|
|
|
len -= copy;
|
|
|
|
if (len == 0)
|
|
|
|
break;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
pgbase += copy;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
if (pgbase == PAGE_SIZE) {
|
2005-04-17 02:20:36 +04:00
|
|
|
flush_dcache_page(*pgto);
|
|
|
|
pgbase = 0;
|
|
|
|
pgto++;
|
|
|
|
}
|
|
|
|
p += copy;
|
2008-04-01 01:02:02 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
flush_dcache_page(*pgto);
|
|
|
|
}
|
|
|
|
|
2012-07-10 14:55:09 +04:00
|
|
|
/**
|
2005-04-17 02:20:36 +04:00
|
|
|
* _copy_from_pages
|
|
|
|
* @p: pointer to destination
|
|
|
|
* @pages: array of pages
|
|
|
|
* @pgbase: offset of source data
|
|
|
|
* @len: length
|
|
|
|
*
|
|
|
|
* Copies data into an arbitrary memory location from an array of pages
|
|
|
|
* The copy is assumed to be non-overlapping.
|
|
|
|
*/
|
2011-12-07 20:55:27 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
_copy_from_pages(char *p, struct page **pages, size_t pgbase, size_t len)
|
|
|
|
{
|
|
|
|
struct page **pgfrom;
|
|
|
|
char *vfrom;
|
|
|
|
size_t copy;
|
|
|
|
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
pgfrom = pages + (pgbase >> PAGE_SHIFT);
|
|
|
|
pgbase &= ~PAGE_MASK;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
do {
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
copy = PAGE_SIZE - pgbase;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (copy > len)
|
|
|
|
copy = len;
|
|
|
|
|
2011-11-25 19:14:40 +04:00
|
|
|
vfrom = kmap_atomic(*pgfrom);
|
2005-04-17 02:20:36 +04:00
|
|
|
memcpy(p, vfrom + pgbase, copy);
|
2011-11-25 19:14:40 +04:00
|
|
|
kunmap_atomic(vfrom);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
pgbase += copy;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
if (pgbase == PAGE_SIZE) {
|
2005-04-17 02:20:36 +04:00
|
|
|
pgbase = 0;
|
|
|
|
pgfrom++;
|
|
|
|
}
|
|
|
|
p += copy;
|
|
|
|
|
|
|
|
} while ((len -= copy) != 0);
|
|
|
|
}
|
2011-12-07 20:55:27 +04:00
|
|
|
EXPORT_SYMBOL_GPL(_copy_from_pages);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-07-10 14:55:09 +04:00
|
|
|
/**
|
2005-04-17 02:20:36 +04:00
|
|
|
* xdr_shrink_bufhead
|
|
|
|
* @buf: xdr_buf
|
|
|
|
* @len: bytes to remove from buf->head[0]
|
|
|
|
*
|
2007-02-10 02:38:13 +03:00
|
|
|
* Shrinks XDR buffer's header kvec buf->head[0] by
|
2005-04-17 02:20:36 +04:00
|
|
|
* 'len' bytes. The extra data is not lost, but is instead
|
|
|
|
* moved into the inlined pages and/or the tail.
|
|
|
|
*/
|
2019-02-11 19:24:16 +03:00
|
|
|
static unsigned int
|
2005-04-17 02:20:36 +04:00
|
|
|
xdr_shrink_bufhead(struct xdr_buf *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct kvec *head, *tail;
|
|
|
|
size_t copy, offs;
|
|
|
|
unsigned int pglen = buf->page_len;
|
2019-02-11 19:24:16 +03:00
|
|
|
unsigned int result;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-02-11 19:24:16 +03:00
|
|
|
result = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
tail = buf->tail;
|
|
|
|
head = buf->head;
|
2012-10-23 18:43:42 +04:00
|
|
|
|
|
|
|
WARN_ON_ONCE(len > head->iov_len);
|
|
|
|
if (len > head->iov_len)
|
|
|
|
len = head->iov_len;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Shift the tail first */
|
|
|
|
if (tail->iov_len != 0) {
|
|
|
|
if (tail->iov_len > len) {
|
|
|
|
copy = tail->iov_len - len;
|
|
|
|
memmove((char *)tail->iov_base + len,
|
|
|
|
tail->iov_base, copy);
|
2019-02-11 19:24:16 +03:00
|
|
|
result += copy;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
/* Copy from the inlined pages into the tail */
|
|
|
|
copy = len;
|
|
|
|
if (copy > pglen)
|
|
|
|
copy = pglen;
|
|
|
|
offs = len - copy;
|
|
|
|
if (offs >= tail->iov_len)
|
|
|
|
copy = 0;
|
|
|
|
else if (copy > tail->iov_len - offs)
|
|
|
|
copy = tail->iov_len - offs;
|
2019-02-11 19:24:16 +03:00
|
|
|
if (copy != 0) {
|
2005-04-17 02:20:36 +04:00
|
|
|
_copy_from_pages((char *)tail->iov_base + offs,
|
|
|
|
buf->pages,
|
|
|
|
buf->page_base + pglen + offs - len,
|
|
|
|
copy);
|
2019-02-11 19:24:16 +03:00
|
|
|
result += copy;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Do we also need to copy data from the head into the tail ? */
|
|
|
|
if (len > pglen) {
|
|
|
|
offs = copy = len - pglen;
|
|
|
|
if (copy > tail->iov_len)
|
|
|
|
copy = tail->iov_len;
|
|
|
|
memcpy(tail->iov_base,
|
|
|
|
(char *)head->iov_base +
|
|
|
|
head->iov_len - offs,
|
|
|
|
copy);
|
2019-02-11 19:24:16 +03:00
|
|
|
result += copy;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Now handle pages */
|
|
|
|
if (pglen != 0) {
|
|
|
|
if (pglen > len)
|
|
|
|
_shift_data_right_pages(buf->pages,
|
|
|
|
buf->page_base + len,
|
|
|
|
buf->page_base,
|
|
|
|
pglen - len);
|
|
|
|
copy = len;
|
|
|
|
if (len > pglen)
|
|
|
|
copy = pglen;
|
|
|
|
_copy_to_pages(buf->pages, buf->page_base,
|
|
|
|
(char *)head->iov_base + head->iov_len - len,
|
|
|
|
copy);
|
2019-02-11 19:24:16 +03:00
|
|
|
result += copy;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
head->iov_len -= len;
|
|
|
|
buf->buflen -= len;
|
|
|
|
/* Have we truncated the message? */
|
|
|
|
if (buf->len > buf->buflen)
|
|
|
|
buf->len = buf->buflen;
|
2019-02-11 19:24:16 +03:00
|
|
|
|
|
|
|
return result;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2012-07-10 14:55:09 +04:00
|
|
|
/**
|
2019-11-15 16:39:07 +03:00
|
|
|
* xdr_shrink_pagelen - shrinks buf->pages by up to @len bytes
|
2005-04-17 02:20:36 +04:00
|
|
|
* @buf: xdr_buf
|
|
|
|
* @len: bytes to remove from buf->pages
|
|
|
|
*
|
2019-11-15 16:39:07 +03:00
|
|
|
* The extra data is not lost, but is instead moved into buf->tail.
|
|
|
|
* Returns the actual number of bytes moved.
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2019-02-11 19:24:16 +03:00
|
|
|
static unsigned int
|
2005-04-17 02:20:36 +04:00
|
|
|
xdr_shrink_pagelen(struct xdr_buf *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct kvec *tail;
|
|
|
|
size_t copy;
|
|
|
|
unsigned int pglen = buf->page_len;
|
2010-08-29 20:13:16 +04:00
|
|
|
unsigned int tailbuf_len;
|
2019-02-11 19:24:16 +03:00
|
|
|
unsigned int result;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-02-11 19:24:16 +03:00
|
|
|
result = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
tail = buf->tail;
|
2019-11-15 16:39:07 +03:00
|
|
|
if (len > buf->page_len)
|
|
|
|
len = buf-> page_len;
|
2010-08-29 20:13:16 +04:00
|
|
|
tailbuf_len = buf->buflen - buf->head->iov_len - buf->page_len;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Shift the tail first */
|
2010-08-29 20:13:16 +04:00
|
|
|
if (tailbuf_len != 0) {
|
|
|
|
unsigned int free_space = tailbuf_len - tail->iov_len;
|
|
|
|
|
|
|
|
if (len < free_space)
|
|
|
|
free_space = len;
|
|
|
|
tail->iov_len += free_space;
|
|
|
|
|
2010-08-29 20:13:15 +04:00
|
|
|
copy = len;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (tail->iov_len > len) {
|
2010-08-29 20:13:15 +04:00
|
|
|
char *p = (char *)tail->iov_base + len;
|
2010-08-29 20:13:15 +04:00
|
|
|
memmove(p, tail->iov_base, tail->iov_len - len);
|
2019-02-11 19:24:16 +03:00
|
|
|
result += tail->iov_len - len;
|
2010-08-29 20:13:15 +04:00
|
|
|
} else
|
2005-04-17 02:20:36 +04:00
|
|
|
copy = tail->iov_len;
|
2010-08-29 20:13:15 +04:00
|
|
|
/* Copy from the inlined pages into the tail */
|
2005-04-17 02:20:36 +04:00
|
|
|
_copy_from_pages((char *)tail->iov_base,
|
|
|
|
buf->pages, buf->page_base + pglen - len,
|
|
|
|
copy);
|
2019-02-11 19:24:16 +03:00
|
|
|
result += copy;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
buf->page_len -= len;
|
|
|
|
buf->buflen -= len;
|
|
|
|
/* Have we truncated the message? */
|
|
|
|
if (buf->len > buf->buflen)
|
|
|
|
buf->len = buf->buflen;
|
2019-02-11 19:24:16 +03:00
|
|
|
|
|
|
|
return result;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xdr_shift_buf(struct xdr_buf *buf, size_t len)
|
|
|
|
{
|
|
|
|
xdr_shrink_bufhead(buf, len);
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_shift_buf);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-06-22 01:14:46 +04:00
|
|
|
/**
|
|
|
|
* xdr_stream_pos - Return the current offset from the start of the xdr_stream
|
|
|
|
* @xdr: pointer to struct xdr_stream
|
|
|
|
*/
|
|
|
|
unsigned int xdr_stream_pos(const struct xdr_stream *xdr)
|
|
|
|
{
|
|
|
|
return (unsigned int)(XDR_QUADLEN(xdr->buf->len) - xdr->nwords) << 2;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_stream_pos);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* xdr_init_encode - Initialize a struct xdr_stream for sending data.
|
|
|
|
* @xdr: pointer to xdr_stream struct
|
|
|
|
* @buf: pointer to XDR buffer in which to encode data
|
|
|
|
* @p: current pointer inside XDR buffer
|
2019-02-11 19:24:05 +03:00
|
|
|
* @rqst: pointer to controlling rpc_rqst, for debugging
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* Note: at the moment the RPC client only passes the length of our
|
|
|
|
* scratch buffer in the xdr_buf's header kvec. Previously this
|
|
|
|
* meant we needed to call xdr_adjust_iovec() after encoding the
|
|
|
|
* data. With the new scheme, the xdr_stream manages the details
|
|
|
|
* of the buffer length, and takes care of adjusting the kvec
|
|
|
|
* length for us.
|
|
|
|
*/
|
2019-02-11 19:24:05 +03:00
|
|
|
void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p,
|
|
|
|
struct rpc_rqst *rqst)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct kvec *iov = buf->head;
|
2005-06-22 21:16:19 +04:00
|
|
|
int scratch_len = buf->buflen - buf->page_len - buf->tail[0].iov_len;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-08-27 00:04:46 +04:00
|
|
|
xdr_set_scratch_buffer(xdr, NULL, 0);
|
2005-06-22 21:16:19 +04:00
|
|
|
BUG_ON(scratch_len < 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
xdr->buf = buf;
|
|
|
|
xdr->iov = iov;
|
2006-09-27 09:29:38 +04:00
|
|
|
xdr->p = (__be32 *)((char *)iov->iov_base + iov->iov_len);
|
|
|
|
xdr->end = (__be32 *)((char *)iov->iov_base + scratch_len);
|
2005-06-22 21:16:19 +04:00
|
|
|
BUG_ON(iov->iov_len > scratch_len);
|
|
|
|
|
|
|
|
if (p != xdr->p && p != NULL) {
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
BUG_ON(p < xdr->p || p > xdr->end);
|
|
|
|
len = (char *)p - (char *)xdr->p;
|
|
|
|
xdr->p = p;
|
|
|
|
buf->len += len;
|
|
|
|
iov->iov_len += len;
|
|
|
|
}
|
2019-02-11 19:24:05 +03:00
|
|
|
xdr->rqst = rqst;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_init_encode);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-08-27 00:04:46 +04:00
|
|
|
/**
|
|
|
|
* xdr_commit_encode - Ensure all data is written to buffer
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
*
|
|
|
|
* We handle encoding across page boundaries by giving the caller a
|
|
|
|
* temporary location to write to, then later copying the data into
|
|
|
|
* place; xdr_commit_encode does that copying.
|
|
|
|
*
|
|
|
|
* Normally the caller doesn't need to call this directly, as the
|
|
|
|
* following xdr_reserve_space will do it. But an explicit call may be
|
|
|
|
* required at the end of encoding, or any other time when the xdr_buf
|
|
|
|
* data might be read.
|
|
|
|
*/
|
2019-08-20 01:37:05 +03:00
|
|
|
inline void xdr_commit_encode(struct xdr_stream *xdr)
|
2013-08-27 00:04:46 +04:00
|
|
|
{
|
|
|
|
int shift = xdr->scratch.iov_len;
|
|
|
|
void *page;
|
|
|
|
|
|
|
|
if (shift == 0)
|
|
|
|
return;
|
|
|
|
page = page_address(*xdr->page_ptr);
|
|
|
|
memcpy(xdr->scratch.iov_base, page, shift);
|
|
|
|
memmove(page, page + shift, (void *)xdr->p - page);
|
|
|
|
xdr->scratch.iov_len = 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_commit_encode);
|
|
|
|
|
2014-07-13 02:01:02 +04:00
|
|
|
static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
|
|
|
|
size_t nbytes)
|
2013-08-27 00:04:46 +04:00
|
|
|
{
|
2018-11-08 05:04:57 +03:00
|
|
|
__be32 *p;
|
2013-08-27 00:04:46 +04:00
|
|
|
int space_left;
|
|
|
|
int frag1bytes, frag2bytes;
|
|
|
|
|
|
|
|
if (nbytes > PAGE_SIZE)
|
2019-02-11 19:24:10 +03:00
|
|
|
goto out_overflow; /* Bigger buffers require special handling */
|
2013-08-27 00:04:46 +04:00
|
|
|
if (xdr->buf->len + nbytes > xdr->buf->buflen)
|
2019-02-11 19:24:10 +03:00
|
|
|
goto out_overflow; /* Sorry, we're totally out of space */
|
2013-08-27 00:04:46 +04:00
|
|
|
frag1bytes = (xdr->end - xdr->p) << 2;
|
|
|
|
frag2bytes = nbytes - frag1bytes;
|
|
|
|
if (xdr->iov)
|
|
|
|
xdr->iov->iov_len += frag1bytes;
|
2014-06-02 20:05:47 +04:00
|
|
|
else
|
2013-08-27 00:04:46 +04:00
|
|
|
xdr->buf->page_len += frag1bytes;
|
2014-06-02 20:05:47 +04:00
|
|
|
xdr->page_ptr++;
|
2013-08-27 00:04:46 +04:00
|
|
|
xdr->iov = NULL;
|
|
|
|
/*
|
|
|
|
* If the last encode didn't end exactly on a page boundary, the
|
|
|
|
* next one will straddle boundaries. Encode into the next
|
|
|
|
* page, then copy it back later in xdr_commit_encode. We use
|
|
|
|
* the "scratch" iov to track any temporarily unused fragment of
|
|
|
|
* space at the end of the previous buffer:
|
|
|
|
*/
|
|
|
|
xdr->scratch.iov_base = xdr->p;
|
|
|
|
xdr->scratch.iov_len = frag1bytes;
|
|
|
|
p = page_address(*xdr->page_ptr);
|
|
|
|
/*
|
|
|
|
* Note this is where the next encode will start after we've
|
|
|
|
* shifted this one back:
|
|
|
|
*/
|
|
|
|
xdr->p = (void *)p + frag2bytes;
|
|
|
|
space_left = xdr->buf->buflen - xdr->buf->len;
|
|
|
|
xdr->end = (void *)p + min_t(int, space_left, PAGE_SIZE);
|
|
|
|
xdr->buf->page_len += frag2bytes;
|
|
|
|
xdr->buf->len += nbytes;
|
|
|
|
return p;
|
2019-02-11 19:24:10 +03:00
|
|
|
out_overflow:
|
|
|
|
trace_rpc_xdr_overflow(xdr, nbytes);
|
|
|
|
return NULL;
|
2013-08-27 00:04:46 +04:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* xdr_reserve_space - Reserve buffer space for sending
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
* @nbytes: number of bytes to reserve
|
|
|
|
*
|
|
|
|
* Checks that we have enough buffer space to encode 'nbytes' more
|
|
|
|
* bytes of data. If so, update the total xdr_buf length, and
|
|
|
|
* adjust the length of the current kvec.
|
|
|
|
*/
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 * xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 *p = xdr->p;
|
|
|
|
__be32 *q;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2013-08-27 00:04:46 +04:00
|
|
|
xdr_commit_encode(xdr);
|
2005-04-17 02:20:36 +04:00
|
|
|
/* align nbytes on the next 32-bit boundary */
|
|
|
|
nbytes += 3;
|
|
|
|
nbytes &= ~3;
|
|
|
|
q = p + (nbytes >> 2);
|
|
|
|
if (unlikely(q > xdr->end || q < p))
|
2013-08-27 00:04:46 +04:00
|
|
|
return xdr_get_next_encode_buffer(xdr, nbytes);
|
2005-04-17 02:20:36 +04:00
|
|
|
xdr->p = q;
|
2013-08-27 00:04:46 +04:00
|
|
|
if (xdr->iov)
|
|
|
|
xdr->iov->iov_len += nbytes;
|
|
|
|
else
|
|
|
|
xdr->buf->page_len += nbytes;
|
2005-04-17 02:20:36 +04:00
|
|
|
xdr->buf->len += nbytes;
|
|
|
|
return p;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_reserve_space);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-02-26 02:44:21 +04:00
|
|
|
/**
|
|
|
|
* xdr_truncate_encode - truncate an encode buffer
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
* @len: new length of buffer
|
|
|
|
*
|
|
|
|
* Truncates the xdr stream, so that xdr->buf->len == len,
|
|
|
|
* and xdr->p points at offset len from the start of the buffer, and
|
|
|
|
* head, tail, and page lengths are adjusted to correspond.
|
|
|
|
*
|
|
|
|
* If this means moving xdr->p to a different buffer, we assume that
|
2020-08-23 04:07:38 +03:00
|
|
|
* the end pointer should be set to the end of the current page,
|
2014-02-26 02:44:21 +04:00
|
|
|
* except in the case of the head buffer when we assume the head
|
|
|
|
* buffer's current length represents the end of the available buffer.
|
|
|
|
*
|
|
|
|
* This is *not* safe to use on a buffer that already has inlined page
|
|
|
|
* cache pages (as in a zero-copy server read reply), except for the
|
|
|
|
* simple case of truncating from one position in the tail to another.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void xdr_truncate_encode(struct xdr_stream *xdr, size_t len)
|
|
|
|
{
|
|
|
|
struct xdr_buf *buf = xdr->buf;
|
|
|
|
struct kvec *head = buf->head;
|
|
|
|
struct kvec *tail = buf->tail;
|
|
|
|
int fraglen;
|
2014-12-23 00:14:51 +03:00
|
|
|
int new;
|
2014-02-26 02:44:21 +04:00
|
|
|
|
|
|
|
if (len > buf->len) {
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return;
|
|
|
|
}
|
2013-08-27 00:04:46 +04:00
|
|
|
xdr_commit_encode(xdr);
|
2014-02-26 02:44:21 +04:00
|
|
|
|
|
|
|
fraglen = min_t(int, buf->len - len, tail->iov_len);
|
|
|
|
tail->iov_len -= fraglen;
|
|
|
|
buf->len -= fraglen;
|
2014-09-20 01:21:35 +04:00
|
|
|
if (tail->iov_len) {
|
2014-02-26 02:44:21 +04:00
|
|
|
xdr->p = tail->iov_base + tail->iov_len;
|
2014-10-01 19:36:31 +04:00
|
|
|
WARN_ON_ONCE(!xdr->end);
|
|
|
|
WARN_ON_ONCE(!xdr->iov);
|
2014-02-26 02:44:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
WARN_ON_ONCE(fraglen);
|
|
|
|
fraglen = min_t(int, buf->len - len, buf->page_len);
|
|
|
|
buf->page_len -= fraglen;
|
|
|
|
buf->len -= fraglen;
|
|
|
|
|
|
|
|
new = buf->page_base + buf->page_len;
|
2014-12-23 00:14:51 +03:00
|
|
|
|
|
|
|
xdr->page_ptr = buf->pages + (new >> PAGE_SHIFT);
|
2014-02-26 02:44:21 +04:00
|
|
|
|
2014-09-20 01:21:35 +04:00
|
|
|
if (buf->page_len) {
|
2014-02-26 02:44:21 +04:00
|
|
|
xdr->p = page_address(*xdr->page_ptr);
|
|
|
|
xdr->end = (void *)xdr->p + PAGE_SIZE;
|
|
|
|
xdr->p = (void *)xdr->p + (new % PAGE_SIZE);
|
2014-10-01 19:36:31 +04:00
|
|
|
WARN_ON_ONCE(xdr->iov);
|
2014-02-26 02:44:21 +04:00
|
|
|
return;
|
|
|
|
}
|
2018-10-30 23:10:40 +03:00
|
|
|
if (fraglen)
|
2014-02-26 02:44:21 +04:00
|
|
|
xdr->end = head->iov_base + head->iov_len;
|
|
|
|
/* (otherwise assume xdr->end is already set) */
|
2018-10-30 23:10:40 +03:00
|
|
|
xdr->page_ptr--;
|
2014-02-26 02:44:21 +04:00
|
|
|
head->iov_len = len;
|
|
|
|
buf->len = len;
|
|
|
|
xdr->p = head->iov_base + head->iov_len;
|
|
|
|
xdr->iov = buf->head;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xdr_truncate_encode);
|
|
|
|
|
2014-03-06 22:22:18 +04:00
|
|
|
/**
|
|
|
|
* xdr_restrict_buflen - decrease available buffer space
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
* @newbuflen: new maximum number of bytes available
|
|
|
|
*
|
|
|
|
* Adjust our idea of how much space is available in the buffer.
|
|
|
|
* If we've already used too much space in the buffer, returns -1.
|
|
|
|
* If the available space is already smaller than newbuflen, returns 0
|
|
|
|
* and does nothing. Otherwise, adjusts xdr->buf->buflen to newbuflen
|
|
|
|
* and ensures xdr->end is set at most offset newbuflen from the start
|
|
|
|
* of the buffer.
|
|
|
|
*/
|
|
|
|
int xdr_restrict_buflen(struct xdr_stream *xdr, int newbuflen)
|
|
|
|
{
|
|
|
|
struct xdr_buf *buf = xdr->buf;
|
|
|
|
int left_in_this_buf = (void *)xdr->end - (void *)xdr->p;
|
|
|
|
int end_offset = buf->len + left_in_this_buf;
|
|
|
|
|
|
|
|
if (newbuflen < 0 || newbuflen < buf->len)
|
|
|
|
return -1;
|
|
|
|
if (newbuflen > buf->buflen)
|
|
|
|
return 0;
|
|
|
|
if (newbuflen < end_offset)
|
|
|
|
xdr->end = (void *)xdr->end + newbuflen - end_offset;
|
|
|
|
buf->buflen = newbuflen;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(xdr_restrict_buflen);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* xdr_write_pages - Insert a list of pages into an XDR buffer for sending
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
* @pages: list of pages
|
|
|
|
* @base: offset of first byte
|
|
|
|
* @len: length of data in bytes
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void xdr_write_pages(struct xdr_stream *xdr, struct page **pages, unsigned int base,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
struct xdr_buf *buf = xdr->buf;
|
|
|
|
struct kvec *iov = buf->tail;
|
|
|
|
buf->pages = pages;
|
|
|
|
buf->page_base = base;
|
|
|
|
buf->page_len = len;
|
|
|
|
|
|
|
|
iov->iov_base = (char *)xdr->p;
|
|
|
|
iov->iov_len = 0;
|
|
|
|
xdr->iov = iov;
|
|
|
|
|
|
|
|
if (len & 3) {
|
|
|
|
unsigned int pad = 4 - (len & 3);
|
|
|
|
|
|
|
|
BUG_ON(xdr->p >= xdr->end);
|
|
|
|
iov->iov_base = (char *)xdr->p + (len & 3);
|
|
|
|
iov->iov_len += pad;
|
|
|
|
len += pad;
|
|
|
|
*xdr->p++ = 0;
|
|
|
|
}
|
|
|
|
buf->buflen += len;
|
|
|
|
buf->len += len;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_write_pages);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-01-09 01:45:38 +03:00
|
|
|
static void xdr_set_iov(struct xdr_stream *xdr, struct kvec *iov,
|
2012-06-29 01:17:48 +04:00
|
|
|
unsigned int len)
|
2011-01-09 01:45:38 +03:00
|
|
|
{
|
|
|
|
if (len > iov->iov_len)
|
|
|
|
len = iov->iov_len;
|
2012-06-29 01:17:48 +04:00
|
|
|
xdr->p = (__be32*)iov->iov_base;
|
2011-01-09 01:45:38 +03:00
|
|
|
xdr->end = (__be32*)(iov->iov_base + len);
|
|
|
|
xdr->iov = iov;
|
|
|
|
xdr->page_ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xdr_set_page_base(struct xdr_stream *xdr,
|
|
|
|
unsigned int base, unsigned int len)
|
|
|
|
{
|
|
|
|
unsigned int pgnr;
|
|
|
|
unsigned int maxlen;
|
|
|
|
unsigned int pgoff;
|
|
|
|
unsigned int pgend;
|
|
|
|
void *kaddr;
|
|
|
|
|
|
|
|
maxlen = xdr->buf->page_len;
|
|
|
|
if (base >= maxlen)
|
|
|
|
return -EINVAL;
|
|
|
|
maxlen -= base;
|
|
|
|
if (len > maxlen)
|
|
|
|
len = maxlen;
|
|
|
|
|
|
|
|
base += xdr->buf->page_base;
|
|
|
|
|
|
|
|
pgnr = base >> PAGE_SHIFT;
|
|
|
|
xdr->page_ptr = &xdr->buf->pages[pgnr];
|
|
|
|
kaddr = page_address(*xdr->page_ptr);
|
|
|
|
|
|
|
|
pgoff = base & ~PAGE_MASK;
|
|
|
|
xdr->p = (__be32*)(kaddr + pgoff);
|
|
|
|
|
|
|
|
pgend = pgoff + len;
|
|
|
|
if (pgend > PAGE_SIZE)
|
|
|
|
pgend = PAGE_SIZE;
|
|
|
|
xdr->end = (__be32*)(kaddr + pgend);
|
|
|
|
xdr->iov = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void xdr_set_next_page(struct xdr_stream *xdr)
|
|
|
|
{
|
|
|
|
unsigned int newbase;
|
|
|
|
|
|
|
|
newbase = (1 + xdr->page_ptr - xdr->buf->pages) << PAGE_SHIFT;
|
|
|
|
newbase -= xdr->buf->page_base;
|
|
|
|
|
|
|
|
if (xdr_set_page_base(xdr, newbase, PAGE_SIZE) < 0)
|
2016-09-20 21:33:43 +03:00
|
|
|
xdr_set_iov(xdr, xdr->buf->tail, xdr->nwords << 2);
|
2011-01-09 01:45:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool xdr_set_next_buffer(struct xdr_stream *xdr)
|
|
|
|
{
|
|
|
|
if (xdr->page_ptr != NULL)
|
|
|
|
xdr_set_next_page(xdr);
|
|
|
|
else if (xdr->iov == xdr->buf->head) {
|
|
|
|
if (xdr_set_page_base(xdr, 0, PAGE_SIZE) < 0)
|
2016-09-20 21:33:43 +03:00
|
|
|
xdr_set_iov(xdr, xdr->buf->tail, xdr->nwords << 2);
|
2011-01-09 01:45:38 +03:00
|
|
|
}
|
|
|
|
return xdr->p != xdr->end;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* xdr_init_decode - Initialize an xdr_stream for decoding data.
|
|
|
|
* @xdr: pointer to xdr_stream struct
|
|
|
|
* @buf: pointer to XDR buffer from which to decode data
|
|
|
|
* @p: current pointer inside XDR buffer
|
2019-02-11 19:24:05 +03:00
|
|
|
* @rqst: pointer to controlling rpc_rqst, for debugging
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2019-02-11 19:24:05 +03:00
|
|
|
void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p,
|
|
|
|
struct rpc_rqst *rqst)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
xdr->buf = buf;
|
2011-01-09 01:45:38 +03:00
|
|
|
xdr->scratch.iov_base = NULL;
|
|
|
|
xdr->scratch.iov_len = 0;
|
2012-06-20 17:58:35 +04:00
|
|
|
xdr->nwords = XDR_QUADLEN(buf->len);
|
2011-01-09 01:45:38 +03:00
|
|
|
if (buf->head[0].iov_len != 0)
|
2012-06-29 01:17:48 +04:00
|
|
|
xdr_set_iov(xdr, buf->head, buf->len);
|
2011-01-09 01:45:38 +03:00
|
|
|
else if (buf->page_len != 0)
|
|
|
|
xdr_set_page_base(xdr, 0, buf->len);
|
2016-04-06 18:32:52 +03:00
|
|
|
else
|
|
|
|
xdr_set_iov(xdr, buf->head, buf->len);
|
2012-06-20 17:58:35 +04:00
|
|
|
if (p != NULL && p > xdr->p && xdr->end >= p) {
|
|
|
|
xdr->nwords -= p - xdr->p;
|
2012-06-29 01:17:48 +04:00
|
|
|
xdr->p = p;
|
2012-06-20 17:58:35 +04:00
|
|
|
}
|
2019-02-11 19:24:05 +03:00
|
|
|
xdr->rqst = rqst;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_init_decode);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-05-19 22:16:47 +04:00
|
|
|
/**
|
2017-04-11 20:23:59 +03:00
|
|
|
* xdr_init_decode_pages - Initialize an xdr_stream for decoding into pages
|
2011-05-19 22:16:47 +04:00
|
|
|
* @xdr: pointer to xdr_stream struct
|
|
|
|
* @buf: pointer to XDR buffer from which to decode data
|
|
|
|
* @pages: list of pages to decode into
|
|
|
|
* @len: length in bytes of buffer in pages
|
|
|
|
*/
|
|
|
|
void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
|
|
|
|
struct page **pages, unsigned int len)
|
|
|
|
{
|
|
|
|
memset(buf, 0, sizeof(*buf));
|
|
|
|
buf->pages = pages;
|
|
|
|
buf->page_len = len;
|
|
|
|
buf->buflen = len;
|
|
|
|
buf->len = len;
|
2019-02-11 19:24:05 +03:00
|
|
|
xdr_init_decode(xdr, buf, NULL, NULL);
|
2011-05-19 22:16:47 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_init_decode_pages);
|
|
|
|
|
2011-01-09 01:45:38 +03:00
|
|
|
static __be32 * __xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes)
|
2010-10-20 03:58:49 +04:00
|
|
|
{
|
2012-06-20 17:58:35 +04:00
|
|
|
unsigned int nwords = XDR_QUADLEN(nbytes);
|
2010-10-20 03:58:49 +04:00
|
|
|
__be32 *p = xdr->p;
|
2012-06-20 17:58:35 +04:00
|
|
|
__be32 *q = p + nwords;
|
2010-10-20 03:58:49 +04:00
|
|
|
|
2012-06-20 17:58:35 +04:00
|
|
|
if (unlikely(nwords > xdr->nwords || q > xdr->end || q < p))
|
2010-10-20 03:58:49 +04:00
|
|
|
return NULL;
|
2011-01-09 01:45:38 +03:00
|
|
|
xdr->p = q;
|
2012-06-20 17:58:35 +04:00
|
|
|
xdr->nwords -= nwords;
|
2010-10-20 03:58:49 +04:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
2011-01-09 01:45:38 +03:00
|
|
|
* xdr_set_scratch_buffer - Attach a scratch buffer for decoding data.
|
|
|
|
* @xdr: pointer to xdr_stream struct
|
|
|
|
* @buf: pointer to an empty buffer
|
|
|
|
* @buflen: size of 'buf'
|
|
|
|
*
|
|
|
|
* The scratch buffer is used when decoding from an array of pages.
|
|
|
|
* If an xdr_inline_decode() call spans across page boundaries, then
|
|
|
|
* we copy the data into the scratch buffer in order to allow linear
|
|
|
|
* access.
|
|
|
|
*/
|
|
|
|
void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
xdr->scratch.iov_base = buf;
|
|
|
|
xdr->scratch.iov_len = buflen;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_set_scratch_buffer);
|
|
|
|
|
|
|
|
static __be32 *xdr_copy_to_scratch(struct xdr_stream *xdr, size_t nbytes)
|
|
|
|
{
|
|
|
|
__be32 *p;
|
2016-09-20 21:33:42 +03:00
|
|
|
char *cpdest = xdr->scratch.iov_base;
|
2011-01-09 01:45:38 +03:00
|
|
|
size_t cplen = (char *)xdr->end - (char *)xdr->p;
|
|
|
|
|
|
|
|
if (nbytes > xdr->scratch.iov_len)
|
2019-02-11 19:24:10 +03:00
|
|
|
goto out_overflow;
|
2016-09-20 21:33:42 +03:00
|
|
|
p = __xdr_inline_decode(xdr, cplen);
|
|
|
|
if (p == NULL)
|
|
|
|
return NULL;
|
|
|
|
memcpy(cpdest, p, cplen);
|
2019-02-11 19:24:10 +03:00
|
|
|
if (!xdr_set_next_buffer(xdr))
|
|
|
|
goto out_overflow;
|
2011-01-09 01:45:38 +03:00
|
|
|
cpdest += cplen;
|
|
|
|
nbytes -= cplen;
|
|
|
|
p = __xdr_inline_decode(xdr, nbytes);
|
|
|
|
if (p == NULL)
|
|
|
|
return NULL;
|
|
|
|
memcpy(cpdest, p, nbytes);
|
|
|
|
return xdr->scratch.iov_base;
|
2019-02-11 19:24:10 +03:00
|
|
|
out_overflow:
|
|
|
|
trace_rpc_xdr_overflow(xdr, nbytes);
|
|
|
|
return NULL;
|
2011-01-09 01:45:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xdr_inline_decode - Retrieve XDR data to decode
|
2005-04-17 02:20:36 +04:00
|
|
|
* @xdr: pointer to xdr_stream struct
|
|
|
|
* @nbytes: number of bytes of data to decode
|
|
|
|
*
|
|
|
|
* Check if the input buffer is long enough to enable us to decode
|
|
|
|
* 'nbytes' more bytes of data starting at the current position.
|
|
|
|
* If so return the current pointer, then update the current
|
|
|
|
* pointer position.
|
|
|
|
*/
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 * xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2011-01-09 01:45:38 +03:00
|
|
|
__be32 *p;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2019-02-11 19:24:10 +03:00
|
|
|
if (unlikely(nbytes == 0))
|
2011-01-09 01:45:38 +03:00
|
|
|
return xdr->p;
|
|
|
|
if (xdr->p == xdr->end && !xdr_set_next_buffer(xdr))
|
2019-02-11 19:24:10 +03:00
|
|
|
goto out_overflow;
|
2011-01-09 01:45:38 +03:00
|
|
|
p = __xdr_inline_decode(xdr, nbytes);
|
|
|
|
if (p != NULL)
|
|
|
|
return p;
|
|
|
|
return xdr_copy_to_scratch(xdr, nbytes);
|
2019-02-11 19:24:10 +03:00
|
|
|
out_overflow:
|
|
|
|
trace_rpc_xdr_overflow(xdr, nbytes);
|
|
|
|
return NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_inline_decode);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-06-26 20:34:05 +04:00
|
|
|
static unsigned int xdr_align_pages(struct xdr_stream *xdr, unsigned int len)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct xdr_buf *buf = xdr->buf;
|
|
|
|
struct kvec *iov;
|
2012-06-20 17:58:35 +04:00
|
|
|
unsigned int nwords = XDR_QUADLEN(len);
|
2012-06-26 20:19:55 +04:00
|
|
|
unsigned int cur = xdr_stream_pos(xdr);
|
2019-02-11 19:24:16 +03:00
|
|
|
unsigned int copied, offset;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-06-20 17:58:35 +04:00
|
|
|
if (xdr->nwords == 0)
|
2012-06-22 01:05:37 +04:00
|
|
|
return 0;
|
2019-02-11 19:24:16 +03:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Realign pages to current pointer position */
|
2019-02-11 19:24:16 +03:00
|
|
|
iov = buf->head;
|
2012-08-02 21:21:43 +04:00
|
|
|
if (iov->iov_len > cur) {
|
2019-02-11 19:24:16 +03:00
|
|
|
offset = iov->iov_len - cur;
|
|
|
|
copied = xdr_shrink_bufhead(buf, offset);
|
|
|
|
trace_rpc_xdr_alignment(xdr, offset, copied);
|
2012-08-02 21:21:43 +04:00
|
|
|
xdr->nwords = XDR_QUADLEN(buf->len - cur);
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-08-02 21:21:43 +04:00
|
|
|
if (nwords > xdr->nwords) {
|
|
|
|
nwords = xdr->nwords;
|
|
|
|
len = nwords << 2;
|
|
|
|
}
|
|
|
|
if (buf->page_len <= len)
|
2012-08-01 22:32:13 +04:00
|
|
|
len = buf->page_len;
|
2012-08-02 21:21:43 +04:00
|
|
|
else if (nwords < xdr->nwords) {
|
|
|
|
/* Truncate page data and move it into the tail */
|
2019-02-11 19:24:16 +03:00
|
|
|
offset = buf->page_len - len;
|
|
|
|
copied = xdr_shrink_pagelen(buf, offset);
|
|
|
|
trace_rpc_xdr_alignment(xdr, offset, copied);
|
2012-08-02 21:21:43 +04:00
|
|
|
xdr->nwords = XDR_QUADLEN(buf->len - cur);
|
|
|
|
}
|
2012-06-26 20:34:05 +04:00
|
|
|
return len;
|
|
|
|
}
|
2012-06-26 21:50:43 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/**
|
|
|
|
* xdr_read_pages - Ensure page-based XDR data to decode is aligned at current pointer position
|
|
|
|
* @xdr: pointer to xdr_stream struct
|
|
|
|
* @len: number of bytes of page data
|
|
|
|
*
|
|
|
|
* Moves data beyond the current pointer position from the XDR head[] buffer
|
|
|
|
* into the page list. Any data that lies beyond current position + "len"
|
2006-06-09 17:34:21 +04:00
|
|
|
* bytes is moved into the XDR tail[].
|
2012-06-26 20:34:05 +04:00
|
|
|
*
|
|
|
|
* Returns the number of XDR encoded bytes now contained in the pages
|
2005-04-17 02:20:36 +04:00
|
|
|
*/
|
2012-06-26 20:34:05 +04:00
|
|
|
unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct xdr_buf *buf = xdr->buf;
|
|
|
|
struct kvec *iov;
|
2012-06-26 20:34:05 +04:00
|
|
|
unsigned int nwords;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int end;
|
2012-06-26 20:34:05 +04:00
|
|
|
unsigned int padding;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2012-06-26 20:34:05 +04:00
|
|
|
len = xdr_align_pages(xdr, len);
|
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
|
|
|
nwords = XDR_QUADLEN(len);
|
2012-06-20 17:58:35 +04:00
|
|
|
padding = (nwords << 2) - len;
|
2005-04-17 02:20:36 +04:00
|
|
|
xdr->iov = iov = buf->tail;
|
|
|
|
/* Compute remaining message length. */
|
2012-06-26 21:50:43 +04:00
|
|
|
end = ((xdr->nwords - nwords) << 2) + padding;
|
|
|
|
if (end > iov->iov_len)
|
|
|
|
end = iov->iov_len;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Position current pointer at beginning of tail, and
|
|
|
|
* set remaining message length.
|
|
|
|
*/
|
2006-09-27 09:29:38 +04:00
|
|
|
xdr->p = (__be32 *)((char *)iov->iov_base + padding);
|
|
|
|
xdr->end = (__be32 *)((char *)iov->iov_base + end);
|
2012-06-26 23:32:40 +04:00
|
|
|
xdr->page_ptr = NULL;
|
2012-06-20 17:58:35 +04:00
|
|
|
xdr->nwords = XDR_QUADLEN(end - padding);
|
2012-06-22 01:05:37 +04:00
|
|
|
return len;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_read_pages);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-06-09 17:34:21 +04:00
|
|
|
/**
|
|
|
|
* xdr_enter_page - decode data from the XDR page
|
|
|
|
* @xdr: pointer to xdr_stream struct
|
|
|
|
* @len: number of bytes of page data
|
|
|
|
*
|
|
|
|
* Moves data beyond the current pointer position from the XDR head[] buffer
|
|
|
|
* into the page list. Any data that lies beyond current position + "len"
|
|
|
|
* bytes is moved into the XDR tail[]. The current pointer is then
|
|
|
|
* repositioned at the beginning of the first XDR page.
|
|
|
|
*/
|
|
|
|
void xdr_enter_page(struct xdr_stream *xdr, unsigned int len)
|
|
|
|
{
|
2012-06-21 22:53:10 +04:00
|
|
|
len = xdr_align_pages(xdr, len);
|
2006-06-09 17:34:21 +04:00
|
|
|
/*
|
|
|
|
* Position current pointer at beginning of tail, and
|
|
|
|
* set remaining message length.
|
|
|
|
*/
|
2012-06-21 22:53:10 +04:00
|
|
|
if (len != 0)
|
|
|
|
xdr_set_page_base(xdr, 0, len);
|
2006-06-09 17:34:21 +04:00
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_enter_page);
|
2006-06-09 17:34:21 +04:00
|
|
|
|
2020-01-01 10:43:30 +03:00
|
|
|
static const struct kvec empty_iov = {.iov_base = NULL, .iov_len = 0};
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
xdr_buf_from_iov(struct kvec *iov, struct xdr_buf *buf)
|
|
|
|
{
|
|
|
|
buf->head[0] = *iov;
|
|
|
|
buf->tail[0] = empty_iov;
|
|
|
|
buf->page_len = 0;
|
|
|
|
buf->buflen = buf->len = iov->iov_len;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_buf_from_iov);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2014-02-26 02:21:08 +04:00
|
|
|
/**
|
|
|
|
* xdr_buf_subsegment - set subbuf to a portion of buf
|
|
|
|
* @buf: an xdr buffer
|
|
|
|
* @subbuf: the result buffer
|
|
|
|
* @base: beginning of range in bytes
|
|
|
|
* @len: length of range in bytes
|
|
|
|
*
|
|
|
|
* sets @subbuf to an xdr buffer representing the portion of @buf of
|
|
|
|
* length @len starting at offset @base.
|
|
|
|
*
|
|
|
|
* @buf and @subbuf may be pointers to the same struct xdr_buf.
|
|
|
|
*
|
|
|
|
* Returns -1 if base of length are out of bounds.
|
|
|
|
*/
|
2005-04-17 02:20:36 +04:00
|
|
|
int
|
|
|
|
xdr_buf_subsegment(struct xdr_buf *buf, struct xdr_buf *subbuf,
|
2006-08-31 23:09:19 +04:00
|
|
|
unsigned int base, unsigned int len)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
subbuf->buflen = subbuf->len = len;
|
2006-08-31 23:09:19 +04:00
|
|
|
if (base < buf->head[0].iov_len) {
|
|
|
|
subbuf->head[0].iov_base = buf->head[0].iov_base + base;
|
|
|
|
subbuf->head[0].iov_len = min_t(unsigned int, len,
|
|
|
|
buf->head[0].iov_len - base);
|
|
|
|
len -= subbuf->head[0].iov_len;
|
|
|
|
base = 0;
|
|
|
|
} else {
|
|
|
|
base -= buf->head[0].iov_len;
|
2020-06-25 18:32:34 +03:00
|
|
|
subbuf->head[0].iov_base = buf->head[0].iov_base;
|
2014-02-26 02:21:08 +04:00
|
|
|
subbuf->head[0].iov_len = 0;
|
2006-08-31 23:09:19 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (base < buf->page_len) {
|
2006-08-31 23:09:19 +04:00
|
|
|
subbuf->page_len = min(buf->page_len - base, len);
|
|
|
|
base += buf->page_base;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
subbuf->page_base = base & ~PAGE_MASK;
|
|
|
|
subbuf->pages = &buf->pages[base >> PAGE_SHIFT];
|
2005-04-17 02:20:36 +04:00
|
|
|
len -= subbuf->page_len;
|
|
|
|
base = 0;
|
|
|
|
} else {
|
|
|
|
base -= buf->page_len;
|
2020-06-25 18:32:34 +03:00
|
|
|
subbuf->pages = buf->pages;
|
|
|
|
subbuf->page_base = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
subbuf->page_len = 0;
|
|
|
|
}
|
|
|
|
|
2006-08-31 23:09:19 +04:00
|
|
|
if (base < buf->tail[0].iov_len) {
|
|
|
|
subbuf->tail[0].iov_base = buf->tail[0].iov_base + base;
|
|
|
|
subbuf->tail[0].iov_len = min_t(unsigned int, len,
|
|
|
|
buf->tail[0].iov_len - base);
|
|
|
|
len -= subbuf->tail[0].iov_len;
|
|
|
|
base = 0;
|
|
|
|
} else {
|
|
|
|
base -= buf->tail[0].iov_len;
|
2020-06-25 18:32:34 +03:00
|
|
|
subbuf->tail[0].iov_base = buf->tail[0].iov_base;
|
2014-02-26 02:21:08 +04:00
|
|
|
subbuf->tail[0].iov_len = 0;
|
2006-08-31 23:09:19 +04:00
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (base || len)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_buf_subsegment);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2020-04-16 00:36:22 +03:00
|
|
|
/**
|
|
|
|
* xdr_buf_trim - lop at most "len" bytes off the end of "buf"
|
|
|
|
* @buf: buf to be trimmed
|
|
|
|
* @len: number of bytes to reduce "buf" by
|
|
|
|
*
|
|
|
|
* Trim an xdr_buf by the given number of bytes by fixing up the lengths. Note
|
|
|
|
* that it's possible that we'll trim less than that amount if the xdr_buf is
|
|
|
|
* too small, or if (for instance) it's all in the head and the parser has
|
|
|
|
* already read too far into it.
|
|
|
|
*/
|
|
|
|
void xdr_buf_trim(struct xdr_buf *buf, unsigned int len)
|
|
|
|
{
|
|
|
|
size_t cur;
|
|
|
|
unsigned int trim = len;
|
|
|
|
|
|
|
|
if (buf->tail[0].iov_len) {
|
|
|
|
cur = min_t(size_t, buf->tail[0].iov_len, trim);
|
|
|
|
buf->tail[0].iov_len -= cur;
|
|
|
|
trim -= cur;
|
|
|
|
if (!trim)
|
|
|
|
goto fix_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf->page_len) {
|
|
|
|
cur = min_t(unsigned int, buf->page_len, trim);
|
|
|
|
buf->page_len -= cur;
|
|
|
|
trim -= cur;
|
|
|
|
if (!trim)
|
|
|
|
goto fix_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf->head[0].iov_len) {
|
|
|
|
cur = min_t(size_t, buf->head[0].iov_len, trim);
|
|
|
|
buf->head[0].iov_len -= cur;
|
|
|
|
trim -= cur;
|
|
|
|
}
|
|
|
|
fix_len:
|
|
|
|
buf->len -= (len - trim);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_buf_trim);
|
|
|
|
|
2006-10-17 21:47:24 +04:00
|
|
|
static void __read_bytes_from_xdr_buf(struct xdr_buf *subbuf, void *obj, unsigned int len)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2006-08-31 23:09:19 +04:00
|
|
|
unsigned int this_len;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-10-17 21:47:24 +04:00
|
|
|
this_len = min_t(unsigned int, len, subbuf->head[0].iov_len);
|
|
|
|
memcpy(obj, subbuf->head[0].iov_base, this_len);
|
2005-04-17 02:20:36 +04:00
|
|
|
len -= this_len;
|
|
|
|
obj += this_len;
|
2006-10-17 21:47:24 +04:00
|
|
|
this_len = min_t(unsigned int, len, subbuf->page_len);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (this_len)
|
2006-10-17 21:47:24 +04:00
|
|
|
_copy_from_pages(obj, subbuf->pages, subbuf->page_base, this_len);
|
2005-04-17 02:20:36 +04:00
|
|
|
len -= this_len;
|
|
|
|
obj += this_len;
|
2006-10-17 21:47:24 +04:00
|
|
|
this_len = min_t(unsigned int, len, subbuf->tail[0].iov_len);
|
|
|
|
memcpy(obj, subbuf->tail[0].iov_base, this_len);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-06-22 21:16:24 +04:00
|
|
|
/* obj is assumed to point to allocated memory of size at least len: */
|
2006-10-17 21:47:24 +04:00
|
|
|
int read_bytes_from_xdr_buf(struct xdr_buf *buf, unsigned int base, void *obj, unsigned int len)
|
2005-06-22 21:16:24 +04:00
|
|
|
{
|
|
|
|
struct xdr_buf subbuf;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = xdr_buf_subsegment(buf, &subbuf, base, len);
|
2006-10-17 21:47:24 +04:00
|
|
|
if (status != 0)
|
|
|
|
return status;
|
|
|
|
__read_bytes_from_xdr_buf(&subbuf, obj, len);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(read_bytes_from_xdr_buf);
|
2006-10-17 21:47:24 +04:00
|
|
|
|
|
|
|
static void __write_bytes_to_xdr_buf(struct xdr_buf *subbuf, void *obj, unsigned int len)
|
|
|
|
{
|
|
|
|
unsigned int this_len;
|
|
|
|
|
|
|
|
this_len = min_t(unsigned int, len, subbuf->head[0].iov_len);
|
|
|
|
memcpy(subbuf->head[0].iov_base, obj, this_len);
|
2005-06-22 21:16:24 +04:00
|
|
|
len -= this_len;
|
|
|
|
obj += this_len;
|
2006-10-17 21:47:24 +04:00
|
|
|
this_len = min_t(unsigned int, len, subbuf->page_len);
|
2005-06-22 21:16:24 +04:00
|
|
|
if (this_len)
|
2006-10-17 21:47:24 +04:00
|
|
|
_copy_to_pages(subbuf->pages, subbuf->page_base, obj, this_len);
|
2005-06-22 21:16:24 +04:00
|
|
|
len -= this_len;
|
|
|
|
obj += this_len;
|
2006-10-17 21:47:24 +04:00
|
|
|
this_len = min_t(unsigned int, len, subbuf->tail[0].iov_len);
|
|
|
|
memcpy(subbuf->tail[0].iov_base, obj, this_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* obj is assumed to point to allocated memory of size at least len: */
|
|
|
|
int write_bytes_to_xdr_buf(struct xdr_buf *buf, unsigned int base, void *obj, unsigned int len)
|
|
|
|
{
|
|
|
|
struct xdr_buf subbuf;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = xdr_buf_subsegment(buf, &subbuf, base, len);
|
|
|
|
if (status != 0)
|
|
|
|
return status;
|
|
|
|
__write_bytes_to_xdr_buf(&subbuf, obj, len);
|
|
|
|
return 0;
|
2005-06-22 21:16:24 +04:00
|
|
|
}
|
2010-03-17 20:02:58 +03:00
|
|
|
EXPORT_SYMBOL_GPL(write_bytes_to_xdr_buf);
|
2005-06-22 21:16:24 +04:00
|
|
|
|
|
|
|
int
|
2006-08-31 23:09:19 +04:00
|
|
|
xdr_decode_word(struct xdr_buf *buf, unsigned int base, u32 *obj)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2006-09-27 09:29:38 +04:00
|
|
|
__be32 raw;
|
2005-04-17 02:20:36 +04:00
|
|
|
int status;
|
|
|
|
|
|
|
|
status = read_bytes_from_xdr_buf(buf, base, &raw, sizeof(*obj));
|
|
|
|
if (status)
|
|
|
|
return status;
|
2009-08-14 18:18:49 +04:00
|
|
|
*obj = be32_to_cpu(raw);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_decode_word);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-06-22 21:16:24 +04:00
|
|
|
int
|
2006-08-31 23:09:19 +04:00
|
|
|
xdr_encode_word(struct xdr_buf *buf, unsigned int base, u32 obj)
|
2005-06-22 21:16:24 +04:00
|
|
|
{
|
2009-08-14 18:18:44 +04:00
|
|
|
__be32 raw = cpu_to_be32(obj);
|
2005-06-22 21:16:24 +04:00
|
|
|
|
|
|
|
return write_bytes_to_xdr_buf(buf, base, &raw, sizeof(obj));
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_encode_word);
|
2005-06-22 21:16:24 +04:00
|
|
|
|
|
|
|
/* Returns 0 on success, or else a negative error code. */
|
|
|
|
static int
|
|
|
|
xdr_xcode_array2(struct xdr_buf *buf, unsigned int base,
|
|
|
|
struct xdr_array2_desc *desc, int encode)
|
|
|
|
{
|
|
|
|
char *elem = NULL, *c;
|
|
|
|
unsigned int copied = 0, todo, avail_here;
|
|
|
|
struct page **ppages = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (encode) {
|
|
|
|
if (xdr_encode_word(buf, base, desc->array_len) != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
|
|
|
if (xdr_decode_word(buf, base, &desc->array_len) != 0 ||
|
2005-08-11 02:15:12 +04:00
|
|
|
desc->array_len > desc->array_maxlen ||
|
2005-06-22 21:16:24 +04:00
|
|
|
(unsigned long) base + 4 + desc->array_len *
|
|
|
|
desc->elem_size > buf->len)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
base += 4;
|
|
|
|
|
|
|
|
if (!desc->xcode)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
todo = desc->array_len * desc->elem_size;
|
|
|
|
|
|
|
|
/* process head */
|
|
|
|
if (todo && base < buf->head->iov_len) {
|
|
|
|
c = buf->head->iov_base + base;
|
|
|
|
avail_here = min_t(unsigned int, todo,
|
|
|
|
buf->head->iov_len - base);
|
|
|
|
todo -= avail_here;
|
|
|
|
|
|
|
|
while (avail_here >= desc->elem_size) {
|
|
|
|
err = desc->xcode(desc, c);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
c += desc->elem_size;
|
|
|
|
avail_here -= desc->elem_size;
|
|
|
|
}
|
|
|
|
if (avail_here) {
|
|
|
|
if (!elem) {
|
|
|
|
elem = kmalloc(desc->elem_size, GFP_KERNEL);
|
|
|
|
err = -ENOMEM;
|
|
|
|
if (!elem)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (encode) {
|
|
|
|
err = desc->xcode(desc, elem);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
memcpy(c, elem, avail_here);
|
|
|
|
} else
|
|
|
|
memcpy(elem, c, avail_here);
|
|
|
|
copied = avail_here;
|
|
|
|
}
|
|
|
|
base = buf->head->iov_len; /* align to start of pages */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process pages array */
|
|
|
|
base -= buf->head->iov_len;
|
|
|
|
if (todo && base < buf->page_len) {
|
|
|
|
unsigned int avail_page;
|
|
|
|
|
|
|
|
avail_here = min(todo, buf->page_len - base);
|
|
|
|
todo -= avail_here;
|
|
|
|
|
|
|
|
base += buf->page_base;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
ppages = buf->pages + (base >> PAGE_SHIFT);
|
|
|
|
base &= ~PAGE_MASK;
|
|
|
|
avail_page = min_t(unsigned int, PAGE_SIZE - base,
|
2005-06-22 21:16:24 +04:00
|
|
|
avail_here);
|
|
|
|
c = kmap(*ppages) + base;
|
|
|
|
|
|
|
|
while (avail_here) {
|
|
|
|
avail_here -= avail_page;
|
|
|
|
if (copied || avail_page < desc->elem_size) {
|
|
|
|
unsigned int l = min(avail_page,
|
|
|
|
desc->elem_size - copied);
|
|
|
|
if (!elem) {
|
|
|
|
elem = kmalloc(desc->elem_size,
|
|
|
|
GFP_KERNEL);
|
|
|
|
err = -ENOMEM;
|
|
|
|
if (!elem)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (encode) {
|
|
|
|
if (!copied) {
|
|
|
|
err = desc->xcode(desc, elem);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
memcpy(c, elem + copied, l);
|
|
|
|
copied += l;
|
|
|
|
if (copied == desc->elem_size)
|
|
|
|
copied = 0;
|
|
|
|
} else {
|
|
|
|
memcpy(elem + copied, c, l);
|
|
|
|
copied += l;
|
|
|
|
if (copied == desc->elem_size) {
|
|
|
|
err = desc->xcode(desc, elem);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
copied = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
avail_page -= l;
|
|
|
|
c += l;
|
|
|
|
}
|
|
|
|
while (avail_page >= desc->elem_size) {
|
|
|
|
err = desc->xcode(desc, c);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
c += desc->elem_size;
|
|
|
|
avail_page -= desc->elem_size;
|
|
|
|
}
|
|
|
|
if (avail_page) {
|
|
|
|
unsigned int l = min(avail_page,
|
|
|
|
desc->elem_size - copied);
|
|
|
|
if (!elem) {
|
|
|
|
elem = kmalloc(desc->elem_size,
|
|
|
|
GFP_KERNEL);
|
|
|
|
err = -ENOMEM;
|
|
|
|
if (!elem)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (encode) {
|
|
|
|
if (!copied) {
|
|
|
|
err = desc->xcode(desc, elem);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
memcpy(c, elem + copied, l);
|
|
|
|
copied += l;
|
|
|
|
if (copied == desc->elem_size)
|
|
|
|
copied = 0;
|
|
|
|
} else {
|
|
|
|
memcpy(elem + copied, c, l);
|
|
|
|
copied += l;
|
|
|
|
if (copied == desc->elem_size) {
|
|
|
|
err = desc->xcode(desc, elem);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
copied = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (avail_here) {
|
|
|
|
kunmap(*ppages);
|
|
|
|
ppages++;
|
|
|
|
c = kmap(*ppages);
|
|
|
|
}
|
|
|
|
|
|
|
|
avail_page = min(avail_here,
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
(unsigned int) PAGE_SIZE);
|
2005-06-22 21:16:24 +04:00
|
|
|
}
|
|
|
|
base = buf->page_len; /* align to start of tail */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process tail */
|
|
|
|
base -= buf->page_len;
|
|
|
|
if (todo) {
|
|
|
|
c = buf->tail->iov_base + base;
|
|
|
|
if (copied) {
|
|
|
|
unsigned int l = desc->elem_size - copied;
|
|
|
|
|
|
|
|
if (encode)
|
|
|
|
memcpy(c, elem + copied, l);
|
|
|
|
else {
|
|
|
|
memcpy(elem + copied, c, l);
|
|
|
|
err = desc->xcode(desc, elem);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
todo -= l;
|
|
|
|
c += l;
|
|
|
|
}
|
|
|
|
while (todo) {
|
|
|
|
err = desc->xcode(desc, c);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
c += desc->elem_size;
|
|
|
|
todo -= desc->elem_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out:
|
2005-11-08 20:41:34 +03:00
|
|
|
kfree(elem);
|
2005-06-22 21:16:24 +04:00
|
|
|
if (ppages)
|
|
|
|
kunmap(*ppages);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
xdr_decode_array2(struct xdr_buf *buf, unsigned int base,
|
|
|
|
struct xdr_array2_desc *desc)
|
|
|
|
{
|
|
|
|
if (base >= buf->len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return xdr_xcode_array2(buf, base, desc, 0);
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_decode_array2);
|
2005-06-22 21:16:24 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
xdr_encode_array2(struct xdr_buf *buf, unsigned int base,
|
|
|
|
struct xdr_array2_desc *desc)
|
|
|
|
{
|
|
|
|
if ((unsigned long) base + 4 + desc->array_len * desc->elem_size >
|
|
|
|
buf->head->iov_len + buf->page_len + buf->tail->iov_len)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return xdr_xcode_array2(buf, base, desc, 1);
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_encode_array2);
|
2006-12-05 04:22:33 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len,
|
2007-02-10 02:38:13 +03:00
|
|
|
int (*actor)(struct scatterlist *, void *), void *data)
|
2006-12-05 04:22:33 +03:00
|
|
|
{
|
|
|
|
int i, ret = 0;
|
2012-04-15 09:58:06 +04:00
|
|
|
unsigned int page_len, thislen, page_offset;
|
2006-12-05 04:22:33 +03:00
|
|
|
struct scatterlist sg[1];
|
|
|
|
|
2007-10-27 11:52:07 +04:00
|
|
|
sg_init_table(sg, 1);
|
|
|
|
|
2006-12-05 04:22:33 +03:00
|
|
|
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;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
page_offset = (offset + buf->page_base) & (PAGE_SIZE - 1);
|
|
|
|
i = (offset + buf->page_base) >> PAGE_SHIFT;
|
|
|
|
thislen = PAGE_SIZE - page_offset;
|
2006-12-05 04:22:33 +03:00
|
|
|
do {
|
|
|
|
if (thislen > page_len)
|
|
|
|
thislen = page_len;
|
2007-10-24 13:20:47 +04:00
|
|
|
sg_set_page(sg, buf->pages[i], thislen, page_offset);
|
2006-12-05 04:22:33 +03:00
|
|
|
ret = actor(sg, data);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
page_len -= thislen;
|
|
|
|
i++;
|
|
|
|
page_offset = 0;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 15:29:47 +03:00
|
|
|
thislen = PAGE_SIZE;
|
2006-12-05 04:22:33 +03:00
|
|
|
} 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;
|
|
|
|
}
|
2008-12-23 23:21:31 +03:00
|
|
|
EXPORT_SYMBOL_GPL(xdr_process_buf);
|
2006-12-05 04:22:33 +03:00
|
|
|
|
2018-03-21 00:03:05 +03:00
|
|
|
/**
|
|
|
|
* xdr_stream_decode_opaque - Decode variable length opaque
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
* @ptr: location to store opaque data
|
|
|
|
* @size: size of storage buffer @ptr
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* On success, returns size of object stored in *@ptr
|
|
|
|
* %-EBADMSG on XDR buffer overflow
|
|
|
|
* %-EMSGSIZE on overflow of storage buffer @ptr
|
|
|
|
*/
|
|
|
|
ssize_t xdr_stream_decode_opaque(struct xdr_stream *xdr, void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
ret = xdr_stream_decode_opaque_inline(xdr, &p, size);
|
|
|
|
if (ret <= 0)
|
|
|
|
return ret;
|
|
|
|
memcpy(ptr, p, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_stream_decode_opaque);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xdr_stream_decode_opaque_dup - Decode and duplicate variable length opaque
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
* @ptr: location to store pointer to opaque data
|
|
|
|
* @maxlen: maximum acceptable object size
|
|
|
|
* @gfp_flags: GFP mask to use
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* On success, returns size of object stored in *@ptr
|
|
|
|
* %-EBADMSG on XDR buffer overflow
|
|
|
|
* %-EMSGSIZE if the size of the object would exceed @maxlen
|
|
|
|
* %-ENOMEM on memory allocation failure
|
|
|
|
*/
|
|
|
|
ssize_t xdr_stream_decode_opaque_dup(struct xdr_stream *xdr, void **ptr,
|
|
|
|
size_t maxlen, gfp_t gfp_flags)
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
ret = xdr_stream_decode_opaque_inline(xdr, &p, maxlen);
|
|
|
|
if (ret > 0) {
|
|
|
|
*ptr = kmemdup(p, ret, gfp_flags);
|
|
|
|
if (*ptr != NULL)
|
|
|
|
return ret;
|
|
|
|
ret = -ENOMEM;
|
|
|
|
}
|
|
|
|
*ptr = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_stream_decode_opaque_dup);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xdr_stream_decode_string - Decode variable length string
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
* @str: location to store string
|
|
|
|
* @size: size of storage buffer @str
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* On success, returns length of NUL-terminated string stored in *@str
|
|
|
|
* %-EBADMSG on XDR buffer overflow
|
|
|
|
* %-EMSGSIZE on overflow of storage buffer @str
|
|
|
|
*/
|
|
|
|
ssize_t xdr_stream_decode_string(struct xdr_stream *xdr, char *str, size_t size)
|
|
|
|
{
|
|
|
|
ssize_t ret;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
ret = xdr_stream_decode_opaque_inline(xdr, &p, size);
|
|
|
|
if (ret > 0) {
|
|
|
|
memcpy(str, p, ret);
|
|
|
|
str[ret] = '\0';
|
|
|
|
return strlen(str);
|
|
|
|
}
|
|
|
|
*str = '\0';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_stream_decode_string);
|
|
|
|
|
2017-02-20 00:08:31 +03:00
|
|
|
/**
|
|
|
|
* xdr_stream_decode_string_dup - Decode and duplicate variable length string
|
|
|
|
* @xdr: pointer to xdr_stream
|
|
|
|
* @str: location to store pointer to string
|
|
|
|
* @maxlen: maximum acceptable string length
|
|
|
|
* @gfp_flags: GFP mask to use
|
|
|
|
*
|
|
|
|
* Return values:
|
|
|
|
* On success, returns length of NUL-terminated string stored in *@ptr
|
|
|
|
* %-EBADMSG on XDR buffer overflow
|
|
|
|
* %-EMSGSIZE if the size of the string would exceed @maxlen
|
|
|
|
* %-ENOMEM on memory allocation failure
|
|
|
|
*/
|
|
|
|
ssize_t xdr_stream_decode_string_dup(struct xdr_stream *xdr, char **str,
|
|
|
|
size_t maxlen, gfp_t gfp_flags)
|
|
|
|
{
|
|
|
|
void *p;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
ret = xdr_stream_decode_opaque_inline(xdr, &p, maxlen);
|
|
|
|
if (ret > 0) {
|
|
|
|
char *s = kmalloc(ret + 1, gfp_flags);
|
|
|
|
if (s != NULL) {
|
|
|
|
memcpy(s, p, ret);
|
|
|
|
s[ret] = '\0';
|
|
|
|
*str = s;
|
|
|
|
return strlen(s);
|
|
|
|
}
|
|
|
|
ret = -ENOMEM;
|
|
|
|
}
|
|
|
|
*str = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(xdr_stream_decode_string_dup);
|