Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2321738pxp; Mon, 7 Mar 2022 12:51:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJywL7jNGUMNROIHiIthfmeXL17pMWdLJOy6ryYJgEeQs8myBEoLTAi5rTRMMHAqILhm0T8L X-Received: by 2002:a05:6a00:23c5:b0:4f7:878:850f with SMTP id g5-20020a056a0023c500b004f70878850fmr5647065pfc.80.1646686312560; Mon, 07 Mar 2022 12:51:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646686312; cv=none; d=google.com; s=arc-20160816; b=G3/byNApX3TwlTSjgPltWqwrND/Sa5pClq1Q4c++MTZjIe6ELqNutyMidB8s2yvKOO eSozjFpSPGDpGcu887gUXGTM7vmIm6BxqiObCBnVauFhVD2521nzjbmbs9DM3zDCQdXf TIoA3phj3hxOSG9uc7y2eZx6TNSx9tFK4fFIFGya+aeaP4Isy8R5wPdgtlx89cE9mwkK 5ftG/01/dlmdyHm7cUPapkhy09f3KXuHVmxsZAt0thCoxpNJ8IikI8PUvr/PmOhz6K2t YBAHRDxOhDqu8oLriuGgrVNCeVaL/J/W2tSB8xPMTxSlXOj8/s74AR7V/j4yOFBh/reg q1RA== 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=mcFyJ1YhxivxUnWeUgEVgLWGftMNf1BX6VxwfdDs5OY=; b=Qvyzs2uEuvXOErJVnrq0wCJEsvv8TQUkFY6iROsqoMwD1+Rn6OhkjzNqn2HCA+sF0A ygz9TAW9nbSZe0YJiEIJ7FOU3YLmkde/1inpIajTF6iqYc7Uk5zAxwhjTtWF/S7umtfI DgPkdyCSg7IzOJRzczPkwMNPd5M7W4p8WOliMslayxYzHfyiHullbgaele35tLYcrL0x AGeOHl5XgMeY+UNgCG94t4jpRBxnsANTO+T5wU/PIBhtOm4FscDEuECZVCEUbfc6NFLN wLW8MrX68a7qK+cS9v2L7aJtZGh+9Au/kmplxvQtyMRNEAt//CKwIf7j8nJ4XTxDAl7v P9HA== 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 np9-20020a17090b4c4900b001bf738669b6si292416pjb.53.2022.03.07.12.51.35; Mon, 07 Mar 2022 12:51:52 -0800 (PST) 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 S242490AbiCGMfK (ORCPT + 99 others); Mon, 7 Mar 2022 07:35:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242400AbiCGMeo (ORCPT ); Mon, 7 Mar 2022 07:34:44 -0500 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D00C440A2B; Mon, 7 Mar 2022 04:33:29 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0V6VOepu_1646656404; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V6VOepu_1646656404) by smtp.aliyun-inc.com(127.0.0.1); Mon, 07 Mar 2022 20:33:25 +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 Subject: [PATCH v4 13/21] erofs: add erofs_fscache_read_pages() helper Date: Mon, 7 Mar 2022 20:32:57 +0800 Message-Id: <20220307123305.79520-14-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220307123305.79520-1-jefflexu@linux.alibaba.com> References: <20220307123305.79520-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 Add erofs_fscache_read_pages() helper reading from fscache. It supports on-demand read semantics. That is, it will make the backend prepare for the data when cache miss. Once data ready, it will reinitiate a read from the cache. This helper can then be used to implement .readpage()/.readahead() of on-demand read semantics. Besides also add erofs_fscache_read_page() wrapper helper. Signed-off-by: Jeffle Xu --- fs/erofs/fscache.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 4d83125ff896..3f9f7d6ede57 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -6,6 +6,44 @@ static struct fscache_volume *volume; +/* + * erofs_fscache_read_pages - Read data from fscache. + * + * Fill the readed data into page cache described by @start/len, which + * shall be both aligned with PAGE_SIZE. @pstart describes the corresponding + * physical start address in the cache file. + */ +static int erofs_fscache_read_pages(struct fscache_cookie *cookie, + struct address_space *mapping, + loff_t start, size_t len, + loff_t pstart) +{ + struct netfs_cache_resources cres; + struct iov_iter iter; + int ret; + + memset(&cres, 0, sizeof(cres)); + + ret = fscache_begin_read_operation(&cres, cookie); + if (ret) + return ret; + + iov_iter_xarray(&iter, READ, &mapping->i_pages, start, len); + + ret = fscache_read(&cres, pstart, &iter, + NETFS_READ_HOLE_ONDEMAND, NULL, NULL); + + fscache_end_operation(&cres); + return ret; +} + +static inline int erofs_fscache_read_page(struct fscache_cookie *cookie, + struct page *page, loff_t pstart) +{ + return erofs_fscache_read_pages(cookie, page_file_mapping(page), + page_offset(page), PAGE_SIZE, pstart); +} + static const struct address_space_operations erofs_fscache_blob_aops = { }; -- 2.27.0