Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2178088pxp; Mon, 7 Mar 2022 09:49:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJys+aL8QFKDY0ce8dSjhEYOJgOGF61Ma7XlS3oCIeKERB2GtuoYy2HPk+kYygtFFWvkoYBt X-Received: by 2002:a17:907:971b:b0:6db:32b4:f262 with SMTP id jg27-20020a170907971b00b006db32b4f262mr3855775ejc.522.1646675346385; Mon, 07 Mar 2022 09:49:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646675346; cv=none; d=google.com; s=arc-20160816; b=jLnpbvxUR6IoRFvn/lirlQFwAeWPQRgjpJNunqUTFm40Pc21mgOGT7QQV7HIkjiYiY XFWrNq76Y2Xyj5imF0Psj3eOn10aDP/E21M9HKLJg6ptdsCD/Fwx+lDZW/zOl/txButI CcNthJb7OXNkKNWWyws4UfcOyBVk0ra1PW1qWy0uWzcfFp9HmMoM4vTdgvvZuMJT6ol6 C6R0sU/tj8mbCHgn+gngn1ExF0Y+sk8enfDIHifWbKqsk9h3240s0ArJ6Gxibn1g1SyQ QKOh+EFiG1V+LlbJeHVOL4XL1n7KXkKRZwJAb1C6nRPolHJud6k8yUq1G96XU0ERDV9Q x32g== 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=lUhM+dbyjQboscUvdWcHV7bmhsYDcSNX6AU0OYnl/Iw=; b=By5C04ZFFtiLgE5DxnjCxNJmmCPLySigMQg+73BpEFnrY9Q0fYl945MlAjrxb1/y9u D1UbGZdhfxNQuNjtdd6DgjOjonluZPSCCd6Q9NnNlfC9TnpXn4rDwDe9NH7ffq2yuPyA p47j+lRE5AGZS52B+yk1MOuDnpit66+lMg06QfNoWtZdA6MLPATpmxDX8s1PP3cyC28b QVkmmQFNu1Tjj5i1580JLD6tgeMrfFbp72ClMWAgApnQf/N+Vr2vgYiEt5/Nu0Tc78xi 6+DpbNQ1ralHiUfUV4W0Z8Pp3DnRRp1O2d03Nr3qJFqqUJYgiquM0rQgJNCqg2HTWTwJ JxgQ== 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 y13-20020a056402358d00b00412b2e999acsi13259437edc.280.2022.03.07.09.48.43; Mon, 07 Mar 2022 09:49:06 -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 S242461AbiCGMfF (ORCPT + 99 others); Mon, 7 Mar 2022 07:35:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242391AbiCGMen (ORCPT ); Mon, 7 Mar 2022 07:34:43 -0500 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CCBC3FD93; Mon, 7 Mar 2022 04:33:26 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R531e4;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=15;SR=0;TI=SMTPD_---0V6VOeph_1646656403; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V6VOeph_1646656403) by smtp.aliyun-inc.com(127.0.0.1); Mon, 07 Mar 2022 20:33:24 +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 12/21] erofs: add anonymous inode managing page cache of blob file Date: Mon, 7 Mar 2022 20:32:56 +0800 Message-Id: <20220307123305.79520-13-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,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 Introduce one anonymous inode for managing page cache of corresponding blob file. Then erofs could read directly from the address space of the anonymous inode when cache hit. Signed-off-by: Jeffle Xu --- fs/erofs/fscache.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- fs/erofs/internal.h | 3 ++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 77d2b46e7ff1..4d83125ff896 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -6,6 +6,9 @@ static struct fscache_volume *volume; +static const struct address_space_operations erofs_fscache_blob_aops = { +}; + static int erofs_fscache_init_cookie(struct erofs_fscache_context *ctx, char *path) { @@ -36,8 +39,34 @@ void erofs_fscache_cleanup_cookie(struct erofs_fscache_context *ctx) ctx->cookie = NULL; } +static int erofs_fscache_get_inode(struct erofs_fscache_context *ctx, + struct super_block *sb) +{ + struct inode *const inode = new_inode(sb); + + if (!inode) + return -ENOMEM; + + set_nlink(inode, 1); + inode->i_size = OFFSET_MAX; + + inode->i_mapping->a_ops = &erofs_fscache_blob_aops; + mapping_set_gfp_mask(inode->i_mapping, + GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE); + ctx->inode = inode; + return 0; +} + +static inline +void erofs_fscache_put_inode(struct erofs_fscache_context *ctx) +{ + iput(ctx->inode); + ctx->inode = NULL; +} + static int erofs_fscache_init_ctx(struct erofs_fscache_context *ctx, - struct super_block *sb, char *path) + struct super_block *sb, char *path, + bool need_inode) { int ret; @@ -47,6 +76,15 @@ static int erofs_fscache_init_ctx(struct erofs_fscache_context *ctx, return ret; } + if (need_inode) { + ret = erofs_fscache_get_inode(ctx, sb); + if (ret) { + erofs_err(sb, "failed to get anonymous inode"); + erofs_fscache_cleanup_cookie(ctx); + return ret; + } + } + return 0; } @@ -54,10 +92,11 @@ static inline void erofs_fscache_cleanup_ctx(struct erofs_fscache_context *ctx) { erofs_fscache_cleanup_cookie(ctx); + erofs_fscache_put_inode(ctx); } struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, - char *path) + char *path, bool need_inode) { struct erofs_fscache_context *ctx; int ret; @@ -66,7 +105,7 @@ struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, if (!ctx) return ERR_PTR(-ENOMEM); - ret = erofs_fscache_init_ctx(ctx, sb, path); + ret = erofs_fscache_init_ctx(ctx, sb, path, need_inode); if (ret) { kfree(ctx); return ERR_PTR(ret); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 1f5bc69e8e9f..bb5e992fe0df 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -99,6 +99,7 @@ struct erofs_sb_lz4_info { struct erofs_fscache_context { struct fscache_cookie *cookie; + struct inode *inode; }; struct erofs_sb_info { @@ -626,7 +627,7 @@ int erofs_init_fscache(void); void erofs_exit_fscache(void); struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, - char *path); + char *path, bool need_inode); void erofs_fscache_put_ctx(struct erofs_fscache_context *ctx); #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ -- 2.27.0