]>
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 ([email protected]) | |
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/fs.h> |
16 | #include <linux/pagemap.h> | |
17 | #include <linux/mount.h> | |
18 | #include <linux/namei.h> | |
5a0e3ad6 | 19 | #include <linux/gfp.h> |
1da177e4 LT |
20 | #include "internal.h" |
21 | ||
22 | ||
23 | static struct dentry *afs_mntpt_lookup(struct inode *dir, | |
24 | struct dentry *dentry, | |
25 | struct nameidata *nd); | |
26 | static int afs_mntpt_open(struct inode *inode, struct file *file); | |
08e0e7c8 | 27 | static void afs_mntpt_expiry_timed_out(struct work_struct *work); |
1da177e4 | 28 | |
4b6f5d20 | 29 | const struct file_operations afs_mntpt_file_operations = { |
1da177e4 | 30 | .open = afs_mntpt_open, |
6038f373 | 31 | .llseek = noop_llseek, |
1da177e4 LT |
32 | }; |
33 | ||
754661f1 | 34 | const struct inode_operations afs_mntpt_inode_operations = { |
1da177e4 | 35 | .lookup = afs_mntpt_lookup, |
1da177e4 | 36 | .readlink = page_readlink, |
416351f2 | 37 | .getattr = afs_getattr, |
1da177e4 LT |
38 | }; |
39 | ||
bec5eb61 | 40 | const struct inode_operations afs_autocell_inode_operations = { |
bec5eb61 | 41 | .getattr = afs_getattr, |
42 | }; | |
43 | ||
1da177e4 | 44 | static LIST_HEAD(afs_vfsmounts); |
08e0e7c8 | 45 | static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out); |
1da177e4 | 46 | |
c1206a2c | 47 | static unsigned long afs_mntpt_expiry_timeout = 10 * 60; |
1da177e4 | 48 | |
1da177e4 LT |
49 | /* |
50 | * check a symbolic link to see whether it actually encodes a mountpoint | |
51 | * - sets the AFS_VNODE_MOUNTPOINT flag on the vnode appropriately | |
52 | */ | |
00d3b7a4 | 53 | int afs_mntpt_check_symlink(struct afs_vnode *vnode, struct key *key) |
1da177e4 LT |
54 | { |
55 | struct page *page; | |
1da177e4 LT |
56 | size_t size; |
57 | char *buf; | |
58 | int ret; | |
59 | ||
416351f2 DH |
60 | _enter("{%x:%u,%u}", |
61 | vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique); | |
1da177e4 LT |
62 | |
63 | /* read the contents of the symlink into the pagecache */ | |
f6d335c0 AV |
64 | page = read_cache_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, |
65 | afs_page_filler, key); | |
1da177e4 LT |
66 | if (IS_ERR(page)) { |
67 | ret = PTR_ERR(page); | |
68 | goto out; | |
69 | } | |
70 | ||
71 | ret = -EIO; | |
1da177e4 LT |
72 | if (PageError(page)) |
73 | goto out_free; | |
74 | ||
6fe6900e NP |
75 | buf = kmap(page); |
76 | ||
1da177e4 LT |
77 | /* examine the symlink's contents */ |
78 | size = vnode->status.size; | |
08e0e7c8 | 79 | _debug("symlink to %*.*s", (int) size, (int) size, buf); |
1da177e4 LT |
80 | |
81 | if (size > 2 && | |
82 | (buf[0] == '%' || buf[0] == '#') && | |
83 | buf[size - 1] == '.' | |
84 | ) { | |
85 | _debug("symlink is a mountpoint"); | |
86 | spin_lock(&vnode->lock); | |
08e0e7c8 | 87 | set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags); |
d18610b0 | 88 | vnode->vfs_inode.i_flags |= S_AUTOMOUNT; |
1da177e4 LT |
89 | spin_unlock(&vnode->lock); |
90 | } | |
91 | ||
92 | ret = 0; | |
93 | ||
1da177e4 | 94 | kunmap(page); |
6fe6900e | 95 | out_free: |
1da177e4 | 96 | page_cache_release(page); |
ec26815a | 97 | out: |
1da177e4 LT |
98 | _leave(" = %d", ret); |
99 | return ret; | |
ec26815a | 100 | } |
1da177e4 | 101 | |
1da177e4 LT |
102 | /* |
103 | * no valid lookup procedure on this sort of dir | |
104 | */ | |
105 | static struct dentry *afs_mntpt_lookup(struct inode *dir, | |
106 | struct dentry *dentry, | |
107 | struct nameidata *nd) | |
108 | { | |
08e0e7c8 | 109 | _enter("%p,%p{%p{%s},%s}", |
1da177e4 LT |
110 | dir, |
111 | dentry, | |
112 | dentry->d_parent, | |
113 | dentry->d_parent ? | |
114 | dentry->d_parent->d_name.name : (const unsigned char *) "", | |
115 | dentry->d_name.name); | |
116 | ||
117 | return ERR_PTR(-EREMOTE); | |
ec26815a | 118 | } |
1da177e4 | 119 | |
1da177e4 LT |
120 | /* |
121 | * no valid open procedure on this sort of dir | |
122 | */ | |
123 | static int afs_mntpt_open(struct inode *inode, struct file *file) | |
124 | { | |
08e0e7c8 | 125 | _enter("%p,%p{%p{%s},%s}", |
1da177e4 | 126 | inode, file, |
1d56a969 JS |
127 | file->f_path.dentry->d_parent, |
128 | file->f_path.dentry->d_parent ? | |
129 | file->f_path.dentry->d_parent->d_name.name : | |
1da177e4 | 130 | (const unsigned char *) "", |
1d56a969 | 131 | file->f_path.dentry->d_name.name); |
1da177e4 LT |
132 | |
133 | return -EREMOTE; | |
ec26815a | 134 | } |
1da177e4 | 135 | |
1da177e4 LT |
136 | /* |
137 | * create a vfsmount to be automounted | |
138 | */ | |
139 | static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt) | |
140 | { | |
141 | struct afs_super_info *super; | |
142 | struct vfsmount *mnt; | |
bec5eb61 | 143 | struct afs_vnode *vnode; |
083fd8b2 | 144 | struct page *page; |
bec5eb61 | 145 | char *devname, *options; |
146 | bool rwpath = false; | |
1da177e4 LT |
147 | int ret; |
148 | ||
08e0e7c8 | 149 | _enter("{%s}", mntpt->d_name.name); |
1da177e4 LT |
150 | |
151 | BUG_ON(!mntpt->d_inode); | |
152 | ||
1da177e4 LT |
153 | ret = -ENOMEM; |
154 | devname = (char *) get_zeroed_page(GFP_KERNEL); | |
155 | if (!devname) | |
083fd8b2 | 156 | goto error_no_devname; |
1da177e4 LT |
157 | |
158 | options = (char *) get_zeroed_page(GFP_KERNEL); | |
159 | if (!options) | |
083fd8b2 | 160 | goto error_no_options; |
1da177e4 | 161 | |
bec5eb61 | 162 | vnode = AFS_FS_I(mntpt->d_inode); |
163 | if (test_bit(AFS_VNODE_PSEUDODIR, &vnode->flags)) { | |
164 | /* if the directory is a pseudo directory, use the d_name */ | |
165 | static const char afs_root_cell[] = ":root.cell."; | |
166 | unsigned size = mntpt->d_name.len; | |
167 | ||
168 | ret = -ENOENT; | |
169 | if (size < 2 || size > AFS_MAXCELLNAME) | |
170 | goto error_no_page; | |
171 | ||
172 | if (mntpt->d_name.name[0] == '.') { | |
173 | devname[0] = '#'; | |
174 | memcpy(devname + 1, mntpt->d_name.name, size - 1); | |
175 | memcpy(devname + size, afs_root_cell, | |
176 | sizeof(afs_root_cell)); | |
177 | rwpath = true; | |
178 | } else { | |
179 | devname[0] = '%'; | |
180 | memcpy(devname + 1, mntpt->d_name.name, size); | |
181 | memcpy(devname + size + 1, afs_root_cell, | |
182 | sizeof(afs_root_cell)); | |
183 | } | |
184 | } else { | |
185 | /* read the contents of the AFS special symlink */ | |
186 | loff_t size = i_size_read(mntpt->d_inode); | |
187 | char *buf; | |
188 | ||
189 | ret = -EINVAL; | |
190 | if (size > PAGE_SIZE - 1) | |
191 | goto error_no_page; | |
192 | ||
193 | page = read_mapping_page(mntpt->d_inode->i_mapping, 0, NULL); | |
194 | if (IS_ERR(page)) { | |
195 | ret = PTR_ERR(page); | |
196 | goto error_no_page; | |
197 | } | |
198 | ||
199 | ret = -EIO; | |
200 | if (PageError(page)) | |
201 | goto error; | |
202 | ||
203 | buf = kmap_atomic(page, KM_USER0); | |
204 | memcpy(devname, buf, size); | |
205 | kunmap_atomic(buf, KM_USER0); | |
206 | page_cache_release(page); | |
207 | page = NULL; | |
1da177e4 LT |
208 | } |
209 | ||
1da177e4 LT |
210 | /* work out what options we want */ |
211 | super = AFS_FS_S(mntpt->d_sb); | |
212 | memcpy(options, "cell=", 5); | |
213 | strcpy(options + 5, super->volume->cell->name); | |
bec5eb61 | 214 | if (super->volume->type == AFSVL_RWVOL || rwpath) |
1da177e4 LT |
215 | strcat(options, ",rwpath"); |
216 | ||
217 | /* try and do the mount */ | |
08e0e7c8 | 218 | _debug("--- attempting mount %s -o %s ---", devname, options); |
1f5ce9e9 | 219 | mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options); |
08e0e7c8 | 220 | _debug("--- mount result %p ---", mnt); |
1da177e4 LT |
221 | |
222 | free_page((unsigned long) devname); | |
223 | free_page((unsigned long) options); | |
08e0e7c8 | 224 | _leave(" = %p", mnt); |
1da177e4 LT |
225 | return mnt; |
226 | ||
ec26815a | 227 | error: |
083fd8b2 DH |
228 | page_cache_release(page); |
229 | error_no_page: | |
230 | free_page((unsigned long) options); | |
231 | error_no_options: | |
232 | free_page((unsigned long) devname); | |
233 | error_no_devname: | |
08e0e7c8 | 234 | _leave(" = %d", ret); |
1da177e4 | 235 | return ERR_PTR(ret); |
ec26815a | 236 | } |
1da177e4 | 237 | |
1da177e4 | 238 | /* |
d18610b0 | 239 | * handle an automount point |
1da177e4 | 240 | */ |
d18610b0 | 241 | struct vfsmount *afs_d_automount(struct path *path) |
1da177e4 LT |
242 | { |
243 | struct vfsmount *newmnt; | |
1da177e4 | 244 | |
d18610b0 | 245 | _enter("{%s,%s}", path->mnt->mnt_devname, path->dentry->d_name.name); |
08e0e7c8 | 246 | |
d18610b0 DH |
247 | newmnt = afs_mntpt_do_automount(path->dentry); |
248 | if (IS_ERR(newmnt)) | |
249 | return newmnt; | |
1da177e4 | 250 | |
ea5b778a DH |
251 | mntget(newmnt); /* prevent immediate expiration */ |
252 | mnt_set_expiry(newmnt, &afs_vfsmounts); | |
253 | queue_delayed_work(afs_wq, &afs_mntpt_expiry_timer, | |
254 | afs_mntpt_expiry_timeout * HZ); | |
255 | _leave(" = %p {%s}", newmnt, newmnt->mnt_devname); | |
256 | return newmnt; | |
ec26815a | 257 | } |
1da177e4 | 258 | |
1da177e4 LT |
259 | /* |
260 | * handle mountpoint expiry timer going off | |
261 | */ | |
08e0e7c8 | 262 | static void afs_mntpt_expiry_timed_out(struct work_struct *work) |
1da177e4 | 263 | { |
08e0e7c8 DH |
264 | _enter(""); |
265 | ||
266 | if (!list_empty(&afs_vfsmounts)) { | |
267 | mark_mounts_for_expiry(&afs_vfsmounts); | |
0ad53eee TH |
268 | queue_delayed_work(afs_wq, &afs_mntpt_expiry_timer, |
269 | afs_mntpt_expiry_timeout * HZ); | |
08e0e7c8 DH |
270 | } |
271 | ||
272 | _leave(""); | |
273 | } | |
1da177e4 | 274 | |
08e0e7c8 DH |
275 | /* |
276 | * kill the AFS mountpoint timer if it's still running | |
277 | */ | |
278 | void afs_mntpt_kill_timer(void) | |
279 | { | |
280 | _enter(""); | |
1da177e4 | 281 | |
08e0e7c8 | 282 | ASSERT(list_empty(&afs_vfsmounts)); |
0ad53eee | 283 | cancel_delayed_work_sync(&afs_mntpt_expiry_timer); |
08e0e7c8 | 284 | } |