autofs_vfsops.c revision 1.4 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.4 christos __KERNEL_RCSID(0, "$NetBSD: autofs_vfsops.c,v 1.4 2018/01/14 22:43:18 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.4 christos struct autofs_mount *amp = VFSTOAUTOFS(mp);
99 1.1 christos struct statvfs *sbp = &mp->mnt_stat;
100 1.1 christos int error;
101 1.1 christos
102 1.4 christos if (mp->mnt_flag & MNT_UPDATE) {
103 1.4 christos if (amp == NULL)
104 1.4 christos return EIO;
105 1.4 christos autofs_flush(amp);
106 1.4 christos return 0;
107 1.4 christos }
108 1.4 christos
109 1.1 christos if (!args)
110 1.1 christos return EINVAL;
111 1.1 christos
112 1.4 christos if (mp->mnt_flag & MNT_GETARGS) {
113 1.4 christos if (amp == NULL)
114 1.4 christos return EIO;
115 1.4 christos error = copyoutstr(amp->am_from, args->from,
116 1.4 christos sizeof(amp->am_from), NULL);
117 1.4 christos if (error)
118 1.4 christos return error;
119 1.4 christos error = copyoutstr(amp->am_options, args->master_options,
120 1.4 christos sizeof(amp->am_options), NULL);
121 1.4 christos if (error)
122 1.4 christos return error;
123 1.4 christos error = copyoutstr(amp->am_prefix, args->master_prefix,
124 1.4 christos sizeof(amp->am_prefix), NULL);
125 1.4 christos return error;
126 1.4 christos }
127 1.1 christos
128 1.4 christos if (amp != NULL)
129 1.4 christos return EBUSY;
130 1.1 christos
131 1.1 christos /*
132 1.1 christos * Allocate the autofs mount.
133 1.1 christos */
134 1.1 christos amp = kmem_zalloc(sizeof(*amp), KM_SLEEP);
135 1.1 christos mp->mnt_data = amp;
136 1.1 christos amp->am_mp = mp;
137 1.1 christos
138 1.1 christos /*
139 1.1 christos * Copy-in master_options string.
140 1.1 christos */
141 1.1 christos error = copyinstr(args->master_options, amp->am_options,
142 1.1 christos sizeof(amp->am_options), NULL);
143 1.1 christos if (error)
144 1.1 christos goto fail;
145 1.1 christos
146 1.1 christos /*
147 1.1 christos * Copy-in master_prefix string.
148 1.1 christos */
149 1.1 christos error = copyinstr(args->master_prefix, amp->am_prefix,
150 1.1 christos sizeof(amp->am_prefix), NULL);
151 1.1 christos if (error)
152 1.1 christos goto fail;
153 1.1 christos
154 1.1 christos /*
155 1.1 christos * Initialize the autofs mount.
156 1.1 christos */
157 1.1 christos mutex_init(&->am_lock, MUTEX_DEFAULT, IPL_NONE);
158 1.1 christos amp->am_last_ino = AUTOFS_ROOTINO;
159 1.1 christos
160 1.1 christos mutex_enter(&->am_lock);
161 1.1 christos error = autofs_node_new(NULL, amp, ".", -1, &->am_root);
162 1.1 christos mutex_exit(&->am_lock);
163 1.4 christos if (error)
164 1.4 christos goto fail1;
165 1.1 christos KASSERT(amp->am_root->an_ino == AUTOFS_ROOTINO);
166 1.1 christos
167 1.1 christos autofs_statvfs(mp, sbp);
168 1.1 christos vfs_getnewfsid(mp);
169 1.1 christos
170 1.1 christos error = set_statvfs_info(path, UIO_USERSPACE, args->from, UIO_USERSPACE,
171 1.1 christos mp->mnt_op->vfs_name, mp, curlwp);
172 1.1 christos if (error)
173 1.4 christos goto fail1;
174 1.1 christos strlcpy(amp->am_from, sbp->f_mntfromname, sizeof(amp->am_from));
175 1.1 christos strlcpy(amp->am_on, sbp->f_mntonname, sizeof(amp->am_on));
176 1.1 christos
177 1.1 christos return 0;
178 1.1 christos
179 1.4 christos fail1:
180 1.4 christos mutex_destroy(&->am_lock);
181 1.1 christos fail:
182 1.4 christos mp->mnt_data = NULL;
183 1.1 christos kmem_free(amp, sizeof(*amp));
184 1.1 christos return error;
185 1.1 christos }
186 1.1 christos
187 1.1 christos static int
188 1.1 christos autofs_unmount(struct mount *mp, int mntflags)
189 1.1 christos {
190 1.1 christos struct autofs_mount *amp = VFSTOAUTOFS(mp);
191 1.1 christos int error, flags;
192 1.1 christos
193 1.1 christos flags = 0;
194 1.1 christos if (mntflags & MNT_FORCE)
195 1.1 christos flags |= FORCECLOSE;
196 1.1 christos error = vflush(mp, NULL, flags);
197 1.1 christos if (error) {
198 1.1 christos AUTOFS_WARN("vflush failed with error %d", error);
199 1.1 christos return error;
200 1.1 christos }
201 1.1 christos
202 1.1 christos /*
203 1.1 christos * All vnodes are gone, and new one will not appear - so,
204 1.1 christos * no new triggerings.
205 1.1 christos */
206 1.1 christos for (;;) {
207 1.1 christos struct autofs_request *ar;
208 1.1 christos int dummy;
209 1.1 christos bool found;
210 1.1 christos
211 1.1 christos found = false;
212 1.1 christos mutex_enter(&autofs_softc->sc_lock);
213 1.1 christos TAILQ_FOREACH(ar, &autofs_softc->sc_requests, ar_next) {
214 1.1 christos if (ar->ar_mount != amp)
215 1.1 christos continue;
216 1.1 christos ar->ar_error = ENXIO;
217 1.1 christos ar->ar_done = true;
218 1.1 christos ar->ar_in_progress = false;
219 1.1 christos found = true;
220 1.1 christos }
221 1.1 christos if (found == false) {
222 1.1 christos mutex_exit(&autofs_softc->sc_lock);
223 1.1 christos break;
224 1.1 christos }
225 1.1 christos
226 1.1 christos cv_broadcast(&autofs_softc->sc_cv);
227 1.1 christos mutex_exit(&autofs_softc->sc_lock);
228 1.1 christos
229 1.1 christos tsleep(&dummy, 0, "autofs_umount", hz);
230 1.1 christos }
231 1.1 christos
232 1.1 christos mutex_enter(&->am_lock);
233 1.1 christos while (!RB_EMPTY(&->am_root->an_children)) {
234 1.1 christos struct autofs_node *anp;
235 1.1 christos anp = RB_MIN(autofs_node_tree, &->am_root->an_children);
236 1.3 christos if (!RB_EMPTY(&anp->an_children)) {
237 1.3 christos AUTOFS_DEBUG("%s: %s has children", __func__,
238 1.3 christos anp->an_name);
239 1.3 christos mutex_exit(&->am_lock);
240 1.3 christos return EBUSY;
241 1.3 christos }
242 1.3 christos
243 1.1 christos autofs_node_delete(anp);
244 1.1 christos }
245 1.1 christos autofs_node_delete(amp->am_root);
246 1.1 christos mp->mnt_data = NULL;
247 1.1 christos mutex_exit(&->am_lock);
248 1.1 christos
249 1.1 christos mutex_destroy(&->am_lock);
250 1.1 christos
251 1.1 christos kmem_free(amp, sizeof(*amp));
252 1.1 christos
253 1.1 christos return 0;
254 1.1 christos }
255 1.1 christos
256 1.1 christos static int
257 1.1 christos autofs_start(struct mount *mp, int flags)
258 1.1 christos {
259 1.1 christos
260 1.1 christos return 0;
261 1.1 christos }
262 1.1 christos
263 1.1 christos static int
264 1.1 christos autofs_root(struct mount *mp, struct vnode **vpp)
265 1.1 christos {
266 1.1 christos struct autofs_node *anp = VFSTOAUTOFS(mp)->am_root;
267 1.1 christos int error;
268 1.1 christos
269 1.1 christos error = vcache_get(mp, &anp, sizeof(anp), vpp);
270 1.1 christos if (error)
271 1.1 christos return error;
272 1.1 christos error = vn_lock(*vpp, LK_EXCLUSIVE);
273 1.1 christos if (error) {
274 1.1 christos vrele(*vpp);
275 1.1 christos *vpp = NULL;
276 1.1 christos return error;
277 1.1 christos }
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_statvfs(struct mount *mp, struct statvfs *sbp)
284 1.1 christos {
285 1.1 christos
286 1.1 christos sbp->f_bsize = S_BLKSIZE;
287 1.1 christos sbp->f_frsize = S_BLKSIZE;
288 1.1 christos sbp->f_iosize = 0;
289 1.1 christos sbp->f_blocks = 0;
290 1.1 christos sbp->f_bfree = 0;
291 1.1 christos sbp->f_bavail = 0;
292 1.1 christos sbp->f_bresvd = 0;
293 1.1 christos sbp->f_files = 0;
294 1.1 christos sbp->f_ffree = 0;
295 1.1 christos sbp->f_favail = 0;
296 1.1 christos sbp->f_fresvd = 0;
297 1.1 christos
298 1.1 christos copy_statvfs_info(sbp, mp);
299 1.1 christos
300 1.1 christos return 0;
301 1.1 christos }
302 1.1 christos
303 1.1 christos static int
304 1.1 christos autofs_sync(struct mount *mp, int waitfor, kauth_cred_t uc)
305 1.1 christos {
306 1.1 christos
307 1.1 christos return 0;
308 1.1 christos }
309 1.1 christos
310 1.1 christos static int
311 1.1 christos autofs_loadvnode(struct mount *mp, struct vnode *vp,
312 1.1 christos const void *key, size_t key_len, const void **new_key)
313 1.1 christos {
314 1.1 christos struct autofs_node *anp;
315 1.1 christos
316 1.1 christos KASSERT(key_len == sizeof(anp));
317 1.1 christos memcpy(&anp, key, key_len);
318 1.1 christos KASSERT(!anp->an_vnode);
319 1.1 christos
320 1.1 christos vp->v_tag = VT_AUTOFS;
321 1.1 christos vp->v_type = VDIR;
322 1.1 christos vp->v_op = autofs_vnodeop_p;
323 1.1 christos vp->v_data = anp;
324 1.1 christos
325 1.1 christos if (anp->an_ino == AUTOFS_ROOTINO)
326 1.1 christos vp->v_vflag |= VV_ROOT;
327 1.1 christos
328 1.1 christos anp->an_vnode = vp;
329 1.1 christos uvm_vnp_setsize(vp, 0);
330 1.1 christos
331 1.1 christos *new_key = &vp->v_data;
332 1.1 christos
333 1.1 christos return 0;
334 1.1 christos }
335 1.1 christos
336 1.1 christos static const struct vnodeopv_desc * const autofs_vnodeopv_descs[] = {
337 1.1 christos &autofs_vnodeop_opv_desc,
338 1.1 christos NULL,
339 1.1 christos };
340 1.1 christos
341 1.1 christos static struct vfsops autofs_vfsops = {
342 1.1 christos .vfs_name = MOUNT_AUTOFS,
343 1.1 christos .vfs_min_mount_data = sizeof(struct autofs_args),
344 1.1 christos .vfs_mount = autofs_mount,
345 1.1 christos .vfs_start = autofs_start,
346 1.1 christos .vfs_unmount = autofs_unmount,
347 1.1 christos .vfs_root = autofs_root,
348 1.1 christos .vfs_quotactl = (void *)eopnotsupp,
349 1.1 christos .vfs_statvfs = autofs_statvfs,
350 1.1 christos .vfs_sync = autofs_sync,
351 1.1 christos .vfs_vget = (void *)eopnotsupp,
352 1.1 christos .vfs_loadvnode = (void *)autofs_loadvnode,
353 1.1 christos .vfs_newvnode = (void *)eopnotsupp,
354 1.1 christos .vfs_fhtovp = (void *)eopnotsupp,
355 1.1 christos .vfs_vptofh = (void *)eopnotsupp,
356 1.1 christos .vfs_init = autofs_init,
357 1.1 christos .vfs_reinit = (void *)eopnotsupp,
358 1.1 christos .vfs_done = autofs_done,
359 1.1 christos .vfs_mountroot = (void *)eopnotsupp,
360 1.1 christos .vfs_snapshot = (void *)eopnotsupp,
361 1.1 christos .vfs_extattrctl = (void *)eopnotsupp,
362 1.1 christos .vfs_suspendctl = (void *)genfs_suspendctl,
363 1.1 christos .vfs_renamelock_enter = (void *)eopnotsupp,
364 1.1 christos .vfs_renamelock_exit = (void *)eopnotsupp,
365 1.1 christos .vfs_fsync = (void *)eopnotsupp,
366 1.1 christos .vfs_opv_descs = autofs_vnodeopv_descs
367 1.1 christos };
368 1.1 christos
369 1.1 christos #define AUTOFS_SYSCTL_DEBUG 1
370 1.1 christos #define AUTOFS_SYSCTL_MOUNT_ON_STAT 2
371 1.1 christos #define AUTOFS_SYSCTL_TIMEOUT 3
372 1.1 christos #define AUTOFS_SYSCTL_CACHE 4
373 1.1 christos #define AUTOFS_SYSCTL_RETRY_ATTEMPTS 5
374 1.1 christos #define AUTOFS_SYSCTL_RETRY_DELAY 6
375 1.1 christos #define AUTOFS_SYSCTL_INTERRUPTIBLE 7
376 1.1 christos
377 1.1 christos static struct sysctllog *autofs_sysctl_log;
378 1.1 christos
379 1.1 christos static int
380 1.1 christos autofs_sysctl_create(void)
381 1.1 christos {
382 1.1 christos int error;
383 1.1 christos
384 1.1 christos /*
385 1.1 christos * XXX the "33" below could be dynamic, thereby eliminating one
386 1.1 christos * more instance of the "number to vfs" mapping problem, but
387 1.1 christos * "33" is the order as taken from sys/mount.h
388 1.1 christos */
389 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
390 1.1 christos CTLFLAG_PERMANENT,
391 1.1 christos CTLTYPE_NODE, "autofs",
392 1.1 christos SYSCTL_DESCR("Automounter filesystem"),
393 1.1 christos NULL, 0, NULL, 0,
394 1.1 christos CTL_VFS, 33, CTL_EOL);
395 1.1 christos if (error)
396 1.1 christos goto fail;
397 1.1 christos
398 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
399 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
400 1.1 christos CTLTYPE_INT, "autofs_debug",
401 1.1 christos SYSCTL_DESCR("Enable debug messages"),
402 1.1 christos NULL, 0, &autofs_debug, 0,
403 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_DEBUG, CTL_EOL);
404 1.1 christos if (error)
405 1.1 christos goto fail;
406 1.1 christos
407 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
408 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
409 1.1 christos CTLTYPE_INT, "autofs_mount_on_stat",
410 1.1 christos SYSCTL_DESCR("Trigger mount on stat(2) on mountpoint"),
411 1.1 christos NULL, 0, &autofs_mount_on_stat, 0,
412 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_MOUNT_ON_STAT, CTL_EOL);
413 1.1 christos if (error)
414 1.1 christos goto fail;
415 1.1 christos
416 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
417 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
418 1.1 christos CTLTYPE_INT, "autofs_timeout",
419 1.1 christos SYSCTL_DESCR("Number of seconds to wait for automountd(8)"),
420 1.1 christos NULL, 0, &autofs_timeout, 0,
421 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_TIMEOUT, CTL_EOL);
422 1.1 christos if (error)
423 1.1 christos goto fail;
424 1.1 christos
425 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
426 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
427 1.1 christos CTLTYPE_INT, "autofs_cache",
428 1.1 christos SYSCTL_DESCR("Number of seconds to wait before reinvoking"),
429 1.1 christos NULL, 0, &autofs_cache, 0,
430 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_CACHE, CTL_EOL);
431 1.1 christos if (error)
432 1.1 christos goto fail;
433 1.1 christos
434 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
435 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
436 1.1 christos CTLTYPE_INT, "autofs_retry_attempts",
437 1.1 christos SYSCTL_DESCR("Number of attempts before failing mount"),
438 1.1 christos NULL, 0, &autofs_retry_attempts, 0,
439 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_RETRY_ATTEMPTS, CTL_EOL);
440 1.1 christos if (error)
441 1.1 christos goto fail;
442 1.1 christos
443 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
444 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
445 1.1 christos CTLTYPE_INT, "autofs_retry_delay",
446 1.1 christos SYSCTL_DESCR("Number of seconds before retrying"),
447 1.1 christos NULL, 0, &autofs_retry_delay, 0,
448 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_RETRY_DELAY, CTL_EOL);
449 1.1 christos if (error)
450 1.1 christos goto fail;
451 1.1 christos
452 1.1 christos error = sysctl_createv(&autofs_sysctl_log, 0, NULL, NULL,
453 1.1 christos CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
454 1.1 christos CTLTYPE_INT, "autofs_interruptible",
455 1.1 christos SYSCTL_DESCR("Allow requests to be interrupted by signal"),
456 1.1 christos NULL, 0, &autofs_interruptible, 0,
457 1.1 christos CTL_VFS, 33, AUTOFS_SYSCTL_INTERRUPTIBLE, CTL_EOL);
458 1.1 christos if (error)
459 1.1 christos goto fail;
460 1.1 christos
461 1.1 christos return 0;
462 1.1 christos fail:
463 1.1 christos AUTOFS_WARN("sysctl_createv failed with error %d", error);
464 1.1 christos
465 1.1 christos return error;
466 1.1 christos }
467 1.1 christos
468 1.2 christos extern const struct cdevsw autofs_cdevsw;
469 1.2 christos
470 1.1 christos static int
471 1.1 christos autofs_modcmd(modcmd_t cmd, void *arg)
472 1.1 christos {
473 1.1 christos #ifdef _MODULE
474 1.1 christos devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
475 1.1 christos #endif
476 1.1 christos int error = 0;
477 1.1 christos
478 1.1 christos switch (cmd) {
479 1.1 christos case MODULE_CMD_INIT:
480 1.1 christos error = vfs_attach(&autofs_vfsops);
481 1.1 christos if (error)
482 1.1 christos break;
483 1.1 christos #ifdef _MODULE
484 1.2 christos error = devsw_attach("autofs", NULL, &bmajor, &autofs_cdevsw,
485 1.1 christos &cmajor);
486 1.1 christos if (error) {
487 1.1 christos vfs_detach(&autofs_vfsops);
488 1.1 christos break;
489 1.1 christos }
490 1.1 christos #endif
491 1.1 christos break;
492 1.1 christos case MODULE_CMD_FINI:
493 1.2 christos #ifdef _MODULE
494 1.1 christos KASSERT(autofs_softc);
495 1.1 christos mutex_enter(&autofs_softc->sc_lock);
496 1.1 christos if (autofs_softc->sc_dev_opened) {
497 1.1 christos mutex_exit(&autofs_softc->sc_lock);
498 1.1 christos error = EBUSY;
499 1.1 christos break;
500 1.1 christos }
501 1.1 christos mutex_exit(&autofs_softc->sc_lock);
502 1.1 christos
503 1.2 christos error = devsw_detach(NULL, &autofs_cdevsw);
504 1.1 christos if (error)
505 1.1 christos break;
506 1.1 christos #endif
507 1.1 christos error = vfs_detach(&autofs_vfsops);
508 1.1 christos if (error)
509 1.1 christos break;
510 1.1 christos break;
511 1.1 christos default:
512 1.1 christos error = ENOTTY;
513 1.1 christos break;
514 1.1 christos }
515 1.1 christos
516 1.1 christos return error;
517 1.1 christos }
518