]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/suse-2.6.27.31/patches.fixes/nfs-02-Add-VFS-helper-functions-for-setting-up-private-namespaces
Merge branch 'master' of git://git.ipfire.org/ipfire-2.x
[people/teissler/ipfire-2.x.git] / src / patches / suse-2.6.27.31 / patches.fixes / nfs-02-Add-VFS-helper-functions-for-setting-up-private-namespaces
1 From cf8d2c11cb77f129675478792122f50827e5b0ae Mon Sep 17 00:00:00 2001
2 From: Trond Myklebust <Trond.Myklebust@netapp.com>
3 Date: Mon, 22 Jun 2009 15:09:13 -0400
4 Subject: [PATCH 2/5] VFS: Add VFS helper functions for setting up private namespaces
5
6 The purpose of this patch is to improve the remote mount path lookup
7 support for distributed filesystems such as the NFSv4 client.
8
9 When given a mount command of the form "mount server:/foo/bar /mnt", the
10 NFSv4 client is required to look up the filehandle for "server:/", and
11 then look up each component of the remote mount path "foo/bar" in order
12 to find the directory that is actually going to be mounted on /mnt.
13 Following that remote mount path may involve following symlinks,
14 crossing server-side mount points and even following referrals to
15 filesystem volumes on other servers.
16
17 Since the standard VFS path lookup code already supports walking paths
18 that contain all these features (using in-kernel automounts for
19 following referrals) we would like to be able to reuse that rather than
20 duplicate the full path traversal functionality in the NFSv4 client code.
21
22 This patch therefore defines a VFS helper function create_mnt_ns(), that
23 sets up a temporary filesystem namespace and attaches a root filesystem to
24 it. It exports the create_mnt_ns() and put_mnt_ns() function for use by
25 filesystem modules.
26
27 Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
28 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
29 Acked-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);