Skip to content

Commit c771d68

Browse files
author
Miklos Szeredi
committed
vfs: introduce clone_private_mount()
Overlayfs needs a private clone of the mount, so create a function for this and export to modules. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent bd5d085 commit c771d68

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

fs/namespace.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,33 @@ void drop_collected_mounts(struct vfsmount *mnt)
16861686
namespace_unlock();
16871687
}
16881688

1689+
/**
1690+
* clone_private_mount - create a private clone of a path
1691+
*
1692+
* This creates a new vfsmount, which will be the clone of @path. The new will
1693+
* not be attached anywhere in the namespace and will be private (i.e. changes
1694+
* to the originating mount won't be propagated into this).
1695+
*
1696+
* Release with mntput().
1697+
*/
1698+
struct vfsmount *clone_private_mount(struct path *path)
1699+
{
1700+
struct mount *old_mnt = real_mount(path->mnt);
1701+
struct mount *new_mnt;
1702+
1703+
if (IS_MNT_UNBINDABLE(old_mnt))
1704+
return ERR_PTR(-EINVAL);
1705+
1706+
down_read(&namespace_sem);
1707+
new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE);
1708+
up_read(&namespace_sem);
1709+
if (IS_ERR(new_mnt))
1710+
return ERR_CAST(new_mnt);
1711+
1712+
return &new_mnt->mnt;
1713+
}
1714+
EXPORT_SYMBOL_GPL(clone_private_mount);
1715+
16891716
int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
16901717
struct vfsmount *root)
16911718
{

include/linux/mount.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ extern struct vfsmount *mntget(struct vfsmount *mnt);
8181
extern struct vfsmount *mnt_clone_internal(struct path *path);
8282
extern int __mnt_is_readonly(struct vfsmount *mnt);
8383

84+
struct path;
85+
extern struct vfsmount *clone_private_mount(struct path *path);
86+
8487
struct file_system_type;
8588
extern struct vfsmount *vfs_kern_mount(struct file_system_type *type,
8689
int flags, const char *name,

0 commit comments

Comments
 (0)