Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp62957lfe; Fri, 15 Apr 2022 19:38:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytEhk9ZJ7Qq0V+1whZZ+znFB+p9LK6c8/TehOnp1ePmpNBdK0eoUCt0HyeNIbXbgSySxRi X-Received: by 2002:a17:902:6b4b:b0:158:d86f:b232 with SMTP id g11-20020a1709026b4b00b00158d86fb232mr1828901plt.106.1650076703651; Fri, 15 Apr 2022 19:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076703; cv=none; d=google.com; s=arc-20160816; b=IBQT5b/ZTNmHyDQF+DqRoYFmBPam5JC7MtyJ/SfvKtIpBzB8bzOo+nOKLojbpXatFb /Nfi4TPv6DKm14DMH5AZa5nv/eNWnDOhyf0bjsSsdLvaqBjcrbiDHSyKzSE6Z5Bv+39n ZYE6RHudrq+niX7wwZitaaJgBB2UZYE0WxlMaseWsH2NQlKyL/PIsrCTBW/yVGEFc0Iu 7neSmWGgoshbsvrU8gFJTKhZJx8fxVmoAhgB/PAok/j92VFWfZSbxiD3Tx1BdOj/hOjd UCCeRr97/2LoJ0Axgasoti/z50afMF5JYgZg1xVnaIFVWhWXtv0kitQv15rx9bDczwfo TT+Q== 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=TY8/C9a8NhJNofbHufyvVeLfSgIsig3LzhJxLpbyddk=; b=rCoLg6hCEcUx7qzFy30WLFh6g4UJzIbP6hzFfx/K0FshlWqpMx2nj+jULyAFtuE9dz kmsJL+4Qj8gBe/QxyY3ZaWVMVPR3kIBYykj8S/ARALGLu7WZOwhVa6A454km5wdAmLsf 66wonCKIV5JTOu247W6R4c/nV1wD2sssSTKy62RzL5jwgQCiyRyz5s1+QaQZyjQVwujw tahxzPoxm/Gi/ZupKmXDte2bN/0SPUFgRkT1Ul6CJQH2ko3F/4+7RSfxl6QLDUB1Ghto cSS58FjT9K8ad+Ihdw2OAZLmqlKiclJ7krPNA2moPUg8QHVYKeNlVAz2/cSQQZed28I6 m3nQ== 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 k64-20020a628443000000b004fa3a8dffe4si2932569pfd.155.2022.04.15.19.38.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:38:23 -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 40CB5172DD2; Fri, 15 Apr 2022 18:50:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353711AbiDOMkC (ORCPT + 99 others); Fri, 15 Apr 2022 08:40:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353689AbiDOMj1 (ORCPT ); Fri, 15 Apr 2022 08:39:27 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 965DDC6EE1; Fri, 15 Apr 2022 05:36:42 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R611e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0VA7Ug1q_1650026197; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VA7Ug1q_1650026197) by smtp.aliyun-inc.com(127.0.0.1); Fri, 15 Apr 2022 20:36:38 +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 Subject: [PATCH v9 14/21] erofs: add erofs_fscache_read_folios() helper Date: Fri, 15 Apr 2022 20:36:07 +0800 Message-Id: <20220415123614.54024-15-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220415123614.54024-1-jefflexu@linux.alibaba.com> References: <20220415123614.54024-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 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 | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 1c88614203d2..066f68c062e2 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -5,6 +5,59 @@ #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_subrequest subreq; + struct netfs_io_request rreq; + struct netfs_cache_resources *cres = &rreq.cache_resources; + struct iov_iter iter; + size_t done = 0; + int ret; + + memset(&rreq, 0, sizeof(rreq)); + memset(&subreq, 0, sizeof(subreq)); + subreq.rreq = &rreq; + + 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) { + 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) + goto out; + + done += subreq.len; + } +out: + fscache_end_operation(cres); + return ret; +} + static const struct address_space_operations erofs_fscache_meta_aops = { }; -- 2.27.0