Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1050463pxb; Wed, 6 Apr 2022 07:33:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTmp43rLM8g15CqLFJ/tXktoVUuyXawouePv1Qr/QkQG0YdTBk+Hg82jN7oB15oGZIW78G X-Received: by 2002:a17:90b:380e:b0:1c7:74f6:ae60 with SMTP id mq14-20020a17090b380e00b001c774f6ae60mr9949063pjb.5.1649255630952; Wed, 06 Apr 2022 07:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649255630; cv=none; d=google.com; s=arc-20160816; b=LZlamSZeWhEMX5UY/DCGeGs+JUVc9dUNi/mWrvxFon+xwBUXg8LbAy2u5lYB+SziG0 W8luw7Tgf1kIyiL82gMhJN3VWqSAqlXotBOJ5hwXYwuNOX5QnR+Q8UeV+BPq2BKXe9Hk ivCOl2xB/2mRfv6ljB7IyN4dARqovIoFiOP5d6+5OAT/w5NrENPG3XMK6yom8q5bGGIz YrhyWPDmvHfuHXs3+XNiQDDUIYKPlC8U5aM0WGeyGtS9XUJ9FWz5kaNjUvnoL7+dHEHB wKxRUIwIUT2doGtzYekcTK443szfArn1/uENA5o5sjNV+bHrKo/iJXGKLdQrVSlf84Db QbWQ== 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=k6JZDLBiITz6j9UQSSrXwhHAWeccAOQ0d4aYvFtKrEQAC8rSTTB5/YrjtgH/q5Grmd F3o2rzlnoiMY/9HFnBpzPvNSHT9s6suCNkM6eKLrM7YLvB1CzV2/J7BMfA/p9M/r/QXL 3KLKgcGC6c3yMTijaD0cOB2MDu9ChuelUYc/9EQ7DVcKju8xIRktpjDuX4sz3exshah+ h+6FZNmtzP+POn+QgikdDyugvcLqfbNa1MRa5EQPoZ/wQM7bukcPX57pfi9yAuXpHn3S f3BjyQGLVRXShNvNVz6BRc8Cv62N+AwnmM0AlGRXHH4lKTLN5sH2w2Fisswmb431wcAd w9UA== 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 g7-20020a056a001a0700b004fb47469b7asi16574774pfv.87.2022.04.06.07.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 07:33:50 -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 6829663B382; Wed, 6 Apr 2022 05:15:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230054AbiDFMQO (ORCPT + 99 others); Wed, 6 Apr 2022 08:16:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbiDFMOj (ORCPT ); Wed, 6 Apr 2022 08:14:39 -0400 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4632370667; Wed, 6 Apr 2022 00:56:44 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0V9KyhvE_1649231799; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V9KyhvE_1649231799) by smtp.aliyun-inc.com(127.0.0.1); Wed, 06 Apr 2022 15:56:40 +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 v8 17/20] erofs: implement fscache-based data read for non-inline layout Date: Wed, 6 Apr 2022 15:56:09 +0800 Message-Id: <20220406075612.60298-18-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220406075612.60298-1-jefflexu@linux.alibaba.com> References: <20220406075612.60298-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 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