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 /* Block on any pending expiry here; invalidate the dentry
134 when expiration is done to trigger mount request with a new
136 if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
137 DPRINTK("waiting for expire %p name=%.*s",
138 dentry, dentry->d_name.len, dentry->d_name.name);
140 status = autofs4_wait(sbi, dentry, NFY_NONE);
142 DPRINTK("expire done status=%d", status);
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.
149 status = d_invalidate(dentry);
150 if (status != -EBUSY)
154 DPRINTK("dentry=%p %.*s ino=%p",
155 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
158 * Wait for a pending mount, triggering one if there
161 if (dentry->d_inode == NULL) {
162 DPRINTK("waiting for mount name=%.*s",
163 dentry->d_name.len, dentry->d_name.name);
165 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
167 DPRINTK("mount done status=%d", status);
169 /* Turn this into a real negative dentry? */
170 if (status == -ENOENT) {
171 spin_lock(&dentry->d_lock);
172 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
173 spin_unlock(&dentry->d_lock);
176 /* Return a negative dentry, but leave it "pending" */
179 /* Trigger mount for path component or follow link */
180 } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
181 flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
182 current->link_count) {
183 DPRINTK("waiting for mount name=%.*s",
184 dentry->d_name.len, dentry->d_name.name);
186 spin_lock(&dentry->d_lock);
187 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
188 spin_unlock(&dentry->d_lock);
189 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
191 DPRINTK("mount done status=%d", status);
194 spin_lock(&dentry->d_lock);
195 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
196 spin_unlock(&dentry->d_lock);
201 /* Initialize expiry counter after successful mount */
203 ino->last_used = jiffies;
205 spin_lock(&dentry->d_lock);
206 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
207 spin_unlock(&dentry->d_lock);
212 /* For autofs direct mounts the follow link triggers the mount */
213 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
215 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
216 struct autofs_info *ino = autofs4_dentry_ino(dentry);
217 int oz_mode = autofs4_oz_mode(sbi);
218 unsigned int lookup_type;
221 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
222 dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
225 /* If it's our master or we shouldn't trigger a mount we're done */
226 lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
228 !(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
231 /* If an expire request is pending wait for it. */
232 if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
233 DPRINTK("waiting for active request %p name=%.*s",
234 dentry, dentry->d_name.len, dentry->d_name.name);
236 status = autofs4_wait(sbi, dentry, NFY_NONE);
238 DPRINTK("request done status=%d", status);
242 * If the dentry contains directories then it is an
243 * autofs multi-mount with no root mount offset. So
244 * don't try to mount it again.
246 spin_lock(&dcache_lock);
247 if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
248 (!d_mountpoint(dentry) && __simple_empty(dentry))) {
249 spin_unlock(&dcache_lock);
251 status = try_to_fill_dentry(dentry, 0);
256 * The mount succeeded but if there is no root mount
257 * it must be an autofs multi-mount with no root offset
258 * so we don't need to follow the mount.
260 if (d_mountpoint(dentry)) {
261 if (!autofs4_follow_mount(&nd->path.mnt,
270 spin_unlock(&dcache_lock);
277 return ERR_PTR(status);
281 * Revalidate is called on every cache lookup. Some of those
282 * cache lookups may actually happen while the dentry is not
283 * yet completely filled in, and revalidate has to delay such
286 static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
288 struct inode *dir = dentry->d_parent->d_inode;
289 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
290 int oz_mode = autofs4_oz_mode(sbi);
291 int flags = nd ? nd->flags : 0;
295 if (autofs4_ispending(dentry)) {
296 /* The daemon never causes a mount to trigger */
301 * A zero status is success otherwise we have a
302 * negative error code.
304 status = try_to_fill_dentry(dentry, flags);
309 * A status of EAGAIN here means that the dentry has gone
310 * away while waiting for an expire to complete. If we are
311 * racing with expire lookup will wait for it so this must
312 * be a revalidate and we need to send it to lookup.
314 if (status == -EAGAIN)
320 /* Negative dentry.. invalidate if "old" */
321 if (dentry->d_inode == NULL)
324 /* Check for a non-mountpoint directory with no contents */
325 spin_lock(&dcache_lock);
326 if (S_ISDIR(dentry->d_inode->i_mode) &&
327 !d_mountpoint(dentry) &&
328 __simple_empty(dentry)) {
329 DPRINTK("dentry=%p %.*s, emptydir",
330 dentry, dentry->d_name.len, dentry->d_name.name);
331 spin_unlock(&dcache_lock);
332 /* The daemon never causes a mount to trigger */
337 * A zero status is success otherwise we have a
338 * negative error code.
340 status = try_to_fill_dentry(dentry, flags);
346 spin_unlock(&dcache_lock);
351 void autofs4_dentry_release(struct dentry *de)
353 struct autofs_info *inf;
355 DPRINTK("releasing %p", de);
357 inf = autofs4_dentry_ino(de);
361 struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
364 spin_lock(&sbi->lookup_lock);
365 if (!list_empty(&inf->active))
366 list_del(&inf->active);
367 if (!list_empty(&inf->expiring))
368 list_del(&inf->expiring);
369 spin_unlock(&sbi->lookup_lock);
375 autofs4_free_ino(inf);
379 /* For dentries of directories in the root dir */
380 static struct dentry_operations autofs4_root_dentry_operations = {
381 .d_revalidate = autofs4_revalidate,
382 .d_release = autofs4_dentry_release,
385 /* For other dentries */
386 static struct dentry_operations autofs4_dentry_operations = {
387 .d_revalidate = autofs4_revalidate,
388 .d_release = autofs4_dentry_release,
391 static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
393 unsigned int len = name->len;
394 unsigned int hash = name->hash;
395 const unsigned char *str = name->name;
396 struct list_head *p, *head;
398 spin_lock(&dcache_lock);
399 spin_lock(&sbi->lookup_lock);
400 head = &sbi->active_list;
401 list_for_each(p, head) {
402 struct autofs_info *ino;
403 struct dentry *dentry;
406 ino = list_entry(p, struct autofs_info, active);
407 dentry = ino->dentry;
409 spin_lock(&dentry->d_lock);
412 if (atomic_read(&dentry->d_count) == 0)
415 qstr = &dentry->d_name;
417 if (dentry->d_name.hash != hash)
419 if (dentry->d_parent != parent)
422 if (qstr->len != len)
424 if (memcmp(qstr->name, str, len))
427 if (d_unhashed(dentry)) {
429 spin_unlock(&dentry->d_lock);
430 spin_unlock(&sbi->lookup_lock);
431 spin_unlock(&dcache_lock);
435 spin_unlock(&dentry->d_lock);
437 spin_unlock(&sbi->lookup_lock);
438 spin_unlock(&dcache_lock);
443 static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
445 unsigned int len = name->len;
446 unsigned int hash = name->hash;
447 const unsigned char *str = name->name;
448 struct list_head *p, *head;
450 spin_lock(&dcache_lock);
451 spin_lock(&sbi->lookup_lock);
452 head = &sbi->expiring_list;
453 list_for_each(p, head) {
454 struct autofs_info *ino;
455 struct dentry *dentry;
458 ino = list_entry(p, struct autofs_info, expiring);
459 dentry = ino->dentry;
461 spin_lock(&dentry->d_lock);
463 /* Bad luck, we've already been dentry_iput */
464 if (!dentry->d_inode)
467 qstr = &dentry->d_name;
469 if (dentry->d_name.hash != hash)
471 if (dentry->d_parent != parent)
474 if (qstr->len != len)
476 if (memcmp(qstr->name, str, len))
479 if (d_unhashed(dentry)) {
481 spin_unlock(&dentry->d_lock);
482 spin_unlock(&sbi->lookup_lock);
483 spin_unlock(&dcache_lock);
487 spin_unlock(&dentry->d_lock);
489 spin_unlock(&sbi->lookup_lock);
490 spin_unlock(&dcache_lock);
495 /* Lookups in the root directory */
496 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
498 struct autofs_sb_info *sbi;
499 struct autofs_info *ino;
500 struct dentry *expiring, *unhashed;
503 DPRINTK("name = %.*s",
504 dentry->d_name.len, dentry->d_name.name);
506 /* File name too long to exist */
507 if (dentry->d_name.len > NAME_MAX)
508 return ERR_PTR(-ENAMETOOLONG);
510 sbi = autofs4_sbi(dir->i_sb);
511 oz_mode = autofs4_oz_mode(sbi);
513 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
514 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
516 expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
519 * If we are racing with expire the request might not
520 * be quite complete but the directory has been removed
521 * so it must have been successful, so just wait for it.
523 ino = autofs4_dentry_ino(expiring);
524 while (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
525 DPRINTK("wait for incomplete expire %p name=%.*s",
526 expiring, expiring->d_name.len,
527 expiring->d_name.name);
528 autofs4_wait(sbi, expiring, NFY_NONE);
529 DPRINTK("request completed");
531 spin_lock(&sbi->lookup_lock);
532 if (!list_empty(&ino->expiring))
533 list_del_init(&ino->expiring);
534 spin_unlock(&sbi->lookup_lock);
538 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
543 * Mark the dentry incomplete but don't hash it. We do this
544 * to serialize our inode creation operations (symlink and
545 * mkdir) which prevents deadlock during the callback to
546 * the daemon. Subsequent user space lookups for the same
547 * dentry are placed on the wait queue while the daemon
548 * itself is allowed passage unresticted so the create
549 * operation itself can then hash the dentry. Finally,
550 * we check for the hashed dentry and return the newly
553 dentry->d_op = &autofs4_root_dentry_operations;
556 * And we need to ensure that the same dentry is used for
557 * all following lookup calls until it is hashed so that
558 * the dentry flags are persistent throughout the request.
560 ino = autofs4_init_ino(NULL, sbi, 0555);
562 return ERR_PTR(-ENOMEM);
564 dentry->d_fsdata = ino;
565 ino->dentry = dentry;
567 spin_lock(&sbi->lookup_lock);
568 list_add(&ino->active, &sbi->active_list);
569 spin_unlock(&sbi->lookup_lock);
571 d_instantiate(dentry, NULL);
575 spin_lock(&dentry->d_lock);
576 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
577 spin_unlock(&dentry->d_lock);
578 if (dentry->d_op && dentry->d_op->d_revalidate) {
579 mutex_unlock(&dir->i_mutex);
580 (dentry->d_op->d_revalidate)(dentry, nd);
581 mutex_lock(&dir->i_mutex);
586 * If we are still pending, check if we had to handle
587 * a signal. If so we can force a restart..
589 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
590 /* See if we were interrupted */
591 if (signal_pending(current)) {
592 sigset_t *sigset = ¤t->pending.signal;
593 if (sigismember (sigset, SIGKILL) ||
594 sigismember (sigset, SIGQUIT) ||
595 sigismember (sigset, SIGINT)) {
598 return ERR_PTR(-ERESTARTNOINTR);
602 spin_lock(&dentry->d_lock);
603 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
604 spin_unlock(&dentry->d_lock);
609 * If this dentry is unhashed, then we shouldn't honour this
610 * lookup. Returning ENOENT here doesn't do the right thing
611 * for all system calls, but it should be OK for the operations
612 * we permit from an autofs.
614 if (!oz_mode && d_unhashed(dentry)) {
616 * A user space application can (and has done in the past)
617 * remove and re-create this directory during the callback.
618 * This can leave us with an unhashed dentry, but a
619 * successful mount! So we need to perform another
620 * cached lookup in case the dentry now exists.
622 struct dentry *parent = dentry->d_parent;
623 struct dentry *new = d_lookup(parent, &dentry->d_name);
627 dentry = ERR_PTR(-ENOENT);
641 static int autofs4_dir_symlink(struct inode *dir,
642 struct dentry *dentry,
645 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
646 struct autofs_info *ino = autofs4_dentry_ino(dentry);
647 struct autofs_info *p_ino;
651 DPRINTK("%s <- %.*s", symname,
652 dentry->d_name.len, dentry->d_name.name);
654 if (!autofs4_oz_mode(sbi))
657 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
661 spin_lock(&sbi->lookup_lock);
662 if (!list_empty(&ino->active))
663 list_del_init(&ino->active);
664 spin_unlock(&sbi->lookup_lock);
666 ino->size = strlen(symname);
667 cp = kmalloc(ino->size + 1, GFP_KERNEL);
669 if (!dentry->d_fsdata)
676 inode = autofs4_get_inode(dir->i_sb, ino);
679 if (!dentry->d_fsdata)
683 d_add(dentry, inode);
685 if (dir == dir->i_sb->s_root->d_inode)
686 dentry->d_op = &autofs4_root_dentry_operations;
688 dentry->d_op = &autofs4_dentry_operations;
690 dentry->d_fsdata = ino;
691 ino->dentry = dget(dentry);
692 atomic_inc(&ino->count);
693 p_ino = autofs4_dentry_ino(dentry->d_parent);
694 if (p_ino && dentry->d_parent != dentry)
695 atomic_inc(&p_ino->count);
699 dir->i_mtime = CURRENT_TIME;
707 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
708 * that the file no longer exists. However, doing that means that the
709 * VFS layer can turn the dentry into a negative dentry. We don't want
710 * this, because the unlink is probably the result of an expire.
711 * We simply d_drop it and add it to a expiring list in the super block,
712 * which allows the dentry lookup to check for an incomplete expire.
714 * If a process is blocked on the dentry waiting for the expire to finish,
715 * it will invalidate the dentry and try to mount with a new one.
717 * Also see autofs4_dir_rmdir()..
719 static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
721 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
722 struct autofs_info *ino = autofs4_dentry_ino(dentry);
723 struct autofs_info *p_ino;
725 /* This allows root to remove symlinks */
726 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
729 if (atomic_dec_and_test(&ino->count)) {
730 p_ino = autofs4_dentry_ino(dentry->d_parent);
731 if (p_ino && dentry->d_parent != dentry)
732 atomic_dec(&p_ino->count);
736 dentry->d_inode->i_size = 0;
737 clear_nlink(dentry->d_inode);
739 dir->i_mtime = CURRENT_TIME;
741 spin_lock(&dcache_lock);
742 spin_lock(&sbi->lookup_lock);
743 if (list_empty(&ino->expiring))
744 list_add(&ino->expiring, &sbi->expiring_list);
745 spin_unlock(&sbi->lookup_lock);
746 spin_lock(&dentry->d_lock);
748 spin_unlock(&dentry->d_lock);
749 spin_unlock(&dcache_lock);
754 static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
756 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
757 struct autofs_info *ino = autofs4_dentry_ino(dentry);
758 struct autofs_info *p_ino;
760 DPRINTK("dentry %p, removing %.*s",
761 dentry, dentry->d_name.len, dentry->d_name.name);
763 if (!autofs4_oz_mode(sbi))
766 spin_lock(&dcache_lock);
767 if (!list_empty(&dentry->d_subdirs)) {
768 spin_unlock(&dcache_lock);
771 spin_lock(&sbi->lookup_lock);
772 if (list_empty(&ino->expiring))
773 list_add(&ino->expiring, &sbi->expiring_list);
774 spin_unlock(&sbi->lookup_lock);
775 spin_lock(&dentry->d_lock);
777 spin_unlock(&dentry->d_lock);
778 spin_unlock(&dcache_lock);
780 if (atomic_dec_and_test(&ino->count)) {
781 p_ino = autofs4_dentry_ino(dentry->d_parent);
782 if (p_ino && dentry->d_parent != dentry)
783 atomic_dec(&p_ino->count);
786 dentry->d_inode->i_size = 0;
787 clear_nlink(dentry->d_inode);
795 static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
797 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
798 struct autofs_info *ino = autofs4_dentry_ino(dentry);
799 struct autofs_info *p_ino;
802 if (!autofs4_oz_mode(sbi))
805 DPRINTK("dentry %p, creating %.*s",
806 dentry, dentry->d_name.len, dentry->d_name.name);
808 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
812 spin_lock(&sbi->lookup_lock);
813 if (!list_empty(&ino->active))
814 list_del_init(&ino->active);
815 spin_unlock(&sbi->lookup_lock);
817 inode = autofs4_get_inode(dir->i_sb, ino);
819 if (!dentry->d_fsdata)
823 d_add(dentry, inode);
825 if (dir == dir->i_sb->s_root->d_inode)
826 dentry->d_op = &autofs4_root_dentry_operations;
828 dentry->d_op = &autofs4_dentry_operations;
830 dentry->d_fsdata = ino;
831 ino->dentry = dget(dentry);
832 atomic_inc(&ino->count);
833 p_ino = autofs4_dentry_ino(dentry->d_parent);
834 if (p_ino && dentry->d_parent != dentry)
835 atomic_inc(&p_ino->count);
838 dir->i_mtime = CURRENT_TIME;
843 /* Get/set timeout ioctl() operation */
844 static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
845 unsigned long __user *p)
848 unsigned long ntimeout;
850 if ((rv = get_user(ntimeout, p)) ||
851 (rv = put_user(sbi->exp_timeout/HZ, p)))
854 if (ntimeout > ULONG_MAX/HZ)
855 sbi->exp_timeout = 0;
857 sbi->exp_timeout = ntimeout * HZ;
862 /* Return protocol version */
863 static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
865 return put_user(sbi->version, p);
868 /* Return protocol sub version */
869 static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
871 return put_user(sbi->sub_version, p);
875 * Tells the daemon whether we need to reghost or not. Also, clears
876 * the reghost_needed flag.
878 static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
882 DPRINTK("returning %d", sbi->needs_reghost);
884 status = put_user(sbi->needs_reghost, p);
888 sbi->needs_reghost = 0;
893 * Enable / Disable reghosting ioctl() operation
895 static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
900 status = get_user(val, p);
902 DPRINTK("reghost = %d", val);
907 /* turn on/off reghosting, with the val */
908 sbi->reghost_enabled = val;
913 * Tells the daemon whether it can umount the autofs mount.
915 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
922 DPRINTK("returning %d", status);
924 status = put_user(status, p);
929 /* Identify autofs4_dentries - this is so we can tell if there's
930 an extra dentry refcount or not. We only hold a refcount on the
931 dentry if its non-negative (ie, d_inode != NULL)
933 int is_autofs4_dentry(struct dentry *dentry)
935 return dentry && dentry->d_inode &&
936 (dentry->d_op == &autofs4_root_dentry_operations ||
937 dentry->d_op == &autofs4_dentry_operations) &&
938 dentry->d_fsdata != NULL;
942 * ioctl()'s on the root directory is the chief method for the daemon to
943 * generate kernel reactions
945 static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
946 unsigned int cmd, unsigned long arg)
948 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
949 void __user *p = (void __user *)arg;
951 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
952 cmd,arg,sbi,task_pgrp_nr(current));
954 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
955 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
958 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
962 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
963 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
964 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
965 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
966 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
967 autofs4_catatonic_mode(sbi);
969 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
970 return autofs4_get_protover(sbi, p);
971 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
972 return autofs4_get_protosubver(sbi, p);
973 case AUTOFS_IOC_SETTIMEOUT:
974 return autofs4_get_set_timeout(sbi, p);
976 case AUTOFS_IOC_TOGGLEREGHOST:
977 return autofs4_toggle_reghost(sbi, p);
978 case AUTOFS_IOC_ASKREGHOST:
979 return autofs4_ask_reghost(sbi, p);
981 case AUTOFS_IOC_ASKUMOUNT:
982 return autofs4_ask_umount(filp->f_path.mnt, p);
984 /* return a single thing to expire */
985 case AUTOFS_IOC_EXPIRE:
986 return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p);
987 /* same as above, but can send multiple expires through pipe */
988 case AUTOFS_IOC_EXPIRE_MULTI:
989 return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p);