blob: 51c873ca8e8d8e51a7bfa445e2251c3ceb5c6c4a [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 int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
29static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
Ian Kent34ca9592006-03-27 01:14:54 -080030static void *autofs4_follow_link(struct dentry *, struct nameidata *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ian Kent6d5cb922008-07-23 21:30:15 -070032#define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
33#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
34
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080035const struct file_operations autofs4_root_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 .open = dcache_dir_open,
37 .release = dcache_dir_close,
38 .read = generic_read_dir,
39 .readdir = autofs4_root_readdir,
40 .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,
Linus Torvalds1da177e2005-04-16 15:20:36 -070048};
49
Arjan van de Ven754661f2007-02-12 00:55:38 -080050const struct inode_operations autofs4_indirect_root_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 .lookup = autofs4_lookup,
52 .unlink = autofs4_dir_unlink,
53 .symlink = autofs4_dir_symlink,
54 .mkdir = autofs4_dir_mkdir,
55 .rmdir = autofs4_dir_rmdir,
56};
57
Arjan van de Ven754661f2007-02-12 00:55:38 -080058const struct inode_operations autofs4_direct_root_inode_operations = {
Ian Kent34ca9592006-03-27 01:14:54 -080059 .lookup = autofs4_lookup,
Ian Kent871f9432006-03-27 01:14:58 -080060 .unlink = autofs4_dir_unlink,
61 .mkdir = autofs4_dir_mkdir,
62 .rmdir = autofs4_dir_rmdir,
Ian Kent34ca9592006-03-27 01:14:54 -080063 .follow_link = autofs4_follow_link,
64};
65
Arjan van de Ven754661f2007-02-12 00:55:38 -080066const struct inode_operations autofs4_dir_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 .lookup = autofs4_lookup,
68 .unlink = autofs4_dir_unlink,
69 .symlink = autofs4_dir_symlink,
70 .mkdir = autofs4_dir_mkdir,
71 .rmdir = autofs4_dir_rmdir,
72};
73
74static int autofs4_root_readdir(struct file *file, void *dirent,
75 filldir_t filldir)
76{
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -080077 struct autofs_sb_info *sbi = autofs4_sbi(file->f_path.dentry->d_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 int oz_mode = autofs4_oz_mode(sbi);
79
80 DPRINTK("called, filp->f_pos = %lld", file->f_pos);
81
82 /*
83 * Don't set reghost flag if:
84 * 1) f_pos is larger than zero -- we've already been here.
85 * 2) we haven't even enabled reghosting in the 1st place.
86 * 3) this is the daemon doing a readdir
87 */
88 if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
89 sbi->needs_reghost = 1;
90
91 DPRINTK("needs_reghost = %d", sbi->needs_reghost);
92
Ian Kentf360ce32006-03-27 01:14:43 -080093 return dcache_readdir(file, dirent, filldir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static int autofs4_dir_open(struct inode *inode, struct file *file)
97{
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -080098 struct dentry *dentry = file->f_path.dentry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kentf360ce32006-03-27 01:14:43 -0800100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 DPRINTK("file=%p dentry=%p %.*s",
102 file, dentry, dentry->d_name.len, dentry->d_name.name);
103
104 if (autofs4_oz_mode(sbi))
105 goto out;
106
Ian Kentff9cd492008-07-23 21:30:24 -0700107 /*
108 * An empty directory in an autofs file system is always a
109 * mount point. The daemon must have failed to mount this
110 * during lookup so it doesn't exist. This can happen, for
111 * example, if user space returns an incorrect status for a
112 * mount request. Otherwise we're doing a readdir on the
113 * autofs file system so just let the libfs routines handle
114 * it.
115 */
116 spin_lock(&dcache_lock);
117 if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 spin_unlock(&dcache_lock);
Ian Kentff9cd492008-07-23 21:30:24 -0700119 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
Ian Kentff9cd492008-07-23 21:30:24 -0700121 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Ian Kentf360ce32006-03-27 01:14:43 -0800123out:
Ian Kentff9cd492008-07-23 21:30:24 -0700124 return dcache_dir_open(inode, file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
Ian Kent862b1102006-03-27 01:14:48 -0800127static int try_to_fill_dentry(struct dentry *dentry, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Ian Kent862b1102006-03-27 01:14:48 -0800129 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kent718c6042006-03-27 01:14:42 -0800130 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Jeff Moyer9d2de6a2008-05-01 04:35:09 -0700131 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 /* Block on any pending expiry here; invalidate the dentry
134 when expiration is done to trigger mount request with a new
135 dentry */
Ian Kent718c6042006-03-27 01:14:42 -0800136 if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 DPRINTK("waiting for expire %p name=%.*s",
138 dentry, dentry->d_name.len, dentry->d_name.name);
139
140 status = autofs4_wait(sbi, dentry, NFY_NONE);
Ian Kent718c6042006-03-27 01:14:42 -0800141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 DPRINTK("expire done status=%d", status);
Ian Kent718c6042006-03-27 01:14:42 -0800143
Ian Kent1684b2b2005-06-21 17:16:41 -0700144 /*
145 * If the directory still exists the mount request must
146 * continue otherwise it can't be followed at the right
147 * time during the walk.
148 */
149 status = d_invalidate(dentry);
150 if (status != -EBUSY)
Ian Kentf50b6f82007-02-20 13:58:10 -0800151 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153
154 DPRINTK("dentry=%p %.*s ino=%p",
155 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
156
Ian Kent718c6042006-03-27 01:14:42 -0800157 /*
158 * Wait for a pending mount, triggering one if there
159 * isn't one already
160 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 if (dentry->d_inode == NULL) {
162 DPRINTK("waiting for mount name=%.*s",
163 dentry->d_name.len, dentry->d_name.name);
164
165 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
Ian Kent718c6042006-03-27 01:14:42 -0800166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 DPRINTK("mount done status=%d", status);
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 /* Turn this into a real negative dentry? */
170 if (status == -ENOENT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 spin_lock(&dentry->d_lock);
172 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
173 spin_unlock(&dentry->d_lock);
Ian Kent34ca9592006-03-27 01:14:54 -0800174 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 } else if (status) {
176 /* Return a negative dentry, but leave it "pending" */
Ian Kent34ca9592006-03-27 01:14:54 -0800177 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
179 /* Trigger mount for path component or follow link */
Ian Kent6d5cb922008-07-23 21:30:15 -0700180 } else if (flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 current->link_count) {
182 DPRINTK("waiting for mount name=%.*s",
183 dentry->d_name.len, dentry->d_name.name);
184
185 spin_lock(&dentry->d_lock);
186 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
187 spin_unlock(&dentry->d_lock);
188 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
189
190 DPRINTK("mount done status=%d", status);
191
192 if (status) {
193 spin_lock(&dentry->d_lock);
194 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
195 spin_unlock(&dentry->d_lock);
Ian Kent34ca9592006-03-27 01:14:54 -0800196 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198 }
199
Ian Kente0a7aae2006-03-27 01:14:47 -0800200 /* Initialize expiry counter after successful mount */
201 if (ino)
202 ino->last_used = jiffies;
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 spin_lock(&dentry->d_lock);
205 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
206 spin_unlock(&dentry->d_lock);
Jeff Moyer03379042008-05-01 04:35:08 -0700207
Jeff Moyer9d2de6a2008-05-01 04:35:09 -0700208 return 0;
Ian Kent34ca9592006-03-27 01:14:54 -0800209}
210
211/* For autofs direct mounts the follow link triggers the mount */
212static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
213{
214 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
Ian Kenta5370552006-05-15 09:43:51 -0700215 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent34ca9592006-03-27 01:14:54 -0800216 int oz_mode = autofs4_oz_mode(sbi);
217 unsigned int lookup_type;
218 int status;
219
220 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
221 dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
222 nd->flags);
223
224 /* If it's our master or we shouldn't trigger a mount we're done */
Ian Kent6d5cb922008-07-23 21:30:15 -0700225 lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
Ian Kent34ca9592006-03-27 01:14:54 -0800226 if (oz_mode || !lookup_type)
227 goto done;
228
Ian Kenta5370552006-05-15 09:43:51 -0700229 /* If an expire request is pending wait for it. */
230 if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
Ian Kent871f9432006-03-27 01:14:58 -0800231 DPRINTK("waiting for active request %p name=%.*s",
232 dentry, dentry->d_name.len, dentry->d_name.name);
Ian Kent34ca9592006-03-27 01:14:54 -0800233
Ian Kent871f9432006-03-27 01:14:58 -0800234 status = autofs4_wait(sbi, dentry, NFY_NONE);
235
236 DPRINTK("request done status=%d", status);
Ian Kent34ca9592006-03-27 01:14:54 -0800237 }
238
Ian Kent871f9432006-03-27 01:14:58 -0800239 /*
240 * If the dentry contains directories then it is an
241 * autofs multi-mount with no root mount offset. So
242 * don't try to mount it again.
243 */
244 spin_lock(&dcache_lock);
Ian Kentbe3ca7f2006-09-29 02:00:53 -0700245 if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
Ian Kent871f9432006-03-27 01:14:58 -0800246 spin_unlock(&dcache_lock);
247
248 status = try_to_fill_dentry(dentry, 0);
249 if (status)
250 goto out_error;
251
252 /*
253 * The mount succeeded but if there is no root mount
254 * it must be an autofs multi-mount with no root offset
255 * so we don't need to follow the mount.
256 */
257 if (d_mountpoint(dentry)) {
Jan Blunck4ac91372008-02-14 19:34:32 -0800258 if (!autofs4_follow_mount(&nd->path.mnt,
259 &nd->path.dentry)) {
Ian Kent871f9432006-03-27 01:14:58 -0800260 status = -ENOENT;
261 goto out_error;
262 }
263 }
264
265 goto done;
266 }
267 spin_unlock(&dcache_lock);
268
Ian Kent34ca9592006-03-27 01:14:54 -0800269done:
270 return NULL;
271
272out_error:
Jan Blunck1d957f92008-02-14 19:34:35 -0800273 path_put(&nd->path);
Ian Kent34ca9592006-03-27 01:14:54 -0800274 return ERR_PTR(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
277/*
278 * Revalidate is called on every cache lookup. Some of those
279 * cache lookups may actually happen while the dentry is not
280 * yet completely filled in, and revalidate has to delay such
281 * lookups..
282 */
Ian Kent718c6042006-03-27 01:14:42 -0800283static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Ian Kent718c6042006-03-27 01:14:42 -0800285 struct inode *dir = dentry->d_parent->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
287 int oz_mode = autofs4_oz_mode(sbi);
288 int flags = nd ? nd->flags : 0;
Ian Kentbcdc5e02006-09-27 01:50:44 -0700289 int status = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 /* Pending dentry */
292 if (autofs4_ispending(dentry)) {
Ian Kentbcdc5e02006-09-27 01:50:44 -0700293 /* The daemon never causes a mount to trigger */
294 if (oz_mode)
295 return 1;
296
297 /*
298 * A zero status is success otherwise we have a
299 * negative error code.
300 */
301 status = try_to_fill_dentry(dentry, flags);
302 if (status == 0)
Ian Kentf50b6f82007-02-20 13:58:10 -0800303 return 1;
304
305 /*
306 * A status of EAGAIN here means that the dentry has gone
307 * away while waiting for an expire to complete. If we are
308 * racing with expire lookup will wait for it so this must
309 * be a revalidate and we need to send it to lookup.
310 */
311 if (status == -EAGAIN)
312 return 0;
Ian Kentbcdc5e02006-09-27 01:50:44 -0700313
314 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316
317 /* Negative dentry.. invalidate if "old" */
318 if (dentry->d_inode == NULL)
Ian Kent2d753e62006-03-27 01:14:44 -0800319 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 /* Check for a non-mountpoint directory with no contents */
322 spin_lock(&dcache_lock);
323 if (S_ISDIR(dentry->d_inode->i_mode) &&
324 !d_mountpoint(dentry) &&
Ian Kent90a59c72006-03-27 01:14:50 -0800325 __simple_empty(dentry)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 DPRINTK("dentry=%p %.*s, emptydir",
327 dentry, dentry->d_name.len, dentry->d_name.name);
328 spin_unlock(&dcache_lock);
Ian Kentbcdc5e02006-09-27 01:50:44 -0700329 /* The daemon never causes a mount to trigger */
330 if (oz_mode)
331 return 1;
332
333 /*
334 * A zero status is success otherwise we have a
335 * negative error code.
336 */
337 status = try_to_fill_dentry(dentry, flags);
338 if (status == 0)
339 return 1;
340
341 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
343 spin_unlock(&dcache_lock);
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 return 1;
346}
347
Ian Kent34ca9592006-03-27 01:14:54 -0800348void autofs4_dentry_release(struct dentry *de)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
350 struct autofs_info *inf;
351
352 DPRINTK("releasing %p", de);
353
354 inf = autofs4_dentry_ino(de);
355 de->d_fsdata = NULL;
356
357 if (inf) {
Ian Kentf50b6f82007-02-20 13:58:10 -0800358 struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
359
Ian Kentf50b6f82007-02-20 13:58:10 -0800360 if (sbi) {
Ian Kent5f6f4f22008-07-23 21:30:09 -0700361 spin_lock(&sbi->lookup_lock);
Ian Kent25767372008-07-23 21:30:12 -0700362 if (!list_empty(&inf->active))
363 list_del(&inf->active);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700364 if (!list_empty(&inf->expiring))
365 list_del(&inf->expiring);
366 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800367 }
368
Jeff Mahoneyc3724b12007-04-11 23:28:46 -0700369 inf->dentry = NULL;
370 inf->inode = NULL;
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 autofs4_free_ino(inf);
373 }
374}
375
376/* For dentries of directories in the root dir */
377static struct dentry_operations autofs4_root_dentry_operations = {
378 .d_revalidate = autofs4_revalidate,
379 .d_release = autofs4_dentry_release,
380};
381
382/* For other dentries */
383static struct dentry_operations autofs4_dentry_operations = {
384 .d_revalidate = autofs4_revalidate,
385 .d_release = autofs4_dentry_release,
386};
387
Ian Kent25767372008-07-23 21:30:12 -0700388static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
389{
390 unsigned int len = name->len;
391 unsigned int hash = name->hash;
392 const unsigned char *str = name->name;
393 struct list_head *p, *head;
394
395 spin_lock(&dcache_lock);
396 spin_lock(&sbi->lookup_lock);
397 head = &sbi->active_list;
398 list_for_each(p, head) {
399 struct autofs_info *ino;
400 struct dentry *dentry;
401 struct qstr *qstr;
402
403 ino = list_entry(p, struct autofs_info, active);
404 dentry = ino->dentry;
405
406 spin_lock(&dentry->d_lock);
407
408 /* Already gone? */
409 if (atomic_read(&dentry->d_count) == 0)
410 goto next;
411
412 qstr = &dentry->d_name;
413
414 if (dentry->d_name.hash != hash)
415 goto next;
416 if (dentry->d_parent != parent)
417 goto next;
418
419 if (qstr->len != len)
420 goto next;
421 if (memcmp(qstr->name, str, len))
422 goto next;
423
424 if (d_unhashed(dentry)) {
425 dget(dentry);
426 spin_unlock(&dentry->d_lock);
427 spin_unlock(&sbi->lookup_lock);
428 spin_unlock(&dcache_lock);
429 return dentry;
430 }
431next:
432 spin_unlock(&dentry->d_lock);
433 }
434 spin_unlock(&sbi->lookup_lock);
435 spin_unlock(&dcache_lock);
436
437 return NULL;
438}
439
Ian Kent5f6f4f22008-07-23 21:30:09 -0700440static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
Ian Kentf50b6f82007-02-20 13:58:10 -0800441{
442 unsigned int len = name->len;
443 unsigned int hash = name->hash;
444 const unsigned char *str = name->name;
445 struct list_head *p, *head;
446
447 spin_lock(&dcache_lock);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700448 spin_lock(&sbi->lookup_lock);
449 head = &sbi->expiring_list;
Ian Kentf50b6f82007-02-20 13:58:10 -0800450 list_for_each(p, head) {
451 struct autofs_info *ino;
452 struct dentry *dentry;
453 struct qstr *qstr;
454
Ian Kent5f6f4f22008-07-23 21:30:09 -0700455 ino = list_entry(p, struct autofs_info, expiring);
Ian Kentf50b6f82007-02-20 13:58:10 -0800456 dentry = ino->dentry;
457
458 spin_lock(&dentry->d_lock);
459
460 /* Bad luck, we've already been dentry_iput */
461 if (!dentry->d_inode)
462 goto next;
463
464 qstr = &dentry->d_name;
465
466 if (dentry->d_name.hash != hash)
467 goto next;
468 if (dentry->d_parent != parent)
469 goto next;
470
471 if (qstr->len != len)
472 goto next;
473 if (memcmp(qstr->name, str, len))
474 goto next;
475
476 if (d_unhashed(dentry)) {
Ian Kentf50b6f82007-02-20 13:58:10 -0800477 dget(dentry);
Ian Kentf50b6f82007-02-20 13:58:10 -0800478 spin_unlock(&dentry->d_lock);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700479 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800480 spin_unlock(&dcache_lock);
481 return dentry;
482 }
483next:
484 spin_unlock(&dentry->d_lock);
485 }
Ian Kent5f6f4f22008-07-23 21:30:09 -0700486 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800487 spin_unlock(&dcache_lock);
488
489 return NULL;
490}
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492/* Lookups in the root directory */
493static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
494{
495 struct autofs_sb_info *sbi;
Ian Kent25767372008-07-23 21:30:12 -0700496 struct autofs_info *ino;
497 struct dentry *expiring, *unhashed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 int oz_mode;
499
500 DPRINTK("name = %.*s",
501 dentry->d_name.len, dentry->d_name.name);
502
Ian Kent718c6042006-03-27 01:14:42 -0800503 /* File name too long to exist */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (dentry->d_name.len > NAME_MAX)
Ian Kent718c6042006-03-27 01:14:42 -0800505 return ERR_PTR(-ENAMETOOLONG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 sbi = autofs4_sbi(dir->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 oz_mode = autofs4_oz_mode(sbi);
Ian Kent718c6042006-03-27 01:14:42 -0800509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
Pavel Emelianova47afb02007-10-18 23:39:46 -0700511 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Ian Kent5f6f4f22008-07-23 21:30:09 -0700513 expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
514 if (expiring) {
Ian Kentf50b6f82007-02-20 13:58:10 -0800515 /*
516 * If we are racing with expire the request might not
517 * be quite complete but the directory has been removed
518 * so it must have been successful, so just wait for it.
519 */
Ian Kent25767372008-07-23 21:30:12 -0700520 ino = autofs4_dentry_ino(expiring);
Ian Kent1864f7b2007-08-22 14:01:54 -0700521 while (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
Ian Kentf50b6f82007-02-20 13:58:10 -0800522 DPRINTK("wait for incomplete expire %p name=%.*s",
Ian Kent5f6f4f22008-07-23 21:30:09 -0700523 expiring, expiring->d_name.len,
524 expiring->d_name.name);
525 autofs4_wait(sbi, expiring, NFY_NONE);
Ian Kentf50b6f82007-02-20 13:58:10 -0800526 DPRINTK("request completed");
527 }
Ian Kent5f6f4f22008-07-23 21:30:09 -0700528 spin_lock(&sbi->lookup_lock);
529 if (!list_empty(&ino->expiring))
530 list_del_init(&ino->expiring);
531 spin_unlock(&sbi->lookup_lock);
532 dput(expiring);
Ian Kentf50b6f82007-02-20 13:58:10 -0800533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Ian Kent25767372008-07-23 21:30:12 -0700535 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
536 if (unhashed)
537 dentry = unhashed;
538 else {
539 /*
540 * Mark the dentry incomplete but don't hash it. We do this
541 * to serialize our inode creation operations (symlink and
542 * mkdir) which prevents deadlock during the callback to
543 * the daemon. Subsequent user space lookups for the same
544 * dentry are placed on the wait queue while the daemon
545 * itself is allowed passage unresticted so the create
546 * operation itself can then hash the dentry. Finally,
547 * we check for the hashed dentry and return the newly
548 * hashed dentry.
549 */
550 dentry->d_op = &autofs4_root_dentry_operations;
Ian Kent5f6f4f22008-07-23 21:30:09 -0700551
Ian Kent25767372008-07-23 21:30:12 -0700552 /*
553 * And we need to ensure that the same dentry is used for
554 * all following lookup calls until it is hashed so that
555 * the dentry flags are persistent throughout the request.
556 */
557 ino = autofs4_init_ino(NULL, sbi, 0555);
558 if (!ino)
559 return ERR_PTR(-ENOMEM);
560
561 dentry->d_fsdata = ino;
562 ino->dentry = dentry;
563
564 spin_lock(&sbi->lookup_lock);
565 list_add(&ino->active, &sbi->active_list);
566 spin_unlock(&sbi->lookup_lock);
567
568 d_instantiate(dentry, NULL);
569 }
Ian Kent5f6f4f22008-07-23 21:30:09 -0700570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (!oz_mode) {
572 spin_lock(&dentry->d_lock);
573 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
574 spin_unlock(&dentry->d_lock);
Ian Kentc432c252008-07-23 21:30:14 -0700575 if (dentry->d_op && dentry->d_op->d_revalidate) {
576 mutex_unlock(&dir->i_mutex);
577 (dentry->d_op->d_revalidate)(dentry, nd);
578 mutex_lock(&dir->i_mutex);
579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 }
581
582 /*
583 * If we are still pending, check if we had to handle
584 * a signal. If so we can force a restart..
585 */
586 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
587 /* See if we were interrupted */
588 if (signal_pending(current)) {
589 sigset_t *sigset = &current->pending.signal;
590 if (sigismember (sigset, SIGKILL) ||
591 sigismember (sigset, SIGQUIT) ||
592 sigismember (sigset, SIGINT)) {
Ian Kent25767372008-07-23 21:30:12 -0700593 if (unhashed)
594 dput(unhashed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 return ERR_PTR(-ERESTARTNOINTR);
596 }
597 }
Ian Kent25767372008-07-23 21:30:12 -0700598 if (!oz_mode) {
599 spin_lock(&dentry->d_lock);
600 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
601 spin_unlock(&dentry->d_lock);
602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
604
605 /*
606 * If this dentry is unhashed, then we shouldn't honour this
Ian Kentc9ffec42007-02-20 13:58:10 -0800607 * lookup. Returning ENOENT here doesn't do the right thing
608 * for all system calls, but it should be OK for the operations
609 * we permit from an autofs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 */
Ian Kent1864f7b2007-08-22 14:01:54 -0700611 if (!oz_mode && d_unhashed(dentry)) {
Ian Kentc9ffec42007-02-20 13:58:10 -0800612 /*
613 * A user space application can (and has done in the past)
614 * remove and re-create this directory during the callback.
615 * This can leave us with an unhashed dentry, but a
616 * successful mount! So we need to perform another
617 * cached lookup in case the dentry now exists.
618 */
619 struct dentry *parent = dentry->d_parent;
620 struct dentry *new = d_lookup(parent, &dentry->d_name);
621 if (new != NULL)
622 dentry = new;
623 else
624 dentry = ERR_PTR(-ENOENT);
625
Ian Kent25767372008-07-23 21:30:12 -0700626 if (unhashed)
627 dput(unhashed);
628
Ian Kentc9ffec42007-02-20 13:58:10 -0800629 return dentry;
Ian Kentf50b6f82007-02-20 13:58:10 -0800630 }
631
Ian Kent25767372008-07-23 21:30:12 -0700632 if (unhashed)
633 return unhashed;
634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 return NULL;
636}
637
638static int autofs4_dir_symlink(struct inode *dir,
639 struct dentry *dentry,
640 const char *symname)
641{
642 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
643 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800644 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 struct inode *inode;
646 char *cp;
647
648 DPRINTK("%s <- %.*s", symname,
649 dentry->d_name.len, dentry->d_name.name);
650
651 if (!autofs4_oz_mode(sbi))
652 return -EACCES;
653
654 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
Ian Kent25767372008-07-23 21:30:12 -0700655 if (!ino)
656 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Ian Kent25767372008-07-23 21:30:12 -0700658 spin_lock(&sbi->lookup_lock);
659 if (!list_empty(&ino->active))
660 list_del_init(&ino->active);
661 spin_unlock(&sbi->lookup_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Ian Kentef581a72008-07-23 21:30:13 -0700663 ino->size = strlen(symname);
Ian Kent25767372008-07-23 21:30:12 -0700664 cp = kmalloc(ino->size + 1, GFP_KERNEL);
665 if (!cp) {
666 if (!dentry->d_fsdata)
667 kfree(ino);
668 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 }
670
671 strcpy(cp, symname);
672
673 inode = autofs4_get_inode(dir->i_sb, ino);
Ian Kent25767372008-07-23 21:30:12 -0700674 if (!inode) {
675 kfree(cp);
676 if (!dentry->d_fsdata)
677 kfree(ino);
678 return -ENOMEM;
679 }
Ian Kent1864f7b2007-08-22 14:01:54 -0700680 d_add(dentry, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 if (dir == dir->i_sb->s_root->d_inode)
683 dentry->d_op = &autofs4_root_dentry_operations;
684 else
685 dentry->d_op = &autofs4_dentry_operations;
686
687 dentry->d_fsdata = ino;
688 ino->dentry = dget(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800689 atomic_inc(&ino->count);
690 p_ino = autofs4_dentry_ino(dentry->d_parent);
691 if (p_ino && dentry->d_parent != dentry)
692 atomic_inc(&p_ino->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 ino->inode = inode;
694
Ian Kent25767372008-07-23 21:30:12 -0700695 ino->u.symlink = cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 dir->i_mtime = CURRENT_TIME;
697
698 return 0;
699}
700
701/*
702 * NOTE!
703 *
704 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
705 * that the file no longer exists. However, doing that means that the
706 * VFS layer can turn the dentry into a negative dentry. We don't want
Ian Kentf50b6f82007-02-20 13:58:10 -0800707 * this, because the unlink is probably the result of an expire.
Ian Kent5f6f4f22008-07-23 21:30:09 -0700708 * We simply d_drop it and add it to a expiring list in the super block,
709 * which allows the dentry lookup to check for an incomplete expire.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 *
711 * If a process is blocked on the dentry waiting for the expire to finish,
712 * it will invalidate the dentry and try to mount with a new one.
713 *
714 * Also see autofs4_dir_rmdir()..
715 */
716static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
717{
718 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
719 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800720 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 /* This allows root to remove symlinks */
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700723 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 return -EACCES;
725
Ian Kent1aff3c82006-03-27 01:14:46 -0800726 if (atomic_dec_and_test(&ino->count)) {
727 p_ino = autofs4_dentry_ino(dentry->d_parent);
728 if (p_ino && dentry->d_parent != dentry)
729 atomic_dec(&p_ino->count);
730 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 dput(ino->dentry);
732
733 dentry->d_inode->i_size = 0;
Dave Hansence71ec32006-09-30 23:29:06 -0700734 clear_nlink(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736 dir->i_mtime = CURRENT_TIME;
737
Ian Kentf50b6f82007-02-20 13:58:10 -0800738 spin_lock(&dcache_lock);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700739 spin_lock(&sbi->lookup_lock);
Ian Kent25767372008-07-23 21:30:12 -0700740 if (list_empty(&ino->expiring))
741 list_add(&ino->expiring, &sbi->expiring_list);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700742 spin_unlock(&sbi->lookup_lock);
Ian Kentf50b6f82007-02-20 13:58:10 -0800743 spin_lock(&dentry->d_lock);
744 __d_drop(dentry);
745 spin_unlock(&dentry->d_lock);
746 spin_unlock(&dcache_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 return 0;
749}
750
751static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
752{
753 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
754 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800755 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Ian Kentf50b6f82007-02-20 13:58:10 -0800757 DPRINTK("dentry %p, removing %.*s",
758 dentry, dentry->d_name.len, dentry->d_name.name);
759
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 if (!autofs4_oz_mode(sbi))
761 return -EACCES;
762
763 spin_lock(&dcache_lock);
764 if (!list_empty(&dentry->d_subdirs)) {
765 spin_unlock(&dcache_lock);
766 return -ENOTEMPTY;
767 }
Ian Kent5f6f4f22008-07-23 21:30:09 -0700768 spin_lock(&sbi->lookup_lock);
Ian Kent25767372008-07-23 21:30:12 -0700769 if (list_empty(&ino->expiring))
770 list_add(&ino->expiring, &sbi->expiring_list);
Ian Kent5f6f4f22008-07-23 21:30:09 -0700771 spin_unlock(&sbi->lookup_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 spin_lock(&dentry->d_lock);
773 __d_drop(dentry);
774 spin_unlock(&dentry->d_lock);
775 spin_unlock(&dcache_lock);
776
Ian Kent1aff3c82006-03-27 01:14:46 -0800777 if (atomic_dec_and_test(&ino->count)) {
778 p_ino = autofs4_dentry_ino(dentry->d_parent);
779 if (p_ino && dentry->d_parent != dentry)
780 atomic_dec(&p_ino->count);
781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 dput(ino->dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 dentry->d_inode->i_size = 0;
Dave Hansence71ec32006-09-30 23:29:06 -0700784 clear_nlink(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786 if (dir->i_nlink)
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700787 drop_nlink(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 return 0;
790}
791
792static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
793{
794 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
795 struct autofs_info *ino = autofs4_dentry_ino(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800796 struct autofs_info *p_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 struct inode *inode;
798
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700799 if (!autofs4_oz_mode(sbi))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return -EACCES;
801
802 DPRINTK("dentry %p, creating %.*s",
803 dentry, dentry->d_name.len, dentry->d_name.name);
804
805 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
Ian Kent25767372008-07-23 21:30:12 -0700806 if (!ino)
807 return -ENOMEM;
808
809 spin_lock(&sbi->lookup_lock);
810 if (!list_empty(&ino->active))
811 list_del_init(&ino->active);
812 spin_unlock(&sbi->lookup_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 inode = autofs4_get_inode(dir->i_sb, ino);
Ian Kent25767372008-07-23 21:30:12 -0700815 if (!inode) {
816 if (!dentry->d_fsdata)
817 kfree(ino);
818 return -ENOMEM;
819 }
Ian Kent1864f7b2007-08-22 14:01:54 -0700820 d_add(dentry, inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 if (dir == dir->i_sb->s_root->d_inode)
823 dentry->d_op = &autofs4_root_dentry_operations;
824 else
825 dentry->d_op = &autofs4_dentry_operations;
826
827 dentry->d_fsdata = ino;
828 ino->dentry = dget(dentry);
Ian Kent1aff3c82006-03-27 01:14:46 -0800829 atomic_inc(&ino->count);
830 p_ino = autofs4_dentry_ino(dentry->d_parent);
831 if (p_ino && dentry->d_parent != dentry)
832 atomic_inc(&p_ino->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 ino->inode = inode;
Dave Hansend8c76e62006-09-30 23:29:04 -0700834 inc_nlink(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 dir->i_mtime = CURRENT_TIME;
836
837 return 0;
838}
839
840/* Get/set timeout ioctl() operation */
841static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
842 unsigned long __user *p)
843{
844 int rv;
845 unsigned long ntimeout;
846
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700847 if ((rv = get_user(ntimeout, p)) ||
848 (rv = put_user(sbi->exp_timeout/HZ, p)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 return rv;
850
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700851 if (ntimeout > ULONG_MAX/HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 sbi->exp_timeout = 0;
853 else
854 sbi->exp_timeout = ntimeout * HZ;
855
856 return 0;
857}
858
859/* Return protocol version */
860static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
861{
862 return put_user(sbi->version, p);
863}
864
865/* Return protocol sub version */
866static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
867{
868 return put_user(sbi->sub_version, p);
869}
870
871/*
872 * Tells the daemon whether we need to reghost or not. Also, clears
873 * the reghost_needed flag.
874 */
875static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
876{
877 int status;
878
879 DPRINTK("returning %d", sbi->needs_reghost);
880
881 status = put_user(sbi->needs_reghost, p);
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700882 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 return status;
884
885 sbi->needs_reghost = 0;
886 return 0;
887}
888
889/*
890 * Enable / Disable reghosting ioctl() operation
891 */
892static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
893{
894 int status;
895 int val;
896
897 status = get_user(val, p);
898
899 DPRINTK("reghost = %d", val);
900
901 if (status)
902 return status;
903
904 /* turn on/off reghosting, with the val */
905 sbi->reghost_enabled = val;
906 return 0;
907}
908
909/*
910* Tells the daemon whether it can umount the autofs mount.
911*/
912static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
913{
914 int status = 0;
915
Ian Kente3474a82006-03-27 01:14:51 -0800916 if (may_umount(mnt))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 status = 1;
918
919 DPRINTK("returning %d", status);
920
921 status = put_user(status, p);
922
923 return status;
924}
925
926/* Identify autofs4_dentries - this is so we can tell if there's
927 an extra dentry refcount or not. We only hold a refcount on the
928 dentry if its non-negative (ie, d_inode != NULL)
929*/
930int is_autofs4_dentry(struct dentry *dentry)
931{
932 return dentry && dentry->d_inode &&
933 (dentry->d_op == &autofs4_root_dentry_operations ||
934 dentry->d_op == &autofs4_dentry_operations) &&
935 dentry->d_fsdata != NULL;
936}
937
938/*
939 * ioctl()'s on the root directory is the chief method for the daemon to
940 * generate kernel reactions
941 */
942static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
943 unsigned int cmd, unsigned long arg)
944{
945 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
946 void __user *p = (void __user *)arg;
947
948 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
Pavel Emelianova47afb02007-10-18 23:39:46 -0700949 cmd,arg,sbi,task_pgrp_nr(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700951 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
952 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 return -ENOTTY;
954
Sukadev Bhattiprolud78e53c2007-05-10 22:23:06 -0700955 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 return -EPERM;
957
958 switch(cmd) {
959 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
960 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
961 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
962 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
963 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
964 autofs4_catatonic_mode(sbi);
965 return 0;
966 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
967 return autofs4_get_protover(sbi, p);
968 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
969 return autofs4_get_protosubver(sbi, p);
970 case AUTOFS_IOC_SETTIMEOUT:
971 return autofs4_get_set_timeout(sbi, p);
972
973 case AUTOFS_IOC_TOGGLEREGHOST:
974 return autofs4_toggle_reghost(sbi, p);
975 case AUTOFS_IOC_ASKREGHOST:
976 return autofs4_ask_reghost(sbi, p);
977
978 case AUTOFS_IOC_ASKUMOUNT:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800979 return autofs4_ask_umount(filp->f_path.mnt, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
981 /* return a single thing to expire */
982 case AUTOFS_IOC_EXPIRE:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800983 return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 /* same as above, but can send multiple expires through pipe */
985 case AUTOFS_IOC_EXPIRE_MULTI:
Josef "Jeff" Sipeka4669ed2006-12-08 02:36:46 -0800986 return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 default:
989 return -ENOSYS;
990 }
991}