[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1ccf326e-dd47-d5cf-02ab-5f033892a7d4@linux.alibaba.com>
Date: Fri, 16 Sep 2022 11:45:12 +0800
From: JeffleXu <jefflexu@...ux.alibaba.com>
To: Jia Zhu <zhujia.zj@...edance.com>, linux-erofs@...ts.ozlabs.org
Cc: linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
yinxin.x@...edance.com
Subject: Re: [PATCH V4 5/6] erofs: Support sharing cookies in the same domain
On 9/15/22 8:42 PM, Jia Zhu wrote:
> +static
> +struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block *sb,
> + char *name, bool need_inode)
> +{
> + int err;
> + struct inode *inode;
> + struct erofs_fscache *ctx;
> + struct erofs_domain *domain = EROFS_SB(sb)->domain;
> +
> + ctx = erofs_fscache_acquire_cookie(sb, name, need_inode);
> + if (IS_ERR(ctx))
> + return ctx;
> +
> + ctx->name = kstrdup(name, GFP_KERNEL);
> + if (!ctx->name) {
> + err = -ENOMEM;
> + goto out;
> + }
> +
> + inode = new_inode(erofs_pseudo_mnt->mnt_sb);
> + if (!inode) {
> + kfree(ctx->name);
> + err = -ENOMEM;
> + goto out;
> + }
> +
> + ctx->domain = domain;
> + ctx->anon_inode = inode;
> + inode->i_private = ctx;
> + refcount_inc(&domain->ref);
> + return ctx;
> +out:
> + fscache_unuse_cookie(ctx->cookie, NULL, NULL);
> + fscache_relinquish_cookie(ctx->cookie, false);
> + if (need_inode)
> + iput(ctx->inode);
> + kfree(ctx);
> + return ERR_PTR(err);
Could you please abstract the cleanup logic into one helper? like:
erofs_fscache_relinquish_cookie()
{
fscache_unuse_cookie(ctx->cookie, NULL, NULL);
fscache_relinquish_cookie(ctx->cookie, false);
iput(ctx->inode);
kfree(ctx->name);
kfree(ctx);
}
which could also be called in erofs_fscache_unregister_cookie().
> void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx)
> {
> + bool drop;
> + struct erofs_domain *domain;
> +
> if (!ctx)
> return;
> + domain = ctx->domain;
> + if (domain) {
> + mutex_lock(&erofs_domain_cookies_lock);
> + drop = atomic_read(&ctx->anon_inode->i_count) == 1;
> + iput(ctx->anon_inode);
> + mutex_unlock(&erofs_domain_cookies_lock);
> + if (!drop)
> + return;
> + }
>
> fscache_unuse_cookie(ctx->cookie, NULL, NULL);
> fscache_relinquish_cookie(ctx->cookie, false);
> + erofs_fscache_domain_put(domain);
> iput(ctx->inode);
> + kfree(ctx->name);
> kfree(ctx);
> }
--
Thanks,
Jingbo
Powered by blists - more mailing lists