Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1050357pxb; Wed, 6 Apr 2022 07:33:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzesJDDkXAGIO/3t+5Pzqk9Muqz9waghWarPy/C/lIT1kQRH+R/kGS0Vb7QoIKhMM603H/t X-Received: by 2002:a17:902:d4c6:b0:156:78c:8486 with SMTP id o6-20020a170902d4c600b00156078c8486mr9043143plg.85.1649255621988; Wed, 06 Apr 2022 07:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649255621; cv=none; d=google.com; s=arc-20160816; b=RyDQHoj4PZCmJpUQiXrvTSX7ZBo5xF7QKQMriPsOvD6siQAGRLLdVn5FvnydtApom3 ywKb+Cou/2aigucmjjuvTPlU1GXXOyAjzqLNydC1543fblFQ0neuyUeJpN9oQz0vFy/A xGtlxy766sW7cPz3pbtS9qFjo7IsYaA3Jgp3QR6lOOCSLKyRw1G95yvLv7txvVrz3rt7 IbWPLmMceb8rrSLXxVQm0akXp6dXHaBLT2AW21FiCZFN6WwmMeRXzHpM8kFJWBWLUNzg 0plKXEVGrQKQEzCYtNeBs73b8YH3FrKKFa1EGWLQK9NID32SLWXP2UzB/qBUp996MiqA ZQHQ== 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=YFErrEJDEY1gMIUTSCkXpYZ30FtQ/bLwYClBuzdvVtoSCd5jJCPlqCbLlPOqfbv6dl x7VqiHI6/yfquWCerkoOXOGp3bseRmhZnZQ/qJhXSe0JuqUDZz/zzf038Av07LEpF6Px 6Nr/UKlLQDKcnAiX24vEJu8XYjyGd5w/xhMVaGHeIEj5So6OcigylYb2lGcRfPrSVZtY hj4CzXUI6UkvtA+FySnd067CLOyUkTqT+CKwc0SRyQUzpQJiWlNbC1gQNXa4H9wNlRGZ XhlfJzJkihGwjsLoK9+YZK2IFW/01DHJnpvi6mZzS4rmQFrbA8w3PaOaLb4mhEaURZ7e c3Ig== 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: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r19-20020a63a553000000b0039805dffc6esi16105954pgu.353.2022.04.06.07.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 07:33:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C9F87517A70; Wed, 6 Apr 2022 05:15:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbiDFMPo (ORCPT + 99 others); Wed, 6 Apr 2022 08:15:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbiDFMOJ (ORCPT ); Wed, 6 Apr 2022 08:14:09 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A29425E00; Wed, 6 Apr 2022 00:56:34 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;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=18;SR=0;TI=SMTPD_---0V9LC86s_1649231790; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V9LC86s_1649231790) by smtp.aliyun-inc.com(127.0.0.1); Wed, 06 Apr 2022 15:56: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: 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 v8 11/20] erofs: add fscache context helper functions Date: Wed, 6 Apr 2022 15:56:03 +0800 Message-Id: <20220406075612.60298-12-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220406075612.60298-1-jefflexu@linux.alibaba.com> References: <20220406075612.60298-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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