Skip to contentSkip to conversation

Allow kernel-only mount interfaces...

PATCH In review Trond Myklebust 2 participants 3 messages Feb 10, 2005 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow kernel-only mount interfaces...

Hi,

I'm working on straightening out a problem we have with NFSv4 in the
case where the server exports a tree of filesystems (as we also do in NFSv2/v3 with the "nohide" option).

If the client mounts such a tree, it is supposed to detect whenever it
crosses a mountpoint on the server, and basically automount the new filesystem in-place. The main reason for wanting to do so is that NFSv4 allows for individual filesystems to be migrated and/or replicated to other servers.

In order to respect atomicity guarantees, it would be nice to do this
automounting in-kernel within nfs_lookup(). For efficiency reasons, it would be nice to be able to pass the old superblock as a parameter to the mount code. The problem is that the current mount interfaces do not allow the kernel to have a private api that differs from the standard userland mount.

Would something like the appended patch be an acceptable method of
implementing such a private mount api?

Cheers,
Trond

VFS: Add GPL_EXPORTED function vfs_kern_mount()

do_kern_mount() does not allow the kernel to use private mount interfaces without exposing the same interfaces to userland. The problem is that the filesystem is referenced by name, thus meaning that it and its mount interface must be registered in the global filesystem list.

vfs_kern_mount() passes the struct file_system_type as an explicit parameter in order to overcome this limitation.

---
 super.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
fs/super.c +12 -4
Index: linux-2.6.11-rc3/fs/super.c
===================================================================
@@ -794,9 +794,8 @@ struct super_block *get_sb_single(struct
 EXPORT_SYMBOL(get_sb_single);
 
 struct vfsmount *
-do_kern_mount(const char *fstype, int flags, const char *name, void *data)
+vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
 {
-	struct file_system_type *type = get_fs_type(fstype);
 	struct super_block *sb = ERR_PTR(-ENOMEM);
 	struct vfsmount *mnt;
 	int error;
@@ -835,7 +834,6 @@ do_kern_mount(const char *fstype, int fl
 	mnt->mnt_parent = mnt;
 	mnt->mnt_namespace = current->namespace;
 	up_write(&sb->s_umount);
-	put_filesystem(type);
 	return mnt;
 out_sb:
 	up_write(&sb->s_umount);
@@ -846,10 +844,20 @@ out_free_secdata:
 out_mnt:
 	free_vfsmnt(mnt);
 out:
-	put_filesystem(type);
 	return (struct vfsmount *)sb;
 }
 
+EXPORT_SYMBOL_GPL(vfs_kern_mount);
+
+struct vfsmount *
+do_kern_mount(const char *fstype, int flags, const char *name, void *data)
+{
+	struct file_system_type *type = get_fs_type(fstype);
+	struct vfsmount *mnt = vfs_kern_mount(type, flags, name, data);
+	put_filesystem(type);
+	return mnt;
+}
+
 EXPORT_SYMBOL_GPL(do_kern_mount);
 
 struct vfsmount *kern_mount(struct file_system_type *type)
Signature · 1 line
Trond Myklebust <[email protected]>
#1 lore raw

fs/super.c out_free_secdata: · line 859

Quoted 8 lines · Trond Myklebust
fs/super.c +8 -0
+struct vfsmount *
+do_kern_mount(const char *fstype, int flags, const char *name, void *data)
+{
+	struct file_system_type *type = get_fs_type(fstype);
+	struct vfsmount *mnt = vfs_kern_mount(type, flags, name, data);
+	put_filesystem(type);
+	return mnt;
+}

This will OOPS if fstype is bad, since you unconditionally put_filesystem() on a possible PTR_ERR() type. You need an extra

	if (!IS_ERR(type))
		put_filesystem(type);

Cheers, Andreas
--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://members.shaw.ca/adilger/ http://members.shaw.ca/golinux/

#2 lore raw

to den 10.02.2005 Klokka 12:01 (-0700) skreiv Andreas Dilger:

Quoted 6 lines

This will OOPS if fstype is bad, since you unconditionally put_filesystem() on a possible PTR_ERR() type. You need an extra

	if (!IS_ERR(type))
		put_filesystem(type);

Agreed. That was not a final patch, but just a first untested draft in order to test the waters.
I'm mainly wanting to hear whether or not anyone has major objections (Al ?) against the new function itself.

Here's an update, though ;-)

Cheers,
Trond

VFS: Add GPL_EXPORTED function vfs_kern_mount()

do_kern_mount() does not allow the kernel to use private mount interfaces without exposing the same interfaces to userland. The problem is that the filesystem is referenced by name, thus meaning that it and its mount interface must be registered in the global filesystem list.

vfs_kern_mount() passes the struct file_system_type as an explicit parameter in order to overcome this limitation.

 super.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)
fs/super.c +15 -7
Index: linux-2.6.11-rc3/fs/super.c
===================================================================
@@ -794,17 +794,13 @@ struct super_block *get_sb_single(struct
 EXPORT_SYMBOL(get_sb_single);
 
 struct vfsmount *
-do_kern_mount(const char *fstype, int flags, const char *name, void *data)
+vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
 {
-	struct file_system_type *type = get_fs_type(fstype);
 	struct super_block *sb = ERR_PTR(-ENOMEM);
 	struct vfsmount *mnt;
 	int error;
 	char *secdata = NULL;
 
-	if (!type)
-		return ERR_PTR(-ENODEV);
-
 	mnt = alloc_vfsmnt(name);
 	if (!mnt)
 		goto out;
@@ -835,7 +831,6 @@ do_kern_mount(const char *fstype, int fl
 	mnt->mnt_parent = mnt;
 	mnt->mnt_namespace = current->namespace;
 	up_write(&sb->s_umount);
-	put_filesystem(type);
 	return mnt;
 out_sb:
 	up_write(&sb->s_umount);
@@ -846,10 +841,23 @@ out_free_secdata:
 out_mnt:
 	free_vfsmnt(mnt);
 out:
-	put_filesystem(type);
 	return (struct vfsmount *)sb;
 }
 
+EXPORT_SYMBOL_GPL(vfs_kern_mount);
+
+struct vfsmount *
+do_kern_mount(const char *fstype, int flags, const char *name, void *data)
+{
+	struct file_system_type *type = get_fs_type(fstype);
+	struct vfsmount *mnt;
+	if (!type)
+		return ERR_PTR(-ENODEV);
+	mnt = vfs_kern_mount(type, flags, name, data);
+	put_filesystem(type);
+	return mnt;
+}
+
 EXPORT_SYMBOL_GPL(do_kern_mount);
 
 struct vfsmount *kern_mount(struct file_system_type *type)
Signature · 1 line
Trond Myklebust <[email protected]>