]>
Commit | Line | Data |
---|---|---|
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> |
13fcc683 | 20 | #include <linux/fs_context.h> |
1da177e4 LT |
21 | #include "internal.h" |
22 | ||
23 | ||
24 | static struct dentry *afs_mntpt_lookup(struct inode *dir, | |
25 | struct dentry *dentry, | |
00cd8dd3 | 26 | unsigned int flags); |
1da177e4 | 27 | static int afs_mntpt_open(struct inode *inode, struct file *file); |
08e0e7c8 | 28 | static void afs_mntpt_expiry_timed_out(struct work_struct *work); |
1da177e4 | 29 | |
4b6f5d20 | 30 | const struct file_operations afs_mntpt_file_operations = { |
1da177e4 | 31 | .open = afs_mntpt_open, |
6038f373 | 32 | .llseek = noop_llseek, |
1da177e4 LT |
33 | }; |
34 | ||
754661f1 | 35 | const struct inode_operations afs_mntpt_inode_operations = { |
1da177e4 | 36 | .lookup = afs_mntpt_lookup, |
1da177e4 | 37 | .readlink = page_readlink, |
416351f2 | 38 | .getattr = afs_getattr, |
d3e3b7ea | 39 | .listxattr = afs_listxattr, |
1da177e4 LT |
40 | }; |
41 | ||
bec5eb61 | 42 | const struct inode_operations afs_autocell_inode_operations = { |
bec5eb61 | 43 | .getattr = afs_getattr, |
44 | }; | |
45 | ||
1da177e4 | 46 | static LIST_HEAD(afs_vfsmounts); |
08e0e7c8 | 47 | static DECLARE_DELAYED_WORK(afs_mntpt_expiry_timer, afs_mntpt_expiry_timed_out); |
1da177e4 | 48 | |
c1206a2c | 49 | static unsigned long afs_mntpt_expiry_timeout = 10 * 60; |
1da177e4 | 50 | |
c99c2171 DH |
51 | static const char afs_root_volume[] = "root.cell"; |
52 | ||
1da177e4 LT |
53 | /* |
54 | * no valid lookup procedure on this sort of dir | |
55 | */ | |
56 | static struct dentry *afs_mntpt_lookup(struct inode *dir, | |
57 | struct dentry *dentry, | |
00cd8dd3 | 58 | unsigned int flags) |
1da177e4 | 59 | { |
a455589f | 60 | _enter("%p,%p{%pd2}", dir, dentry, dentry); |
1da177e4 | 61 | return ERR_PTR(-EREMOTE); |
ec26815a | 62 | } |
1da177e4 | 63 | |
1da177e4 LT |
64 | /* |
65 | * no valid open procedure on this sort of dir | |
66 | */ | |
67 | static int afs_mntpt_open(struct inode *inode, struct file *file) | |
68 | { | |
a455589f | 69 | _enter("%p,%p{%pD2}", inode, file, file); |
1da177e4 | 70 | return -EREMOTE; |
ec26815a | 71 | } |
1da177e4 | 72 | |
1da177e4 | 73 | /* |
c99c2171 | 74 | * Set the parameters for the proposed superblock. |
1da177e4 | 75 | */ |
c99c2171 | 76 | static int afs_mntpt_set_params(struct fs_context *fc, struct dentry *mntpt) |
1da177e4 | 77 | { |
c99c2171 DH |
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; | |
82 | const char *p; | |
1da177e4 LT |
83 | int ret; |
84 | ||
c99c2171 DH |
85 | if (fc->net_ns != src_as->net_ns) { |
86 | put_net(fc->net_ns); | |
87 | fc->net_ns = get_net(src_as->net_ns); | |
88 | } | |
1da177e4 | 89 | |
c99c2171 DH |
90 | if (src_as->volume && src_as->volume->type == AFSVL_RWVOL) { |
91 | ctx->type = AFSVL_RWVOL; | |
92 | ctx->force = true; | |
93 | } | |
94 | if (ctx->cell) { | |
95 | afs_put_cell(ctx->net, ctx->cell); | |
96 | ctx->cell = NULL; | |
97 | } | |
bec5eb61 | 98 | if (test_bit(AFS_VNODE_PSEUDODIR, &vnode->flags)) { |
99 | /* if the directory is a pseudo directory, use the d_name */ | |
bec5eb61 | 100 | unsigned size = mntpt->d_name.len; |
101 | ||
c99c2171 DH |
102 | if (size < 2) |
103 | return -ENOENT; | |
bec5eb61 | 104 | |
c99c2171 | 105 | p = mntpt->d_name.name; |
bec5eb61 | 106 | if (mntpt->d_name.name[0] == '.') { |
c99c2171 DH |
107 | size--; |
108 | p++; | |
109 | ctx->type = AFSVL_RWVOL; | |
110 | ctx->force = true; | |
bec5eb61 | 111 | } |
c99c2171 DH |
112 | if (size > AFS_MAXCELLNAME) |
113 | return -ENAMETOOLONG; | |
114 | ||
115 | cell = afs_lookup_cell(ctx->net, p, size, NULL, false); | |
116 | if (IS_ERR(cell)) { | |
117 | pr_err("kAFS: unable to lookup cell '%pd'\n", mntpt); | |
118 | return PTR_ERR(cell); | |
119 | } | |
120 | ctx->cell = cell; | |
121 | ||
122 | ctx->volname = afs_root_volume; | |
123 | ctx->volnamesz = sizeof(afs_root_volume) - 1; | |
bec5eb61 | 124 | } else { |
125 | /* read the contents of the AFS special symlink */ | |
c99c2171 | 126 | struct page *page; |
2b0143b5 | 127 | loff_t size = i_size_read(d_inode(mntpt)); |
bec5eb61 | 128 | char *buf; |
129 | ||
c99c2171 DH |
130 | if (src_as->cell) |
131 | ctx->cell = afs_get_cell(src_as->cell); | |
132 | ||
bec5eb61 | 133 | if (size > PAGE_SIZE - 1) |
c99c2171 | 134 | return -EINVAL; |
bec5eb61 | 135 | |
2b0143b5 | 136 | page = read_mapping_page(d_inode(mntpt)->i_mapping, 0, NULL); |
c99c2171 DH |
137 | if (IS_ERR(page)) |
138 | return PTR_ERR(page); | |
bec5eb61 | 139 | |
f51375cd DH |
140 | if (PageError(page)) { |
141 | ret = afs_bad(AFS_FS_I(d_inode(mntpt)), afs_file_error_mntpt); | |
c99c2171 DH |
142 | put_page(page); |
143 | return ret; | |
f51375cd | 144 | } |
bec5eb61 | 145 | |
c99c2171 DH |
146 | buf = kmap(page); |
147 | ret = vfs_parse_fs_string(fc, "source", buf, size); | |
148 | kunmap(page); | |
09cbfeaf | 149 | put_page(page); |
c99c2171 DH |
150 | if (ret < 0) |
151 | return ret; | |
1da177e4 LT |
152 | } |
153 | ||
c99c2171 DH |
154 | return 0; |
155 | } | |
1da177e4 | 156 | |
c99c2171 DH |
157 | /* |
158 | * create a vfsmount to be automounted | |
159 | */ | |
160 | static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt) | |
161 | { | |
162 | struct fs_context *fc; | |
163 | struct vfsmount *mnt; | |
164 | int ret; | |
1da177e4 | 165 | |
c99c2171 | 166 | BUG_ON(!d_inode(mntpt)); |
1da177e4 | 167 | |
c99c2171 DH |
168 | fc = fs_context_for_submount(&afs_fs_type, mntpt); |
169 | if (IS_ERR(fc)) | |
170 | return ERR_CAST(fc); | |
171 | ||
172 | ret = afs_mntpt_set_params(fc, mntpt); | |
173 | if (!ret) | |
174 | mnt = fc_mount(fc); | |
175 | else | |
176 | mnt = ERR_PTR(ret); | |
177 | ||
178 | put_fs_context(fc); | |
179 | return mnt; | |
ec26815a | 180 | } |
1da177e4 | 181 | |
1da177e4 | 182 | /* |
d18610b0 | 183 | * handle an automount point |
1da177e4 | 184 | */ |
d18610b0 | 185 | struct vfsmount *afs_d_automount(struct path *path) |
1da177e4 LT |
186 | { |
187 | struct vfsmount *newmnt; | |
1da177e4 | 188 | |
a455589f | 189 | _enter("{%pd}", path->dentry); |
08e0e7c8 | 190 | |
d18610b0 DH |
191 | newmnt = afs_mntpt_do_automount(path->dentry); |
192 | if (IS_ERR(newmnt)) | |
193 | return newmnt; | |
1da177e4 | 194 | |
ea5b778a DH |
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); | |
5ffc2836 | 199 | _leave(" = %p", newmnt); |
ea5b778a | 200 | return newmnt; |
ec26815a | 201 | } |
1da177e4 | 202 | |
1da177e4 LT |
203 | /* |
204 | * handle mountpoint expiry timer going off | |
205 | */ | |
08e0e7c8 | 206 | static void afs_mntpt_expiry_timed_out(struct work_struct *work) |
1da177e4 | 207 | { |
08e0e7c8 DH |
208 | _enter(""); |
209 | ||
210 | if (!list_empty(&afs_vfsmounts)) { | |
211 | mark_mounts_for_expiry(&afs_vfsmounts); | |
0ad53eee TH |
212 | queue_delayed_work(afs_wq, &afs_mntpt_expiry_timer, |
213 | afs_mntpt_expiry_timeout * HZ); | |
08e0e7c8 DH |
214 | } |
215 | ||
216 | _leave(""); | |
217 | } | |
1da177e4 | 218 | |
08e0e7c8 DH |
219 | /* |
220 | * kill the AFS mountpoint timer if it's still running | |
221 | */ | |
222 | void afs_mntpt_kill_timer(void) | |
223 | { | |
224 | _enter(""); | |
1da177e4 | 225 | |
08e0e7c8 | 226 | ASSERT(list_empty(&afs_vfsmounts)); |
0ad53eee | 227 | cancel_delayed_work_sync(&afs_mntpt_expiry_timer); |
08e0e7c8 | 228 | } |