1 /* mountpoint management
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
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>
20 #include <linux/fs_context.h>
24 static struct dentry *afs_mntpt_lookup(struct inode *dir,
25 struct dentry *dentry,
27 static int afs_mntpt_open(struct inode *inode, struct file *file);
28 static void afs_mntpt_expiry_timed_out(struct work_struct *work);
30 const struct file_operations afs_mntpt_file_operations = {
31 .open = afs_mntpt_open,
32 .llseek = noop_llseek,
35 const struct inode_operations afs_mntpt_inode_operations = {
36 .lookup = afs_mntpt_lookup,
37 .readlink = page_readlink,
38 .getattr = afs_getattr,
39 .listxattr = afs_listxattr,
42 const struct inode_operations afs_autocell_inode_operations = {
43 .getattr = afs_getattr,
46 static LIST_HEAD(afs_vfsmounts);
47 static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out);
49 static unsigned long afs_mntpt_expiry_timeout = 10 * 60;
51 static const char afs_root_volume[] = "root.cell";
54 * no valid lookup procedure on this sort of dir
56 static struct dentry *afs_mntpt_lookup(struct inode *dir,
57 struct dentry *dentry,
60 _enter("%p,%p{%pd2}", dir, dentry, dentry);
61 return ERR_PTR(-EREMOTE);
65 * no valid open procedure on this sort of dir
67 static int afs_mntpt_open(struct inode *inode, struct file *file)
69 _enter("%p,%p{%pD2}", inode, file, file);
74 * Set the parameters for the proposed superblock.
76 static int afs_mntpt_set_params(struct fs_context *fc, struct dentry *mntpt)
78 struct afs_fs_context *ctx = fc->fs_private;
79 struct afs_super_info *src_as = AFS_FS_S(mntpt->d_sb);
80 struct afs_vnode *vnode = AFS_FS_I(d_inode(mntpt));
81 struct afs_cell *cell;
85 if (fc->net_ns != src_as->net_ns) {
87 fc->net_ns = get_net(src_as->net_ns);
90 if (src_as->volume && src_as->volume->type == AFSVL_RWVOL) {
91 ctx->type = AFSVL_RWVOL;
95 afs_put_cell(ctx->net, ctx->cell);
98 if (test_bit(AFS_VNODE_PSEUDODIR, &vnode->flags)) {
99 /* if the directory is a pseudo directory, use the d_name */
100 unsigned size = mntpt->d_name.len;
105 p = mntpt->d_name.name;
106 if (mntpt->d_name.name[0] == '.') {
109 ctx->type = AFSVL_RWVOL;
112 if (size > AFS_MAXCELLNAME)
113 return -ENAMETOOLONG;
115 cell = afs_lookup_cell(ctx->net, p, size, NULL, false);
117 pr_err("kAFS: unable to lookup cell '%pd'\n", mntpt);
118 return PTR_ERR(cell);
122 ctx->volname = afs_root_volume;
123 ctx->volnamesz = sizeof(afs_root_volume) - 1;
125 /* read the contents of the AFS special symlink */
127 loff_t size = i_size_read(d_inode(mntpt));
131 ctx->cell = afs_get_cell(src_as->cell);
133 if (size > PAGE_SIZE - 1)
136 page = read_mapping_page(d_inode(mntpt)->i_mapping, 0, NULL);
138 return PTR_ERR(page);
140 if (PageError(page)) {
141 ret = afs_bad(AFS_FS_I(d_inode(mntpt)), afs_file_error_mntpt);
147 ret = vfs_parse_fs_string(fc, "source", buf, size);
158 * create a vfsmount to be automounted
160 static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
162 struct fs_context *fc;
163 struct vfsmount *mnt;
166 BUG_ON(!d_inode(mntpt));
168 fc = fs_context_for_submount(&afs_fs_type, mntpt);
172 ret = afs_mntpt_set_params(fc, mntpt);
183 * handle an automount point
185 struct vfsmount *afs_d_automount(struct path *path)
187 struct vfsmount *newmnt;
189 _enter("{%pd}", path->dentry);
191 newmnt = afs_mntpt_do_automount(path->dentry);
195 mntget(newmnt); /* prevent immediate expiration */
196 mnt_set_expiry(newmnt, &afs_vfsmounts);
197 queue_delayed_work(afs_wq, &afs_mntpt_expiry_timer,
198 afs_mntpt_expiry_timeout * HZ);
199 _leave(" = %p", newmnt);
204 * handle mountpoint expiry timer going off
206 static void afs_mntpt_expiry_timed_out(struct work_struct *work)
210 if (!list_empty(&afs_vfsmounts)) {
211 mark_mounts_for_expiry(&afs_vfsmounts);
212 queue_delayed_work(afs_wq, &afs_mntpt_expiry_timer,
213 afs_mntpt_expiry_timeout * HZ);
220 * kill the AFS mountpoint timer if it's still running
222 void afs_mntpt_kill_timer(void)
226 ASSERT(list_empty(&afs_vfsmounts));
227 cancel_delayed_work_sync(&afs_mntpt_expiry_timer);