Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4865913iob; Mon, 9 May 2022 03:33:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+94eXqz0VvRT2AmTY60eUrV+XCxp0eo4tpDYzBxh2xo18dzBwQv4Hs0BEoy73k5+ZI1DI X-Received: by 2002:a62:a50c:0:b0:510:6b52:cd87 with SMTP id v12-20020a62a50c000000b005106b52cd87mr15511598pfm.30.1652092416721; Mon, 09 May 2022 03:33:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652092416; cv=none; d=google.com; s=arc-20160816; b=i3gzd+T9tSV0pd++14Ruw9q9V/E7SQhojrrPRXL573DGLchPWLmpL35FCumnN3CJ9m gklghjvCPXJ+LBgGdPEoPZHitllo3y589I2kQtuqWoigBkxT9Au5uPARaiGRn4KFqUC3 zlXb2u/uLMLEW78pc/p/YmgFp+fN5b4ztoTKbuKsZfD0UvJk9BDseowN9ALwU472lmmC ejybf77rnbnI7GL7gZcFXfAF1JSqVILCYPuxQi5h10/gmVoCIOk9IudlfzL/crlxHjX6 Vc1j3wpLHo4gnnYr5sSgTIZ6zcmq10eHCLQaqqi0snIBhfjCvxjg+Py34qi0vEbY9gCe esRg== 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=d3b+R4qkVRfvPcE5a4au9Bd+CC/6RrRUHSgPFcB0swU=; b=zc/ukG7XZ6geDrR+iXWTsV/WKRdXWguYuIoTAOotjs8taIvdfc0WYdD70TT7yC09gz /7viG3KX6lf0BNrs/FJmoZg0ZXBDjE1GnBWxJvEoZD2aubHOZLoUgKa497dVtVODR0cR IfNQ1Z82CX1gM0lieO6LLYjkQAwi6klsSR4miFDv8qYkT5bVsHAyvXYI4MdnPd/7qlbE pe3jmYXcjg0iPoV0U9h1H5QVryh48VLsOGp4mJmooAOs9H27nC/haOcwkTCxFzX5n5Ua paLf0VFxW5pg+88jtWLXS0C2YY70Ae6wF9dc0JaZWlsC//6R7kjhT7nlaXgygLpIE63f IdZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id t184-20020a6381c1000000b003ab3dd01959si12646637pgd.699.2022.05.09.03.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 03:33:36 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 CDEBC25B077; Mon, 9 May 2022 03:03:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236907AbiEIHye (ORCPT + 99 others); Mon, 9 May 2022 03:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235793AbiEIHpB (ORCPT ); Mon, 9 May 2022 03:45:01 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC17E15FFF; Mon, 9 May 2022 00:41:05 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;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=20;SR=0;TI=SMTPD_---0VCgwzEf_1652082057; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VCgwzEf_1652082057) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 May 2022 15:40:58 +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 18/22] erofs: implement fscache-based data read for non-inline layout Date: Mon, 9 May 2022 15:40:24 +0800 Message-Id: <20220509074028.74954-19-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 data from data blobs over fscache for non-inline layout. Signed-off-by: Jeffle Xu Reviewed-by: Gao Xiang --- fs/erofs/fscache.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/inode.c | 4 ++++ fs/erofs/internal.h | 2 ++ 3 files changed, 57 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 23d7e862eed8..b3af72af7c88 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -83,10 +83,61 @@ 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_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; + + 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; + } + + 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_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, +}; + int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, char *name, bool need_inode) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index e8b37ba5e9ad..8d3f56c6469b 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -297,6 +297,10 @@ static int erofs_fill_inode(struct inode *inode, int isdir) 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 fa488af8dfcf..c8f6ac910976 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -639,6 +639,8 @@ int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, char *name, bool need_inode); void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); + +extern const struct address_space_operations erofs_fscache_access_aops; #else static inline int erofs_fscache_register_fs(struct super_block *sb) { -- 2.27.0