Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9067901rwl; Wed, 11 Jan 2023 00:41:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXvDfsHUDUJR4kNX1AyVjqKjXSkVgRwU4g8t/jS0KIZGp6mr9Il4SfzK/bRrA4WA1O1EtijH X-Received: by 2002:a05:6402:5172:b0:493:597e:2193 with SMTP id d18-20020a056402517200b00493597e2193mr16519472ede.37.1673426486983; Wed, 11 Jan 2023 00:41:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673426486; cv=none; d=google.com; s=arc-20160816; b=IWcgoJZDs975YNIQ1nLriuG+EJtVGXBoIEHjWnVg7beQwC+b16TKOZr8jPm7kjbJzS 7Bt3OD0qgJ2UL/c5BAo4v5qt5x0VZzKJkeRgmQ1XbjTn8kbQ0u9JF6S46zTr9OTjYgR4 WRP3TS9sueU6zuTiX0olfVRmTEhyC9pT7sY4RNtoTydoqvhjJK0AF79KqzRipY+hsSoV n+67mElEE/K0c9QakMC2E8T2OGIP/QUnbUnyZNNUV3EdLducpnY7XCU7HhLOY1xbSb8/ 56Vxh+lckg1UToxRVaUpIvDhcEbzQ9fXtO57txEbhoZoOOxMwndjD2WtV4jQateReG+J J+Zw== 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=Z1eTUhEz+MC1IQIDfws/AqsaGNc+I0/TZrPRNTkpBjM=; b=Oo+OrceH75LdFmSYXuqbCHDY+CPVFZw/0gVYK8+PHtKpdjMxNXyRRm+rVZaqIjvS3V M+tvWV9ebrkaeNAzbroMUvU77pTsBKUxB8FMP4Ds3Q756L08NBfE5c7vTYatFkdmqi7m 8RMWX+8/zxkpghkIhVR6tm75bleNNhe1n0uFrqqY7be6kpyl95jHNDVjKQFmy4vUFiVt JI3BYyzH5AGVdD0GqcXxbqZE0oHHhJNGyx+pe6EigvQQLv74pg3AGolY4Om/pgP7yeaf p1KxbKs3HIjCmufNSWdbRRMUhTvvKHg7yQ2L85QxICPq0moqitZwHz9ovL0KQ1DjNHR/ ao/w== 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 ae10-20020a17090725ca00b0084c4a806258si13288174ejc.645.2023.01.11.00.41.14; Wed, 11 Jan 2023 00:41:26 -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 S236180AbjAKIcm (ORCPT + 53 others); Wed, 11 Jan 2023 03:32:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230074AbjAKIcP (ORCPT ); Wed, 11 Jan 2023 03:32:15 -0500 Received: from out30-7.freemail.mail.aliyun.com (out30-7.freemail.mail.aliyun.com [115.124.30.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E804EBC9F; Wed, 11 Jan 2023 00:32:07 -0800 (PST) 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=ay29a033018046050;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VZMek6i_1673425922; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMek6i_1673425922) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:03 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v2 4/7] erofs: implement .read_iter for page cache sharing Date: Wed, 11 Jan 2023 16:31:55 +0800 Message-Id: <20230111083158.23462-5-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-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_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, 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 When page cache sharing enabled, page caches are managed in the address space of blobs rather than erofs inodes. All erofs inodes sharing one chunk will refer to and share the page cache in the blob's address space. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index f715b3efcc77..4075d9519a7d 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -384,8 +384,56 @@ static int erofs_fscache_share_file_open(struct inode *inode, struct file *filp) return 0; } +static ssize_t erofs_fscache_share_file_read_iter(struct kiocb *iocb, + struct iov_iter *to) +{ + struct file *filp = iocb->ki_filp; + struct inode *inode = file_inode(filp); + struct file *realfile = filp->private_data; + struct inode *realinode = file_inode(realfile); + struct erofs_fscache_share_file_info *finfo = realfile->private_data; + ssize_t already_read = 0; + int ret = 0; + + /* no need taking (shared) inode lock since it's a ro filesystem */ + if (!iov_iter_count(to)) + return 0; + + if (IS_DAX(inode) || iocb->ki_flags & IOCB_DIRECT) + return -EOPNOTSUPP; + + do { + struct folio *folio; + size_t bytes, copied, offset, fsize; + pgoff_t index = (finfo->pa + iocb->ki_pos) >> PAGE_SHIFT; + + folio = read_cache_folio(realinode->i_mapping, index, NULL, NULL); + if (IS_ERR(folio)) { + ret = PTR_ERR(folio); + break; + } + + fsize = folio_size(folio); + offset = iocb->ki_pos & (fsize - 1); + bytes = min_t(size_t, inode->i_size - iocb->ki_pos, iov_iter_count(to)); + bytes = min_t(size_t, bytes, fsize - offset); + copied = copy_folio_to_iter(folio, offset, bytes, to); + folio_put(folio); + iocb->ki_pos += copied; + already_read += copied; + if (copied < bytes) { + ret = -EFAULT; + break; + } + } while (iov_iter_count(to) && iocb->ki_pos < inode->i_size); + + file_accessed(filp); + return already_read ? already_read : ret; +} + const struct file_operations erofs_fscache_share_file_fops = { .llseek = generic_file_llseek, + .read_iter = erofs_fscache_share_file_read_iter, .open = erofs_fscache_share_file_open, .release = erofs_fscache_share_file_release, }; -- 2.19.1.6.gb485710b