From patchwork Wed Aug 14 20:38:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13763964 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A876C52D7F for ; Wed, 14 Aug 2024 20:41:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2447E6B00AF; Wed, 14 Aug 2024 16:41:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F5896B00B0; Wed, 14 Aug 2024 16:41:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06F716B00B1; Wed, 14 Aug 2024 16:41:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D9DDA6B00AF for ; Wed, 14 Aug 2024 16:41:13 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 96F1341228 for ; Wed, 14 Aug 2024 20:41:13 +0000 (UTC) X-FDA: 82452020826.26.63C7D7A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id DF90E2000D for ; Wed, 14 Aug 2024 20:41:11 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZWhpo26B; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723668013; a=rsa-sha256; cv=none; b=p+5ncSBCA7hFKFX24LAGm2DgkvSjjotcEb/QZyoAWsw/yNi5Jq4JDSsJprsQX4lTuiV2/d /RlBJ0YSl6O2qasJUOb0c8JYOeBD9sBMbdRAWC62RRKBQRWk0RqY2dKiOsX/ag/i2phGnP fK4+ybLroLcgfbCT0LGf6/fRQCId630= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZWhpo26B; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723668013; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/5GudhtF+T887yYtTq2ccnSMC605t1SyQsaR8Y8Wa80=; b=r55TBFco0FpEm+thr+UWdh1NlVuixmcPWdXYLgDCTZzBTjtaGHK4pjgfwLZDK0+FZCZnRr 4XwY/slZ1g6e8KvLnsGFXZthZWmnmo3wFUtq1BmLSB6DyC/n1hj7YL/N4qJlCSLB+MZtsr 9D59TkAoKBdi5okxS1Si+eu7TteEiVg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723668071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/5GudhtF+T887yYtTq2ccnSMC605t1SyQsaR8Y8Wa80=; b=ZWhpo26BnMDy9JOo6H8eMFzpQ+BKnm/oD2MQVv+6B/uYo/j40xmURJUUXaI8ydiZeimWUf BRvM3Sfe2Uw8hU5UusLy+wlxQpG8lR9Xibo6o3dRiTHFclxHgcYLEOCzaYoT70wZ0n1zwf 8AEA5hW0vqKJR3Wr7TGAfKIzxs6BtcA= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-cuSPPapgNmmADvVkpaXVwA-1; Wed, 14 Aug 2024 16:41:05 -0400 X-MC-Unique: cuSPPapgNmmADvVkpaXVwA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 837281954B0E; Wed, 14 Aug 2024 20:41:02 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E3421300019A; Wed, 14 Aug 2024 20:40:56 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French , Matthew Wilcox Cc: David Howells , Jeff Layton , Gao Xiang , Dominique Martinet , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 16/25] netfs: Provide an iterator-reset function Date: Wed, 14 Aug 2024 21:38:36 +0100 Message-ID: <20240814203850.2240469-17-dhowells@redhat.com> In-Reply-To: <20240814203850.2240469-1-dhowells@redhat.com> References: <20240814203850.2240469-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: DF90E2000D X-Stat-Signature: zhfz54farzhrmtkmg637umatmg6yfxcn X-Rspam-User: X-HE-Tag: 1723668071-410042 X-HE-Meta: U2FsdGVkX1+wRTeLOeeh7Q4YWo10CxOVtmG1AlJ+bFQQPAX04aX2pPABSF8WzESC/KxoGBO4AaOCW72aXZxBcexMFBPn0R98VOxPX9UtraExUn2mPNuqnXenhaYiZx+YU+9dOWp+/9m+qfhZo4CGKnbwAWEqzMd9+1GXLCMBZyLlI3UQtA4XoCj4azV1jkbZrx8jkXWhmqNY8ZpM2FFoK3g/OyT+gibtI07BqsT8bAeBlAK5rO4CL27TJ27X5OhWjeUv8HycgAcaiBWMycQ1L0TUYp/97d+ZjMFP8bD/onFUPxvnZtcjGs3hJtFwZio88bTaMWSg4tFVLgO027WaCJHQ9XZ9YjFGaeAPKgtd+cB73UUXLSryR/NF+ALTpy6fC7gMw4Ed8GqeJpF/E1Rtc0LW+wrI5TSFgzMPRnB96yePr6XNtwV7erqXBjBX+Qikkg+ueuQGIl3dnEwHQF2fyGNaz9v3BWn8kRSwgHQYgUzoEh2sd7FZnMKcOEK1DoSpESNwEu9n1F108/xc3vDt0E/hbj/hdlvmxIi9YSOWapVH+tzvckP7FMG7CmtR9uQ0fAImA0qAA//QYWZllk7wIujM7wLbbDTDew90FkBdf/TtNwaoTnrtkoJXygdW9xp5hKgq3wtaXfADlZOEq0SniZObnXmlyKOeUGrB62cNdVYdpU+1yClCtvrVu0iHlpu1U5rq7tl5rUTCesu8Eo1fNNppwn5AobilsOJ92DiQLv80fZUtzhHzPUXoYRK3GJnd5JtiIQak5qmYkQ/N0ds4LroTRisBKDBZ73IMcm9ld5rU42/ZmXetr2hk4gHJijabf9Xzpknc3EZxtEMqiIsCRj/4RE639w0z1gNg4E9EebpZkl+neY0Xyk81Udr0ezv5iegtoruNi/BHXlaYPZhF6SrovLkpIH6WmCPy0dLQiB+CCX6LPrf+ZE50HjN0UJdrbyRZJCNq+v+W3YtopEN 3HMTG/BW mF9jhQWXZPmfTnsFEA6Q2UfoUheP/7oPO3ZNmETr5wOUlyT8VKZAOhsTwPUqOPuL6u7h/oyGvNMf0IGUSGzaOWpqIJXdtYNXxIeT8Tl6XLD2QpQDL8rHDDwLQ4laOYkGZ4ny5KonVcB2VM0z8DR3vX5rmtBH58hXKsof2wymgv7z2NNXp3iFIcC77YeTrIViQSSbfusMGYLYvK3MwtBwto9xNhjJsUrVfbn1VJWHi82MtnXkYbaFstPOR6SGLTZgWCV1tXg4iHFhm/F7gVQed5HyykvLkYb1TqDz//ICTPCT+VnOQztARSH6pxNrGkZJFvMwDoG6yGdOt2s3LMT7++5Ln83dXLXdGzNa+J8w9MTiTCrM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Provide a function to reset the iterator on a subrequest. Signed-off-by: David Howells cc: Jeff Layton cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/netfs/internal.h | 4 +--- fs/netfs/misc.c | 18 ++++++++++++++++++ fs/netfs/write_collect.c | 3 +-- fs/netfs/write_issue.c | 6 +++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h index e1149e05a5c8..21a3c7d13585 100644 --- a/fs/netfs/internal.h +++ b/fs/netfs/internal.h @@ -69,6 +69,7 @@ int netfs_buffer_append_folio(struct netfs_io_request *rreq, struct folio *folio bool needs_put); struct folio_queue *netfs_delete_buffer_head(struct netfs_io_request *wreq); void netfs_clear_buffer(struct netfs_io_request *rreq); +void netfs_reset_iter(struct netfs_io_subrequest *subreq); /* * objects.c @@ -161,9 +162,6 @@ struct netfs_io_request *netfs_create_write_req(struct address_space *mapping, void netfs_reissue_write(struct netfs_io_stream *stream, struct netfs_io_subrequest *subreq, struct iov_iter *source); -int netfs_advance_write(struct netfs_io_request *wreq, - struct netfs_io_stream *stream, - loff_t start, size_t len, bool to_eof); struct netfs_io_request *netfs_begin_writethrough(struct kiocb *iocb, size_t len); int netfs_advance_writethrough(struct netfs_io_request *wreq, struct writeback_control *wbc, struct folio *folio, size_t copied, bool to_page_end, diff --git a/fs/netfs/misc.c b/fs/netfs/misc.c index e642e5cacb8d..08987765306f 100644 --- a/fs/netfs/misc.c +++ b/fs/netfs/misc.c @@ -84,6 +84,24 @@ void netfs_clear_buffer(struct netfs_io_request *rreq) } } +/* + * Reset the subrequest iterator to refer just to the region remaining to be + * read. The iterator may or may not have been advanced by socket ops or + * extraction ops to an extent that may or may not match the amount actually + * read. + */ +void netfs_reset_iter(struct netfs_io_subrequest *subreq) +{ + struct iov_iter *io_iter = &subreq->io_iter; + size_t remain = subreq->len - subreq->transferred; + + if (io_iter->count > remain) + iov_iter_advance(io_iter, io_iter->count - remain); + else if (io_iter->count < remain) + iov_iter_revert(io_iter, remain - io_iter->count); + iov_iter_truncate(&subreq->io_iter, remain); +} + /** * netfs_dirty_folio - Mark folio dirty and pin a cache object for writeback * @mapping: The mapping the folio belongs to. diff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c index 1521a23077c3..801a130a0ce1 100644 --- a/fs/netfs/write_collect.c +++ b/fs/netfs/write_collect.c @@ -219,9 +219,8 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq, /* Determine the set of buffers we're going to use. Each * subreq gets a subset of a single overall contiguous buffer. */ + netfs_reset_iter(from); source = from->io_iter; - iov_iter_revert(&source, subreq->len - source.count); - iov_iter_advance(&source, from->transferred); source.count = len; /* Work through the sublist. */ diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c index a75b62b202c5..9ead075962f0 100644 --- a/fs/netfs/write_issue.c +++ b/fs/netfs/write_issue.c @@ -261,9 +261,9 @@ static void netfs_issue_write(struct netfs_io_request *wreq, * we can avoid overrunning the credits obtained (cifs) and try to parallelise * content-crypto preparation with network writes. */ -int netfs_advance_write(struct netfs_io_request *wreq, - struct netfs_io_stream *stream, - loff_t start, size_t len, bool to_eof) +static int netfs_advance_write(struct netfs_io_request *wreq, + struct netfs_io_stream *stream, + loff_t start, size_t len, bool to_eof) { struct netfs_io_subrequest *subreq = stream->construct; size_t part;