diff options
Diffstat (limited to 'fs/nfs/namespace.c')
-rw-r--r-- | fs/nfs/namespace.c | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c index f32b8603dca8..c0b8344db0c6 100644 --- a/fs/nfs/namespace.c +++ b/fs/nfs/namespace.c | |||
@@ -25,33 +25,30 @@ static LIST_HEAD(nfs_automount_list); | |||
25 | static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); | 25 | static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); |
26 | int nfs_mountpoint_expiry_timeout = 500 * HZ; | 26 | int nfs_mountpoint_expiry_timeout = 500 * HZ; |
27 | 27 | ||
28 | static struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent, | 28 | static struct vfsmount *nfs_do_submount(struct dentry *dentry, |
29 | const struct dentry *dentry, | ||
30 | struct nfs_fh *fh, | 29 | struct nfs_fh *fh, |
31 | struct nfs_fattr *fattr); | 30 | struct nfs_fattr *fattr); |
32 | 31 | ||
33 | /* | 32 | /* |
34 | * nfs_path - reconstruct the path given an arbitrary dentry | 33 | * nfs_path - reconstruct the path given an arbitrary dentry |
35 | * @base - arbitrary string to prepend to the path | 34 | * @base - used to return pointer to the end of devname part of path |
36 | * @droot - pointer to root dentry for mountpoint | ||
37 | * @dentry - pointer to dentry | 35 | * @dentry - pointer to dentry |
38 | * @buffer - result buffer | 36 | * @buffer - result buffer |
39 | * @buflen - length of buffer | 37 | * @buflen - length of buffer |
40 | * | 38 | * |
41 | * Helper function for constructing the path from the | 39 | * Helper function for constructing the server pathname |
42 | * root dentry to an arbitrary hashed dentry. | 40 | * by arbitrary hashed dentry. |
43 | * | 41 | * |
44 | * This is mainly for use in figuring out the path on the | 42 | * This is mainly for use in figuring out the path on the |
45 | * server side when automounting on top of an existing partition. | 43 | * server side when automounting on top of an existing partition |
44 | * and in generating /proc/mounts and friends. | ||
46 | */ | 45 | */ |
47 | char *nfs_path(const char *base, | 46 | char *nfs_path(char **p, struct dentry *dentry, char *buffer, ssize_t buflen) |
48 | const struct dentry *droot, | ||
49 | const struct dentry *dentry, | ||
50 | char *buffer, ssize_t buflen) | ||
51 | { | 47 | { |
52 | char *end; | 48 | char *end; |
53 | int namelen; | 49 | int namelen; |
54 | unsigned seq; | 50 | unsigned seq; |
51 | const char *base; | ||
55 | 52 | ||
56 | rename_retry: | 53 | rename_retry: |
57 | end = buffer+buflen; | 54 | end = buffer+buflen; |
@@ -60,7 +57,10 @@ rename_retry: | |||
60 | 57 | ||
61 | seq = read_seqbegin(&rename_lock); | 58 | seq = read_seqbegin(&rename_lock); |
62 | rcu_read_lock(); | 59 | rcu_read_lock(); |
63 | while (!IS_ROOT(dentry) && dentry != droot) { | 60 | while (1) { |
61 | spin_lock(&dentry->d_lock); | ||
62 | if (IS_ROOT(dentry)) | ||
63 | break; | ||
64 | namelen = dentry->d_name.len; | 64 | namelen = dentry->d_name.len; |
65 | buflen -= namelen + 1; | 65 | buflen -= namelen + 1; |
66 | if (buflen < 0) | 66 | if (buflen < 0) |
@@ -68,27 +68,47 @@ rename_retry: | |||
68 | end -= namelen; | 68 | end -= namelen; |
69 | memcpy(end, dentry->d_name.name, namelen); | 69 | memcpy(end, dentry->d_name.name, namelen); |
70 | *--end = '/'; | 70 | *--end = '/'; |
71 | spin_unlock(&dentry->d_lock); | ||
71 | dentry = dentry->d_parent; | 72 | dentry = dentry->d_parent; |
72 | } | 73 | } |
73 | rcu_read_unlock(); | 74 | if (read_seqretry(&rename_lock, seq)) { |
74 | if (read_seqretry(&rename_lock, seq)) | 75 | spin_unlock(&dentry->d_lock); |
76 | rcu_read_unlock(); | ||
75 | goto rename_retry; | 77 | goto rename_retry; |
78 | } | ||
76 | if (*end != '/') { | 79 | if (*end != '/') { |
77 | if (--buflen < 0) | 80 | if (--buflen < 0) { |
81 | spin_unlock(&dentry->d_lock); | ||
82 | rcu_read_unlock(); | ||
78 | goto Elong; | 83 | goto Elong; |
84 | } | ||
79 | *--end = '/'; | 85 | *--end = '/'; |
80 | } | 86 | } |
87 | *p = end; | ||
88 | base = dentry->d_fsdata; | ||
89 | if (!base) { | ||
90 | spin_unlock(&dentry->d_lock); | ||
91 | rcu_read_unlock(); | ||
92 | WARN_ON(1); | ||
93 | return end; | ||
94 | } | ||
81 | namelen = strlen(base); | 95 | namelen = strlen(base); |
82 | /* Strip off excess slashes in base string */ | 96 | /* Strip off excess slashes in base string */ |
83 | while (namelen > 0 && base[namelen - 1] == '/') | 97 | while (namelen > 0 && base[namelen - 1] == '/') |
84 | namelen--; | 98 | namelen--; |
85 | buflen -= namelen; | 99 | buflen -= namelen; |
86 | if (buflen < 0) | 100 | if (buflen < 0) { |
101 | spin_lock(&dentry->d_lock); | ||
102 | rcu_read_unlock(); | ||
87 | goto Elong; | 103 | goto Elong; |
104 | } | ||
88 | end -= namelen; | 105 | end -= namelen; |
89 | memcpy(end, base, namelen); | 106 | memcpy(end, base, namelen); |
107 | spin_unlock(&dentry->d_lock); | ||
108 | rcu_read_unlock(); | ||
90 | return end; | 109 | return end; |
91 | Elong_unlock: | 110 | Elong_unlock: |
111 | spin_lock(&dentry->d_lock); | ||
92 | rcu_read_unlock(); | 112 | rcu_read_unlock(); |
93 | if (read_seqretry(&rename_lock, seq)) | 113 | if (read_seqretry(&rename_lock, seq)) |
94 | goto rename_retry; | 114 | goto rename_retry; |
@@ -143,9 +163,9 @@ struct vfsmount *nfs_d_automount(struct path *path) | |||
143 | } | 163 | } |
144 | 164 | ||
145 | if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) | 165 | if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) |
146 | mnt = nfs_do_refmount(path->mnt, path->dentry); | 166 | mnt = nfs_do_refmount(path->dentry); |
147 | else | 167 | else |
148 | mnt = nfs_do_submount(path->mnt, path->dentry, fh, fattr); | 168 | mnt = nfs_do_submount(path->dentry, fh, fattr); |
149 | if (IS_ERR(mnt)) | 169 | if (IS_ERR(mnt)) |
150 | goto out; | 170 | goto out; |
151 | 171 | ||
@@ -209,19 +229,17 @@ static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server, | |||
209 | 229 | ||
210 | /** | 230 | /** |
211 | * nfs_do_submount - set up mountpoint when crossing a filesystem boundary | 231 | * nfs_do_submount - set up mountpoint when crossing a filesystem boundary |
212 | * @mnt_parent - mountpoint of parent directory | ||
213 | * @dentry - parent directory | 232 | * @dentry - parent directory |
214 | * @fh - filehandle for new root dentry | 233 | * @fh - filehandle for new root dentry |
215 | * @fattr - attributes for new root inode | 234 | * @fattr - attributes for new root inode |
216 | * | 235 | * |
217 | */ | 236 | */ |
218 | static struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent, | 237 | static struct vfsmount *nfs_do_submount(struct dentry *dentry, |
219 | const struct dentry *dentry, | ||
220 | struct nfs_fh *fh, | 238 | struct nfs_fh *fh, |
221 | struct nfs_fattr *fattr) | 239 | struct nfs_fattr *fattr) |
222 | { | 240 | { |
223 | struct nfs_clone_mount mountdata = { | 241 | struct nfs_clone_mount mountdata = { |
224 | .sb = mnt_parent->mnt_sb, | 242 | .sb = dentry->d_sb, |
225 | .dentry = dentry, | 243 | .dentry = dentry, |
226 | .fh = fh, | 244 | .fh = fh, |
227 | .fattr = fattr, | 245 | .fattr = fattr, |
@@ -237,11 +255,11 @@ static struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent, | |||
237 | dentry->d_name.name); | 255 | dentry->d_name.name); |
238 | if (page == NULL) | 256 | if (page == NULL) |
239 | goto out; | 257 | goto out; |
240 | devname = nfs_devname(mnt_parent, dentry, page, PAGE_SIZE); | 258 | devname = nfs_devname(dentry, page, PAGE_SIZE); |
241 | mnt = (struct vfsmount *)devname; | 259 | mnt = (struct vfsmount *)devname; |
242 | if (IS_ERR(devname)) | 260 | if (IS_ERR(devname)) |
243 | goto free_page; | 261 | goto free_page; |
244 | mnt = nfs_do_clone_mount(NFS_SB(mnt_parent->mnt_sb), devname, &mountdata); | 262 | mnt = nfs_do_clone_mount(NFS_SB(dentry->d_sb), devname, &mountdata); |
245 | free_page: | 263 | free_page: |
246 | free_page((unsigned long)page); | 264 | free_page((unsigned long)page); |
247 | out: | 265 | out: |