From: Valerie Aurora <vaurora@xxxxxxxxxx> Passing the CL_MAKE_HARD_READONLY flag to clone_mnt() causes the clone to fail if the source superblock is not read-only. If it is read-only, it increments the hard read-only users and sets the MNT_HARD_READONLY flag in the vfsmount. When the mount is freed via free_vfsmnt(), automatically decrement the hard read-only users count. Cc: Ram Pai <linuxram@xxxxxxxxxx> --- fs/namespace.c | 18 ++++++++++++++++++ fs/pnode.h | 1 + include/linux/mount.h | 1 + 3 files changed, 20 insertions(+), 0 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index a9e5e06..8306871 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -469,6 +469,12 @@ static void __mnt_unmake_readonly(struct vfsmount *mnt) static void free_vfsmnt(struct vfsmount *mnt) { kfree(mnt->mnt_devname); + if (mnt->mnt_flags & MNT_HARD_READONLY) { + BUG_ON(mnt->mnt_sb->s_hard_readonly_users <= 0); + down_write(&mnt->mnt_sb->s_umount); + mnt->mnt_sb->s_hard_readonly_users--; + up_write(&mnt->mnt_sb->s_umount); + } mnt_free_id(mnt); #ifdef CONFIG_SMP free_percpu(mnt->mnt_pcp); @@ -713,6 +719,16 @@ static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root, if ((flag & CL_NO_SLAVE) && IS_MNT_SLAVE(old)) return ERR_PTR(-EINVAL); + if (flag & CL_MAKE_HARD_READONLY) { + down_write(&sb->s_umount); + if (!(sb->s_flags & MS_RDONLY)) { + up_write(&sb->s_umount); + return ERR_PTR(-EBUSY); + } + sb->s_hard_readonly_users++; + up_write(&sb->s_umount); + } + mnt = alloc_vfsmnt(old->mnt_devname); if (!mnt) return ERR_PTR(-ENOMEM); @@ -748,6 +764,8 @@ static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root, } if (flag & CL_MAKE_SHARED) set_mnt_shared(mnt); + if (flag & CL_MAKE_HARD_READONLY) + mnt->mnt_flags |= MNT_HARD_READONLY; /* stick the duplicate mount on the same expiry list as the * original if that was on one */ diff --git a/fs/pnode.h b/fs/pnode.h index 8920e47..dc7b468 100644 --- a/fs/pnode.h +++ b/fs/pnode.h @@ -24,6 +24,7 @@ #define CL_PRIVATE 0x10 #define CL_NO_SHARED 0x20 #define CL_NO_SLAVE 0x40 +#define CL_MAKE_HARD_READONLY 0x80 static inline void set_mnt_shared(struct vfsmount *mnt) { diff --git a/include/linux/mount.h b/include/linux/mount.h index 604f122..7101157 100644 --- a/include/linux/mount.h +++ b/include/linux/mount.h @@ -46,6 +46,7 @@ struct mnt_namespace; #define MNT_INTERNAL 0x4000 +#define MNT_HARD_READONLY 0x8000 /* has a hard read-only ref on the sb */ struct mnt_pcp { int mnt_count; -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html