Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1675698pxb; Fri, 1 Apr 2022 22:33:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw77/ZNDDYutYFQpFkA9AcpGz8FYIrIfEieVew0e8FS3pt/6UJ6PJ0+4dKq3nkOe4J/yuLl X-Received: by 2002:a17:907:1c9d:b0:6e4:a223:1af2 with SMTP id nb29-20020a1709071c9d00b006e4a2231af2mr2775835ejc.102.1648877585502; Fri, 01 Apr 2022 22:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648877585; cv=none; d=google.com; s=arc-20160816; b=eD8cmAr8PCpH+I3ziGr3//R4jeEblRzgV+VQmT0XBCXdwPGnV7JiTeBIkEVASEuQuo d6/Z6bZ590XZPKW9YaAZ6dhIbYnl51Gi3qwD7V4V4/e0sd3SAwcYigN/omE0PS7eyOZR ASAJuf1C2etCrmo3IJtDY8tvbrf6zf2dHSVBCvXvS0bARg+0Z0FetsQwnBPbPepq7kR5 1YJeT1rl28KySaBuW3HFiPZLLC9UbZNZXmwHFldtavs7PB92IRd/qaFQw8iZRknZ7Vrk +b+DgVrmGZC+z/JwwFiq+wCQ2Poe/A3O9N+yP7eh1MkgRJZkwt5ypJ33PuZH8ZiRpriu fVAg== 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=GdN7jFVA6KA0gO6iH4TddC8y/0kZ858w/U5RWU5p64A=; b=dA2JxVS3BeE7Un+feCoihuvocM0KhyT2SvXvEuG4QyCBv2iqpjuNJsDsSpz2Pnr5+1 ls1meMCzlAB5eUKPJvz9U+oFFQdEkZWe3iFzBRynwoE92n4K+Xb0n/sU3cTCcezJQICi JjOXNYzPtUXFrJhG0hYV2RFX3/jgsmZ9lj1oqxEya/N/I8Zjqgn0JxF6eO/fGgk0CJe0 jQo4dJVI9A334NzDuHATg7PGINCCccsoBck3jJEZUrfgGxliWPWechPNISDxD3ZSDCzB m6GOFpIttOjutgSqdUraniUEQkTrEfp4ZsgZXHBlF0esozxx3Glg8XdCtwQ0AgfwC7MR /eyg== 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 c10-20020a50cf0a000000b00418c2b5bd35si3016751edk.23.2022.04.01.22.32.41; Fri, 01 Apr 2022 22:33:05 -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 S235443AbiCaMAt (ORCPT + 99 others); Thu, 31 Mar 2022 08:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235442AbiCaMAT (ORCPT ); Thu, 31 Mar 2022 08:00:19 -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 D28B6208C1B; Thu, 31 Mar 2022 04:58:13 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R981e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0V8imrsv_1648727888; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V8imrsv_1648727888) by smtp.aliyun-inc.com(127.0.0.1); Thu, 31 Mar 2022 19:58:09 +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 Subject: [PATCH v7 10/19] erofs: add fscache context helper functions Date: Thu, 31 Mar 2022 19:57:44 +0800 Message-Id: <20220331115753.89431-11-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220331115753.89431-1-jefflexu@linux.alibaba.com> References: <20220331115753.89431-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,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,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 a context structure for managing data blobs, and helper functions for initializing and cleaning up this context structure. Signed-off-by: Jeffle Xu --- fs/erofs/fscache.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/internal.h | 19 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 7a6d0239ebb1..67a3c4935245 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -5,6 +5,52 @@ #include #include "internal.h" +/* + * Create an fscache context for data blob. + * Return: 0 on success and allocated fscache context is assigned to @fscache, + * negative error number on failure. + */ +int erofs_fscache_register_cookie(struct super_block *sb, + struct erofs_fscache **fscache, char *name) +{ + struct fscache_volume *volume = EROFS_SB(sb)->volume; + struct erofs_fscache *ctx; + struct fscache_cookie *cookie; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + cookie = fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE, + name, strlen(name), NULL, 0, 0); + if (!cookie) { + erofs_err(sb, "failed to get cookie for %s", name); + kfree(name); + return -EINVAL; + } + + fscache_use_cookie(cookie, false); + ctx->cookie = cookie; + + *fscache = ctx; + return 0; +} + +void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) +{ + struct erofs_fscache *ctx = *fscache; + + if (!ctx) + return; + + fscache_unuse_cookie(ctx->cookie, NULL, NULL); + fscache_relinquish_cookie(ctx->cookie, false); + ctx->cookie = NULL; + + kfree(ctx); + *fscache = NULL; +} + int erofs_fscache_register_fs(struct super_block *sb) { struct erofs_sb_info *sbi = EROFS_SB(sb); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 952a2f483f94..c6a3351a4d7d 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -97,6 +97,10 @@ struct erofs_sb_lz4_info { u16 max_pclusterblks; }; +struct erofs_fscache { + struct fscache_cookie *cookie; +}; + struct erofs_sb_info { struct erofs_mount_opts opt; /* options */ #ifdef CONFIG_EROFS_FS_ZIP @@ -626,9 +630,24 @@ static inline int z_erofs_load_lzma_config(struct super_block *sb, #ifdef CONFIG_EROFS_FS_ONDEMAND 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); +void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache); #else static inline int erofs_fscache_register_fs(struct super_block *sb) { return 0; } 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) +{ + return -EOPNOTSUPP; +} + +static inline void erofs_fscache_unregister_cookie(struct erofs_fscache **fscache) +{ +} #endif #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ -- 2.27.0