Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5268241rwl; Sun, 8 Jan 2023 11:43:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXtzWER/Huf3FjSrN7pCfk6kZGOVk2umDaIyqFvzobKJGyrf5N95cPKXPHq9cd0tGeN5SLlr X-Received: by 2002:a05:6a21:6d90:b0:b0:3318:ab59 with SMTP id wl16-20020a056a216d9000b000b03318ab59mr95794468pzb.14.1673206985517; Sun, 08 Jan 2023 11:43:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673206985; cv=none; d=google.com; s=arc-20160816; b=hzcvYhAhHJzhfW5V4NGlVAGLc6ONKjq5VirYB/xkwpqutlOyR9Ks3bbbjkV+r4msI9 f8Bc48VSqf03NxeinEYpipIGkKjOuXOOO19MihCWz7FTsXyDFR71k+ezrOqHw1v8jmgR 1XNumj/tSfQxqXKP6ccm4wTJLWljFoelbdTApJq+dg+8gK4KyfxwEKpddgv4VRs8CcOW 84evAeGSfRC7qb8Rc8wSaZx05XpE/cMJ+QQsZwGUA5b/Kf9q8pEX8DicTgEjZDhen8Kk u/nGlLS/TarKuv9ToUYWekR598xDkqNVGYLFOxhHy1sLOuKXR3yFr2vLIZOTsBjJ6OiJ tVwQ== 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=VkAO5mFJ218kYx2y/3xUiDVAsyN3pxE7gJvNvvmhAxQ=; b=Jh9KZtMUxviGfmiRUlQzfgpVDzWkA7pDMDML0epqXRjH5H1PKearCOz4YKDvk/rSbl ZrdFJ1Oc5LM8mf3jmzJyelimK75Wg0O80083+3FLU4O4J6bQfUGoBUM4F8qKOWkhMB5J yf+V5J480BtS3T7HBnAQYnrV6x3k+GwALhLvbvqKpGdJ3NVf5/f2nm8DbXWJqi2QMYvo SzDfm7vnDvzYl72lgdZIu/eARwVziLHx3/swi+xpNXG+HPvZq6fay+pndLyDBXXTxKR7 AlUjmKV9tkiJCUWTJ4Aak7mg5Elbalxhrmj68V5K7gu/N5rjntiHqpX6tgTdiRIi9n9q sNOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FFMpkpo8; 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 p19-20020a63c153000000b004a6e4bf3a2bsi7811584pgi.710.2023.01.08.11.42.50; Sun, 08 Jan 2023 11:43:05 -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=FFMpkpo8; 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 S233546AbjAHTmR (ORCPT + 99 others); Sun, 8 Jan 2023 14:42:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233243AbjAHTmP (ORCPT ); Sun, 8 Jan 2023 14:42:15 -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 64F56B871 for ; Sun, 8 Jan 2023 11:40:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673206854; 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=VkAO5mFJ218kYx2y/3xUiDVAsyN3pxE7gJvNvvmhAxQ=; b=FFMpkpo8q34uzMqK1n2YmQBRIWD+KwgMq/FMV5DUx5+CEkwYDZV0GTGBLI7aPa0aXZjjOT 4kD7ZpkuhwshHG4E7WDJVmuQIfXniyamrG/gLoq9KCk7OyvHRfTIxSM9iLS15zrDsuQ/Xu cgTXUchnY+x0wJLgD47bllwKxrQSD2g= 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-571-2-mWDVBOPxqAKRbtiPUlBA-1; Sun, 08 Jan 2023 14:40:50 -0500 X-MC-Unique: 2-mWDVBOPxqAKRbtiPUlBA-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 F0DE885A588; Sun, 8 Jan 2023 19:40:49 +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 7D9F9492B06; Sun, 8 Jan 2023 19:40:47 +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 04/10] iomap: Add iomap_get_folio helper Date: Sun, 8 Jan 2023 20:40:28 +0100 Message-Id: <20230108194034.1444764-5-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_get_folio() helper that gets a folio reference based on an iomap iterator and an offset into the address space. Use it in iomap_write_begin(). Signed-off-by: Andreas Gruenbacher Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 39 ++++++++++++++++++++++++++++++--------- include/linux/iomap.h | 1 + 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index d4b444e44861..de4a8e5f721a 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -457,6 +457,33 @@ bool iomap_is_partially_uptodate(struct folio *folio, size_t from, size_t count) } EXPORT_SYMBOL_GPL(iomap_is_partially_uptodate); +/** + * iomap_get_folio - get a folio reference for writing + * @iter: iteration structure + * @pos: start offset of write + * + * Returns a locked reference to the folio at @pos, or an error pointer if the + * folio could not be obtained. + */ +struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos) +{ + unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS; + struct folio *folio; + + if (iter->flags & IOMAP_NOWAIT) + fgp |= FGP_NOWAIT; + + folio = __filemap_get_folio(iter->inode->i_mapping, pos >> PAGE_SHIFT, + fgp, mapping_gfp_mask(iter->inode->i_mapping)); + if (folio) + return folio; + + if (iter->flags & IOMAP_NOWAIT) + return ERR_PTR(-EAGAIN); + return ERR_PTR(-ENOMEM); +} +EXPORT_SYMBOL_GPL(iomap_get_folio); + bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags) { trace_iomap_release_folio(folio->mapping->host, folio_pos(folio), @@ -603,12 +630,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,12 +648,10 @@ 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)); - if (!folio) { - status = (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; + folio = iomap_get_folio(iter, pos); + if (IS_ERR(folio)) { __iomap_put_folio(iter, pos, 0, NULL); - return status; + return PTR_ERR(folio); } /* diff --git a/include/linux/iomap.h b/include/linux/iomap.h index ecf815b34d51..188d14e786a4 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_get_folio(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, -- 2.38.1