autofs_vfsops.c revision 1.2 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.2 christos __KERNEL_RCSID(0, "$NetBSD: autofs_vfsops.c,v 1.2 2018/01/09 16:19:39 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(&->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(&->am_lock);
148 1.1 christos error = autofs_node_new(NULL, amp, ".", -1, &->am_root);
149 1.1 christos if (error) {
150 1.1 christos mutex_exit(&->am_lock);
151 1.1 christos goto fail;
152 1.1 christos }
153 1.1 christos mutex_exit(&->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(&->am_lock);
219 1.1 christos while (!RB_EMPTY(&->am_root->an_children)) {
220 1.1 christos struct autofs_node *anp;
221 1.1 christos anp = RB_MIN(autofs_node_tree, &->am_root->an_children);
222 1.1 christos autofs_node_delete(anp);
223 1.1 christos }
224 1.1 christos autofs_node_delete(amp->am_root);
225 1.1 christos mp->mnt_data = NULL;
226 1.1 christos mutex_exit(&->am_lock);
227 1.1 christos
228 1.1 christos mutex_destroy(&->am_lock);
229 1.1 christos
230 1.1 christos kmem_free(amp, sizeof(*amp));
231 1.1 christos
232 1.1 christos return 0;
233 1.1 christos }
234 1.1 christos
235 1.1 christos static int
236 1.1 christos autofs_start(struct mount *mp, int flags)
237 1.1 christos {
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_root(struct mount *mp, struct vnode **vpp)
244 1.1 christos {
245 1.1 christos struct autofs_node *anp = VFSTOAUTOFS(mp)->am_root;
246 1.1 christos int error;
247 1.1 christos
248 1.1 christos error = vcache_get(mp, &anp, sizeof(anp), vpp);
249 1.1 christos if (error)
250 1.1 christos return error;
251 1.1 christos error = vn_lock(*vpp, LK_EXCLUSIVE);
252 1.1 christos if (error) {
253 1.1 christos vrele(*vpp);
254 1.1 christos *vpp = NULL;
255 1.1 christos return error;
256 1.1 christos }
257 1.1 christos
258 1.1 christos return 0;
259 1.1 christos }
260 1.1 christos
261 1.1 christos static int
262 1.1 christos autofs_statvfs(struct mount *mp, struct statvfs *sbp)
263 1.1 christos {
264 1.1 christos
265 1.1 christos sbp->f_bsize = S_BLKSIZE;
266 1.1 christos sbp->f_frsize = S_BLKSIZE;
267 1.1 christos sbp->f_iosize = 0;
268 1.1 christos sbp->f_blocks = 0;
269 1.1 christos sbp->f_bfree = 0;
270 1.1 christos sbp->f_bavail = 0;
271 1.1 christos sbp->f_bresvd = 0;
272 1.1 christos sbp->f_files = 0;
273 1.1 christos sbp->f_ffree = 0;
274 1.1 christos sbp->f_favail = 0;
275 1.1 christos sbp->f_fresvd = 0;
276 1.1 christos
277 1.1 christos copy_statvfs_info(sbp, mp);
278 1.1 christos
279 1.1 christos return 0;
280 1.1 christos }
281 1.1 christos
282 1.1 christos static int
283 1.1 christos autofs_sync(struct mount *mp, int waitfor, kauth_cred_t uc)
284 1.1 christos {
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_loadvnode(struct mount *mp, struct vnode *vp,
291 1.1 christos const void *key, size_t key_len, const void **new_key)
292 1.1 christos {
293 1.1 christos struct autofs_node *anp;
294 1.1 christos
295 1.1 christos KASSERT(key_len == sizeof(anp));
296 1.1 christos memcpy(&anp, key, key_len);
297 1.1 christos KASSERT(!anp->an_vnode);
298 1.1 christos
299 1.1 christos vp->v_tag = VT_AUTOFS;
300 1.1 christos vp->v_type = VDIR;
301 1.1 christos vp->v_op = autofs_vnodeop_p;
302 1.1 christos vp->v_data = anp;
303 1.1 christos
304 1.1 christos if (anp->an_ino == AUTOFS_ROOTINO)
305 1.1 christos vp->v_vflag |= VV_ROOT;
306 1.1 christos
307 1.1 christos anp->an_vnode = vp;
308 1.1 christos uvm_vnp_setsize(vp, 0);
309 1.1 christos
310 1.1 christos *new_key = &vp->v_data;
311 1.1 christos
312 1.1 christos return 0;
313 1.1 christos }
314 1.1 christos
315 1.1 christos static const struct vnodeopv_desc * const autofs_vnodeopv_descs[] = {
316 1.1 christos &autofs_vnodeop_opv_desc,
317 1.1 christos NULL,
318 1.1 christos };
319 1.1 christos
320 1.1 christos static struct vfsops autofs_vfsops = {
321 1.1 christos .vfs_name = MOUNT_AUTOFS,
322 1.1 christos .vfs_min_mount_data = sizeof(struct autofs_args),
323 1.1 christos .vfs_mount = autofs_mount,
324 1.1 christos .vfs_start = autofs_start,
325 1.1 christos .vfs_unmount = autofs_unmount,
326 1.1 christos .vfs_root = autofs_root,
327 1.1 christos .vfs_quotactl = (void *)eopnotsupp,
328 1.1 christos .vfs_statvfs = autofs_statvfs,
329 1.1 christos .vfs_sync = autofs_sync,
330 1.1 christos .vfs_vget = (void *)eopnotsupp,
331 1.1 christos .vfs_loadvnode = (void *)autofs_loadvnode,
332 1.1 christos .vfs_newvnode = (void *)eopnotsupp,
333 1.1 christos .vfs_fhtovp = (void *)eopnotsupp,
334 1.1 christos .vfs_vptofh = (void *)eopnotsupp,
335 1.1 christos .vfs_init = autofs_init,
336 1.1 christos .vfs_reinit = (void *)eopnotsupp,
337 1.1 christos .vfs_done = autofs_done,
338 1.1 christos .vfs_mountroot = (void *)eopnotsupp,
339 1.1 christos .vfs_snapshot = (void *)eopnotsupp,
340 1.1 christos .vfs_extattrctl = (void *)eopnotsupp,
341 1.1 christos .vfs_suspendctl = (void *)genfs_suspendctl,
342 1.1 christos .vfs_renamelock_enter = (void *)eopnotsupp,
343 1.1 christos .vfs_renamelock_exit = (void *)eopnotsupp,
344 1.1 christos .vfs_fsync = (void *)eopnotsupp,
345 1.1 christos .vfs_opv_descs = autofs_vnodeopv_descs
346 1.1 christos };
347 1.1 christos
348 1.1 christos #define AUTOFS_SYSCTL_DEBUG 1
349 1.1 christos #define AUTOFS_SYSCTL_MOUNT_ON_STAT 2
350 1.1 christos #define AUTOFS_SYSCTL_TIMEOUT 3
351 1.1 christos #define AUTOFS_SYSCTL_CACHE 4
352 1.1 christos #define AUTOFS_SYSCTL_RETRY_ATTEMPTS 5
353 1.1 christos #define AUTOFS_SYSCTL_RETRY_DELAY 6
354 1.1 christos #define AUTOFS_SYSCTL_INTERRUPTIBLE 7
355 1.1 christos
356 1.1 christos static struct sysctllog *autofs_sysctl_log;
357 1.1 christos
358 1.1 christos static int
359 1.1 christos autofs_sysctl_create(void)
360 1.1 christos {
361 1.1 christos int error;
362 1.1 christos
363 1.1 christos /*
364 1.1 christos * XXX the "33" below could be dynamic, thereby eliminating one
365 1.1 christos * more instance of the "number to vfs" mapping problem, but
366 1.1 christos * "33" is the order as taken from sys/mount.h
367 1.1 christos */
368 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
369 1.1 christos CTLFLAG_PERMANENT,
370 1.1 christos CTLTYPE_NODE, "autofs",
371 1.1 christos SYSCTL_DESCR("Automounter filesystem"),
372 1.1 christos NULL, 0, NULL, 0,
373 1.1 christos CTL_VFS, 33, CTL_EOL);
374 1.1 christos if (error)
375 1.1 christos goto fail;
376 1.1 christos
377 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
378 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
379 1.1 christos CTLTYPE_INT, "autofs_debug",
380 1.1 christos SYSCTL_DESCR("Enable debug messages"),
381 1.1 christos NULL, 0, &autofs_debug, 0,
382 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_DEBUG, CTL_EOL);
383 1.1 christos if (error)
384 1.1 christos goto fail;
385 1.1 christos
386 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
387 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
388 1.1 christos CTLTYPE_INT, "autofs_mount_on_stat",
389 1.1 christos SYSCTL_DESCR("Trigger mount on stat(2) on mountpoint"),
390 1.1 christos NULL, 0, &autofs_mount_on_stat, 0,
391 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_MOUNT_ON_STAT, CTL_EOL);
392 1.1 christos if (error)
393 1.1 christos goto fail;
394 1.1 christos
395 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
396 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
397 1.1 christos CTLTYPE_INT, "autofs_timeout",
398 1.1 christos SYSCTL_DESCR("Number of seconds to wait for automountd(8)"),
399 1.1 christos NULL, 0, &autofs_timeout, 0,
400 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_TIMEOUT, CTL_EOL);
401 1.1 christos if (error)
402 1.1 christos goto fail;
403 1.1 christos
404 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
405 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
406 1.1 christos CTLTYPE_INT, "autofs_cache",
407 1.1 christos SYSCTL_DESCR("Number of seconds to wait before reinvoking"),
408 1.1 christos NULL, 0, &autofs_cache, 0,
409 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_CACHE, CTL_EOL);
410 1.1 christos if (error)
411 1.1 christos goto fail;
412 1.1 christos
413 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
414 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
415 1.1 christos CTLTYPE_INT, "autofs_retry_attempts",
416 1.1 christos SYSCTL_DESCR("Number of attempts before failing mount"),
417 1.1 christos NULL, 0, &autofs_retry_attempts, 0,
418 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_RETRY_ATTEMPTS, CTL_EOL);
419 1.1 christos if (error)
420 1.1 christos goto fail;
421 1.1 christos
422 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
423 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
424 1.1 christos CTLTYPE_INT, "autofs_retry_delay",
425 1.1 christos SYSCTL_DESCR("Number of seconds before retrying"),
426 1.1 christos NULL, 0, &autofs_retry_delay, 0,
427 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_RETRY_DELAY, CTL_EOL);
428 1.1 christos if (error)
429 1.1 christos goto fail;
430 1.1 christos
431 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
432 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
433 1.1 christos CTLTYPE_INT, "autofs_interruptible",
434 1.1 christos SYSCTL_DESCR("Allow requests to be interrupted by signal"),
435 1.1 christos NULL, 0, &autofs_interruptible, 0,
436 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_INTERRUPTIBLE, CTL_EOL);
437 1.1 christos if (error)
438 1.1 christos goto fail;
439 1.1 christos
440 1.1 christos return 0;
441 1.1 christos fail:
442 1.1 christos AUTOFS_WARN("sysctl_createv failed with error %d", error);
443 1.1 christos
444 1.1 christos return error;
445 1.1 christos }
446 1.1 christos
447 1.2 christos extern const struct cdevsw autofs_cdevsw;
448 1.2 christos
449 1.1 christos static int
450 1.1 christos autofs_modcmd(modcmd_t cmd, void *arg)
451 1.1 christos {
452 1.1 christos #ifdef _MODULE
453 1.1 christos devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
454 1.1 christos #endif
455 1.1 christos int error = 0;
456 1.1 christos
457 1.1 christos switch (cmd) {
458 1.1 christos case MODULE_CMD_INIT:
459 1.1 christos error = vfs_attach(&autofs_vfsops);
460 1.1 christos if (error)
461 1.1 christos break;
462 1.1 christos #ifdef _MODULE
463 1.2 christos error = devsw_attach("autofs", NULL, &bmajor, &autofs_cdevsw,
464 1.1 christos &cmajor);
465 1.1 christos if (error) {
466 1.1 christos vfs_detach(&autofs_vfsops);
467 1.1 christos break;
468 1.1 christos }
469 1.1 christos #endif
470 1.1 christos break;
471 1.1 christos case MODULE_CMD_FINI:
472 1.2 christos #ifdef _MODULE
473 1.1 christos KASSERT(autofs_softc);
474 1.1 christos mutex_enter(&autofs_softc->sc_lock);
475 1.1 christos if (autofs_softc->sc_dev_opened) {
476 1.1 christos mutex_exit(&autofs_softc->sc_lock);
477 1.1 christos error = EBUSY;
478 1.1 christos break;
479 1.1 christos }
480 1.1 christos mutex_exit(&autofs_softc->sc_lock);
481 1.1 christos
482 1.2 christos error = devsw_detach(NULL, &autofs_cdevsw);
483 1.1 christos if (error)
484 1.1 christos break;
485 1.1 christos #endif
486 1.1 christos error = vfs_detach(&autofs_vfsops);
487 1.1 christos if (error)
488 1.1 christos break;
489 1.1 christos break;
490 1.1 christos default:
491 1.1 christos error = ENOTTY;
492 1.1 christos break;
493 1.1 christos }
494 1.1 christos
495 1.1 christos return error;
496 1.1 christos }
497