The patch titled r-o-bind-mounts: honor r/w changes at do_remount() time has been added to the -mm tree. Its filename is r-o-bind-mounts-honor-r-w-changes-at-do_remount-time.patch *** Remember to use Documentation/SubmitChecklist when testing your code *** See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: r-o-bind-mounts: honor r/w changes at do_remount() time From: Dave Hansen <haveblue@xxxxxxxxxx> Originally from: Herbert Poetzl <herbert@xxxxxxxxxxxx> This is the core of the read-only bind mount patch set. Note that this does _not_ add a "ro" option directly to the bind mount operation. If you require such a mount, you must first do the bind, then follow it up with a 'mount -o remount,ro' operation. Signed-off-by: Dave Hansen <haveblue@xxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/namespace.c | 46 +++++++++++++++++++++++++++++++++------- include/linux/mount.h | 1 2 files changed, 40 insertions(+), 7 deletions(-) diff -puN fs/namespace.c~r-o-bind-mounts-honor-r-w-changes-at-do_remount-time fs/namespace.c --- a/fs/namespace.c~r-o-bind-mounts-honor-r-w-changes-at-do_remount-time +++ a/fs/namespace.c @@ -105,7 +105,11 @@ struct vfsmount *alloc_vfsmnt(const char */ int __mnt_is_readonly(struct vfsmount *mnt) { - return (mnt->mnt_sb->s_flags & MS_RDONLY); + if (mnt->mnt_flags & MNT_READONLY) + return 1; + if (mnt->mnt_sb->s_flags & MS_RDONLY) + return 1; + return 0; } EXPORT_SYMBOL_GPL(__mnt_is_readonly); @@ -280,7 +284,7 @@ void mnt_drop_write(struct vfsmount *mnt } EXPORT_SYMBOL_GPL(mnt_drop_write); -int mnt_make_readonly(struct vfsmount *mnt) +static int mnt_make_readonly(struct vfsmount *mnt) { int ret = 0; @@ -293,15 +297,21 @@ int mnt_make_readonly(struct vfsmount *m goto out; } /* - * actually set mount's r/o flag here to make - * __mnt_is_readonly() true, which keeps anyone - * from doing a successful mnt_want_write(). + * nobody can do a successful mnt_want_write() with all + * of the counts in MNT_DENIED_WRITE and the locks held. */ + if (!ret) + mnt->mnt_flags |= MNT_READONLY; out: mnt_unlock_cpus(); return ret; } +static void __mnt_unmake_readonly(struct vfsmount *mnt) +{ + mnt->mnt_flags &= ~MNT_READONLY; +} + int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb) { mnt->mnt_sb = sb; @@ -681,7 +691,7 @@ static int show_vfsmnt(struct seq_file * seq_putc(m, '.'); mangle(m, mnt->mnt_sb->s_subtype); } - seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw"); + seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw"); for (fs_infop = fs_info; fs_infop->flag; fs_infop++) { if (mnt->mnt_sb->s_flags & fs_infop->flag) seq_puts(m, fs_infop->str); @@ -1313,6 +1323,23 @@ out: return err; } +static int change_mount_flags(struct vfsmount *mnt, int ms_flags) +{ + int error = 0; + int readonly_request = 0; + + if (ms_flags & MS_RDONLY) + readonly_request = 1; + if (readonly_request == __mnt_is_readonly(mnt)) + return 0; + + if (readonly_request) + error = mnt_make_readonly(mnt); + else + __mnt_unmake_readonly(mnt); + return error; +} + /* * change filesystem flags. dir should be a physical root of filesystem. * If you've mounted a non-root directory somewhere and want to do remount @@ -1334,7 +1361,10 @@ static int do_remount(struct nameidata * return -EINVAL; down_write(&sb->s_umount); - err = do_remount_sb(sb, flags, data, 0); + if (flags & MS_BIND) + err = change_mount_flags(nd->mnt, flags); + else + err = do_remount_sb(sb, flags, data, 0); if (!err) { clear_mnt_user(nd->mnt); nd->mnt->mnt_flags = mnt_flags; @@ -1834,6 +1864,8 @@ long do_mount(char *dev_name, char *dir_ mnt_flags |= MNT_RELATIME; if (flags & MS_NOMNT) mnt_flags |= MNT_NOMNT; + if (flags & MS_RDONLY) + mnt_flags |= MNT_READONLY; flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT | MS_NOMNT); diff -puN include/linux/mount.h~r-o-bind-mounts-honor-r-w-changes-at-do_remount-time include/linux/mount.h --- a/include/linux/mount.h~r-o-bind-mounts-honor-r-w-changes-at-do_remount-time +++ a/include/linux/mount.h @@ -30,6 +30,7 @@ struct mnt_namespace; #define MNT_NODIRATIME 0x10 #define MNT_RELATIME 0x20 #define MNT_NOMNT 0x40 +#define MNT_READONLY 0x80 /* does the user want this to be r/o? */ #define MNT_SHRINKABLE 0x100 #define MNT_USER 0x200 _ Patches currently in -mm which might be from haveblue@xxxxxxxxxx are markers-fix-warnings.patch maps4-add-proportional-set-size-accounting-in-smaps.patch maps4-rework-task_size-macros.patch maps4-move-is_swap_pte.patch maps4-introduce-a-generic-page-walker.patch maps4-use-pagewalker-in-clear_refs-and-smaps.patch maps4-simplify-interdependence-of-maps-and-smaps.patch maps4-move-clear_refs-code-to-task_mmuc.patch maps4-regroup-task_mmu-by-interface.patch maps4-add-proc-pid-pagemap-interface.patch maps4-add-proc-kpagecount-interface.patch maps4-add-proc-kpageflags-interface.patch maps4-make-page-monitoring-proc-file-optional.patch maps4-make-page-monitoring-proc-file-optional-fix.patch hugetlb-split-alloc_huge_page-into-private-and-shared-components.patch hugetlb-split-alloc_huge_page-into-private-and-shared-components-checkpatch-fixes.patch hugetlb-fix-quota-management-for-private-mappings.patch hugetlb-debit-quota-in-alloc_huge_page.patch hugetlb-allow-bulk-updating-in-hugetlb__quota.patch hugetlb-enforce-quotas-during-reservation-for-shared-mappings.patch add-remove_memory-for-ppc64-2.patch enable-hotplug-memory-remove-for-ppc64.patch add-arch-specific-walk_memory_remove-for-ppc64.patch do-namei_flags-calculation-inside-open_namei.patch make-open_namei-return-a-filp.patch kill-do_filp_open.patch kill-filp_open.patch kill-filp_open-checkpatch-fixes.patch rename-open_namei-to-open_pathname.patch r-o-bind-mounts-stub-functions.patch r-o-bind-mounts-do_rmdir-elevate-write-count.patch r-o-bind-mounts-elevate-mnt-writers-for-callers-of-vfs_mkdir.patch r-o-bind-mounts-elevate-mnt-writers-for-vfs_unlink-callers.patch r-o-bind-mounts-elevate-mount-count-for-extended-attributes.patch r-o-bind-mounts-elevate-write-count-during-entire-ncp_ioctl.patch r-o-bind-mounts-elevate-write-count-for-do_sys_utime-and-touch_atime.patch r-o-bind-mounts-elevate-write-count-for-do_utimes.patch r-o-bind-mounts-elevate-write-count-for-file_update_time.patch r-o-bind-mounts-elevate-write-count-for-link-and-symlink-calls.patch r-o-bind-mounts-elevate-write-count-for-some-ioctls.patch r-o-bind-mounts-elevate-write-count-for-some-ioctls-checkpatch-fixes.patch r-o-bind-mounts-elevate-write-count-for-some-ioctls-vs-forbid-user-to-change-file-flags-on-quota-files.patch r-o-bind-mounts-elevate-write-count-opened-files.patch r-o-bind-mounts-elevate-write-count-over-calls-to-vfs_rename.patch r-o-bind-mounts-elevate-writer-count-for-chown-and-friends.patch r-o-bind-mounts-elevate-writer-count-for-do_sys_truncate.patch r-o-bind-mounts-make-access-use-mnt-check.patch r-o-bind-mounts-nfs-check-mnt-instead-of-superblock-directly.patch r-o-bind-mounts-nfs-check-mnt-instead-of-superblock-directly-checkpatch-fixes.patch r-o-bind-mounts-sys_mknodat-elevate-write-count-for-vfs_mknod-create.patch r-o-bind-mounts-track-number-of-mount-writers.patch r-o-bind-mounts-track-number-of-mount-writers-make-lockdep-happy-with-r-o-bind-mounts.patch r-o-bind-mounts-honor-r-w-changes-at-do_remount-time.patch keep-track-of-mnt_writer-state-of-struct-file.patch reiser4.patch page-owner-tracking-leak-detector.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html