diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2017-11-10 09:39:15 +0100 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2017-11-10 09:39:15 +0100 |
commit | 520d7c867f26d216730e0d0e43b2f2ac90953a2d (patch) | |
tree | c0956531466bbbc94fa124e842f8563c128dafdf /fs/overlayfs/super.c | |
parent | 6e88256e197d2a3b5aa0d054e6e2f553469bf389 (diff) |
ovl: move ovl_get_workdir() and ovl_get_lower_layers()
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs/super.c')
-rw-r--r-- | fs/overlayfs/super.c | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index c1344c8a9520..3807472b718e 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -864,58 +864,6 @@ out: return err; } -static int ovl_get_workpath(struct ovl_fs *ufs, struct path *upperpath, - struct path *workpath) -{ - int err; - - err = ovl_mount_dir(ufs->config.workdir, workpath); - if (err) - goto out; - - err = -EINVAL; - if (upperpath->mnt != workpath->mnt) { - pr_err("overlayfs: workdir and upperdir must reside under the same mount\n"); - goto out; - } - if (!ovl_workdir_ok(workpath->dentry, upperpath->dentry)) { - pr_err("overlayfs: workdir and upperdir must be separate subtrees\n"); - goto out; - } - - err = -EBUSY; - if (ovl_inuse_trylock(workpath->dentry)) { - ufs->workdir_locked = true; - } else if (ufs->config.index) { - pr_err("overlayfs: workdir is in-use by another mount, mount with '-o index=off' to override exclusive workdir protection.\n"); - goto out; - } else { - pr_warn("overlayfs: workdir is in-use by another mount, accessing files from both mounts will result in undefined behavior.\n"); - } - - ufs->workbasedir = dget(workpath->dentry); - err = 0; -out: - return err; -} - -static int ovl_get_upper(struct ovl_fs *ufs, struct path *upperpath) -{ - struct vfsmount *upper_mnt; - - upper_mnt = clone_private_mount(upperpath); - if (IS_ERR(upper_mnt)) { - pr_err("overlayfs: failed to clone upperpath\n"); - return PTR_ERR(upper_mnt); - } - - /* Don't inherit atime flags */ - upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME); - ufs->upper_mnt = upper_mnt; - - return 0; -} - static int ovl_get_workdir(struct ovl_fs *ufs, struct path *workpath) { struct dentry *temp; @@ -971,6 +919,58 @@ static int ovl_get_workdir(struct ovl_fs *ufs, struct path *workpath) return 0; } +static int ovl_get_workpath(struct ovl_fs *ufs, struct path *upperpath, + struct path *workpath) +{ + int err; + + err = ovl_mount_dir(ufs->config.workdir, workpath); + if (err) + goto out; + + err = -EINVAL; + if (upperpath->mnt != workpath->mnt) { + pr_err("overlayfs: workdir and upperdir must reside under the same mount\n"); + goto out; + } + if (!ovl_workdir_ok(workpath->dentry, upperpath->dentry)) { + pr_err("overlayfs: workdir and upperdir must be separate subtrees\n"); + goto out; + } + + err = -EBUSY; + if (ovl_inuse_trylock(workpath->dentry)) { + ufs->workdir_locked = true; + } else if (ufs->config.index) { + pr_err("overlayfs: workdir is in-use by another mount, mount with '-o index=off' to override exclusive workdir protection.\n"); + goto out; + } else { + pr_warn("overlayfs: workdir is in-use by another mount, accessing files from both mounts will result in undefined behavior.\n"); + } + + ufs->workbasedir = dget(workpath->dentry); + err = 0; +out: + return err; +} + +static int ovl_get_upper(struct ovl_fs *ufs, struct path *upperpath) +{ + struct vfsmount *upper_mnt; + + upper_mnt = clone_private_mount(upperpath); + if (IS_ERR(upper_mnt)) { + pr_err("overlayfs: failed to clone upperpath\n"); + return PTR_ERR(upper_mnt); + } + + /* Don't inherit atime flags */ + upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME); + ufs->upper_mnt = upper_mnt; + + return 0; +} + static int ovl_get_indexdir(struct ovl_fs *ufs, struct ovl_entry *oe, struct path *upperpath) { @@ -1008,6 +1008,55 @@ out: return err; } +static int ovl_get_lower_layers(struct ovl_fs *ufs, struct path *stack, + unsigned int numlower) +{ + int err; + unsigned int i; + + err = -ENOMEM; + ufs->lower_layers = kcalloc(numlower, sizeof(struct ovl_layer), + GFP_KERNEL); + if (ufs->lower_layers == NULL) + goto out; + for (i = 0; i < numlower; i++) { + struct vfsmount *mnt; + dev_t dev; + + err = get_anon_bdev(&dev); + if (err) { + pr_err("overlayfs: failed to get anonymous bdev for lowerpath\n"); + goto out; + } + + mnt = clone_private_mount(&stack[i]); + err = PTR_ERR(mnt); + if (IS_ERR(mnt)) { + pr_err("overlayfs: failed to clone lowerpath\n"); + free_anon_bdev(dev); + goto out; + } + /* + * Make lower layers R/O. That way fchmod/fchown on lower file + * will fail instead of modifying lower fs. + */ + mnt->mnt_flags |= MNT_READONLY | MNT_NOATIME; + + ufs->lower_layers[ufs->numlower].mnt = mnt; + ufs->lower_layers[ufs->numlower].pseudo_dev = dev; + ufs->numlower++; + + /* Check if all lower layers are on same sb */ + if (i == 0) + ufs->same_sb = mnt->mnt_sb; + else if (ufs->same_sb != mnt->mnt_sb) + ufs->same_sb = NULL; + } + err = 0; +out: + return err; +} + static int ovl_get_lowerstack(struct super_block *sb, struct ovl_fs *ufs, struct path **stackp, unsigned int *stacklenp) { @@ -1077,55 +1126,6 @@ out_free_stack: goto out; } -static int ovl_get_lower_layers(struct ovl_fs *ufs, struct path *stack, - unsigned int numlower) -{ - int err; - unsigned int i; - - err = -ENOMEM; - ufs->lower_layers = kcalloc(numlower, sizeof(struct ovl_layer), - GFP_KERNEL); - if (ufs->lower_layers == NULL) - goto out; - for (i = 0; i < numlower; i++) { - struct vfsmount *mnt; - dev_t dev; - - err = get_anon_bdev(&dev); - if (err) { - pr_err("overlayfs: failed to get anonymous bdev for lowerpath\n"); - goto out; - } - - mnt = clone_private_mount(&stack[i]); - err = PTR_ERR(mnt); - if (IS_ERR(mnt)) { - pr_err("overlayfs: failed to clone lowerpath\n"); - free_anon_bdev(dev); - goto out; - } - /* - * Make lower layers R/O. That way fchmod/fchown on lower file - * will fail instead of modifying lower fs. - */ - mnt->mnt_flags |= MNT_READONLY | MNT_NOATIME; - - ufs->lower_layers[ufs->numlower].mnt = mnt; - ufs->lower_layers[ufs->numlower].pseudo_dev = dev; - ufs->numlower++; - - /* Check if all lower layers are on same sb */ - if (i == 0) - ufs->same_sb = mnt->mnt_sb; - else if (ufs->same_sb != mnt->mnt_sb) - ufs->same_sb = NULL; - } - err = 0; -out: - return err; -} - static int ovl_fill_super(struct super_block *sb, void *data, int silent) { struct path upperpath = { }; |