blob: f6e8ca9ea56a173c82409ddd9fe0bf118ae814b1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* -*- c -*- --------------------------------------------------------------- *
2 *
3 * linux/fs/autofs/root.c
4 *
5 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
6 * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
Ian Kent34ca9592006-03-27 01:14:54 -08007 * Copyright 2001-2006 Ian Kent <raven@themaw.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This file is part of the Linux kernel and is made available under
10 * the terms of the GNU General Public License, version 2, or at your
11 * option, any later version, incorporated herein by reference.
12 *
13 * ------------------------------------------------------------------------- */
14
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080015#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/errno.h>
17#include <linux/stat.h>
18#include <linux/param.h>
19#include <linux/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "autofs_i.h"
21
22static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *);
23static int autofs4_dir_unlink(struct inode *,struct dentry *);
24static int autofs4_dir_rmdir(struct inode *,struct dentry *);
25static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
26static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
27static int autofs4_dir_open(struct inode *inode, struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
Ian Kent34ca9592006-03-27 01:14:54 -080029static void *autofs4_follow_link(struct dentry *, struct nameidata *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Ian Kent6d5cb922008-07-23 21:30:15 -070031#define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
32#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
33
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080034const struct file_operations autofs4_root_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 .open = dcache_dir_open,
36 .release = dcache_dir_close,
37 .read = generic_read_dir,
Ian Kentaa55ddf2008-07-23 21:30:29 -070038 .readdir = dcache_readdir,
Al Viro59af1582008-08-24 07:24:41 -040039 .llseek = dcache_dir_lseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 .ioctl = autofs4_root_ioctl,
41};
42
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080043const struct file_operations autofs4_dir_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 .open = autofs4_dir_open,
Ian Kentff9cd492008-07-23 21:30:24 -070045 .release = dcache_dir_close,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 .read = generic_read_dir,
Ian Kentff9cd492008-07-23 21:30:24 -070047 .readdir = dcache_readdir,
Al Viro59af1582008-08-24 07:24:41 -040048 .llseek = dcache_dir_lseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
50
Arjan van de Ven754661f2007-02-12 00:55:38 -080051const struct inode_operations autofs4_indirect_root_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 .lookup = autofs4_lookup,
53 .unlink = autofs4_dir_unlink,
54 .symlink = autofs4_dir_symlink,
55 .mkdir = autofs4_dir_mkdir,
56 .rmdir = autofs4_dir_rmdir,
57};
58
Arjan van de Ven754661f2007-02-12 00:55:38 -080059const struct inode_operations autofs4_direct_root_inode_operations = {
Ian Kent34ca9592006-03-27 01:14:54 -080060 .lookup = autofs4_lookup,
Ian Kent871f9432006-03-27 01:14:58 -080061 .unlink = autofs4_dir_unlink,
62 .mkdir = autofs4_dir_mkdir,
63 .rmdir = autofs4_dir_rmdir,
Ian Kent34ca9592006-03-27 01:14:54 -080064 .follow_link = autofs4_follow_link,
65};
66
Arjan van de Ven754661f2007-02-12 00:55:38 -080067const struct inode_operations autofs4_dir_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 .lookup = autofs4_lookup,
69 .unlink = autofs4_dir_unlink,
70 .symlink = autofs4_dir_symlink,
71 .mkdir = autofs4_dir_mkdir,
72 .rmdir = autofs4_dir_rmdir,
73};
74
Ian Kent4f8427d2009-12-15 16:45:42 -080075static void autofs4_add_active(struct dentry *dentry)
76{
77 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
78 struct autofs_info *ino = autofs4_dentry_ino(dentry);
79 if (ino) {
80 spin_lock(&sbi->lookup_lock);
81 if (!ino->active_count) {
82 if (list_empty(&ino->active))
83 list_add(&ino->active, &sbi->active_list);
84 }
85 ino->active_count++;
86 spin_unlock(&sbi->lookup_lock);
87 }
88 return;
89}
90
91static void autofs4_del_active(struct dentry *dentry)
92{
93 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
94 struct autofs_info *ino = autofs4_dentry_ino(dentry);
95 if (ino) {
96 spin_lock(&sbi->lookup_lock);
97 ino->active_count--;
98 if (!ino->active_count) {
99 if (!list_empty(&ino->active))
100 list_del_init(&ino->active);
101 }
102 spin_unlock(&sbi->lookup_lock);
103 }
104 return;
105}
106
Ian Kent36b64132009-12-15 16:45:44 -0800107static unsigned int autofs4_need_mount(unsigned int flags)
108{
109 unsigned int res = 0;
110 if (flags & (TRIGGER_FLAGS | TRIGGER_INTENTS))
111 res = 1;
112 return res;
113}
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115static int autofs4_dir_open(struct inode *inode, struct file *file)
116{
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800117 struct dentry *dentry = file->f_path.dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kentf360ce32006-03-27 01:14:43 -0800119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 DPRINTK("file=%p dentry=%p %.*s",
121 file, dentry, dentry->d_name.len, dentry->d_name.name);
122
123 if (autofs4_oz_mode(sbi))
124 goto out;
125
Ian Kentff9cd492008-07-23 21:30:24 -0700126 /*
127 * An empty directory in an autofs file system is always a
128 * mount point. The daemon must have failed to mount this
129 * during lookup so it doesn't exist. This can happen, for
130 * example, if user space returns an incorrect status for a
131 * mount request. Otherwise we're doing a readdir on the
132 * autofs file system so just let the libfs routines handle
133 * it.
134 */
135 spin_lock(&dcache_lock);
136 if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 spin_unlock(&dcache_lock);
Ian Kentff9cd492008-07-23 21:30:24 -0700138 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
Ian Kentff9cd492008-07-23 21:30:24 -0700140 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Ian Kentf360ce32006-03-27 01:14:43 -0800142out:
Ian Kentff9cd492008-07-23 21:30:24 -0700143 return dcache_dir_open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
Ian Kent862b1102006-03-27 01:14:48 -0800146static int try_to_fill_dentry(struct dentry *dentry, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Ian Kent862b1102006-03-27 01:14:48 -0800148 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kent718c6042006-03-27 01:14:42 -0800149 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Jeff Moyer9d2de6a2008-05-01 04:35:09 -0700150 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 DPRINTK("dentry=%p %.*s ino=%p",
153 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
154
Ian Kent718c6042006-03-27 01:14:42 -0800155 /*
156 * Wait for a pending mount, triggering one if there
157 * isn't one already
158 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 if (dentry->d_inode == NULL) {
160 DPRINTK("waiting for mount name=%.*s",
161 dentry->d_name.len, dentry->d_name.name);
162
163 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
Ian Kent718c6042006-03-27 01:14:42 -0800164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 DPRINTK("mount done status=%d", status);
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 /* Turn this into a real negative dentry? */
168 if (status == -ENOENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 spin_lock(&dentry->d_lock);
170 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
171 spin_unlock(&dentry->d_lock);
Ian Kent34ca9592006-03-27 01:14:54 -0800172 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 } else if (status) {
174 /* Return a negative dentry, but leave it "pending" */
Ian Kent34ca9592006-03-27 01:14:54 -0800175 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
177 /* Trigger mount for path component or follow link */
Ian Kent26e81b32008-07-23 21:30:25 -0700178 } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
Ian Kent36b64132009-12-15 16:45:44 -0800179 autofs4_need_mount(flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 current->link_count) {
181 DPRINTK("waiting for mount name=%.*s",
182 dentry->d_name.len, dentry->d_name.name);
183
184 spin_lock(&dentry->d_lock);
185 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
186 spin_unlock(&dentry->d_lock);
187 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
188
189 DPRINTK("mount done status=%d", status);
190
191 if (status) {
192 spin_lock(&dentry->d_lock);
193 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
194 spin_unlock(&dentry->d_lock);
Ian Kent34ca9592006-03-27 01:14:54 -0800195 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
197 }
198
Ian Kente0a7aae2006-03-27 01:14:47 -0800199 /* Initialize expiry counter after successful mount */
200 if (ino)
201 ino->last_used = jiffies;
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 spin_lock(&dentry->d_lock);
204 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
205 spin_unlock(&dentry->d_lock);
Jeff Moyer03379042008-05-01 04:35:08 -0700206
Jeff Moyer9d2de6a2008-05-01 04:35:09 -0700207 return 0;
Ian Kent34ca9592006-03-27 01:14:54 -0800208}
209
210/* For autofs direct mounts the follow link triggers the mount */
211static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
212{
213 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kenta5370552006-05-15 09:43:51 -0700214 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent34ca9592006-03-27 01:14:54 -0800215 int oz_mode = autofs4_oz_mode(sbi);
216 unsigned int lookup_type;
217 int status;
218
219 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
220 dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
221 nd->flags);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700222 /*
223 * For an expire of a covered direct or offset mount we need
Al Viro9393bd02009-04-18 13:58:15 -0400224 * to break out of follow_down() at the autofs mount trigger
Ian Kent6e60a9a2008-07-23 21:30:27 -0700225 * (d_mounted--), so we can see the expiring flag, and manage
226 * the blocking and following here until the expire is completed.
227 */
228 if (oz_mode) {
229 spin_lock(&sbi->fs_lock);
230 if (ino->flags & AUTOFS_INF_EXPIRING) {
231 spin_unlock(&sbi->fs_lock);
232 /* Follow down to our covering mount. */
Al Viro9393bd02009-04-18 13:58:15 -0400233 if (!follow_down(&nd->path))
Ian Kent6e60a9a2008-07-23 21:30:27 -0700234 goto done;
Ian Kentec6e8c72008-07-23 21:30:28 -0700235 goto follow;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700236 }
237 spin_unlock(&sbi->fs_lock);
Ian Kent34ca9592006-03-27 01:14:54 -0800238 goto done;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700239 }
Ian Kent34ca9592006-03-27 01:14:54 -0800240
Ian Kent6e60a9a2008-07-23 21:30:27 -0700241 /* If an expire request is pending everyone must wait. */
Ian Kent06a35982008-07-23 21:30:28 -0700242 autofs4_expire_wait(dentry);
Ian Kent97e74492008-07-23 21:30:26 -0700243
Ian Kent6e60a9a2008-07-23 21:30:27 -0700244 /* We trigger a mount for almost all flags */
Ian Kent36b64132009-12-15 16:45:44 -0800245 lookup_type = autofs4_need_mount(nd->flags);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700246 if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
Ian Kentec6e8c72008-07-23 21:30:28 -0700247 goto follow;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700248
Ian Kent871f9432006-03-27 01:14:58 -0800249 /*
Ian Kent6e60a9a2008-07-23 21:30:27 -0700250 * If the dentry contains directories then it is an autofs
251 * multi-mount with no root mount offset. So don't try to
252 * mount it again.
Ian Kent871f9432006-03-27 01:14:58 -0800253 */
254 spin_lock(&dcache_lock);
Ian Kent26e81b32008-07-23 21:30:25 -0700255 if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
256 (!d_mountpoint(dentry) && __simple_empty(dentry))) {
Ian Kent871f9432006-03-27 01:14:58 -0800257 spin_unlock(&dcache_lock);
258
259 status = try_to_fill_dentry(dentry, 0);
260 if (status)
261 goto out_error;
262
Ian Kent6e60a9a2008-07-23 21:30:27 -0700263 goto follow;
Ian Kent871f9432006-03-27 01:14:58 -0800264 }
265 spin_unlock(&dcache_lock);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700266follow:
267 /*
268 * If there is no root mount it must be an autofs
269 * multi-mount with no root offset so we don't need
270 * to follow it.
271 */
272 if (d_mountpoint(dentry)) {
Al Viro9393bd02009-04-18 13:58:15 -0400273 if (!autofs4_follow_mount(&nd->path)) {
Ian Kent6e60a9a2008-07-23 21:30:27 -0700274 status = -ENOENT;
275 goto out_error;
276 }
277 }
Ian Kent871f9432006-03-27 01:14:58 -0800278
Ian Kent34ca9592006-03-27 01:14:54 -0800279done:
280 return NULL;
281
282out_error:
Jan Blunck1d957f92008-02-14 19:34:35 -0800283 path_put(&nd->path);
Ian Kent34ca9592006-03-27 01:14:54 -0800284 return ERR_PTR(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
287/*
288 * Revalidate is called on every cache lookup. Some of those
289 * cache lookups may actually happen while the dentry is not
290 * yet completely filled in, and revalidate has to delay such
291 * lookups..
292 */
Ian Kent718c6042006-03-27 01:14:42 -0800293static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Ian Kent718c6042006-03-27 01:14:42 -0800295 struct inode *dir = dentry->d_parent->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
297 int oz_mode = autofs4_oz_mode(sbi);
298 int flags = nd ? nd->flags : 0;
Ian Kentbcdc5e02006-09-27 01:50:44 -0700299 int status = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301 /* Pending dentry */
Ian Kent97e74492008-07-23 21:30:26 -0700302 spin_lock(&sbi->fs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 if (autofs4_ispending(dentry)) {
Ian Kentbcdc5e02006-09-27 01:50:44 -0700304 /* The daemon never causes a mount to trigger */
Ian Kent97e74492008-07-23 21:30:26 -0700305 spin_unlock(&sbi->fs_lock);
306
Ian Kentbcdc5e02006-09-27 01:50:44 -0700307 if (oz_mode)
308 return 1;
309
310 /*
Ian Kent06a35982008-07-23 21:30:28 -0700311 * If the directory has gone away due to an expire
312 * we have been called as ->d_revalidate() and so
313 * we need to return false and proceed to ->lookup().
314 */
315 if (autofs4_expire_wait(dentry) == -EAGAIN)
316 return 0;
317
318 /*
Ian Kentbcdc5e02006-09-27 01:50:44 -0700319 * A zero status is success otherwise we have a
320 * negative error code.
321 */
322 status = try_to_fill_dentry(dentry, flags);
323 if (status == 0)
Ian Kentf50b6f82007-02-20 13:58:10 -0800324 return 1;
325
Ian Kentbcdc5e02006-09-27 01:50:44 -0700326 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 }
Ian Kent97e74492008-07-23 21:30:26 -0700328 spin_unlock(&sbi->fs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /* Negative dentry.. invalidate if "old" */
331 if (dentry->d_inode == NULL)
Ian Kent2d753e62006-03-27 01:14:44 -0800332 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 /* Check for a non-mountpoint directory with no contents */
335 spin_lock(&dcache_lock);
336 if (S_ISDIR(dentry->d_inode->i_mode) &&
337 !d_mountpoint(dentry) &&
Ian Kent90a59c72006-03-27 01:14:50 -0800338 __simple_empty(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 DPRINTK("dentry=%p %.*s, emptydir",
340 dentry, dentry->d_name.len, dentry->d_name.name);
341 spin_unlock(&dcache_lock);
Ian Kent97e74492008-07-23 21:30:26 -0700342
Ian Kentbcdc5e02006-09-27 01:50:44 -0700343 /* The daemon never causes a mount to trigger */
344 if (oz_mode)
345 return 1;
346
347 /*
348 * A zero status is success otherwise we have a
349 * negative error code.
350 */
351 status = try_to_fill_dentry(dentry, flags);
352 if (status == 0)
353 return 1;
354
355 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357 spin_unlock(&dcache_lock);
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return 1;
360}
361
Ian Kent34ca9592006-03-27 01:14:54 -0800362void autofs4_dentry_release(struct dentry *de)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
364 struct autofs_info *inf;
365
366 DPRINTK("releasing %p", de);
367
368 inf = autofs4_dentry_ino(de);
369 de->d_fsdata = NULL;
370
371 if (inf) {
Ian Kentf50b6f82007-02-20 13:58:10 -0800372 struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
373
Ian Kentf50b6f82007-02-20 13:58:10 -0800374 if (sbi) {
Ian Kent5f6f4f22008-07-23 21:30:09 -0700375 spin_lock(&sbi->lookup_lock);
Ian Kent25767372008-07-23 21:30:12 -0700376 if (!list_empty(&inf->active))
377 list_del(&inf->active);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700378 if (!list_empty(&inf->expiring))
379 list_del(&inf->expiring);
380 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800381 }
382
Jeff Mahoneyc3724b12007-04-11 23:28:46 -0700383 inf->dentry = NULL;
384 inf->inode = NULL;
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 autofs4_free_ino(inf);
387 }
388}
389
390/* For dentries of directories in the root dir */
Al Viro08f11512009-02-20 05:56:19 +0000391static const struct dentry_operations autofs4_root_dentry_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 .d_revalidate = autofs4_revalidate,
393 .d_release = autofs4_dentry_release,
394};
395
396/* For other dentries */
Al Viro08f11512009-02-20 05:56:19 +0000397static const struct dentry_operations autofs4_dentry_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .d_revalidate = autofs4_revalidate,
399 .d_release = autofs4_dentry_release,
400};
401
Ian Kent25767372008-07-23 21:30:12 -0700402static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
403{
404 unsigned int len = name->len;
405 unsigned int hash = name->hash;
406 const unsigned char *str = name->name;
407 struct list_head *p, *head;
408
409 spin_lock(&dcache_lock);
410 spin_lock(&sbi->lookup_lock);
411 head = &sbi->active_list;
412 list_for_each(p, head) {
413 struct autofs_info *ino;
414 struct dentry *dentry;
415 struct qstr *qstr;
416
417 ino = list_entry(p, struct autofs_info, active);
418 dentry = ino->dentry;
419
420 spin_lock(&dentry->d_lock);
421
422 /* Already gone? */
423 if (atomic_read(&dentry->d_count) == 0)
424 goto next;
425
426 qstr = &dentry->d_name;
427
428 if (dentry->d_name.hash != hash)
429 goto next;
430 if (dentry->d_parent != parent)
431 goto next;
432
433 if (qstr->len != len)
434 goto next;
435 if (memcmp(qstr->name, str, len))
436 goto next;
437
438 if (d_unhashed(dentry)) {
439 dget(dentry);
440 spin_unlock(&dentry->d_lock);
441 spin_unlock(&sbi->lookup_lock);
442 spin_unlock(&dcache_lock);
443 return dentry;
444 }
445next:
446 spin_unlock(&dentry->d_lock);
447 }
448 spin_unlock(&sbi->lookup_lock);
449 spin_unlock(&dcache_lock);
450
451 return NULL;
452}
453
Ian Kent5f6f4f22008-07-23 21:30:09 -0700454static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
Ian Kentf50b6f82007-02-20 13:58:10 -0800455{
456 unsigned int len = name->len;
457 unsigned int hash = name->hash;
458 const unsigned char *str = name->name;
459 struct list_head *p, *head;
460
461 spin_lock(&dcache_lock);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700462 spin_lock(&sbi->lookup_lock);
463 head = &sbi->expiring_list;
Ian Kentf50b6f82007-02-20 13:58:10 -0800464 list_for_each(p, head) {
465 struct autofs_info *ino;
466 struct dentry *dentry;
467 struct qstr *qstr;
468
Ian Kent5f6f4f22008-07-23 21:30:09 -0700469 ino = list_entry(p, struct autofs_info, expiring);
Ian Kentf50b6f82007-02-20 13:58:10 -0800470 dentry = ino->dentry;
471
472 spin_lock(&dentry->d_lock);
473
474 /* Bad luck, we've already been dentry_iput */
475 if (!dentry->d_inode)
476 goto next;
477
478 qstr = &dentry->d_name;
479
480 if (dentry->d_name.hash != hash)
481 goto next;
482 if (dentry->d_parent != parent)
483 goto next;
484
485 if (qstr->len != len)
486 goto next;
487 if (memcmp(qstr->name, str, len))
488 goto next;
489
490 if (d_unhashed(dentry)) {
Ian Kentf50b6f82007-02-20 13:58:10 -0800491 dget(dentry);
Ian Kentf50b6f82007-02-20 13:58:10 -0800492 spin_unlock(&dentry->d_lock);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700493 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800494 spin_unlock(&dcache_lock);
495 return dentry;
496 }
497next:
498 spin_unlock(&dentry->d_lock);
499 }
Ian Kent5f6f4f22008-07-23 21:30:09 -0700500 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800501 spin_unlock(&dcache_lock);
502
503 return NULL;
504}
505
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506/* Lookups in the root directory */
507static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
508{
509 struct autofs_sb_info *sbi;
Ian Kent25767372008-07-23 21:30:12 -0700510 struct autofs_info *ino;
511 struct dentry *expiring, *unhashed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 int oz_mode;
513
514 DPRINTK("name = %.*s",
515 dentry->d_name.len, dentry->d_name.name);
516
Ian Kent718c6042006-03-27 01:14:42 -0800517 /* File name too long to exist */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 if (dentry->d_name.len > NAME_MAX)
Ian Kent718c6042006-03-27 01:14:42 -0800519 return ERR_PTR(-ENAMETOOLONG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521 sbi = autofs4_sbi(dir->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 oz_mode = autofs4_oz_mode(sbi);
Ian Kent718c6042006-03-27 01:14:42 -0800523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
Pavel Emelianova47afb02007-10-18 23:39:46 -0700525 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Ian Kent25767372008-07-23 21:30:12 -0700527 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
528 if (unhashed)
529 dentry = unhashed;
530 else {
531 /*
532 * Mark the dentry incomplete but don't hash it. We do this
533 * to serialize our inode creation operations (symlink and
534 * mkdir) which prevents deadlock during the callback to
535 * the daemon. Subsequent user space lookups for the same
536 * dentry are placed on the wait queue while the daemon
537 * itself is allowed passage unresticted so the create
538 * operation itself can then hash the dentry. Finally,
539 * we check for the hashed dentry and return the newly
540 * hashed dentry.
541 */
542 dentry->d_op = &autofs4_root_dentry_operations;
Ian Kent5f6f4f22008-07-23 21:30:09 -0700543
Ian Kent25767372008-07-23 21:30:12 -0700544 /*
545 * And we need to ensure that the same dentry is used for
546 * all following lookup calls until it is hashed so that
547 * the dentry flags are persistent throughout the request.
548 */
549 ino = autofs4_init_ino(NULL, sbi, 0555);
550 if (!ino)
551 return ERR_PTR(-ENOMEM);
552
553 dentry->d_fsdata = ino;
554 ino->dentry = dentry;
555
Ian Kent4f8427d2009-12-15 16:45:42 -0800556 autofs4_add_active(dentry);
Ian Kent25767372008-07-23 21:30:12 -0700557
558 d_instantiate(dentry, NULL);
559 }
Ian Kent5f6f4f22008-07-23 21:30:09 -0700560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 if (!oz_mode) {
Ian Kent8f63aaa8b2009-03-31 15:24:45 -0700562 mutex_unlock(&dir->i_mutex);
563 expiring = autofs4_lookup_expiring(sbi,
564 dentry->d_parent,
565 &dentry->d_name);
566 if (expiring) {
567 /*
568 * If we are racing with expire the request might not
569 * be quite complete but the directory has been removed
570 * so it must have been successful, so just wait for it.
571 */
572 ino = autofs4_dentry_ino(expiring);
573 autofs4_expire_wait(expiring);
Ian Kentc4cd70b2009-12-15 16:45:43 -0800574 autofs4_del_expiring(expiring);
Ian Kent8f63aaa8b2009-03-31 15:24:45 -0700575 dput(expiring);
576 }
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 spin_lock(&dentry->d_lock);
579 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
580 spin_unlock(&dentry->d_lock);
Ian Kent8f63aaa8b2009-03-31 15:24:45 -0700581 if (dentry->d_op && dentry->d_op->d_revalidate)
Ian Kentc432c252008-07-23 21:30:14 -0700582 (dentry->d_op->d_revalidate)(dentry, nd);
Ian Kent8f63aaa8b2009-03-31 15:24:45 -0700583 mutex_lock(&dir->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 }
585
586 /*
587 * If we are still pending, check if we had to handle
588 * a signal. If so we can force a restart..
589 */
590 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
591 /* See if we were interrupted */
592 if (signal_pending(current)) {
593 sigset_t *sigset = &current->pending.signal;
594 if (sigismember (sigset, SIGKILL) ||
595 sigismember (sigset, SIGQUIT) ||
596 sigismember (sigset, SIGINT)) {
Ian Kent25767372008-07-23 21:30:12 -0700597 if (unhashed)
598 dput(unhashed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return ERR_PTR(-ERESTARTNOINTR);
600 }
601 }
Ian Kent25767372008-07-23 21:30:12 -0700602 if (!oz_mode) {
603 spin_lock(&dentry->d_lock);
604 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
605 spin_unlock(&dentry->d_lock);
606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608
609 /*
610 * If this dentry is unhashed, then we shouldn't honour this
Ian Kentc9ffec42007-02-20 13:58:10 -0800611 * lookup. Returning ENOENT here doesn't do the right thing
612 * for all system calls, but it should be OK for the operations
613 * we permit from an autofs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 */
Ian Kent1864f7b2007-08-22 14:01:54 -0700615 if (!oz_mode && d_unhashed(dentry)) {
Ian Kentc9ffec42007-02-20 13:58:10 -0800616 /*
617 * A user space application can (and has done in the past)
618 * remove and re-create this directory during the callback.
619 * This can leave us with an unhashed dentry, but a
620 * successful mount! So we need to perform another
621 * cached lookup in case the dentry now exists.
622 */
623 struct dentry *parent = dentry->d_parent;
624 struct dentry *new = d_lookup(parent, &dentry->d_name);
625 if (new != NULL)
626 dentry = new;
627 else
628 dentry = ERR_PTR(-ENOENT);
629
Ian Kent25767372008-07-23 21:30:12 -0700630 if (unhashed)
631 dput(unhashed);
632
Ian Kentc9ffec42007-02-20 13:58:10 -0800633 return dentry;
Ian Kentf50b6f82007-02-20 13:58:10 -0800634 }
635
Ian Kent25767372008-07-23 21:30:12 -0700636 if (unhashed)
637 return unhashed;
638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return NULL;
640}
641
642static int autofs4_dir_symlink(struct inode *dir,
643 struct dentry *dentry,
644 const char *symname)
645{
646 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
647 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800648 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 struct inode *inode;
650 char *cp;
651
652 DPRINTK("%s <- %.*s", symname,
653 dentry->d_name.len, dentry->d_name.name);
654
655 if (!autofs4_oz_mode(sbi))
656 return -EACCES;
657
658 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
Ian Kent25767372008-07-23 21:30:12 -0700659 if (!ino)
660 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Ian Kent4f8427d2009-12-15 16:45:42 -0800662 autofs4_del_active(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Ian Kentef581a72008-07-23 21:30:13 -0700664 ino->size = strlen(symname);
Ian Kent25767372008-07-23 21:30:12 -0700665 cp = kmalloc(ino->size + 1, GFP_KERNEL);
666 if (!cp) {
667 if (!dentry->d_fsdata)
668 kfree(ino);
669 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
671
672 strcpy(cp, symname);
673
674 inode = autofs4_get_inode(dir->i_sb, ino);
Ian Kent25767372008-07-23 21:30:12 -0700675 if (!inode) {
676 kfree(cp);
677 if (!dentry->d_fsdata)
678 kfree(ino);
679 return -ENOMEM;
680 }
Ian Kent1864f7b2007-08-22 14:01:54 -0700681 d_add(dentry, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 if (dir == dir->i_sb->s_root->d_inode)
684 dentry->d_op = &autofs4_root_dentry_operations;
685 else
686 dentry->d_op = &autofs4_dentry_operations;
687
688 dentry->d_fsdata = ino;
689 ino->dentry = dget(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800690 atomic_inc(&ino->count);
691 p_ino = autofs4_dentry_ino(dentry->d_parent);
692 if (p_ino && dentry->d_parent != dentry)
693 atomic_inc(&p_ino->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 ino->inode = inode;
695
Ian Kent25767372008-07-23 21:30:12 -0700696 ino->u.symlink = cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 dir->i_mtime = CURRENT_TIME;
698
699 return 0;
700}
701
702/*
703 * NOTE!
704 *
705 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
706 * that the file no longer exists. However, doing that means that the
707 * VFS layer can turn the dentry into a negative dentry. We don't want
Ian Kentf50b6f82007-02-20 13:58:10 -0800708 * this, because the unlink is probably the result of an expire.
Ian Kent5f6f4f22008-07-23 21:30:09 -0700709 * We simply d_drop it and add it to a expiring list in the super block,
710 * which allows the dentry lookup to check for an incomplete expire.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 *
712 * If a process is blocked on the dentry waiting for the expire to finish,
713 * it will invalidate the dentry and try to mount with a new one.
714 *
715 * Also see autofs4_dir_rmdir()..
716 */
717static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
718{
719 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
720 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800721 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 /* This allows root to remove symlinks */
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700724 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 return -EACCES;
726
Ian Kent1aff3c82006-03-27 01:14:46 -0800727 if (atomic_dec_and_test(&ino->count)) {
728 p_ino = autofs4_dentry_ino(dentry->d_parent);
729 if (p_ino && dentry->d_parent != dentry)
730 atomic_dec(&p_ino->count);
731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 dput(ino->dentry);
733
734 dentry->d_inode->i_size = 0;
Dave Hansence71ec32006-09-30 23:29:06 -0700735 clear_nlink(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 dir->i_mtime = CURRENT_TIME;
738
Ian Kentf50b6f82007-02-20 13:58:10 -0800739 spin_lock(&dcache_lock);
Ian Kentc4cd70b2009-12-15 16:45:43 -0800740 autofs4_add_expiring(dentry);
Ian Kentf50b6f82007-02-20 13:58:10 -0800741 spin_lock(&dentry->d_lock);
742 __d_drop(dentry);
743 spin_unlock(&dentry->d_lock);
744 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
746 return 0;
747}
748
749static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
750{
751 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
752 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800753 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Ian Kentf50b6f82007-02-20 13:58:10 -0800755 DPRINTK("dentry %p, removing %.*s",
756 dentry, dentry->d_name.len, dentry->d_name.name);
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 if (!autofs4_oz_mode(sbi))
759 return -EACCES;
760
761 spin_lock(&dcache_lock);
762 if (!list_empty(&dentry->d_subdirs)) {
763 spin_unlock(&dcache_lock);
764 return -ENOTEMPTY;
765 }
Ian Kentc4cd70b2009-12-15 16:45:43 -0800766 autofs4_add_expiring(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 spin_lock(&dentry->d_lock);
768 __d_drop(dentry);
769 spin_unlock(&dentry->d_lock);
770 spin_unlock(&dcache_lock);
771
Ian Kent1aff3c82006-03-27 01:14:46 -0800772 if (atomic_dec_and_test(&ino->count)) {
773 p_ino = autofs4_dentry_ino(dentry->d_parent);
774 if (p_ino && dentry->d_parent != dentry)
775 atomic_dec(&p_ino->count);
776 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 dput(ino->dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 dentry->d_inode->i_size = 0;
Dave Hansence71ec32006-09-30 23:29:06 -0700779 clear_nlink(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 if (dir->i_nlink)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700782 drop_nlink(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784 return 0;
785}
786
787static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
788{
789 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
790 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800791 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 struct inode *inode;
793
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700794 if (!autofs4_oz_mode(sbi))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 return -EACCES;
796
797 DPRINTK("dentry %p, creating %.*s",
798 dentry, dentry->d_name.len, dentry->d_name.name);
799
800 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
Ian Kent25767372008-07-23 21:30:12 -0700801 if (!ino)
802 return -ENOMEM;
803
Ian Kent4f8427d2009-12-15 16:45:42 -0800804 autofs4_del_active(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 inode = autofs4_get_inode(dir->i_sb, ino);
Ian Kent25767372008-07-23 21:30:12 -0700807 if (!inode) {
808 if (!dentry->d_fsdata)
809 kfree(ino);
810 return -ENOMEM;
811 }
Ian Kent1864f7b2007-08-22 14:01:54 -0700812 d_add(dentry, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 if (dir == dir->i_sb->s_root->d_inode)
815 dentry->d_op = &autofs4_root_dentry_operations;
816 else
817 dentry->d_op = &autofs4_dentry_operations;
818
819 dentry->d_fsdata = ino;
820 ino->dentry = dget(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800821 atomic_inc(&ino->count);
822 p_ino = autofs4_dentry_ino(dentry->d_parent);
823 if (p_ino && dentry->d_parent != dentry)
824 atomic_inc(&p_ino->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 ino->inode = inode;
Dave Hansend8c76e62006-09-30 23:29:04 -0700826 inc_nlink(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 dir->i_mtime = CURRENT_TIME;
828
829 return 0;
830}
831
832/* Get/set timeout ioctl() operation */
833static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
834 unsigned long __user *p)
835{
836 int rv;
837 unsigned long ntimeout;
838
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700839 if ((rv = get_user(ntimeout, p)) ||
840 (rv = put_user(sbi->exp_timeout/HZ, p)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 return rv;
842
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700843 if (ntimeout > ULONG_MAX/HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 sbi->exp_timeout = 0;
845 else
846 sbi->exp_timeout = ntimeout * HZ;
847
848 return 0;
849}
850
851/* Return protocol version */
852static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
853{
854 return put_user(sbi->version, p);
855}
856
857/* Return protocol sub version */
858static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
859{
860 return put_user(sbi->sub_version, p);
861}
862
863/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864* Tells the daemon whether it can umount the autofs mount.
865*/
866static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
867{
868 int status = 0;
869
Ian Kente3474a82006-03-27 01:14:51 -0800870 if (may_umount(mnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 status = 1;
872
873 DPRINTK("returning %d", status);
874
875 status = put_user(status, p);
876
877 return status;
878}
879
880/* Identify autofs4_dentries - this is so we can tell if there's
881 an extra dentry refcount or not. We only hold a refcount on the
882 dentry if its non-negative (ie, d_inode != NULL)
883*/
884int is_autofs4_dentry(struct dentry *dentry)
885{
886 return dentry && dentry->d_inode &&
887 (dentry->d_op == &autofs4_root_dentry_operations ||
888 dentry->d_op == &autofs4_dentry_operations) &&
889 dentry->d_fsdata != NULL;
890}
891
892/*
893 * ioctl()'s on the root directory is the chief method for the daemon to
894 * generate kernel reactions
895 */
896static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
897 unsigned int cmd, unsigned long arg)
898{
899 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
900 void __user *p = (void __user *)arg;
901
902 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
Pavel Emelianova47afb02007-10-18 23:39:46 -0700903 cmd,arg,sbi,task_pgrp_nr(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700905 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
906 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 return -ENOTTY;
908
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700909 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 return -EPERM;
911
912 switch(cmd) {
913 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
914 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
915 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
916 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
917 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
918 autofs4_catatonic_mode(sbi);
919 return 0;
920 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
921 return autofs4_get_protover(sbi, p);
922 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
923 return autofs4_get_protosubver(sbi, p);
924 case AUTOFS_IOC_SETTIMEOUT:
925 return autofs4_get_set_timeout(sbi, p);
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 case AUTOFS_IOC_ASKUMOUNT:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800928 return autofs4_ask_umount(filp->f_path.mnt, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 /* return a single thing to expire */
931 case AUTOFS_IOC_EXPIRE:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800932 return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 /* same as above, but can send multiple expires through pipe */
934 case AUTOFS_IOC_EXPIRE_MULTI:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800935 return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937 default:
938 return -ENOSYS;
939 }
940}