Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2214181pxb; Fri, 25 Mar 2022 13:10:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7ezPFvM9x2fFgoQzxRF5LIqgrL44VRuVS+jtVnSAgWPz73f/hy1l/KsBs97hr5ZFnSE2c X-Received: by 2002:a17:902:b7c9:b0:153:f2e4:18f0 with SMTP id v9-20020a170902b7c900b00153f2e418f0mr13328291plz.100.1648239045295; Fri, 25 Mar 2022 13:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648239045; cv=none; d=google.com; s=arc-20160816; b=oEgMGRlajIaeEMiJ60iJGLAfi/VQ0oVgrm+vYpkkr56Qi5xa+Fc6BjM4yZpyK5hTCi IWW49k7Lhbh2LrchKSlcZi6b5XHyGVNVDCzVf5GfviAC/STdtZvEqd4DBE5mIF+dr7uO sfikUYft9HoaFpUgvicXAKvmoV/RTWtg/dBikibs74LDi/UJo110ToywXh4mvxx7cpSy iThrIeTR7KdTjFbkUC0qu2LCY0FxHqB/aPs6zQUOJ6zh6SBY2KDCmDCadTdy6FG9CXXe fk0KUHRCUwkMlSP25dYhw4zybRbB6yf+kTo0KDgTAyCQBGf4o20XNlKeBtKOptfWdqlv nTWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date; bh=MdU/PKv5IV6MSPJEIHWvCAFe//b9qZjFiyT5ULnuEgU=; b=OTykNTn9jivb7XXjJlJxTh3rNnE2TGH9AJDtAP4/EAHBSkcPickWik1ju8gmsnH5SC foWthqOh9uNwHkRkvEP10i1b/mpus+l7JCDb3m2HWqKbQKuSlwgnQVfP8HJJG/l7Bfm+ 5TIzzGgJODDnR5KW8MCtwZiPDEEaTeN9FOZQRuB43Nq0dOnHGwCHYTTOH8dSKyu+Kz8V DFEQ87aIhFjSyT43u6t8JqmP/QibICBNwfyN6WZCEEI1W1HsQ3F5BnOJ7VvPCKCm57sB mGEBxbNNIHS/CVmRf7jrsGmYnJcRCwL4LD+N/2g/V/jCTPEjbkrSZIYIJ+aEpSOn7A0b 3cRQ== 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 w13-20020a63474d000000b00384b2898db2si3347845pgk.434.2022.03.25.13.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 13:10:45 -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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3DD131C6EEA; Fri, 25 Mar 2022 11:53:19 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357519AbiCYNnZ (ORCPT + 99 others); Fri, 25 Mar 2022 09:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233213AbiCYNnX (ORCPT ); Fri, 25 Mar 2022 09:43:23 -0400 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAD28CFBBB; Fri, 25 Mar 2022 06:41:48 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0V89jU5E_1648215702; Received: from B-P7TQMD6M-0146.local(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0V89jU5E_1648215702) by smtp.aliyun-inc.com(127.0.0.1); Fri, 25 Mar 2022 21:41:44 +0800 Date: Fri, 25 Mar 2022 21:41:42 +0800 From: Gao Xiang To: Jeffle Xu Cc: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, 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: Re: [PATCH v6 12/22] erofs: add cookie context helper functions Message-ID: Mail-Followup-To: Jeffle Xu , dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, 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 References: <20220325122223.102958-1-jefflexu@linux.alibaba.com> <20220325122223.102958-13-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220325122223.102958-13-jefflexu@linux.alibaba.com> 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 Hi Jeffle, On Fri, Mar 25, 2022 at 08:22:13PM +0800, Jeffle Xu wrote: > Introduce "struct erofs_fscache" for managing cookie for backinig file, > and helper functions for initializing and cleaning up this context > structure. > > Signed-off-by: Jeffle Xu > --- > fs/erofs/fscache.c | 61 +++++++++++++++++++++++++++++++++++++++++++++ > fs/erofs/internal.h | 14 +++++++++++ > 2 files changed, 75 insertions(+) > > diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c > index 08cf570a0810..73235fd43bf6 100644 > --- a/fs/erofs/fscache.c > +++ b/fs/erofs/fscache.c > @@ -7,6 +7,67 @@ > > static struct fscache_volume *volume; > > +static int erofs_fscache_init_cookie(struct erofs_fscache *ctx, char *path) > +{ > + struct fscache_cookie *cookie; > + > + cookie = fscache_acquire_cookie(volume, FSCACHE_ADV_WANT_CACHE_SIZE, > + path, strlen(path), > + NULL, 0, 0); It'd be better to rearrange in one line? 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 *ctx) > +{ > + struct fscache_cookie *cookie = ctx->cookie; > + > + fscache_unuse_cookie(cookie, NULL, NULL); > + fscache_relinquish_cookie(cookie, false); > + ctx->cookie = NULL; > +} > + > +/* > + * erofs_fscache_get - create an fscache context for blob file > + * @sb: superblock > + * @path: name of blob file > + * > + * Return: fscache context on success, ERR_PTR() on failure. > + */ > +struct erofs_fscache *erofs_fscache_get(struct super_block *sb, char *path) erofs_fscache_register? > +{ > + struct erofs_fscache *ctx; > + int ret; > + > + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); > + if (!ctx) > + return ERR_PTR(-ENOMEM); > + > + ret = erofs_fscache_init_cookie(ctx, path); Can we fold it here? No need to introduce such simple wrapper.. > + if (ret) { > + erofs_err(sb, "failed to init cookie"); It would be better to print the path? > + goto err; kfree(ctx); return ERR_PTR(ret); At least for now. > + } > + > + return ctx; > +err: > + kfree(ctx); > + return ERR_PTR(ret); > +} > + > +void erofs_fscache_put(struct erofs_fscache *ctx) erofs_fscache_unregister? > +{ > + if (!ctx) > + return; > + > + erofs_fscache_cleanup_cookie(ctx); Fold it too, since such helper doesn't simplify code a lot but need to take one more time to redirect.. Thanks, Gao Xiang > + 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 45b8b0dd8a27..d4f2b43cedae 100644 > --- a/fs/erofs/internal.h > +++ b/fs/erofs/internal.h > @@ -96,6 +96,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 > @@ -620,9 +624,19 @@ static inline int z_erofs_load_lzma_config(struct super_block *sb, > #ifdef CONFIG_EROFS_FS_ONDEMAND > int erofs_init_fscache(void); > void erofs_exit_fscache(void); > + > +struct erofs_fscache *erofs_fscache_get(struct super_block *sb, char *path); > +void erofs_fscache_put(struct erofs_fscache *ctx); > #else > static inline int erofs_init_fscache(void) { return 0; } > static inline void erofs_exit_fscache(void) {} > + > +static inline struct erofs_fscache *erofs_fscache_get(struct super_block *sb, > + char *path) > +{ > + return ERR_PTR(-EOPNOTSUPP); > +} > +static inline void erofs_fscache_put(struct erofs_fscache *ctx) {} > #endif > > #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ > -- > 2.27.0