Blame view
fs/afs/mntpt.c
6.72 KB
ec26815ad [AFS]: Clean up t... |
1 |
/* mountpoint management |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 5 6 7 8 9 10 11 12 13 14 |
* * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> |
1da177e4c Linux-2.6.12-rc2 |
15 16 17 18 19 |
#include <linux/slab.h> #include <linux/fs.h> #include <linux/pagemap.h> #include <linux/mount.h> #include <linux/namei.h> |
6b3286ed1 [PATCH] rename st... |
20 |
#include <linux/mnt_namespace.h> |
1da177e4c Linux-2.6.12-rc2 |
21 22 23 24 25 26 27 |
#include "internal.h" static struct dentry *afs_mntpt_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd); static int afs_mntpt_open(struct inode *inode, struct file *file); |
008b150a3 [PATCH] Fix up sy... |
28 |
static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd); |
08e0e7c82 [AF_RXRPC]: Make ... |
29 |
static void afs_mntpt_expiry_timed_out(struct work_struct *work); |
1da177e4c Linux-2.6.12-rc2 |
30 |
|
4b6f5d20b [PATCH] Make most... |
31 |
const struct file_operations afs_mntpt_file_operations = { |
1da177e4c Linux-2.6.12-rc2 |
32 33 |
.open = afs_mntpt_open, }; |
754661f14 [PATCH] mark stru... |
34 |
const struct inode_operations afs_mntpt_inode_operations = { |
1da177e4c Linux-2.6.12-rc2 |
35 36 37 |
.lookup = afs_mntpt_lookup, .follow_link = afs_mntpt_follow_link, .readlink = page_readlink, |
416351f28 AFS: AFS fixups |
38 |
.getattr = afs_getattr, |
1da177e4c Linux-2.6.12-rc2 |
39 40 41 |
}; static LIST_HEAD(afs_vfsmounts); |
08e0e7c82 [AF_RXRPC]: Make ... |
42 |
static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out); |
1da177e4c Linux-2.6.12-rc2 |
43 |
|
08e0e7c82 [AF_RXRPC]: Make ... |
44 |
unsigned long afs_mntpt_expiry_timeout = 10 * 60; |
1da177e4c Linux-2.6.12-rc2 |
45 |
|
1da177e4c Linux-2.6.12-rc2 |
46 47 48 49 |
/* * check a symbolic link to see whether it actually encodes a mountpoint * - sets the AFS_VNODE_MOUNTPOINT flag on the vnode appropriately */ |
00d3b7a45 [AFS]: Add securi... |
50 |
int afs_mntpt_check_symlink(struct afs_vnode *vnode, struct key *key) |
1da177e4c Linux-2.6.12-rc2 |
51 |
{ |
00d3b7a45 [AFS]: Add securi... |
52 53 54 |
struct file file = { .private_data = key, }; |
1da177e4c Linux-2.6.12-rc2 |
55 |
struct page *page; |
1da177e4c Linux-2.6.12-rc2 |
56 57 58 |
size_t size; char *buf; int ret; |
416351f28 AFS: AFS fixups |
59 60 |
_enter("{%x:%u,%u}", vnode->fid.vid, vnode->fid.vnode, vnode->fid.unique); |
1da177e4c Linux-2.6.12-rc2 |
61 62 |
/* read the contents of the symlink into the pagecache */ |
00d3b7a45 [AFS]: Add securi... |
63 |
page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, &file); |
1da177e4c Linux-2.6.12-rc2 |
64 65 66 67 68 69 |
if (IS_ERR(page)) { ret = PTR_ERR(page); goto out; } ret = -EIO; |
1da177e4c Linux-2.6.12-rc2 |
70 71 |
if (PageError(page)) goto out_free; |
6fe6900e1 mm: make read_cac... |
72 |
buf = kmap(page); |
1da177e4c Linux-2.6.12-rc2 |
73 74 |
/* examine the symlink's contents */ size = vnode->status.size; |
08e0e7c82 [AF_RXRPC]: Make ... |
75 |
_debug("symlink to %*.*s", (int) size, (int) size, buf); |
1da177e4c Linux-2.6.12-rc2 |
76 77 78 79 80 81 82 |
if (size > 2 && (buf[0] == '%' || buf[0] == '#') && buf[size - 1] == '.' ) { _debug("symlink is a mountpoint"); spin_lock(&vnode->lock); |
08e0e7c82 [AF_RXRPC]: Make ... |
83 |
set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags); |
1da177e4c Linux-2.6.12-rc2 |
84 85 86 87 |
spin_unlock(&vnode->lock); } ret = 0; |
1da177e4c Linux-2.6.12-rc2 |
88 |
kunmap(page); |
6fe6900e1 mm: make read_cac... |
89 |
out_free: |
1da177e4c Linux-2.6.12-rc2 |
90 |
page_cache_release(page); |
ec26815ad [AFS]: Clean up t... |
91 |
out: |
1da177e4c Linux-2.6.12-rc2 |
92 93 |
_leave(" = %d", ret); return ret; |
ec26815ad [AFS]: Clean up t... |
94 |
} |
1da177e4c Linux-2.6.12-rc2 |
95 |
|
1da177e4c Linux-2.6.12-rc2 |
96 97 98 99 100 101 102 |
/* * no valid lookup procedure on this sort of dir */ static struct dentry *afs_mntpt_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) { |
08e0e7c82 [AF_RXRPC]: Make ... |
103 |
_enter("%p,%p{%p{%s},%s}", |
1da177e4c Linux-2.6.12-rc2 |
104 105 106 107 108 109 110 111 |
dir, dentry, dentry->d_parent, dentry->d_parent ? dentry->d_parent->d_name.name : (const unsigned char *) "", dentry->d_name.name); return ERR_PTR(-EREMOTE); |
ec26815ad [AFS]: Clean up t... |
112 |
} |
1da177e4c Linux-2.6.12-rc2 |
113 |
|
1da177e4c Linux-2.6.12-rc2 |
114 115 116 117 118 |
/* * no valid open procedure on this sort of dir */ static int afs_mntpt_open(struct inode *inode, struct file *file) { |
08e0e7c82 [AF_RXRPC]: Make ... |
119 |
_enter("%p,%p{%p{%s},%s}", |
1da177e4c Linux-2.6.12-rc2 |
120 |
inode, file, |
1d56a9695 [PATCH] struct pa... |
121 122 123 |
file->f_path.dentry->d_parent, file->f_path.dentry->d_parent ? file->f_path.dentry->d_parent->d_name.name : |
1da177e4c Linux-2.6.12-rc2 |
124 |
(const unsigned char *) "", |
1d56a9695 [PATCH] struct pa... |
125 |
file->f_path.dentry->d_name.name); |
1da177e4c Linux-2.6.12-rc2 |
126 127 |
return -EREMOTE; |
ec26815ad [AFS]: Clean up t... |
128 |
} |
1da177e4c Linux-2.6.12-rc2 |
129 |
|
1da177e4c Linux-2.6.12-rc2 |
130 131 132 133 134 135 136 137 138 139 |
/* * create a vfsmount to be automounted */ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt) { struct afs_super_info *super; struct vfsmount *mnt; struct page *page = NULL; size_t size; char *buf, *devname = NULL, *options = NULL; |
1da177e4c Linux-2.6.12-rc2 |
140 |
int ret; |
08e0e7c82 [AF_RXRPC]: Make ... |
141 |
_enter("{%s}", mntpt->d_name.name); |
1da177e4c Linux-2.6.12-rc2 |
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
BUG_ON(!mntpt->d_inode); ret = -EINVAL; size = mntpt->d_inode->i_size; if (size > PAGE_SIZE - 1) goto error; ret = -ENOMEM; devname = (char *) get_zeroed_page(GFP_KERNEL); if (!devname) goto error; options = (char *) get_zeroed_page(GFP_KERNEL); if (!options) goto error; /* read the contents of the AFS special symlink */ |
090d2b185 [PATCH] read_mapp... |
160 |
page = read_mapping_page(mntpt->d_inode->i_mapping, 0, NULL); |
1da177e4c Linux-2.6.12-rc2 |
161 162 163 164 165 166 |
if (IS_ERR(page)) { ret = PTR_ERR(page); goto error; } ret = -EIO; |
6fe6900e1 mm: make read_cac... |
167 |
if (PageError(page)) |
1da177e4c Linux-2.6.12-rc2 |
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
goto error; buf = kmap(page); memcpy(devname, buf, size); kunmap(page); page_cache_release(page); page = NULL; /* work out what options we want */ super = AFS_FS_S(mntpt->d_sb); memcpy(options, "cell=", 5); strcpy(options + 5, super->volume->cell->name); if (super->volume->type == AFSVL_RWVOL) strcat(options, ",rwpath"); /* try and do the mount */ |
08e0e7c82 [AF_RXRPC]: Make ... |
184 |
_debug("--- attempting mount %s -o %s ---", devname, options); |
1f5ce9e93 VFS: Unexport do_... |
185 |
mnt = vfs_kern_mount(&afs_fs_type, 0, devname, options); |
08e0e7c82 [AF_RXRPC]: Make ... |
186 |
_debug("--- mount result %p ---", mnt); |
1da177e4c Linux-2.6.12-rc2 |
187 188 189 |
free_page((unsigned long) devname); free_page((unsigned long) options); |
08e0e7c82 [AF_RXRPC]: Make ... |
190 |
_leave(" = %p", mnt); |
1da177e4c Linux-2.6.12-rc2 |
191 |
return mnt; |
ec26815ad [AFS]: Clean up t... |
192 |
error: |
1da177e4c Linux-2.6.12-rc2 |
193 194 195 196 197 198 |
if (page) page_cache_release(page); if (devname) free_page((unsigned long) devname); if (options) free_page((unsigned long) options); |
08e0e7c82 [AF_RXRPC]: Make ... |
199 |
_leave(" = %d", ret); |
1da177e4c Linux-2.6.12-rc2 |
200 |
return ERR_PTR(ret); |
ec26815ad [AFS]: Clean up t... |
201 |
} |
1da177e4c Linux-2.6.12-rc2 |
202 |
|
1da177e4c Linux-2.6.12-rc2 |
203 204 205 |
/* * follow a link from a mountpoint directory, thus causing it to be mounted */ |
008b150a3 [PATCH] Fix up sy... |
206 |
static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd) |
1da177e4c Linux-2.6.12-rc2 |
207 208 |
{ struct vfsmount *newmnt; |
1da177e4c Linux-2.6.12-rc2 |
209 |
int err; |
00d3b7a45 [AFS]: Add securi... |
210 |
_enter("%p{%s},{%s:%p{%s},}", |
1da177e4c Linux-2.6.12-rc2 |
211 212 213 214 215 |
dentry, dentry->d_name.name, nd->mnt->mnt_devname, dentry, nd->dentry->d_name.name); |
08e0e7c82 [AF_RXRPC]: Make ... |
216 217 218 219 |
dput(nd->dentry); nd->dentry = dget(dentry); newmnt = afs_mntpt_do_automount(nd->dentry); |
1da177e4c Linux-2.6.12-rc2 |
220 221 |
if (IS_ERR(newmnt)) { path_release(nd); |
008b150a3 [PATCH] Fix up sy... |
222 |
return (void *)newmnt; |
1da177e4c Linux-2.6.12-rc2 |
223 |
} |
08e0e7c82 [AF_RXRPC]: Make ... |
224 225 226 227 |
mntget(newmnt); err = do_add_mount(newmnt, nd, MNT_SHRINKABLE, &afs_vfsmounts); switch (err) { case 0: |
00d3b7a45 [AFS]: Add securi... |
228 229 |
mntput(nd->mnt); dput(nd->dentry); |
1da177e4c Linux-2.6.12-rc2 |
230 |
nd->mnt = newmnt; |
08e0e7c82 [AF_RXRPC]: Make ... |
231 232 233 234 235 236 237 238 239 240 241 242 243 |
nd->dentry = dget(newmnt->mnt_root); schedule_delayed_work(&afs_mntpt_expiry_timer, afs_mntpt_expiry_timeout * HZ); break; case -EBUSY: /* someone else made a mount here whilst we were busy */ while (d_mountpoint(nd->dentry) && follow_down(&nd->mnt, &nd->dentry)) ; err = 0; default: mntput(newmnt); break; |
1da177e4c Linux-2.6.12-rc2 |
244 |
} |
08e0e7c82 [AF_RXRPC]: Make ... |
245 |
_leave(" = %d", err); |
008b150a3 [PATCH] Fix up sy... |
246 |
return ERR_PTR(err); |
ec26815ad [AFS]: Clean up t... |
247 |
} |
1da177e4c Linux-2.6.12-rc2 |
248 |
|
1da177e4c Linux-2.6.12-rc2 |
249 250 251 |
/* * handle mountpoint expiry timer going off */ |
08e0e7c82 [AF_RXRPC]: Make ... |
252 |
static void afs_mntpt_expiry_timed_out(struct work_struct *work) |
1da177e4c Linux-2.6.12-rc2 |
253 |
{ |
08e0e7c82 [AF_RXRPC]: Make ... |
254 255 256 257 258 259 260 261 262 263 |
_enter(""); if (!list_empty(&afs_vfsmounts)) { mark_mounts_for_expiry(&afs_vfsmounts); schedule_delayed_work(&afs_mntpt_expiry_timer, afs_mntpt_expiry_timeout * HZ); } _leave(""); } |
1da177e4c Linux-2.6.12-rc2 |
264 |
|
08e0e7c82 [AF_RXRPC]: Make ... |
265 266 267 268 269 270 |
/* * kill the AFS mountpoint timer if it's still running */ void afs_mntpt_kill_timer(void) { _enter(""); |
1da177e4c Linux-2.6.12-rc2 |
271 |
|
08e0e7c82 [AF_RXRPC]: Make ... |
272 273 274 275 |
ASSERT(list_empty(&afs_vfsmounts)); cancel_delayed_work(&afs_mntpt_expiry_timer); flush_scheduled_work(); } |
1da177e4c Linux-2.6.12-rc2 |
276 |
|
08e0e7c82 [AF_RXRPC]: Make ... |
277 278 279 280 281 282 |
/* * begin unmount by attempting to remove all automounted mountpoints we added */ void afs_umount_begin(struct vfsmount *vfsmnt, int flags) { shrink_submounts(vfsmnt, &afs_vfsmounts); |
ec26815ad [AFS]: Clean up t... |
283 |
} |