Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp917578pxp; Wed, 16 Mar 2022 21:14:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbZXIJbD4bRtCIYoOSR8/vq4Yd8RYcdMyS+idwIq8rtSR+HwGpuH07B/enAWOCnQqvLvxI X-Received: by 2002:a17:902:9b92:b0:153:99b1:1e94 with SMTP id y18-20020a1709029b9200b0015399b11e94mr2952207plp.2.1647490488816; Wed, 16 Mar 2022 21:14:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647490488; cv=none; d=google.com; s=arc-20160816; b=hCM2GWBox8G1UBVAsSPpeb4r5QRcewsfN3KQey3pxHdAyDIRzy2e2wpLmsHl9RXYAp Z8m5tZ5ILD8tQscCRQhU/DlMfglZZnFNHQXzygxCs2CK0wv5cjOoKigjQlE8BqODzptV tX/FHA9zyGzQ6uVw+RnT9MUsaP7gAqQdSVYfLFEFlkW6GnZQPmiF1iKp+1OycEb+wpn8 OV2SIJNlGG80jN+InfZVjM5zI1HqWz879D1XpSYnFjhf/aFIGiV0vulgyRZ0rOBKw1qi zh5WRoBhS+xMWGnwichzAoUZ+6f9/vmsDTymFohjzokjIt9cdZt0Y2RVlhFapZVwTqpM 504g== 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=dd0MipGwXKo7wL1/hwjEByb+Qi1q7/BEtQIC5MHnPcE=; b=XYXYv2jcbF6jUimZZZ0IxyBGNaIk/P+3ZaWOESEsRhiU2iztGgjtSIOLY2ywr0SyaJ 3y04NCqfvuJTlhL1DklViScuVIgRyHY2uI2jR2lRu7KtsLJtBvoCNXZl/4R9dXShce/F zZ/Vgnkjw2t9avgxhbetm3prPajksksdlG3oFmX9ofcRxFqU8u1Fa/aTSE+HRhrrHpwq rICYk4Pz3rJHz2Skvn74itNMqUuVGnw3ntLfUWcW0k0vdwKZ7pnFwkaIawylcrK7Ei39 INeIxsNNo/YQtC0os5YgLwXY5vPHqWJq9qmxKUD5VUcJ/7YtPBsA0c//F8/xdcSzc/vB 5d2Q== 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 u15-20020a63d34f000000b003816043effesi946427pgi.499.2022.03.16.21.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 21:14:48 -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 6D216BD8B0; Wed, 16 Mar 2022 20:52:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356321AbiCPNTx (ORCPT + 99 others); Wed, 16 Mar 2022 09:19:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356264AbiCPNTH (ORCPT ); Wed, 16 Mar 2022 09:19:07 -0400 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF71B12601; Wed, 16 Mar 2022 06:17:49 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R721e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0V7Mu90V_1647436664; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V7Mu90V_1647436664) by smtp.aliyun-inc.com(127.0.0.1); Wed, 16 Mar 2022 21:17:45 +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 Subject: [PATCH v5 14/22] erofs: add erofs_fscache_read_pages() helper Date: Wed, 16 Mar 2022 21:17:15 +0800 Message-Id: <20220316131723.111553-15-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220316131723.111553-1-jefflexu@linux.alibaba.com> References: <20220316131723.111553-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_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 684ac6f940bc..38b5a9380092 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