Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3344162ioa; Tue, 26 Apr 2022 01:39:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7z50QFMxc+tOE/pxGqWzBuxPx07hOQ69JTLuhOmuXa4L9jywZZgg7ZawjsDeYw399gR43 X-Received: by 2002:a17:907:1b19:b0:6f0:1022:1430 with SMTP id mp25-20020a1709071b1900b006f010221430mr20687273ejc.13.1650962352002; Tue, 26 Apr 2022 01:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650962351; cv=none; d=google.com; s=arc-20160816; b=oaje81zu9p5JrAXgLMcNuVmYBUZnRj3YLL2HAtIOk8CWbJzuxm+Wtm3bN08NHZ7SuO rSRQNMocS3vMuPQdXuvYKoc2OrePKXrR6SsYJFjkfVRuQ/OP194JgGUjd2WI1GMixLWO BAgWhwqEXnI9xh9cWqtLDbImrOrADosW43KfC3p0DGeeKSvYBqrleB64Y3iBL3PsNf3O CwXTO79fVLUC5x77/NPuXJVpKqqLnCUOJ+/9dnYixoHMAXB6s0okI+GXsUd9u/ZakxXq GIbke7hLN2XOS7vrjXGkKO5eK7hqQhOEky0w3bAmgmZeqe+m0SqJiaibme52TKGO5aUg OmrQ== 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=yRYkIauyE+yg1afkd/O/T++a0+qLaWm9vhtHKVyE/8E=; b=el8ftG95uXCt9DJJIVaKS39AZFhSFgpAEvCcPOO0gqe5ZLzIq8KDwVmgZBb3lN3EUp aaIXU9ZI5jnE2qXMSznbVjv+QV+9e4gsgxkIPFtfban/hy88uOqPQJBoCq0o7iguRdgv f8aaZ/Y4Sp69/N4wmBHqA2tzUmVL0MIdt4sVaPhqTwR+0aN/V69p62IR8JkF+MZVjcm9 YjtQrI89N4x9wlckxBIhw+UgWwuIXjjKbpXeEEDrbO0KKSH64zmeEy+1gvZiuNCM+F70 fEJsPtu8TTeWbyx3Edfl1MBO6HHGk1Iui2WlGIvUmPbMGsZ0Elj+xx9g6/pB/6v1T01d AimQ== 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 y1-20020a056402440100b0041cb4fb0c7bsi17747900eda.516.2022.04.26.01.38.48; Tue, 26 Apr 2022 01:39:11 -0700 (PDT) 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 S236980AbiDYM0K (ORCPT + 99 others); Mon, 25 Apr 2022 08:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241704AbiDYMZS (ORCPT ); Mon, 25 Apr 2022 08:25:18 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2D8862A17; Mon, 25 Apr 2022 05:22:10 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;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=20;SR=0;TI=SMTPD_---0VBDrnXQ_1650889325; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VBDrnXQ_1650889325) by smtp.aliyun-inc.com(127.0.0.1); Mon, 25 Apr 2022 20:22:06 +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, zhujia.zj@bytedance.com Subject: [PATCH v10 13/21] erofs: add anonymous inode caching metadata for data blobs Date: Mon, 25 Apr 2022 20:21:35 +0800 Message-Id: <20220425122143.56815-14-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220425122143.56815-1-jefflexu@linux.alibaba.com> References: <20220425122143.56815-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, 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 data blobs so that erofs can cache metadata directly within such anonymous inode. Signed-off-by: Jeffle Xu Reviewed-by: Gao Xiang --- fs/erofs/fscache.c | 39 ++++++++++++++++++++++++++++++++++++--- fs/erofs/internal.h | 6 ++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index dfff245b006b..26f038d9c4e1 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -5,12 +5,17 @@ #include #include "internal.h" +static const struct address_space_operations erofs_fscache_meta_aops = { +}; + int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, char *name) + struct erofs_fscache **fscache, + char *name, bool need_inode) { struct fscache_volume *volume = EROFS_SB(sb)->volume; struct erofs_fscache *ctx; struct fscache_cookie *cookie; + int ret; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) @@ -20,15 +25,40 @@ int erofs_fscache_register_cookie(struct super_block *sb, name, strlen(name), NULL, 0, 0); if (!cookie) { erofs_err(sb, "failed to get cookie for %s", name); - kfree(name); - return -EINVAL; + ret = -EINVAL; + goto err; } fscache_use_cookie(cookie, false); ctx->cookie = cookie; + if (need_inode) { + struct inode *const inode = new_inode(sb); + + if (!inode) { + erofs_err(sb, "failed to get anon inode for %s", name); + ret = -ENOMEM; + goto err_cookie; + } + + set_nlink(inode, 1); + inode->i_size = OFFSET_MAX; + inode->i_mapping->a_ops = &erofs_fscache_meta_aops; + mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + + ctx->inode = inode; + } + *fscache = ctx; return 0; + +err_cookie: + fscache_unuse_cookie(ctx->cookie, NULL, NULL); + fscache_relinquish_cookie(ctx->cookie, false); + ctx->cookie = NULL; +err: + kfree(ctx); + return ret; } void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) @@ -42,6 +72,9 @@ void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) fscache_relinquish_cookie(ctx->cookie, false); ctx->cookie = NULL; + iput(ctx->inode); + ctx->inode = NULL; + kfree(ctx); *fscache = NULL; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index b1f19f058503..5867cb63fd74 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -99,6 +99,7 @@ struct erofs_sb_lz4_info { struct erofs_fscache { struct fscache_cookie *cookie; + struct inode *inode; }; struct erofs_sb_info { @@ -632,7 +633,8 @@ int erofs_fscache_register_fs(struct super_block *sb); void erofs_fscache_unregister_fs(struct super_block *sb); int erofs_fscache_register_cookie(struct super_block *sb, - struct erofs_fscache **fscache, char *name); + struct erofs_fscache **fscache, + char *name, bool need_inode); void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); #else static inline int erofs_fscache_register_fs(struct super_block *sb) @@ -643,7 +645,7 @@ static inline void erofs_fscache_unregister_fs(struct super_block *sb) {} static inline int erofs_fscache_register_cookie(struct super_block *sb, struct erofs_fscache **fscache, - char *name) + char *name, bool need_inode) { return -EOPNOTSUPP; } -- 2.27.0