summaryrefslogtreecommitdiffstats
path: root/fs/overlayfs
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2017-11-10 09:39:15 +0100
committerMiklos Szeredi <mszeredi@redhat.com>2017-11-10 09:39:15 +0100
commit4155c10a0309523924b934b81d08aac03f15c990 (patch)
treeee9d57ad5bf2fe141c3e6fbf0bb39aad87bb9db7 /fs/overlayfs
parentovl: clean up workdir creation (diff)
downloadlinux-4155c10a0309523924b934b81d08aac03f15c990.tar.xz
linux-4155c10a0309523924b934b81d08aac03f15c990.zip
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>
Diffstat (limited to 'fs/overlayfs')
-rw-r--r--fs/overlayfs/super.c100
1 files changed, 48 insertions, 52 deletions
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 115cbf3303de..e4852cb1ec64 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -38,15 +38,20 @@ module_param_named(index, ovl_index_def, bool, 0644);
MODULE_PARM_DESC(ovl_index_def,
"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)
{
struct ovl_entry *oe = dentry->d_fsdata;
if (oe) {
- unsigned int i;
-
- for (i = 0; i < oe->numlower; i++)
- dput(oe->lowerstack[i].dentry);
+ ovl_entry_stack_free(oe);
kfree_rcu(oe, rcu);
}
}
@@ -1058,35 +1063,36 @@ out:
return err;
}
-static int ovl_get_lowerstack(struct super_block *sb, struct ovl_fs *ufs,
- struct path **stackp, unsigned int *stacklenp)
+static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
+ struct ovl_fs *ufs)
{
int err;
char *lowertmp, *lower;
- struct path *stack;
- unsigned int stacklen, numlower, i;
+ struct path *stack = NULL;
+ unsigned int stacklen, numlower = 0, i;
bool remote = false;
+ struct ovl_entry *oe;
err = -ENOMEM;
lowertmp = kstrdup(ufs->config.lowerdir, GFP_KERNEL);
if (!lowertmp)
- goto out;
+ goto out_err;
err = -EINVAL;
stacklen = ovl_split_lowerdirs(lowertmp);
if (stacklen > OVL_MAX_STACK) {
pr_err("overlayfs: too many lower directories, limit is %d\n",
OVL_MAX_STACK);
- goto out;
+ goto out_err;
} else if (!ufs->config.upperdir && stacklen == 1) {
pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n");
- goto out;
+ goto out_err;
}
err = -ENOMEM;
stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL);
if (!stack)
- goto out;
+ goto out_err;
err = -EINVAL;
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,
&sb->s_stack_depth, &remote);
if (err)
- goto out_free_stack;
+ goto out_err;
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++;
if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
pr_err("overlayfs: maximum fs stacking depth exceeded\n");
- goto out_free_stack;
+ goto out_err;
}
- *stackp = stack;
- *stacklenp = numlower;
+ err = ovl_get_lower_layers(ufs, stack, 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)
sb->s_d_op = &ovl_reval_dentry_operations;
else
sb->s_d_op = &ovl_dentry_operations;
- err = 0;
-
out:
- kfree(lowertmp);
- return err;
-
-out_free_stack:
for (i = 0; i < numlower; i++)
path_put(&stack[i]);
kfree(stack);
+ kfree(lowertmp);
+
+ return oe;
+
+out_err:
+ oe = ERR_PTR(err);
goto out;
}
@@ -1131,11 +1148,8 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
{
struct path upperpath = { };
struct dentry *root_dentry;
- struct ovl_entry *oe = NULL;
+ struct ovl_entry *oe;
struct ovl_fs *ufs;
- struct path *stack = NULL;
- unsigned int numlower = 0;
- unsigned int i;
struct cred *cred;
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;
}
- err = ovl_get_lowerstack(sb, ufs, &stack, &numlower);
- if (err)
- goto out_err;
-
- err = ovl_get_lower_layers(ufs, stack, numlower);
- if (err)
+ oe = ovl_get_lowerstack(sb, ufs);
+ err = PTR_ERR(oe);
+ if (IS_ERR(oe))
goto out_err;
/* 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)
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) {
err = ovl_get_indexdir(ufs, oe, &upperpath);
if (err)
- goto out_err;
+ goto out_free_oe;
if (!ufs->indexdir)
sb->s_flags |= MS_RDONLY;
@@ -1233,13 +1234,9 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
err = -ENOMEM;
root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
if (!root_dentry)
- goto out_err;
+ goto out_free_oe;
mntput(upperpath.mnt);
- for (i = 0; i < numlower; i++)
- mntput(stack[i].mnt);
- kfree(stack);
-
if (upperpath.dentry) {
oe->has_upper = true;
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;
-out_err:
+out_free_oe:
+ ovl_entry_stack_free(oe);
kfree(oe);
- for (i = 0; i < numlower; i++)
- path_put(&stack[i]);
- kfree(stack);
+out_err:
path_put(&upperpath);
ovl_free_fs(ufs);
out: