Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5268451rwl; Sun, 8 Jan 2023 11:43:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXvmZw2t5ugzJ4lJFICGWYhOAiqQTf+lyiyK8HvD4AQDjklO7IFb3Xxf4pBcs3AuwZvlf9bZ X-Received: by 2002:a05:6a21:1509:b0:a7:c9a:73c with SMTP id nq9-20020a056a21150900b000a70c9a073cmr82119341pzb.2.1673207000971; Sun, 08 Jan 2023 11:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673207000; cv=none; d=google.com; s=arc-20160816; b=sXJ7fpBymfDxHeKt1qmt8FOg4IooT8lYMtvhGkH61ChfwSe/f02nizkj4yfAJ8Z6X+ M7EX1RmgEAvb3HFRqN/LPNoxJRZc4pmvNIocgeDlsQs6mbBbw7auYRQh+TcPfDgCX+In RvBNbgvlrByKtyn9nQ8Xm0Ku5qrshgPirnPc+iaBPIHLzj+OeH9XOHi3/zTcDMEwIJ/7 zZRwPtwWHTBxPonxvTfNZPn8JFUWc/nHMyXHrEMOsTCEHxllRjdotx6hbBiQkC+21loA 8p8GflvL3GP0nH1arBAFDnHPKfMeJfUwuVVa3YTXFcaSyWNS6aGuoiidHlMpsAPxB2gt Qgjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jXcUsgijX8a01pme6reNRRyWGuiUaJCZZfbmlAHU5B8=; b=WWNN2zUvKSYXNzxTiHPGicufwGjtRJPAIh48j0K8EOL72B8v0NjIPgR9qk/R1DmM+F vblutQiUqRbxHPDPRcD4+NHxRYCYWbnDZ4qOSRkB15CzGtudSKHOK2rLOJ8Py3xWQA3V kD/qJ8QLVOhZOqkaMKe5I03CZJP8J3FV2hejvNMiUaEAn78tTfT86l0mcSvOZWFzX74n s1ydyXuscilqiHG5UYgoX8cAr2aY8oncfiszvfy9NTU2rYL5Zl3bFGq8a02gm2xMBuCj x4e9R3KFKVrF01jioMLL28nmm9u+hSBhXxA2yGCzW6h/aR5U9sqlsu9mYK5w9ukGgEx1 7/Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d9lMM+xT; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i21-20020a63e455000000b00476f5ad5027si8005117pgk.114.2023.01.08.11.43.08; Sun, 08 Jan 2023 11:43:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d9lMM+xT; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233790AbjAHTmZ (ORCPT + 99 others); Sun, 8 Jan 2023 14:42:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233644AbjAHTmS (ORCPT ); Sun, 8 Jan 2023 14:42:18 -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 D23C6B870 for ; Sun, 8 Jan 2023 11:40:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673206846; 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=jXcUsgijX8a01pme6reNRRyWGuiUaJCZZfbmlAHU5B8=; b=d9lMM+xTd/jaI7cavib77RWNiENBb1fhHoHqEqyA9uGF0lfumEcQH98QpkONe+ghnA90TZ slhpswxJP5+yRYaI4HZWRHXXUxN+l3xHW6bc550HtdfZje4zOQJN2qnFD5JoGFpMmPEIGW gXSTJgLFbNuefP+T1wuXYojv3UgXyFE= 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-397-1euvXKVAM-KpgeJYKX_dPw-1; Sun, 08 Jan 2023 14:40:41 -0500 X-MC-Unique: 1euvXKVAM-KpgeJYKX_dPw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BCEFD3806077; Sun, 8 Jan 2023 19:40:40 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-3.brq.redhat.com [10.40.192.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62B35492B06; Sun, 8 Jan 2023 19:40:38 +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, Christoph Hellwig Subject: [RFC v6 01/10] iomap: Add __iomap_put_folio helper Date: Sun, 8 Jan 2023 20:40:25 +0100 Message-Id: <20230108194034.1444764-2-agruenba@redhat.com> In-Reply-To: <20230108194034.1444764-1-agruenba@redhat.com> References: <20230108194034.1444764-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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 Add an __iomap_put_folio() helper to encapsulate unlocking the folio, calling ->page_done(), and putting the folio. Use the new helper in iomap_write_begin() and iomap_write_end(). This effectively doesn't change the way the code works, but prepares for successive improvements. Signed-off-by: Andreas Gruenbacher Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 356193e44cf0..c045689b6af8 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_put_folio(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_put_folio(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_put_folio(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; @@ -735,14 +744,10 @@ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, i_size_write(iter->inode, pos + ret); iter->iomap.flags |= IOMAP_F_SIZE_CHANGED; } - folio_unlock(folio); + __iomap_put_folio(iter, pos, ret, 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); - if (ret < len) iomap_write_failed(iter->inode, pos + ret, len - ret); return ret; -- 2.38.1