Received: by 2002:a05:6a10:5594:0:0:0:0 with SMTP id ee20csp399506pxb; Mon, 25 Apr 2022 12:17:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyaYxMZQB5+kJrip6rvorzS86SrC7MVTjQnf+INFaNjK0pTutriUwOtjaMlPllXpgM7ObM X-Received: by 2002:a62:1e03:0:b0:505:64c1:3e19 with SMTP id e3-20020a621e03000000b0050564c13e19mr20702190pfe.32.1650914232939; Mon, 25 Apr 2022 12:17:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650914232; cv=none; d=google.com; s=arc-20160816; b=msv7UTGezUvkWOrARjMAuWhRw3Dnq1kMr+CCSujB5qLyai4QsDUlHtrtvl8MbHtVh5 FE13yBgrx/ifdayIzVWIMUqy6tI1cjNwu3GofMcQyUdJnUfM2kqBg5r0N9whCRJhwaRu 9mOBg4X5/HOQwa0JhINWPytytK6ay5GUmW1ZPkCnzPaMm06PEuk+0K0Wua1Jo2Jbf8GO y8kpzO7bBofKw/0u0aQxqneXhImcTIqqkev+ibn2LNQ35nGcrU9uTxckp1a8kUvc+wgN GR/GeWc5rnUxGIjqm/nemFLyjdH2mHtiU1S7T+jhmP2IGrSv3WeRL0ZEOPj616qxiBad kVIA== 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; bh=FDwrqTprEQpVUfoUnc+7rkD7Lo57Xdz6opAEU+giO78=; b=uex+rFrT2/7jXHMD+kns7vpiSDcu/hILVJpKZdwjl2Fb+jnhEuC+j6Ax8i06SDt4pI EBV6tkzb5gDONbCh4xTsO+Huf9HGw3LpAEMPwoUesGIWmDs0KqNzZ90+6nXNl0ZRqvo5 GutnrtO4JhzgPRIdH6OpU33hTEdfjYTPy0NlcvIU4XGrBsIA5r7C/omfKCOjg0baCmoG TBkuDQLu6ykfN8R074NlJIjn8Qe7MvHhF6g4WNFvoLZeyw9LjE5fU0YmmSjxlMLfG2X6 jHtVrblqAlSB1KtZKvOwd6Lr3ikgsXI/JCRA00Mf076ye071X7Jc3AZTirOhwKBf/QuA rHHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y185-20020a638ac2000000b003ab23fbadbdsi4744089pgd.33.2022.04.25.12.16.55; Mon, 25 Apr 2022 12:17:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241778AbiDYM0z (ORCPT + 99 others); Mon, 25 Apr 2022 08:26:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237563AbiDYMZV (ORCPT ); Mon, 25 Apr 2022 08:25:21 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEEB260D92; Mon, 25 Apr 2022 05:22:17 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0VBDrnYz_1650889331; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VBDrnYz_1650889331) by smtp.aliyun-inc.com(127.0.0.1); Mon, 25 Apr 2022 20:22:12 +0800 From: Jeffle Xu To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: torvalds@linux-foundation.org, gregkh@linuxfoundation.org, willy@infradead.org, linux-fsdevel@vger.kernel.org, joseph.qi@linux.alibaba.com, bo.liu@linux.alibaba.com, tao.peng@linux.alibaba.com, gerry@linux.alibaba.com, eguan@linux.alibaba.com, linux-kernel@vger.kernel.org, luodaowen.backend@bytedance.com, tianzichen@kuaishou.com, fannaihao@baidu.com, zhangjiachen.jaycee@bytedance.com, zhujia.zj@bytedance.com Subject: [PATCH v10 17/21] erofs: implement fscache-based metadata read Date: Mon, 25 Apr 2022 20:21:39 +0800 Message-Id: <20220425122143.56815-18-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220425122143.56815-1-jefflexu@linux.alibaba.com> References: <20220425122143.56815-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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-kernel@vger.kernel.org Implement the data plane of reading metadata from primary data blob over fscache. Signed-off-by: Jeffle Xu --- fs/erofs/data.c | 19 +++++++++++++++---- fs/erofs/fscache.c | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 14b64d960541..bb9c1fd48c19 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -6,6 +6,7 @@ */ #include "internal.h" #include +#include #include #include @@ -35,14 +36,20 @@ void *erofs_bread(struct erofs_buf *buf, struct inode *inode, erofs_off_t offset = blknr_to_addr(blkaddr); pgoff_t index = offset >> PAGE_SHIFT; struct page *page = buf->page; + struct folio *folio; + unsigned int nofs_flag; if (!page || page->index != index) { erofs_put_metabuf(buf); - page = read_cache_page_gfp(mapping, index, - mapping_gfp_constraint(mapping, ~__GFP_FS)); - if (IS_ERR(page)) - return page; + + nofs_flag = memalloc_nofs_save(); + folio = read_cache_folio(mapping, index, NULL, NULL); + memalloc_nofs_restore(nofs_flag); + if (IS_ERR(folio)) + return folio; + /* should already be PageUptodate, no need to lock page */ + page = folio_file_page(folio, index); buf->page = page; } if (buf->kmap_type == EROFS_NO_KMAP) { @@ -63,6 +70,10 @@ void *erofs_bread(struct erofs_buf *buf, struct inode *inode, void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, erofs_blk_t blkaddr, enum erofs_kmap_type type) { + if (erofs_is_fscache_mode(sb)) + return erofs_bread(buf, EROFS_SB(sb)->s_fscache->inode, + blkaddr, type); + return erofs_bread(buf, sb->s_bdev->bd_inode, blkaddr, type); } diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index ac02af8cce3e..23d7e862eed8 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -59,7 +59,32 @@ static int erofs_fscache_read_folios(struct fscache_cookie *cookie, return ret; } +static int erofs_fscache_meta_readpage(struct file *data, struct page *page) +{ + int ret; + struct folio *folio = page_folio(page); + struct super_block *sb = folio_mapping(folio)->host->i_sb; + struct erofs_map_dev mdev = { + .m_deviceid = 0, + .m_pa = folio_pos(folio), + }; + + ret = erofs_map_dev(sb, &mdev); + if (ret) + goto out; + + ret = erofs_fscache_read_folios(mdev.m_fscache->cookie, + folio_mapping(folio), folio_pos(folio), + folio_size(folio), mdev.m_pa); + if (!ret) + folio_mark_uptodate(folio); +out: + folio_unlock(folio); + return ret; +} + static const struct address_space_operations erofs_fscache_meta_aops = { + .readpage = erofs_fscache_meta_readpage, }; int erofs_fscache_register_cookie(struct super_block *sb, -- 2.27.0