Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp982639pxp; Wed, 16 Mar 2022 23:25:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLbXzADU7w9szG715z9zXj35O074eWGSveA71otovRVmdaG7lxE6VXgeTKBFP/DAUyB4Q1 X-Received: by 2002:a17:90a:4286:b0:1b8:8ba1:730c with SMTP id p6-20020a17090a428600b001b88ba1730cmr3544890pjg.181.1647498324885; Wed, 16 Mar 2022 23:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647498324; cv=none; d=google.com; s=arc-20160816; b=Kt4sbrjFqycyvTUmKdSvRycmNqPgr6kxgjlo9z7BnFCHmwYqLtF0xMDdojIFHFyT5e koZRnSdtnwrLiXKn+tQMm7NKykBHk7r6j1T+rEuF4YRBSpQ0qPhQIDeX+6j6pavjAL+u +xghYY/kMkWkhAViEvrIcpUGhL8GXFw7oLmNhO6JD8QqsSzljKg+S4KqLo76pn6iL8mP ZJkKhlKoZ8qwvM5EwgiHkJlQuKg3RVQ9pgn/bFmJWb/agT0FoDFgHLbPoN5YY2+A6Eq8 y8IlodvS4rsgPiMKQDIIovC41Tussf+My/xoM+PZCuSocTwPImG5EArmekYjHDEO7HJR LJMQ== 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=BMeSFaS1+ME09Vmf+dr3ckKC6ZKLK3KkdsyPfThte1s=; b=sEFb48rnMwT96rdLuZeWfLLy3WjTuaNKiSk+LEEHhtkqc4COmLEvEZYA4dJMXzmTpP i1ndOfDF6WrrjAHi1I+gSym1WKSXUPkUXztvc+68axVGTx0ePMET9QloLincBTQfa15M 9b+a5Haw8OvcvJVaflziREaU1EWCOZ+9wsigHuiNCJFvAdbGJY2HtHqtZr66YuxJVkhh IfLjil41bJO699BOvN9n3ncmvfzjy4J+vSh6cUEwFNjFtKFMZkx8A7nJDNi5TpsN3dDl 2q1heWqnNRWFgAlIdtXnJuHBiYSx+ntT7pA/GP6P41CqFBcPTStKAa5RBUCVNQCUw3w+ Ytsg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id j15-20020a63b60f000000b003816043efcbsi1242885pgf.448.2022.03.16.23.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:25:24 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 020F428182D; Wed, 16 Mar 2022 22:11:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356337AbiCPNTo (ORCPT + 99 others); Wed, 16 Mar 2022 09:19:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356260AbiCPNTH (ORCPT ); Wed, 16 Mar 2022 09:19:07 -0400 Received: from out199-12.us.a.mail.aliyun.com (out199-12.us.a.mail.aliyun.com [47.90.199.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79DA8EB3; Wed, 16 Mar 2022 06:17:47 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0V7MlTAu_1647436661; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V7MlTAu_1647436661) by smtp.aliyun-inc.com(127.0.0.1); Wed, 16 Mar 2022 21:17:42 +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 Subject: [PATCH v5 12/22] erofs: add cookie context helper functions Date: Wed, 16 Mar 2022 21:17:13 +0800 Message-Id: <20220316131723.111553-13-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220316131723.111553-1-jefflexu@linux.alibaba.com> References: <20220316131723.111553-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 'struct erofs_cookie_ctx' for managing cookie for backing file, and the following introduced API for reading from backing file. Besides, introduce two helper functions for initializing and cleaning up erofs_cookie_ctx. struct erofs_cookie_ctx * erofs_fscache_get_ctx(struct super_block *sb, char *path); void erofs_fscache_put_ctx(struct erofs_cookie_ctx *ctx); Signed-off-by: Jeffle Xu --- fs/erofs/fscache.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/internal.h | 8 +++++ 2 files changed, 82 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 9c32f42e1056..28ec7c69744a 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -6,6 +6,80 @@ static struct fscache_volume *volume; +static int erofs_fscache_init_cookie(struct erofs_fscache_context *ctx, + char *path) +{ + struct fscache_cookie *cookie; + + cookie = fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE, + path, strlen(path), + NULL, 0, 0); + if (!cookie) + return -EINVAL; + + fscache_use_cookie(cookie, false); + ctx->cookie = cookie; + return 0; +} + +static inline +void erofs_fscache_cleanup_cookie(struct erofs_fscache_context *ctx) +{ + struct fscache_cookie *cookie = ctx->cookie; + + fscache_unuse_cookie(cookie, NULL, NULL); + fscache_relinquish_cookie(cookie, false); + ctx->cookie = NULL; +} + +static int erofs_fscache_init_ctx(struct erofs_fscache_context *ctx, + struct super_block *sb, char *path) +{ + int ret; + + ret = erofs_fscache_init_cookie(ctx, path); + if (ret) { + erofs_err(sb, "failed to init cookie"); + return ret; + } + + return 0; +} + +static inline +void erofs_fscache_cleanup_ctx(struct erofs_fscache_context *ctx) +{ + erofs_fscache_cleanup_cookie(ctx); +} + +struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, + char *path) +{ + struct erofs_fscache_context *ctx; + int ret; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return ERR_PTR(-ENOMEM); + + ret = erofs_fscache_init_ctx(ctx, sb, path); + if (ret) { + kfree(ctx); + return ERR_PTR(ret); + } + + return ctx; +} + +void erofs_fscache_put_ctx(struct erofs_fscache_context *ctx) +{ + if (!ctx) + return; + + erofs_fscache_cleanup_ctx(ctx); + kfree(ctx); +} + int __init erofs_init_fscache(void) { volume = fscache_acquire_volume("erofs", NULL, NULL, 0); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 51fe5c2a419d..123a8dfc179b 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_context { + struct fscache_cookie *cookie; +}; + struct erofs_sb_info { struct erofs_mount_opts opt; /* options */ #ifdef CONFIG_EROFS_FS_ZIP @@ -621,6 +625,10 @@ static inline int z_erofs_load_lzma_config(struct super_block *sb, int erofs_init_fscache(void); void erofs_exit_fscache(void); +struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, + char *path); +void erofs_fscache_put_ctx(struct erofs_fscache_context *ctx); + #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ #endif /* __EROFS_INTERNAL_H */ -- 2.27.0