Home | History | Annotate | Line # | Download | only in autofs
autofs_vfsops.c revision 1.3
      1  1.1  christos /*-
      2  1.1  christos  * Copyright (c) 2017 The NetBSD Foundation, Inc.
      3  1.1  christos  * Copyright (c) 2016 The DragonFly Project
      4  1.1  christos  * Copyright (c) 2014 The FreeBSD Foundation
      5  1.1  christos  * All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  christos  * by Tomohiro Kusumi <kusumi.tomohiro (at) gmail.com>.
      9  1.1  christos  *
     10  1.1  christos  * This software was developed by Edward Tomasz Napierala under sponsorship
     11  1.1  christos  * from the FreeBSD Foundation.
     12  1.1  christos  *
     13  1.1  christos  * Redistribution and use in source and binary forms, with or without
     14  1.1  christos  * modification, are permitted provided that the following conditions
     15  1.1  christos  * are met:
     16  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     17  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     18  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     20  1.1  christos  *    documentation and/or other materials provided with the distribution.
     21  1.1  christos  *
     22  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     23  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     26  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  christos  * SUCH DAMAGE.
     33  1.1  christos  *
     34  1.1  christos  */
     35  1.1  christos #include <sys/cdefs.h>
     36  1.3  christos __KERNEL_RCSID(0, "$NetBSD: autofs_vfsops.c,v 1.3 2018/01/13 22:06:21 christos Exp $");
     37  1.1  christos 
     38  1.1  christos 
     39  1.1  christos #include "autofs.h"
     40  1.1  christos #include "autofs_mount.h"
     41  1.1  christos 
     42  1.1  christos #include <sys/stat.h>
     43  1.1  christos #include <sys/sysctl.h>
     44  1.1  christos #include <miscfs/genfs/genfs.h>
     45  1.1  christos 
     46  1.1  christos MODULE(MODULE_CLASS_VFS, autofs, NULL);
     47  1.1  christos 
     48  1.1  christos static int	autofs_statvfs(struct mount *, struct statvfs *);
     49  1.2  christos static int	autofs_sysctl_create(void);
     50  1.1  christos 
     51  1.1  christos static void
     52  1.1  christos autofs_init(void)
     53  1.1  christos {
     54  1.1  christos 
     55  1.1  christos 	KASSERT(!autofs_softc);
     56  1.1  christos 
     57  1.1  christos 	autofs_softc = kmem_zalloc(sizeof(*autofs_softc), KM_SLEEP);
     58  1.1  christos 
     59  1.1  christos 	pool_init(&autofs_request_pool, sizeof(struct autofs_request), 0, 0, 0,
     60  1.1  christos 	    "autofs_request", &pool_allocator_nointr, IPL_NONE);
     61  1.1  christos 	pool_init(&autofs_node_pool, sizeof(struct autofs_node), 0, 0, 0,
     62  1.1  christos 	    "autofs_node", &pool_allocator_nointr, IPL_NONE);
     63  1.1  christos 
     64  1.1  christos 	TAILQ_INIT(&autofs_softc->sc_requests);
     65  1.1  christos 	cv_init(&autofs_softc->sc_cv, "autofscv");
     66  1.1  christos 	mutex_init(&autofs_softc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
     67  1.1  christos 	autofs_softc->sc_dev_opened = false;
     68  1.2  christos 
     69  1.2  christos 	autofs_sysctl_create();
     70  1.2  christos 	workqueue_create(&autofs_tmo_wq, "autofstmo",
     71  1.2  christos 	    autofs_timeout_wq, NULL, 0, 0, WQ_MPSAFE);
     72  1.1  christos }
     73  1.1  christos 
     74  1.1  christos static void
     75  1.1  christos autofs_done(void)
     76  1.1  christos {
     77  1.1  christos 	KASSERT(autofs_softc);
     78  1.1  christos 	KASSERT(!autofs_softc->sc_dev_opened);
     79  1.1  christos 
     80  1.2  christos 	workqueue_destroy(autofs_tmo_wq);
     81  1.2  christos 
     82  1.1  christos 	struct autofs_softc *sc = autofs_softc;
     83  1.1  christos 	autofs_softc = NULL;
     84  1.1  christos 
     85  1.1  christos 	cv_destroy(&sc->sc_cv);
     86  1.1  christos 	mutex_destroy(&sc->sc_lock);
     87  1.1  christos 
     88  1.1  christos 	pool_destroy(&autofs_request_pool);
     89  1.1  christos 	pool_destroy(&autofs_node_pool);
     90  1.1  christos 
     91  1.1  christos 	kmem_free(sc, sizeof(*sc));
     92  1.1  christos }
     93  1.1  christos 
     94  1.1  christos static int
     95  1.1  christos autofs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
     96  1.1  christos {
     97  1.1  christos 	struct autofs_args *args = data;
     98  1.1  christos 	struct autofs_mount *amp;
     99  1.1  christos 	struct statvfs *sbp = &mp->mnt_stat;
    100  1.1  christos 	int error;
    101  1.1  christos 
    102  1.1  christos 	if (!args)
    103  1.1  christos 		return EINVAL;
    104  1.1  christos 
    105  1.1  christos 	/*
    106  1.1  christos 	 * MNT_GETARGS is unsupported.  Autofs is mounted via automount(8) by
    107  1.1  christos 	 * parsing /etc/auto_master instead of regular mount(8) variants with
    108  1.1  christos 	 * -o getargs support, thus not really needed either.
    109  1.1  christos 	 */
    110  1.1  christos 	if (mp->mnt_flag & MNT_GETARGS)
    111  1.1  christos 		return EOPNOTSUPP;
    112  1.1  christos 
    113  1.1  christos 	if (mp->mnt_flag & MNT_UPDATE) {
    114  1.1  christos 		autofs_flush(VFSTOAUTOFS(mp));
    115  1.1  christos 		return 0;
    116  1.1  christos 	}
    117  1.1  christos 
    118  1.1  christos 	/*
    119  1.1  christos 	 * Allocate the autofs mount.
    120  1.1  christos 	 */
    121  1.1  christos 	amp = kmem_zalloc(sizeof(*amp), KM_SLEEP);
    122  1.1  christos 	mp->mnt_data = amp;
    123  1.1  christos 	amp->am_mp = mp;
    124  1.1  christos 
    125  1.1  christos 	/*
    126  1.1  christos 	 * Copy-in master_options string.
    127  1.1  christos 	 */
    128  1.1  christos 	error = copyinstr(args->master_options, amp->am_options,
    129  1.1  christos 	    sizeof(amp->am_options), NULL);
    130  1.1  christos 	if (error)
    131  1.1  christos 		goto fail;
    132  1.1  christos 
    133  1.1  christos 	/*
    134  1.1  christos 	 * Copy-in master_prefix string.
    135  1.1  christos 	 */
    136  1.1  christos 	error = copyinstr(args->master_prefix, amp->am_prefix,
    137  1.1  christos 	    sizeof(amp->am_prefix), NULL);
    138  1.1  christos 	if (error)
    139  1.1  christos 		goto fail;
    140  1.1  christos 
    141  1.1  christos 	/*
    142  1.1  christos 	 * Initialize the autofs mount.
    143  1.1  christos 	 */
    144  1.1  christos 	mutex_init(&amp->am_lock, MUTEX_DEFAULT, IPL_NONE);
    145  1.1  christos 	amp->am_last_ino = AUTOFS_ROOTINO;
    146  1.1  christos 
    147  1.1  christos 	mutex_enter(&amp->am_lock);
    148  1.1  christos 	error = autofs_node_new(NULL, amp, ".", -1, &amp->am_root);
    149  1.1  christos 	if (error) {
    150  1.1  christos 		mutex_exit(&amp->am_lock);
    151  1.1  christos 		goto fail;
    152  1.1  christos 	}
    153  1.1  christos 	mutex_exit(&amp->am_lock);
    154  1.1  christos 	KASSERT(amp->am_root->an_ino == AUTOFS_ROOTINO);
    155  1.1  christos 
    156  1.1  christos 	autofs_statvfs(mp, sbp);
    157  1.1  christos 	vfs_getnewfsid(mp);
    158  1.1  christos 
    159  1.1  christos 	error = set_statvfs_info(path, UIO_USERSPACE, args->from, UIO_USERSPACE,
    160  1.1  christos 	    mp->mnt_op->vfs_name, mp, curlwp);
    161  1.1  christos 	if (error)
    162  1.1  christos 		goto fail;
    163  1.1  christos 	strlcpy(amp->am_from, sbp->f_mntfromname, sizeof(amp->am_from));
    164  1.1  christos 	strlcpy(amp->am_on, sbp->f_mntonname, sizeof(amp->am_on));
    165  1.1  christos 
    166  1.1  christos 	return 0;
    167  1.1  christos 
    168  1.1  christos fail:
    169  1.1  christos 	kmem_free(amp, sizeof(*amp));
    170  1.1  christos 	return error;
    171  1.1  christos }
    172  1.1  christos 
    173  1.1  christos static int
    174  1.1  christos autofs_unmount(struct mount *mp, int mntflags)
    175  1.1  christos {
    176  1.1  christos 	struct autofs_mount *amp = VFSTOAUTOFS(mp);
    177  1.1  christos 	int error, flags;
    178  1.1  christos 
    179  1.1  christos 	flags = 0;
    180  1.1  christos 	if (mntflags & MNT_FORCE)
    181  1.1  christos 		flags |= FORCECLOSE;
    182  1.1  christos 	error = vflush(mp, NULL, flags);
    183  1.1  christos 	if (error) {
    184  1.1  christos 		AUTOFS_WARN("vflush failed with error %d", error);
    185  1.1  christos 		return error;
    186  1.1  christos 	}
    187  1.1  christos 
    188  1.1  christos 	/*
    189  1.1  christos 	 * All vnodes are gone, and new one will not appear - so,
    190  1.1  christos 	 * no new triggerings.
    191  1.1  christos 	 */
    192  1.1  christos 	for (;;) {
    193  1.1  christos 		struct autofs_request *ar;
    194  1.1  christos 		int dummy;
    195  1.1  christos 		bool found;
    196  1.1  christos 
    197  1.1  christos 		found = false;
    198  1.1  christos 		mutex_enter(&autofs_softc->sc_lock);
    199  1.1  christos 		TAILQ_FOREACH(ar, &autofs_softc->sc_requests, ar_next) {
    200  1.1  christos 			if (ar->ar_mount != amp)
    201  1.1  christos 				continue;
    202  1.1  christos 			ar->ar_error = ENXIO;
    203  1.1  christos 			ar->ar_done = true;
    204  1.1  christos 			ar->ar_in_progress = false;
    205  1.1  christos 			found = true;
    206  1.1  christos 		}
    207  1.1  christos 		if (found == false) {
    208  1.1  christos 			mutex_exit(&autofs_softc->sc_lock);
    209  1.1  christos 			break;
    210  1.1  christos 		}
    211  1.1  christos 
    212  1.1  christos 		cv_broadcast(&autofs_softc->sc_cv);
    213  1.1  christos 		mutex_exit(&autofs_softc->sc_lock);
    214  1.1  christos 
    215  1.1  christos 		tsleep(&dummy, 0, "autofs_umount", hz);
    216  1.1  christos 	}
    217  1.1  christos 
    218  1.1  christos 	mutex_enter(&amp->am_lock);
    219  1.1  christos 	while (!RB_EMPTY(&amp->am_root->an_children)) {
    220  1.1  christos 		struct autofs_node *anp;
    221  1.1  christos 		anp = RB_MIN(autofs_node_tree, &amp->am_root->an_children);
    222  1.3  christos 		if (!RB_EMPTY(&anp->an_children)) {
    223  1.3  christos 			AUTOFS_DEBUG("%s: %s has children", __func__,
    224  1.3  christos 			    anp->an_name);
    225  1.3  christos 			mutex_exit(&amp->am_lock);
    226  1.3  christos 			return EBUSY;
    227  1.3  christos 		}
    228  1.3  christos 
    229  1.1  christos 		autofs_node_delete(anp);
    230  1.1  christos 	}
    231  1.1  christos 	autofs_node_delete(amp->am_root);
    232  1.1  christos 	mp->mnt_data = NULL;
    233  1.1  christos 	mutex_exit(&amp->am_lock);
    234  1.1  christos 
    235  1.1  christos 	mutex_destroy(&amp->am_lock);
    236  1.1  christos 
    237  1.1  christos 	kmem_free(amp, sizeof(*amp));
    238  1.1  christos 
    239  1.1  christos 	return 0;
    240  1.1  christos }
    241  1.1  christos 
    242  1.1  christos static int
    243  1.1  christos autofs_start(struct mount *mp, int flags)
    244  1.1  christos {
    245  1.1  christos 
    246  1.1  christos 	return 0;
    247  1.1  christos }
    248  1.1  christos 
    249  1.1  christos static int
    250  1.1  christos autofs_root(struct mount *mp, struct vnode **vpp)
    251  1.1  christos {
    252  1.1  christos 	struct autofs_node *anp = VFSTOAUTOFS(mp)->am_root;
    253  1.1  christos 	int error;
    254  1.1  christos 
    255  1.1  christos 	error = vcache_get(mp, &anp, sizeof(anp), vpp);
    256  1.1  christos 	if (error)
    257  1.1  christos 		return error;
    258  1.1  christos 	error = vn_lock(*vpp, LK_EXCLUSIVE);
    259  1.1  christos 	if (error) {
    260  1.1  christos 		vrele(*vpp);
    261  1.1  christos 		*vpp = NULL;
    262  1.1  christos 		return error;
    263  1.1  christos 	}
    264  1.1  christos 
    265  1.1  christos 	return 0;
    266  1.1  christos }
    267  1.1  christos 
    268  1.1  christos static int
    269  1.1  christos autofs_statvfs(struct mount *mp, struct statvfs *sbp)
    270  1.1  christos {
    271  1.1  christos 
    272  1.1  christos 	sbp->f_bsize = S_BLKSIZE;
    273  1.1  christos 	sbp->f_frsize = S_BLKSIZE;
    274  1.1  christos 	sbp->f_iosize = 0;
    275  1.1  christos 	sbp->f_blocks = 0;
    276  1.1  christos 	sbp->f_bfree = 0;
    277  1.1  christos 	sbp->f_bavail = 0;
    278  1.1  christos 	sbp->f_bresvd = 0;
    279  1.1  christos 	sbp->f_files = 0;
    280  1.1  christos 	sbp->f_ffree = 0;
    281  1.1  christos 	sbp->f_favail = 0;
    282  1.1  christos 	sbp->f_fresvd = 0;
    283  1.1  christos 
    284  1.1  christos 	copy_statvfs_info(sbp, mp);
    285  1.1  christos 
    286  1.1  christos 	return 0;
    287  1.1  christos }
    288  1.1  christos 
    289  1.1  christos static int
    290  1.1  christos autofs_sync(struct mount *mp, int waitfor, kauth_cred_t uc)
    291  1.1  christos {
    292  1.1  christos 
    293  1.1  christos 	return 0;
    294  1.1  christos }
    295  1.1  christos 
    296  1.1  christos static int
    297  1.1  christos autofs_loadvnode(struct mount *mp, struct vnode *vp,
    298  1.1  christos     const void *key, size_t key_len, const void **new_key)
    299  1.1  christos {
    300  1.1  christos 	struct autofs_node *anp;
    301  1.1  christos 
    302  1.1  christos 	KASSERT(key_len == sizeof(anp));
    303  1.1  christos 	memcpy(&anp, key, key_len);
    304  1.1  christos 	KASSERT(!anp->an_vnode);
    305  1.1  christos 
    306  1.1  christos 	vp->v_tag = VT_AUTOFS;
    307  1.1  christos 	vp->v_type = VDIR;
    308  1.1  christos 	vp->v_op = autofs_vnodeop_p;
    309  1.1  christos 	vp->v_data = anp;
    310  1.1  christos 
    311  1.1  christos 	if (anp->an_ino == AUTOFS_ROOTINO)
    312  1.1  christos 		vp->v_vflag |= VV_ROOT;
    313  1.1  christos 
    314  1.1  christos 	anp->an_vnode = vp;
    315  1.1  christos 	uvm_vnp_setsize(vp, 0);
    316  1.1  christos 
    317  1.1  christos 	*new_key = &vp->v_data;
    318  1.1  christos 
    319  1.1  christos 	return 0;
    320  1.1  christos }
    321  1.1  christos 
    322  1.1  christos static const struct vnodeopv_desc * const autofs_vnodeopv_descs[] = {
    323  1.1  christos 	&autofs_vnodeop_opv_desc,
    324  1.1  christos 	NULL,
    325  1.1  christos };
    326  1.1  christos 
    327  1.1  christos static struct vfsops autofs_vfsops = {
    328  1.1  christos 	.vfs_name = MOUNT_AUTOFS,
    329  1.1  christos 	.vfs_min_mount_data = sizeof(struct autofs_args),
    330  1.1  christos 	.vfs_mount = autofs_mount,
    331  1.1  christos 	.vfs_start = autofs_start,
    332  1.1  christos 	.vfs_unmount = autofs_unmount,
    333  1.1  christos 	.vfs_root = autofs_root,
    334  1.1  christos 	.vfs_quotactl = (void *)eopnotsupp,
    335  1.1  christos 	.vfs_statvfs = autofs_statvfs,
    336  1.1  christos 	.vfs_sync = autofs_sync,
    337  1.1  christos 	.vfs_vget = (void *)eopnotsupp,
    338  1.1  christos 	.vfs_loadvnode = (void *)autofs_loadvnode,
    339  1.1  christos 	.vfs_newvnode = (void *)eopnotsupp,
    340  1.1  christos 	.vfs_fhtovp = (void *)eopnotsupp,
    341  1.1  christos 	.vfs_vptofh = (void *)eopnotsupp,
    342  1.1  christos 	.vfs_init = autofs_init,
    343  1.1  christos 	.vfs_reinit = (void *)eopnotsupp,
    344  1.1  christos 	.vfs_done = autofs_done,
    345  1.1  christos 	.vfs_mountroot = (void *)eopnotsupp,
    346  1.1  christos 	.vfs_snapshot = (void *)eopnotsupp,
    347  1.1  christos 	.vfs_extattrctl = (void *)eopnotsupp,
    348  1.1  christos 	.vfs_suspendctl = (void *)genfs_suspendctl,
    349  1.1  christos 	.vfs_renamelock_enter = (void *)eopnotsupp,
    350  1.1  christos 	.vfs_renamelock_exit = (void *)eopnotsupp,
    351  1.1  christos 	.vfs_fsync = (void *)eopnotsupp,
    352  1.1  christos 	.vfs_opv_descs = autofs_vnodeopv_descs
    353  1.1  christos };
    354  1.1  christos 
    355  1.1  christos #define AUTOFS_SYSCTL_DEBUG		1
    356  1.1  christos #define AUTOFS_SYSCTL_MOUNT_ON_STAT	2
    357  1.1  christos #define AUTOFS_SYSCTL_TIMEOUT		3
    358  1.1  christos #define AUTOFS_SYSCTL_CACHE		4
    359  1.1  christos #define AUTOFS_SYSCTL_RETRY_ATTEMPTS	5
    360  1.1  christos #define AUTOFS_SYSCTL_RETRY_DELAY	6
    361  1.1  christos #define AUTOFS_SYSCTL_INTERRUPTIBLE	7
    362  1.1  christos 
    363  1.1  christos static struct sysctllog *autofs_sysctl_log;
    364  1.1  christos 
    365  1.1  christos static int
    366  1.1  christos autofs_sysctl_create(void)
    367  1.1  christos {
    368  1.1  christos 	int error;
    369  1.1  christos 
    370  1.1  christos 	/*
    371  1.1  christos 	 * XXX the "33" below could be dynamic, thereby eliminating one
    372  1.1  christos 	 * more instance of the "number to vfs" mapping problem, but
    373  1.1  christos 	 * "33" is the order as taken from sys/mount.h
    374  1.1  christos 	 */
    375  1.1  christos 	error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
    376  1.1  christos 	    CTLFLAG_PERMANENT,
    377  1.1  christos 	    CTLTYPE_NODE, "autofs",
    378  1.1  christos 	    SYSCTL_DESCR("Automounter filesystem"),
    379  1.1  christos 	    NULL, 0, NULL, 0,
    380  1.1  christos 	    CTL_VFS, 33, CTL_EOL);
    381  1.1  christos 	if (error)
    382  1.1  christos 		goto fail;
    383  1.1  christos 
    384  1.1  christos 	error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
    385  1.1  christos 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
    386  1.1  christos 	    CTLTYPE_INT, "autofs_debug",
    387  1.1  christos 	    SYSCTL_DESCR("Enable debug messages"),
    388  1.1  christos 	    NULL, 0, &autofs_debug, 0,
    389  1.1  christos 	    CTL_VFS, 33, AUTOFS_SYSCTL_DEBUG, CTL_EOL);
    390  1.1  christos 	if (error)
    391  1.1  christos 		goto fail;
    392  1.1  christos 
    393  1.1  christos 	error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
    394  1.1  christos 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
    395  1.1  christos 	    CTLTYPE_INT, "autofs_mount_on_stat",
    396  1.1  christos 	    SYSCTL_DESCR("Trigger mount on stat(2) on mountpoint"),
    397  1.1  christos 	    NULL, 0, &autofs_mount_on_stat, 0,
    398  1.1  christos 	    CTL_VFS, 33, AUTOFS_SYSCTL_MOUNT_ON_STAT, CTL_EOL);
    399  1.1  christos 	if (error)
    400  1.1  christos 		goto fail;
    401  1.1  christos 
    402  1.1  christos 	error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
    403  1.1  christos 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
    404  1.1  christos 	    CTLTYPE_INT, "autofs_timeout",
    405  1.1  christos 	    SYSCTL_DESCR("Number of seconds to wait for automountd(8)"),
    406  1.1  christos 	    NULL, 0, &autofs_timeout, 0,
    407  1.1  christos 	    CTL_VFS, 33, AUTOFS_SYSCTL_TIMEOUT, CTL_EOL);
    408  1.1  christos 	if (error)
    409  1.1  christos 		goto fail;
    410  1.1  christos 
    411  1.1  christos 	error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
    412  1.1  christos 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
    413  1.1  christos 	    CTLTYPE_INT, "autofs_cache",
    414  1.1  christos 	    SYSCTL_DESCR("Number of seconds to wait before reinvoking"),
    415  1.1  christos 	    NULL, 0, &autofs_cache, 0,
    416  1.1  christos 	    CTL_VFS, 33, AUTOFS_SYSCTL_CACHE, CTL_EOL);
    417  1.1  christos 	if (error)
    418  1.1  christos 		goto fail;
    419  1.1  christos 
    420  1.1  christos 	error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
    421  1.1  christos 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
    422  1.1  christos 	    CTLTYPE_INT, "autofs_retry_attempts",
    423  1.1  christos 	    SYSCTL_DESCR("Number of attempts before failing mount"),
    424  1.1  christos 	    NULL, 0, &autofs_retry_attempts, 0,
    425  1.1  christos 	    CTL_VFS, 33, AUTOFS_SYSCTL_RETRY_ATTEMPTS, CTL_EOL);
    426  1.1  christos 	if (error)
    427  1.1  christos 		goto fail;
    428  1.1  christos 
    429  1.1  christos 	error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
    430  1.1  christos 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
    431  1.1  christos 	    CTLTYPE_INT, "autofs_retry_delay",
    432  1.1  christos 	    SYSCTL_DESCR("Number of seconds before retrying"),
    433  1.1  christos 	    NULL, 0, &autofs_retry_delay, 0,
    434  1.1  christos 	    CTL_VFS, 33, AUTOFS_SYSCTL_RETRY_DELAY, CTL_EOL);
    435  1.1  christos 	if (error)
    436  1.1  christos 		goto fail;
    437  1.1  christos 
    438  1.1  christos 	error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
    439  1.1  christos 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
    440  1.1  christos 	    CTLTYPE_INT, "autofs_interruptible",
    441  1.1  christos 	    SYSCTL_DESCR("Allow requests to be interrupted by signal"),
    442  1.1  christos 	    NULL, 0, &autofs_interruptible, 0,
    443  1.1  christos 	    CTL_VFS, 33, AUTOFS_SYSCTL_INTERRUPTIBLE, CTL_EOL);
    444  1.1  christos 	if (error)
    445  1.1  christos 		goto fail;
    446  1.1  christos 
    447  1.1  christos 	return 0;
    448  1.1  christos fail:
    449  1.1  christos 	AUTOFS_WARN("sysctl_createv failed with error %d", error);
    450  1.1  christos 
    451  1.1  christos 	return error;
    452  1.1  christos }
    453  1.1  christos 
    454  1.2  christos extern const struct cdevsw autofs_cdevsw;
    455  1.2  christos 
    456  1.1  christos static int
    457  1.1  christos autofs_modcmd(modcmd_t cmd, void *arg)
    458  1.1  christos {
    459  1.1  christos #ifdef _MODULE
    460  1.1  christos 	devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
    461  1.1  christos #endif
    462  1.1  christos 	int error = 0;
    463  1.1  christos 
    464  1.1  christos 	switch (cmd) {
    465  1.1  christos 	case MODULE_CMD_INIT:
    466  1.1  christos 		error = vfs_attach(&autofs_vfsops);
    467  1.1  christos 		if (error)
    468  1.1  christos 			break;
    469  1.1  christos #ifdef _MODULE
    470  1.2  christos 		error = devsw_attach("autofs", NULL, &bmajor, &autofs_cdevsw,
    471  1.1  christos 		    &cmajor);
    472  1.1  christos 		if (error) {
    473  1.1  christos 			vfs_detach(&autofs_vfsops);
    474  1.1  christos 			break;
    475  1.1  christos 		}
    476  1.1  christos #endif
    477  1.1  christos 		break;
    478  1.1  christos 	case MODULE_CMD_FINI:
    479  1.2  christos #ifdef _MODULE
    480  1.1  christos 		KASSERT(autofs_softc);
    481  1.1  christos 		mutex_enter(&autofs_softc->sc_lock);
    482  1.1  christos 		if (autofs_softc->sc_dev_opened) {
    483  1.1  christos 			mutex_exit(&autofs_softc->sc_lock);
    484  1.1  christos 			error = EBUSY;
    485  1.1  christos 			break;
    486  1.1  christos 		}
    487  1.1  christos 		mutex_exit(&autofs_softc->sc_lock);
    488  1.1  christos 
    489  1.2  christos 		error = devsw_detach(NULL, &autofs_cdevsw);
    490  1.1  christos 		if (error)
    491  1.1  christos 			break;
    492  1.1  christos #endif
    493  1.1  christos 		error = vfs_detach(&autofs_vfsops);
    494  1.1  christos 		if (error)
    495  1.1  christos 			break;
    496  1.1  christos 		break;
    497  1.1  christos 	default:
    498  1.1  christos 		error = ENOTTY;
    499  1.1  christos 		break;
    500  1.1  christos 	}
    501  1.1  christos 
    502  1.1  christos 	return error;
    503  1.1  christos }
    504