Message ID | 20220622041552.737754-27-viro@zeniv.linux.org.uk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/44] 9p: handling Rerror without copy_from_iter_full() | expand |
On Wed, 2022-06-22 at 05:15 +0100, Al Viro wrote: > same as for pipes > > Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> > --- > lib/iov_iter.c | 49 ++++++++++--------------------------------------- > 1 file changed, 10 insertions(+), 39 deletions(-) > > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 1c98f2f3a581..07dacb274ba5 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -1276,7 +1276,7 @@ static ssize_t iter_xarray_populate_pages(struct page **pages, struct xarray *xa > } > > static ssize_t iter_xarray_get_pages(struct iov_iter *i, > - struct page **pages, size_t maxsize, > + struct page ***pages, size_t maxsize, > unsigned maxpages, size_t *_start_offset) > { > unsigned nr, offset; > @@ -1301,7 +1301,13 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i, > if (count > maxpages) > count = maxpages; > > - nr = iter_xarray_populate_pages(pages, i->xarray, index, count); > + if (!*pages) { > + *pages = get_pages_array(count); > + if (!*pages) > + return -ENOMEM; > + } > + > + nr = iter_xarray_populate_pages(*pages, i->xarray, index, count); > if (nr == 0) > return 0; > > @@ -1409,46 +1415,11 @@ ssize_t iov_iter_get_pages(struct iov_iter *i, > if (iov_iter_is_pipe(i)) > return pipe_get_pages(i, &pages, maxsize, maxpages, start); > if (iov_iter_is_xarray(i)) > - return iter_xarray_get_pages(i, pages, maxsize, maxpages, start); > + return iter_xarray_get_pages(i, &pages, maxsize, maxpages, start); > return -EFAULT; > } > EXPORT_SYMBOL(iov_iter_get_pages); > > -static ssize_t iter_xarray_get_pages_alloc(struct iov_iter *i, > - struct page ***pages, size_t maxsize, > - size_t *_start_offset) > -{ > - struct page **p; > - unsigned nr, offset; > - pgoff_t index, count; > - size_t size = maxsize; > - loff_t pos; > - > - pos = i->xarray_start + i->iov_offset; > - index = pos >> PAGE_SHIFT; > - offset = pos & ~PAGE_MASK; > - *_start_offset = offset; > - > - count = 1; > - if (size > PAGE_SIZE - offset) { > - size -= PAGE_SIZE - offset; > - count += size >> PAGE_SHIFT; > - size &= ~PAGE_MASK; > - if (size) > - count++; > - } > - > - *pages = p = get_pages_array(count); > - if (!p) > - return -ENOMEM; > - > - nr = iter_xarray_populate_pages(p, i->xarray, index, count); > - if (nr == 0) > - return 0; > - > - return min_t(size_t, nr * PAGE_SIZE - offset, maxsize); > -} > - > static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, > struct page ***pages, size_t maxsize, > size_t *start) > @@ -1498,7 +1469,7 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, > if (iov_iter_is_pipe(i)) > return pipe_get_pages(i, pages, maxsize, ~0U, start); > if (iov_iter_is_xarray(i)) > - return iter_xarray_get_pages_alloc(i, pages, maxsize, start); > + return iter_xarray_get_pages(i, pages, maxsize, ~0U, start); > return -EFAULT; > } > Reviewed-by: Jeff Layton <jlayton@kernel.org>
diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 1c98f2f3a581..07dacb274ba5 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1276,7 +1276,7 @@ static ssize_t iter_xarray_populate_pages(struct page **pages, struct xarray *xa } static ssize_t iter_xarray_get_pages(struct iov_iter *i, - struct page **pages, size_t maxsize, + struct page ***pages, size_t maxsize, unsigned maxpages, size_t *_start_offset) { unsigned nr, offset; @@ -1301,7 +1301,13 @@ static ssize_t iter_xarray_get_pages(struct iov_iter *i, if (count > maxpages) count = maxpages; - nr = iter_xarray_populate_pages(pages, i->xarray, index, count); + if (!*pages) { + *pages = get_pages_array(count); + if (!*pages) + return -ENOMEM; + } + + nr = iter_xarray_populate_pages(*pages, i->xarray, index, count); if (nr == 0) return 0; @@ -1409,46 +1415,11 @@ ssize_t iov_iter_get_pages(struct iov_iter *i, if (iov_iter_is_pipe(i)) return pipe_get_pages(i, &pages, maxsize, maxpages, start); if (iov_iter_is_xarray(i)) - return iter_xarray_get_pages(i, pages, maxsize, maxpages, start); + return iter_xarray_get_pages(i, &pages, maxsize, maxpages, start); return -EFAULT; } EXPORT_SYMBOL(iov_iter_get_pages); -static ssize_t iter_xarray_get_pages_alloc(struct iov_iter *i, - struct page ***pages, size_t maxsize, - size_t *_start_offset) -{ - struct page **p; - unsigned nr, offset; - pgoff_t index, count; - size_t size = maxsize; - loff_t pos; - - pos = i->xarray_start + i->iov_offset; - index = pos >> PAGE_SHIFT; - offset = pos & ~PAGE_MASK; - *_start_offset = offset; - - count = 1; - if (size > PAGE_SIZE - offset) { - size -= PAGE_SIZE - offset; - count += size >> PAGE_SHIFT; - size &= ~PAGE_MASK; - if (size) - count++; - } - - *pages = p = get_pages_array(count); - if (!p) - return -ENOMEM; - - nr = iter_xarray_populate_pages(p, i->xarray, index, count); - if (nr == 0) - return 0; - - return min_t(size_t, nr * PAGE_SIZE - offset, maxsize); -} - static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, struct page ***pages, size_t maxsize, size_t *start) @@ -1498,7 +1469,7 @@ static ssize_t __iov_iter_get_pages_alloc(struct iov_iter *i, if (iov_iter_is_pipe(i)) return pipe_get_pages(i, pages, maxsize, ~0U, start); if (iov_iter_is_xarray(i)) - return iter_xarray_get_pages_alloc(i, pages, maxsize, start); + return iter_xarray_get_pages(i, pages, maxsize, ~0U, start); return -EFAULT; }
same as for pipes Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> --- lib/iov_iter.c | 49 ++++++++++--------------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-)