Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1949588rdb; Thu, 7 Dec 2023 13:29:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfSL1cEjzb5qSfIE3qU6Tcd8AbofAE0pPGvvYhg/mE7TV6MI7e5UULXHjJhOlzaZQyD+FW X-Received: by 2002:a05:6a20:8f0b:b0:190:2b27:aa34 with SMTP id b11-20020a056a208f0b00b001902b27aa34mr377869pzk.62.1701984581406; Thu, 07 Dec 2023 13:29:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701984581; cv=none; d=google.com; s=arc-20160816; b=wC0sx4cHPPeAH9QZ9mWusbCn47iFZ7qAZCB1Wuv928OvbTOwyma+aGfQO5/7tmi6OS 8xYqth01d78w6jsaRiWflA6p33c77e8tIxcQghWgIr9TiaN6P4XbtfaMdVlDHapRyu2H Y9EDMxDvvvK7J1DJqXJEq37VGhjXqnczCJUvO/maIH7BQ9ywusuKPin8s6u3osY7Rtzi aBBaCU8wCC5Ubj6MMoaf1Zwx2pjqFISknyKvMLfjs+wa25MIihUqgFOni1uwP1G8M4D6 1x37CzA3kxuMgWKYDyLSmAqUuBcUvP2V7Bxk8q/J+lRglPsM5UzzsOdL0N1Q1vqtkfY0 LdsQ== 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=YcUt6Wlq9qFzNGrM+VViKKkJSoOctikTKew3FuWO+5w=; fh=ib4gl95HfLmZdfX9QIMf3rTepWCH9JlNymcDKJTPhJg=; b=awuHMv7eI7JV+VONjkxTDLX5Yrv+30um8R1xwO/zztUw0kJ3p1Og4lvNNox75NGLSm P4npEvaWqfkQDKdeNXsyNc/o8Q7QusspJ2zouvLH9nRdxyotvgI4t3Dly2mH34Y/yZ5A 9CG5P9cxgpJp50Z1RRaEVQo+Dhck6pFKHnQgvVyojf9ZNixKs0MmwacgL/fw07Zol0aN r4CcLBYDTQ5FPBgUO0lDdTjqoooBJCQiGx/yplimFLvbzeSwnO6Yk7vUsMzItTBJUvJV eitJ7TxqY1uv2/MCxHdMnyVtD88Y5VWuvZMlTuVaOA/TjjebSkcWOd6AB/sE0ZoxxfFj tvzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="A6/In2hE"; spf=pass (google.com: domain of linux-nfs+bounces-413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-413-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v3-20020a655683000000b005bdf5961d93si312592pgs.387.2023.12.07.13.29.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 13:29:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="A6/In2hE"; spf=pass (google.com: domain of linux-nfs+bounces-413-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-413-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 D211428216B for ; Thu, 7 Dec 2023 21:29:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4CC956B91; Thu, 7 Dec 2023 21:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A6/In2hE" 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]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6AAD3864 for ; Thu, 7 Dec 2023 13:24:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701984248; 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=YcUt6Wlq9qFzNGrM+VViKKkJSoOctikTKew3FuWO+5w=; b=A6/In2hEwPGbJzTyb0ruQlOPKsV+hh69zxt3UXgLx1sfPOyvcbugoTQbjb5YshVejfgG1S Nwn81YK8z9eNcBVngkQbYeMMrMgPrrjWD1+2zh3HwZk42z4xEkAgRffKQzPyJ+eY6epl10 iqTt3bt6xnaQcHmOFhW4Ang+1S20fRs= 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-50-YYix5oYnM_O-H5lo0OEt7w-1; Thu, 07 Dec 2023 16:23:59 -0500 X-MC-Unique: YYix5oYnM_O-H5lo0OEt7w-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 BE76F1C5407F; Thu, 7 Dec 2023 21:23:58 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2968C492BE6; Thu, 7 Dec 2023 21:23:56 +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 v3 31/59] netfs: Allow buffered shared-writeable mmap through netfs_page_mkwrite() Date: Thu, 7 Dec 2023 21:21:38 +0000 Message-ID: <20231207212206.1379128-32-dhowells@redhat.com> In-Reply-To: <20231207212206.1379128-1-dhowells@redhat.com> References: <20231207212206.1379128-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.10 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 cc: 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 702b864a4993..46c0a6b45bb8 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -403,6 +403,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);