Commit a9075cdb authored by Miklos Szeredi's avatar Miklos Szeredi

ovl: factor out ovl_free_fs() helper

This can be called both from ovl_put_super() and in the error cleanup path
from ovl_fill_super().
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 95e6d417
...@@ -206,9 +206,8 @@ static void ovl_destroy_inode(struct inode *inode) ...@@ -206,9 +206,8 @@ static void ovl_destroy_inode(struct inode *inode)
call_rcu(&inode->i_rcu, ovl_i_callback); call_rcu(&inode->i_rcu, ovl_i_callback);
} }
static void ovl_put_super(struct super_block *sb) static void ovl_free_fs(struct ovl_fs *ufs)
{ {
struct ovl_fs *ufs = sb->s_fs_info;
unsigned i; unsigned i;
dput(ufs->indexdir); dput(ufs->indexdir);
...@@ -216,7 +215,7 @@ static void ovl_put_super(struct super_block *sb) ...@@ -216,7 +215,7 @@ static void ovl_put_super(struct super_block *sb)
if (ufs->workdir_locked) if (ufs->workdir_locked)
ovl_inuse_unlock(ufs->workbasedir); ovl_inuse_unlock(ufs->workbasedir);
dput(ufs->workbasedir); dput(ufs->workbasedir);
if (ufs->upper_mnt && ufs->upperdir_locked) if (ufs->upperdir_locked)
ovl_inuse_unlock(ufs->upper_mnt->mnt_root); ovl_inuse_unlock(ufs->upper_mnt->mnt_root);
mntput(ufs->upper_mnt); mntput(ufs->upper_mnt);
for (i = 0; i < ufs->numlower; i++) { for (i = 0; i < ufs->numlower; i++) {
...@@ -228,10 +227,18 @@ static void ovl_put_super(struct super_block *sb) ...@@ -228,10 +227,18 @@ static void ovl_put_super(struct super_block *sb)
kfree(ufs->config.lowerdir); kfree(ufs->config.lowerdir);
kfree(ufs->config.upperdir); kfree(ufs->config.upperdir);
kfree(ufs->config.workdir); kfree(ufs->config.workdir);
put_cred(ufs->creator_cred); if (ufs->creator_cred)
put_cred(ufs->creator_cred);
kfree(ufs); kfree(ufs);
} }
static void ovl_put_super(struct super_block *sb)
{
struct ovl_fs *ofs = sb->s_fs_info;
ovl_free_fs(ofs);
}
static int ovl_sync_fs(struct super_block *sb, int wait) static int ovl_sync_fs(struct super_block *sb, int wait)
{ {
struct ovl_fs *ufs = sb->s_fs_info; struct ovl_fs *ufs = sb->s_fs_info;
...@@ -1131,7 +1138,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1131,7 +1138,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
struct path upperpath = { }; struct path upperpath = { };
struct path workpath = { }; struct path workpath = { };
struct dentry *root_dentry; struct dentry *root_dentry;
struct ovl_entry *oe; struct ovl_entry *oe = NULL;
struct ovl_fs *ufs; struct ovl_fs *ufs;
struct path *stack = NULL; struct path *stack = NULL;
unsigned int numlower = 0; unsigned int numlower = 0;
...@@ -1148,13 +1155,13 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1148,13 +1155,13 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
ufs->config.index = ovl_index_def; ufs->config.index = ovl_index_def;
err = ovl_parse_opt((char *) data, &ufs->config); err = ovl_parse_opt((char *) data, &ufs->config);
if (err) if (err)
goto out_free_config; goto out_err;
err = -EINVAL; err = -EINVAL;
if (!ufs->config.lowerdir) { if (!ufs->config.lowerdir) {
if (!silent) if (!silent)
pr_err("overlayfs: missing 'lowerdir'\n"); pr_err("overlayfs: missing 'lowerdir'\n");
goto out_free_config; goto out_err;
} }
sb->s_stack_depth = 0; sb->s_stack_depth = 0;
...@@ -1162,38 +1169,38 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1162,38 +1169,38 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
if (ufs->config.upperdir) { if (ufs->config.upperdir) {
if (!ufs->config.workdir) { if (!ufs->config.workdir) {
pr_err("overlayfs: missing 'workdir'\n"); pr_err("overlayfs: missing 'workdir'\n");
goto out_free_config; goto out_err;
} }
err = ovl_get_upperpath(ufs, &upperpath); err = ovl_get_upperpath(ufs, &upperpath);
if (err) if (err)
goto out_unlock_upperdentry; goto out_err;
err = ovl_get_workpath(ufs, &upperpath, &workpath); err = ovl_get_workpath(ufs, &upperpath, &workpath);
if (err) if (err)
goto out_unlock_workdentry; goto out_err;
sb->s_stack_depth = upperpath.mnt->mnt_sb->s_stack_depth; sb->s_stack_depth = upperpath.mnt->mnt_sb->s_stack_depth;
} }
err = ovl_get_lowerstack(sb, ufs, &stack, &numlower); err = ovl_get_lowerstack(sb, ufs, &stack, &numlower);
if (err) if (err)
goto out_unlock_workdentry; goto out_err;
if (ufs->config.upperdir) { if (ufs->config.upperdir) {
err = ovl_get_upper(ufs, &upperpath); err = ovl_get_upper(ufs, &upperpath);
if (err) if (err)
goto out_put_lowerpath; goto out_err;
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_workdir(sb, ufs, &workpath); err = ovl_get_workdir(sb, ufs, &workpath);
if (err) if (err)
goto out_put_workdir; goto out_err;
} }
err = ovl_get_lower_layers(ufs, stack, numlower); err = ovl_get_lower_layers(ufs, stack, numlower);
if (err) if (err)
goto out_put_lower_layers; 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 */
if (!ufs->upper_mnt) if (!ufs->upper_mnt)
...@@ -1204,7 +1211,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1204,7 +1211,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
err = -ENOMEM; err = -ENOMEM;
oe = ovl_alloc_entry(numlower); oe = ovl_alloc_entry(numlower);
if (!oe) if (!oe)
goto out_put_lower_layers; goto out_err;
for (i = 0; i < numlower; i++) { for (i = 0; i < numlower; i++) {
oe->lowerstack[i].dentry = stack[i].dentry; oe->lowerstack[i].dentry = stack[i].dentry;
...@@ -1214,7 +1221,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1214,7 +1221,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
if (!(ovl_force_readonly(ufs)) && ufs->config.index) { if (!(ovl_force_readonly(ufs)) && ufs->config.index) {
err = ovl_get_indexdir(sb, ufs, oe, &upperpath); err = ovl_get_indexdir(sb, ufs, oe, &upperpath);
if (err) if (err)
goto out_put_indexdir; goto out_err;
} }
/* Show index=off/on in /proc/mounts for any of the reasons above */ /* Show index=off/on in /proc/mounts for any of the reasons above */
...@@ -1224,7 +1231,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1224,7 +1231,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
err = -ENOMEM; err = -ENOMEM;
ufs->creator_cred = cred = prepare_creds(); ufs->creator_cred = cred = prepare_creds();
if (!cred) if (!cred)
goto out_put_indexdir; goto out_err;
/* Never override disk quota limits or use reserved space */ /* Never override disk quota limits or use reserved space */
cap_lower(cred->cap_effective, CAP_SYS_RESOURCE); cap_lower(cred->cap_effective, CAP_SYS_RESOURCE);
...@@ -1237,7 +1244,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1237,7 +1244,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
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_put_cred; goto out_err;
mntput(upperpath.mnt); mntput(upperpath.mnt);
for (i = 0; i < numlower; i++) for (i = 0; i < numlower; i++)
...@@ -1262,39 +1269,14 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1262,39 +1269,14 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
return 0; return 0;
out_put_cred: out_err:
put_cred(ufs->creator_cred);
out_put_indexdir:
dput(ufs->indexdir);
kfree(oe); kfree(oe);
out_put_lower_layers:
for (i = 0; i < ufs->numlower; i++) {
if (ufs->lower_layers[i].mnt)
free_anon_bdev(ufs->lower_layers[i].pseudo_dev);
mntput(ufs->lower_layers[i].mnt);
}
kfree(ufs->lower_layers);
out_put_workdir:
dput(ufs->workdir);
mntput(ufs->upper_mnt);
out_put_lowerpath:
for (i = 0; i < numlower; i++) for (i = 0; i < numlower; i++)
path_put(&stack[i]); path_put(&stack[i]);
kfree(stack); kfree(stack);
out_unlock_workdentry:
if (ufs->workdir_locked)
ovl_inuse_unlock(ufs->workbasedir);
dput(ufs->workbasedir);
path_put(&workpath); path_put(&workpath);
out_unlock_upperdentry:
if (ufs->upperdir_locked)
ovl_inuse_unlock(upperpath.dentry);
path_put(&upperpath); path_put(&upperpath);
out_free_config: ovl_free_fs(ufs);
kfree(ufs->config.lowerdir);
kfree(ufs->config.upperdir);
kfree(ufs->config.workdir);
kfree(ufs);
out: out:
return err; return err;
} }
......
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