Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp154024rdb; Thu, 21 Dec 2023 05:42:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXg5oEWC++YUBcXvPo6Ou70npI70ZQvUpcJabeUyy8wNTkjV7WfySSF2Z3VFduDZK8zFCo X-Received: by 2002:a0c:c58d:0:b0:67a:a721:f322 with SMTP id a13-20020a0cc58d000000b0067aa721f322mr21067363qvj.98.1703166175503; Thu, 21 Dec 2023 05:42:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703166175; cv=none; d=google.com; s=arc-20160816; b=jEJZyMRMOHjKQdSO1IJTnX2KU9BH25i2fQn8d8wX45UIjUzHsJKgVifBMI/gnLYxhB WmPucqHr26deGD6F6P+dZaj50swBSVw1XkzZfLg48D0MYNCDXKZ7p0nSBdBovIPc/HmQ 6aNUJ2mf2umXBdJG9nVPK3t+BqnZ+u1wPl/khtiFl1vVmmTUQL1Dwu4Mxwhzn2p0Za35 hk1Ay21RRizRJA+C8grv5aolZTGBqvVmWVCr2LKiupOPumPlVbmDoVkUmqBweA2jjvFQ pDdwtnG23144rMHy+4/hmHubFGwZApMiZmWgiofJAS4xUcAKQIo/zCkAE5CYQUnp4Sov kWZg== ARC-Message-Signature: i=1; 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=Lo7aiJvCCD3HpSl6jVNRfFvoImcPzv/sQTt6KTq//FQ=; fh=ib4gl95HfLmZdfX9QIMf3rTepWCH9JlNymcDKJTPhJg=; b=ehq+kmklznL89zuX2f1nlecIPmvZ3TZi4MTN4jNcBGLE1wVYP+tA3QZZGsgNfC5++N fkflfrZGRJwE9KzgYbrULvdGG2bIL4JYrRJRm4Ad58TuOrLC3oBzXc479q9isxpWAgwR oP68y9yZ61Pv88eIPSzFWLuQT7iyvt0MkDBW9UhQctm/k+lFAgULYtH7p2aC78ImVa2f eFlkhNjIAEus46R6Sx94vfnQnK3Sm43lvJrZY5h6qHYdtyn+HmuW8NELa390ln3kJdEg /5PP2L6UI5bNtc+OQfzPTC9m/FAIGLIl3wFHWg4h71H5RfSyCAb2kkbg2lGP9VT09Ge8 bM2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fPCn+GI+; spf=pass (google.com: domain of linux-nfs+bounces-757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w17-20020a0cdf91000000b0067f3ac7815esi2221184qvl.570.2023.12.21.05.42.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 05:42:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fPCn+GI+; spf=pass (google.com: domain of linux-nfs+bounces-757-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-nfs+bounces-757-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 44C921C24E33 for ; Thu, 21 Dec 2023 13:42:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34CD41396D0; Thu, 21 Dec 2023 13:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fPCn+GI+" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 9CA231396D1 for ; Thu, 21 Dec 2023 13:26:09 +0000 (UTC) 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=1703165168; 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=Lo7aiJvCCD3HpSl6jVNRfFvoImcPzv/sQTt6KTq//FQ=; b=fPCn+GI+ZlA3gt5CsTMlxf4AZW06YBe7shhyJ0okOcCdtM7bAUDsRGis3WBKQO9ZBq98kb K27ObfzWTu7fY+MZlLLzhcO6vRYzFQpfx3d0pNfAlxHqk2Oh7H87JPjmlt7Do5gecfkM9M NwpSUHHCp/nSi5ElvPANqGVEjY2Cf5U= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-iLvM_qjVNmCc3BKo7CvF9A-1; Thu, 21 Dec 2023 08:26:04 -0500 X-MC-Unique: iLvM_qjVNmCc3BKo7CvF9A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 C70CE3C000BD; Thu, 21 Dec 2023 13:26:03 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.39.195.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1C452166B31; Thu, 21 Dec 2023 13:26:00 +0000 (UTC) From: David Howells To: Jeff Layton , Steve French Cc: David Howells , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Eric Van Hensbergen , Ilya Dryomov , Christian Brauner , 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-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 31/40] netfs: Allow buffered shared-writeable mmap through netfs_page_mkwrite() Date: Thu, 21 Dec 2023 13:23:26 +0000 Message-ID: <20231221132400.1601991-32-dhowells@redhat.com> In-Reply-To: <20231221132400.1601991-1-dhowells@redhat.com> References: <20231221132400.1601991-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.6 Provide an entry point to delegate a filesystem's ->page_mkwrite() to. This checks for conflicting writes, then attached any netfs-specific group marking (e.g. ceph snap) to the page to be considered dirty. Signed-off-by: David Howells Reviewed-by: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/buffered_write.c | 59 +++++++++++++++++++++++++++++++++++++++ include/linux/netfs.h | 4 +++ 2 files changed, 63 insertions(+) diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index f244123ab568..70cb8e98d068 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -416,3 +416,62 @@ ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) return ret; } EXPORT_SYMBOL(netfs_file_write_iter); + +/* + * Notification that a previously read-only page is about to become writable. + * Note that the caller indicates a single page of a multipage folio. + */ +vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group) +{ + struct folio *folio = page_folio(vmf->page); + struct file *file = vmf->vma->vm_file; + struct inode *inode = file_inode(file); + vm_fault_t ret = VM_FAULT_RETRY; + int err; + + _enter("%lx", folio->index); + + sb_start_pagefault(inode->i_sb); + + if (folio_wait_writeback_killable(folio)) + goto out; + + if (folio_lock_killable(folio) < 0) + goto out; + + /* Can we see a streaming write here? */ + if (WARN_ON(!folio_test_uptodate(folio))) { + ret = VM_FAULT_SIGBUS | VM_FAULT_LOCKED; + goto out; + } + + if (netfs_folio_group(folio) != netfs_group) { + folio_unlock(folio); + err = filemap_fdatawait_range(inode->i_mapping, + folio_pos(folio), + folio_pos(folio) + folio_size(folio)); + switch (err) { + case 0: + ret = VM_FAULT_RETRY; + goto out; + case -ENOMEM: + ret = VM_FAULT_OOM; + goto out; + default: + ret = VM_FAULT_SIGBUS; + goto out; + } + } + + if (folio_test_dirty(folio)) + trace_netfs_folio(folio, netfs_folio_trace_mkwrite_plus); + else + trace_netfs_folio(folio, netfs_folio_trace_mkwrite); + netfs_set_group(folio, netfs_group); + file_update_time(file); + ret = VM_FAULT_LOCKED; +out: + sb_end_pagefault(inode->i_sb); + return ret; +} +EXPORT_SYMBOL(netfs_page_mkwrite); diff --git a/include/linux/netfs.h b/include/linux/netfs.h index 5c225f308704..e444f814dd56 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -401,6 +401,10 @@ void netfs_clear_inode_writeback(struct inode *inode, const void *aux); void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length); bool netfs_release_folio(struct folio *folio, gfp_t gfp); +/* VMA operations API. */ +vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group); + +/* (Sub)request management API. */ void netfs_subreq_terminated(struct netfs_io_subrequest *, ssize_t, bool); void netfs_get_subrequest(struct netfs_io_subrequest *subreq, enum netfs_sreq_ref_trace what);