From patchwork Fri Dec 16 15:06:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 1716551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=e81s=4o=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WZ6HoS/9; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYXXJ5l82z23ym for ; Sat, 17 Dec 2022 02:07:44 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXXJ5FVYz4xFr for ; Sat, 17 Dec 2022 02:07:44 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NYXXJ5CPlz4xGP; Sat, 17 Dec 2022 02:07:44 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WZ6HoS/9; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXXJ56Mdz4xFr for ; Sat, 17 Dec 2022 02:07:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231282AbiLPPHn (ORCPT ); Fri, 16 Dec 2022 10:07:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231284AbiLPPHW (ORCPT ); Fri, 16 Dec 2022 10:07:22 -0500 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 B30F2FDA for ; Fri, 16 Dec 2022 07:06:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671203194; 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=oaDAnC1sTKX92MKULIjHiEC9OYj6fZcVoW9K2+IChko=; b=WZ6HoS/9lF/2f5QAYWTbNyTc3D/1pDspUhR1PgQD7OVGKDenpZf49tFAcggLxlLVn9k0eL 2dx9MDz9eXmqDHfA9/LuFfWu4RTOW8IJIf389FPa0GhcIZBq5U/rTEty69500iMlgpY/GL pYKSB7hEKtxac+HkC+vsGBh7YrTA8iA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-BcFUScATMWGpX0_Un_nT4A-1; Fri, 16 Dec 2022 10:06:32 -0500 X-MC-Unique: BcFUScATMWGpX0_Un_nT4A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1F1763C10ECE; Fri, 16 Dec 2022 15:06:32 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-182.brq.redhat.com [10.40.192.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id D24CE14171BE; Fri, 16 Dec 2022 15:06:29 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox Cc: Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC v3 1/7] fs: Add folio_may_straddle_isize helper Date: Fri, 16 Dec 2022 16:06:20 +0100 Message-Id: <20221216150626.670312-2-agruenba@redhat.com> In-Reply-To: <20221216150626.670312-1-agruenba@redhat.com> References: <20221216150626.670312-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add a folio_may_straddle_isize() helper as a replacement for pagecache_isize_extended() when we have a locked folio. Use the new helper in generic_write_end(), iomap_write_end(), ext4_write_end(), and ext4_journalled_write_end(). Signed-off-by: Andreas Gruenbacher --- fs/buffer.c | 5 ++--- fs/ext4/inode.c | 13 ++++++------- fs/iomap/buffered-io.c | 3 +-- include/linux/mm.h | 2 ++ mm/truncate.c | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 12 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index d9c6d1fbb6dd..bbae1437994b 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2164,16 +2164,15 @@ int generic_write_end(struct file *file, struct address_space *mapping, * But it's important to update i_size while still holding page lock: * page writeout could otherwise come in and zero beyond i_size. */ - if (pos + copied > inode->i_size) { + if (pos + copied > old_size) { i_size_write(inode, pos + copied); i_size_changed = true; + folio_may_straddle_isize(inode, page_folio(page), old_size, pos); } unlock_page(page); put_page(page); - if (old_size < pos) - pagecache_isize_extended(inode, old_size, pos); /* * Don't mark the inode dirty under page lock. First, it unnecessarily * makes the holding time of page lock longer. Second, it forces lock diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9d9f414f99fe..6fe1c9609d86 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1327,13 +1327,13 @@ static int ext4_write_end(struct file *file, * If FS_IOC_ENABLE_VERITY is running on this inode, then Merkle tree * blocks are being written past EOF, so skip the i_size update. */ - if (!verity) + if (!verity) { i_size_changed = ext4_update_inode_size(inode, pos + copied); + folio_may_straddle_isize(inode, page_folio(page), old_size, pos); + } unlock_page(page); put_page(page); - if (old_size < pos && !verity) - pagecache_isize_extended(inode, old_size, pos); /* * Don't mark the inode dirty under page lock. First, it unnecessarily * makes the holding time of page lock longer. Second, it forces lock @@ -1439,16 +1439,15 @@ static int ext4_journalled_write_end(struct file *file, if (!partial) SetPageUptodate(page); } - if (!verity) + if (!verity) { size_changed = ext4_update_inode_size(inode, pos + copied); + folio_may_straddle_isize(inode, page_folio(page), old_size, pos); + } ext4_set_inode_state(inode, EXT4_STATE_JDATA); EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; unlock_page(page); put_page(page); - if (old_size < pos && !verity) - pagecache_isize_extended(inode, old_size, pos); - if (size_changed) { ret2 = ext4_mark_inode_dirty(handle, inode); if (!ret) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 356193e44cf0..347010c6a652 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -734,11 +734,10 @@ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, if (pos + ret > old_size) { i_size_write(iter->inode, pos + ret); iter->iomap.flags |= IOMAP_F_SIZE_CHANGED; + folio_may_straddle_isize(iter->inode, folio, old_size, pos); } folio_unlock(folio); - if (old_size < pos) - pagecache_isize_extended(iter->inode, old_size, pos); if (page_ops && page_ops->page_done) page_ops->page_done(iter->inode, pos, ret, &folio->page); folio_put(folio); diff --git a/include/linux/mm.h b/include/linux/mm.h index 8178fe894e2e..a8632747780e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2016,6 +2016,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, extern void truncate_pagecache(struct inode *inode, loff_t new); extern void truncate_setsize(struct inode *inode, loff_t newsize); +void folio_may_straddle_isize(struct inode *inode, struct folio *folio, + loff_t old_size, loff_t start); void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to); void truncate_pagecache_range(struct inode *inode, loff_t offset, loff_t end); int generic_error_remove_page(struct address_space *mapping, struct page *page); diff --git a/mm/truncate.c b/mm/truncate.c index 7b4ea4c4a46b..971b08399144 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -769,6 +769,41 @@ void truncate_setsize(struct inode *inode, loff_t newsize) } EXPORT_SYMBOL(truncate_setsize); +/** + * folio_may_straddle_isize - update pagecache after extending i_size + * @inode: inode for which i_size was extended + * @folio: folio to maybe mark read-only + * @old_size: original inode size + * @start: start of the write + * + * Handle extending an inode by a write that starts behind the old inode size. + * If a block-aligned hole exists between the old inode size and the start of + * the write, we mark the folio read-only so that page_mkwrite() is called on + * the nearest write access to the page. That way, the filesystem can be sure + * that page_mkwrite() is called on the page before a user writes to the page + * via mmap. + * + * This function must be called while we still hold i_rwsem - this not only + * makes sure i_size is stable but also that userspace cannot observe the new + * i_size value before we are prepared to handle mmap writes there. + */ +void folio_may_straddle_isize(struct inode *inode, struct folio *folio, + loff_t old_size, loff_t start) +{ + unsigned int blocksize = i_blocksize(inode); + + if (round_up(old_size, blocksize) >= round_down(start, blocksize)) + return; + + /* + * See clear_page_dirty_for_io() for details why folio_set_dirty() + * is needed. + */ + if (folio_mkclean(folio)) + folio_set_dirty(folio); +} +EXPORT_SYMBOL(folio_may_straddle_isize); + /** * pagecache_isize_extended - update pagecache after extension of i_size * @inode: inode for which i_size was extended From patchwork Fri Dec 16 15:06:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 1716554 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=e81s=4o=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ixX9ZZpB; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYXXd5s7Xz23ym for ; Sat, 17 Dec 2022 02:08:01 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXXd5gYgz4xFr for ; Sat, 17 Dec 2022 02:08:01 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NYXXd5dL5z4xGP; Sat, 17 Dec 2022 02:08:01 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ixX9ZZpB; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXXd5Vfsz4xFr for ; Sat, 17 Dec 2022 02:08:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231297AbiLPPH7 (ORCPT ); Fri, 16 Dec 2022 10:07:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231292AbiLPPHa (ORCPT ); Fri, 16 Dec 2022 10:07:30 -0500 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 81E8865B6 for ; Fri, 16 Dec 2022 07:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671203198; 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=VO+moG/oEppC7fzqfjLDfJ6GvGE7XkJyRsj4uh85qjM=; b=ixX9ZZpB8zvX0z3ELt0L3bjXPbZckDX7aXj9crg4SnczXmFo3Y4zU5WU1FP2VdVXxGEI1N p0TU4GHh11dyo8to2OPqQSXhzBguAXJ+VdBzHo6XmH4QlDG4omXGTrwoADYHjtgA/QUhfv K9Od+gHDxXaHw1JBz/pFWcx9a8D8uik= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-424-72lxkenAM3Cbt1AoMuZRSg-1; Fri, 16 Dec 2022 10:06:35 -0500 X-MC-Unique: 72lxkenAM3Cbt1AoMuZRSg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7461858F09; Fri, 16 Dec 2022 15:06:34 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-182.brq.redhat.com [10.40.192.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9912E14171C0; Fri, 16 Dec 2022 15:06:32 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox Cc: Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC v3 2/7] iomap: Add iomap_folio_done helper Date: Fri, 16 Dec 2022 16:06:21 +0100 Message-Id: <20221216150626.670312-3-agruenba@redhat.com> In-Reply-To: <20221216150626.670312-1-agruenba@redhat.com> References: <20221216150626.670312-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add an iomap_folio_done() helper to encapsulate unlocking the folio, calling ->page_done(), and putting the folio. This doesn't change the functionality. Signed-off-by: Andreas Gruenbacher --- fs/iomap/buffered-io.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 347010c6a652..8ce9abb29d46 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -575,6 +575,19 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, return 0; } +static void iomap_folio_done(struct iomap_iter *iter, loff_t pos, size_t ret, + struct folio *folio) +{ + const struct iomap_page_ops *page_ops = iter->iomap.page_ops; + + if (folio) + folio_unlock(folio); + if (page_ops && page_ops->page_done) + page_ops->page_done(iter->inode, pos, ret, &folio->page); + if (folio) + folio_put(folio); +} + static int iomap_write_begin_inline(const struct iomap_iter *iter, struct folio *folio) { @@ -616,7 +629,8 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, fgp, mapping_gfp_mask(iter->inode->i_mapping)); if (!folio) { status = (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; - goto out_no_page; + iomap_folio_done(iter, pos, 0, NULL); + return status; } /* @@ -656,13 +670,9 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, return 0; out_unlock: - folio_unlock(folio); - folio_put(folio); + iomap_folio_done(iter, pos, 0, folio); iomap_write_failed(iter->inode, pos, len); -out_no_page: - if (page_ops && page_ops->page_done) - page_ops->page_done(iter->inode, pos, 0, NULL); return status; } @@ -712,7 +722,6 @@ static size_t iomap_write_end_inline(const struct iomap_iter *iter, static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, size_t copied, struct folio *folio) { - const struct iomap_page_ops *page_ops = iter->iomap.page_ops; const struct iomap *srcmap = iomap_iter_srcmap(iter); loff_t old_size = iter->inode->i_size; size_t ret; @@ -736,11 +745,8 @@ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, iter->iomap.flags |= IOMAP_F_SIZE_CHANGED; folio_may_straddle_isize(iter->inode, folio, old_size, pos); } - folio_unlock(folio); - if (page_ops && page_ops->page_done) - page_ops->page_done(iter->inode, pos, ret, &folio->page); - folio_put(folio); + iomap_folio_done(iter, pos, ret, folio); if (ret < len) iomap_write_failed(iter->inode, pos + ret, len - ret); From patchwork Fri Dec 16 15:06:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 1716552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=e81s=4o=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EuNl6i7e; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYXXc2c55z23ym for ; Sat, 17 Dec 2022 02:08:00 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXXc25Pkz4xFr for ; Sat, 17 Dec 2022 02:08:00 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NYXXc233jz4xGP; Sat, 17 Dec 2022 02:08:00 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EuNl6i7e; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXXc1z4sz4xFr for ; Sat, 17 Dec 2022 02:08:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231330AbiLPPH5 (ORCPT ); Fri, 16 Dec 2022 10:07:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbiLPPHZ (ORCPT ); Fri, 16 Dec 2022 10:07:25 -0500 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 2185012639 for ; Fri, 16 Dec 2022 07:06:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671203201; 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=/nz1ABIr9FX4nrBYSQ3w8yAlDY1zba1m15vCTBuzyx8=; b=EuNl6i7eqKOHE/FjLPFfJeXIOMWNktyVqY5w9QZtqBU6cxx3IS1ATSmKeC3Uv2G4tfOOKJ 8KM0Y1HNefbdxNtbMsgm4m36M9V31kTJfLlwTk9IyJ1nJmwLm1V78Itxe9nsEIUo/d/wi+ +XhnWq9AXOmbSd63QpvUvS1MMGJQL08= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-190-oWHbi9_dOZOOPCoLKPZyzg-1; Fri, 16 Dec 2022 10:06:37 -0500 X-MC-Unique: oWHbi9_dOZOOPCoLKPZyzg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7A83829AB3E9; Fri, 16 Dec 2022 15:06:37 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-182.brq.redhat.com [10.40.192.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 139B614171BE; Fri, 16 Dec 2022 15:06:34 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox Cc: Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC v3 3/7] iomap/gfs2: Unlock and put folio in page_done handler Date: Fri, 16 Dec 2022 16:06:22 +0100 Message-Id: <20221216150626.670312-4-agruenba@redhat.com> In-Reply-To: <20221216150626.670312-1-agruenba@redhat.com> References: <20221216150626.670312-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When an iomap defines a ->page_done() handler in its page_ops, delegate unlocking the folio and putting the folio reference to that handler. This allows to fix a race between journaled data writes and folio writeback in gfs2: before this change, gfs2_iomap_page_done() was called after unlocking the folio, so writeback could start writing the folio's buffers back before they could be marked for writing to the journal. Also, try_to_free_buffers() could free the buffers before gfs2_iomap_page_done() was done adding the buffers to the current current transaction. With this change, gfs2_iomap_page_done() can add the buffers to the current transaction while the folio is still locked. It can then unlock the folio and complete the current transaction. (If we just moved the entire ->page_done() handler under the folio lock, dirtying the inode could deadlock with the locked folio on filesystems with a block size smaller than the page size.) The only current user of ->page_done() is gfs2, so other filesystems are not affected. Still, to catch out any new users, switch from a page to a folio in ->page_done(). Signed-off-by: Andreas Gruenbacher --- fs/gfs2/bmap.c | 15 ++++++++++++--- fs/iomap/buffered-io.c | 8 ++++---- include/linux/iomap.h | 7 ++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 3bdb2c668a71..11115fce68cb 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -971,14 +971,23 @@ static int gfs2_iomap_page_prepare(struct inode *inode, loff_t pos, } static void gfs2_iomap_page_done(struct inode *inode, loff_t pos, - unsigned copied, struct page *page) + unsigned copied, struct folio *folio) { struct gfs2_trans *tr = current->journal_info; struct gfs2_inode *ip = GFS2_I(inode); struct gfs2_sbd *sdp = GFS2_SB(inode); - if (page && !gfs2_is_stuffed(ip)) - gfs2_page_add_databufs(ip, page, offset_in_page(pos), copied); + if (!folio) { + gfs2_trans_end(sdp); + return; + } + + if (!gfs2_is_stuffed(ip)) + gfs2_page_add_databufs(ip, &folio->page, offset_in_page(pos), + copied); + + folio_unlock(folio); + folio_put(folio); if (tr->tr_num_buf_new) __mark_inode_dirty(inode, I_DIRTY_DATASYNC); diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 8ce9abb29d46..517ad5380a62 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -580,12 +580,12 @@ static void iomap_folio_done(struct iomap_iter *iter, loff_t pos, size_t ret, { const struct iomap_page_ops *page_ops = iter->iomap.page_ops; - if (folio) + if (page_ops && page_ops->page_done) { + page_ops->page_done(iter->inode, pos, ret, folio); + } else if (folio) { folio_unlock(folio); - if (page_ops && page_ops->page_done) - page_ops->page_done(iter->inode, pos, ret, &folio->page); - if (folio) folio_put(folio); + } } static int iomap_write_begin_inline(const struct iomap_iter *iter, diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 0983dfc9a203..743e2a909162 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -131,13 +131,14 @@ static inline bool iomap_inline_data_valid(const struct iomap *iomap) * associated with them. * * When page_prepare succeeds, page_done will always be called to do any - * cleanup work necessary. In that page_done call, @page will be NULL if the - * associated page could not be obtained. + * cleanup work necessary. In that page_done call, @folio will be NULL if the + * associated folio could not be obtained. When folio is not NULL, page_done + * is responsible for unlocking and putting the folio. */ struct iomap_page_ops { int (*page_prepare)(struct inode *inode, loff_t pos, unsigned len); void (*page_done)(struct inode *inode, loff_t pos, unsigned copied, - struct page *page); + struct folio *folio); /* * Check that the cached iomap still maps correctly to the filesystem's From patchwork Fri Dec 16 15:06:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 1716553 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=e81s=4o=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=coy2XM1A; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYXXc5VzQz240X for ; Sat, 17 Dec 2022 02:08:00 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXXc546Tz4xFr for ; Sat, 17 Dec 2022 02:08:00 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NYXXc521Tz4xGP; Sat, 17 Dec 2022 02:08:00 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=coy2XM1A; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXXc4xw5z4xFr for ; Sat, 17 Dec 2022 02:08:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231337AbiLPPH6 (ORCPT ); Fri, 16 Dec 2022 10:07:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbiLPPHa (ORCPT ); Fri, 16 Dec 2022 10:07:30 -0500 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 DF2B013F44 for ; Fri, 16 Dec 2022 07:06:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671203202; 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=BZgSNEk7ohWBknf3nvFSN56CDLafXV5s1mvKpkk+zzc=; b=coy2XM1AnTOfy6NyJkMYW5vH8S/r5GhdHHVZ4aORkKwp8ij5gBFraxjJ/LIlHJhHN1zc4H dOq7L4JXfHBQdpZleIKr9by7CH0Nbs4rhys4+lwAA0t8Qhv13lqsfA4NSTskqrgAxGYbjZ h0NNlhpewuy10KVdmkh3yy6mpPguHa4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-422-FlOPzOmuOOS6mhfGXN7I-w-1; Fri, 16 Dec 2022 10:06:40 -0500 X-MC-Unique: FlOPzOmuOOS6mhfGXN7I-w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1B27710119EB; Fri, 16 Dec 2022 15:06:40 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-182.brq.redhat.com [10.40.192.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE64C14171BE; Fri, 16 Dec 2022 15:06:37 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox Cc: Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC v3 4/7] iomap: Add iomap_folio_prepare helper Date: Fri, 16 Dec 2022 16:06:23 +0100 Message-Id: <20221216150626.670312-5-agruenba@redhat.com> In-Reply-To: <20221216150626.670312-1-agruenba@redhat.com> References: <20221216150626.670312-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add an iomap_folio_prepare() helper that gets a folio reference based on an iomap iterator and an offset into the address space. Signed-off-by: Andreas Gruenbacher --- fs/iomap/buffered-io.c | 27 +++++++++++++++++++++------ include/linux/iomap.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 517ad5380a62..f0f167ca1b2e 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -457,6 +457,26 @@ bool iomap_is_partially_uptodate(struct folio *folio, size_t from, size_t count) } EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate); +/** + * iomap_folio_prepare - get a folio reference for writing + * @iter: iteration structure + * @pos: start offset of write + * + * Returns a locked reference to the folio at @pos, or NULL if the folio could + * not be obtained. + */ +struct folio *iomap_folio_prepare(struct iomap_iter *iter, loff_t pos) +{ + unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS; + + if (iter->flags & IOMAP_NOWAIT) + fgp |= FGP_NOWAIT; + + return __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, + fgp, mapping_gfp_mask(iter->inode->i_mapping)); +} +EXPORT_SYMBOL(iomap_folio_prepare); + bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags) { trace_iomap_release_folio(folio->mapping->host, folio_pos(folio), @@ -603,12 +623,8 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, const struct iomap_page_ops *page_ops = iter->iomap.page_ops; const struct iomap *srcmap = iomap_iter_srcmap(iter); struct folio *folio; - unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS; int status = 0; - if (iter->flags & IOMAP_NOWAIT) - fgp |= FGP_NOWAIT; - BUG_ON(pos + len > iter->iomap.offset + iter->iomap.length); if (srcmap != &iter->iomap) BUG_ON(pos + len > srcmap->offset + srcmap->length); @@ -625,8 +641,7 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, return status; } - folio = __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, - fgp, mapping_gfp_mask(iter->inode->i_mapping)); + folio = iomap_folio_prepare(iter, pos); if (!folio) { status = (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; iomap_folio_done(iter, pos, 0, NULL); diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 743e2a909162..0bf16ef22d81 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -261,6 +261,7 @@ int iomap_file_buffered_write_punch_delalloc(struct inode *inode, int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops); void iomap_readahead(struct readahead_control *, const struct iomap_ops *ops); bool iomap_is_partially_uptodate(struct folio *, size_t from, size_t count); +struct folio *iomap_folio_prepare(struct iomap_iter *iter, loff_t pos); bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags); void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len); int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, From patchwork Fri Dec 16 15:06:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 1716555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=e81s=4o=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZgSy0lyR; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYXY76Qw6z23ym for ; Sat, 17 Dec 2022 02:08:27 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXY75ymgz4xFr for ; Sat, 17 Dec 2022 02:08:27 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NYXY75wW3z4xGP; Sat, 17 Dec 2022 02:08:27 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZgSy0lyR; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXY75rGHz4xFr for ; Sat, 17 Dec 2022 02:08:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbiLPPI0 (ORCPT ); Fri, 16 Dec 2022 10:08:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231301AbiLPPHi (ORCPT ); Fri, 16 Dec 2022 10:07:38 -0500 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 63EE31C2 for ; Fri, 16 Dec 2022 07:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671203206; 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=QI72j2XrdosgKnSLpRZ/7ZEOQEe2TrvWzPHFLuxiJBI=; b=ZgSy0lyRlGKzojMnfp6A4Gu53zkgOpftsFEiT7gbIgTrzHuUNjFG6hzH5cfnIE5dmj72QV gp4eLpZZz1vfKrH4yfkW0Nbp1wuiSFPx5qMLyq1G4YaC1Kua3s41CcWnwnTMrMYA0mQpo1 Hb+r2dMuuwOA0I2zA7ye4eXdJXK/Hgg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-474-FL60E5LNN169iDjYzpHFjg-1; Fri, 16 Dec 2022 10:06:43 -0500 X-MC-Unique: FL60E5LNN169iDjYzpHFjg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC1E2886066; Fri, 16 Dec 2022 15:06:42 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-182.brq.redhat.com [10.40.192.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BA0314171BE; Fri, 16 Dec 2022 15:06:40 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox Cc: Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC v3 5/7] iomap: Get page in page_prepare handler Date: Fri, 16 Dec 2022 16:06:24 +0100 Message-Id: <20221216150626.670312-6-agruenba@redhat.com> In-Reply-To: <20221216150626.670312-1-agruenba@redhat.com> References: <20221216150626.670312-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Change the iomap ->page_prepare() handler to get and return a locked folio instead of doing that in iomap_write_begin(). This allows to recover from out-of-memory situations in ->page_prepare(), which eliminates the corresponding error handling code in iomap_write_begin(). The ->page_done() handler is now not called with a NULL folio anymore. Filesystems are expected to use the iomap_folio_prepare() helper for getting locked folios in their ->page_prepare() handlers. Signed-off-by: Andreas Gruenbacher --- fs/gfs2/bmap.c | 16 +++++++++++++--- fs/iomap/buffered-io.c | 21 +++++++++------------ include/linux/iomap.h | 9 +++++---- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 11115fce68cb..cd5984d3ba50 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -959,15 +959,25 @@ static int __gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, goto out; } -static int gfs2_iomap_page_prepare(struct inode *inode, loff_t pos, - unsigned len) +static struct folio * +gfs2_iomap_page_prepare(struct iomap_iter *iter, loff_t pos, unsigned len) { + struct inode *inode = iter->inode; unsigned int blockmask = i_blocksize(inode) - 1; struct gfs2_sbd *sdp = GFS2_SB(inode); unsigned int blocks; + struct folio *folio; + int status; blocks = ((pos & blockmask) + len + blockmask) >> inode->i_blkbits; - return gfs2_trans_begin(sdp, RES_DINODE + blocks, 0); + status = gfs2_trans_begin(sdp, RES_DINODE + blocks, 0); + if (status) + return ERR_PTR(status); + + folio = iomap_folio_prepare(iter, pos); + if (!folio) + gfs2_trans_end(sdp); + return folio; } static void gfs2_iomap_page_done(struct inode *inode, loff_t pos, diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index f0f167ca1b2e..6b7c1a10b8ec 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -602,7 +602,7 @@ static void iomap_folio_done(struct iomap_iter *iter, loff_t pos, size_t ret, if (page_ops && page_ops->page_done) { page_ops->page_done(iter->inode, pos, ret, folio); - } else if (folio) { + } else { folio_unlock(folio); folio_put(folio); } @@ -635,17 +635,14 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, if (!mapping_large_folio_support(iter->inode->i_mapping)) len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos)); - if (page_ops && page_ops->page_prepare) { - status = page_ops->page_prepare(iter->inode, pos, len); - if (status) - return status; - } - - folio = iomap_folio_prepare(iter, pos); - if (!folio) { - status = (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; - iomap_folio_done(iter, pos, 0, NULL); - return status; + if (page_ops && page_ops->page_prepare) + folio = page_ops->page_prepare(iter, pos, len); + else + folio = iomap_folio_prepare(iter, pos); + if (IS_ERR_OR_NULL(folio)) { + if (!folio) + return (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; + return PTR_ERR(folio); } /* diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 0bf16ef22d81..c74ab8c53b47 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -13,6 +13,7 @@ struct address_space; struct fiemap_extent_info; struct inode; +struct iomap_iter; struct iomap_dio; struct iomap_writepage_ctx; struct iov_iter; @@ -131,12 +132,12 @@ static inline bool iomap_inline_data_valid(const struct iomap *iomap) * associated with them. * * When page_prepare succeeds, page_done will always be called to do any - * cleanup work necessary. In that page_done call, @folio will be NULL if the - * associated folio could not be obtained. When folio is not NULL, page_done - * is responsible for unlocking and putting the folio. + * cleanup work necessary. page_done is responsible for unlocking and putting + * @folio. */ struct iomap_page_ops { - int (*page_prepare)(struct inode *inode, loff_t pos, unsigned len); + struct folio *(*page_prepare)(struct iomap_iter *iter, loff_t pos, + unsigned len); void (*page_done)(struct inode *inode, loff_t pos, unsigned copied, struct folio *folio); From patchwork Fri Dec 16 15:06:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 1716556 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=e81s=4o=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Bs62BlM7; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYXY82V2Jz240X for ; Sat, 17 Dec 2022 02:08:28 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXY823nFz4xFr for ; Sat, 17 Dec 2022 02:08:28 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NYXY820T8z4xGP; Sat, 17 Dec 2022 02:08:28 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Bs62BlM7; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXY81jv7z4xFr for ; Sat, 17 Dec 2022 02:08:28 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231371AbiLPPI1 (ORCPT ); Fri, 16 Dec 2022 10:08:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbiLPPHi (ORCPT ); Fri, 16 Dec 2022 10:07:38 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00EA926F9 for ; Fri, 16 Dec 2022 07:06:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671203208; 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=Hx1hr3zVnpxfjUoh5oVvuyRaT+eEP0rAMA6HZN8X1gk=; b=Bs62BlM7nI6K2JEvNh9DHszbX2rmx6jy06au6vjiycCnZQvR0uV+zyz8uwuWbQwxrYtX32 qo2e7nAzW+GsUxLaRemgI9mCS8jcaaLc7t1hPFSrny2zY9OKGLV+uLE54KMO7DMj/JJyUh j7yGD4sLK/bVdkQXb0hHoJIrZEWPIvM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-323-u8Rdga8HO_uSQuxF1_tiZw-1; Fri, 16 Dec 2022 10:06:46 -0500 X-MC-Unique: u8Rdga8HO_uSQuxF1_tiZw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 370033C10ED8; Fri, 16 Dec 2022 15:06:45 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-182.brq.redhat.com [10.40.192.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 181A314171BE; Fri, 16 Dec 2022 15:06:42 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox Cc: Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC v3 6/7] iomap/xfs: Eliminate the iomap_valid handler Date: Fri, 16 Dec 2022 16:06:25 +0100 Message-Id: <20221216150626.670312-7-agruenba@redhat.com> In-Reply-To: <20221216150626.670312-1-agruenba@redhat.com> References: <20221216150626.670312-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Eliminate the ->iomap_valid() handler by switching to a ->page_prepare() handler and validating the mapping there. Signed-off-by: Andreas Gruenbacher --- fs/iomap/buffered-io.c | 24 ++++-------------------- fs/xfs/xfs_iomap.c | 38 +++++++++++++++++++++++++++----------- include/linux/iomap.h | 17 ----------------- 3 files changed, 31 insertions(+), 48 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 6b7c1a10b8ec..b73ff317da21 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -623,7 +623,7 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, const struct iomap_page_ops *page_ops = iter->iomap.page_ops; const struct iomap *srcmap = iomap_iter_srcmap(iter); struct folio *folio; - int status = 0; + int status; BUG_ON(pos + len > iter->iomap.offset + iter->iomap.length); if (srcmap != &iter->iomap) @@ -642,27 +642,11 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, if (IS_ERR_OR_NULL(folio)) { if (!folio) return (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; - return PTR_ERR(folio); - } - - /* - * Now we have a locked folio, before we do anything with it we need to - * check that the iomap we have cached is not stale. The inode extent - * mapping can change due to concurrent IO in flight (e.g. - * IOMAP_UNWRITTEN state can change and memory reclaim could have - * reclaimed a previously partially written page at this index after IO - * completion before this write reaches this file offset) and hence we - * could do the wrong thing here (zero a page range incorrectly or fail - * to zero) and corrupt data. - */ - if (page_ops && page_ops->iomap_valid) { - bool iomap_valid = page_ops->iomap_valid(iter->inode, - &iter->iomap); - if (!iomap_valid) { + if (folio == ERR_PTR(-ESTALE)) { iter->iomap.flags |= IOMAP_F_STALE; - status = 0; - goto out_unlock; + return 0; } + return PTR_ERR(folio); } if (pos + len > folio_pos(folio) + folio_size(folio)) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 669c1bc5c3a7..2248ce7be2e3 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -62,29 +62,45 @@ xfs_iomap_inode_sequence( return cookie | READ_ONCE(ip->i_df.if_seq); } -/* - * Check that the iomap passed to us is still valid for the given offset and - * length. - */ -static bool -xfs_iomap_valid( - struct inode *inode, - const struct iomap *iomap) +static struct folio * +xfs_page_prepare( + struct iomap_iter *iter, + loff_t pos, + unsigned len) { + struct inode *inode = iter->inode; + struct iomap *iomap = &iter->iomap; struct xfs_inode *ip = XFS_I(inode); + struct folio *folio; + folio = iomap_folio_prepare(iter, pos); + if (!folio) + return NULL; + + /* + * Now we have a locked folio, before we do anything with it we need to + * check that the iomap we have cached is not stale. The inode extent + * mapping can change due to concurrent IO in flight (e.g. + * IOMAP_UNWRITTEN state can change and memory reclaim could have + * reclaimed a previously partially written page at this index after IO + * completion before this write reaches this file offset) and hence we + * could do the wrong thing here (zero a page range incorrectly or fail + * to zero) and corrupt data. + */ if (iomap->validity_cookie != xfs_iomap_inode_sequence(ip, iomap->flags)) { trace_xfs_iomap_invalid(ip, iomap); - return false; + folio_unlock(folio); + folio_put(folio); + return ERR_PTR(-ESTALE); } XFS_ERRORTAG_DELAY(ip->i_mount, XFS_ERRTAG_WRITE_DELAY_MS); - return true; + return folio; } const struct iomap_page_ops xfs_iomap_page_ops = { - .iomap_valid = xfs_iomap_valid, + .page_prepare = xfs_page_prepare, }; int diff --git a/include/linux/iomap.h b/include/linux/iomap.h index c74ab8c53b47..1c8b9a04b0bb 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -140,23 +140,6 @@ struct iomap_page_ops { unsigned len); void (*page_done)(struct inode *inode, loff_t pos, unsigned copied, struct folio *folio); - - /* - * Check that the cached iomap still maps correctly to the filesystem's - * internal extent map. FS internal extent maps can change while iomap - * is iterating a cached iomap, so this hook allows iomap to detect that - * the iomap needs to be refreshed during a long running write - * operation. - * - * The filesystem can store internal state (e.g. a sequence number) in - * iomap->validity_cookie when the iomap is first mapped to be able to - * detect changes between mapping time and whenever .iomap_valid() is - * called. - * - * This is called with the folio over the specified file position held - * locked by the iomap code. - */ - bool (*iomap_valid)(struct inode *inode, const struct iomap *iomap); }; /* From patchwork Fri Dec 16 15:06:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 1716557 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=e81s=4o=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KElqAvBB; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NYXYC07Mmz23ym for ; Sat, 17 Dec 2022 02:08:31 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXYB6mnJz4xFr for ; Sat, 17 Dec 2022 02:08:30 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NYXYB6jsPz4xGP; Sat, 17 Dec 2022 02:08:30 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KElqAvBB; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NYXYB6TNDz4xFr for ; Sat, 17 Dec 2022 02:08:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbiLPPI2 (ORCPT ); Fri, 16 Dec 2022 10:08:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231348AbiLPPHl (ORCPT ); Fri, 16 Dec 2022 10:07:41 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A14FDF50 for ; Fri, 16 Dec 2022 07:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671203211; 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=olYz7KsF9MP6VTKDZWx6VuyJBrZtR85wJBwS21HUX9Q=; b=KElqAvBBDNEBPsc13UzKaMtAvxhdkha8teBV3IFw+sRbKtVNdYc6uQj9lwXv+2x+UgSHjh Ie7mRxR35J9vyVFcrk4ZzbgGq2gC8GHLgRxwOEG7DHvT314zD5atYi9XN7zue33sTKd2ak pD9h48O1SPrDriRMBePWxNdCj3eNO4I= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-595-DYI6maR7Oj-m-9q3CXnxlQ-1; Fri, 16 Dec 2022 10:06:48 -0500 X-MC-Unique: DYI6maR7Oj-m-9q3CXnxlQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7525A1C05155; Fri, 16 Dec 2022 15:06:47 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-182.brq.redhat.com [10.40.192.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8884614171BE; Fri, 16 Dec 2022 15:06:45 +0000 (UTC) From: Andreas Gruenbacher To: Christoph Hellwig , "Darrick J . Wong" , Alexander Viro , Matthew Wilcox Cc: Andreas Gruenbacher , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, cluster-devel@redhat.com Subject: [RFC v3 7/7] iomap: Rename page_ops to folio_ops Date: Fri, 16 Dec 2022 16:06:26 +0100 Message-Id: <20221216150626.670312-8-agruenba@redhat.com> In-Reply-To: <20221216150626.670312-1-agruenba@redhat.com> References: <20221216150626.670312-1-agruenba@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The operations in struct page_ops all operate on folios, so rename struct page_ops to struct folio_ops, ->page_prepare() to ->folio_prepare(), and ->page_done() to ->folio_done(). Signed-off-by: Andreas Gruenbacher --- fs/gfs2/bmap.c | 16 ++++++++-------- fs/iomap/buffered-io.c | 12 ++++++------ fs/xfs/xfs_iomap.c | 8 ++++---- include/linux/iomap.h | 22 +++++++++++----------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index cd5984d3ba50..ba8627ddc2bc 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -960,7 +960,7 @@ static int __gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, } static struct folio * -gfs2_iomap_page_prepare(struct iomap_iter *iter, loff_t pos, unsigned len) +gfs2_iomap_folio_prepare(struct iomap_iter *iter, loff_t pos, unsigned len) { struct inode *inode = iter->inode; unsigned int blockmask = i_blocksize(inode) - 1; @@ -980,8 +980,8 @@ gfs2_iomap_page_prepare(struct iomap_iter *iter, loff_t pos, unsigned len) return folio; } -static void gfs2_iomap_page_done(struct inode *inode, loff_t pos, - unsigned copied, struct folio *folio) +static void gfs2_iomap_folio_done(struct inode *inode, loff_t pos, + unsigned copied, struct folio *folio) { struct gfs2_trans *tr = current->journal_info; struct gfs2_inode *ip = GFS2_I(inode); @@ -1005,9 +1005,9 @@ static void gfs2_iomap_page_done(struct inode *inode, loff_t pos, gfs2_trans_end(sdp); } -static const struct iomap_page_ops gfs2_iomap_page_ops = { - .page_prepare = gfs2_iomap_page_prepare, - .page_done = gfs2_iomap_page_done, +static const struct iomap_folio_ops gfs2_iomap_folio_ops = { + .folio_prepare = gfs2_iomap_folio_prepare, + .folio_done = gfs2_iomap_folio_done, }; static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, @@ -1083,7 +1083,7 @@ static int gfs2_iomap_begin_write(struct inode *inode, loff_t pos, } if (gfs2_is_stuffed(ip) || gfs2_is_jdata(ip)) - iomap->page_ops = &gfs2_iomap_page_ops; + iomap->folio_ops = &gfs2_iomap_folio_ops; return 0; out_trans_end: @@ -1299,7 +1299,7 @@ int gfs2_alloc_extent(struct inode *inode, u64 lblock, u64 *dblock, /* * NOTE: Never call gfs2_block_zero_range with an open transaction because it * uses iomap write to perform its actions, which begin their own transactions - * (iomap_begin, page_prepare, etc.) + * (iomap_begin, folio_prepare, etc.) */ static int gfs2_block_zero_range(struct inode *inode, loff_t from, unsigned int length) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index b73ff317da21..da4570d9d1ff 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -598,10 +598,10 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos, static void iomap_folio_done(struct iomap_iter *iter, loff_t pos, size_t ret, struct folio *folio) { - const struct iomap_page_ops *page_ops = iter->iomap.page_ops; + const struct iomap_folio_ops *folio_ops = iter->iomap.folio_ops; - if (page_ops && page_ops->page_done) { - page_ops->page_done(iter->inode, pos, ret, folio); + if (folio_ops && folio_ops->folio_done) { + folio_ops->folio_done(iter->inode, pos, ret, folio); } else { folio_unlock(folio); folio_put(folio); @@ -620,7 +620,7 @@ static int iomap_write_begin_inline(const struct iomap_iter *iter, static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, size_t len, struct folio **foliop) { - const struct iomap_page_ops *page_ops = iter->iomap.page_ops; + const struct iomap_folio_ops *folio_ops = iter->iomap.folio_ops; const struct iomap *srcmap = iomap_iter_srcmap(iter); struct folio *folio; int status; @@ -635,8 +635,8 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, if (!mapping_large_folio_support(iter->inode->i_mapping)) len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos)); - if (page_ops && page_ops->page_prepare) - folio = page_ops->page_prepare(iter, pos, len); + if (folio_ops && folio_ops->folio_prepare) + folio = folio_ops->folio_prepare(iter, pos, len); else folio = iomap_folio_prepare(iter, pos); if (IS_ERR_OR_NULL(folio)) { diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 2248ce7be2e3..79b3f2d4c8ab 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -63,7 +63,7 @@ xfs_iomap_inode_sequence( } static struct folio * -xfs_page_prepare( +xfs_folio_prepare( struct iomap_iter *iter, loff_t pos, unsigned len) @@ -99,8 +99,8 @@ xfs_page_prepare( return folio; } -const struct iomap_page_ops xfs_iomap_page_ops = { - .page_prepare = xfs_page_prepare, +const struct iomap_folio_ops xfs_iomap_folio_ops = { + .folio_prepare = xfs_folio_prepare, }; int @@ -149,7 +149,7 @@ xfs_bmbt_to_iomap( iomap->flags |= IOMAP_F_DIRTY; iomap->validity_cookie = sequence_cookie; - iomap->page_ops = &xfs_iomap_page_ops; + iomap->folio_ops = &xfs_iomap_folio_ops; return 0; } diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 1c8b9a04b0bb..85d360881851 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -86,7 +86,7 @@ struct vm_fault; */ #define IOMAP_NULL_ADDR -1ULL /* addr is not valid */ -struct iomap_page_ops; +struct iomap_folio_ops; struct iomap { u64 addr; /* disk offset of mapping, bytes */ @@ -98,7 +98,7 @@ struct iomap { struct dax_device *dax_dev; /* dax_dev for dax operations */ void *inline_data; void *private; /* filesystem private */ - const struct iomap_page_ops *page_ops; + const struct iomap_folio_ops *folio_ops; u64 validity_cookie; /* used with .iomap_valid() */ }; @@ -126,19 +126,19 @@ static inline bool iomap_inline_data_valid(const struct iomap *iomap) } /* - * When a filesystem sets page_ops in an iomap mapping it returns, page_prepare - * and page_done will be called for each page written to. This only applies to - * buffered writes as unbuffered writes will not typically have pages - * associated with them. + * When a filesystem sets folio_ops in an iomap mapping it returns, + * folio_prepare and folio_done will be called for each page written to. This + * only applies to buffered writes as unbuffered writes will not typically have + * pages associated with them. * - * When page_prepare succeeds, page_done will always be called to do any - * cleanup work necessary. page_done is responsible for unlocking and putting + * When folio_prepare succeeds, folio_done will always be called to do any + * cleanup work necessary. folio_done is responsible for unlocking and putting * @folio. */ -struct iomap_page_ops { - struct folio *(*page_prepare)(struct iomap_iter *iter, loff_t pos, +struct iomap_folio_ops { + struct folio *(*folio_prepare)(struct iomap_iter *iter, loff_t pos, unsigned len); - void (*page_done)(struct inode *inode, loff_t pos, unsigned copied, + void (*folio_done)(struct inode *inode, loff_t pos, unsigned copied, struct folio *folio); };