diff options
Diffstat (limited to 'fs/afs/mntpt.c')
-rw-r--r-- | fs/afs/mntpt.c | 141 |
1 files changed, 79 insertions, 62 deletions
diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c index 68495f0de7b3..b905ae37f912 100644 --- a/fs/afs/mntpt.c +++ b/fs/afs/mntpt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* mntpt.c: mountpoint management | 1 | /* mountpoint management |
2 | * | 2 | * |
3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. | 3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. |
4 | * Written by David Howells (dhowells@redhat.com) | 4 | * Written by David Howells (dhowells@redhat.com) |
@@ -18,10 +18,6 @@ | |||
18 | #include <linux/mount.h> | 18 | #include <linux/mount.h> |
19 | #include <linux/namei.h> | 19 | #include <linux/namei.h> |
20 | #include <linux/mnt_namespace.h> | 20 | #include <linux/mnt_namespace.h> |
21 | #include "super.h" | ||
22 | #include "cell.h" | ||
23 | #include "volume.h" | ||
24 | #include "vnode.h" | ||
25 | #include "internal.h" | 21 | #include "internal.h" |
26 | 22 | ||
27 | 23 | ||
@@ -30,6 +26,7 @@ static struct dentry *afs_mntpt_lookup(struct inode *dir, | |||
30 | struct nameidata *nd); | 26 | struct nameidata *nd); |
31 | static int afs_mntpt_open(struct inode *inode, struct file *file); | 27 | static int afs_mntpt_open(struct inode *inode, struct file *file); |
32 | static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd); | 28 | static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd); |
29 | static void afs_mntpt_expiry_timed_out(struct work_struct *work); | ||
33 | 30 | ||
34 | const struct file_operations afs_mntpt_file_operations = { | 31 | const struct file_operations afs_mntpt_file_operations = { |
35 | .open = afs_mntpt_open, | 32 | .open = afs_mntpt_open, |
@@ -43,24 +40,19 @@ const struct inode_operations afs_mntpt_inode_operations = { | |||
43 | }; | 40 | }; |
44 | 41 | ||
45 | static LIST_HEAD(afs_vfsmounts); | 42 | static LIST_HEAD(afs_vfsmounts); |
43 | static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out); | ||
46 | 44 | ||
47 | static void afs_mntpt_expiry_timed_out(struct afs_timer *timer); | 45 | unsigned long afs_mntpt_expiry_timeout = 10 * 60; |
48 | 46 | ||
49 | struct afs_timer_ops afs_mntpt_expiry_timer_ops = { | ||
50 | .timed_out = afs_mntpt_expiry_timed_out, | ||
51 | }; | ||
52 | |||
53 | struct afs_timer afs_mntpt_expiry_timer; | ||
54 | |||
55 | unsigned long afs_mntpt_expiry_timeout = 20; | ||
56 | |||
57 | /*****************************************************************************/ | ||
58 | /* | 47 | /* |
59 | * check a symbolic link to see whether it actually encodes a mountpoint | 48 | * check a symbolic link to see whether it actually encodes a mountpoint |
60 | * - sets the AFS_VNODE_MOUNTPOINT flag on the vnode appropriately | 49 | * - sets the AFS_VNODE_MOUNTPOINT flag on the vnode appropriately |
61 | */ | 50 | */ |
62 | int afs_mntpt_check_symlink(struct afs_vnode *vnode) | 51 | int afs_mntpt_check_symlink(struct afs_vnode *vnode, struct key *key) |
63 | { | 52 | { |
53 | struct file file = { | ||
54 | .private_data = key, | ||
55 | }; | ||
64 | struct page *page; | 56 | struct page *page; |
65 | size_t size; | 57 | size_t size; |
66 | char *buf; | 58 | char *buf; |
@@ -69,7 +61,7 @@ int afs_mntpt_check_symlink(struct afs_vnode *vnode) | |||
69 | _enter("{%u,%u}", vnode->fid.vnode, vnode->fid.unique); | 61 | _enter("{%u,%u}", vnode->fid.vnode, vnode->fid.unique); |
70 | 62 | ||
71 | /* read the contents of the symlink into the pagecache */ | 63 | /* read the contents of the symlink into the pagecache */ |
72 | page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, NULL); | 64 | page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, &file); |
73 | if (IS_ERR(page)) { | 65 | if (IS_ERR(page)) { |
74 | ret = PTR_ERR(page); | 66 | ret = PTR_ERR(page); |
75 | goto out; | 67 | goto out; |
@@ -85,7 +77,7 @@ int afs_mntpt_check_symlink(struct afs_vnode *vnode) | |||
85 | 77 | ||
86 | /* examine the symlink's contents */ | 78 | /* examine the symlink's contents */ |
87 | size = vnode->status.size; | 79 | size = vnode->status.size; |
88 | _debug("symlink to %*.*s", size, (int) size, buf); | 80 | _debug("symlink to %*.*s", (int) size, (int) size, buf); |
89 | 81 | ||
90 | if (size > 2 && | 82 | if (size > 2 && |
91 | (buf[0] == '%' || buf[0] == '#') && | 83 | (buf[0] == '%' || buf[0] == '#') && |
@@ -93,22 +85,20 @@ int afs_mntpt_check_symlink(struct afs_vnode *vnode) | |||
93 | ) { | 85 | ) { |
94 | _debug("symlink is a mountpoint"); | 86 | _debug("symlink is a mountpoint"); |
95 | spin_lock(&vnode->lock); | 87 | spin_lock(&vnode->lock); |
96 | vnode->flags |= AFS_VNODE_MOUNTPOINT; | 88 | set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags); |
97 | spin_unlock(&vnode->lock); | 89 | spin_unlock(&vnode->lock); |
98 | } | 90 | } |
99 | 91 | ||
100 | ret = 0; | 92 | ret = 0; |
101 | 93 | ||
102 | out_free: | 94 | out_free: |
103 | kunmap(page); | 95 | kunmap(page); |
104 | page_cache_release(page); | 96 | page_cache_release(page); |
105 | out: | 97 | out: |
106 | _leave(" = %d", ret); | 98 | _leave(" = %d", ret); |
107 | return ret; | 99 | return ret; |
100 | } | ||
108 | 101 | ||
109 | } /* end afs_mntpt_check_symlink() */ | ||
110 | |||
111 | /*****************************************************************************/ | ||
112 | /* | 102 | /* |
113 | * no valid lookup procedure on this sort of dir | 103 | * no valid lookup procedure on this sort of dir |
114 | */ | 104 | */ |
@@ -116,7 +106,7 @@ static struct dentry *afs_mntpt_lookup(struct inode *dir, | |||
116 | struct dentry *dentry, | 106 | struct dentry *dentry, |
117 | struct nameidata *nd) | 107 | struct nameidata *nd) |
118 | { | 108 | { |
119 | kenter("%p,%p{%p{%s},%s}", | 109 | _enter("%p,%p{%p{%s},%s}", |
120 | dir, | 110 | dir, |
121 | dentry, | 111 | dentry, |
122 | dentry->d_parent, | 112 | dentry->d_parent, |
@@ -125,15 +115,14 @@ static struct dentry *afs_mntpt_lookup(struct inode *dir, | |||
125 | dentry->d_name.name); | 115 | dentry->d_name.name); |
126 | 116 | ||
127 | return ERR_PTR(-EREMOTE); | 117 | return ERR_PTR(-EREMOTE); |
128 | } /* end afs_mntpt_lookup() */ | 118 | } |
129 | 119 | ||
130 | /*****************************************************************************/ | ||
131 | /* | 120 | /* |
132 | * no valid open procedure on this sort of dir | 121 | * no valid open procedure on this sort of dir |
133 | */ | 122 | */ |
134 | static int afs_mntpt_open(struct inode *inode, struct file *file) | 123 | static int afs_mntpt_open(struct inode *inode, struct file *file) |
135 | { | 124 | { |
136 | kenter("%p,%p{%p{%s},%s}", | 125 | _enter("%p,%p{%p{%s},%s}", |
137 | inode, file, | 126 | inode, file, |
138 | file->f_path.dentry->d_parent, | 127 | file->f_path.dentry->d_parent, |
139 | file->f_path.dentry->d_parent ? | 128 | file->f_path.dentry->d_parent ? |
@@ -142,9 +131,8 @@ static int afs_mntpt_open(struct inode *inode, struct file *file) | |||
142 | file->f_path.dentry->d_name.name); | 131 | file->f_path.dentry->d_name.name); |
143 | 132 | ||
144 | return -EREMOTE; | 133 | return -EREMOTE; |
145 | } /* end afs_mntpt_open() */ | 134 | } |
146 | 135 | ||
147 | /*****************************************************************************/ | ||
148 | /* | 136 | /* |
149 | * create a vfsmount to be automounted | 137 | * create a vfsmount to be automounted |
150 | */ | 138 | */ |
@@ -157,7 +145,7 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt) | |||
157 | char *buf, *devname = NULL, *options = NULL; | 145 | char *buf, *devname = NULL, *options = NULL; |
158 | int ret; | 146 | int ret; |
159 | 147 | ||
160 | kenter("{%s}", mntpt->d_name.name); | 148 | _enter("{%s}", mntpt->d_name.name); |
161 | 149 | ||
162 | BUG_ON(!mntpt->d_inode); | 150 | BUG_ON(!mntpt->d_inode); |
163 | 151 | ||
@@ -201,79 +189,108 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt) | |||
201 | strcat(options, ",rwpath"); | 189 | strcat(options, ",rwpath"); |
202 | 190 | ||
203 | /* try and do the mount */ | 191 | /* try and do the mount */ |
204 | kdebug("--- attempting mount %s -o %s ---", devname, options); | 192 | _debug("--- attempting mount %s -o %s ---", devname, options); |
205 | mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options); | 193 | mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options); |
206 | kdebug("--- mount result %p ---", mnt); | 194 | _debug("--- mount result %p ---", mnt); |
207 | 195 | ||
208 | free_page((unsigned long) devname); | 196 | free_page((unsigned long) devname); |
209 | free_page((unsigned long) options); | 197 | free_page((unsigned long) options); |
210 | kleave(" = %p", mnt); | 198 | _leave(" = %p", mnt); |
211 | return mnt; | 199 | return mnt; |
212 | 200 | ||
213 | error: | 201 | error: |
214 | if (page) | 202 | if (page) |
215 | page_cache_release(page); | 203 | page_cache_release(page); |
216 | if (devname) | 204 | if (devname) |
217 | free_page((unsigned long) devname); | 205 | free_page((unsigned long) devname); |
218 | if (options) | 206 | if (options) |
219 | free_page((unsigned long) options); | 207 | free_page((unsigned long) options); |
220 | kleave(" = %d", ret); | 208 | _leave(" = %d", ret); |
221 | return ERR_PTR(ret); | 209 | return ERR_PTR(ret); |
222 | } /* end afs_mntpt_do_automount() */ | 210 | } |
223 | 211 | ||
224 | /*****************************************************************************/ | ||
225 | /* | 212 | /* |
226 | * follow a link from a mountpoint directory, thus causing it to be mounted | 213 | * follow a link from a mountpoint directory, thus causing it to be mounted |
227 | */ | 214 | */ |
228 | static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd) | 215 | static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd) |
229 | { | 216 | { |
230 | struct vfsmount *newmnt; | 217 | struct vfsmount *newmnt; |
231 | struct dentry *old_dentry; | ||
232 | int err; | 218 | int err; |
233 | 219 | ||
234 | kenter("%p{%s},{%s:%p{%s}}", | 220 | _enter("%p{%s},{%s:%p{%s},}", |
235 | dentry, | 221 | dentry, |
236 | dentry->d_name.name, | 222 | dentry->d_name.name, |
237 | nd->mnt->mnt_devname, | 223 | nd->mnt->mnt_devname, |
238 | dentry, | 224 | dentry, |
239 | nd->dentry->d_name.name); | 225 | nd->dentry->d_name.name); |
240 | 226 | ||
241 | newmnt = afs_mntpt_do_automount(dentry); | 227 | dput(nd->dentry); |
228 | nd->dentry = dget(dentry); | ||
229 | |||
230 | newmnt = afs_mntpt_do_automount(nd->dentry); | ||
242 | if (IS_ERR(newmnt)) { | 231 | if (IS_ERR(newmnt)) { |
243 | path_release(nd); | 232 | path_release(nd); |
244 | return (void *)newmnt; | 233 | return (void *)newmnt; |
245 | } | 234 | } |
246 | 235 | ||
247 | old_dentry = nd->dentry; | 236 | mntget(newmnt); |
248 | nd->dentry = dentry; | 237 | err = do_add_mount(newmnt, nd, MNT_SHRINKABLE, &afs_vfsmounts); |
249 | err = do_add_mount(newmnt, nd, 0, &afs_vfsmounts); | 238 | switch (err) { |
250 | nd->dentry = old_dentry; | 239 | case 0: |
251 | 240 | mntput(nd->mnt); | |
252 | path_release(nd); | 241 | dput(nd->dentry); |
253 | |||
254 | if (!err) { | ||
255 | mntget(newmnt); | ||
256 | nd->mnt = newmnt; | 242 | nd->mnt = newmnt; |
257 | dget(newmnt->mnt_root); | 243 | nd->dentry = dget(newmnt->mnt_root); |
258 | nd->dentry = newmnt->mnt_root; | 244 | schedule_delayed_work(&afs_mntpt_expiry_timer, |
245 | afs_mntpt_expiry_timeout * HZ); | ||
246 | break; | ||
247 | case -EBUSY: | ||
248 | /* someone else made a mount here whilst we were busy */ | ||
249 | while (d_mountpoint(nd->dentry) && | ||
250 | follow_down(&nd->mnt, &nd->dentry)) | ||
251 | ; | ||
252 | err = 0; | ||
253 | default: | ||
254 | mntput(newmnt); | ||
255 | break; | ||
259 | } | 256 | } |
260 | 257 | ||
261 | kleave(" = %d", err); | 258 | _leave(" = %d", err); |
262 | return ERR_PTR(err); | 259 | return ERR_PTR(err); |
263 | } /* end afs_mntpt_follow_link() */ | 260 | } |
264 | 261 | ||
265 | /*****************************************************************************/ | ||
266 | /* | 262 | /* |
267 | * handle mountpoint expiry timer going off | 263 | * handle mountpoint expiry timer going off |
268 | */ | 264 | */ |
269 | static void afs_mntpt_expiry_timed_out(struct afs_timer *timer) | 265 | static void afs_mntpt_expiry_timed_out(struct work_struct *work) |
270 | { | 266 | { |
271 | kenter(""); | 267 | _enter(""); |
272 | 268 | ||
273 | mark_mounts_for_expiry(&afs_vfsmounts); | 269 | if (!list_empty(&afs_vfsmounts)) { |
270 | mark_mounts_for_expiry(&afs_vfsmounts); | ||
271 | schedule_delayed_work(&afs_mntpt_expiry_timer, | ||
272 | afs_mntpt_expiry_timeout * HZ); | ||
273 | } | ||
274 | |||
275 | _leave(""); | ||
276 | } | ||
274 | 277 | ||
275 | afs_kafstimod_add_timer(&afs_mntpt_expiry_timer, | 278 | /* |
276 | afs_mntpt_expiry_timeout * HZ); | 279 | * kill the AFS mountpoint timer if it's still running |
280 | */ | ||
281 | void afs_mntpt_kill_timer(void) | ||
282 | { | ||
283 | _enter(""); | ||
277 | 284 | ||
278 | kleave(""); | 285 | ASSERT(list_empty(&afs_vfsmounts)); |
279 | } /* end afs_mntpt_expiry_timed_out() */ | 286 | cancel_delayed_work(&afs_mntpt_expiry_timer); |
287 | flush_scheduled_work(); | ||
288 | } | ||
289 | |||
290 | /* | ||
291 | * begin unmount by attempting to remove all automounted mountpoints we added | ||
292 | */ | ||
293 | void afs_umount_begin(struct vfsmount *vfsmnt, int flags) | ||
294 | { | ||
295 | shrink_submounts(vfsmnt, &afs_vfsmounts); | ||
296 | } | ||