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 .llseek
= dcache_dir_lseek
,
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
,
48 .llseek
= dcache_dir_lseek
,
51 const struct inode_operations autofs4_indirect_root_inode_operations
= {
52 .lookup
= autofs4_lookup
,
53 .unlink
= autofs4_dir_unlink
,
54 .symlink
= autofs4_dir_symlink
,
55 .mkdir
= autofs4_dir_mkdir
,
56 .rmdir
= autofs4_dir_rmdir
,
59 const struct inode_operations autofs4_direct_root_inode_operations
= {
60 .lookup
= autofs4_lookup
,
61 .unlink
= autofs4_dir_unlink
,
62 .mkdir
= autofs4_dir_mkdir
,
63 .rmdir
= autofs4_dir_rmdir
,
64 .follow_link
= autofs4_follow_link
,
67 const struct inode_operations autofs4_dir_inode_operations
= {
68 .lookup
= autofs4_lookup
,
69 .unlink
= autofs4_dir_unlink
,
70 .symlink
= autofs4_dir_symlink
,
71 .mkdir
= autofs4_dir_mkdir
,
72 .rmdir
= autofs4_dir_rmdir
,
75 static void autofs4_add_active(struct dentry
*dentry
)
77 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
78 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
80 spin_lock(&sbi
->lookup_lock
);
81 if (!ino
->active_count
) {
82 if (list_empty(&ino
->active
))
83 list_add(&ino
->active
, &sbi
->active_list
);
86 spin_unlock(&sbi
->lookup_lock
);
91 static void autofs4_del_active(struct dentry
*dentry
)
93 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
94 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
96 spin_lock(&sbi
->lookup_lock
);
98 if (!ino
->active_count
) {
99 if (!list_empty(&ino
->active
))
100 list_del_init(&ino
->active
);
102 spin_unlock(&sbi
->lookup_lock
);
107 static unsigned int autofs4_need_mount(unsigned int flags
)
109 unsigned int res
= 0;
110 if (flags
& (TRIGGER_FLAGS
| TRIGGER_INTENTS
))
115 static int autofs4_dir_open(struct inode
*inode
, struct file
*file
)
117 struct dentry
*dentry
= file
->f_path
.dentry
;
118 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
120 DPRINTK("file=%p dentry=%p %.*s",
121 file
, dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
123 if (autofs4_oz_mode(sbi
))
127 * An empty directory in an autofs file system is always a
128 * mount point. The daemon must have failed to mount this
129 * during lookup so it doesn't exist. This can happen, for
130 * example, if user space returns an incorrect status for a
131 * mount request. Otherwise we're doing a readdir on the
132 * autofs file system so just let the libfs routines handle
135 spin_lock(&dcache_lock
);
136 if (!d_mountpoint(dentry
) && list_empty(&dentry
->d_subdirs
)) {
137 spin_unlock(&dcache_lock
);
140 spin_unlock(&dcache_lock
);
143 return dcache_dir_open(inode
, file
);
146 static int try_to_fill_dentry(struct dentry
*dentry
, int flags
)
148 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
149 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
152 DPRINTK("dentry=%p %.*s ino=%p",
153 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
, dentry
->d_inode
);
156 * Wait for a pending mount, triggering one if there
159 if (dentry
->d_inode
== NULL
) {
160 DPRINTK("waiting for mount name=%.*s",
161 dentry
->d_name
.len
, dentry
->d_name
.name
);
163 status
= autofs4_wait(sbi
, dentry
, NFY_MOUNT
);
165 DPRINTK("mount done status=%d", status
);
167 /* Turn this into a real negative dentry? */
168 if (status
== -ENOENT
) {
169 spin_lock(&sbi
->fs_lock
);
170 ino
->flags
&= ~AUTOFS_INF_PENDING
;
171 spin_unlock(&sbi
->fs_lock
);
174 /* Return a negative dentry, but leave it "pending" */
177 /* Trigger mount for path component or follow link */
178 } else if (ino
->flags
& AUTOFS_INF_PENDING
||
179 autofs4_need_mount(flags
) ||
180 current
->link_count
) {
181 DPRINTK("waiting for mount name=%.*s",
182 dentry
->d_name
.len
, dentry
->d_name
.name
);
184 spin_lock(&sbi
->fs_lock
);
185 ino
->flags
|= AUTOFS_INF_PENDING
;
186 spin_unlock(&sbi
->fs_lock
);
187 status
= autofs4_wait(sbi
, dentry
, NFY_MOUNT
);
189 DPRINTK("mount done status=%d", status
);
192 spin_lock(&sbi
->fs_lock
);
193 ino
->flags
&= ~AUTOFS_INF_PENDING
;
194 spin_unlock(&sbi
->fs_lock
);
199 /* Initialize expiry counter after successful mount */
201 ino
->last_used
= jiffies
;
203 spin_lock(&sbi
->fs_lock
);
204 ino
->flags
&= ~AUTOFS_INF_PENDING
;
205 spin_unlock(&sbi
->fs_lock
);
210 /* For autofs direct mounts the follow link triggers the mount */
211 static void *autofs4_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
213 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
214 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
215 int oz_mode
= autofs4_oz_mode(sbi
);
216 unsigned int lookup_type
;
219 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
220 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
, oz_mode
,
223 * For an expire of a covered direct or offset mount we need
224 * to break out of follow_down() at the autofs mount trigger
225 * (d_mounted--), so we can see the expiring flag, and manage
226 * the blocking and following here until the expire is completed.
229 spin_lock(&sbi
->fs_lock
);
230 if (ino
->flags
& AUTOFS_INF_EXPIRING
) {
231 spin_unlock(&sbi
->fs_lock
);
232 /* Follow down to our covering mount. */
233 if (!follow_down(&nd
->path
))
237 spin_unlock(&sbi
->fs_lock
);
241 /* If an expire request is pending everyone must wait. */
242 autofs4_expire_wait(dentry
);
244 /* We trigger a mount for almost all flags */
245 lookup_type
= autofs4_need_mount(nd
->flags
);
246 spin_lock(&sbi
->fs_lock
);
247 spin_lock(&dcache_lock
);
248 if (!(lookup_type
|| ino
->flags
& AUTOFS_INF_PENDING
)) {
249 spin_unlock(&dcache_lock
);
250 spin_unlock(&sbi
->fs_lock
);
255 * If the dentry contains directories then it is an autofs
256 * multi-mount with no root mount offset. So don't try to
259 if (ino
->flags
& AUTOFS_INF_PENDING
||
260 (!d_mountpoint(dentry
) && list_empty(&dentry
->d_subdirs
))) {
261 spin_unlock(&dcache_lock
);
262 spin_unlock(&sbi
->fs_lock
);
264 status
= try_to_fill_dentry(dentry
, 0);
270 spin_unlock(&dcache_lock
);
271 spin_unlock(&sbi
->fs_lock
);
274 * If there is no root mount it must be an autofs
275 * multi-mount with no root offset so we don't need
278 if (d_mountpoint(dentry
)) {
279 if (!autofs4_follow_mount(&nd
->path
)) {
290 return ERR_PTR(status
);
294 * Revalidate is called on every cache lookup. Some of those
295 * cache lookups may actually happen while the dentry is not
296 * yet completely filled in, and revalidate has to delay such
299 static int autofs4_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
301 struct inode
*dir
= dentry
->d_parent
->d_inode
;
302 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
303 int oz_mode
= autofs4_oz_mode(sbi
);
304 int flags
= nd
? nd
->flags
: 0;
308 spin_lock(&sbi
->fs_lock
);
309 if (autofs4_ispending(dentry
)) {
310 /* The daemon never causes a mount to trigger */
311 spin_unlock(&sbi
->fs_lock
);
317 * If the directory has gone away due to an expire
318 * we have been called as ->d_revalidate() and so
319 * we need to return false and proceed to ->lookup().
321 if (autofs4_expire_wait(dentry
) == -EAGAIN
)
325 * A zero status is success otherwise we have a
326 * negative error code.
328 status
= try_to_fill_dentry(dentry
, flags
);
334 spin_unlock(&sbi
->fs_lock
);
336 /* Negative dentry.. invalidate if "old" */
337 if (dentry
->d_inode
== NULL
)
340 /* Check for a non-mountpoint directory with no contents */
341 spin_lock(&dcache_lock
);
342 if (S_ISDIR(dentry
->d_inode
->i_mode
) &&
343 !d_mountpoint(dentry
) && list_empty(&dentry
->d_subdirs
)) {
344 DPRINTK("dentry=%p %.*s, emptydir",
345 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
346 spin_unlock(&dcache_lock
);
348 /* The daemon never causes a mount to trigger */
353 * A zero status is success otherwise we have a
354 * negative error code.
356 status
= try_to_fill_dentry(dentry
, flags
);
362 spin_unlock(&dcache_lock
);
367 void autofs4_dentry_release(struct dentry
*de
)
369 struct autofs_info
*inf
;
371 DPRINTK("releasing %p", de
);
373 inf
= autofs4_dentry_ino(de
);
377 struct autofs_sb_info
*sbi
= autofs4_sbi(de
->d_sb
);
380 spin_lock(&sbi
->lookup_lock
);
381 if (!list_empty(&inf
->active
))
382 list_del(&inf
->active
);
383 if (!list_empty(&inf
->expiring
))
384 list_del(&inf
->expiring
);
385 spin_unlock(&sbi
->lookup_lock
);
391 autofs4_free_ino(inf
);
395 /* For dentries of directories in the root dir */
396 static const struct dentry_operations autofs4_root_dentry_operations
= {
397 .d_revalidate
= autofs4_revalidate
,
398 .d_release
= autofs4_dentry_release
,
401 /* For other dentries */
402 static const struct dentry_operations autofs4_dentry_operations
= {
403 .d_revalidate
= autofs4_revalidate
,
404 .d_release
= autofs4_dentry_release
,
407 static struct dentry
*autofs4_lookup_active(struct dentry
*dentry
)
409 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
410 struct dentry
*parent
= dentry
->d_parent
;
411 struct qstr
*name
= &dentry
->d_name
;
412 unsigned int len
= name
->len
;
413 unsigned int hash
= name
->hash
;
414 const unsigned char *str
= name
->name
;
415 struct list_head
*p
, *head
;
417 spin_lock(&dcache_lock
);
418 spin_lock(&sbi
->lookup_lock
);
419 head
= &sbi
->active_list
;
420 list_for_each(p
, head
) {
421 struct autofs_info
*ino
;
422 struct dentry
*active
;
425 ino
= list_entry(p
, struct autofs_info
, active
);
426 active
= ino
->dentry
;
428 spin_lock(&active
->d_lock
);
431 if (atomic_read(&active
->d_count
) == 0)
434 qstr
= &active
->d_name
;
436 if (active
->d_name
.hash
!= hash
)
438 if (active
->d_parent
!= parent
)
441 if (qstr
->len
!= len
)
443 if (memcmp(qstr
->name
, str
, len
))
446 if (d_unhashed(active
)) {
448 spin_unlock(&active
->d_lock
);
449 spin_unlock(&sbi
->lookup_lock
);
450 spin_unlock(&dcache_lock
);
454 spin_unlock(&active
->d_lock
);
456 spin_unlock(&sbi
->lookup_lock
);
457 spin_unlock(&dcache_lock
);
462 static struct dentry
*autofs4_lookup_expiring(struct dentry
*dentry
)
464 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
465 struct dentry
*parent
= dentry
->d_parent
;
466 struct qstr
*name
= &dentry
->d_name
;
467 unsigned int len
= name
->len
;
468 unsigned int hash
= name
->hash
;
469 const unsigned char *str
= name
->name
;
470 struct list_head
*p
, *head
;
472 spin_lock(&dcache_lock
);
473 spin_lock(&sbi
->lookup_lock
);
474 head
= &sbi
->expiring_list
;
475 list_for_each(p
, head
) {
476 struct autofs_info
*ino
;
477 struct dentry
*expiring
;
480 ino
= list_entry(p
, struct autofs_info
, expiring
);
481 expiring
= ino
->dentry
;
483 spin_lock(&expiring
->d_lock
);
485 /* Bad luck, we've already been dentry_iput */
486 if (!expiring
->d_inode
)
489 qstr
= &expiring
->d_name
;
491 if (expiring
->d_name
.hash
!= hash
)
493 if (expiring
->d_parent
!= parent
)
496 if (qstr
->len
!= len
)
498 if (memcmp(qstr
->name
, str
, len
))
501 if (d_unhashed(expiring
)) {
503 spin_unlock(&expiring
->d_lock
);
504 spin_unlock(&sbi
->lookup_lock
);
505 spin_unlock(&dcache_lock
);
509 spin_unlock(&expiring
->d_lock
);
511 spin_unlock(&sbi
->lookup_lock
);
512 spin_unlock(&dcache_lock
);
517 /* Lookups in the root directory */
518 static struct dentry
*autofs4_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
520 struct autofs_sb_info
*sbi
;
521 struct autofs_info
*ino
;
522 struct dentry
*expiring
, *active
;
525 DPRINTK("name = %.*s",
526 dentry
->d_name
.len
, dentry
->d_name
.name
);
528 /* File name too long to exist */
529 if (dentry
->d_name
.len
> NAME_MAX
)
530 return ERR_PTR(-ENAMETOOLONG
);
532 sbi
= autofs4_sbi(dir
->i_sb
);
533 oz_mode
= autofs4_oz_mode(sbi
);
535 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
536 current
->pid
, task_pgrp_nr(current
), sbi
->catatonic
, oz_mode
);
538 active
= autofs4_lookup_active(dentry
);
541 ino
= autofs4_dentry_ino(dentry
);
544 * Mark the dentry incomplete but don't hash it. We do this
545 * to serialize our inode creation operations (symlink and
546 * mkdir) which prevents deadlock during the callback to
547 * the daemon. Subsequent user space lookups for the same
548 * dentry are placed on the wait queue while the daemon
549 * itself is allowed passage unresticted so the create
550 * operation itself can then hash the dentry. Finally,
551 * we check for the hashed dentry and return the newly
554 dentry
->d_op
= &autofs4_root_dentry_operations
;
557 * And we need to ensure that the same dentry is used for
558 * all following lookup calls until it is hashed so that
559 * the dentry flags are persistent throughout the request.
561 ino
= autofs4_init_ino(NULL
, sbi
, 0555);
563 return ERR_PTR(-ENOMEM
);
565 dentry
->d_fsdata
= ino
;
566 ino
->dentry
= dentry
;
568 autofs4_add_active(dentry
);
570 d_instantiate(dentry
, NULL
);
574 mutex_unlock(&dir
->i_mutex
);
575 expiring
= autofs4_lookup_expiring(dentry
);
578 * If we are racing with expire the request might not
579 * be quite complete but the directory has been removed
580 * so it must have been successful, so just wait for it.
582 autofs4_expire_wait(expiring
);
583 autofs4_del_expiring(expiring
);
587 spin_lock(&sbi
->fs_lock
);
588 ino
->flags
|= AUTOFS_INF_PENDING
;
589 spin_unlock(&sbi
->fs_lock
);
590 if (dentry
->d_op
&& dentry
->d_op
->d_revalidate
)
591 (dentry
->d_op
->d_revalidate
)(dentry
, nd
);
592 mutex_lock(&dir
->i_mutex
);
596 * If we are still pending, check if we had to handle
597 * a signal. If so we can force a restart..
599 if (ino
->flags
& AUTOFS_INF_PENDING
) {
600 /* See if we were interrupted */
601 if (signal_pending(current
)) {
602 sigset_t
*sigset
= ¤t
->pending
.signal
;
603 if (sigismember (sigset
, SIGKILL
) ||
604 sigismember (sigset
, SIGQUIT
) ||
605 sigismember (sigset
, SIGINT
)) {
608 return ERR_PTR(-ERESTARTNOINTR
);
612 spin_lock(&sbi
->fs_lock
);
613 ino
->flags
&= ~AUTOFS_INF_PENDING
;
614 spin_unlock(&sbi
->fs_lock
);
619 * If this dentry is unhashed, then we shouldn't honour this
620 * lookup. Returning ENOENT here doesn't do the right thing
621 * for all system calls, but it should be OK for the operations
622 * we permit from an autofs.
624 if (!oz_mode
&& d_unhashed(dentry
)) {
626 * A user space application can (and has done in the past)
627 * remove and re-create this directory during the callback.
628 * This can leave us with an unhashed dentry, but a
629 * successful mount! So we need to perform another
630 * cached lookup in case the dentry now exists.
632 struct dentry
*parent
= dentry
->d_parent
;
633 struct dentry
*new = d_lookup(parent
, &dentry
->d_name
);
637 dentry
= ERR_PTR(-ENOENT
);
651 static int autofs4_dir_symlink(struct inode
*dir
,
652 struct dentry
*dentry
,
655 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
656 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
657 struct autofs_info
*p_ino
;
661 DPRINTK("%s <- %.*s", symname
,
662 dentry
->d_name
.len
, dentry
->d_name
.name
);
664 if (!autofs4_oz_mode(sbi
))
667 ino
= autofs4_init_ino(ino
, sbi
, S_IFLNK
| 0555);
671 autofs4_del_active(dentry
);
673 ino
->size
= strlen(symname
);
674 cp
= kmalloc(ino
->size
+ 1, GFP_KERNEL
);
676 if (!dentry
->d_fsdata
)
683 inode
= autofs4_get_inode(dir
->i_sb
, ino
);
686 if (!dentry
->d_fsdata
)
690 d_add(dentry
, inode
);
692 if (dir
== dir
->i_sb
->s_root
->d_inode
)
693 dentry
->d_op
= &autofs4_root_dentry_operations
;
695 dentry
->d_op
= &autofs4_dentry_operations
;
697 dentry
->d_fsdata
= ino
;
698 ino
->dentry
= dget(dentry
);
699 atomic_inc(&ino
->count
);
700 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
701 if (p_ino
&& dentry
->d_parent
!= dentry
)
702 atomic_inc(&p_ino
->count
);
706 dir
->i_mtime
= CURRENT_TIME
;
714 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
715 * that the file no longer exists. However, doing that means that the
716 * VFS layer can turn the dentry into a negative dentry. We don't want
717 * this, because the unlink is probably the result of an expire.
718 * We simply d_drop it and add it to a expiring list in the super block,
719 * which allows the dentry lookup to check for an incomplete expire.
721 * If a process is blocked on the dentry waiting for the expire to finish,
722 * it will invalidate the dentry and try to mount with a new one.
724 * Also see autofs4_dir_rmdir()..
726 static int autofs4_dir_unlink(struct inode
*dir
, struct dentry
*dentry
)
728 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
729 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
730 struct autofs_info
*p_ino
;
732 /* This allows root to remove symlinks */
733 if (!autofs4_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
736 if (atomic_dec_and_test(&ino
->count
)) {
737 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
738 if (p_ino
&& dentry
->d_parent
!= dentry
)
739 atomic_dec(&p_ino
->count
);
743 dentry
->d_inode
->i_size
= 0;
744 clear_nlink(dentry
->d_inode
);
746 dir
->i_mtime
= CURRENT_TIME
;
748 spin_lock(&dcache_lock
);
749 autofs4_add_expiring(dentry
);
750 spin_lock(&dentry
->d_lock
);
752 spin_unlock(&dentry
->d_lock
);
753 spin_unlock(&dcache_lock
);
758 static int autofs4_dir_rmdir(struct inode
*dir
, struct dentry
*dentry
)
760 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
761 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
762 struct autofs_info
*p_ino
;
764 DPRINTK("dentry %p, removing %.*s",
765 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
767 if (!autofs4_oz_mode(sbi
))
770 spin_lock(&dcache_lock
);
771 if (!list_empty(&dentry
->d_subdirs
)) {
772 spin_unlock(&dcache_lock
);
775 autofs4_add_expiring(dentry
);
776 spin_lock(&dentry
->d_lock
);
778 spin_unlock(&dentry
->d_lock
);
779 spin_unlock(&dcache_lock
);
781 if (atomic_dec_and_test(&ino
->count
)) {
782 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
783 if (p_ino
&& dentry
->d_parent
!= dentry
)
784 atomic_dec(&p_ino
->count
);
787 dentry
->d_inode
->i_size
= 0;
788 clear_nlink(dentry
->d_inode
);
796 static int autofs4_dir_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
798 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
799 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
800 struct autofs_info
*p_ino
;
803 if (!autofs4_oz_mode(sbi
))
806 DPRINTK("dentry %p, creating %.*s",
807 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
809 ino
= autofs4_init_ino(ino
, sbi
, S_IFDIR
| 0555);
813 autofs4_del_active(dentry
);
815 inode
= autofs4_get_inode(dir
->i_sb
, ino
);
817 if (!dentry
->d_fsdata
)
821 d_add(dentry
, inode
);
823 if (dir
== dir
->i_sb
->s_root
->d_inode
)
824 dentry
->d_op
= &autofs4_root_dentry_operations
;
826 dentry
->d_op
= &autofs4_dentry_operations
;
828 dentry
->d_fsdata
= ino
;
829 ino
->dentry
= dget(dentry
);
830 atomic_inc(&ino
->count
);
831 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
832 if (p_ino
&& dentry
->d_parent
!= dentry
)
833 atomic_inc(&p_ino
->count
);
836 dir
->i_mtime
= CURRENT_TIME
;
841 /* Get/set timeout ioctl() operation */
842 static inline int autofs4_get_set_timeout(struct autofs_sb_info
*sbi
,
843 unsigned long __user
*p
)
846 unsigned long ntimeout
;
848 if ((rv
= get_user(ntimeout
, p
)) ||
849 (rv
= put_user(sbi
->exp_timeout
/HZ
, p
)))
852 if (ntimeout
> ULONG_MAX
/HZ
)
853 sbi
->exp_timeout
= 0;
855 sbi
->exp_timeout
= ntimeout
* HZ
;
860 /* Return protocol version */
861 static inline int autofs4_get_protover(struct autofs_sb_info
*sbi
, int __user
*p
)
863 return put_user(sbi
->version
, p
);
866 /* Return protocol sub version */
867 static inline int autofs4_get_protosubver(struct autofs_sb_info
*sbi
, int __user
*p
)
869 return put_user(sbi
->sub_version
, p
);
873 * Tells the daemon whether it can umount the autofs mount.
875 static inline int autofs4_ask_umount(struct vfsmount
*mnt
, int __user
*p
)
882 DPRINTK("returning %d", status
);
884 status
= put_user(status
, p
);
889 /* Identify autofs4_dentries - this is so we can tell if there's
890 an extra dentry refcount or not. We only hold a refcount on the
891 dentry if its non-negative (ie, d_inode != NULL)
893 int is_autofs4_dentry(struct dentry
*dentry
)
895 return dentry
&& dentry
->d_inode
&&
896 (dentry
->d_op
== &autofs4_root_dentry_operations
||
897 dentry
->d_op
== &autofs4_dentry_operations
) &&
898 dentry
->d_fsdata
!= NULL
;
902 * ioctl()'s on the root directory is the chief method for the daemon to
903 * generate kernel reactions
905 static int autofs4_root_ioctl(struct inode
*inode
, struct file
*filp
,
906 unsigned int cmd
, unsigned long arg
)
908 struct autofs_sb_info
*sbi
= autofs4_sbi(inode
->i_sb
);
909 void __user
*p
= (void __user
*)arg
;
911 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
912 cmd
,arg
,sbi
,task_pgrp_nr(current
));
914 if (_IOC_TYPE(cmd
) != _IOC_TYPE(AUTOFS_IOC_FIRST
) ||
915 _IOC_NR(cmd
) - _IOC_NR(AUTOFS_IOC_FIRST
) >= AUTOFS_IOC_COUNT
)
918 if (!autofs4_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
922 case AUTOFS_IOC_READY
: /* Wait queue: go ahead and retry */
923 return autofs4_wait_release(sbi
,(autofs_wqt_t
)arg
,0);
924 case AUTOFS_IOC_FAIL
: /* Wait queue: fail with ENOENT */
925 return autofs4_wait_release(sbi
,(autofs_wqt_t
)arg
,-ENOENT
);
926 case AUTOFS_IOC_CATATONIC
: /* Enter catatonic mode (daemon shutdown) */
927 autofs4_catatonic_mode(sbi
);
929 case AUTOFS_IOC_PROTOVER
: /* Get protocol version */
930 return autofs4_get_protover(sbi
, p
);
931 case AUTOFS_IOC_PROTOSUBVER
: /* Get protocol sub version */
932 return autofs4_get_protosubver(sbi
, p
);
933 case AUTOFS_IOC_SETTIMEOUT
:
934 return autofs4_get_set_timeout(sbi
, p
);
936 case AUTOFS_IOC_ASKUMOUNT
:
937 return autofs4_ask_umount(filp
->f_path
.mnt
, p
);
939 /* return a single thing to expire */
940 case AUTOFS_IOC_EXPIRE
:
941 return autofs4_expire_run(inode
->i_sb
,filp
->f_path
.mnt
,sbi
, p
);
942 /* same as above, but can send multiple expires through pipe */
943 case AUTOFS_IOC_EXPIRE_MULTI
:
944 return autofs4_expire_multi(inode
->i_sb
,filp
->f_path
.mnt
,sbi
, p
);