1 /* -*- c -*- --------------------------------------------------------------- *
3 * linux/fs/autofs/root.c
5 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
6 * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
7 * Copyright 2001-2006 Ian Kent <raven@themaw.net>
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.
13 * ------------------------------------------------------------------------- */
15 #include <linux/capability.h>
16 #include <linux/errno.h>
17 #include <linux/stat.h>
18 #include <linux/param.h>
19 #include <linux/time.h>
22 static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *);
23 static int autofs4_dir_unlink(struct inode *,struct dentry *);
24 static int autofs4_dir_rmdir(struct inode *,struct dentry *);
25 static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
26 static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
27 static int autofs4_dir_open(struct inode *inode, struct file *file);
28 static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
29 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
30 static void *autofs4_follow_link(struct dentry *, struct nameidata *);
32 #define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
33 #define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
35 const struct file_operations autofs4_root_operations = {
36 .open = dcache_dir_open,
37 .release = dcache_dir_close,
38 .read = generic_read_dir,
39 .readdir = autofs4_root_readdir,
40 .ioctl = autofs4_root_ioctl,
43 const struct file_operations autofs4_dir_operations = {
44 .open = autofs4_dir_open,
45 .release = dcache_dir_close,
46 .read = generic_read_dir,
47 .readdir = dcache_readdir,
50 const struct inode_operations autofs4_indirect_root_inode_operations = {
51 .lookup = autofs4_lookup,
52 .unlink = autofs4_dir_unlink,
53 .symlink = autofs4_dir_symlink,
54 .mkdir = autofs4_dir_mkdir,
55 .rmdir = autofs4_dir_rmdir,
58 const struct inode_operations autofs4_direct_root_inode_operations = {
59 .lookup = autofs4_lookup,
60 .unlink = autofs4_dir_unlink,
61 .mkdir = autofs4_dir_mkdir,
62 .rmdir = autofs4_dir_rmdir,
63 .follow_link = autofs4_follow_link,
66 const struct inode_operations autofs4_dir_inode_operations = {
67 .lookup = autofs4_lookup,
68 .unlink = autofs4_dir_unlink,
69 .symlink = autofs4_dir_symlink,
70 .mkdir = autofs4_dir_mkdir,
71 .rmdir = autofs4_dir_rmdir,
74 static int autofs4_root_readdir(struct file *file, void *dirent,
77 struct autofs_sb_info *sbi = autofs4_sbi(file->f_path.dentry->d_sb);
78 int oz_mode = autofs4_oz_mode(sbi);
80 DPRINTK("called, filp->f_pos = %lld", file->f_pos);
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
88 if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
89 sbi->needs_reghost = 1;
91 DPRINTK("needs_reghost = %d", sbi->needs_reghost);
93 return dcache_readdir(file, dirent, filldir);
96 static int autofs4_dir_open(struct inode *inode, struct file *file)
98 struct dentry *dentry = file->f_path.dentry;
99 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
101 DPRINTK("file=%p dentry=%p %.*s",
102 file, dentry, dentry->d_name.len, dentry->d_name.name);
104 if (autofs4_oz_mode(sbi))
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
116 spin_lock(&dcache_lock);
117 if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
118 spin_unlock(&dcache_lock);
121 spin_unlock(&dcache_lock);
124 return dcache_dir_open(inode, file);
127 static int try_to_fill_dentry(struct dentry *dentry, int flags)
129 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
130 struct autofs_info *ino = autofs4_dentry_ino(dentry);
133 DPRINTK("dentry=%p %.*s ino=%p",
134 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
137 * Wait for a pending mount, triggering one if there
140 if (dentry->d_inode == NULL) {
141 DPRINTK("waiting for mount name=%.*s",
142 dentry->d_name.len, dentry->d_name.name);
144 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
146 DPRINTK("mount done status=%d", status);
148 /* Turn this into a real negative dentry? */
149 if (status == -ENOENT) {
150 spin_lock(&dentry->d_lock);
151 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
152 spin_unlock(&dentry->d_lock);
155 /* Return a negative dentry, but leave it "pending" */
158 /* Trigger mount for path component or follow link */
159 } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
160 flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
161 current->link_count) {
162 DPRINTK("waiting for mount name=%.*s",
163 dentry->d_name.len, dentry->d_name.name);
165 spin_lock(&dentry->d_lock);
166 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
167 spin_unlock(&dentry->d_lock);
168 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
170 DPRINTK("mount done status=%d", status);
173 spin_lock(&dentry->d_lock);
174 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
175 spin_unlock(&dentry->d_lock);
180 /* Initialize expiry counter after successful mount */
182 ino->last_used = jiffies;
184 spin_lock(&dentry->d_lock);
185 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
186 spin_unlock(&dentry->d_lock);
191 /* For autofs direct mounts the follow link triggers the mount */
192 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
194 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
195 struct autofs_info *ino = autofs4_dentry_ino(dentry);
196 int oz_mode = autofs4_oz_mode(sbi);
197 unsigned int lookup_type;
200 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
201 dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
204 * For an expire of a covered direct or offset mount we need
205 * to beeak out of follow_down() at the autofs mount trigger
206 * (d_mounted--), so we can see the expiring flag, and manage
207 * the blocking and following here until the expire is completed.
210 spin_lock(&sbi->fs_lock);
211 if (ino->flags & AUTOFS_INF_EXPIRING) {
212 spin_unlock(&sbi->fs_lock);
213 /* Follow down to our covering mount. */
214 if (!follow_down(&nd->path.mnt, &nd->path.dentry))
218 spin_unlock(&sbi->fs_lock);
222 /* If an expire request is pending everyone must wait. */
223 autofs4_expire_wait(dentry);
225 /* We trigger a mount for almost all flags */
226 lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
227 if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
231 * If the dentry contains directories then it is an autofs
232 * multi-mount with no root mount offset. So don't try to
235 spin_lock(&dcache_lock);
236 if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
237 (!d_mountpoint(dentry) && __simple_empty(dentry))) {
238 spin_unlock(&dcache_lock);
240 status = try_to_fill_dentry(dentry, 0);
246 spin_unlock(&dcache_lock);
249 * If there is no root mount it must be an autofs
250 * multi-mount with no root offset so we don't need
253 if (d_mountpoint(dentry)) {
254 if (!autofs4_follow_mount(&nd->path.mnt,
266 return ERR_PTR(status);
270 * Revalidate is called on every cache lookup. Some of those
271 * cache lookups may actually happen while the dentry is not
272 * yet completely filled in, and revalidate has to delay such
275 static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
277 struct inode *dir = dentry->d_parent->d_inode;
278 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
279 int oz_mode = autofs4_oz_mode(sbi);
280 int flags = nd ? nd->flags : 0;
284 spin_lock(&sbi->fs_lock);
285 if (autofs4_ispending(dentry)) {
286 /* The daemon never causes a mount to trigger */
287 spin_unlock(&sbi->fs_lock);
293 * If the directory has gone away due to an expire
294 * we have been called as ->d_revalidate() and so
295 * we need to return false and proceed to ->lookup().
297 if (autofs4_expire_wait(dentry) == -EAGAIN)
301 * A zero status is success otherwise we have a
302 * negative error code.
304 status = try_to_fill_dentry(dentry, flags);
310 spin_unlock(&sbi->fs_lock);
312 /* Negative dentry.. invalidate if "old" */
313 if (dentry->d_inode == NULL)
316 /* Check for a non-mountpoint directory with no contents */
317 spin_lock(&dcache_lock);
318 if (S_ISDIR(dentry->d_inode->i_mode) &&
319 !d_mountpoint(dentry) &&
320 __simple_empty(dentry)) {
321 DPRINTK("dentry=%p %.*s, emptydir",
322 dentry, dentry->d_name.len, dentry->d_name.name);
323 spin_unlock(&dcache_lock);
325 /* The daemon never causes a mount to trigger */
330 * A zero status is success otherwise we have a
331 * negative error code.
333 status = try_to_fill_dentry(dentry, flags);
339 spin_unlock(&dcache_lock);
344 void autofs4_dentry_release(struct dentry *de)
346 struct autofs_info *inf;
348 DPRINTK("releasing %p", de);
350 inf = autofs4_dentry_ino(de);
354 struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
357 spin_lock(&sbi->lookup_lock);
358 if (!list_empty(&inf->active))
359 list_del(&inf->active);
360 if (!list_empty(&inf->expiring))
361 list_del(&inf->expiring);
362 spin_unlock(&sbi->lookup_lock);
368 autofs4_free_ino(inf);
372 /* For dentries of directories in the root dir */
373 static struct dentry_operations autofs4_root_dentry_operations = {
374 .d_revalidate = autofs4_revalidate,
375 .d_release = autofs4_dentry_release,
378 /* For other dentries */
379 static struct dentry_operations autofs4_dentry_operations = {
380 .d_revalidate = autofs4_revalidate,
381 .d_release = autofs4_dentry_release,
384 static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
386 unsigned int len = name->len;
387 unsigned int hash = name->hash;
388 const unsigned char *str = name->name;
389 struct list_head *p, *head;
391 spin_lock(&dcache_lock);
392 spin_lock(&sbi->lookup_lock);
393 head = &sbi->active_list;
394 list_for_each(p, head) {
395 struct autofs_info *ino;
396 struct dentry *dentry;
399 ino = list_entry(p, struct autofs_info, active);
400 dentry = ino->dentry;
402 spin_lock(&dentry->d_lock);
405 if (atomic_read(&dentry->d_count) == 0)
408 qstr = &dentry->d_name;
410 if (dentry->d_name.hash != hash)
412 if (dentry->d_parent != parent)
415 if (qstr->len != len)
417 if (memcmp(qstr->name, str, len))
420 if (d_unhashed(dentry)) {
422 spin_unlock(&dentry->d_lock);
423 spin_unlock(&sbi->lookup_lock);
424 spin_unlock(&dcache_lock);
428 spin_unlock(&dentry->d_lock);
430 spin_unlock(&sbi->lookup_lock);
431 spin_unlock(&dcache_lock);
436 static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
438 unsigned int len = name->len;
439 unsigned int hash = name->hash;
440 const unsigned char *str = name->name;
441 struct list_head *p, *head;
443 spin_lock(&dcache_lock);
444 spin_lock(&sbi->lookup_lock);
445 head = &sbi->expiring_list;
446 list_for_each(p, head) {
447 struct autofs_info *ino;
448 struct dentry *dentry;
451 ino = list_entry(p, struct autofs_info, expiring);
452 dentry = ino->dentry;
454 spin_lock(&dentry->d_lock);
456 /* Bad luck, we've already been dentry_iput */
457 if (!dentry->d_inode)
460 qstr = &dentry->d_name;
462 if (dentry->d_name.hash != hash)
464 if (dentry->d_parent != parent)
467 if (qstr->len != len)
469 if (memcmp(qstr->name, str, len))
472 if (d_unhashed(dentry)) {
474 spin_unlock(&dentry->d_lock);
475 spin_unlock(&sbi->lookup_lock);
476 spin_unlock(&dcache_lock);
480 spin_unlock(&dentry->d_lock);
482 spin_unlock(&sbi->lookup_lock);
483 spin_unlock(&dcache_lock);
488 /* Lookups in the root directory */
489 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
491 struct autofs_sb_info *sbi;
492 struct autofs_info *ino;
493 struct dentry *expiring, *unhashed;
496 DPRINTK("name = %.*s",
497 dentry->d_name.len, dentry->d_name.name);
499 /* File name too long to exist */
500 if (dentry->d_name.len > NAME_MAX)
501 return ERR_PTR(-ENAMETOOLONG);
503 sbi = autofs4_sbi(dir->i_sb);
504 oz_mode = autofs4_oz_mode(sbi);
506 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
507 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
509 expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
512 * If we are racing with expire the request might not
513 * be quite complete but the directory has been removed
514 * so it must have been successful, so just wait for it.
516 ino = autofs4_dentry_ino(expiring);
517 autofs4_expire_wait(expiring);
518 spin_lock(&sbi->lookup_lock);
519 if (!list_empty(&ino->expiring))
520 list_del_init(&ino->expiring);
521 spin_unlock(&sbi->lookup_lock);
525 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
530 * Mark the dentry incomplete but don't hash it. We do this
531 * to serialize our inode creation operations (symlink and
532 * mkdir) which prevents deadlock during the callback to
533 * the daemon. Subsequent user space lookups for the same
534 * dentry are placed on the wait queue while the daemon
535 * itself is allowed passage unresticted so the create
536 * operation itself can then hash the dentry. Finally,
537 * we check for the hashed dentry and return the newly
540 dentry->d_op = &autofs4_root_dentry_operations;
543 * And we need to ensure that the same dentry is used for
544 * all following lookup calls until it is hashed so that
545 * the dentry flags are persistent throughout the request.
547 ino = autofs4_init_ino(NULL, sbi, 0555);
549 return ERR_PTR(-ENOMEM);
551 dentry->d_fsdata = ino;
552 ino->dentry = dentry;
554 spin_lock(&sbi->lookup_lock);
555 list_add(&ino->active, &sbi->active_list);
556 spin_unlock(&sbi->lookup_lock);
558 d_instantiate(dentry, NULL);
562 spin_lock(&dentry->d_lock);
563 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
564 spin_unlock(&dentry->d_lock);
565 if (dentry->d_op && dentry->d_op->d_revalidate) {
566 mutex_unlock(&dir->i_mutex);
567 (dentry->d_op->d_revalidate)(dentry, nd);
568 mutex_lock(&dir->i_mutex);
573 * If we are still pending, check if we had to handle
574 * a signal. If so we can force a restart..
576 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
577 /* See if we were interrupted */
578 if (signal_pending(current)) {
579 sigset_t *sigset = ¤t->pending.signal;
580 if (sigismember (sigset, SIGKILL) ||
581 sigismember (sigset, SIGQUIT) ||
582 sigismember (sigset, SIGINT)) {
585 return ERR_PTR(-ERESTARTNOINTR);
589 spin_lock(&dentry->d_lock);
590 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
591 spin_unlock(&dentry->d_lock);
596 * If this dentry is unhashed, then we shouldn't honour this
597 * lookup. Returning ENOENT here doesn't do the right thing
598 * for all system calls, but it should be OK for the operations
599 * we permit from an autofs.
601 if (!oz_mode && d_unhashed(dentry)) {
603 * A user space application can (and has done in the past)
604 * remove and re-create this directory during the callback.
605 * This can leave us with an unhashed dentry, but a
606 * successful mount! So we need to perform another
607 * cached lookup in case the dentry now exists.
609 struct dentry *parent = dentry->d_parent;
610 struct dentry *new = d_lookup(parent, &dentry->d_name);
614 dentry = ERR_PTR(-ENOENT);
628 static int autofs4_dir_symlink(struct inode *dir,
629 struct dentry *dentry,
632 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
633 struct autofs_info *ino = autofs4_dentry_ino(dentry);
634 struct autofs_info *p_ino;
638 DPRINTK("%s <- %.*s", symname,
639 dentry->d_name.len, dentry->d_name.name);
641 if (!autofs4_oz_mode(sbi))
644 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
648 spin_lock(&sbi->lookup_lock);
649 if (!list_empty(&ino->active))
650 list_del_init(&ino->active);
651 spin_unlock(&sbi->lookup_lock);
653 ino->size = strlen(symname);
654 cp = kmalloc(ino->size + 1, GFP_KERNEL);
656 if (!dentry->d_fsdata)
663 inode = autofs4_get_inode(dir->i_sb, ino);
666 if (!dentry->d_fsdata)
670 d_add(dentry, inode);
672 if (dir == dir->i_sb->s_root->d_inode)
673 dentry->d_op = &autofs4_root_dentry_operations;
675 dentry->d_op = &autofs4_dentry_operations;
677 dentry->d_fsdata = ino;
678 ino->dentry = dget(dentry);
679 atomic_inc(&ino->count);
680 p_ino = autofs4_dentry_ino(dentry->d_parent);
681 if (p_ino && dentry->d_parent != dentry)
682 atomic_inc(&p_ino->count);
686 dir->i_mtime = CURRENT_TIME;
694 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
695 * that the file no longer exists. However, doing that means that the
696 * VFS layer can turn the dentry into a negative dentry. We don't want
697 * this, because the unlink is probably the result of an expire.
698 * We simply d_drop it and add it to a expiring list in the super block,
699 * which allows the dentry lookup to check for an incomplete expire.
701 * If a process is blocked on the dentry waiting for the expire to finish,
702 * it will invalidate the dentry and try to mount with a new one.
704 * Also see autofs4_dir_rmdir()..
706 static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
708 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
709 struct autofs_info *ino = autofs4_dentry_ino(dentry);
710 struct autofs_info *p_ino;
712 /* This allows root to remove symlinks */
713 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
716 if (atomic_dec_and_test(&ino->count)) {
717 p_ino = autofs4_dentry_ino(dentry->d_parent);
718 if (p_ino && dentry->d_parent != dentry)
719 atomic_dec(&p_ino->count);
723 dentry->d_inode->i_size = 0;
724 clear_nlink(dentry->d_inode);
726 dir->i_mtime = CURRENT_TIME;
728 spin_lock(&dcache_lock);
729 spin_lock(&sbi->lookup_lock);
730 if (list_empty(&ino->expiring))
731 list_add(&ino->expiring, &sbi->expiring_list);
732 spin_unlock(&sbi->lookup_lock);
733 spin_lock(&dentry->d_lock);
735 spin_unlock(&dentry->d_lock);
736 spin_unlock(&dcache_lock);
741 static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
743 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
744 struct autofs_info *ino = autofs4_dentry_ino(dentry);
745 struct autofs_info *p_ino;
747 DPRINTK("dentry %p, removing %.*s",
748 dentry, dentry->d_name.len, dentry->d_name.name);
750 if (!autofs4_oz_mode(sbi))
753 spin_lock(&dcache_lock);
754 if (!list_empty(&dentry->d_subdirs)) {
755 spin_unlock(&dcache_lock);
758 spin_lock(&sbi->lookup_lock);
759 if (list_empty(&ino->expiring))
760 list_add(&ino->expiring, &sbi->expiring_list);
761 spin_unlock(&sbi->lookup_lock);
762 spin_lock(&dentry->d_lock);
764 spin_unlock(&dentry->d_lock);
765 spin_unlock(&dcache_lock);
767 if (atomic_dec_and_test(&ino->count)) {
768 p_ino = autofs4_dentry_ino(dentry->d_parent);
769 if (p_ino && dentry->d_parent != dentry)
770 atomic_dec(&p_ino->count);
773 dentry->d_inode->i_size = 0;
774 clear_nlink(dentry->d_inode);
782 static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
784 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
785 struct autofs_info *ino = autofs4_dentry_ino(dentry);
786 struct autofs_info *p_ino;
789 if (!autofs4_oz_mode(sbi))
792 DPRINTK("dentry %p, creating %.*s",
793 dentry, dentry->d_name.len, dentry->d_name.name);
795 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
799 spin_lock(&sbi->lookup_lock);
800 if (!list_empty(&ino->active))
801 list_del_init(&ino->active);
802 spin_unlock(&sbi->lookup_lock);
804 inode = autofs4_get_inode(dir->i_sb, ino);
806 if (!dentry->d_fsdata)
810 d_add(dentry, inode);
812 if (dir == dir->i_sb->s_root->d_inode)
813 dentry->d_op = &autofs4_root_dentry_operations;
815 dentry->d_op = &autofs4_dentry_operations;
817 dentry->d_fsdata = ino;
818 ino->dentry = dget(dentry);
819 atomic_inc(&ino->count);
820 p_ino = autofs4_dentry_ino(dentry->d_parent);
821 if (p_ino && dentry->d_parent != dentry)
822 atomic_inc(&p_ino->count);
825 dir->i_mtime = CURRENT_TIME;
830 /* Get/set timeout ioctl() operation */
831 static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
832 unsigned long __user *p)
835 unsigned long ntimeout;
837 if ((rv = get_user(ntimeout, p)) ||
838 (rv = put_user(sbi->exp_timeout/HZ, p)))
841 if (ntimeout > ULONG_MAX/HZ)
842 sbi->exp_timeout = 0;
844 sbi->exp_timeout = ntimeout * HZ;
849 /* Return protocol version */
850 static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
852 return put_user(sbi->version, p);
855 /* Return protocol sub version */
856 static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
858 return put_user(sbi->sub_version, p);
862 * Tells the daemon whether we need to reghost or not. Also, clears
863 * the reghost_needed flag.
865 static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
869 DPRINTK("returning %d", sbi->needs_reghost);
871 status = put_user(sbi->needs_reghost, p);
875 sbi->needs_reghost = 0;
880 * Enable / Disable reghosting ioctl() operation
882 static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
887 status = get_user(val, p);
889 DPRINTK("reghost = %d", val);
894 /* turn on/off reghosting, with the val */
895 sbi->reghost_enabled = val;
900 * Tells the daemon whether it can umount the autofs mount.
902 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
909 DPRINTK("returning %d", status);
911 status = put_user(status, p);
916 /* Identify autofs4_dentries - this is so we can tell if there's
917 an extra dentry refcount or not. We only hold a refcount on the
918 dentry if its non-negative (ie, d_inode != NULL)
920 int is_autofs4_dentry(struct dentry *dentry)
922 return dentry && dentry->d_inode &&
923 (dentry->d_op == &autofs4_root_dentry_operations ||
924 dentry->d_op == &autofs4_dentry_operations) &&
925 dentry->d_fsdata != NULL;
929 * ioctl()'s on the root directory is the chief method for the daemon to
930 * generate kernel reactions
932 static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
933 unsigned int cmd, unsigned long arg)
935 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
936 void __user *p = (void __user *)arg;
938 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
939 cmd,arg,sbi,task_pgrp_nr(current));
941 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
942 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
945 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
949 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
950 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
951 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
952 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
953 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
954 autofs4_catatonic_mode(sbi);
956 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
957 return autofs4_get_protover(sbi, p);
958 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
959 return autofs4_get_protosubver(sbi, p);
960 case AUTOFS_IOC_SETTIMEOUT:
961 return autofs4_get_set_timeout(sbi, p);
963 case AUTOFS_IOC_TOGGLEREGHOST:
964 return autofs4_toggle_reghost(sbi, p);
965 case AUTOFS_IOC_ASKREGHOST:
966 return autofs4_ask_reghost(sbi, p);
968 case AUTOFS_IOC_ASKUMOUNT:
969 return autofs4_ask_umount(filp->f_path.mnt, p);
971 /* return a single thing to expire */
972 case AUTOFS_IOC_EXPIRE:
973 return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p);
974 /* same as above, but can send multiple expires through pipe */
975 case AUTOFS_IOC_EXPIRE_MULTI:
976 return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p);