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 struct dentry
*autofs4_lookup(struct inode
*,struct dentry
*, struct nameidata
*);
29 static void *autofs4_follow_link(struct dentry
*, struct nameidata
*);
31 #define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
32 #define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
34 const struct file_operations autofs4_root_operations
= {
35 .open
= dcache_dir_open
,
36 .release
= dcache_dir_close
,
37 .read
= generic_read_dir
,
38 .readdir
= dcache_readdir
,
39 .ioctl
= autofs4_root_ioctl
,
42 const struct file_operations autofs4_dir_operations
= {
43 .open
= autofs4_dir_open
,
44 .release
= dcache_dir_close
,
45 .read
= generic_read_dir
,
46 .readdir
= dcache_readdir
,
49 const struct inode_operations autofs4_indirect_root_inode_operations
= {
50 .lookup
= autofs4_lookup
,
51 .unlink
= autofs4_dir_unlink
,
52 .symlink
= autofs4_dir_symlink
,
53 .mkdir
= autofs4_dir_mkdir
,
54 .rmdir
= autofs4_dir_rmdir
,
57 const struct inode_operations autofs4_direct_root_inode_operations
= {
58 .lookup
= autofs4_lookup
,
59 .unlink
= autofs4_dir_unlink
,
60 .mkdir
= autofs4_dir_mkdir
,
61 .rmdir
= autofs4_dir_rmdir
,
62 .follow_link
= autofs4_follow_link
,
65 const struct inode_operations autofs4_dir_inode_operations
= {
66 .lookup
= autofs4_lookup
,
67 .unlink
= autofs4_dir_unlink
,
68 .symlink
= autofs4_dir_symlink
,
69 .mkdir
= autofs4_dir_mkdir
,
70 .rmdir
= autofs4_dir_rmdir
,
73 static int autofs4_dir_open(struct inode
*inode
, struct file
*file
)
75 struct dentry
*dentry
= file
->f_path
.dentry
;
76 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
78 DPRINTK("file=%p dentry=%p %.*s",
79 file
, dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
81 if (autofs4_oz_mode(sbi
))
85 * An empty directory in an autofs file system is always a
86 * mount point. The daemon must have failed to mount this
87 * during lookup so it doesn't exist. This can happen, for
88 * example, if user space returns an incorrect status for a
89 * mount request. Otherwise we're doing a readdir on the
90 * autofs file system so just let the libfs routines handle
93 spin_lock(&dcache_lock
);
94 if (!d_mountpoint(dentry
) && __simple_empty(dentry
)) {
95 spin_unlock(&dcache_lock
);
98 spin_unlock(&dcache_lock
);
101 return dcache_dir_open(inode
, file
);
104 static int try_to_fill_dentry(struct dentry
*dentry
, int flags
)
106 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
107 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
110 DPRINTK("dentry=%p %.*s ino=%p",
111 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
, dentry
->d_inode
);
114 * Wait for a pending mount, triggering one if there
117 if (dentry
->d_inode
== NULL
) {
118 DPRINTK("waiting for mount name=%.*s",
119 dentry
->d_name
.len
, dentry
->d_name
.name
);
121 status
= autofs4_wait(sbi
, dentry
, NFY_MOUNT
);
123 DPRINTK("mount done status=%d", status
);
125 /* Turn this into a real negative dentry? */
126 if (status
== -ENOENT
) {
127 spin_lock(&dentry
->d_lock
);
128 dentry
->d_flags
&= ~DCACHE_AUTOFS_PENDING
;
129 spin_unlock(&dentry
->d_lock
);
132 /* Return a negative dentry, but leave it "pending" */
135 /* Trigger mount for path component or follow link */
136 } else if (dentry
->d_flags
& DCACHE_AUTOFS_PENDING
||
137 flags
& (TRIGGER_FLAGS
| TRIGGER_INTENTS
) ||
138 current
->link_count
) {
139 DPRINTK("waiting for mount name=%.*s",
140 dentry
->d_name
.len
, dentry
->d_name
.name
);
142 spin_lock(&dentry
->d_lock
);
143 dentry
->d_flags
|= DCACHE_AUTOFS_PENDING
;
144 spin_unlock(&dentry
->d_lock
);
145 status
= autofs4_wait(sbi
, dentry
, NFY_MOUNT
);
147 DPRINTK("mount done status=%d", status
);
150 spin_lock(&dentry
->d_lock
);
151 dentry
->d_flags
&= ~DCACHE_AUTOFS_PENDING
;
152 spin_unlock(&dentry
->d_lock
);
157 /* Initialize expiry counter after successful mount */
159 ino
->last_used
= jiffies
;
161 spin_lock(&dentry
->d_lock
);
162 dentry
->d_flags
&= ~DCACHE_AUTOFS_PENDING
;
163 spin_unlock(&dentry
->d_lock
);
168 /* For autofs direct mounts the follow link triggers the mount */
169 static void *autofs4_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
171 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
172 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
173 int oz_mode
= autofs4_oz_mode(sbi
);
174 unsigned int lookup_type
;
177 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
178 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
, oz_mode
,
181 * For an expire of a covered direct or offset mount we need
182 * to beeak out of follow_down() at the autofs mount trigger
183 * (d_mounted--), so we can see the expiring flag, and manage
184 * the blocking and following here until the expire is completed.
187 spin_lock(&sbi
->fs_lock
);
188 if (ino
->flags
& AUTOFS_INF_EXPIRING
) {
189 spin_unlock(&sbi
->fs_lock
);
190 /* Follow down to our covering mount. */
191 if (!follow_down(&nd
->path
.mnt
, &nd
->path
.dentry
))
195 spin_unlock(&sbi
->fs_lock
);
199 /* If an expire request is pending everyone must wait. */
200 autofs4_expire_wait(dentry
);
202 /* We trigger a mount for almost all flags */
203 lookup_type
= nd
->flags
& (TRIGGER_FLAGS
| TRIGGER_INTENTS
);
204 if (!(lookup_type
|| dentry
->d_flags
& DCACHE_AUTOFS_PENDING
))
208 * If the dentry contains directories then it is an autofs
209 * multi-mount with no root mount offset. So don't try to
212 spin_lock(&dcache_lock
);
213 if (dentry
->d_flags
& DCACHE_AUTOFS_PENDING
||
214 (!d_mountpoint(dentry
) && __simple_empty(dentry
))) {
215 spin_unlock(&dcache_lock
);
217 status
= try_to_fill_dentry(dentry
, 0);
223 spin_unlock(&dcache_lock
);
226 * If there is no root mount it must be an autofs
227 * multi-mount with no root offset so we don't need
230 if (d_mountpoint(dentry
)) {
231 if (!autofs4_follow_mount(&nd
->path
.mnt
,
243 return ERR_PTR(status
);
247 * Revalidate is called on every cache lookup. Some of those
248 * cache lookups may actually happen while the dentry is not
249 * yet completely filled in, and revalidate has to delay such
252 static int autofs4_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
254 struct inode
*dir
= dentry
->d_parent
->d_inode
;
255 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
256 int oz_mode
= autofs4_oz_mode(sbi
);
257 int flags
= nd
? nd
->flags
: 0;
261 spin_lock(&sbi
->fs_lock
);
262 if (autofs4_ispending(dentry
)) {
263 /* The daemon never causes a mount to trigger */
264 spin_unlock(&sbi
->fs_lock
);
270 * If the directory has gone away due to an expire
271 * we have been called as ->d_revalidate() and so
272 * we need to return false and proceed to ->lookup().
274 if (autofs4_expire_wait(dentry
) == -EAGAIN
)
278 * A zero status is success otherwise we have a
279 * negative error code.
281 status
= try_to_fill_dentry(dentry
, flags
);
287 spin_unlock(&sbi
->fs_lock
);
289 /* Negative dentry.. invalidate if "old" */
290 if (dentry
->d_inode
== NULL
)
293 /* Check for a non-mountpoint directory with no contents */
294 spin_lock(&dcache_lock
);
295 if (S_ISDIR(dentry
->d_inode
->i_mode
) &&
296 !d_mountpoint(dentry
) &&
297 __simple_empty(dentry
)) {
298 DPRINTK("dentry=%p %.*s, emptydir",
299 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
300 spin_unlock(&dcache_lock
);
302 /* The daemon never causes a mount to trigger */
307 * A zero status is success otherwise we have a
308 * negative error code.
310 status
= try_to_fill_dentry(dentry
, flags
);
316 spin_unlock(&dcache_lock
);
321 void autofs4_dentry_release(struct dentry
*de
)
323 struct autofs_info
*inf
;
325 DPRINTK("releasing %p", de
);
327 inf
= autofs4_dentry_ino(de
);
331 struct autofs_sb_info
*sbi
= autofs4_sbi(de
->d_sb
);
334 spin_lock(&sbi
->lookup_lock
);
335 if (!list_empty(&inf
->active
))
336 list_del(&inf
->active
);
337 if (!list_empty(&inf
->expiring
))
338 list_del(&inf
->expiring
);
339 spin_unlock(&sbi
->lookup_lock
);
345 autofs4_free_ino(inf
);
349 /* For dentries of directories in the root dir */
350 static struct dentry_operations autofs4_root_dentry_operations
= {
351 .d_revalidate
= autofs4_revalidate
,
352 .d_release
= autofs4_dentry_release
,
355 /* For other dentries */
356 static struct dentry_operations autofs4_dentry_operations
= {
357 .d_revalidate
= autofs4_revalidate
,
358 .d_release
= autofs4_dentry_release
,
361 static struct dentry
*autofs4_lookup_active(struct autofs_sb_info
*sbi
, struct dentry
*parent
, struct qstr
*name
)
363 unsigned int len
= name
->len
;
364 unsigned int hash
= name
->hash
;
365 const unsigned char *str
= name
->name
;
366 struct list_head
*p
, *head
;
368 spin_lock(&dcache_lock
);
369 spin_lock(&sbi
->lookup_lock
);
370 head
= &sbi
->active_list
;
371 list_for_each(p
, head
) {
372 struct autofs_info
*ino
;
373 struct dentry
*dentry
;
376 ino
= list_entry(p
, struct autofs_info
, active
);
377 dentry
= ino
->dentry
;
379 spin_lock(&dentry
->d_lock
);
382 if (atomic_read(&dentry
->d_count
) == 0)
385 qstr
= &dentry
->d_name
;
387 if (dentry
->d_name
.hash
!= hash
)
389 if (dentry
->d_parent
!= parent
)
392 if (qstr
->len
!= len
)
394 if (memcmp(qstr
->name
, str
, len
))
397 if (d_unhashed(dentry
)) {
399 spin_unlock(&dentry
->d_lock
);
400 spin_unlock(&sbi
->lookup_lock
);
401 spin_unlock(&dcache_lock
);
405 spin_unlock(&dentry
->d_lock
);
407 spin_unlock(&sbi
->lookup_lock
);
408 spin_unlock(&dcache_lock
);
413 static struct dentry
*autofs4_lookup_expiring(struct autofs_sb_info
*sbi
, struct dentry
*parent
, struct qstr
*name
)
415 unsigned int len
= name
->len
;
416 unsigned int hash
= name
->hash
;
417 const unsigned char *str
= name
->name
;
418 struct list_head
*p
, *head
;
420 spin_lock(&dcache_lock
);
421 spin_lock(&sbi
->lookup_lock
);
422 head
= &sbi
->expiring_list
;
423 list_for_each(p
, head
) {
424 struct autofs_info
*ino
;
425 struct dentry
*dentry
;
428 ino
= list_entry(p
, struct autofs_info
, expiring
);
429 dentry
= ino
->dentry
;
431 spin_lock(&dentry
->d_lock
);
433 /* Bad luck, we've already been dentry_iput */
434 if (!dentry
->d_inode
)
437 qstr
= &dentry
->d_name
;
439 if (dentry
->d_name
.hash
!= hash
)
441 if (dentry
->d_parent
!= parent
)
444 if (qstr
->len
!= len
)
446 if (memcmp(qstr
->name
, str
, len
))
449 if (d_unhashed(dentry
)) {
451 spin_unlock(&dentry
->d_lock
);
452 spin_unlock(&sbi
->lookup_lock
);
453 spin_unlock(&dcache_lock
);
457 spin_unlock(&dentry
->d_lock
);
459 spin_unlock(&sbi
->lookup_lock
);
460 spin_unlock(&dcache_lock
);
465 /* Lookups in the root directory */
466 static struct dentry
*autofs4_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
468 struct autofs_sb_info
*sbi
;
469 struct autofs_info
*ino
;
470 struct dentry
*expiring
, *unhashed
;
473 DPRINTK("name = %.*s",
474 dentry
->d_name
.len
, dentry
->d_name
.name
);
476 /* File name too long to exist */
477 if (dentry
->d_name
.len
> NAME_MAX
)
478 return ERR_PTR(-ENAMETOOLONG
);
480 sbi
= autofs4_sbi(dir
->i_sb
);
481 oz_mode
= autofs4_oz_mode(sbi
);
483 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
484 current
->pid
, task_pgrp_nr(current
), sbi
->catatonic
, oz_mode
);
486 expiring
= autofs4_lookup_expiring(sbi
, dentry
->d_parent
, &dentry
->d_name
);
489 * If we are racing with expire the request might not
490 * be quite complete but the directory has been removed
491 * so it must have been successful, so just wait for it.
493 ino
= autofs4_dentry_ino(expiring
);
494 autofs4_expire_wait(expiring
);
495 spin_lock(&sbi
->lookup_lock
);
496 if (!list_empty(&ino
->expiring
))
497 list_del_init(&ino
->expiring
);
498 spin_unlock(&sbi
->lookup_lock
);
502 unhashed
= autofs4_lookup_active(sbi
, dentry
->d_parent
, &dentry
->d_name
);
507 * Mark the dentry incomplete but don't hash it. We do this
508 * to serialize our inode creation operations (symlink and
509 * mkdir) which prevents deadlock during the callback to
510 * the daemon. Subsequent user space lookups for the same
511 * dentry are placed on the wait queue while the daemon
512 * itself is allowed passage unresticted so the create
513 * operation itself can then hash the dentry. Finally,
514 * we check for the hashed dentry and return the newly
517 dentry
->d_op
= &autofs4_root_dentry_operations
;
520 * And we need to ensure that the same dentry is used for
521 * all following lookup calls until it is hashed so that
522 * the dentry flags are persistent throughout the request.
524 ino
= autofs4_init_ino(NULL
, sbi
, 0555);
526 return ERR_PTR(-ENOMEM
);
528 dentry
->d_fsdata
= ino
;
529 ino
->dentry
= dentry
;
531 spin_lock(&sbi
->lookup_lock
);
532 list_add(&ino
->active
, &sbi
->active_list
);
533 spin_unlock(&sbi
->lookup_lock
);
535 d_instantiate(dentry
, NULL
);
539 spin_lock(&dentry
->d_lock
);
540 dentry
->d_flags
|= DCACHE_AUTOFS_PENDING
;
541 spin_unlock(&dentry
->d_lock
);
542 if (dentry
->d_op
&& dentry
->d_op
->d_revalidate
) {
543 mutex_unlock(&dir
->i_mutex
);
544 (dentry
->d_op
->d_revalidate
)(dentry
, nd
);
545 mutex_lock(&dir
->i_mutex
);
550 * If we are still pending, check if we had to handle
551 * a signal. If so we can force a restart..
553 if (dentry
->d_flags
& DCACHE_AUTOFS_PENDING
) {
554 /* See if we were interrupted */
555 if (signal_pending(current
)) {
556 sigset_t
*sigset
= ¤t
->pending
.signal
;
557 if (sigismember (sigset
, SIGKILL
) ||
558 sigismember (sigset
, SIGQUIT
) ||
559 sigismember (sigset
, SIGINT
)) {
562 return ERR_PTR(-ERESTARTNOINTR
);
566 spin_lock(&dentry
->d_lock
);
567 dentry
->d_flags
&= ~DCACHE_AUTOFS_PENDING
;
568 spin_unlock(&dentry
->d_lock
);
573 * If this dentry is unhashed, then we shouldn't honour this
574 * lookup. Returning ENOENT here doesn't do the right thing
575 * for all system calls, but it should be OK for the operations
576 * we permit from an autofs.
578 if (!oz_mode
&& d_unhashed(dentry
)) {
580 * A user space application can (and has done in the past)
581 * remove and re-create this directory during the callback.
582 * This can leave us with an unhashed dentry, but a
583 * successful mount! So we need to perform another
584 * cached lookup in case the dentry now exists.
586 struct dentry
*parent
= dentry
->d_parent
;
587 struct dentry
*new = d_lookup(parent
, &dentry
->d_name
);
591 dentry
= ERR_PTR(-ENOENT
);
605 static int autofs4_dir_symlink(struct inode
*dir
,
606 struct dentry
*dentry
,
609 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
610 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
611 struct autofs_info
*p_ino
;
615 DPRINTK("%s <- %.*s", symname
,
616 dentry
->d_name
.len
, dentry
->d_name
.name
);
618 if (!autofs4_oz_mode(sbi
))
621 ino
= autofs4_init_ino(ino
, sbi
, S_IFLNK
| 0555);
625 spin_lock(&sbi
->lookup_lock
);
626 if (!list_empty(&ino
->active
))
627 list_del_init(&ino
->active
);
628 spin_unlock(&sbi
->lookup_lock
);
630 ino
->size
= strlen(symname
);
631 cp
= kmalloc(ino
->size
+ 1, GFP_KERNEL
);
633 if (!dentry
->d_fsdata
)
640 inode
= autofs4_get_inode(dir
->i_sb
, ino
);
643 if (!dentry
->d_fsdata
)
647 d_add(dentry
, inode
);
649 if (dir
== dir
->i_sb
->s_root
->d_inode
)
650 dentry
->d_op
= &autofs4_root_dentry_operations
;
652 dentry
->d_op
= &autofs4_dentry_operations
;
654 dentry
->d_fsdata
= ino
;
655 ino
->dentry
= dget(dentry
);
656 atomic_inc(&ino
->count
);
657 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
658 if (p_ino
&& dentry
->d_parent
!= dentry
)
659 atomic_inc(&p_ino
->count
);
663 dir
->i_mtime
= CURRENT_TIME
;
671 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
672 * that the file no longer exists. However, doing that means that the
673 * VFS layer can turn the dentry into a negative dentry. We don't want
674 * this, because the unlink is probably the result of an expire.
675 * We simply d_drop it and add it to a expiring list in the super block,
676 * which allows the dentry lookup to check for an incomplete expire.
678 * If a process is blocked on the dentry waiting for the expire to finish,
679 * it will invalidate the dentry and try to mount with a new one.
681 * Also see autofs4_dir_rmdir()..
683 static int autofs4_dir_unlink(struct inode
*dir
, struct dentry
*dentry
)
685 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
686 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
687 struct autofs_info
*p_ino
;
689 /* This allows root to remove symlinks */
690 if (!autofs4_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
693 if (atomic_dec_and_test(&ino
->count
)) {
694 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
695 if (p_ino
&& dentry
->d_parent
!= dentry
)
696 atomic_dec(&p_ino
->count
);
700 dentry
->d_inode
->i_size
= 0;
701 clear_nlink(dentry
->d_inode
);
703 dir
->i_mtime
= CURRENT_TIME
;
705 spin_lock(&dcache_lock
);
706 spin_lock(&sbi
->lookup_lock
);
707 if (list_empty(&ino
->expiring
))
708 list_add(&ino
->expiring
, &sbi
->expiring_list
);
709 spin_unlock(&sbi
->lookup_lock
);
710 spin_lock(&dentry
->d_lock
);
712 spin_unlock(&dentry
->d_lock
);
713 spin_unlock(&dcache_lock
);
718 static int autofs4_dir_rmdir(struct inode
*dir
, struct dentry
*dentry
)
720 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
721 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
722 struct autofs_info
*p_ino
;
724 DPRINTK("dentry %p, removing %.*s",
725 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
727 if (!autofs4_oz_mode(sbi
))
730 spin_lock(&dcache_lock
);
731 if (!list_empty(&dentry
->d_subdirs
)) {
732 spin_unlock(&dcache_lock
);
735 spin_lock(&sbi
->lookup_lock
);
736 if (list_empty(&ino
->expiring
))
737 list_add(&ino
->expiring
, &sbi
->expiring_list
);
738 spin_unlock(&sbi
->lookup_lock
);
739 spin_lock(&dentry
->d_lock
);
741 spin_unlock(&dentry
->d_lock
);
742 spin_unlock(&dcache_lock
);
744 if (atomic_dec_and_test(&ino
->count
)) {
745 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
746 if (p_ino
&& dentry
->d_parent
!= dentry
)
747 atomic_dec(&p_ino
->count
);
750 dentry
->d_inode
->i_size
= 0;
751 clear_nlink(dentry
->d_inode
);
759 static int autofs4_dir_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
761 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
762 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
763 struct autofs_info
*p_ino
;
766 if (!autofs4_oz_mode(sbi
))
769 DPRINTK("dentry %p, creating %.*s",
770 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
772 ino
= autofs4_init_ino(ino
, sbi
, S_IFDIR
| 0555);
776 spin_lock(&sbi
->lookup_lock
);
777 if (!list_empty(&ino
->active
))
778 list_del_init(&ino
->active
);
779 spin_unlock(&sbi
->lookup_lock
);
781 inode
= autofs4_get_inode(dir
->i_sb
, ino
);
783 if (!dentry
->d_fsdata
)
787 d_add(dentry
, inode
);
789 if (dir
== dir
->i_sb
->s_root
->d_inode
)
790 dentry
->d_op
= &autofs4_root_dentry_operations
;
792 dentry
->d_op
= &autofs4_dentry_operations
;
794 dentry
->d_fsdata
= ino
;
795 ino
->dentry
= dget(dentry
);
796 atomic_inc(&ino
->count
);
797 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
798 if (p_ino
&& dentry
->d_parent
!= dentry
)
799 atomic_inc(&p_ino
->count
);
802 dir
->i_mtime
= CURRENT_TIME
;
807 /* Get/set timeout ioctl() operation */
808 static inline int autofs4_get_set_timeout(struct autofs_sb_info
*sbi
,
809 unsigned long __user
*p
)
812 unsigned long ntimeout
;
814 if ((rv
= get_user(ntimeout
, p
)) ||
815 (rv
= put_user(sbi
->exp_timeout
/HZ
, p
)))
818 if (ntimeout
> ULONG_MAX
/HZ
)
819 sbi
->exp_timeout
= 0;
821 sbi
->exp_timeout
= ntimeout
* HZ
;
826 /* Return protocol version */
827 static inline int autofs4_get_protover(struct autofs_sb_info
*sbi
, int __user
*p
)
829 return put_user(sbi
->version
, p
);
832 /* Return protocol sub version */
833 static inline int autofs4_get_protosubver(struct autofs_sb_info
*sbi
, int __user
*p
)
835 return put_user(sbi
->sub_version
, p
);
839 * Tells the daemon whether it can umount the autofs mount.
841 static inline int autofs4_ask_umount(struct vfsmount
*mnt
, int __user
*p
)
848 DPRINTK("returning %d", status
);
850 status
= put_user(status
, p
);
855 /* Identify autofs4_dentries - this is so we can tell if there's
856 an extra dentry refcount or not. We only hold a refcount on the
857 dentry if its non-negative (ie, d_inode != NULL)
859 int is_autofs4_dentry(struct dentry
*dentry
)
861 return dentry
&& dentry
->d_inode
&&
862 (dentry
->d_op
== &autofs4_root_dentry_operations
||
863 dentry
->d_op
== &autofs4_dentry_operations
) &&
864 dentry
->d_fsdata
!= NULL
;
868 * ioctl()'s on the root directory is the chief method for the daemon to
869 * generate kernel reactions
871 static int autofs4_root_ioctl(struct inode
*inode
, struct file
*filp
,
872 unsigned int cmd
, unsigned long arg
)
874 struct autofs_sb_info
*sbi
= autofs4_sbi(inode
->i_sb
);
875 void __user
*p
= (void __user
*)arg
;
877 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
878 cmd
,arg
,sbi
,task_pgrp_nr(current
));
880 if (_IOC_TYPE(cmd
) != _IOC_TYPE(AUTOFS_IOC_FIRST
) ||
881 _IOC_NR(cmd
) - _IOC_NR(AUTOFS_IOC_FIRST
) >= AUTOFS_IOC_COUNT
)
884 if (!autofs4_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
888 case AUTOFS_IOC_READY
: /* Wait queue: go ahead and retry */
889 return autofs4_wait_release(sbi
,(autofs_wqt_t
)arg
,0);
890 case AUTOFS_IOC_FAIL
: /* Wait queue: fail with ENOENT */
891 return autofs4_wait_release(sbi
,(autofs_wqt_t
)arg
,-ENOENT
);
892 case AUTOFS_IOC_CATATONIC
: /* Enter catatonic mode (daemon shutdown) */
893 autofs4_catatonic_mode(sbi
);
895 case AUTOFS_IOC_PROTOVER
: /* Get protocol version */
896 return autofs4_get_protover(sbi
, p
);
897 case AUTOFS_IOC_PROTOSUBVER
: /* Get protocol sub version */
898 return autofs4_get_protosubver(sbi
, p
);
899 case AUTOFS_IOC_SETTIMEOUT
:
900 return autofs4_get_set_timeout(sbi
, p
);
902 case AUTOFS_IOC_ASKUMOUNT
:
903 return autofs4_ask_umount(filp
->f_path
.mnt
, p
);
905 /* return a single thing to expire */
906 case AUTOFS_IOC_EXPIRE
:
907 return autofs4_expire_run(inode
->i_sb
,filp
->f_path
.mnt
,sbi
, p
);
908 /* same as above, but can send multiple expires through pipe */
909 case AUTOFS_IOC_EXPIRE_MULTI
:
910 return autofs4_expire_multi(inode
->i_sb
,filp
->f_path
.mnt
,sbi
, p
);