Commit 7d419637 authored by Jia Zhu's avatar Jia Zhu Committed by Gao Xiang

erofs: Support sharing cookies in the same domain

Several erofs filesystems can belong to one domain, and data blobs can
be shared among these erofs filesystems of same domain.

Users could specify domain_id mount option to create or join into a
domain.
Signed-off-by: default avatarJia Zhu <zhujia.zj@bytedance.com>
Reviewed-by: default avatarJingbo Xu <jefflexu@linux.alibaba.com>
Link: https://lore.kernel.org/r/20220918110150.6338-1-zhujia.zj@bytedance.comSigned-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent a9849560
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "internal.h" #include "internal.h"
static DEFINE_MUTEX(erofs_domain_list_lock); static DEFINE_MUTEX(erofs_domain_list_lock);
static DEFINE_MUTEX(erofs_domain_cookies_lock);
static LIST_HEAD(erofs_domain_list); static LIST_HEAD(erofs_domain_list);
static struct vfsmount *erofs_pseudo_mnt; static struct vfsmount *erofs_pseudo_mnt;
...@@ -531,8 +532,9 @@ static int erofs_fscache_register_domain(struct super_block *sb) ...@@ -531,8 +532,9 @@ static int erofs_fscache_register_domain(struct super_block *sb)
return err; return err;
} }
struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, static
char *name, bool need_inode) struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb,
char *name, bool need_inode)
{ {
struct fscache_volume *volume = EROFS_SB(sb)->volume; struct fscache_volume *volume = EROFS_SB(sb)->volume;
struct erofs_fscache *ctx; struct erofs_fscache *ctx;
...@@ -581,17 +583,102 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, ...@@ -581,17 +583,102 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
return ERR_PTR(ret); return ERR_PTR(ret);
} }
void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx)
{ {
if (!ctx)
return;
fscache_unuse_cookie(ctx->cookie, NULL, NULL); fscache_unuse_cookie(ctx->cookie, NULL, NULL);
fscache_relinquish_cookie(ctx->cookie, false); fscache_relinquish_cookie(ctx->cookie, false);
iput(ctx->inode); iput(ctx->inode);
kfree(ctx->name);
kfree(ctx); kfree(ctx);
} }
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) {
err = -ENOMEM;
goto out;
}
ctx->domain = domain;
ctx->anon_inode = inode;
inode->i_private = ctx;
refcount_inc(&domain->ref);
return ctx;
out:
erofs_fscache_relinquish_cookie(ctx);
return ERR_PTR(err);
}
static
struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb,
char *name, bool need_inode)
{
struct inode *inode;
struct erofs_fscache *ctx;
struct erofs_domain *domain = EROFS_SB(sb)->domain;
struct super_block *psb = erofs_pseudo_mnt->mnt_sb;
mutex_lock(&erofs_domain_cookies_lock);
list_for_each_entry(inode, &psb->s_inodes, i_sb_list) {
ctx = inode->i_private;
if (!ctx || ctx->domain != domain || strcmp(ctx->name, name))
continue;
igrab(inode);
mutex_unlock(&erofs_domain_cookies_lock);
return ctx;
}
ctx = erofs_fscache_domain_init_cookie(sb, name, need_inode);
mutex_unlock(&erofs_domain_cookies_lock);
return ctx;
}
struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb,
char *name, bool need_inode)
{
if (EROFS_SB(sb)->opt.domain_id)
return erofs_domain_register_cookie(sb, name, need_inode);
return erofs_fscache_acquire_cookie(sb, name, need_inode);
}
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;
}
erofs_fscache_relinquish_cookie(ctx);
erofs_fscache_domain_put(domain);
}
int erofs_fscache_register_fs(struct super_block *sb) int erofs_fscache_register_fs(struct super_block *sb)
{ {
int ret; int ret;
......
...@@ -109,6 +109,9 @@ struct erofs_domain { ...@@ -109,6 +109,9 @@ struct erofs_domain {
struct erofs_fscache { struct erofs_fscache {
struct fscache_cookie *cookie; struct fscache_cookie *cookie;
struct inode *inode; struct inode *inode;
struct inode *anon_inode;
struct erofs_domain *domain;
char *name;
}; };
struct erofs_sb_info { struct erofs_sb_info {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment