Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5688197pxb; Thu, 20 Jan 2022 02:30:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5gQXerC6kqfqCS9rqNYKdBPVW0csBKxW0EoF+2YhET3e/yLED225NbXWq7EAte5Ns+BJD X-Received: by 2002:a17:90b:33c7:: with SMTP id lk7mr9917889pjb.86.1642674630500; Thu, 20 Jan 2022 02:30:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642674630; cv=none; d=google.com; s=arc-20160816; b=yxsSVK8UI1UEHt0RDXxugtWYToC0JTI+EwTIKFAFk7q6uf+ZFTouGJEuxoXeFyUQ1U C4Q8cGPV+NASqHK2c9o64yergTwYRPMfGWILJyQrIl1uZGCv9lcPS/f6d49KuJYRA/1s fEUQxHr33yk/l4Tyod/PDMx1FIeF58+pWVtPV+C0vPaKuSOHmYG9IFBa6dR6h5JmLxqk N7gO9NoUG5ltrGlXcVktKhsSdSH9nAXNB39IX1X4ZQBosP0ElFySUQFG1Wm04pvy5arF 3+TubbRPjaBvAi6zT6iLA6izey94g8aW4SN343hJIEiDUpuFsAx3t/uk3tdftY1AtZZF vNIw== 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=CVpot+btDUsCUyurOnsuYfJ7vOYpWxvGiiBd5PZe5rg=; b=d9S/c3ATbYxVYhA8fcv9K8djAWTQE03yiSGinPBZnFRScCu/gcLO45cU4zDqmOK3kF nHvncswcpqfnKs0P6msBwutK1+4CtrhUfRcLpx4WVCBAaHK3XNHjKothtdUktxphyaax JuCljX6YqAL5EJbNCxXVt93X2w6osdnmjQMmUBMQcZ6KJDkdejjvB10z8uzKVUUYSg6c QPqUV2TB5NmcLp/GTZZuK48loMjHLpUrX8xmrY0fA7Br2VIIU7u/duTMqn9G/MNIQiLW gFOomde0Zg2brsgE52G8NdvAOOT3DEPns4xt/Y4GjSUH6VtgVTut1J0q2nBiRTOg5US9 BXHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c35si2854534pgm.848.2022.01.20.02.30.18; Thu, 20 Jan 2022 02:30:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243668AbiARNNU (ORCPT + 99 others); Tue, 18 Jan 2022 08:13:20 -0500 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:59123 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242231AbiARNMd (ORCPT ); Tue, 18 Jan 2022 08:12:33 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;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=12;SR=0;TI=SMTPD_---0V2C5CoQ_1642511550; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V2C5CoQ_1642511550) by smtp.aliyun-inc.com(127.0.0.1); Tue, 18 Jan 2022 21:12:31 +0800 From: Jeffle Xu To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: 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 v2 12/20] erofs: add anonymous inode managing page cache of blob file Date: Tue, 18 Jan 2022 21:12:08 +0800 Message-Id: <20220118131216.85338-13-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220118131216.85338-1-jefflexu@linux.alibaba.com> References: <20220118131216.85338-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 10c3f5ea9e24..74683df6144d 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_fscahce_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_fscahce_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_fscahce_init_ctx(ctx, sb, path); + ret = erofs_fscahce_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