aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2011-03-16 06:26:11 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2011-03-16 16:47:55 -0400
commitb514f872f86d4b0c13fed74a1fe1f7ab500c4fd0 (patch)
treea54821b3e2363150e4e9b180e097a8092f884dda
parentb1942c5f8cf3bea3a3c88a7498ae4c4361f31afe (diff)
nfs: make nfs_path() work without vfsmount
part 3: now we have everything to get nfs_path() just by dentry - just follow to (disconnected) root and pick the rest of the thing there. Start killing propagation of struct vfsmount * on the paths that used to bring it to nfs_path(). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/nfs/internal.h15
-rw-r--r--fs/nfs/namespace.c69
-rw-r--r--fs/nfs/nfs4namespace.c43
-rw-r--r--fs/nfs/super.c9
4 files changed, 74 insertions, 62 deletions
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 9e5a003ccc53..f0234118d044 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -163,10 +163,10 @@ static inline void nfs_fs_proc_exit(void)
163 163
164/* nfs4namespace.c */ 164/* nfs4namespace.c */
165#ifdef CONFIG_NFS_V4 165#ifdef CONFIG_NFS_V4
166extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry); 166extern struct vfsmount *nfs_do_refmount(struct super_block *sb, struct dentry *dentry);
167#else 167#else
168static inline 168static inline
169struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 169struct vfsmount *nfs_do_refmount(struct super_block *sb, struct dentry *dentry)
170{ 170{
171 return ERR_PTR(-ENOENT); 171 return ERR_PTR(-ENOENT);
172} 172}
@@ -247,9 +247,7 @@ extern void nfs_sb_active(struct super_block *sb);
247extern void nfs_sb_deactive(struct super_block *sb); 247extern void nfs_sb_deactive(struct super_block *sb);
248 248
249/* namespace.c */ 249/* namespace.c */
250extern char *nfs_path(const char *base, 250extern char *nfs_path(char **p, struct dentry *dentry,
251 const struct dentry *droot,
252 const struct dentry *dentry,
253 char *buffer, ssize_t buflen); 251 char *buffer, ssize_t buflen);
254extern struct vfsmount *nfs_d_automount(struct path *path); 252extern struct vfsmount *nfs_d_automount(struct path *path);
255 253
@@ -290,12 +288,11 @@ extern int _nfs4_call_sync_session(struct nfs_server *server,
290/* 288/*
291 * Determine the device name as a string 289 * Determine the device name as a string
292 */ 290 */
293static inline char *nfs_devname(const struct vfsmount *mnt_parent, 291static inline char *nfs_devname(struct dentry *dentry,
294 const struct dentry *dentry,
295 char *buffer, ssize_t buflen) 292 char *buffer, ssize_t buflen)
296{ 293{
297 return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root, 294 char *dummy;
298 dentry, buffer, buflen); 295 return nfs_path(&dummy, dentry, buffer, buflen);
299} 296}
300 297
301/* 298/*
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index f32b8603dca8..859cdaba4c1c 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -25,33 +25,31 @@ static LIST_HEAD(nfs_automount_list);
25static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); 25static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts);
26int nfs_mountpoint_expiry_timeout = 500 * HZ; 26int nfs_mountpoint_expiry_timeout = 500 * HZ;
27 27
28static struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent, 28static struct vfsmount *nfs_do_submount(struct super_block *sb,
29 const struct dentry *dentry, 29 struct dentry *dentry,
30 struct nfs_fh *fh, 30 struct nfs_fh *fh,
31 struct nfs_fattr *fattr); 31 struct nfs_fattr *fattr);
32 32
33/* 33/*
34 * nfs_path - reconstruct the path given an arbitrary dentry 34 * nfs_path - reconstruct the path given an arbitrary dentry
35 * @base - arbitrary string to prepend to the path 35 * @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 36 * @dentry - pointer to dentry
38 * @buffer - result buffer 37 * @buffer - result buffer
39 * @buflen - length of buffer 38 * @buflen - length of buffer
40 * 39 *
41 * Helper function for constructing the path from the 40 * Helper function for constructing the server pathname
42 * root dentry to an arbitrary hashed dentry. 41 * by arbitrary hashed dentry.
43 * 42 *
44 * This is mainly for use in figuring out the path on the 43 * This is mainly for use in figuring out the path on the
45 * server side when automounting on top of an existing partition. 44 * server side when automounting on top of an existing partition
45 * and in generating /proc/mounts and friends.
46 */ 46 */
47char *nfs_path(const char *base, 47char *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{ 48{
52 char *end; 49 char *end;
53 int namelen; 50 int namelen;
54 unsigned seq; 51 unsigned seq;
52 const char *base;
55 53
56rename_retry: 54rename_retry:
57 end = buffer+buflen; 55 end = buffer+buflen;
@@ -60,7 +58,10 @@ rename_retry:
60 58
61 seq = read_seqbegin(&rename_lock); 59 seq = read_seqbegin(&rename_lock);
62 rcu_read_lock(); 60 rcu_read_lock();
63 while (!IS_ROOT(dentry) && dentry != droot) { 61 while (1) {
62 spin_lock(&dentry->d_lock);
63 if (IS_ROOT(dentry))
64 break;
64 namelen = dentry->d_name.len; 65 namelen = dentry->d_name.len;
65 buflen -= namelen + 1; 66 buflen -= namelen + 1;
66 if (buflen < 0) 67 if (buflen < 0)
@@ -68,27 +69,47 @@ rename_retry:
68 end -= namelen; 69 end -= namelen;
69 memcpy(end, dentry->d_name.name, namelen); 70 memcpy(end, dentry->d_name.name, namelen);
70 *--end = '/'; 71 *--end = '/';
72 spin_unlock(&dentry->d_lock);
71 dentry = dentry->d_parent; 73 dentry = dentry->d_parent;
72 } 74 }
73 rcu_read_unlock(); 75 if (read_seqretry(&rename_lock, seq)) {
74 if (read_seqretry(&rename_lock, seq)) 76 spin_unlock(&dentry->d_lock);
77 rcu_read_unlock();
75 goto rename_retry; 78 goto rename_retry;
79 }
76 if (*end != '/') { 80 if (*end != '/') {
77 if (--buflen < 0) 81 if (--buflen < 0) {
82 spin_unlock(&dentry->d_lock);
83 rcu_read_unlock();
78 goto Elong; 84 goto Elong;
85 }
79 *--end = '/'; 86 *--end = '/';
80 } 87 }
88 *p = end;
89 base = dentry->d_fsdata;
90 if (!base) {
91 spin_unlock(&dentry->d_lock);
92 rcu_read_unlock();
93 WARN_ON(1);
94 return end;
95 }
81 namelen = strlen(base); 96 namelen = strlen(base);
82 /* Strip off excess slashes in base string */ 97 /* Strip off excess slashes in base string */
83 while (namelen > 0 && base[namelen - 1] == '/') 98 while (namelen > 0 && base[namelen - 1] == '/')
84 namelen--; 99 namelen--;
85 buflen -= namelen; 100 buflen -= namelen;
86 if (buflen < 0) 101 if (buflen < 0) {
102 spin_lock(&dentry->d_lock);
103 rcu_read_unlock();
87 goto Elong; 104 goto Elong;
105 }
88 end -= namelen; 106 end -= namelen;
89 memcpy(end, base, namelen); 107 memcpy(end, base, namelen);
108 spin_unlock(&dentry->d_lock);
109 rcu_read_unlock();
90 return end; 110 return end;
91Elong_unlock: 111Elong_unlock:
112 spin_lock(&dentry->d_lock);
92 rcu_read_unlock(); 113 rcu_read_unlock();
93 if (read_seqretry(&rename_lock, seq)) 114 if (read_seqretry(&rename_lock, seq))
94 goto rename_retry; 115 goto rename_retry;
@@ -143,9 +164,9 @@ struct vfsmount *nfs_d_automount(struct path *path)
143 } 164 }
144 165
145 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) 166 if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
146 mnt = nfs_do_refmount(path->mnt, path->dentry); 167 mnt = nfs_do_refmount(path->mnt->mnt_sb, path->dentry);
147 else 168 else
148 mnt = nfs_do_submount(path->mnt, path->dentry, fh, fattr); 169 mnt = nfs_do_submount(path->mnt->mnt_sb, path->dentry, fh, fattr);
149 if (IS_ERR(mnt)) 170 if (IS_ERR(mnt))
150 goto out; 171 goto out;
151 172
@@ -209,19 +230,19 @@ static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server,
209 230
210/** 231/**
211 * nfs_do_submount - set up mountpoint when crossing a filesystem boundary 232 * nfs_do_submount - set up mountpoint when crossing a filesystem boundary
212 * @mnt_parent - mountpoint of parent directory 233 * @sb - superblock of parent directory
213 * @dentry - parent directory 234 * @dentry - parent directory
214 * @fh - filehandle for new root dentry 235 * @fh - filehandle for new root dentry
215 * @fattr - attributes for new root inode 236 * @fattr - attributes for new root inode
216 * 237 *
217 */ 238 */
218static struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent, 239static struct vfsmount *nfs_do_submount(struct super_block *sb,
219 const struct dentry *dentry, 240 struct dentry *dentry,
220 struct nfs_fh *fh, 241 struct nfs_fh *fh,
221 struct nfs_fattr *fattr) 242 struct nfs_fattr *fattr)
222{ 243{
223 struct nfs_clone_mount mountdata = { 244 struct nfs_clone_mount mountdata = {
224 .sb = mnt_parent->mnt_sb, 245 .sb = sb,
225 .dentry = dentry, 246 .dentry = dentry,
226 .fh = fh, 247 .fh = fh,
227 .fattr = fattr, 248 .fattr = fattr,
@@ -237,11 +258,11 @@ static struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent,
237 dentry->d_name.name); 258 dentry->d_name.name);
238 if (page == NULL) 259 if (page == NULL)
239 goto out; 260 goto out;
240 devname = nfs_devname(mnt_parent, dentry, page, PAGE_SIZE); 261 devname = nfs_devname(dentry, page, PAGE_SIZE);
241 mnt = (struct vfsmount *)devname; 262 mnt = (struct vfsmount *)devname;
242 if (IS_ERR(devname)) 263 if (IS_ERR(devname))
243 goto free_page; 264 goto free_page;
244 mnt = nfs_do_clone_mount(NFS_SB(mnt_parent->mnt_sb), devname, &mountdata); 265 mnt = nfs_do_clone_mount(NFS_SB(sb), devname, &mountdata);
245free_page: 266free_page:
246 free_page((unsigned long)page); 267 free_page((unsigned long)page);
247out: 268out:
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 3c2a1724fbd2..46942e2680a0 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -54,33 +54,29 @@ Elong:
54/* 54/*
55 * Determine the mount path as a string 55 * Determine the mount path as a string
56 */ 56 */
57static char *nfs4_path(const struct vfsmount *mnt_parent, 57static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
58 const struct dentry *dentry,
59 char *buffer, ssize_t buflen)
60{ 58{
61 const char *srvpath; 59 char *limit;
62 60 char *path = nfs_path(&limit, dentry, buffer, buflen);
63 srvpath = strchr(mnt_parent->mnt_devname, ':'); 61 if (!IS_ERR(path)) {
64 if (srvpath) 62 char *colon = strchr(path, ':');
65 srvpath++; 63 if (colon && colon < limit)
66 else 64 path = colon + 1;
67 srvpath = mnt_parent->mnt_devname; 65 }
68 66 return path;
69 return nfs_path(srvpath, mnt_parent->mnt_root, dentry, buffer, buflen);
70} 67}
71 68
72/* 69/*
73 * Check that fs_locations::fs_root [RFC3530 6.3] is a prefix for what we 70 * Check that fs_locations::fs_root [RFC3530 6.3] is a prefix for what we
74 * believe to be the server path to this dentry 71 * believe to be the server path to this dentry
75 */ 72 */
76static int nfs4_validate_fspath(const struct vfsmount *mnt_parent, 73static int nfs4_validate_fspath(struct dentry *dentry,
77 const struct dentry *dentry,
78 const struct nfs4_fs_locations *locations, 74 const struct nfs4_fs_locations *locations,
79 char *page, char *page2) 75 char *page, char *page2)
80{ 76{
81 const char *path, *fs_path; 77 const char *path, *fs_path;
82 78
83 path = nfs4_path(mnt_parent, dentry, page, PAGE_SIZE); 79 path = nfs4_path(dentry, page, PAGE_SIZE);
84 if (IS_ERR(path)) 80 if (IS_ERR(path))
85 return PTR_ERR(path); 81 return PTR_ERR(path);
86 82
@@ -165,20 +161,20 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
165 161
166/** 162/**
167 * nfs_follow_referral - set up mountpoint when hitting a referral on moved error 163 * nfs_follow_referral - set up mountpoint when hitting a referral on moved error
168 * @mnt_parent - mountpoint of parent directory 164 * @sb - superblock of parent directory
169 * @dentry - parent directory 165 * @dentry - parent directory
170 * @locations - array of NFSv4 server location information 166 * @locations - array of NFSv4 server location information
171 * 167 *
172 */ 168 */
173static struct vfsmount *nfs_follow_referral(const struct vfsmount *mnt_parent, 169static struct vfsmount *nfs_follow_referral(struct super_block *sb,
174 const struct dentry *dentry, 170 struct dentry *dentry,
175 const struct nfs4_fs_locations *locations) 171 const struct nfs4_fs_locations *locations)
176{ 172{
177 struct vfsmount *mnt = ERR_PTR(-ENOENT); 173 struct vfsmount *mnt = ERR_PTR(-ENOENT);
178 struct nfs_clone_mount mountdata = { 174 struct nfs_clone_mount mountdata = {
179 .sb = mnt_parent->mnt_sb, 175 .sb = sb,
180 .dentry = dentry, 176 .dentry = dentry,
181 .authflavor = NFS_SB(mnt_parent->mnt_sb)->client->cl_auth->au_flavor, 177 .authflavor = NFS_SB(sb)->client->cl_auth->au_flavor,
182 }; 178 };
183 char *page = NULL, *page2 = NULL; 179 char *page = NULL, *page2 = NULL;
184 int loc, error; 180 int loc, error;
@@ -198,7 +194,7 @@ static struct vfsmount *nfs_follow_referral(const struct vfsmount *mnt_parent,
198 goto out; 194 goto out;
199 195
200 /* Ensure fs path is a prefix of current dentry path */ 196 /* Ensure fs path is a prefix of current dentry path */
201 error = nfs4_validate_fspath(mnt_parent, dentry, locations, page, page2); 197 error = nfs4_validate_fspath(dentry, locations, page, page2);
202 if (error < 0) { 198 if (error < 0) {
203 mnt = ERR_PTR(error); 199 mnt = ERR_PTR(error);
204 goto out; 200 goto out;
@@ -225,11 +221,10 @@ out:
225 221
226/* 222/*
227 * nfs_do_refmount - handle crossing a referral on server 223 * nfs_do_refmount - handle crossing a referral on server
228 * @mnt_parent - mountpoint of referral
229 * @dentry - dentry of referral 224 * @dentry - dentry of referral
230 * 225 *
231 */ 226 */
232struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 227struct vfsmount *nfs_do_refmount(struct super_block *sb, struct dentry *dentry)
233{ 228{
234 struct vfsmount *mnt = ERR_PTR(-ENOMEM); 229 struct vfsmount *mnt = ERR_PTR(-ENOMEM);
235 struct dentry *parent; 230 struct dentry *parent;
@@ -262,7 +257,7 @@ struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentr
262 fs_locations->fs_path.ncomponents <= 0) 257 fs_locations->fs_path.ncomponents <= 0)
263 goto out_free; 258 goto out_free;
264 259
265 mnt = nfs_follow_referral(mnt_parent, dentry, fs_locations); 260 mnt = nfs_follow_referral(sb, dentry, fs_locations);
266out_free: 261out_free:
267 __free_page(page); 262 __free_page(page);
268 kfree(fs_locations); 263 kfree(fs_locations);
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 1d81032b226a..a6ab483c9ad0 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -2771,16 +2771,15 @@ static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
2771 return root_mnt; 2771 return root_mnt;
2772} 2772}
2773 2773
2774static void nfs_fix_devname(const struct path *path, struct vfsmount *mnt) 2774static void nfs_fix_devname(struct dentry *dentry, struct vfsmount *mnt)
2775{ 2775{
2776 char *page = (char *) __get_free_page(GFP_KERNEL); 2776 char *page = (char *) __get_free_page(GFP_KERNEL);
2777 char *devname, *tmp; 2777 char *devname, *tmp;
2778 char *dummy;
2778 2779
2779 if (page == NULL) 2780 if (page == NULL)
2780 return; 2781 return;
2781 devname = nfs_path(path->mnt->mnt_devname, 2782 devname = nfs_path(&dummy, dentry, page, PAGE_SIZE);
2782 path->mnt->mnt_root, path->dentry,
2783 page, PAGE_SIZE);
2784 if (IS_ERR(devname)) 2783 if (IS_ERR(devname))
2785 goto out_freepage; 2784 goto out_freepage;
2786 tmp = kstrdup(devname, GFP_KERNEL); 2785 tmp = kstrdup(devname, GFP_KERNEL);
@@ -2894,7 +2893,7 @@ static int nfs_follow_remote_path(struct vfsmount *root_mnt,
2894 mnt_target->mnt_root = dget(nd->path.dentry); 2893 mnt_target->mnt_root = dget(nd->path.dentry);
2895 2894
2896 /* Correct the device pathname */ 2895 /* Correct the device pathname */
2897 nfs_fix_devname(&nd->path, mnt_target); 2896 nfs_fix_devname(nd->path.dentry, mnt_target);
2898 2897
2899 path_put(&nd->path); 2898 path_put(&nd->path);
2900 kfree(nd); 2899 kfree(nd);