Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4864612iob; Mon, 9 May 2022 03:31:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx68mqhdrjzw6MQUKbBtFadYvxfy0dCNCzGWiWgRwJmn5U978sZvUkx02dyFsjt5I6ZOzJH X-Received: by 2002:a65:6b8e:0:b0:39d:6761:300f with SMTP id d14-20020a656b8e000000b0039d6761300fmr13022627pgw.42.1652092319203; Mon, 09 May 2022 03:31:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652092319; cv=none; d=google.com; s=arc-20160816; b=TVUl8gCalY4LUWjlNBCEnck5gl0Mkwx0UJn8wosVh+nqyHtaB+FbB6t8J//eJC2orL 86lYcxGJAY7wxzFVLXt6mgjvl0cMzVTNPZmPmgz84BBcstXoHIFEEbsbOvFniIEHA9sR GgULsgMoae48rVZ+4br9D8fy3j8T53FiWUsUZATxLWKBxoMCX9lzZR7H8mfc83VnyH5e Orck4vghZlewdhayxyUok6Ju1M+vDg0wpcnpYzagWyuAQtqgmIMh7Yq86+oHAS06TglI /xhHN/+ZpsjbLq0ud04G8xSn88egQjIFSJa20ffKZz3CUgY/FBf59VjVXNKYnmrxtqtB J/6A== 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=2WKz1BSyAE+kpmmXc92a6D5bk9wA8NWEVPukSLx7yJs=; b=C5NWi+wtNn3p+9RG0keWbIoc2DnaHnTpxGYi1SO7QmedKhqrIM7bo4L4OE6ToD6vAM 4LCFemUUcu1FC/7RxHEeF9pWjDLihGMtZX5fMetUIrmIryOr5Y51h72eRYGsqnSMK0Sa C1wB5BNvNmCcphVPEI/xMhHWQ36KrkqqYB6elAZuBG9iOv3FwscX0K3sowbnJXxSCYGf H/VXGkWJ3G99bfLgoJE+2T2OKf3mlszI37gLUatmjNrifO1aKj/JYFrz3Cc0SzzJQfgz 8HeIvHCfGekKlNYpms4Z9lclM8n0Ko3LvMfMewsDe1o4P93KYjtaVmzhgENSd9mzprRL WbGA== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i4-20020a17090a2a0400b001c664d0720bsi18882430pjd.69.2022.05.09.03.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 03:31:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 109C41F9A2C; Mon, 9 May 2022 03:02:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236660AbiEIHx2 (ORCPT + 99 others); Mon, 9 May 2022 03:53:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235808AbiEIHpB (ORCPT ); Mon, 9 May 2022 03:45:01 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC239165BC; Mon, 9 May 2022 00:41:05 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0VCfaIpJ_1652082055; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VCfaIpJ_1652082055) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 May 2022 15:40:56 +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, yinxin.x@bytedance.com, zhangjiachen.jaycee@bytedance.com, zhujia.zj@bytedance.com Subject: [PATCH v11 17/22] erofs: implement fscache-based metadata read Date: Mon, 9 May 2022 15:40:23 +0800 Message-Id: <20220509074028.74954-18-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220509074028.74954-1-jefflexu@linux.alibaba.com> References: <20220509074028.74954-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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 Reviewed-by: Gao Xiang --- 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