]>
Commit | Line | Data |
---|---|---|
ec26815a | 1 | /* mountpoint management |
1da177e4 LT |
2 | * |
3 | * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells (dhowells@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the License, or (at your option) any later version. | |
10 | */ | |
11 | ||
12 | #include <linux/kernel.h> | |
13 | #include <linux/module.h> | |
14 | #include <linux/init.h> | |
1da177e4 LT |
15 | #include <linux/slab.h> |
16 | #include <linux/fs.h> | |
17 | #include <linux/pagemap.h> | |
18 | #include <linux/mount.h> | |
19 | #include <linux/namei.h> | |
6b3286ed | 20 | #include <linux/mnt_namespace.h> |
1da177e4 LT |
21 | #include "super.h" |
22 | #include "cell.h" | |
23 | #include "volume.h" | |
24 | #include "vnode.h" | |
25 | #include "internal.h" | |
26 | ||
27 | ||
28 | static struct dentry *afs_mntpt_lookup(struct inode *dir, | |
29 | struct dentry *dentry, | |
30 | struct nameidata *nd); | |
31 | static int afs_mntpt_open(struct inode *inode, struct file *file); | |
008b150a | 32 | static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd); |
1da177e4 | 33 | |
4b6f5d20 | 34 | const struct file_operations afs_mntpt_file_operations = { |
1da177e4 LT |
35 | .open = afs_mntpt_open, |
36 | }; | |
37 | ||
754661f1 | 38 | const struct inode_operations afs_mntpt_inode_operations = { |
1da177e4 LT |
39 | .lookup = afs_mntpt_lookup, |
40 | .follow_link = afs_mntpt_follow_link, | |
41 | .readlink = page_readlink, | |
42 | .getattr = afs_inode_getattr, | |
43 | }; | |
44 | ||
45 | static LIST_HEAD(afs_vfsmounts); | |
46 | ||
47 | static void afs_mntpt_expiry_timed_out(struct afs_timer *timer); | |
48 | ||
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 | ||
1da177e4 LT |
57 | /* |
58 | * check a symbolic link to see whether it actually encodes a mountpoint | |
59 | * - sets the AFS_VNODE_MOUNTPOINT flag on the vnode appropriately | |
60 | */ | |
61 | int afs_mntpt_check_symlink(struct afs_vnode *vnode) | |
62 | { | |
63 | struct page *page; | |
1da177e4 LT |
64 | size_t size; |
65 | char *buf; | |
66 | int ret; | |
67 | ||
68 | _enter("{%u,%u}", vnode->fid.vnode, vnode->fid.unique); | |
69 | ||
70 | /* read the contents of the symlink into the pagecache */ | |
090d2b18 | 71 | page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, NULL); |
1da177e4 LT |
72 | if (IS_ERR(page)) { |
73 | ret = PTR_ERR(page); | |
74 | goto out; | |
75 | } | |
76 | ||
77 | ret = -EIO; | |
78 | wait_on_page_locked(page); | |
79 | buf = kmap(page); | |
80 | if (!PageUptodate(page)) | |
81 | goto out_free; | |
82 | if (PageError(page)) | |
83 | goto out_free; | |
84 | ||
85 | /* examine the symlink's contents */ | |
86 | size = vnode->status.size; | |
87 | _debug("symlink to %*.*s", size, (int) size, buf); | |
88 | ||
89 | if (size > 2 && | |
90 | (buf[0] == '%' || buf[0] == '#') && | |
91 | buf[size - 1] == '.' | |
92 | ) { | |
93 | _debug("symlink is a mountpoint"); | |
94 | spin_lock(&vnode->lock); | |
95 | vnode->flags |= AFS_VNODE_MOUNTPOINT; | |
96 | spin_unlock(&vnode->lock); | |
97 | } | |
98 | ||
99 | ret = 0; | |
100 | ||
ec26815a | 101 | out_free: |
1da177e4 LT |
102 | kunmap(page); |
103 | page_cache_release(page); | |
ec26815a | 104 | out: |
1da177e4 LT |
105 | _leave(" = %d", ret); |
106 | return ret; | |
ec26815a | 107 | } |
1da177e4 | 108 | |
1da177e4 LT |
109 | /* |
110 | * no valid lookup procedure on this sort of dir | |
111 | */ | |
112 | static struct dentry *afs_mntpt_lookup(struct inode *dir, | |
113 | struct dentry *dentry, | |
114 | struct nameidata *nd) | |
115 | { | |
116 | kenter("%p,%p{%p{%s},%s}", | |
117 | dir, | |
118 | dentry, | |
119 | dentry->d_parent, | |
120 | dentry->d_parent ? | |
121 | dentry->d_parent->d_name.name : (const unsigned char *) "", | |
122 | dentry->d_name.name); | |
123 | ||
124 | return ERR_PTR(-EREMOTE); | |
ec26815a | 125 | } |
1da177e4 | 126 | |
1da177e4 LT |
127 | /* |
128 | * no valid open procedure on this sort of dir | |
129 | */ | |
130 | static int afs_mntpt_open(struct inode *inode, struct file *file) | |
131 | { | |
132 | kenter("%p,%p{%p{%s},%s}", | |
133 | inode, file, | |
1d56a969 JS |
134 | file->f_path.dentry->d_parent, |
135 | file->f_path.dentry->d_parent ? | |
136 | file->f_path.dentry->d_parent->d_name.name : | |
1da177e4 | 137 | (const unsigned char *) "", |
1d56a969 | 138 | file->f_path.dentry->d_name.name); |
1da177e4 LT |
139 | |
140 | return -EREMOTE; | |
ec26815a | 141 | } |
1da177e4 | 142 | |
1da177e4 LT |
143 | /* |
144 | * create a vfsmount to be automounted | |
145 | */ | |
146 | static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt) | |
147 | { | |
148 | struct afs_super_info *super; | |
149 | struct vfsmount *mnt; | |
150 | struct page *page = NULL; | |
151 | size_t size; | |
152 | char *buf, *devname = NULL, *options = NULL; | |
1da177e4 LT |
153 | int ret; |
154 | ||
155 | kenter("{%s}", mntpt->d_name.name); | |
156 | ||
157 | BUG_ON(!mntpt->d_inode); | |
158 | ||
159 | ret = -EINVAL; | |
160 | size = mntpt->d_inode->i_size; | |
161 | if (size > PAGE_SIZE - 1) | |
162 | goto error; | |
163 | ||
164 | ret = -ENOMEM; | |
165 | devname = (char *) get_zeroed_page(GFP_KERNEL); | |
166 | if (!devname) | |
167 | goto error; | |
168 | ||
169 | options = (char *) get_zeroed_page(GFP_KERNEL); | |
170 | if (!options) | |
171 | goto error; | |
172 | ||
173 | /* read the contents of the AFS special symlink */ | |
090d2b18 | 174 | page = read_mapping_page(mntpt->d_inode->i_mapping, 0, NULL); |
1da177e4 LT |
175 | if (IS_ERR(page)) { |
176 | ret = PTR_ERR(page); | |
177 | goto error; | |
178 | } | |
179 | ||
180 | ret = -EIO; | |
181 | wait_on_page_locked(page); | |
182 | if (!PageUptodate(page) || PageError(page)) | |
183 | goto error; | |
184 | ||
185 | buf = kmap(page); | |
186 | memcpy(devname, buf, size); | |
187 | kunmap(page); | |
188 | page_cache_release(page); | |
189 | page = NULL; | |
190 | ||
191 | /* work out what options we want */ | |
192 | super = AFS_FS_S(mntpt->d_sb); | |
193 | memcpy(options, "cell=", 5); | |
194 | strcpy(options + 5, super->volume->cell->name); | |
195 | if (super->volume->type == AFSVL_RWVOL) | |
196 | strcat(options, ",rwpath"); | |
197 | ||
198 | /* try and do the mount */ | |
199 | kdebug("--- attempting mount %s -o %s ---", devname, options); | |
1f5ce9e9 | 200 | mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options); |
1da177e4 LT |
201 | kdebug("--- mount result %p ---", mnt); |
202 | ||
203 | free_page((unsigned long) devname); | |
204 | free_page((unsigned long) options); | |
205 | kleave(" = %p", mnt); | |
206 | return mnt; | |
207 | ||
ec26815a | 208 | error: |
1da177e4 LT |
209 | if (page) |
210 | page_cache_release(page); | |
211 | if (devname) | |
212 | free_page((unsigned long) devname); | |
213 | if (options) | |
214 | free_page((unsigned long) options); | |
215 | kleave(" = %d", ret); | |
216 | return ERR_PTR(ret); | |
ec26815a | 217 | } |
1da177e4 | 218 | |
1da177e4 LT |
219 | /* |
220 | * follow a link from a mountpoint directory, thus causing it to be mounted | |
221 | */ | |
008b150a | 222 | static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd) |
1da177e4 LT |
223 | { |
224 | struct vfsmount *newmnt; | |
225 | struct dentry *old_dentry; | |
226 | int err; | |
227 | ||
228 | kenter("%p{%s},{%s:%p{%s}}", | |
229 | dentry, | |
230 | dentry->d_name.name, | |
231 | nd->mnt->mnt_devname, | |
232 | dentry, | |
233 | nd->dentry->d_name.name); | |
234 | ||
235 | newmnt = afs_mntpt_do_automount(dentry); | |
236 | if (IS_ERR(newmnt)) { | |
237 | path_release(nd); | |
008b150a | 238 | return (void *)newmnt; |
1da177e4 LT |
239 | } |
240 | ||
241 | old_dentry = nd->dentry; | |
242 | nd->dentry = dentry; | |
243 | err = do_add_mount(newmnt, nd, 0, &afs_vfsmounts); | |
244 | nd->dentry = old_dentry; | |
245 | ||
246 | path_release(nd); | |
247 | ||
248 | if (!err) { | |
249 | mntget(newmnt); | |
250 | nd->mnt = newmnt; | |
251 | dget(newmnt->mnt_root); | |
252 | nd->dentry = newmnt->mnt_root; | |
253 | } | |
254 | ||
255 | kleave(" = %d", err); | |
008b150a | 256 | return ERR_PTR(err); |
ec26815a | 257 | } |
1da177e4 | 258 | |
1da177e4 LT |
259 | /* |
260 | * handle mountpoint expiry timer going off | |
261 | */ | |
262 | static void afs_mntpt_expiry_timed_out(struct afs_timer *timer) | |
263 | { | |
264 | kenter(""); | |
265 | ||
266 | mark_mounts_for_expiry(&afs_vfsmounts); | |
267 | ||
268 | afs_kafstimod_add_timer(&afs_mntpt_expiry_timer, | |
269 | afs_mntpt_expiry_timeout * HZ); | |
270 | ||
271 | kleave(""); | |
ec26815a | 272 | } |