From patchwork Tue Apr 30 14:00:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13649087 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 DA413C25B4F for ; Tue, 30 Apr 2024 14:03:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 576E46B00A0; Tue, 30 Apr 2024 10:03:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AE116B00B5; Tue, 30 Apr 2024 10:03:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FFA06B00B7; Tue, 30 Apr 2024 10:03:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 11EFF6B00A0 for ; Tue, 30 Apr 2024 10:03:08 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C19B01C03E6 for ; Tue, 30 Apr 2024 14:03:07 +0000 (UTC) X-FDA: 82066364814.06.DE545D5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id D7CA5C0016 for ; Tue, 30 Apr 2024 14:03:05 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=G74Gue6U; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1714485785; 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=Odg3aZxytikbkfbMJrl0CzuPexMShHC0Kl20ZMSfA0U=; b=VlyJ0Epxm4RmINOLJ4CmhQv0WgS+bOM4pMi8Qk1QbjCxqYACy+A8OwY3N1tfQmS7g4goCh 6rdl2FV61C/UcHfkhIMIkHODLzVnEZzZhV4AGxGbXsrf5wQCZcgtAHh0GPmd6jR5LrQQn6 3M+jq9tO1cLRrwj6jc6K17q1d3oppJs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714485785; a=rsa-sha256; cv=none; b=C6QFpP+r15wr9f5LhQMChYewPgm6Lgk/Ru9rSnFLAim/ME/JecnkhMH9JGnwSRxdCzKght o17zprGUzbJDotc3yjQd+7v15mGqsIeGNQHTq0TQ9ZI1U7H5sI9wQRGmzZ8M6W8YfZggBh jMb0gvJ1xiIUyr8mv6K4Jt0lihXbf1o= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=G74Gue6U; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714485785; 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=Odg3aZxytikbkfbMJrl0CzuPexMShHC0Kl20ZMSfA0U=; b=G74Gue6Uuw+Hu/jtZpnDM5Jvc6iGqQaSFuZ1uzleKsmblgyjXTCDaPd4P6vXjmrys0SCvs qbhICtZHYM3wzR2P43QnafENeolszxPfs+uF0ajaFch+lLp1L40yK7g4GpUAr6Kg0XFkJQ 8kRMZmtHL6BNYHeyuSl0+j2JAQtVwLo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-445-MRk4RIKmNLehtOWuC76kKg-1; Tue, 30 Apr 2024 10:03:00 -0400 X-MC-Unique: MRk4RIKmNLehtOWuC76kKg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF5AD18065DC; Tue, 30 Apr 2024 14:02:19 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AF33EC680; Tue, 30 Apr 2024 14:02:16 +0000 (UTC) From: David Howells To: Christian Brauner , Jeff Layton , Gao Xiang , Dominique Martinet Cc: David Howells , Matthew Wilcox , Steve French , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, linux-cachefs@redhat.com, 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 18/22] netfs, cachefiles: Implement helpers for new write code Date: Tue, 30 Apr 2024 15:00:49 +0100 Message-ID: <20240430140056.261997-19-dhowells@redhat.com> In-Reply-To: <20240430140056.261997-1-dhowells@redhat.com> References: <20240430140056.261997-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D7CA5C0016 X-Stat-Signature: snozuywebmkyn1qiee4nfyqghy6ybz4y X-Rspam-User: X-HE-Tag: 1714485785-772329 X-HE-Meta: U2FsdGVkX19q1seljkkK5PDDZY5EhbbrhijcHhBfPrXnN/nM1hN+3QlykpOTTRriYRT4y8vtJOES5oQROKXjJT4A9up8WbXbspGyxQd50eLWLqenyULgDQ90Nb6QWfrBabbBSDWp6IvmhSeu8OPHb30vl+F73GJLyxCIDJCzB3WRRatO6i1Vrf785/Ybevv2z1ziBI4octwX03rM7TtD1vuxscbnTvSH4tI+rkljSqoF5or8QV3szwguNImRkT2idUbOaFmwmQLibg/b5YmGu80SR0EQ2/S/o4p1rv0/Lj993T9h1ltR9neoc3HLY9wZjtGiZroIZRPSuQAIDq8isLdw/vO1zaZFu7++8QupcJ9nLI/JgPBKFTN6dVm/vIu/pDLomOL/M+WS7+U3IgJsS9zZdtRm1BY/8phPN7eKQlA7MeVc0lmUspGHjYqdpB0ug9ENOZITZOeGrhEjT5SZD0tt9o4tpaLBrBLmvCHJg9WNosDZ3U17OgXSQhNGyq8kySHA5xnzvzCzLBiBg97ElklyB9g+Uffm9fUdeFIfj7YaxdGsqI8gWiZ/0nPaZpF+yzzSiWvRAfRTsAutpeGzJDzdADiz7/XNiAb6U6/Xly7hu5oxSw2QpZoopaFh7rQavcj99SmKtUn5YlmjZoVe+o+5y/kuP+D3zz3Yg1uLwXDXX1Vj0R3jM1PBWOhVZKOqCNLLfPx3b56u6Nvaoh74080WW+SZDUAu60t4X2AKwr3xBPchpQqEUhTjcM2eHjaHbXAqU5QAL34V8iggdWS/Y4Z3u2FS0ASqMlA9b7HcZ7XHhU034xQyqkYFhwWo0iDSgVQUGjlApkO9SZA5CI5jfkEBpqkckQEA5HD6v9+aF5djTpYpCQGlVGOBfiO4RivNsZ0Gt8OKLLyYRW00vP48h5Gz2yjuEelMsoHfNotBBuypeY8I0rUA0ee54bmVg3ja6d55xhZC2W/bv+j+M+C KvbI+9t0 juzr/KXnmXIa+1V7GBaUQN8F9ak0XI8dazuNKA75FKuy+Ay8N02fEwRpVP4rSbdrYsfU3LDfdp3tetRiTrr2qWK/Swk1tOSyXSek1zg9dwU+8RrWiRCbH5FxIriBBJ6xYcTnIYnKg50knG4zoAHNADjoqEtUdWN+QQfauN2+oRPvKjhRQPQ7bzEFsO6SBokBiCUcr3XHWJ/zrb8GkNg1szpJhRkTYVUR4vHNKiZAcR23kFPBCQrNB2pIWUQ+gpQi9qEM2c9OGgT9SPAJMZbaC9ZD+cA7kql4lsmwCjDbZjFu11TccZcuzGfAcoMNA1O6/CbfF 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: Implement the helpers for the new write code in cachefiles. There's now an optional ->prepare_write() that allows the filesystem to set the parameters for the next write, such as maximum size and maximum segment count, and an ->issue_write() that is called to initiate an (asynchronous) write operation. Signed-off-by: David Howells Reviewed-by: Jeff Layton cc: netfs@lists.linux.dev cc: linux-erofs@lists.ozlabs.org cc: linux-fsdevel@vger.kernel.org --- Notes: Changes ======= ver #2) - Add missing linux/bio.h for BIO_MAX_VECS. fs/cachefiles/io.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c index 5ba5c7814fe4..e667dbcd20e8 100644 --- a/fs/cachefiles/io.c +++ b/fs/cachefiles/io.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -622,6 +623,77 @@ static int cachefiles_prepare_write(struct netfs_cache_resources *cres, return ret; } +static void cachefiles_prepare_write_subreq(struct netfs_io_subrequest *subreq) +{ + struct netfs_io_request *wreq = subreq->rreq; + struct netfs_cache_resources *cres = &wreq->cache_resources; + + _enter("W=%x[%x] %llx", wreq->debug_id, subreq->debug_index, subreq->start); + + subreq->max_len = ULONG_MAX; + subreq->max_nr_segs = BIO_MAX_VECS; + + if (!cachefiles_cres_file(cres)) { + if (!fscache_wait_for_operation(cres, FSCACHE_WANT_WRITE)) + return netfs_prepare_write_failed(subreq); + if (!cachefiles_cres_file(cres)) + return netfs_prepare_write_failed(subreq); + } +} + +static void cachefiles_issue_write(struct netfs_io_subrequest *subreq) +{ + struct netfs_io_request *wreq = subreq->rreq; + struct netfs_cache_resources *cres = &wreq->cache_resources; + struct cachefiles_object *object = cachefiles_cres_object(cres); + struct cachefiles_cache *cache = object->volume->cache; + const struct cred *saved_cred; + size_t off, pre, post, len = subreq->len; + loff_t start = subreq->start; + int ret; + + _enter("W=%x[%x] %llx-%llx", + wreq->debug_id, subreq->debug_index, start, start + len - 1); + + /* We need to start on the cache granularity boundary */ + off = start & (CACHEFILES_DIO_BLOCK_SIZE - 1); + if (off) { + pre = CACHEFILES_DIO_BLOCK_SIZE - off; + if (pre >= len) { + netfs_write_subrequest_terminated(subreq, len, false); + return; + } + subreq->transferred += pre; + start += pre; + len -= pre; + iov_iter_advance(&subreq->io_iter, pre); + } + + /* We also need to end on the cache granularity boundary */ + post = len & (CACHEFILES_DIO_BLOCK_SIZE - 1); + if (post) { + len -= post; + if (len == 0) { + netfs_write_subrequest_terminated(subreq, post, false); + return; + } + iov_iter_truncate(&subreq->io_iter, len); + } + + cachefiles_begin_secure(cache, &saved_cred); + ret = __cachefiles_prepare_write(object, cachefiles_cres_file(cres), + &start, &len, len, true); + cachefiles_end_secure(cache, saved_cred); + if (ret < 0) { + netfs_write_subrequest_terminated(subreq, ret, false); + return; + } + + cachefiles_write(&subreq->rreq->cache_resources, + subreq->start, &subreq->io_iter, + netfs_write_subrequest_terminated, subreq); +} + /* * Clean up an operation. */ @@ -638,8 +710,10 @@ static const struct netfs_cache_ops cachefiles_netfs_cache_ops = { .end_operation = cachefiles_end_operation, .read = cachefiles_read, .write = cachefiles_write, + .issue_write = cachefiles_issue_write, .prepare_read = cachefiles_prepare_read, .prepare_write = cachefiles_prepare_write, + .prepare_write_subreq = cachefiles_prepare_write_subreq, .prepare_ondemand_read = cachefiles_prepare_ondemand_read, .query_occupancy = cachefiles_query_occupancy, };