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