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 (flags
& (TRIGGER_FLAGS
| TRIGGER_INTENTS
) ||
181 current
->link_count
) {
182 DPRINTK("waiting for mount name=%.*s",
183 dentry
->d_name
.len
, dentry
->d_name
.name
);
185 spin_lock(&dentry
->d_lock
);
186 dentry
->d_flags
|= DCACHE_AUTOFS_PENDING
;
187 spin_unlock(&dentry
->d_lock
);
188 status
= autofs4_wait(sbi
, dentry
, NFY_MOUNT
);
190 DPRINTK("mount done status=%d", status
);
193 spin_lock(&dentry
->d_lock
);
194 dentry
->d_flags
&= ~DCACHE_AUTOFS_PENDING
;
195 spin_unlock(&dentry
->d_lock
);
200 /* Initialize expiry counter after successful mount */
202 ino
->last_used
= jiffies
;
204 spin_lock(&dentry
->d_lock
);
205 dentry
->d_flags
&= ~DCACHE_AUTOFS_PENDING
;
206 spin_unlock(&dentry
->d_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 /* If it's our master or we shouldn't trigger a mount we're done */
225 lookup_type
= nd
->flags
& (TRIGGER_FLAGS
| TRIGGER_INTENTS
);
226 if (oz_mode
|| !lookup_type
)
229 /* If an expire request is pending wait for it. */
230 if (ino
&& (ino
->flags
& AUTOFS_INF_EXPIRING
)) {
231 DPRINTK("waiting for active request %p name=%.*s",
232 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
234 status
= autofs4_wait(sbi
, dentry
, NFY_NONE
);
236 DPRINTK("request done status=%d", status
);
240 * If the dentry contains directories then it is an
241 * autofs multi-mount with no root mount offset. So
242 * don't try to mount it again.
244 spin_lock(&dcache_lock
);
245 if (!d_mountpoint(dentry
) && __simple_empty(dentry
)) {
246 spin_unlock(&dcache_lock
);
248 status
= try_to_fill_dentry(dentry
, 0);
253 * The mount succeeded but if there is no root mount
254 * it must be an autofs multi-mount with no root offset
255 * so we don't need to follow the mount.
257 if (d_mountpoint(dentry
)) {
258 if (!autofs4_follow_mount(&nd
->path
.mnt
,
267 spin_unlock(&dcache_lock
);
274 return ERR_PTR(status
);
278 * Revalidate is called on every cache lookup. Some of those
279 * cache lookups may actually happen while the dentry is not
280 * yet completely filled in, and revalidate has to delay such
283 static int autofs4_revalidate(struct dentry
*dentry
, struct nameidata
*nd
)
285 struct inode
*dir
= dentry
->d_parent
->d_inode
;
286 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
287 int oz_mode
= autofs4_oz_mode(sbi
);
288 int flags
= nd
? nd
->flags
: 0;
292 if (autofs4_ispending(dentry
)) {
293 /* The daemon never causes a mount to trigger */
298 * A zero status is success otherwise we have a
299 * negative error code.
301 status
= try_to_fill_dentry(dentry
, flags
);
306 * A status of EAGAIN here means that the dentry has gone
307 * away while waiting for an expire to complete. If we are
308 * racing with expire lookup will wait for it so this must
309 * be a revalidate and we need to send it to lookup.
311 if (status
== -EAGAIN
)
317 /* Negative dentry.. invalidate if "old" */
318 if (dentry
->d_inode
== NULL
)
321 /* Check for a non-mountpoint directory with no contents */
322 spin_lock(&dcache_lock
);
323 if (S_ISDIR(dentry
->d_inode
->i_mode
) &&
324 !d_mountpoint(dentry
) &&
325 __simple_empty(dentry
)) {
326 DPRINTK("dentry=%p %.*s, emptydir",
327 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
328 spin_unlock(&dcache_lock
);
329 /* The daemon never causes a mount to trigger */
334 * A zero status is success otherwise we have a
335 * negative error code.
337 status
= try_to_fill_dentry(dentry
, flags
);
343 spin_unlock(&dcache_lock
);
348 void autofs4_dentry_release(struct dentry
*de
)
350 struct autofs_info
*inf
;
352 DPRINTK("releasing %p", de
);
354 inf
= autofs4_dentry_ino(de
);
358 struct autofs_sb_info
*sbi
= autofs4_sbi(de
->d_sb
);
361 spin_lock(&sbi
->lookup_lock
);
362 if (!list_empty(&inf
->active
))
363 list_del(&inf
->active
);
364 if (!list_empty(&inf
->expiring
))
365 list_del(&inf
->expiring
);
366 spin_unlock(&sbi
->lookup_lock
);
372 autofs4_free_ino(inf
);
376 /* For dentries of directories in the root dir */
377 static struct dentry_operations autofs4_root_dentry_operations
= {
378 .d_revalidate
= autofs4_revalidate
,
379 .d_release
= autofs4_dentry_release
,
382 /* For other dentries */
383 static struct dentry_operations autofs4_dentry_operations
= {
384 .d_revalidate
= autofs4_revalidate
,
385 .d_release
= autofs4_dentry_release
,
388 static struct dentry
*autofs4_lookup_active(struct autofs_sb_info
*sbi
, struct dentry
*parent
, struct qstr
*name
)
390 unsigned int len
= name
->len
;
391 unsigned int hash
= name
->hash
;
392 const unsigned char *str
= name
->name
;
393 struct list_head
*p
, *head
;
395 spin_lock(&dcache_lock
);
396 spin_lock(&sbi
->lookup_lock
);
397 head
= &sbi
->active_list
;
398 list_for_each(p
, head
) {
399 struct autofs_info
*ino
;
400 struct dentry
*dentry
;
403 ino
= list_entry(p
, struct autofs_info
, active
);
404 dentry
= ino
->dentry
;
406 spin_lock(&dentry
->d_lock
);
409 if (atomic_read(&dentry
->d_count
) == 0)
412 qstr
= &dentry
->d_name
;
414 if (dentry
->d_name
.hash
!= hash
)
416 if (dentry
->d_parent
!= parent
)
419 if (qstr
->len
!= len
)
421 if (memcmp(qstr
->name
, str
, len
))
424 if (d_unhashed(dentry
)) {
426 spin_unlock(&dentry
->d_lock
);
427 spin_unlock(&sbi
->lookup_lock
);
428 spin_unlock(&dcache_lock
);
432 spin_unlock(&dentry
->d_lock
);
434 spin_unlock(&sbi
->lookup_lock
);
435 spin_unlock(&dcache_lock
);
440 static struct dentry
*autofs4_lookup_expiring(struct autofs_sb_info
*sbi
, struct dentry
*parent
, struct qstr
*name
)
442 unsigned int len
= name
->len
;
443 unsigned int hash
= name
->hash
;
444 const unsigned char *str
= name
->name
;
445 struct list_head
*p
, *head
;
447 spin_lock(&dcache_lock
);
448 spin_lock(&sbi
->lookup_lock
);
449 head
= &sbi
->expiring_list
;
450 list_for_each(p
, head
) {
451 struct autofs_info
*ino
;
452 struct dentry
*dentry
;
455 ino
= list_entry(p
, struct autofs_info
, expiring
);
456 dentry
= ino
->dentry
;
458 spin_lock(&dentry
->d_lock
);
460 /* Bad luck, we've already been dentry_iput */
461 if (!dentry
->d_inode
)
464 qstr
= &dentry
->d_name
;
466 if (dentry
->d_name
.hash
!= hash
)
468 if (dentry
->d_parent
!= parent
)
471 if (qstr
->len
!= len
)
473 if (memcmp(qstr
->name
, str
, len
))
476 if (d_unhashed(dentry
)) {
478 spin_unlock(&dentry
->d_lock
);
479 spin_unlock(&sbi
->lookup_lock
);
480 spin_unlock(&dcache_lock
);
484 spin_unlock(&dentry
->d_lock
);
486 spin_unlock(&sbi
->lookup_lock
);
487 spin_unlock(&dcache_lock
);
492 /* Lookups in the root directory */
493 static struct dentry
*autofs4_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
495 struct autofs_sb_info
*sbi
;
496 struct autofs_info
*ino
;
497 struct dentry
*expiring
, *unhashed
;
500 DPRINTK("name = %.*s",
501 dentry
->d_name
.len
, dentry
->d_name
.name
);
503 /* File name too long to exist */
504 if (dentry
->d_name
.len
> NAME_MAX
)
505 return ERR_PTR(-ENAMETOOLONG
);
507 sbi
= autofs4_sbi(dir
->i_sb
);
508 oz_mode
= autofs4_oz_mode(sbi
);
510 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
511 current
->pid
, task_pgrp_nr(current
), sbi
->catatonic
, oz_mode
);
513 expiring
= autofs4_lookup_expiring(sbi
, dentry
->d_parent
, &dentry
->d_name
);
516 * If we are racing with expire the request might not
517 * be quite complete but the directory has been removed
518 * so it must have been successful, so just wait for it.
520 ino
= autofs4_dentry_ino(expiring
);
521 while (ino
&& (ino
->flags
& AUTOFS_INF_EXPIRING
)) {
522 DPRINTK("wait for incomplete expire %p name=%.*s",
523 expiring
, expiring
->d_name
.len
,
524 expiring
->d_name
.name
);
525 autofs4_wait(sbi
, expiring
, NFY_NONE
);
526 DPRINTK("request completed");
528 spin_lock(&sbi
->lookup_lock
);
529 if (!list_empty(&ino
->expiring
))
530 list_del_init(&ino
->expiring
);
531 spin_unlock(&sbi
->lookup_lock
);
535 unhashed
= autofs4_lookup_active(sbi
, dentry
->d_parent
, &dentry
->d_name
);
540 * Mark the dentry incomplete but don't hash it. We do this
541 * to serialize our inode creation operations (symlink and
542 * mkdir) which prevents deadlock during the callback to
543 * the daemon. Subsequent user space lookups for the same
544 * dentry are placed on the wait queue while the daemon
545 * itself is allowed passage unresticted so the create
546 * operation itself can then hash the dentry. Finally,
547 * we check for the hashed dentry and return the newly
550 dentry
->d_op
= &autofs4_root_dentry_operations
;
553 * And we need to ensure that the same dentry is used for
554 * all following lookup calls until it is hashed so that
555 * the dentry flags are persistent throughout the request.
557 ino
= autofs4_init_ino(NULL
, sbi
, 0555);
559 return ERR_PTR(-ENOMEM
);
561 dentry
->d_fsdata
= ino
;
562 ino
->dentry
= dentry
;
564 spin_lock(&sbi
->lookup_lock
);
565 list_add(&ino
->active
, &sbi
->active_list
);
566 spin_unlock(&sbi
->lookup_lock
);
568 d_instantiate(dentry
, NULL
);
572 spin_lock(&dentry
->d_lock
);
573 dentry
->d_flags
|= DCACHE_AUTOFS_PENDING
;
574 spin_unlock(&dentry
->d_lock
);
575 if (dentry
->d_op
&& dentry
->d_op
->d_revalidate
) {
576 mutex_unlock(&dir
->i_mutex
);
577 (dentry
->d_op
->d_revalidate
)(dentry
, nd
);
578 mutex_lock(&dir
->i_mutex
);
583 * If we are still pending, check if we had to handle
584 * a signal. If so we can force a restart..
586 if (dentry
->d_flags
& DCACHE_AUTOFS_PENDING
) {
587 /* See if we were interrupted */
588 if (signal_pending(current
)) {
589 sigset_t
*sigset
= ¤t
->pending
.signal
;
590 if (sigismember (sigset
, SIGKILL
) ||
591 sigismember (sigset
, SIGQUIT
) ||
592 sigismember (sigset
, SIGINT
)) {
595 return ERR_PTR(-ERESTARTNOINTR
);
599 spin_lock(&dentry
->d_lock
);
600 dentry
->d_flags
&= ~DCACHE_AUTOFS_PENDING
;
601 spin_unlock(&dentry
->d_lock
);
606 * If this dentry is unhashed, then we shouldn't honour this
607 * lookup. Returning ENOENT here doesn't do the right thing
608 * for all system calls, but it should be OK for the operations
609 * we permit from an autofs.
611 if (!oz_mode
&& d_unhashed(dentry
)) {
613 * A user space application can (and has done in the past)
614 * remove and re-create this directory during the callback.
615 * This can leave us with an unhashed dentry, but a
616 * successful mount! So we need to perform another
617 * cached lookup in case the dentry now exists.
619 struct dentry
*parent
= dentry
->d_parent
;
620 struct dentry
*new = d_lookup(parent
, &dentry
->d_name
);
624 dentry
= ERR_PTR(-ENOENT
);
638 static int autofs4_dir_symlink(struct inode
*dir
,
639 struct dentry
*dentry
,
642 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
643 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
644 struct autofs_info
*p_ino
;
648 DPRINTK("%s <- %.*s", symname
,
649 dentry
->d_name
.len
, dentry
->d_name
.name
);
651 if (!autofs4_oz_mode(sbi
))
654 ino
= autofs4_init_ino(ino
, sbi
, S_IFLNK
| 0555);
658 spin_lock(&sbi
->lookup_lock
);
659 if (!list_empty(&ino
->active
))
660 list_del_init(&ino
->active
);
661 spin_unlock(&sbi
->lookup_lock
);
663 ino
->size
= strlen(symname
);
664 cp
= kmalloc(ino
->size
+ 1, GFP_KERNEL
);
666 if (!dentry
->d_fsdata
)
673 inode
= autofs4_get_inode(dir
->i_sb
, ino
);
676 if (!dentry
->d_fsdata
)
680 d_add(dentry
, inode
);
682 if (dir
== dir
->i_sb
->s_root
->d_inode
)
683 dentry
->d_op
= &autofs4_root_dentry_operations
;
685 dentry
->d_op
= &autofs4_dentry_operations
;
687 dentry
->d_fsdata
= ino
;
688 ino
->dentry
= dget(dentry
);
689 atomic_inc(&ino
->count
);
690 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
691 if (p_ino
&& dentry
->d_parent
!= dentry
)
692 atomic_inc(&p_ino
->count
);
696 dir
->i_mtime
= CURRENT_TIME
;
704 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
705 * that the file no longer exists. However, doing that means that the
706 * VFS layer can turn the dentry into a negative dentry. We don't want
707 * this, because the unlink is probably the result of an expire.
708 * We simply d_drop it and add it to a expiring list in the super block,
709 * which allows the dentry lookup to check for an incomplete expire.
711 * If a process is blocked on the dentry waiting for the expire to finish,
712 * it will invalidate the dentry and try to mount with a new one.
714 * Also see autofs4_dir_rmdir()..
716 static int autofs4_dir_unlink(struct inode
*dir
, struct dentry
*dentry
)
718 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
719 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
720 struct autofs_info
*p_ino
;
722 /* This allows root to remove symlinks */
723 if (!autofs4_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
726 if (atomic_dec_and_test(&ino
->count
)) {
727 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
728 if (p_ino
&& dentry
->d_parent
!= dentry
)
729 atomic_dec(&p_ino
->count
);
733 dentry
->d_inode
->i_size
= 0;
734 clear_nlink(dentry
->d_inode
);
736 dir
->i_mtime
= CURRENT_TIME
;
738 spin_lock(&dcache_lock
);
739 spin_lock(&sbi
->lookup_lock
);
740 if (list_empty(&ino
->expiring
))
741 list_add(&ino
->expiring
, &sbi
->expiring_list
);
742 spin_unlock(&sbi
->lookup_lock
);
743 spin_lock(&dentry
->d_lock
);
745 spin_unlock(&dentry
->d_lock
);
746 spin_unlock(&dcache_lock
);
751 static int autofs4_dir_rmdir(struct inode
*dir
, struct dentry
*dentry
)
753 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
754 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
755 struct autofs_info
*p_ino
;
757 DPRINTK("dentry %p, removing %.*s",
758 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
760 if (!autofs4_oz_mode(sbi
))
763 spin_lock(&dcache_lock
);
764 if (!list_empty(&dentry
->d_subdirs
)) {
765 spin_unlock(&dcache_lock
);
768 spin_lock(&sbi
->lookup_lock
);
769 if (list_empty(&ino
->expiring
))
770 list_add(&ino
->expiring
, &sbi
->expiring_list
);
771 spin_unlock(&sbi
->lookup_lock
);
772 spin_lock(&dentry
->d_lock
);
774 spin_unlock(&dentry
->d_lock
);
775 spin_unlock(&dcache_lock
);
777 if (atomic_dec_and_test(&ino
->count
)) {
778 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
779 if (p_ino
&& dentry
->d_parent
!= dentry
)
780 atomic_dec(&p_ino
->count
);
783 dentry
->d_inode
->i_size
= 0;
784 clear_nlink(dentry
->d_inode
);
792 static int autofs4_dir_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
794 struct autofs_sb_info
*sbi
= autofs4_sbi(dir
->i_sb
);
795 struct autofs_info
*ino
= autofs4_dentry_ino(dentry
);
796 struct autofs_info
*p_ino
;
799 if (!autofs4_oz_mode(sbi
))
802 DPRINTK("dentry %p, creating %.*s",
803 dentry
, dentry
->d_name
.len
, dentry
->d_name
.name
);
805 ino
= autofs4_init_ino(ino
, sbi
, S_IFDIR
| 0555);
809 spin_lock(&sbi
->lookup_lock
);
810 if (!list_empty(&ino
->active
))
811 list_del_init(&ino
->active
);
812 spin_unlock(&sbi
->lookup_lock
);
814 inode
= autofs4_get_inode(dir
->i_sb
, ino
);
816 if (!dentry
->d_fsdata
)
820 d_add(dentry
, inode
);
822 if (dir
== dir
->i_sb
->s_root
->d_inode
)
823 dentry
->d_op
= &autofs4_root_dentry_operations
;
825 dentry
->d_op
= &autofs4_dentry_operations
;
827 dentry
->d_fsdata
= ino
;
828 ino
->dentry
= dget(dentry
);
829 atomic_inc(&ino
->count
);
830 p_ino
= autofs4_dentry_ino(dentry
->d_parent
);
831 if (p_ino
&& dentry
->d_parent
!= dentry
)
832 atomic_inc(&p_ino
->count
);
835 dir
->i_mtime
= CURRENT_TIME
;
840 /* Get/set timeout ioctl() operation */
841 static inline int autofs4_get_set_timeout(struct autofs_sb_info
*sbi
,
842 unsigned long __user
*p
)
845 unsigned long ntimeout
;
847 if ((rv
= get_user(ntimeout
, p
)) ||
848 (rv
= put_user(sbi
->exp_timeout
/HZ
, p
)))
851 if (ntimeout
> ULONG_MAX
/HZ
)
852 sbi
->exp_timeout
= 0;
854 sbi
->exp_timeout
= ntimeout
* HZ
;
859 /* Return protocol version */
860 static inline int autofs4_get_protover(struct autofs_sb_info
*sbi
, int __user
*p
)
862 return put_user(sbi
->version
, p
);
865 /* Return protocol sub version */
866 static inline int autofs4_get_protosubver(struct autofs_sb_info
*sbi
, int __user
*p
)
868 return put_user(sbi
->sub_version
, p
);
872 * Tells the daemon whether we need to reghost or not. Also, clears
873 * the reghost_needed flag.
875 static inline int autofs4_ask_reghost(struct autofs_sb_info
*sbi
, int __user
*p
)
879 DPRINTK("returning %d", sbi
->needs_reghost
);
881 status
= put_user(sbi
->needs_reghost
, p
);
885 sbi
->needs_reghost
= 0;
890 * Enable / Disable reghosting ioctl() operation
892 static inline int autofs4_toggle_reghost(struct autofs_sb_info
*sbi
, int __user
*p
)
897 status
= get_user(val
, p
);
899 DPRINTK("reghost = %d", val
);
904 /* turn on/off reghosting, with the val */
905 sbi
->reghost_enabled
= val
;
910 * Tells the daemon whether it can umount the autofs mount.
912 static inline int autofs4_ask_umount(struct vfsmount
*mnt
, int __user
*p
)
919 DPRINTK("returning %d", status
);
921 status
= put_user(status
, p
);
926 /* Identify autofs4_dentries - this is so we can tell if there's
927 an extra dentry refcount or not. We only hold a refcount on the
928 dentry if its non-negative (ie, d_inode != NULL)
930 int is_autofs4_dentry(struct dentry
*dentry
)
932 return dentry
&& dentry
->d_inode
&&
933 (dentry
->d_op
== &autofs4_root_dentry_operations
||
934 dentry
->d_op
== &autofs4_dentry_operations
) &&
935 dentry
->d_fsdata
!= NULL
;
939 * ioctl()'s on the root directory is the chief method for the daemon to
940 * generate kernel reactions
942 static int autofs4_root_ioctl(struct inode
*inode
, struct file
*filp
,
943 unsigned int cmd
, unsigned long arg
)
945 struct autofs_sb_info
*sbi
= autofs4_sbi(inode
->i_sb
);
946 void __user
*p
= (void __user
*)arg
;
948 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
949 cmd
,arg
,sbi
,task_pgrp_nr(current
));
951 if (_IOC_TYPE(cmd
) != _IOC_TYPE(AUTOFS_IOC_FIRST
) ||
952 _IOC_NR(cmd
) - _IOC_NR(AUTOFS_IOC_FIRST
) >= AUTOFS_IOC_COUNT
)
955 if (!autofs4_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
959 case AUTOFS_IOC_READY
: /* Wait queue: go ahead and retry */
960 return autofs4_wait_release(sbi
,(autofs_wqt_t
)arg
,0);
961 case AUTOFS_IOC_FAIL
: /* Wait queue: fail with ENOENT */
962 return autofs4_wait_release(sbi
,(autofs_wqt_t
)arg
,-ENOENT
);
963 case AUTOFS_IOC_CATATONIC
: /* Enter catatonic mode (daemon shutdown) */
964 autofs4_catatonic_mode(sbi
);
966 case AUTOFS_IOC_PROTOVER
: /* Get protocol version */
967 return autofs4_get_protover(sbi
, p
);
968 case AUTOFS_IOC_PROTOSUBVER
: /* Get protocol sub version */
969 return autofs4_get_protosubver(sbi
, p
);
970 case AUTOFS_IOC_SETTIMEOUT
:
971 return autofs4_get_set_timeout(sbi
, p
);
973 case AUTOFS_IOC_TOGGLEREGHOST
:
974 return autofs4_toggle_reghost(sbi
, p
);
975 case AUTOFS_IOC_ASKREGHOST
:
976 return autofs4_ask_reghost(sbi
, p
);
978 case AUTOFS_IOC_ASKUMOUNT
:
979 return autofs4_ask_umount(filp
->f_path
.mnt
, p
);
981 /* return a single thing to expire */
982 case AUTOFS_IOC_EXPIRE
:
983 return autofs4_expire_run(inode
->i_sb
,filp
->f_path
.mnt
,sbi
, p
);
984 /* same as above, but can send multiple expires through pipe */
985 case AUTOFS_IOC_EXPIRE_MULTI
:
986 return autofs4_expire_multi(inode
->i_sb
,filp
->f_path
.mnt
,sbi
, p
);