Skip to contentSkip to conversation

mount: enable use MS_RDONLY with MS_BIND

PATCH Gustavo Padovan 1 participant 1 message Dec 23, 2011 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

So I put Lennart's email wrong. Fixing it.

Quoted 57 lines · Gustavo F. Padovan

From: "Gustavo F. Padovan" <[email protected]>

This allow creation of read-only bind mounts in a single mount() call, instead of two.

---
 fs/namespace.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
fs/namespace.c +8 -3
index 5c07af8..c08c150 100644
@@ -1743,7 +1743,7 @@ static int do_change_type(struct path *path, int flag)
  * do loopback mount.
  */
 static int do_loopback(struct path *path, char *old_name,
-				int recurse)
+						unsigned long flags)
 {
 	LIST_HEAD(umount_list);
 	struct path old_path;
@@ -1769,7 +1769,7 @@ static int do_loopback(struct path *path, char *old_name,
 		goto out2;
 
 	err = -ENOMEM;
-	if (recurse)
+	if (flags & MS_REC)
 		mnt = copy_tree(old_path.mnt, old_path.dentry, 0);
 	else
 		mnt = clone_mnt(old_path.mnt, old_path.dentry, 0);
@@ -1782,7 +1782,12 @@ static int do_loopback(struct path *path, char *old_name,
 		br_write_lock(&vfsmount_lock);
 		umount_tree(mnt, 0, &umount_list);
 		br_write_unlock(&vfsmount_lock);
+		goto out2;
 	}
+
+	if (flags & MS_RDONLY)
+		path->mnt->mnt_flags |= MNT_READONLY;
+
 out2:
 	unlock_mount(path);
 	release_mounts(&umount_list);
@@ -2338,7 +2343,7 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
 		retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
 				    data_page);
 	else if (flags & MS_BIND)
-		retval = do_loopback(&path, dev_name, flags & MS_REC);
+		retval = do_loopback(&path, dev_name, flags);
 	else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
 		retval = do_change_type(&path, flags);
 	else if (flags & MS_MOVE)
Signature · 1 line
1.7.6.4

Gustavo