]>
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, | |
00cd8dd3 | 25 | unsigned int flags); |
1da177e4 | 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: |
09cbfeaf | 96 | put_page(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, | |
00cd8dd3 | 107 | unsigned int flags) |
1da177e4 | 108 | { |
a455589f | 109 | _enter("%p,%p{%pd2}", dir, dentry, dentry); |
1da177e4 | 110 | return ERR_PTR(-EREMOTE); |
ec26815a | 111 | } |
1da177e4 | 112 | |
1da177e4 LT |
113 | /* |
114 | * no valid open procedure on this sort of dir | |
115 | */ | |
116 | static int afs_mntpt_open(struct inode *inode, struct file *file) | |
117 | { | |
a455589f | 118 | _enter("%p,%p{%pD2}", inode, file, file); |
1da177e4 | 119 | return -EREMOTE; |
ec26815a | 120 | } |
1da177e4 | 121 | |
1da177e4 LT |
122 | /* |
123 | * create a vfsmount to be automounted | |
124 | */ | |
125 | static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt) | |
126 | { | |
127 | struct afs_super_info *super; | |
128 | struct vfsmount *mnt; | |
bec5eb61 | 129 | struct afs_vnode *vnode; |
083fd8b2 | 130 | struct page *page; |
bec5eb61 | 131 | char *devname, *options; |
132 | bool rwpath = false; | |
1da177e4 LT |
133 | int ret; |
134 | ||
a455589f | 135 | _enter("{%pd}", mntpt); |
1da177e4 | 136 | |
2b0143b5 | 137 | BUG_ON(!d_inode(mntpt)); |
1da177e4 | 138 | |
1da177e4 LT |
139 | ret = -ENOMEM; |
140 | devname = (char *) get_zeroed_page(GFP_KERNEL); | |
141 | if (!devname) | |
083fd8b2 | 142 | goto error_no_devname; |
1da177e4 LT |
143 | |
144 | options = (char *) get_zeroed_page(GFP_KERNEL); | |
145 | if (!options) | |
083fd8b2 | 146 | goto error_no_options; |
1da177e4 | 147 | |
2b0143b5 | 148 | vnode = AFS_FS_I(d_inode(mntpt)); |
bec5eb61 | 149 | if (test_bit(AFS_VNODE_PSEUDODIR, &vnode->flags)) { |
150 | /* if the directory is a pseudo directory, use the d_name */ | |
151 | static const char afs_root_cell[] = ":root.cell."; | |
152 | unsigned size = mntpt->d_name.len; | |
153 | ||
154 | ret = -ENOENT; | |
155 | if (size < 2 || size > AFS_MAXCELLNAME) | |
156 | goto error_no_page; | |
157 | ||
158 | if (mntpt->d_name.name[0] == '.') { | |
159 | devname[0] = '#'; | |
160 | memcpy(devname + 1, mntpt->d_name.name, size - 1); | |
161 | memcpy(devname + size, afs_root_cell, | |
162 | sizeof(afs_root_cell)); | |
163 | rwpath = true; | |
164 | } else { | |
165 | devname[0] = '%'; | |
166 | memcpy(devname + 1, mntpt->d_name.name, size); | |
167 | memcpy(devname + size + 1, afs_root_cell, | |
168 | sizeof(afs_root_cell)); | |
169 | } | |
170 | } else { | |
171 | /* read the contents of the AFS special symlink */ | |
2b0143b5 | 172 | loff_t size = i_size_read(d_inode(mntpt)); |
bec5eb61 | 173 | char *buf; |
174 | ||
175 | ret = -EINVAL; | |
176 | if (size > PAGE_SIZE - 1) | |
177 | goto error_no_page; | |
178 | ||
2b0143b5 | 179 | page = read_mapping_page(d_inode(mntpt)->i_mapping, 0, NULL); |
bec5eb61 | 180 | if (IS_ERR(page)) { |
181 | ret = PTR_ERR(page); | |
182 | goto error_no_page; | |
183 | } | |
184 | ||
185 | ret = -EIO; | |
186 | if (PageError(page)) | |
187 | goto error; | |
188 | ||
da4aa36d | 189 | buf = kmap_atomic(page); |
bec5eb61 | 190 | memcpy(devname, buf, size); |
da4aa36d | 191 | kunmap_atomic(buf); |
09cbfeaf | 192 | put_page(page); |
bec5eb61 | 193 | page = NULL; |
1da177e4 LT |
194 | } |
195 | ||
1da177e4 LT |
196 | /* work out what options we want */ |
197 | super = AFS_FS_S(mntpt->d_sb); | |
198 | memcpy(options, "cell=", 5); | |
199 | strcpy(options + 5, super->volume->cell->name); | |
bec5eb61 | 200 | if (super->volume->type == AFSVL_RWVOL || rwpath) |
1da177e4 LT |
201 | strcat(options, ",rwpath"); |
202 | ||
203 | /* try and do the mount */ | |
08e0e7c8 | 204 | _debug("--- attempting mount %s -o %s ---", devname, options); |
1f5ce9e9 | 205 | mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options); |
08e0e7c8 | 206 | _debug("--- mount result %p ---", mnt); |
1da177e4 LT |
207 | |
208 | free_page((unsigned long) devname); | |
209 | free_page((unsigned long) options); | |
08e0e7c8 | 210 | _leave(" = %p", mnt); |
1da177e4 LT |
211 | return mnt; |
212 | ||
ec26815a | 213 | error: |
09cbfeaf | 214 | put_page(page); |
083fd8b2 DH |
215 | error_no_page: |
216 | free_page((unsigned long) options); | |
217 | error_no_options: | |
218 | free_page((unsigned long) devname); | |
219 | error_no_devname: | |
08e0e7c8 | 220 | _leave(" = %d", ret); |
1da177e4 | 221 | return ERR_PTR(ret); |
ec26815a | 222 | } |
1da177e4 | 223 | |
1da177e4 | 224 | /* |
d18610b0 | 225 | * handle an automount point |
1da177e4 | 226 | */ |
d18610b0 | 227 | struct vfsmount *afs_d_automount(struct path *path) |
1da177e4 LT |
228 | { |
229 | struct vfsmount *newmnt; | |
1da177e4 | 230 | |
a455589f | 231 | _enter("{%pd}", path->dentry); |
08e0e7c8 | 232 | |
d18610b0 DH |
233 | newmnt = afs_mntpt_do_automount(path->dentry); |
234 | if (IS_ERR(newmnt)) | |
235 | return newmnt; | |
1da177e4 | 236 | |
ea5b778a DH |
237 | mntget(newmnt); /* prevent immediate expiration */ |
238 | mnt_set_expiry(newmnt, &afs_vfsmounts); | |
239 | queue_delayed_work(afs_wq, &afs_mntpt_expiry_timer, | |
240 | afs_mntpt_expiry_timeout * HZ); | |
5ffc2836 | 241 | _leave(" = %p", newmnt); |
ea5b778a | 242 | return newmnt; |
ec26815a | 243 | } |
1da177e4 | 244 | |
1da177e4 LT |
245 | /* |
246 | * handle mountpoint expiry timer going off | |
247 | */ | |
08e0e7c8 | 248 | static void afs_mntpt_expiry_timed_out(struct work_struct *work) |
1da177e4 | 249 | { |
08e0e7c8 DH |
250 | _enter(""); |
251 | ||
252 | if (!list_empty(&afs_vfsmounts)) { | |
253 | mark_mounts_for_expiry(&afs_vfsmounts); | |
0ad53eee TH |
254 | queue_delayed_work(afs_wq, &afs_mntpt_expiry_timer, |
255 | afs_mntpt_expiry_timeout * HZ); | |
08e0e7c8 DH |
256 | } |
257 | ||
258 | _leave(""); | |
259 | } | |
1da177e4 | 260 | |
08e0e7c8 DH |
261 | /* |
262 | * kill the AFS mountpoint timer if it's still running | |
263 | */ | |
264 | void afs_mntpt_kill_timer(void) | |
265 | { | |
266 | _enter(""); | |
1da177e4 | 267 | |
08e0e7c8 | 268 | ASSERT(list_empty(&afs_vfsmounts)); |
0ad53eee | 269 | cancel_delayed_work_sync(&afs_mntpt_expiry_timer); |
08e0e7c8 | 270 | } |