Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1788883pxb; Wed, 9 Feb 2022 04:39:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwj9rTjaEmmtG6jk8tGnkAwc9CNpacK+oY69Gn/uRxHtaUDE19olEb5GpDsC8vNv35dZ/6t X-Received: by 2002:a17:902:8205:: with SMTP id x5mr2230694pln.40.1644410361330; Wed, 09 Feb 2022 04:39:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644410361; cv=none; d=google.com; s=arc-20160816; b=p7cyA2MsG7Cjfct02fzVdBoGbM5X+AhfDEpSdvf/YQiGqtGIp7q4+tOk0jLasV4j7B cjtPhpoojXPoDLxF7M7uyRd678JGci17EpH3CCM2gmDFtJHEvP0OEAPGrf3g/6uf0OD/ xJidgtswhQXxRAY3OS0zlMqdwln2WoecSJXCIhQPD3skQ1rltqKlO60eYLcH0waeP1uC ZKnxglBQxF5iwn95EZrVaS9oZzPkeuV9cWkQ00cYZTdISulkGWlvJaZHpJ6QK6CHwB+S PAvQGPgXp4hTSwXKvGbR4JXILGhjKeedU43XqC1RoggDYDFZ7vGVjk/9J0Vs6e3Dw5fI oYJw== 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=hjgCQfKEMLRdQxfXlq2b5tvs1YsjbFBcAN+zBxBoaNE=; b=cZ8zTopIh0aCxrym5dtaIQQWw1YoezaEaCF3fX9IprXGcaVWbjCcPXA+PrVrVEf8xm zQOntTrd1BqtDKjetpa/sAQ0ObLn4rq+Ve2hAN8730rDqry95wQQohLj3qJktW7qXbLl qmFE1mQJRdHRkeBKzqNI0qiPqH94dzeDICW83j+bqRFcxPRpKbLpWU0z1vj59ZT1ScOd w692WBT7d4E9JnhOLgRdqIlk4+xY5Oe6n0G3/KH+rFBt6Y0CXTr57C81qZTAmUjU6plQ dsGhoiZAkSXOlT7lOcpy6+OBtaxj9rygiWN8KyjQ1wbwRUqZqC/cWSN2XgF4eOoi1Q+o nXpg== 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 y9si2612762plr.610.2022.02.09.04.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 04:39:21 -0800 (PST) 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 1E4C3E0918C2; Wed, 9 Feb 2022 02:24:56 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236712AbiBIGDD (ORCPT + 99 others); Wed, 9 Feb 2022 01:03:03 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:52096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233578AbiBIGB0 (ORCPT ); Wed, 9 Feb 2022 01:01:26 -0500 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21CBAC05CB86; Tue, 8 Feb 2022 22:01:27 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R491e4;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=15;SR=0;TI=SMTPD_---0V3zwJlp_1644386481; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V3zwJlp_1644386481) by smtp.aliyun-inc.com(127.0.0.1); Wed, 09 Feb 2022 14:01:22 +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 Subject: [PATCH v3 10/22] erofs: add cookie context helper functions Date: Wed, 9 Feb 2022 14:00:56 +0800 Message-Id: <20220209060108.43051-11-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220209060108.43051-1-jefflexu@linux.alibaba.com> References: <20220209060108.43051-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 | 78 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/internal.h | 8 +++++ 2 files changed, 86 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 9c32f42e1056..c043d7709d65 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -6,6 +6,84 @@ static struct fscache_volume *volume; +static int erofs_fscache_init_cookie(struct erofs_fscache_context *ctx, + char *path) +{ + struct fscache_cookie *cookie; + + /* + * @object_size shall be non-zero to avoid + * FSCACHE_COOKIE_NO_DATA_TO_READ. + */ + cookie = fscache_acquire_cookie(volume, 0, + path, strlen(path), + NULL, 0, -1); + 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 c2608a469107..1f5bc69e8e9f 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