AFS: Don't put struct file on the stack
[deliverable/linux.git] / fs / afs / mntpt.c
CommitLineData
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/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
23static struct dentry *afs_mntpt_lookup(struct inode *dir,
24 struct dentry *dentry,
25 struct nameidata *nd);
26static int afs_mntpt_open(struct inode *inode, struct file *file);
008b150a 27static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd);
08e0e7c8 28static void afs_mntpt_expiry_timed_out(struct work_struct *work);
1da177e4 29
4b6f5d20 30const struct file_operations afs_mntpt_file_operations = {
1da177e4
LT
31 .open = afs_mntpt_open,
32};
33
754661f1 34const struct inode_operations afs_mntpt_inode_operations = {
1da177e4
LT
35 .lookup = afs_mntpt_lookup,
36 .follow_link = afs_mntpt_follow_link,
37 .readlink = page_readlink,
416351f2 38 .getattr = afs_getattr,
1da177e4
LT
39};
40
41static LIST_HEAD(afs_vfsmounts);
08e0e7c8 42static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out);
1da177e4 43
c1206a2c 44static unsigned long afs_mntpt_expiry_timeout = 10 * 60;
1da177e4 45
1da177e4
LT
46/*
47 * check a symbolic link to see whether it actually encodes a mountpoint
48 * - sets the AFS_VNODE_MOUNTPOINT flag on the vnode appropriately
49 */
00d3b7a4 50int afs_mntpt_check_symlink(struct afs_vnode *vnode, struct key *key)
1da177e4
LT
51{
52 struct page *page;
1da177e4
LT
53 size_t size;
54 char *buf;
55 int ret;
56
416351f2
DH
57 _enter("{%x:%u,%u}",
58 vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique);
1da177e4
LT
59
60 /* read the contents of the symlink into the pagecache */
f6d335c0
AV
61 page = read_cache_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0,
62 afs_page_filler, key);
1da177e4
LT
63 if (IS_ERR(page)) {
64 ret = PTR_ERR(page);
65 goto out;
66 }
67
68 ret = -EIO;
1da177e4
LT
69 if (PageError(page))
70 goto out_free;
71
6fe6900e
NP
72 buf = kmap(page);
73
1da177e4
LT
74 /* examine the symlink's contents */
75 size = vnode->status.size;
08e0e7c8 76 _debug("symlink to %*.*s", (int) size, (int) size, buf);
1da177e4
LT
77
78 if (size > 2 &&
79 (buf[0] == '%' || buf[0] == '#') &&
80 buf[size - 1] == '.'
81 ) {
82 _debug("symlink is a mountpoint");
83 spin_lock(&vnode->lock);
08e0e7c8 84 set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags);
1da177e4
LT
85 spin_unlock(&vnode->lock);
86 }
87
88 ret = 0;
89
1da177e4 90 kunmap(page);
6fe6900e 91out_free:
1da177e4 92 page_cache_release(page);
ec26815a 93out:
1da177e4
LT
94 _leave(" = %d", ret);
95 return ret;
ec26815a 96}
1da177e4 97
1da177e4
LT
98/*
99 * no valid lookup procedure on this sort of dir
100 */
101static struct dentry *afs_mntpt_lookup(struct inode *dir,
102 struct dentry *dentry,
103 struct nameidata *nd)
104{
08e0e7c8 105 _enter("%p,%p{%p{%s},%s}",
1da177e4
LT
106 dir,
107 dentry,
108 dentry->d_parent,
109 dentry->d_parent ?
110 dentry->d_parent->d_name.name : (const unsigned char *) "",
111 dentry->d_name.name);
112
113 return ERR_PTR(-EREMOTE);
ec26815a 114}
1da177e4 115
1da177e4
LT
116/*
117 * no valid open procedure on this sort of dir
118 */
119static int afs_mntpt_open(struct inode *inode, struct file *file)
120{
08e0e7c8 121 _enter("%p,%p{%p{%s},%s}",
1da177e4 122 inode, file,
1d56a969
JS
123 file->f_path.dentry->d_parent,
124 file->f_path.dentry->d_parent ?
125 file->f_path.dentry->d_parent->d_name.name :
1da177e4 126 (const unsigned char *) "",
1d56a969 127 file->f_path.dentry->d_name.name);
1da177e4
LT
128
129 return -EREMOTE;
ec26815a 130}
1da177e4 131
1da177e4
LT
132/*
133 * create a vfsmount to be automounted
134 */
135static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
136{
137 struct afs_super_info *super;
138 struct vfsmount *mnt;
083fd8b2 139 struct page *page;
1da177e4 140 size_t size;
083fd8b2 141 char *buf, *devname, *options;
1da177e4
LT
142 int ret;
143
08e0e7c8 144 _enter("{%s}", mntpt->d_name.name);
1da177e4
LT
145
146 BUG_ON(!mntpt->d_inode);
147
148 ret = -EINVAL;
149 size = mntpt->d_inode->i_size;
150 if (size > PAGE_SIZE - 1)
083fd8b2 151 goto error_no_devname;
1da177e4
LT
152
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
LT
161
162 /* read the contents of the AFS special symlink */
090d2b18 163 page = read_mapping_page(mntpt->d_inode->i_mapping, 0, NULL);
1da177e4
LT
164 if (IS_ERR(page)) {
165 ret = PTR_ERR(page);
083fd8b2 166 goto error_no_page;
1da177e4
LT
167 }
168
169 ret = -EIO;
6fe6900e 170 if (PageError(page))
1da177e4
LT
171 goto error;
172
9b3f26c9 173 buf = kmap_atomic(page, KM_USER0);
1da177e4 174 memcpy(devname, buf, size);
9b3f26c9 175 kunmap_atomic(buf, KM_USER0);
1da177e4
LT
176 page_cache_release(page);
177 page = NULL;
178
179 /* work out what options we want */
180 super = AFS_FS_S(mntpt->d_sb);
181 memcpy(options, "cell=", 5);
182 strcpy(options + 5, super->volume->cell->name);
183 if (super->volume->type == AFSVL_RWVOL)
184 strcat(options, ",rwpath");
185
186 /* try and do the mount */
08e0e7c8 187 _debug("--- attempting mount %s -o %s ---", devname, options);
1f5ce9e9 188 mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options);
08e0e7c8 189 _debug("--- mount result %p ---", mnt);
1da177e4
LT
190
191 free_page((unsigned long) devname);
192 free_page((unsigned long) options);
08e0e7c8 193 _leave(" = %p", mnt);
1da177e4
LT
194 return mnt;
195
ec26815a 196error:
083fd8b2
DH
197 page_cache_release(page);
198error_no_page:
199 free_page((unsigned long) options);
200error_no_options:
201 free_page((unsigned long) devname);
202error_no_devname:
08e0e7c8 203 _leave(" = %d", ret);
1da177e4 204 return ERR_PTR(ret);
ec26815a 205}
1da177e4 206
1da177e4
LT
207/*
208 * follow a link from a mountpoint directory, thus causing it to be mounted
209 */
008b150a 210static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd)
1da177e4
LT
211{
212 struct vfsmount *newmnt;
1da177e4
LT
213 int err;
214
00d3b7a4 215 _enter("%p{%s},{%s:%p{%s},}",
1da177e4
LT
216 dentry,
217 dentry->d_name.name,
4ac91378 218 nd->path.mnt->mnt_devname,
1da177e4 219 dentry,
4ac91378 220 nd->path.dentry->d_name.name);
1da177e4 221
4ac91378
JB
222 dput(nd->path.dentry);
223 nd->path.dentry = dget(dentry);
08e0e7c8 224
4ac91378 225 newmnt = afs_mntpt_do_automount(nd->path.dentry);
1da177e4 226 if (IS_ERR(newmnt)) {
1d957f9b 227 path_put(&nd->path);
008b150a 228 return (void *)newmnt;
1da177e4
LT
229 }
230
08e0e7c8 231 mntget(newmnt);
8d66bf54 232 err = do_add_mount(newmnt, &nd->path, MNT_SHRINKABLE, &afs_vfsmounts);
08e0e7c8
DH
233 switch (err) {
234 case 0:
09da5916 235 path_put(&nd->path);
4ac91378
JB
236 nd->path.mnt = newmnt;
237 nd->path.dentry = dget(newmnt->mnt_root);
08e0e7c8
DH
238 schedule_delayed_work(&afs_mntpt_expiry_timer,
239 afs_mntpt_expiry_timeout * HZ);
240 break;
241 case -EBUSY:
242 /* someone else made a mount here whilst we were busy */
4ac91378 243 while (d_mountpoint(nd->path.dentry) &&
9393bd07 244 follow_down(&nd->path))
08e0e7c8
DH
245 ;
246 err = 0;
247 default:
248 mntput(newmnt);
249 break;
1da177e4
LT
250 }
251
08e0e7c8 252 _leave(" = %d", err);
008b150a 253 return ERR_PTR(err);
ec26815a 254}
1da177e4 255
1da177e4
LT
256/*
257 * handle mountpoint expiry timer going off
258 */
08e0e7c8 259static void afs_mntpt_expiry_timed_out(struct work_struct *work)
1da177e4 260{
08e0e7c8
DH
261 _enter("");
262
263 if (!list_empty(&afs_vfsmounts)) {
264 mark_mounts_for_expiry(&afs_vfsmounts);
265 schedule_delayed_work(&afs_mntpt_expiry_timer,
266 afs_mntpt_expiry_timeout * HZ);
267 }
268
269 _leave("");
270}
1da177e4 271
08e0e7c8
DH
272/*
273 * kill the AFS mountpoint timer if it's still running
274 */
275void afs_mntpt_kill_timer(void)
276{
277 _enter("");
1da177e4 278
08e0e7c8
DH
279 ASSERT(list_empty(&afs_vfsmounts));
280 cancel_delayed_work(&afs_mntpt_expiry_timer);
281 flush_scheduled_work();
282}
This page took 0.471108 seconds and 5 git commands to generate.