Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp942924rwb; Thu, 1 Dec 2022 10:12:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf50S9XHmMsQdRVlKTEgnTihJAug2fKG56cG6e31Htx7l8ImOZAxY/NBLL+V4l09I+BiZGBE X-Received: by 2002:a17:906:27d8:b0:7bd:6264:a022 with SMTP id k24-20020a17090627d800b007bd6264a022mr24588466ejc.693.1669918374470; Thu, 01 Dec 2022 10:12:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669918374; cv=none; d=google.com; s=arc-20160816; b=rzgXinmQ6FrnMt6tBFa2HuRIxAqvHQ9nMg+Wv8D4t7l7oFcjFUwopohLqiyYHeNBfn I40fcUeiviRzAyTgYychBAN0gNQiBkJ+nRu7I1ax9LStFDPrPo5LFezln4mcUf+bOU6n 0kcwGDbxh0jkT7DYBNo8PfXOXaIBrJXHxdYKTTr1yTmySscQjzdgP5C5KwH1FYQkWLEm hMLW6b0FMU7UH3kN+Z3aUzONZpcugPAVHjqTDTuaQuQSWq5TLsRpoQOAtXGob1MCnVOx 1Ib5tBoxtHrzJGUFkTdBgv9KohBspXY+5v/sXXlGVpGFMnMDA8Dc0GoGWggawz+AY/Y9 io1A== 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=L4wpGn5ZS2+dyBPI2xOTo6pp4/bLux152wPskgwYzHs=; b=Fu8/hA7AoDZMwfhbaRFGEV5Gaoi4bZX55voCW/N4TmBFvThyug+viP0lp/jQefEFB5 rwOi2l3FIp+LMYvE1OYdekIjMglFQqWKP2/DhdTVsN0QxjKIZZBmjeRBKTmpJNcKtTGK f2SrAhgB27A5lU8tois2EtV/3NO9+oNdhcAZJoxZQqtAza+Ab6cGF3dfZzEgfPQOl54S 2XLFIvPzsX03G60ptIqoQDJhXNGkV+0Q9TfVaHu34PLnwXFv1EYT85DRi1dwNRW5ovG9 8koA734RykG1Ei9nLhr8GBs3psuplcOphEyrDHop/byfLQOeJP7TLZ8EtPVPUpMm18fB ruUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TG6135Wx; 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 sg39-20020a170907a42700b007ae2dfe8b76si4837050ejc.76.2022.12.01.10.12.26; Thu, 01 Dec 2022 10:12:54 -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=TG6135Wx; 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 S229943AbiLASLI (ORCPT + 99 others); Thu, 1 Dec 2022 13:11:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229965AbiLASLH (ORCPT ); Thu, 1 Dec 2022 13:11:07 -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 E8386B7DD7 for ; Thu, 1 Dec 2022 10:10:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669918210; 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=L4wpGn5ZS2+dyBPI2xOTo6pp4/bLux152wPskgwYzHs=; b=TG6135Wxfr/vWyrc1YFqkxUwX6JRHaxJySqadhac/O09I1TRZ1U5eP1Y9YuQ+DauflngYf gVBlpguT9nY65XO9dpYufeC4Qh9ZrzswuZVv/41E0TvCKn5vS3kUARfeA5AGICsZXzEUWi vZdfsvueVEFNuqfm8h1PUl4m9apqAHk= 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-524-lPeyQ7tHNp6F5-oZuvgMwA-1; Thu, 01 Dec 2022 13:10:09 -0500 X-MC-Unique: lPeyQ7tHNp6F5-oZuvgMwA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9845D1010431; Thu, 1 Dec 2022 18:10:05 +0000 (UTC) Received: from pasta.redhat.com (ovpn-192-141.brq.redhat.com [10.40.192.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id A27AFC15BB4; Thu, 1 Dec 2022 18:10:03 +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 v2 2/3] iomap: Turn iomap_page_ops into iomap_folio_ops Date: Thu, 1 Dec 2022 19:09:56 +0100 Message-Id: <20221201180957.1268079-3-agruenba@redhat.com> In-Reply-To: <20221201160619.1247788-1-agruenba@redhat.com> References: <20221201160619.1247788-1-agruenba@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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 Rename the iomap page_ops into folio_ops, and rename the operations accordingly. Move looking up the folio into ->folio_prepare(), and unlocking and putting the folio into ->folio_done(). We'll need the added flexibility in gfs2. Signed-off-by: Andreas Gruenbacher --- fs/gfs2/bmap.c | 40 +++++++++++++++++++++++++---------- fs/iomap/buffered-io.c | 48 +++++++++++++++++++++++------------------- include/linux/iomap.h | 24 ++++++++++----------- 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 3bdb2c668a71..18dcaa95408e 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -959,36 +959,54 @@ 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_folio_prepare(struct inode *inode, unsigned fgp, + loff_t pos, unsigned len) { unsigned int blockmask = i_blocksize(inode) - 1; struct gfs2_sbd *sdp = GFS2_SB(inode); unsigned int blocks; + struct folio *folio; + int ret; blocks = ((pos & blockmask) + len + blockmask) >> inode->i_blkbits; - return gfs2_trans_begin(sdp, RES_DINODE + blocks, 0); + ret = gfs2_trans_begin(sdp, RES_DINODE + blocks, 0); + if (ret) + return ERR_PTR(ret); + + folio = __filemap_get_folio(inode->i_mapping, pos >> PAGE_SHIFT, fgp, + mapping_gfp_mask(inode->i_mapping)); + if (!folio) + gfs2_trans_end(sdp); + + return folio; } -static void gfs2_iomap_page_done(struct inode *inode, loff_t pos, - unsigned copied, struct page *page) +static void +gfs2_iomap_folio_done(struct inode *inode, struct folio *folio, + loff_t pos, unsigned copied) { 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); + folio_unlock(folio); + + if (!gfs2_is_stuffed(ip)) + gfs2_page_add_databufs(ip, &folio->page, offset_in_page(pos), + copied); if (tr->tr_num_buf_new) __mark_inode_dirty(inode, I_DIRTY_DATASYNC); gfs2_trans_end(sdp); + + folio_put(folio); } -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, @@ -1064,7 +1082,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: diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 96e643de32a0..9f1656f3df17 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -587,7 +587,7 @@ static int iomap_write_begin_inline(const struct iomap_iter *iter, static int iomap_write_begin(const 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; unsigned fgp = FGP_LOCK | FGP_WRITE | FGP_CREAT | FGP_STABLE | FGP_NOFS; @@ -606,17 +606,18 @@ static int iomap_write_begin(const 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; + if (folio_ops && folio_ops->folio_prepare) { + folio = folio_ops->folio_prepare(iter->inode, fgp, pos, len); + } else { + folio = __filemap_get_folio(iter->inode->i_mapping, + pos >> PAGE_SHIFT, fgp, + mapping_gfp_mask(iter->inode->i_mapping)); } - - 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; - goto out_no_page; + if (IS_ERR_OR_NULL(folio)) { + status = PTR_ERR(folio); + if (folio == NULL) + status = (iter->flags & IOMAP_NOWAIT) ? -EAGAIN : -ENOMEM; + return status; } if (pos + len > folio_pos(folio) + folio_size(folio)) len = folio_pos(folio) + folio_size(folio) - pos; @@ -635,13 +636,13 @@ static int iomap_write_begin(const struct iomap_iter *iter, loff_t pos, return 0; out_unlock: - folio_unlock(folio); - folio_put(folio); + if (folio_ops && folio_ops->folio_done) { + folio_ops->folio_done(iter->inode, folio, pos, 0); + } else { + folio_unlock(folio); + folio_put(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; } @@ -691,7 +692,7 @@ 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_folio_ops *folio_ops = iter->iomap.folio_ops; const struct iomap *srcmap = iomap_iter_srcmap(iter); loff_t old_size = iter->inode->i_size; size_t ret; @@ -715,10 +716,13 @@ 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); + if (folio_ops && folio_ops->folio_done) { + folio_ops->folio_done(iter->inode, folio, pos, ret); + } else { + folio_unlock(folio); + folio_put(folio); + } + if (ret < len) iomap_write_failed(iter->inode, pos + ret, len - ret); return ret; diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 238a03087e17..9d3a6ad222cc 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -76,7 +76,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 */ @@ -88,7 +88,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; }; static inline sector_t iomap_sector(const struct iomap *iomap, loff_t pos) @@ -115,19 +115,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 + * When a filesystem sets folio_ops in an iomap mapping it returns, folio_prepare + * and folio_done will be called for each folio written to. This only applies to + * buffered writes as unbuffered writes will not typically have folios * 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. + * When folio_prepare succeeds, folio_done will always be called to do any + * cleanup work necessary. */ -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 iomap_folio_ops { + struct folio *(*folio_prepare)(struct inode *inode, unsigned fgp, + loff_t pos, unsigned len); + void (*folio_done)(struct inode *inode, struct folio *folio, + loff_t pos, unsigned copied); }; /* -- 2.38.1