1 /* mountpoint management
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
16 #include <linux/pagemap.h>
17 #include <linux/mount.h>
18 #include <linux/namei.h>
19 #include <linux/gfp.h>
23 static struct dentry
*afs_mntpt_lookup(struct inode
*dir
,
24 struct dentry
*dentry
,
26 static int afs_mntpt_open(struct inode
*inode
, struct file
*file
);
27 static void afs_mntpt_expiry_timed_out(struct work_struct
*work
);
29 const struct file_operations afs_mntpt_file_operations
= {
30 .open
= afs_mntpt_open
,
31 .llseek
= noop_llseek
,
34 const struct inode_operations afs_mntpt_inode_operations
= {
35 .lookup
= afs_mntpt_lookup
,
36 .readlink
= page_readlink
,
37 .getattr
= afs_getattr
,
40 const struct inode_operations afs_autocell_inode_operations
= {
41 .getattr
= afs_getattr
,
44 static LIST_HEAD(afs_vfsmounts
);
45 static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer
, afs_mntpt_expiry_timed_out
);
47 static unsigned long afs_mntpt_expiry_timeout
= 10 * 60;
50 * no valid lookup procedure on this sort of dir
52 static struct dentry
*afs_mntpt_lookup(struct inode
*dir
,
53 struct dentry
*dentry
,
56 _enter("%p,%p{%pd2}", dir
, dentry
, dentry
);
57 return ERR_PTR(-EREMOTE
);
61 * no valid open procedure on this sort of dir
63 static int afs_mntpt_open(struct inode
*inode
, struct file
*file
)
65 _enter("%p,%p{%pD2}", inode
, file
, file
);
70 * create a vfsmount to be automounted
72 static struct vfsmount
*afs_mntpt_do_automount(struct dentry
*mntpt
)
74 struct afs_super_info
*super
;
76 struct afs_vnode
*vnode
;
78 char *devname
, *options
;
82 _enter("{%pd}", mntpt
);
84 BUG_ON(!d_inode(mntpt
));
87 devname
= (char *) get_zeroed_page(GFP_KERNEL
);
89 goto error_no_devname
;
91 options
= (char *) get_zeroed_page(GFP_KERNEL
);
93 goto error_no_options
;
95 vnode
= AFS_FS_I(d_inode(mntpt
));
96 if (test_bit(AFS_VNODE_PSEUDODIR
, &vnode
->flags
)) {
97 /* if the directory is a pseudo directory, use the d_name */
98 static const char afs_root_cell
[] = ":root.cell.";
99 unsigned size
= mntpt
->d_name
.len
;
102 if (size
< 2 || size
> AFS_MAXCELLNAME
)
105 if (mntpt
->d_name
.name
[0] == '.') {
107 memcpy(devname
+ 1, mntpt
->d_name
.name
, size
- 1);
108 memcpy(devname
+ size
, afs_root_cell
,
109 sizeof(afs_root_cell
));
113 memcpy(devname
+ 1, mntpt
->d_name
.name
, size
);
114 memcpy(devname
+ size
+ 1, afs_root_cell
,
115 sizeof(afs_root_cell
));
118 /* read the contents of the AFS special symlink */
119 loff_t size
= i_size_read(d_inode(mntpt
));
123 if (size
> PAGE_SIZE
- 1)
126 page
= read_mapping_page(d_inode(mntpt
)->i_mapping
, 0, NULL
);
136 buf
= kmap_atomic(page
);
137 memcpy(devname
, buf
, size
);
143 /* work out what options we want */
144 super
= AFS_FS_S(mntpt
->d_sb
);
145 memcpy(options
, "cell=", 5);
146 strcpy(options
+ 5, super
->volume
->cell
->name
);
147 if (super
->volume
->type
== AFSVL_RWVOL
|| rwpath
)
148 strcat(options
, ",rwpath");
150 /* try and do the mount */
151 _debug("--- attempting mount %s -o %s ---", devname
, options
);
152 mnt
= vfs_submount(mntpt
, &afs_fs_type
, devname
, options
);
153 _debug("--- mount result %p ---", mnt
);
155 free_page((unsigned long) devname
);
156 free_page((unsigned long) options
);
157 _leave(" = %p", mnt
);
163 free_page((unsigned long) options
);
165 free_page((unsigned long) devname
);
167 _leave(" = %d", ret
);
172 * handle an automount point
174 struct vfsmount
*afs_d_automount(struct path
*path
)
176 struct vfsmount
*newmnt
;
178 _enter("{%pd}", path
->dentry
);
180 newmnt
= afs_mntpt_do_automount(path
->dentry
);
184 mntget(newmnt
); /* prevent immediate expiration */
185 mnt_set_expiry(newmnt
, &afs_vfsmounts
);
186 queue_delayed_work(afs_wq
, &afs_mntpt_expiry_timer
,
187 afs_mntpt_expiry_timeout
* HZ
);
188 _leave(" = %p", newmnt
);
193 * handle mountpoint expiry timer going off
195 static void afs_mntpt_expiry_timed_out(struct work_struct
*work
)
199 if (!list_empty(&afs_vfsmounts
)) {
200 mark_mounts_for_expiry(&afs_vfsmounts
);
201 queue_delayed_work(afs_wq
, &afs_mntpt_expiry_timer
,
202 afs_mntpt_expiry_timeout
* HZ
);
209 * kill the AFS mountpoint timer if it's still running
211 void afs_mntpt_kill_timer(void)
215 ASSERT(list_empty(&afs_vfsmounts
));
216 cancel_delayed_work_sync(&afs_mntpt_expiry_timer
);