Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5687018pxb; Thu, 20 Jan 2022 02:28:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJx28qlS+E5fWVdo190POR1sN3qmtJ6eP2eG/sl0PuPN7nA1ZSoNer0XT0gI6mW+fvqHDzPK X-Received: by 2002:a17:902:da8c:b0:14a:909b:c911 with SMTP id j12-20020a170902da8c00b0014a909bc911mr29258293plx.103.1642674522115; Thu, 20 Jan 2022 02:28:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642674522; cv=none; d=google.com; s=arc-20160816; b=Rx3aaQGSL0AjtRepYvUx7FzDGpQ6X9nLj3k5WCZOdKlEJ0qG9y3QpYmSVzs2q03ix9 qEwnL2lrnOB4tATWap+jdUUHC18FowqyAOxzzRlEED7VTeGwoPsjoDkWw9bE22GvkCy5 UZF4HhTVoQ4ncgjnaA0tyo06FKAN3NRGqKpsXhocLi9DTboA/xhxsz5Qx8ORFLDNoRAp 7YBZ+irzcdhm48rVZhwN9eRZHZ4uPnjYHJ/hQtBmyfspdIrZmD27cZaskZiUWi3Fx5UM nJEUtTEwq0uc57T+olBQsChYUCV6c38aUXTKN+JEfKPCAxA9DofReaVO3wgmGcLZ6VXg Oy6w== 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=fzJPd+mwd9bkvyySmupp3z00xZoSj4wAuZMcBstO0+0=; b=JfqH5oMwIeqrTnJJxqFh6NUJLV9yt2/rRZ7Iad6gRYcYBRS1AhiGYz/495bnfvJdaY 4DGozZbFP8k2Eb8yC2CDuMmOsKc3yZEQOSdI6BpHdluCR6zlxlmYDGsBjo7nvDWhb7il UhApMsL+KEKKshjNwsbpPezcmGcI/4La7dlGuUK86YYStmQ7Xgi08LmTwfyjrTyFkQGt NVWeENcvdVQXLhcn+GEpAiMfc9wnaKrbsYqmUMvTCDQ5FPvSlj0wFiirVaax3Ttr62+1 SIraqIswf+lfIPBfxwYnUFKmfh5I1+y/y3oY0URL2REgO7LbnszkvJtsgimyXfR5yP3B 5PZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x9si3226436pfh.311.2022.01.20.02.28.30; Thu, 20 Jan 2022 02:28:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242324AbiARNMp (ORCPT + 99 others); Tue, 18 Jan 2022 08:12:45 -0500 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:44644 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242187AbiARNMc (ORCPT ); Tue, 18 Jan 2022 08:12:32 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;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=12;SR=0;TI=SMTPD_---0V2C2ax2_1642511549; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V2C2ax2_1642511549) by smtp.aliyun-inc.com(127.0.0.1); Tue, 18 Jan 2022 21:12:30 +0800 From: Jeffle Xu To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: 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 v2 11/20] erofs: add cookie context helper functions Date: Tue, 18 Jan 2022 21:12:07 +0800 Message-Id: <20220118131216.85338-12-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220118131216.85338-1-jefflexu@linux.alibaba.com> References: <20220118131216.85338-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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..10c3f5ea9e24 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_fscahce_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_fscahce_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