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/slab.h>
19 #include <linux/param.h>
20 #include <linux/time.h>
21 #include <linux/smp_lock.h>
24 static int autofs4_dir_symlink(struct inode
*,struct dentry
*,const char *);
25 static int autofs4_dir_unlink(struct inode
*,struct dentry
*);
26 static int autofs4_dir_rmdir(struct inode
*,struct dentry
*);
27 static int autofs4_dir_mkdir(struct inode
*,struct dentry
*,int);
28 static long autofs4_root_ioctl(struct file
*,unsigned int,unsigned long);
29 static int autofs4_dir_open(struct inode
*inode
, struct file
*file
);
30 static struct dentry
*autofs4_lookup(struct inode
*,struct dentry
*, struct nameidata
*);
31 static void *autofs4_follow_link(struct dentry
*, struct nameidata
*);
33 #define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
34 #define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
36 const struct file_operations autofs4_root_operations
= {
37 .open
= dcache_dir_open
,
38 .release
= dcache_dir_close
,
39 .read
= generic_read_dir
,
40 .readdir
= dcache_readdir
,
41 .llseek
= dcache_dir_lseek
,
42 .unlocked_ioctl
= autofs4_root_ioctl
,
45 const struct file_operations autofs4_dir_operations
= {
46 .open
= autofs4_dir_open
,
47 .release
= dcache_dir_close
,
48 .read
= generic_read_dir
,
49 .readdir
= dcache_readdir
,
50 .llseek
= dcache_dir_lseek
,
53 const struct inode_operations autofs4_indirect_root_inode_operations
= {
54 .lookup
= autofs4_lookup
,
55 .unlink
= autofs4_dir_unlink
,
56 .symlink
= autofs4_dir_symlink
,
57 .mkdir
= autofs4_dir_mkdir
,
58 .rmdir
= autofs4_dir_rmdir
,
61 const struct inode_operations autofs4_direct_root_inode_operations
= {
62 .lookup
= autofs4_lookup
,
63 .unlink
= autofs4_dir_unlink
,
64 .mkdir
= autofs4_dir_mkdir
,
65 .rmdir
= autofs4_dir_rmdir
,
66 .follow_link
= autofs4_follow_link
,
69 const struct inode_operations autofs4_dir_inode_operations
= {
70 .lookup
= autofs4_lookup
,
71 .unlink
= autofs4_dir_unlink
,
72 .symlink
= autofs4_dir_symlink
,
73 .mkdir
= autofs4_dir_mkdir
,
74 .rmdir
= autofs4_dir_rmdir
,
77 static void autofs4_add_active(struct dentry
*dentry
)
79 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
80 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
82 spin_lock(&sbi
->lookup_lock
);
83 if (!ino
->active_count
) {
84 if (list_empty(&ino
->active
))
85 list_add(&ino
->active
, &sbi
->active_list
);
88 spin_unlock(&sbi
->lookup_lock
);
93 static void autofs4_del_active(struct dentry
*dentry
)
95 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
96 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
98 spin_lock(&sbi
->lookup_lock
);
100 if (!ino
->active_count
) {
101 if (!list_empty(&ino
->active
))
102 list_del_init(&ino
->active
);
104 spin_unlock(&sbi
->lookup_lock
);
109 static unsigned int autofs4_need_mount(unsigned int flags
)
111 unsigned int res
= 0;
112 if (flags
& (TRIGGER_FLAGS
| TRIGGER_INTENTS
))
117 static int autofs4_dir_open(struct inode
*inode
, struct file
*file
)
119 struct dentry
*dentry
= file
->f_path
.dentry
;
120 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
122 DPRINTK("file=%p dentry=%p %.*s",
123 file
, dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
125 if (autofs4_oz_mode(sbi
))
129 * An empty directory in an autofs file system is always a
130 * mount point. The daemon must have failed to mount this
131 * during lookup so it doesn't exist. This can happen, for
132 * example, if user space returns an incorrect status for a
133 * mount request. Otherwise we're doing a readdir on the
134 * autofs file system so just let the libfs routines handle
137 spin_lock(&dcache_lock
);
138 if (!d_mountpoint(dentry
) && list_empty(&dentry
->d_subdirs
)) {
139 spin_unlock(&dcache_lock
);
142 spin_unlock(&dcache_lock
);
145 return dcache_dir_open(inode
, file
);
148 static int try_to_fill_dentry(struct dentry
*dentry
, int flags
)
150 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
151 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
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(&sbi
->fs_lock
);
172 ino
->flags
&= ~AUTOFS_INF_PENDING
;
173 spin_unlock(&sbi
->fs_lock
);
176 /* Return a negative dentry, but leave it "pending" */
179 /* Trigger mount for path component or follow link */
180 } else if (ino
->flags
& AUTOFS_INF_PENDING
||
181 autofs4_need_mount(flags
)) {
182 DPRINTK("waiting for mount name=%.*s",
183 dentry
->d_name
.len
, dentry
->d_name
.name
);
185 spin_lock(&sbi
->fs_lock
);
186 ino
->flags
|= AUTOFS_INF_PENDING
;
187 spin_unlock(&sbi
->fs_lock
);
188 status
= autofs4_wait(sbi
, dentry
, NFY_MOUNT
);
190 DPRINTK("mount done status=%d", status
);
193 spin_lock(&sbi
->fs_lock
);
194 ino
->flags
&= ~AUTOFS_INF_PENDING
;
195 spin_unlock(&sbi
->fs_lock
);
200 /* Initialize expiry counter after successful mount */
202 ino
->last_used
= jiffies
;
204 spin_lock(&sbi
->fs_lock
);
205 ino
->flags
&= ~AUTOFS_INF_PENDING
;
206 spin_unlock(&sbi
->fs_lock
);
211 /* For autofs direct mounts the follow link triggers the mount */
212 static void *autofs4_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
214 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
215 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
216 int oz_mode
= autofs4_oz_mode(sbi
);
217 unsigned int lookup_type
;
220 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
221 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
, oz_mode
,
224 * For an expire of a covered direct or offset mount we need
225 * to break out of follow_down() at the autofs mount trigger
226 * (d_mounted--), so we can see the expiring flag, and manage
227 * the blocking and following here until the expire is completed.
230 spin_lock(&sbi
->fs_lock
);
231 if (ino
->flags
& AUTOFS_INF_EXPIRING
) {
232 spin_unlock(&sbi
->fs_lock
);
233 /* Follow down to our covering mount. */
234 if (!follow_down(&nd
->path
))
238 spin_unlock(&sbi
->fs_lock
);
242 /* If an expire request is pending everyone must wait. */
243 autofs4_expire_wait(dentry
);
245 /* We trigger a mount for almost all flags */
246 lookup_type
= autofs4_need_mount(nd
->flags
);
247 spin_lock(&sbi
->fs_lock
);
248 spin_lock(&dcache_lock
);
249 if (!(lookup_type
|| ino
->flags
& AUTOFS_INF_PENDING
)) {
250 spin_unlock(&dcache_lock
);
251 spin_unlock(&sbi
->fs_lock
);
256 * If the dentry contains directories then it is an autofs
257 * multi-mount with no root mount offset. So don't try to
260 if (ino
->flags
& AUTOFS_INF_PENDING
||
261 (!d_mountpoint(dentry
) && list_empty(&dentry
->d_subdirs
))) {
262 spin_unlock(&dcache_lock
);
263 spin_unlock(&sbi
->fs_lock
);
265 status
= try_to_fill_dentry(dentry
, nd
->flags
);
271 spin_unlock(&dcache_lock
);
272 spin_unlock(&sbi
->fs_lock
);
275 * If there is no root mount it must be an autofs
276 * multi-mount with no root offset so we don't need
279 if (d_mountpoint(dentry
)) {
280 if (!autofs4_follow_mount(&nd
->path
)) {
291 return ERR_PTR(status
);
295 * Revalidate is called on every cache lookup. Some of those
296 * cache lookups may actually happen while the dentry is not
297 * yet completely filled in, and revalidate has to delay such
300 static int autofs4_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
302 struct inode
*dir
= dentry
->d_parent
->d_inode
;
303 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
304 int oz_mode
= autofs4_oz_mode(sbi
);
305 int flags
= nd
? nd
->flags
: 0;
309 spin_lock(&sbi
->fs_lock
);
310 if (autofs4_ispending(dentry
)) {
311 /* The daemon never causes a mount to trigger */
312 spin_unlock(&sbi
->fs_lock
);
318 * If the directory has gone away due to an expire
319 * we have been called as ->d_revalidate() and so
320 * we need to return false and proceed to ->lookup().
322 if (autofs4_expire_wait(dentry
) == -EAGAIN
)
326 * A zero status is success otherwise we have a
327 * negative error code.
329 status
= try_to_fill_dentry(dentry
, flags
);
335 spin_unlock(&sbi
->fs_lock
);
337 /* Negative dentry.. invalidate if "old" */
338 if (dentry
->d_inode
== NULL
)
341 /* Check for a non-mountpoint directory with no contents */
342 spin_lock(&dcache_lock
);
343 if (S_ISDIR(dentry
->d_inode
->i_mode
) &&
344 !d_mountpoint(dentry
) && list_empty(&dentry
->d_subdirs
)) {
345 DPRINTK("dentry=%p %.*s, emptydir",
346 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
347 spin_unlock(&dcache_lock
);
349 /* The daemon never causes a mount to trigger */
354 * A zero status is success otherwise we have a
355 * negative error code.
357 status
= try_to_fill_dentry(dentry
, flags
);
363 spin_unlock(&dcache_lock
);
368 void autofs4_dentry_release(struct dentry
*de
)
370 struct autofs_info
*inf
;
372 DPRINTK("releasing %p", de
);
374 inf
= autofs4_dentry_ino(de
);
378 struct autofs_sb_info
*sbi
= autofs4_sbi(de
->d_sb
);
381 spin_lock(&sbi
->lookup_lock
);
382 if (!list_empty(&inf
->active
))
383 list_del(&inf
->active
);
384 if (!list_empty(&inf
->expiring
))
385 list_del(&inf
->expiring
);
386 spin_unlock(&sbi
->lookup_lock
);
392 autofs4_free_ino(inf
);
396 /* For dentries of directories in the root dir */
397 static const struct dentry_operations autofs4_root_dentry_operations
= {
398 .d_revalidate
= autofs4_revalidate
,
399 .d_release
= autofs4_dentry_release
,
402 /* For other dentries */
403 static const struct dentry_operations autofs4_dentry_operations
= {
404 .d_revalidate
= autofs4_revalidate
,
405 .d_release
= autofs4_dentry_release
,
408 static struct dentry
*autofs4_lookup_active(struct dentry
*dentry
)
410 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
411 struct dentry
*parent
= dentry
->d_parent
;
412 struct qstr
*name
= &dentry
->d_name
;
413 unsigned int len
= name
->len
;
414 unsigned int hash
= name
->hash
;
415 const unsigned char *str
= name
->name
;
416 struct list_head
*p
, *head
;
418 spin_lock(&dcache_lock
);
419 spin_lock(&sbi
->lookup_lock
);
420 head
= &sbi
->active_list
;
421 list_for_each(p
, head
) {
422 struct autofs_info
*ino
;
423 struct dentry
*active
;
426 ino
= list_entry(p
, struct autofs_info
, active
);
427 active
= ino
->dentry
;
429 spin_lock(&active
->d_lock
);
432 if (atomic_read(&active
->d_count
) == 0)
435 qstr
= &active
->d_name
;
437 if (active
->d_name
.hash
!= hash
)
439 if (active
->d_parent
!= parent
)
442 if (qstr
->len
!= len
)
444 if (memcmp(qstr
->name
, str
, len
))
447 if (d_unhashed(active
)) {
449 spin_unlock(&active
->d_lock
);
450 spin_unlock(&sbi
->lookup_lock
);
451 spin_unlock(&dcache_lock
);
455 spin_unlock(&active
->d_lock
);
457 spin_unlock(&sbi
->lookup_lock
);
458 spin_unlock(&dcache_lock
);
463 static struct dentry
*autofs4_lookup_expiring(struct dentry
*dentry
)
465 struct autofs_sb_info
*sbi
= autofs4_sbi(dentry
->d_sb
);
466 struct dentry
*parent
= dentry
->d_parent
;
467 struct qstr
*name
= &dentry
->d_name
;
468 unsigned int len
= name
->len
;
469 unsigned int hash
= name
->hash
;
470 const unsigned char *str
= name
->name
;
471 struct list_head
*p
, *head
;
473 spin_lock(&dcache_lock
);
474 spin_lock(&sbi
->lookup_lock
);
475 head
= &sbi
->expiring_list
;
476 list_for_each(p
, head
) {
477 struct autofs_info
*ino
;
478 struct dentry
*expiring
;
481 ino
= list_entry(p
, struct autofs_info
, expiring
);
482 expiring
= ino
->dentry
;
484 spin_lock(&expiring
->d_lock
);
486 /* Bad luck, we've already been dentry_iput */
487 if (!expiring
->d_inode
)
490 qstr
= &expiring
->d_name
;
492 if (expiring
->d_name
.hash
!= hash
)
494 if (expiring
->d_parent
!= parent
)
497 if (qstr
->len
!= len
)
499 if (memcmp(qstr
->name
, str
, len
))
502 if (d_unhashed(expiring
)) {
504 spin_unlock(&expiring
->d_lock
);
505 spin_unlock(&sbi
->lookup_lock
);
506 spin_unlock(&dcache_lock
);
510 spin_unlock(&expiring
->d_lock
);
512 spin_unlock(&sbi
->lookup_lock
);
513 spin_unlock(&dcache_lock
);
518 /* Lookups in the root directory */
519 static struct dentry
*autofs4_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
521 struct autofs_sb_info
*sbi
;
522 struct autofs_info
*ino
;
523 struct dentry
*expiring
, *active
;
526 DPRINTK("name = %.*s",
527 dentry
->d_name
.len
, dentry
->d_name
.name
);
529 /* File name too long to exist */
530 if (dentry
->d_name
.len
> NAME_MAX
)
531 return ERR_PTR(-ENAMETOOLONG
);
533 sbi
= autofs4_sbi(dir
->i_sb
);
534 oz_mode
= autofs4_oz_mode(sbi
);
536 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
537 current
->pid
, task_pgrp_nr(current
), sbi
->catatonic
, oz_mode
);
539 active
= autofs4_lookup_active(dentry
);
542 ino
= autofs4_dentry_ino(dentry
);
545 * Mark the dentry incomplete but don't hash it. We do this
546 * to serialize our inode creation operations (symlink and
547 * mkdir) which prevents deadlock during the callback to
548 * the daemon. Subsequent user space lookups for the same
549 * dentry are placed on the wait queue while the daemon
550 * itself is allowed passage unresticted so the create
551 * operation itself can then hash the dentry. Finally,
552 * we check for the hashed dentry and return the newly
555 dentry
->d_op
= &autofs4_root_dentry_operations
;
558 * And we need to ensure that the same dentry is used for
559 * all following lookup calls until it is hashed so that
560 * the dentry flags are persistent throughout the request.
562 ino
= autofs4_init_ino(NULL
, sbi
, 0555);
564 return ERR_PTR(-ENOMEM
);
566 dentry
->d_fsdata
= ino
;
567 ino
->dentry
= dentry
;
569 autofs4_add_active(dentry
);
571 d_instantiate(dentry
, NULL
);
575 mutex_unlock(&dir
->i_mutex
);
576 expiring
= autofs4_lookup_expiring(dentry
);
579 * If we are racing with expire the request might not
580 * be quite complete but the directory has been removed
581 * so it must have been successful, so just wait for it.
583 autofs4_expire_wait(expiring
);
584 autofs4_del_expiring(expiring
);
588 spin_lock(&sbi
->fs_lock
);
589 ino
->flags
|= AUTOFS_INF_PENDING
;
590 spin_unlock(&sbi
->fs_lock
);
591 if (dentry
->d_op
&& dentry
->d_op
->d_revalidate
)
592 (dentry
->d_op
->d_revalidate
)(dentry
, nd
);
593 mutex_lock(&dir
->i_mutex
);
597 * If we are still pending, check if we had to handle
598 * a signal. If so we can force a restart..
600 if (ino
->flags
& AUTOFS_INF_PENDING
) {
601 /* See if we were interrupted */
602 if (signal_pending(current
)) {
603 sigset_t
*sigset
= ¤t
->pending
.signal
;
604 if (sigismember (sigset
, SIGKILL
) ||
605 sigismember (sigset
, SIGQUIT
) ||
606 sigismember (sigset
, SIGINT
)) {
609 return ERR_PTR(-ERESTARTNOINTR
);
613 spin_lock(&sbi
->fs_lock
);
614 ino
->flags
&= ~AUTOFS_INF_PENDING
;
615 spin_unlock(&sbi
->fs_lock
);
620 * If this dentry is unhashed, then we shouldn't honour this
621 * lookup. Returning ENOENT here doesn't do the right thing
622 * for all system calls, but it should be OK for the operations
623 * we permit from an autofs.
625 if (!oz_mode
&& d_unhashed(dentry
)) {
627 * A user space application can (and has done in the past)
628 * remove and re-create this directory during the callback.
629 * This can leave us with an unhashed dentry, but a
630 * successful mount! So we need to perform another
631 * cached lookup in case the dentry now exists.
633 struct dentry
*parent
= dentry
->d_parent
;
634 struct dentry
*new = d_lookup(parent
, &dentry
->d_name
);
638 dentry
= ERR_PTR(-ENOENT
);
652 static int autofs4_dir_symlink(struct inode
*dir
,
653 struct dentry
*dentry
,
656 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
657 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
658 struct autofs_info
*p_ino
;
662 DPRINTK("%s <- %.*s", symname
,
663 dentry
->d_name
.len
, dentry
->d_name
.name
);
665 if (!autofs4_oz_mode(sbi
))
668 ino
= autofs4_init_ino(ino
, sbi
, S_IFLNK
| 0555);
672 autofs4_del_active(dentry
);
674 ino
->size
= strlen(symname
);
675 cp
= kmalloc(ino
->size
+ 1, GFP_KERNEL
);
677 if (!dentry
->d_fsdata
)
684 inode
= autofs4_get_inode(dir
->i_sb
, ino
);
687 if (!dentry
->d_fsdata
)
691 d_add(dentry
, inode
);
693 if (dir
== dir
->i_sb
->s_root
->d_inode
)
694 dentry
->d_op
= &autofs4_root_dentry_operations
;
696 dentry
->d_op
= &autofs4_dentry_operations
;
698 dentry
->d_fsdata
= ino
;
699 ino
->dentry
= dget(dentry
);
700 atomic_inc(&ino
->count
);
701 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
702 if (p_ino
&& dentry
->d_parent
!= dentry
)
703 atomic_inc(&p_ino
->count
);
707 dir
->i_mtime
= CURRENT_TIME
;
715 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
716 * that the file no longer exists. However, doing that means that the
717 * VFS layer can turn the dentry into a negative dentry. We don't want
718 * this, because the unlink is probably the result of an expire.
719 * We simply d_drop it and add it to a expiring list in the super block,
720 * which allows the dentry lookup to check for an incomplete expire.
722 * If a process is blocked on the dentry waiting for the expire to finish,
723 * it will invalidate the dentry and try to mount with a new one.
725 * Also see autofs4_dir_rmdir()..
727 static int autofs4_dir_unlink(struct inode
*dir
, struct dentry
*dentry
)
729 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
730 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
731 struct autofs_info
*p_ino
;
733 /* This allows root to remove symlinks */
734 if (!autofs4_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
737 if (atomic_dec_and_test(&ino
->count
)) {
738 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
739 if (p_ino
&& dentry
->d_parent
!= dentry
)
740 atomic_dec(&p_ino
->count
);
744 dentry
->d_inode
->i_size
= 0;
745 clear_nlink(dentry
->d_inode
);
747 dir
->i_mtime
= CURRENT_TIME
;
749 spin_lock(&dcache_lock
);
750 autofs4_add_expiring(dentry
);
751 spin_lock(&dentry
->d_lock
);
753 spin_unlock(&dentry
->d_lock
);
754 spin_unlock(&dcache_lock
);
759 static int autofs4_dir_rmdir(struct inode
*dir
, struct dentry
*dentry
)
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
;
765 DPRINTK("dentry %p, removing %.*s",
766 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
768 if (!autofs4_oz_mode(sbi
))
771 spin_lock(&dcache_lock
);
772 if (!list_empty(&dentry
->d_subdirs
)) {
773 spin_unlock(&dcache_lock
);
776 autofs4_add_expiring(dentry
);
777 spin_lock(&dentry
->d_lock
);
779 spin_unlock(&dentry
->d_lock
);
780 spin_unlock(&dcache_lock
);
782 if (atomic_dec_and_test(&ino
->count
)) {
783 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
784 if (p_ino
&& dentry
->d_parent
!= dentry
)
785 atomic_dec(&p_ino
->count
);
788 dentry
->d_inode
->i_size
= 0;
789 clear_nlink(dentry
->d_inode
);
797 static int autofs4_dir_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
799 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
800 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
801 struct autofs_info
*p_ino
;
804 if (!autofs4_oz_mode(sbi
))
807 DPRINTK("dentry %p, creating %.*s",
808 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
810 ino
= autofs4_init_ino(ino
, sbi
, S_IFDIR
| 0555);
814 autofs4_del_active(dentry
);
816 inode
= autofs4_get_inode(dir
->i_sb
, ino
);
818 if (!dentry
->d_fsdata
)
822 d_add(dentry
, inode
);
824 if (dir
== dir
->i_sb
->s_root
->d_inode
)
825 dentry
->d_op
= &autofs4_root_dentry_operations
;
827 dentry
->d_op
= &autofs4_dentry_operations
;
829 dentry
->d_fsdata
= ino
;
830 ino
->dentry
= dget(dentry
);
831 atomic_inc(&ino
->count
);
832 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
833 if (p_ino
&& dentry
->d_parent
!= dentry
)
834 atomic_inc(&p_ino
->count
);
837 dir
->i_mtime
= CURRENT_TIME
;
842 /* Get/set timeout ioctl() operation */
843 static inline int autofs4_get_set_timeout(struct autofs_sb_info
*sbi
,
844 unsigned long __user
*p
)
847 unsigned long ntimeout
;
849 if ((rv
= get_user(ntimeout
, p
)) ||
850 (rv
= put_user(sbi
->exp_timeout
/HZ
, p
)))
853 if (ntimeout
> ULONG_MAX
/HZ
)
854 sbi
->exp_timeout
= 0;
856 sbi
->exp_timeout
= ntimeout
* HZ
;
861 /* Return protocol version */
862 static inline int autofs4_get_protover(struct autofs_sb_info
*sbi
, int __user
*p
)
864 return put_user(sbi
->version
, p
);
867 /* Return protocol sub version */
868 static inline int autofs4_get_protosubver(struct autofs_sb_info
*sbi
, int __user
*p
)
870 return put_user(sbi
->sub_version
, p
);
874 * Tells the daemon whether it can umount the autofs mount.
876 static inline int autofs4_ask_umount(struct vfsmount
*mnt
, int __user
*p
)
883 DPRINTK("returning %d", status
);
885 status
= put_user(status
, p
);
890 /* Identify autofs4_dentries - this is so we can tell if there's
891 an extra dentry refcount or not. We only hold a refcount on the
892 dentry if its non-negative (ie, d_inode != NULL)
894 int is_autofs4_dentry(struct dentry
*dentry
)
896 return dentry
&& dentry
->d_inode
&&
897 (dentry
->d_op
== &autofs4_root_dentry_operations
||
898 dentry
->d_op
== &autofs4_dentry_operations
) &&
899 dentry
->d_fsdata
!= NULL
;
903 * ioctl()'s on the root directory is the chief method for the daemon to
904 * generate kernel reactions
906 static int autofs4_root_ioctl_unlocked(struct inode
*inode
, struct file
*filp
,
907 unsigned int cmd
, unsigned long arg
)
909 struct autofs_sb_info
*sbi
= autofs4_sbi(inode
->i_sb
);
910 void __user
*p
= (void __user
*)arg
;
912 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
913 cmd
,arg
,sbi
,task_pgrp_nr(current
));
915 if (_IOC_TYPE(cmd
) != _IOC_TYPE(AUTOFS_IOC_FIRST
) ||
916 _IOC_NR(cmd
) - _IOC_NR(AUTOFS_IOC_FIRST
) >= AUTOFS_IOC_COUNT
)
919 if (!autofs4_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
923 case AUTOFS_IOC_READY
: /* Wait queue: go ahead and retry */
924 return autofs4_wait_release(sbi
,(autofs_wqt_t
)arg
,0);
925 case AUTOFS_IOC_FAIL
: /* Wait queue: fail with ENOENT */
926 return autofs4_wait_release(sbi
,(autofs_wqt_t
)arg
,-ENOENT
);
927 case AUTOFS_IOC_CATATONIC
: /* Enter catatonic mode (daemon shutdown) */
928 autofs4_catatonic_mode(sbi
);
930 case AUTOFS_IOC_PROTOVER
: /* Get protocol version */
931 return autofs4_get_protover(sbi
, p
);
932 case AUTOFS_IOC_PROTOSUBVER
: /* Get protocol sub version */
933 return autofs4_get_protosubver(sbi
, p
);
934 case AUTOFS_IOC_SETTIMEOUT
:
935 return autofs4_get_set_timeout(sbi
, p
);
937 case AUTOFS_IOC_ASKUMOUNT
:
938 return autofs4_ask_umount(filp
->f_path
.mnt
, p
);
940 /* return a single thing to expire */
941 case AUTOFS_IOC_EXPIRE
:
942 return autofs4_expire_run(inode
->i_sb
,filp
->f_path
.mnt
,sbi
, p
);
943 /* same as above, but can send multiple expires through pipe */
944 case AUTOFS_IOC_EXPIRE_MULTI
:
945 return autofs4_expire_multi(inode
->i_sb
,filp
->f_path
.mnt
,sbi
, p
);
952 static long autofs4_root_ioctl(struct file
*filp
,
953 unsigned int cmd
, unsigned long arg
)
956 struct inode
*inode
= filp
->f_dentry
->d_inode
;
959 ret
= autofs4_root_ioctl_unlocked(inode
, filp
, cmd
, arg
);