blob: 2954ac5fec759ddb60462f5219241b1102a5a1a8 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static int autofs4_dir_open(struct inode *inode, struct file *file)
108{
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800109 struct dentry *dentry = file->f_path.dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kentf360ce32006-03-27 01:14:43 -0800111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 DPRINTK("file=%p dentry=%p %.*s",
113 file, dentry, dentry->d_name.len, dentry->d_name.name);
114
115 if (autofs4_oz_mode(sbi))
116 goto out;
117
Ian Kentff9cd492008-07-23 21:30:24 -0700118 /*
119 * An empty directory in an autofs file system is always a
120 * mount point. The daemon must have failed to mount this
121 * during lookup so it doesn't exist. This can happen, for
122 * example, if user space returns an incorrect status for a
123 * mount request. Otherwise we're doing a readdir on the
124 * autofs file system so just let the libfs routines handle
125 * it.
126 */
127 spin_lock(&dcache_lock);
128 if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 spin_unlock(&dcache_lock);
Ian Kentff9cd492008-07-23 21:30:24 -0700130 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
Ian Kentff9cd492008-07-23 21:30:24 -0700132 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Ian Kentf360ce32006-03-27 01:14:43 -0800134out:
Ian Kentff9cd492008-07-23 21:30:24 -0700135 return dcache_dir_open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Ian Kent862b1102006-03-27 01:14:48 -0800138static int try_to_fill_dentry(struct dentry *dentry, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Ian Kent862b1102006-03-27 01:14:48 -0800140 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kent718c6042006-03-27 01:14:42 -0800141 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Jeff Moyer9d2de6a2008-05-01 04:35:09 -0700142 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 DPRINTK("dentry=%p %.*s ino=%p",
145 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
146
Ian Kent718c6042006-03-27 01:14:42 -0800147 /*
148 * Wait for a pending mount, triggering one if there
149 * isn't one already
150 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 if (dentry->d_inode == NULL) {
152 DPRINTK("waiting for mount name=%.*s",
153 dentry->d_name.len, dentry->d_name.name);
154
155 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
Ian Kent718c6042006-03-27 01:14:42 -0800156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 DPRINTK("mount done status=%d", status);
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 /* Turn this into a real negative dentry? */
160 if (status == -ENOENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 spin_lock(&dentry->d_lock);
162 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
163 spin_unlock(&dentry->d_lock);
Ian Kent34ca9592006-03-27 01:14:54 -0800164 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 } else if (status) {
166 /* Return a negative dentry, but leave it "pending" */
Ian Kent34ca9592006-03-27 01:14:54 -0800167 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169 /* Trigger mount for path component or follow link */
Ian Kent26e81b32008-07-23 21:30:25 -0700170 } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
171 flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 current->link_count) {
173 DPRINTK("waiting for mount name=%.*s",
174 dentry->d_name.len, dentry->d_name.name);
175
176 spin_lock(&dentry->d_lock);
177 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
178 spin_unlock(&dentry->d_lock);
179 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
180
181 DPRINTK("mount done status=%d", status);
182
183 if (status) {
184 spin_lock(&dentry->d_lock);
185 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
186 spin_unlock(&dentry->d_lock);
Ian Kent34ca9592006-03-27 01:14:54 -0800187 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189 }
190
Ian Kente0a7aae2006-03-27 01:14:47 -0800191 /* Initialize expiry counter after successful mount */
192 if (ino)
193 ino->last_used = jiffies;
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 spin_lock(&dentry->d_lock);
196 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
197 spin_unlock(&dentry->d_lock);
Jeff Moyer03379042008-05-01 04:35:08 -0700198
Jeff Moyer9d2de6a2008-05-01 04:35:09 -0700199 return 0;
Ian Kent34ca9592006-03-27 01:14:54 -0800200}
201
202/* For autofs direct mounts the follow link triggers the mount */
203static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
204{
205 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kenta5370552006-05-15 09:43:51 -0700206 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent34ca9592006-03-27 01:14:54 -0800207 int oz_mode = autofs4_oz_mode(sbi);
208 unsigned int lookup_type;
209 int status;
210
211 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
212 dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
213 nd->flags);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700214 /*
215 * For an expire of a covered direct or offset mount we need
Al Viro9393bd02009-04-18 13:58:15 -0400216 * to break out of follow_down() at the autofs mount trigger
Ian Kent6e60a9a2008-07-23 21:30:27 -0700217 * (d_mounted--), so we can see the expiring flag, and manage
218 * the blocking and following here until the expire is completed.
219 */
220 if (oz_mode) {
221 spin_lock(&sbi->fs_lock);
222 if (ino->flags & AUTOFS_INF_EXPIRING) {
223 spin_unlock(&sbi->fs_lock);
224 /* Follow down to our covering mount. */
Al Viro9393bd02009-04-18 13:58:15 -0400225 if (!follow_down(&nd->path))
Ian Kent6e60a9a2008-07-23 21:30:27 -0700226 goto done;
Ian Kentec6e8c72008-07-23 21:30:28 -0700227 goto follow;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700228 }
229 spin_unlock(&sbi->fs_lock);
Ian Kent34ca9592006-03-27 01:14:54 -0800230 goto done;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700231 }
Ian Kent34ca9592006-03-27 01:14:54 -0800232
Ian Kent6e60a9a2008-07-23 21:30:27 -0700233 /* If an expire request is pending everyone must wait. */
Ian Kent06a35982008-07-23 21:30:28 -0700234 autofs4_expire_wait(dentry);
Ian Kent97e74492008-07-23 21:30:26 -0700235
Ian Kent6e60a9a2008-07-23 21:30:27 -0700236 /* We trigger a mount for almost all flags */
237 lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
238 if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
Ian Kentec6e8c72008-07-23 21:30:28 -0700239 goto follow;
Ian Kent6e60a9a2008-07-23 21:30:27 -0700240
Ian Kent871f9432006-03-27 01:14:58 -0800241 /*
Ian Kent6e60a9a2008-07-23 21:30:27 -0700242 * If the dentry contains directories then it is an autofs
243 * multi-mount with no root mount offset. So don't try to
244 * mount it again.
Ian Kent871f9432006-03-27 01:14:58 -0800245 */
246 spin_lock(&dcache_lock);
Ian Kent26e81b32008-07-23 21:30:25 -0700247 if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
248 (!d_mountpoint(dentry) && __simple_empty(dentry))) {
Ian Kent871f9432006-03-27 01:14:58 -0800249 spin_unlock(&dcache_lock);
250
251 status = try_to_fill_dentry(dentry, 0);
252 if (status)
253 goto out_error;
254
Ian Kent6e60a9a2008-07-23 21:30:27 -0700255 goto follow;
Ian Kent871f9432006-03-27 01:14:58 -0800256 }
257 spin_unlock(&dcache_lock);
Ian Kent6e60a9a2008-07-23 21:30:27 -0700258follow:
259 /*
260 * If there is no root mount it must be an autofs
261 * multi-mount with no root offset so we don't need
262 * to follow it.
263 */
264 if (d_mountpoint(dentry)) {
Al Viro9393bd02009-04-18 13:58:15 -0400265 if (!autofs4_follow_mount(&nd->path)) {
Ian Kent6e60a9a2008-07-23 21:30:27 -0700266 status = -ENOENT;
267 goto out_error;
268 }
269 }
Ian Kent871f9432006-03-27 01:14:58 -0800270
Ian Kent34ca9592006-03-27 01:14:54 -0800271done:
272 return NULL;
273
274out_error:
Jan Blunck1d957f92008-02-14 19:34:35 -0800275 path_put(&nd->path);
Ian Kent34ca9592006-03-27 01:14:54 -0800276 return ERR_PTR(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
279/*
280 * Revalidate is called on every cache lookup. Some of those
281 * cache lookups may actually happen while the dentry is not
282 * yet completely filled in, and revalidate has to delay such
283 * lookups..
284 */
Ian Kent718c6042006-03-27 01:14:42 -0800285static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Ian Kent718c6042006-03-27 01:14:42 -0800287 struct inode *dir = dentry->d_parent->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
289 int oz_mode = autofs4_oz_mode(sbi);
290 int flags = nd ? nd->flags : 0;
Ian Kentbcdc5e02006-09-27 01:50:44 -0700291 int status = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 /* Pending dentry */
Ian Kent97e74492008-07-23 21:30:26 -0700294 spin_lock(&sbi->fs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (autofs4_ispending(dentry)) {
Ian Kentbcdc5e02006-09-27 01:50:44 -0700296 /* The daemon never causes a mount to trigger */
Ian Kent97e74492008-07-23 21:30:26 -0700297 spin_unlock(&sbi->fs_lock);
298
Ian Kentbcdc5e02006-09-27 01:50:44 -0700299 if (oz_mode)
300 return 1;
301
302 /*
Ian Kent06a35982008-07-23 21:30:28 -0700303 * If the directory has gone away due to an expire
304 * we have been called as ->d_revalidate() and so
305 * we need to return false and proceed to ->lookup().
306 */
307 if (autofs4_expire_wait(dentry) == -EAGAIN)
308 return 0;
309
310 /*
Ian Kentbcdc5e02006-09-27 01:50:44 -0700311 * A zero status is success otherwise we have a
312 * negative error code.
313 */
314 status = try_to_fill_dentry(dentry, flags);
315 if (status == 0)
Ian Kentf50b6f82007-02-20 13:58:10 -0800316 return 1;
317
Ian Kentbcdc5e02006-09-27 01:50:44 -0700318 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
Ian Kent97e74492008-07-23 21:30:26 -0700320 spin_unlock(&sbi->fs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 /* Negative dentry.. invalidate if "old" */
323 if (dentry->d_inode == NULL)
Ian Kent2d753e62006-03-27 01:14:44 -0800324 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 /* Check for a non-mountpoint directory with no contents */
327 spin_lock(&dcache_lock);
328 if (S_ISDIR(dentry->d_inode->i_mode) &&
329 !d_mountpoint(dentry) &&
Ian Kent90a59c72006-03-27 01:14:50 -0800330 __simple_empty(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 DPRINTK("dentry=%p %.*s, emptydir",
332 dentry, dentry->d_name.len, dentry->d_name.name);
333 spin_unlock(&dcache_lock);
Ian Kent97e74492008-07-23 21:30:26 -0700334
Ian Kentbcdc5e02006-09-27 01:50:44 -0700335 /* The daemon never causes a mount to trigger */
336 if (oz_mode)
337 return 1;
338
339 /*
340 * A zero status is success otherwise we have a
341 * negative error code.
342 */
343 status = try_to_fill_dentry(dentry, flags);
344 if (status == 0)
345 return 1;
346
347 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
349 spin_unlock(&dcache_lock);
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 return 1;
352}
353
Ian Kent34ca9592006-03-27 01:14:54 -0800354void autofs4_dentry_release(struct dentry *de)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 struct autofs_info *inf;
357
358 DPRINTK("releasing %p", de);
359
360 inf = autofs4_dentry_ino(de);
361 de->d_fsdata = NULL;
362
363 if (inf) {
Ian Kentf50b6f82007-02-20 13:58:10 -0800364 struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
365
Ian Kentf50b6f82007-02-20 13:58:10 -0800366 if (sbi) {
Ian Kent5f6f4f22008-07-23 21:30:09 -0700367 spin_lock(&sbi->lookup_lock);
Ian Kent25767372008-07-23 21:30:12 -0700368 if (!list_empty(&inf->active))
369 list_del(&inf->active);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700370 if (!list_empty(&inf->expiring))
371 list_del(&inf->expiring);
372 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800373 }
374
Jeff Mahoneyc3724b12007-04-11 23:28:46 -0700375 inf->dentry = NULL;
376 inf->inode = NULL;
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 autofs4_free_ino(inf);
379 }
380}
381
382/* For dentries of directories in the root dir */
Al Viro08f11512009-02-20 05:56:19 +0000383static const struct dentry_operations autofs4_root_dentry_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 .d_revalidate = autofs4_revalidate,
385 .d_release = autofs4_dentry_release,
386};
387
388/* For other dentries */
Al Viro08f11512009-02-20 05:56:19 +0000389static const struct dentry_operations autofs4_dentry_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .d_revalidate = autofs4_revalidate,
391 .d_release = autofs4_dentry_release,
392};
393
Ian Kent25767372008-07-23 21:30:12 -0700394static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
395{
396 unsigned int len = name->len;
397 unsigned int hash = name->hash;
398 const unsigned char *str = name->name;
399 struct list_head *p, *head;
400
401 spin_lock(&dcache_lock);
402 spin_lock(&sbi->lookup_lock);
403 head = &sbi->active_list;
404 list_for_each(p, head) {
405 struct autofs_info *ino;
406 struct dentry *dentry;
407 struct qstr *qstr;
408
409 ino = list_entry(p, struct autofs_info, active);
410 dentry = ino->dentry;
411
412 spin_lock(&dentry->d_lock);
413
414 /* Already gone? */
415 if (atomic_read(&dentry->d_count) == 0)
416 goto next;
417
418 qstr = &dentry->d_name;
419
420 if (dentry->d_name.hash != hash)
421 goto next;
422 if (dentry->d_parent != parent)
423 goto next;
424
425 if (qstr->len != len)
426 goto next;
427 if (memcmp(qstr->name, str, len))
428 goto next;
429
430 if (d_unhashed(dentry)) {
431 dget(dentry);
432 spin_unlock(&dentry->d_lock);
433 spin_unlock(&sbi->lookup_lock);
434 spin_unlock(&dcache_lock);
435 return dentry;
436 }
437next:
438 spin_unlock(&dentry->d_lock);
439 }
440 spin_unlock(&sbi->lookup_lock);
441 spin_unlock(&dcache_lock);
442
443 return NULL;
444}
445
Ian Kent5f6f4f22008-07-23 21:30:09 -0700446static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
Ian Kentf50b6f82007-02-20 13:58:10 -0800447{
448 unsigned int len = name->len;
449 unsigned int hash = name->hash;
450 const unsigned char *str = name->name;
451 struct list_head *p, *head;
452
453 spin_lock(&dcache_lock);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700454 spin_lock(&sbi->lookup_lock);
455 head = &sbi->expiring_list;
Ian Kentf50b6f82007-02-20 13:58:10 -0800456 list_for_each(p, head) {
457 struct autofs_info *ino;
458 struct dentry *dentry;
459 struct qstr *qstr;
460
Ian Kent5f6f4f22008-07-23 21:30:09 -0700461 ino = list_entry(p, struct autofs_info, expiring);
Ian Kentf50b6f82007-02-20 13:58:10 -0800462 dentry = ino->dentry;
463
464 spin_lock(&dentry->d_lock);
465
466 /* Bad luck, we've already been dentry_iput */
467 if (!dentry->d_inode)
468 goto next;
469
470 qstr = &dentry->d_name;
471
472 if (dentry->d_name.hash != hash)
473 goto next;
474 if (dentry->d_parent != parent)
475 goto next;
476
477 if (qstr->len != len)
478 goto next;
479 if (memcmp(qstr->name, str, len))
480 goto next;
481
482 if (d_unhashed(dentry)) {
Ian Kentf50b6f82007-02-20 13:58:10 -0800483 dget(dentry);
Ian Kentf50b6f82007-02-20 13:58:10 -0800484 spin_unlock(&dentry->d_lock);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700485 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800486 spin_unlock(&dcache_lock);
487 return dentry;
488 }
489next:
490 spin_unlock(&dentry->d_lock);
491 }
Ian Kent5f6f4f22008-07-23 21:30:09 -0700492 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800493 spin_unlock(&dcache_lock);
494
495 return NULL;
496}
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498/* Lookups in the root directory */
499static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
500{
501 struct autofs_sb_info *sbi;
Ian Kent25767372008-07-23 21:30:12 -0700502 struct autofs_info *ino;
503 struct dentry *expiring, *unhashed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 int oz_mode;
505
506 DPRINTK("name = %.*s",
507 dentry->d_name.len, dentry->d_name.name);
508
Ian Kent718c6042006-03-27 01:14:42 -0800509 /* File name too long to exist */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 if (dentry->d_name.len > NAME_MAX)
Ian Kent718c6042006-03-27 01:14:42 -0800511 return ERR_PTR(-ENAMETOOLONG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 sbi = autofs4_sbi(dir->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 oz_mode = autofs4_oz_mode(sbi);
Ian Kent718c6042006-03-27 01:14:42 -0800515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
Pavel Emelianova47afb02007-10-18 23:39:46 -0700517 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Ian Kent25767372008-07-23 21:30:12 -0700519 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
520 if (unhashed)
521 dentry = unhashed;
522 else {
523 /*
524 * Mark the dentry incomplete but don't hash it. We do this
525 * to serialize our inode creation operations (symlink and
526 * mkdir) which prevents deadlock during the callback to
527 * the daemon. Subsequent user space lookups for the same
528 * dentry are placed on the wait queue while the daemon
529 * itself is allowed passage unresticted so the create
530 * operation itself can then hash the dentry. Finally,
531 * we check for the hashed dentry and return the newly
532 * hashed dentry.
533 */
534 dentry->d_op = &autofs4_root_dentry_operations;
Ian Kent5f6f4f22008-07-23 21:30:09 -0700535
Ian Kent25767372008-07-23 21:30:12 -0700536 /*
537 * And we need to ensure that the same dentry is used for
538 * all following lookup calls until it is hashed so that
539 * the dentry flags are persistent throughout the request.
540 */
541 ino = autofs4_init_ino(NULL, sbi, 0555);
542 if (!ino)
543 return ERR_PTR(-ENOMEM);
544
545 dentry->d_fsdata = ino;
546 ino->dentry = dentry;
547
Ian Kent4f8427d2009-12-15 16:45:42 -0800548 autofs4_add_active(dentry);
Ian Kent25767372008-07-23 21:30:12 -0700549
550 d_instantiate(dentry, NULL);
551 }
Ian Kent5f6f4f22008-07-23 21:30:09 -0700552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (!oz_mode) {
Ian Kent8f63aaa8b2009-03-31 15:24:45 -0700554 mutex_unlock(&dir->i_mutex);
555 expiring = autofs4_lookup_expiring(sbi,
556 dentry->d_parent,
557 &dentry->d_name);
558 if (expiring) {
559 /*
560 * If we are racing with expire the request might not
561 * be quite complete but the directory has been removed
562 * so it must have been successful, so just wait for it.
563 */
564 ino = autofs4_dentry_ino(expiring);
565 autofs4_expire_wait(expiring);
Ian Kentc4cd70b2009-12-15 16:45:43 -0800566 autofs4_del_expiring(expiring);
Ian Kent8f63aaa8b2009-03-31 15:24:45 -0700567 dput(expiring);
568 }
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 spin_lock(&dentry->d_lock);
571 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
572 spin_unlock(&dentry->d_lock);
Ian Kent8f63aaa8b2009-03-31 15:24:45 -0700573 if (dentry->d_op && dentry->d_op->d_revalidate)
Ian Kentc432c252008-07-23 21:30:14 -0700574 (dentry->d_op->d_revalidate)(dentry, nd);
Ian Kent8f63aaa8b2009-03-31 15:24:45 -0700575 mutex_lock(&dir->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 }
577
578 /*
579 * If we are still pending, check if we had to handle
580 * a signal. If so we can force a restart..
581 */
582 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
583 /* See if we were interrupted */
584 if (signal_pending(current)) {
585 sigset_t *sigset = &current->pending.signal;
586 if (sigismember (sigset, SIGKILL) ||
587 sigismember (sigset, SIGQUIT) ||
588 sigismember (sigset, SIGINT)) {
Ian Kent25767372008-07-23 21:30:12 -0700589 if (unhashed)
590 dput(unhashed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 return ERR_PTR(-ERESTARTNOINTR);
592 }
593 }
Ian Kent25767372008-07-23 21:30:12 -0700594 if (!oz_mode) {
595 spin_lock(&dentry->d_lock);
596 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
597 spin_unlock(&dentry->d_lock);
598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
600
601 /*
602 * If this dentry is unhashed, then we shouldn't honour this
Ian Kentc9ffec42007-02-20 13:58:10 -0800603 * lookup. Returning ENOENT here doesn't do the right thing
604 * for all system calls, but it should be OK for the operations
605 * we permit from an autofs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 */
Ian Kent1864f7b2007-08-22 14:01:54 -0700607 if (!oz_mode && d_unhashed(dentry)) {
Ian Kentc9ffec42007-02-20 13:58:10 -0800608 /*
609 * A user space application can (and has done in the past)
610 * remove and re-create this directory during the callback.
611 * This can leave us with an unhashed dentry, but a
612 * successful mount! So we need to perform another
613 * cached lookup in case the dentry now exists.
614 */
615 struct dentry *parent = dentry->d_parent;
616 struct dentry *new = d_lookup(parent, &dentry->d_name);
617 if (new != NULL)
618 dentry = new;
619 else
620 dentry = ERR_PTR(-ENOENT);
621
Ian Kent25767372008-07-23 21:30:12 -0700622 if (unhashed)
623 dput(unhashed);
624
Ian Kentc9ffec42007-02-20 13:58:10 -0800625 return dentry;
Ian Kentf50b6f82007-02-20 13:58:10 -0800626 }
627
Ian Kent25767372008-07-23 21:30:12 -0700628 if (unhashed)
629 return unhashed;
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 return NULL;
632}
633
634static int autofs4_dir_symlink(struct inode *dir,
635 struct dentry *dentry,
636 const char *symname)
637{
638 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
639 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800640 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 struct inode *inode;
642 char *cp;
643
644 DPRINTK("%s <- %.*s", symname,
645 dentry->d_name.len, dentry->d_name.name);
646
647 if (!autofs4_oz_mode(sbi))
648 return -EACCES;
649
650 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
Ian Kent25767372008-07-23 21:30:12 -0700651 if (!ino)
652 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Ian Kent4f8427d2009-12-15 16:45:42 -0800654 autofs4_del_active(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Ian Kentef581a72008-07-23 21:30:13 -0700656 ino->size = strlen(symname);
Ian Kent25767372008-07-23 21:30:12 -0700657 cp = kmalloc(ino->size + 1, GFP_KERNEL);
658 if (!cp) {
659 if (!dentry->d_fsdata)
660 kfree(ino);
661 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
663
664 strcpy(cp, symname);
665
666 inode = autofs4_get_inode(dir->i_sb, ino);
Ian Kent25767372008-07-23 21:30:12 -0700667 if (!inode) {
668 kfree(cp);
669 if (!dentry->d_fsdata)
670 kfree(ino);
671 return -ENOMEM;
672 }
Ian Kent1864f7b2007-08-22 14:01:54 -0700673 d_add(dentry, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675 if (dir == dir->i_sb->s_root->d_inode)
676 dentry->d_op = &autofs4_root_dentry_operations;
677 else
678 dentry->d_op = &autofs4_dentry_operations;
679
680 dentry->d_fsdata = ino;
681 ino->dentry = dget(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800682 atomic_inc(&ino->count);
683 p_ino = autofs4_dentry_ino(dentry->d_parent);
684 if (p_ino && dentry->d_parent != dentry)
685 atomic_inc(&p_ino->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 ino->inode = inode;
687
Ian Kent25767372008-07-23 21:30:12 -0700688 ino->u.symlink = cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 dir->i_mtime = CURRENT_TIME;
690
691 return 0;
692}
693
694/*
695 * NOTE!
696 *
697 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
698 * that the file no longer exists. However, doing that means that the
699 * VFS layer can turn the dentry into a negative dentry. We don't want
Ian Kentf50b6f82007-02-20 13:58:10 -0800700 * this, because the unlink is probably the result of an expire.
Ian Kent5f6f4f22008-07-23 21:30:09 -0700701 * We simply d_drop it and add it to a expiring list in the super block,
702 * which allows the dentry lookup to check for an incomplete expire.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 *
704 * If a process is blocked on the dentry waiting for the expire to finish,
705 * it will invalidate the dentry and try to mount with a new one.
706 *
707 * Also see autofs4_dir_rmdir()..
708 */
709static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
710{
711 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
712 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800713 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 /* This allows root to remove symlinks */
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700716 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 return -EACCES;
718
Ian Kent1aff3c82006-03-27 01:14:46 -0800719 if (atomic_dec_and_test(&ino->count)) {
720 p_ino = autofs4_dentry_ino(dentry->d_parent);
721 if (p_ino && dentry->d_parent != dentry)
722 atomic_dec(&p_ino->count);
723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 dput(ino->dentry);
725
726 dentry->d_inode->i_size = 0;
Dave Hansence71ec32006-09-30 23:29:06 -0700727 clear_nlink(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729 dir->i_mtime = CURRENT_TIME;
730
Ian Kentf50b6f82007-02-20 13:58:10 -0800731 spin_lock(&dcache_lock);
Ian Kentc4cd70b2009-12-15 16:45:43 -0800732 autofs4_add_expiring(dentry);
Ian Kentf50b6f82007-02-20 13:58:10 -0800733 spin_lock(&dentry->d_lock);
734 __d_drop(dentry);
735 spin_unlock(&dentry->d_lock);
736 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 return 0;
739}
740
741static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
742{
743 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
744 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800745 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Ian Kentf50b6f82007-02-20 13:58:10 -0800747 DPRINTK("dentry %p, removing %.*s",
748 dentry, dentry->d_name.len, dentry->d_name.name);
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 if (!autofs4_oz_mode(sbi))
751 return -EACCES;
752
753 spin_lock(&dcache_lock);
754 if (!list_empty(&dentry->d_subdirs)) {
755 spin_unlock(&dcache_lock);
756 return -ENOTEMPTY;
757 }
Ian Kentc4cd70b2009-12-15 16:45:43 -0800758 autofs4_add_expiring(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 spin_lock(&dentry->d_lock);
760 __d_drop(dentry);
761 spin_unlock(&dentry->d_lock);
762 spin_unlock(&dcache_lock);
763
Ian Kent1aff3c82006-03-27 01:14:46 -0800764 if (atomic_dec_and_test(&ino->count)) {
765 p_ino = autofs4_dentry_ino(dentry->d_parent);
766 if (p_ino && dentry->d_parent != dentry)
767 atomic_dec(&p_ino->count);
768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 dput(ino->dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 dentry->d_inode->i_size = 0;
Dave Hansence71ec32006-09-30 23:29:06 -0700771 clear_nlink(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 if (dir->i_nlink)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700774 drop_nlink(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 return 0;
777}
778
779static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
780{
781 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
782 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800783 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 struct inode *inode;
785
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700786 if (!autofs4_oz_mode(sbi))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 return -EACCES;
788
789 DPRINTK("dentry %p, creating %.*s",
790 dentry, dentry->d_name.len, dentry->d_name.name);
791
792 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
Ian Kent25767372008-07-23 21:30:12 -0700793 if (!ino)
794 return -ENOMEM;
795
Ian Kent4f8427d2009-12-15 16:45:42 -0800796 autofs4_del_active(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 inode = autofs4_get_inode(dir->i_sb, ino);
Ian Kent25767372008-07-23 21:30:12 -0700799 if (!inode) {
800 if (!dentry->d_fsdata)
801 kfree(ino);
802 return -ENOMEM;
803 }
Ian Kent1864f7b2007-08-22 14:01:54 -0700804 d_add(dentry, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 if (dir == dir->i_sb->s_root->d_inode)
807 dentry->d_op = &autofs4_root_dentry_operations;
808 else
809 dentry->d_op = &autofs4_dentry_operations;
810
811 dentry->d_fsdata = ino;
812 ino->dentry = dget(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800813 atomic_inc(&ino->count);
814 p_ino = autofs4_dentry_ino(dentry->d_parent);
815 if (p_ino && dentry->d_parent != dentry)
816 atomic_inc(&p_ino->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 ino->inode = inode;
Dave Hansend8c76e62006-09-30 23:29:04 -0700818 inc_nlink(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 dir->i_mtime = CURRENT_TIME;
820
821 return 0;
822}
823
824/* Get/set timeout ioctl() operation */
825static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
826 unsigned long __user *p)
827{
828 int rv;
829 unsigned long ntimeout;
830
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700831 if ((rv = get_user(ntimeout, p)) ||
832 (rv = put_user(sbi->exp_timeout/HZ, p)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 return rv;
834
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700835 if (ntimeout > ULONG_MAX/HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 sbi->exp_timeout = 0;
837 else
838 sbi->exp_timeout = ntimeout * HZ;
839
840 return 0;
841}
842
843/* Return protocol version */
844static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
845{
846 return put_user(sbi->version, p);
847}
848
849/* Return protocol sub version */
850static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
851{
852 return put_user(sbi->sub_version, p);
853}
854
855/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856* Tells the daemon whether it can umount the autofs mount.
857*/
858static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
859{
860 int status = 0;
861
Ian Kente3474a82006-03-27 01:14:51 -0800862 if (may_umount(mnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 status = 1;
864
865 DPRINTK("returning %d", status);
866
867 status = put_user(status, p);
868
869 return status;
870}
871
872/* Identify autofs4_dentries - this is so we can tell if there's
873 an extra dentry refcount or not. We only hold a refcount on the
874 dentry if its non-negative (ie, d_inode != NULL)
875*/
876int is_autofs4_dentry(struct dentry *dentry)
877{
878 return dentry && dentry->d_inode &&
879 (dentry->d_op == &autofs4_root_dentry_operations ||
880 dentry->d_op == &autofs4_dentry_operations) &&
881 dentry->d_fsdata != NULL;
882}
883
884/*
885 * ioctl()'s on the root directory is the chief method for the daemon to
886 * generate kernel reactions
887 */
888static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
889 unsigned int cmd, unsigned long arg)
890{
891 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
892 void __user *p = (void __user *)arg;
893
894 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
Pavel Emelianova47afb02007-10-18 23:39:46 -0700895 cmd,arg,sbi,task_pgrp_nr(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700897 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
898 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 return -ENOTTY;
900
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700901 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 return -EPERM;
903
904 switch(cmd) {
905 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
906 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
907 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
908 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
909 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
910 autofs4_catatonic_mode(sbi);
911 return 0;
912 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
913 return autofs4_get_protover(sbi, p);
914 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
915 return autofs4_get_protosubver(sbi, p);
916 case AUTOFS_IOC_SETTIMEOUT:
917 return autofs4_get_set_timeout(sbi, p);
918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 case AUTOFS_IOC_ASKUMOUNT:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800920 return autofs4_ask_umount(filp->f_path.mnt, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 /* return a single thing to expire */
923 case AUTOFS_IOC_EXPIRE:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800924 return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 /* same as above, but can send multiple expires through pipe */
926 case AUTOFS_IOC_EXPIRE_MULTI:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800927 return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 default:
930 return -ENOSYS;
931 }
932}