ovl: clean up getting lower layers
Move calling ovl_get_lower_layers() into ovl_get_lowerstack(). ovl_get_lowerstack() now returns the root dentry's filled in ovl_entry. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
parent
bca44b52f8
commit
4155c10a03
|
@ -38,15 +38,20 @@ module_param_named(index, ovl_index_def, bool, 0644);
|
||||||
MODULE_PARM_DESC(ovl_index_def,
|
MODULE_PARM_DESC(ovl_index_def,
|
||||||
"Default to on or off for the inodes index feature");
|
"Default to on or off for the inodes index feature");
|
||||||
|
|
||||||
|
static void ovl_entry_stack_free(struct ovl_entry *oe)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < oe->numlower; i++)
|
||||||
|
dput(oe->lowerstack[i].dentry);
|
||||||
|
}
|
||||||
|
|
||||||
static void ovl_dentry_release(struct dentry *dentry)
|
static void ovl_dentry_release(struct dentry *dentry)
|
||||||
{
|
{
|
||||||
struct ovl_entry *oe = dentry->d_fsdata;
|
struct ovl_entry *oe = dentry->d_fsdata;
|
||||||
|
|
||||||
if (oe) {
|
if (oe) {
|
||||||
unsigned int i;
|
ovl_entry_stack_free(oe);
|
||||||
|
|
||||||
for (i = 0; i < oe->numlower; i++)
|
|
||||||
dput(oe->lowerstack[i].dentry);
|
|
||||||
kfree_rcu(oe, rcu);
|
kfree_rcu(oe, rcu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1058,35 +1063,36 @@ out:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ovl_get_lowerstack(struct super_block *sb, struct ovl_fs *ufs,
|
static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
|
||||||
struct path **stackp, unsigned int *stacklenp)
|
struct ovl_fs *ufs)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
char *lowertmp, *lower;
|
char *lowertmp, *lower;
|
||||||
struct path *stack;
|
struct path *stack = NULL;
|
||||||
unsigned int stacklen, numlower, i;
|
unsigned int stacklen, numlower = 0, i;
|
||||||
bool remote = false;
|
bool remote = false;
|
||||||
|
struct ovl_entry *oe;
|
||||||
|
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
lowertmp = kstrdup(ufs->config.lowerdir, GFP_KERNEL);
|
lowertmp = kstrdup(ufs->config.lowerdir, GFP_KERNEL);
|
||||||
if (!lowertmp)
|
if (!lowertmp)
|
||||||
goto out;
|
goto out_err;
|
||||||
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
stacklen = ovl_split_lowerdirs(lowertmp);
|
stacklen = ovl_split_lowerdirs(lowertmp);
|
||||||
if (stacklen > OVL_MAX_STACK) {
|
if (stacklen > OVL_MAX_STACK) {
|
||||||
pr_err("overlayfs: too many lower directories, limit is %d\n",
|
pr_err("overlayfs: too many lower directories, limit is %d\n",
|
||||||
OVL_MAX_STACK);
|
OVL_MAX_STACK);
|
||||||
goto out;
|
goto out_err;
|
||||||
} else if (!ufs->config.upperdir && stacklen == 1) {
|
} else if (!ufs->config.upperdir && stacklen == 1) {
|
||||||
pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n");
|
pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n");
|
||||||
goto out;
|
goto out_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL);
|
stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL);
|
||||||
if (!stack)
|
if (!stack)
|
||||||
goto out;
|
goto out_err;
|
||||||
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
lower = lowertmp;
|
lower = lowertmp;
|
||||||
|
@ -1094,7 +1100,7 @@ static int ovl_get_lowerstack(struct super_block *sb, struct ovl_fs *ufs,
|
||||||
err = ovl_lower_dir(lower, &stack[numlower], ufs,
|
err = ovl_lower_dir(lower, &stack[numlower], ufs,
|
||||||
&sb->s_stack_depth, &remote);
|
&sb->s_stack_depth, &remote);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_free_stack;
|
goto out_err;
|
||||||
|
|
||||||
lower = strchr(lower, '\0') + 1;
|
lower = strchr(lower, '\0') + 1;
|
||||||
}
|
}
|
||||||
|
@ -1103,27 +1109,38 @@ static int ovl_get_lowerstack(struct super_block *sb, struct ovl_fs *ufs,
|
||||||
sb->s_stack_depth++;
|
sb->s_stack_depth++;
|
||||||
if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
|
if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
|
||||||
pr_err("overlayfs: maximum fs stacking depth exceeded\n");
|
pr_err("overlayfs: maximum fs stacking depth exceeded\n");
|
||||||
goto out_free_stack;
|
goto out_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
*stackp = stack;
|
err = ovl_get_lower_layers(ufs, stack, numlower);
|
||||||
*stacklenp = numlower;
|
if (err)
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
err = -ENOMEM;
|
||||||
|
oe = ovl_alloc_entry(numlower);
|
||||||
|
if (!oe)
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
for (i = 0; i < numlower; i++) {
|
||||||
|
oe->lowerstack[i].dentry = dget(stack[i].dentry);
|
||||||
|
oe->lowerstack[i].layer = &ufs->lower_layers[i];
|
||||||
|
}
|
||||||
|
|
||||||
if (remote)
|
if (remote)
|
||||||
sb->s_d_op = &ovl_reval_dentry_operations;
|
sb->s_d_op = &ovl_reval_dentry_operations;
|
||||||
else
|
else
|
||||||
sb->s_d_op = &ovl_dentry_operations;
|
sb->s_d_op = &ovl_dentry_operations;
|
||||||
|
|
||||||
err = 0;
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
kfree(lowertmp);
|
|
||||||
return err;
|
|
||||||
|
|
||||||
out_free_stack:
|
|
||||||
for (i = 0; i < numlower; i++)
|
for (i = 0; i < numlower; i++)
|
||||||
path_put(&stack[i]);
|
path_put(&stack[i]);
|
||||||
kfree(stack);
|
kfree(stack);
|
||||||
|
kfree(lowertmp);
|
||||||
|
|
||||||
|
return oe;
|
||||||
|
|
||||||
|
out_err:
|
||||||
|
oe = ERR_PTR(err);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1131,11 +1148,8 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
{
|
{
|
||||||
struct path upperpath = { };
|
struct path upperpath = { };
|
||||||
struct dentry *root_dentry;
|
struct dentry *root_dentry;
|
||||||
struct ovl_entry *oe = NULL;
|
struct ovl_entry *oe;
|
||||||
struct ovl_fs *ufs;
|
struct ovl_fs *ufs;
|
||||||
struct path *stack = NULL;
|
|
||||||
unsigned int numlower = 0;
|
|
||||||
unsigned int i;
|
|
||||||
struct cred *cred;
|
struct cred *cred;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -1184,12 +1198,9 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
sb->s_time_gran = ufs->upper_mnt->mnt_sb->s_time_gran;
|
sb->s_time_gran = ufs->upper_mnt->mnt_sb->s_time_gran;
|
||||||
|
|
||||||
}
|
}
|
||||||
err = ovl_get_lowerstack(sb, ufs, &stack, &numlower);
|
oe = ovl_get_lowerstack(sb, ufs);
|
||||||
if (err)
|
err = PTR_ERR(oe);
|
||||||
goto out_err;
|
if (IS_ERR(oe))
|
||||||
|
|
||||||
err = ovl_get_lower_layers(ufs, stack, numlower);
|
|
||||||
if (err)
|
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
/* If the upper fs is nonexistent, we mark overlayfs r/o too */
|
/* If the upper fs is nonexistent, we mark overlayfs r/o too */
|
||||||
|
@ -1198,20 +1209,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
else if (ufs->upper_mnt->mnt_sb != ufs->same_sb)
|
else if (ufs->upper_mnt->mnt_sb != ufs->same_sb)
|
||||||
ufs->same_sb = NULL;
|
ufs->same_sb = NULL;
|
||||||
|
|
||||||
err = -ENOMEM;
|
|
||||||
oe = ovl_alloc_entry(numlower);
|
|
||||||
if (!oe)
|
|
||||||
goto out_err;
|
|
||||||
|
|
||||||
for (i = 0; i < numlower; i++) {
|
|
||||||
oe->lowerstack[i].dentry = stack[i].dentry;
|
|
||||||
oe->lowerstack[i].layer = &(ufs->lower_layers[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(ovl_force_readonly(ufs)) && ufs->config.index) {
|
if (!(ovl_force_readonly(ufs)) && ufs->config.index) {
|
||||||
err = ovl_get_indexdir(ufs, oe, &upperpath);
|
err = ovl_get_indexdir(ufs, oe, &upperpath);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_err;
|
goto out_free_oe;
|
||||||
|
|
||||||
if (!ufs->indexdir)
|
if (!ufs->indexdir)
|
||||||
sb->s_flags |= MS_RDONLY;
|
sb->s_flags |= MS_RDONLY;
|
||||||
|
@ -1233,13 +1234,9 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
|
root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
|
||||||
if (!root_dentry)
|
if (!root_dentry)
|
||||||
goto out_err;
|
goto out_free_oe;
|
||||||
|
|
||||||
mntput(upperpath.mnt);
|
mntput(upperpath.mnt);
|
||||||
for (i = 0; i < numlower; i++)
|
|
||||||
mntput(stack[i].mnt);
|
|
||||||
kfree(stack);
|
|
||||||
|
|
||||||
if (upperpath.dentry) {
|
if (upperpath.dentry) {
|
||||||
oe->has_upper = true;
|
oe->has_upper = true;
|
||||||
if (ovl_is_impuredir(upperpath.dentry))
|
if (ovl_is_impuredir(upperpath.dentry))
|
||||||
|
@ -1257,11 +1254,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_err:
|
out_free_oe:
|
||||||
|
ovl_entry_stack_free(oe);
|
||||||
kfree(oe);
|
kfree(oe);
|
||||||
for (i = 0; i < numlower; i++)
|
out_err:
|
||||||
path_put(&stack[i]);
|
|
||||||
kfree(stack);
|
|
||||||
path_put(&upperpath);
|
path_put(&upperpath);
|
||||||
ovl_free_fs(ufs);
|
ovl_free_fs(ufs);
|
||||||
out:
|
out:
|
||||||
|
|
Loading…
Reference in New Issue