Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp325808pxb; Thu, 31 Mar 2022 06:25:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYKhM5xt03j7bII+QMJnJ2ljAiinP7mH0j97buvD0bSglV9aCR2H03OwZrmJzjaxo/PSg8 X-Received: by 2002:a17:90b:1184:b0:1c7:2d83:6e03 with SMTP id gk4-20020a17090b118400b001c72d836e03mr6053630pjb.221.1648733101677; Thu, 31 Mar 2022 06:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648733101; cv=none; d=google.com; s=arc-20160816; b=cT5gghri7rXLMrl8yShnV1tN6N8Fhn0V84bnfBC2nM8y6s4tS1+Uk38mrVSm0vx/rU 6qX/3Z2UYYc2OhKpRJPmSnUUeah+dlK1rBpWrwUZ9+M1R6lvZwlbeR83I8soDuJHhj2W r34H1BDjhOVaww0+gaxDMo3yBD2c5Ml7K55unOoKpVjvOXa9RUOTT+LBmm8L2LmFomFb 0mbyp0T9FnXUmnErCVUplCPlNZFH0+a5dBd9/aEDhNFIvAQ84XmHkJmQKkhjaUkHSyjF wyVW5EVMWbuaURuHk9ZHUEvrcv91+QV4x5mqu6LODFk3MMmvH/Kkg21MX/gEjCkEJ3jF W5fA== 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=0ouZQL9JoqXJDxNR/NGvEUimcZvuZoahktojv43cAnk=; b=FlyYz9cFW04cfq3X620IfOsvdn/nV+hV3IAC+RVzoWNKWk9y3QU+/eCAvQAW4VC1S4 IOlEsxS1JkJzfdAeQEv4Y6BNZVGDq+PEQCXn10g2fi7s41lX/MZMbY0PeGGw0VZzqzn1 X1MVMhBSCqHogVOIBRCCNBaoCq9QdGm0GSYjb3rPg7x4S1lXIzpl7bLq4UN3r59cwmMm u5vipHw3uqcVCsXjrT59OY1NtXCJoQUJqaSRdFl69wUXSAwMs/4w08YUBMrec7Px0V7n qFNYXoBRkjEj9zk/ZPFb4ZKbf8QBNUZrfiPPuX+qKP0B+9cq1iykuaBGj+kkZyLSiG/5 30TA== 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 m4-20020a056a00080400b004fa3a8dffc5si19606236pfk.124.2022.03.31.06.24.46; Thu, 31 Mar 2022 06:25:01 -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 S235457AbiCaMBZ (ORCPT + 99 others); Thu, 31 Mar 2022 08:01:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235571AbiCaMAn (ORCPT ); Thu, 31 Mar 2022 08:00:43 -0400 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 437DBDFCB; Thu, 31 Mar 2022 04:58:23 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R431e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0V8iijs4_1648727898; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V8iijs4_1648727898) by smtp.aliyun-inc.com(127.0.0.1); Thu, 31 Mar 2022 19:58:19 +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 Subject: [PATCH v7 16/19] erofs: implement fscache-based data read for non-inline layout Date: Thu, 31 Mar 2022 19:57:50 +0800 Message-Id: <20220331115753.89431-17-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220331115753.89431-1-jefflexu@linux.alibaba.com> References: <20220331115753.89431-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,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, 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 data from data blobs over fscache for non-inline layout. Signed-off-by: Jeffle Xu --- fs/erofs/fscache.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 5 +++++ fs/erofs/internal.h | 2 ++ 3 files changed, 59 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 158cc273f8fb..65de1c754e80 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -60,10 +60,62 @@ static int erofs_fscache_meta_readpage(struct file *data, struct page *page) return ret; } +static int erofs_fscache_readpage(struct file *file, struct page *page) +{ + struct folio *folio = page_folio(page); + struct inode *inode = folio_file_mapping(folio)->host; + struct super_block *sb = inode->i_sb; + struct erofs_map_blocks map; + struct erofs_map_dev mdev; + erofs_off_t pos; + loff_t pstart; + int ret = 0; + + DBG_BUGON(folio_size(folio) != EROFS_BLKSIZ); + + pos = folio_pos(folio); + map.m_la = pos; + + ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); + if (ret) + goto out_unlock; + + if (!(map.m_flags & EROFS_MAP_MAPPED)) { + folio_zero_range(folio, 0, folio_size(folio)); + goto out_uptodate; + } + + /* no-inline readpage */ + mdev = (struct erofs_map_dev) { + .m_deviceid = map.m_deviceid, + .m_pa = map.m_pa, + }; + + ret = erofs_map_dev(sb, &mdev); + if (ret) + goto out_unlock; + + pstart = mdev.m_pa + (pos - map.m_la); + ret = erofs_fscache_read_folios(mdev.m_fscache->cookie, + folio_file_mapping(folio), folio_pos(folio), + folio_size(folio), pstart); + +out_uptodate: + if (!ret) + folio_mark_uptodate(folio); +out_unlock: + folio_unlock(folio); + return ret; +} + static const struct address_space_operations erofs_fscache_meta_aops = { .readpage = erofs_fscache_meta_readpage, }; +const struct address_space_operations erofs_fscache_access_aops = { + .readpage = erofs_fscache_readpage, +}; + /* * Get the page cache of data blob at the index offset. * Return: up to date page on success, ERR_PTR() on failure. diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index e8b37ba5e9ad..88b51b5fb53f 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -296,7 +296,12 @@ static int erofs_fill_inode(struct inode *inode, int isdir) err = z_erofs_fill_inode(inode); goto out_unlock; } + inode->i_mapping->a_ops = &erofs_raw_access_aops; +#ifdef CONFIG_EROFS_FS_ONDEMAND + if (erofs_is_fscache_mode(inode->i_sb)) + inode->i_mapping->a_ops = &erofs_fscache_access_aops; +#endif out_unlock: erofs_put_metabuf(&buf); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index e186051f0640..336d19647c96 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -642,6 +642,8 @@ int erofs_fscache_register_cookie(struct super_block *sb, void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); struct folio *erofs_fscache_get_folio(struct super_block *sb, pgoff_t index); + +extern const struct address_space_operations erofs_fscache_access_aops; #else static inline int erofs_fscache_register_fs(struct super_block *sb) { return 0; } static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} -- 2.27.0