]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/afs/mntpt.c
Merge remote-tracking branches 'asoc/topic/sta529', 'asoc/topic/sti', 'asoc/topic...
[mirror_ubuntu-bionic-kernel.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,
00cd8dd3 25 unsigned int flags);
1da177e4 26static int afs_mntpt_open(struct inode *inode, struct file *file);
08e0e7c8 27static void afs_mntpt_expiry_timed_out(struct work_struct *work);
1da177e4 28
4b6f5d20 29const struct file_operations afs_mntpt_file_operations = {
1da177e4 30 .open = afs_mntpt_open,
6038f373 31 .llseek = noop_llseek,
1da177e4
LT
32};
33
754661f1 34const 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 40const struct inode_operations afs_autocell_inode_operations = {
bec5eb61 41 .getattr = afs_getattr,
42};
43
1da177e4 44static LIST_HEAD(afs_vfsmounts);
08e0e7c8 45static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out);
1da177e4 46
c1206a2c 47static unsigned long afs_mntpt_expiry_timeout = 10 * 60;
1da177e4 48
1da177e4
LT
49/*
50 * no valid lookup procedure on this sort of dir
51 */
52static struct dentry *afs_mntpt_lookup(struct inode *dir,
53 struct dentry *dentry,
00cd8dd3 54 unsigned int flags)
1da177e4 55{
a455589f 56 _enter("%p,%p{%pd2}", dir, dentry, dentry);
1da177e4 57 return ERR_PTR(-EREMOTE);
ec26815a 58}
1da177e4 59
1da177e4
LT
60/*
61 * no valid open procedure on this sort of dir
62 */
63static int afs_mntpt_open(struct inode *inode, struct file *file)
64{
a455589f 65 _enter("%p,%p{%pD2}", inode, file, file);
1da177e4 66 return -EREMOTE;
ec26815a 67}
1da177e4 68
1da177e4
LT
69/*
70 * create a vfsmount to be automounted
71 */
72static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
73{
74 struct afs_super_info *super;
75 struct vfsmount *mnt;
bec5eb61 76 struct afs_vnode *vnode;
083fd8b2 77 struct page *page;
bec5eb61 78 char *devname, *options;
79 bool rwpath = false;
1da177e4
LT
80 int ret;
81
a455589f 82 _enter("{%pd}", mntpt);
1da177e4 83
2b0143b5 84 BUG_ON(!d_inode(mntpt));
1da177e4 85
1da177e4
LT
86 ret = -ENOMEM;
87 devname = (char *) get_zeroed_page(GFP_KERNEL);
88 if (!devname)
083fd8b2 89 goto error_no_devname;
1da177e4
LT
90
91 options = (char *) get_zeroed_page(GFP_KERNEL);
92 if (!options)
083fd8b2 93 goto error_no_options;
1da177e4 94
2b0143b5 95 vnode = AFS_FS_I(d_inode(mntpt));
bec5eb61 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;
100
101 ret = -ENOENT;
102 if (size < 2 || size > AFS_MAXCELLNAME)
103 goto error_no_page;
104
105 if (mntpt->d_name.name[0] == '.') {
106 devname[0] = '#';
107 memcpy(devname + 1, mntpt->d_name.name, size - 1);
108 memcpy(devname + size, afs_root_cell,
109 sizeof(afs_root_cell));
110 rwpath = true;
111 } else {
112 devname[0] = '%';
113 memcpy(devname + 1, mntpt->d_name.name, size);
114 memcpy(devname + size + 1, afs_root_cell,
115 sizeof(afs_root_cell));
116 }
117 } else {
118 /* read the contents of the AFS special symlink */
2b0143b5 119 loff_t size = i_size_read(d_inode(mntpt));
bec5eb61 120 char *buf;
121
122 ret = -EINVAL;
123 if (size > PAGE_SIZE - 1)
124 goto error_no_page;
125
2b0143b5 126 page = read_mapping_page(d_inode(mntpt)->i_mapping, 0, NULL);
bec5eb61 127 if (IS_ERR(page)) {
128 ret = PTR_ERR(page);
129 goto error_no_page;
130 }
131
132 ret = -EIO;
133 if (PageError(page))
134 goto error;
135
da4aa36d 136 buf = kmap_atomic(page);
bec5eb61 137 memcpy(devname, buf, size);
da4aa36d 138 kunmap_atomic(buf);
09cbfeaf 139 put_page(page);
bec5eb61 140 page = NULL;
1da177e4
LT
141 }
142
1da177e4
LT
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);
bec5eb61 147 if (super->volume->type == AFSVL_RWVOL || rwpath)
1da177e4
LT
148 strcat(options, ",rwpath");
149
150 /* try and do the mount */
08e0e7c8 151 _debug("--- attempting mount %s -o %s ---", devname, options);
93faccbb 152 mnt = vfs_submount(mntpt, &afs_fs_type, devname, options);
08e0e7c8 153 _debug("--- mount result %p ---", mnt);
1da177e4
LT
154
155 free_page((unsigned long) devname);
156 free_page((unsigned long) options);
08e0e7c8 157 _leave(" = %p", mnt);
1da177e4
LT
158 return mnt;
159
ec26815a 160error:
09cbfeaf 161 put_page(page);
083fd8b2
DH
162error_no_page:
163 free_page((unsigned long) options);
164error_no_options:
165 free_page((unsigned long) devname);
166error_no_devname:
08e0e7c8 167 _leave(" = %d", ret);
1da177e4 168 return ERR_PTR(ret);
ec26815a 169}
1da177e4 170
1da177e4 171/*
d18610b0 172 * handle an automount point
1da177e4 173 */
d18610b0 174struct vfsmount *afs_d_automount(struct path *path)
1da177e4
LT
175{
176 struct vfsmount *newmnt;
1da177e4 177
a455589f 178 _enter("{%pd}", path->dentry);
08e0e7c8 179
d18610b0
DH
180 newmnt = afs_mntpt_do_automount(path->dentry);
181 if (IS_ERR(newmnt))
182 return newmnt;
1da177e4 183
ea5b778a
DH
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);
5ffc2836 188 _leave(" = %p", newmnt);
ea5b778a 189 return newmnt;
ec26815a 190}
1da177e4 191
1da177e4
LT
192/*
193 * handle mountpoint expiry timer going off
194 */
08e0e7c8 195static void afs_mntpt_expiry_timed_out(struct work_struct *work)
1da177e4 196{
08e0e7c8
DH
197 _enter("");
198
199 if (!list_empty(&afs_vfsmounts)) {
200 mark_mounts_for_expiry(&afs_vfsmounts);
0ad53eee
TH
201 queue_delayed_work(afs_wq, &afs_mntpt_expiry_timer,
202 afs_mntpt_expiry_timeout * HZ);
08e0e7c8
DH
203 }
204
205 _leave("");
206}
1da177e4 207
08e0e7c8
DH
208/*
209 * kill the AFS mountpoint timer if it's still running
210 */
211void afs_mntpt_kill_timer(void)
212{
213 _enter("");
1da177e4 214
08e0e7c8 215 ASSERT(list_empty(&afs_vfsmounts));
0ad53eee 216 cancel_delayed_work_sync(&afs_mntpt_expiry_timer);
08e0e7c8 217}