Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2056917lqa; Tue, 30 Apr 2024 07:13:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXrjb2HZHIuhG1DySPAZspIJLpFeBqvHrm4FTwJBb+nKmF97hZVV7JC8LajmynTKhT+w2jSLwg3VElGyw8QGguro7usD57oFHYOI70/Yg== X-Google-Smtp-Source: AGHT+IG1xQ2JE/TXWVACWntTtrKnDpRQB9WpJkGjhETcG2ajmODI/cAWt1IIXgMYLzh0ULa/tXac X-Received: by 2002:a05:6870:32d4:b0:22e:bb57:94c6 with SMTP id r20-20020a05687032d400b0022ebb5794c6mr11677462oac.4.1714486405473; Tue, 30 Apr 2024 07:13:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714486405; cv=pass; d=google.com; s=arc-20160816; b=SizYrw3DoT2jIzLNxCEe18qSapm5lRaLNIdQ0E4RbxEftVwpgE90bgZyENm2s2dwmc 6+gLN6jDBU6kVEtxHIj5DChwQ20YxIFyzjZWD2DTkLByxeegZpW0uPM959hbcpHfcoWV tjamCHrJy9dH+JpsLVsa3mLCmcYrtfOe0faKjj4ELhGyFQTW/p4P06v9tBnSt5iPzHAT pyGDPS2Ehqkf1PhQR5mt80F7L32h16CIVcUmk3xORP/j2pEVjCkL9O3oygxNQOy0zof7 H+QeRjiBWHA+ZAhHG86llEF9P0Xl+FWA0CU/ntHlxpM5H1AEDfCNarU0W8xD50pBy/6l r0ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Odg3aZxytikbkfbMJrl0CzuPexMShHC0Kl20ZMSfA0U=; fh=dijFYpEVp+4ijccmXeOrV1fnLJQjsqwgNfcTPuMjuvg=; b=N/jfaXDXaHp7kstPu26BCltFoa8mBGSCH536YPE4WJuHZsoYsS/9to9Utm3z1wA+dd gMZJYuhTLcAo3AUFNEPspIJalEkiE5B/riBZxh/qnK5WiG1EbzQJbFooId5DDmH1nFzt BVJxGWmnQdO44lJLq7UXeq6rZh1OZ8v0C524laM/8wVEd6S4YAsH3/Lox0ew5ijyLv+n rsDep5f/iMP6FBewZfcVqkBg898z42gP342mZGzGUCDSLFNymtcdtsfh6lCPdo+YNjjx +SFDAFqcA+nIqBaEFjkwQ8aJ3QX1i6e9GTK5qTVbN47UBWfLVyPnBFLQD8IF7UvXi+ej +j/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G74Gue6U; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-3092-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3092-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id op9-20020a0568715b0900b0022ea7461ce8si10813871oac.48.2024.04.30.07.13.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:13:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3092-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=G74Gue6U; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-3092-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3092-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CF54528469B for ; Tue, 30 Apr 2024 14:11:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 82C2217A92D; Tue, 30 Apr 2024 14:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G74Gue6U" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 536A5179972 for ; Tue, 30 Apr 2024 14:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714485789; cv=none; b=lYRajPoyxv+SNxFRS49ynddBulQcG50nZ6uDSELDQi4sCtGyVPAakyR+Bk/YgaJR0cgUopc9EnK2b7/lylaXIjkr6r15xkFg9jF7b1te0I4UTGQlVPG16R/Ivn/Ksi40nxxPS8AlKokvJmJ0rHLFKYczl702pxPxgDVqb8T92l8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714485789; c=relaxed/simple; bh=1jcywdFFIj6PVu7haQO4pjpdjJMILtdNqUtDZkKjiFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O154m3n/zIqk+UwDZ5X9nQuuZVli0p7ZjLsycsY5pmtBL+dPq6FiipKsT0kAyjnN2Wi1DEFiB7qcxW6kjtJ4pbxKYMR6yqUFzDUZtBcq4TAAFsWOK5gJpZIYEEBcl2fmTtzCcFCqWfXOxSemJOLxqh+Kb8nm0unGKT5YKVaGhBs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=G74Gue6U; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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, };