From patchwork Mon Apr 25 12:21:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 12825684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 817A2C433EF for ; Mon, 25 Apr 2022 12:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236979AbiDYMZc (ORCPT ); Mon, 25 Apr 2022 08:25:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241748AbiDYMZS (ORCPT ); Mon, 25 Apr 2022 08:25:18 -0400 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7FDF62A26; Mon, 25 Apr 2022 05:22:11 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R511e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0VBE4bIb_1650889326; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VBE4bIb_1650889326) by smtp.aliyun-inc.com(127.0.0.1); Mon, 25 Apr 2022 20:22:07 +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, zhangjiachen.jaycee@bytedance.com, zhujia.zj@bytedance.com Subject: [PATCH v10 14/21] erofs: add erofs_fscache_read_folios() helper Date: Mon, 25 Apr 2022 20:21:36 +0800 Message-Id: <20220425122143.56815-15-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220425122143.56815-1-jefflexu@linux.alibaba.com> References: <20220425122143.56815-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Add erofs_fscache_read_folios() 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 read from the cache. This helper can then be used to implement .readpage()/.readahead() of on-demand read semantics. Signed-off-by: Jeffle Xu Reviewed-by: Gao Xiang --- fs/erofs/fscache.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 26f038d9c4e1..ac02af8cce3e 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -5,6 +5,60 @@ #include #include "internal.h" +/* + * Read data from fscache and fill the read data into page cache described by + * @start/len, which shall be both aligned with PAGE_SIZE. @pstart describes + * the start physical address in the cache file. + */ +static int erofs_fscache_read_folios(struct fscache_cookie *cookie, + struct address_space *mapping, + loff_t start, size_t len, + loff_t pstart) +{ + enum netfs_io_source source; + struct netfs_io_request rreq = {}; + struct netfs_io_subrequest subreq = { .rreq = &rreq, }; + struct netfs_cache_resources *cres = &rreq.cache_resources; + struct super_block *sb = mapping->host->i_sb; + struct iov_iter iter; + size_t done = 0; + int ret; + + ret = fscache_begin_read_operation(cres, cookie); + if (ret) + return ret; + + while (done < len) { + subreq.start = pstart + done; + subreq.len = len - done; + subreq.flags = 1 << NETFS_SREQ_ONDEMAND; + + source = cres->ops->prepare_read(&subreq, LLONG_MAX); + if (WARN_ON(subreq.len == 0)) + source = NETFS_INVALID_READ; + if (source != NETFS_READ_FROM_CACHE) { + erofs_err(sb, "failed to fscache prepare_read (source %d)", + source); + ret = -EIO; + goto out; + } + + iov_iter_xarray(&iter, READ, &mapping->i_pages, + start + done, subreq.len); + ret = fscache_read(cres, subreq.start, &iter, + NETFS_READ_HOLE_FAIL, NULL, NULL); + if (ret) { + erofs_err(sb, "failed to fscache_read (ret %d)", ret); + goto out; + } + + done += subreq.len; + } +out: + fscache_end_operation(cres); + return ret; +} + static const struct address_space_operations erofs_fscache_meta_aops = { };