From patchwork Wed Jun 22 04:15:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 12890103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AA95C43334 for ; Wed, 22 Jun 2022 04:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356939AbiFVEQo (ORCPT ); Wed, 22 Jun 2022 00:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356796AbiFVEQI (ORCPT ); Wed, 22 Jun 2022 00:16:08 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E22D764C for ; Tue, 21 Jun 2022 21:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=t+ZhgCyfjPqW81eYAJou5jvuXDlrzrNGX9oqhs/L/dg=; b=KzSVaG30mWIDlNSlGlbZ5+X3MW L1i8B0Z3UUaPvb3cmLzJbpAve9c8zqYRHkerL1A4z2vm9wL9XDfRmT6xgE30/BC6BZUKiqDhPT/02 4GLMpx9b4sI3+KSqTLaFBW7Z3dFU5kp3HsMu+qKVr8LaZvh/PM4cnPL8KaAP8Iqk2BMLCdEMxP1rM YjWMNfo/3UkuNUhhnpQ7EpRhRNLATpPmbs0MYcZVW+Ju3AEtSkEinziLZf4lRnrYVzF3TnGyA7rp0 p9J1zKGmAtJLWXBEmKszRkgNjWVRZRkEqcCLAlMCAQXdPv7t+fcuDAPyccP61Oh2UcUzRLDgLAW8z is5uhj1g==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o3rmX-0035yA-3t; Wed, 22 Jun 2022 04:15:57 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Jens Axboe , Christoph Hellwig , Matthew Wilcox , David Howells , Dominique Martinet , Christian Brauner Subject: [PATCH 27/44] unify xarray_get_pages() and xarray_get_pages_alloc() Date: Wed, 22 Jun 2022 05:15:35 +0100 Message-Id: <20220622041552.737754-27-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220622041552.737754-1-viro@zeniv.linux.org.uk> References: <20220622041552.737754-1-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org same as for pipes Signed-off-by: Al Viro Reviewed-by: Jeff Layton --- 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; }