]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/suse-2.6.27.39/patches.fixes/nfs-02-Add-VFS-helper-functions-for-setting-up-private-namespaces
Imported linux-2.6.27.39 suse/xen patches.
[ipfire-2.x.git] / src / patches / suse-2.6.27.39 / patches.fixes / nfs-02-Add-VFS-helper-functions-for-setting-up-private-namespaces
CommitLineData
2cb7cef9
BS
1From cf8d2c11cb77f129675478792122f50827e5b0ae Mon Sep 17 00:00:00 2001
2From: Trond Myklebust <Trond.Myklebust@netapp.com>
3Date: Mon, 22 Jun 2009 15:09:13 -0400
4Subject: [PATCH 2/5] VFS: Add VFS helper functions for setting up private namespaces
5
6The purpose of this patch is to improve the remote mount path lookup
7support for distributed filesystems such as the NFSv4 client.
8
9When given a mount command of the form "mount server:/foo/bar /mnt", the
10NFSv4 client is required to look up the filehandle for "server:/", and
11then look up each component of the remote mount path "foo/bar" in order
12to find the directory that is actually going to be mounted on /mnt.
13Following that remote mount path may involve following symlinks,
14crossing server-side mount points and even following referrals to
15filesystem volumes on other servers.
16
17Since the standard VFS path lookup code already supports walking paths
18that contain all these features (using in-kernel automounts for
19following referrals) we would like to be able to reuse that rather than
20duplicate the full path traversal functionality in the NFSv4 client code.
21
22This patch therefore defines a VFS helper function create_mnt_ns(), that
23sets up a temporary filesystem namespace and attaches a root filesystem to
24it. It exports the create_mnt_ns() and put_mnt_ns() function for use by
25filesystem modules.
26
27Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
28Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
29Acked-by: NeilBrown <neilb@suse.de>
30---
31 fs/namespace.c | 45 ++++++++++++++++++++++++++++++++++--------
32 include/linux/mnt_namespace.h | 1
33 2 files changed, 38 insertions(+), 8 deletions(-)
34
35--- a/fs/namespace.c
36+++ b/fs/namespace.c
37@@ -1939,6 +1939,21 @@ dput_out:
38 return retval;
39 }
40
41+static struct mnt_namespace *alloc_mnt_ns(void)
42+{
43+ struct mnt_namespace *new_ns;
44+
45+ new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL);
46+ if (!new_ns)
47+ return ERR_PTR(-ENOMEM);
48+ atomic_set(&new_ns->count, 1);
49+ new_ns->root = NULL;
50+ INIT_LIST_HEAD(&new_ns->list);
51+ init_waitqueue_head(&new_ns->poll);
52+ new_ns->event = 0;
53+ return new_ns;
54+}
55+
56 /*
57 * Allocate a new namespace structure and populate it with contents
58 * copied from the namespace of the passed in task structure.
59@@ -1950,14 +1965,9 @@ static struct mnt_namespace *dup_mnt_ns(
60 struct vfsmount *rootmnt = NULL, *pwdmnt = NULL;
61 struct vfsmount *p, *q;
62
63- new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL);
64- if (!new_ns)
65- return ERR_PTR(-ENOMEM);
66-
67- atomic_set(&new_ns->count, 1);
68- INIT_LIST_HEAD(&new_ns->list);
69- init_waitqueue_head(&new_ns->poll);
70- new_ns->event = 0;
71+ new_ns = alloc_mnt_ns();
72+ if (IS_ERR(new_ns))
73+ return new_ns;
74
75 down_write(&namespace_sem);
76 /* First pass: copy the tree topology */
77@@ -2021,6 +2031,24 @@ struct mnt_namespace *copy_mnt_ns(unsign
78 return new_ns;
79 }
80
81+/**
82+ * create_mnt_ns - creates a private namespace and adds a root filesystem
83+ * @mnt: pointer to the new root filesystem mountpoint
84+ */
85+struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt)
86+{
87+ struct mnt_namespace *new_ns;
88+
89+ new_ns = alloc_mnt_ns();
90+ if (!IS_ERR(new_ns)) {
91+ mnt->mnt_ns = new_ns;
92+ new_ns->root = mnt;
93+ list_add(&new_ns->list, &new_ns->root->mnt_list);
94+ }
95+ return new_ns;
96+}
97+EXPORT_SYMBOL(create_mnt_ns);
98+
99 SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
100 char __user *, type, unsigned long, flags, void __user *, data)
101 {
102@@ -2328,3 +2356,4 @@ void put_mnt_ns(struct mnt_namespace *ns
103 release_mounts(&umount_list);
104 kfree(ns);
105 }
106+EXPORT_SYMBOL(put_mnt_ns);
107--- a/include/linux/mnt_namespace.h
108+++ b/include/linux/mnt_namespace.h
109@@ -22,6 +22,7 @@ struct proc_mounts {
110 int event;
111 };
112
113+extern struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt);
114 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
115 struct fs_struct *);
116 extern void put_mnt_ns(struct mnt_namespace *ns);