xref: /freebsd/sys/kern/vfs_init.c (revision 88b8b7f0c4e9948667a2279e78e975a784049cba)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed
8  * to Berkeley by John Heidemann of the UCLA Ficus project.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/fnv_hash.h>
38 #include <sys/jail.h>
39 #include <sys/kernel.h>
40 #include <sys/linker.h>
41 #include <sys/mount.h>
42 #include <sys/proc.h>
43 #include <sys/sx.h>
44 #include <sys/syscallsubr.h>
45 #include <sys/sysctl.h>
46 #include <sys/vnode.h>
47 #include <sys/malloc.h>
48 
49 static int	vfs_register(struct vfsconf *);
50 static int	vfs_unregister(struct vfsconf *);
51 
52 MALLOC_DEFINE(M_VNODE, "vnodes", "Dynamically allocated vnodes");
53 
54 /*
55  * The highest defined VFS number.
56  */
57 int maxvfsconf = VFS_GENERIC + 1;
58 
59 /*
60  * Single-linked list of configured VFSes.
61  * New entries are added/deleted by vfs_register()/vfs_unregister()
62  */
63 struct vfsconfhead vfsconf = TAILQ_HEAD_INITIALIZER(vfsconf);
64 struct sx vfsconf_sx;
65 SX_SYSINIT(vfsconf, &vfsconf_sx, "vfsconf");
66 
67 /*
68  * Loader.conf variable vfs.typenumhash enables setting vfc_typenum using a hash
69  * calculation on vfc_name, so that it doesn't change when file systems are
70  * loaded in a different order. This will avoid the NFS server file handles from
71  * changing for file systems that use vfc_typenum in their fsid.
72  */
73 static int	vfs_typenumhash = 1;
74 SYSCTL_INT(_vfs, OID_AUTO, typenumhash, CTLFLAG_RDTUN, &vfs_typenumhash, 0,
75     "Set vfc_typenum using a hash calculation on vfc_name, so that it does not"
76     " change when file systems are loaded in a different order.");
77 
78 /*
79  * A Zen vnode attribute structure.
80  *
81  * Initialized when the first filesystem registers by vfs_register().
82  */
83 struct vattr va_null;
84 
85 /*
86  * vfs_init.c
87  *
88  * Allocate and fill in operations vectors.
89  *
90  * An undocumented feature of this approach to defining operations is that
91  * there can be multiple entries in vfs_opv_descs for the same operations
92  * vector. This allows third parties to extend the set of operations
93  * supported by another layer in a binary compatibile way. For example,
94  * assume that NFS needed to be modified to support Ficus. NFS has an entry
95  * (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by
96  * default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions)
97  * listing those new operations Ficus adds to NFS, all without modifying the
98  * NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but
99  * that is a(whole)nother story.) This is a feature.
100  */
101 
102 /*
103  * Routines having to do with the management of the vnode table.
104  */
105 
106 void
107 vfs_unref_vfsconf(struct vfsconf *vfsp)
108 {
109 	vfsconf_lock();
110 	KASSERT(vfsp->vfc_refcount > 0,
111 	    ("vfs %p refcount underflow %d", vfsp, vfsp->vfc_refcount));
112 	vfsp->vfc_refcount--;
113 	vfsconf_unlock();
114 }
115 
116 static struct vfsconf *
117 vfs_byname_locked(const char *name)
118 {
119 	struct vfsconf *vfsp;
120 
121 	sx_assert(&vfsconf_sx, SA_LOCKED);
122 	if (!strcmp(name, "ffs"))
123 		name = "ufs";
124 	TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
125 		if (!strcmp(name, vfsp->vfc_name))
126 			return (vfsp);
127 	}
128 	return (NULL);
129 }
130 
131 struct vfsconf *
132 vfs_byname(const char *name)
133 {
134 	struct vfsconf *vfsp;
135 
136 	vfsconf_lock();
137 	vfsp = vfs_byname_locked(name);
138 	if (vfsp != NULL)
139 		vfsp->vfc_refcount++;
140 	vfsconf_unlock();
141 	return (vfsp);
142 }
143 
144 struct vfsconf *
145 vfs_byname_kld(const char *fstype, struct thread *td, int *error)
146 {
147 	struct vfsconf *vfsp;
148 	int fileid, loaded;
149 
150 	vfsp = vfs_byname(fstype);
151 	if (vfsp != NULL)
152 		return (vfsp);
153 
154 	/* Try to load the respective module. */
155 	*error = kern_kldload(td, fstype, &fileid);
156 	loaded = (*error == 0);
157 	if (*error == EEXIST)
158 		*error = 0;
159 	if (*error) {
160 		*error = ENODEV;
161 		return (NULL);
162 	}
163 
164 	/* Look up again to see if the VFS was loaded. */
165 	vfsp = vfs_byname(fstype);
166 	if (vfsp == NULL) {
167 		if (loaded)
168 			(void)kern_kldunload(td, fileid, LINKER_UNLOAD_FORCE);
169 		*error = ENODEV;
170 		return (NULL);
171 	}
172 	return (vfsp);
173 }
174 
175 static int
176 vfs_mount_sigdefer(struct mount *mp)
177 {
178 	int prev_stops, rc;
179 
180 	TSRAW(curthread, TS_ENTER, "VFS_MOUNT", mp->mnt_vfc->vfc_name);
181 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
182 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_mount)(mp);
183 	sigallowstop(prev_stops);
184 	TSRAW(curthread, TS_EXIT, "VFS_MOUNT", mp->mnt_vfc->vfc_name);
185 	return (rc);
186 }
187 
188 static int
189 vfs_unmount_sigdefer(struct mount *mp, int mntflags)
190 {
191 	int prev_stops, rc;
192 
193 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
194 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_unmount)(mp, mntflags);
195 	sigallowstop(prev_stops);
196 	return (rc);
197 }
198 
199 static int
200 vfs_root_sigdefer(struct mount *mp, int flags, struct vnode **vpp)
201 {
202 	int prev_stops, rc;
203 
204 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
205 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_root)(mp, flags, vpp);
206 	sigallowstop(prev_stops);
207 	return (rc);
208 }
209 
210 static int
211 vfs_cachedroot_sigdefer(struct mount *mp, int flags, struct vnode **vpp)
212 {
213 	int prev_stops, rc;
214 
215 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
216 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_cachedroot)(mp, flags, vpp);
217 	sigallowstop(prev_stops);
218 	return (rc);
219 }
220 
221 static int
222 vfs_quotactl_sigdefer(struct mount *mp, int cmd, uid_t uid, void *arg,
223     bool *mp_busy)
224 {
225 	int prev_stops, rc;
226 
227 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
228 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_quotactl)(mp, cmd, uid, arg,
229 	    mp_busy);
230 	sigallowstop(prev_stops);
231 	return (rc);
232 }
233 
234 static int
235 vfs_statfs_sigdefer(struct mount *mp, struct statfs *sbp)
236 {
237 	int prev_stops, rc;
238 
239 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
240 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_statfs)(mp, sbp);
241 	sigallowstop(prev_stops);
242 	return (rc);
243 }
244 
245 static int
246 vfs_sync_sigdefer(struct mount *mp, int waitfor)
247 {
248 	int prev_stops, rc;
249 
250 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
251 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_sync)(mp, waitfor);
252 	sigallowstop(prev_stops);
253 	return (rc);
254 }
255 
256 static int
257 vfs_vget_sigdefer(struct mount *mp, ino_t ino, int flags, struct vnode **vpp)
258 {
259 	int prev_stops, rc;
260 
261 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
262 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_vget)(mp, ino, flags, vpp);
263 	sigallowstop(prev_stops);
264 	return (rc);
265 }
266 
267 static int
268 vfs_fhtovp_sigdefer(struct mount *mp, struct fid *fidp, int flags,
269     struct vnode **vpp)
270 {
271 	int prev_stops, rc;
272 
273 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
274 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_fhtovp)(mp, fidp, flags, vpp);
275 	sigallowstop(prev_stops);
276 	return (rc);
277 }
278 
279 static int
280 vfs_checkexp_sigdefer(struct mount *mp, struct sockaddr *nam, uint64_t *exflg,
281     struct ucred **credp, int *numsecflavors, int *secflavors)
282 {
283 	int prev_stops, rc;
284 
285 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
286 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_checkexp)(mp, nam, exflg, credp,
287 	    numsecflavors, secflavors);
288 	sigallowstop(prev_stops);
289 	return (rc);
290 }
291 
292 static int
293 vfs_extattrctl_sigdefer(struct mount *mp, int cmd, struct vnode *filename_vp,
294     int attrnamespace, const char *attrname)
295 {
296 	int prev_stops, rc;
297 
298 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
299 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_extattrctl)(mp, cmd,
300 	    filename_vp, attrnamespace, attrname);
301 	sigallowstop(prev_stops);
302 	return (rc);
303 }
304 
305 static int
306 vfs_sysctl_sigdefer(struct mount *mp, fsctlop_t op, struct sysctl_req *req)
307 {
308 	int prev_stops, rc;
309 
310 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
311 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_sysctl)(mp, op, req);
312 	sigallowstop(prev_stops);
313 	return (rc);
314 }
315 
316 static void
317 vfs_susp_clean_sigdefer(struct mount *mp)
318 {
319 	int prev_stops;
320 
321 	if (*mp->mnt_vfc->vfc_vfsops_sd->vfs_susp_clean == NULL)
322 		return;
323 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
324 	(*mp->mnt_vfc->vfc_vfsops_sd->vfs_susp_clean)(mp);
325 	sigallowstop(prev_stops);
326 }
327 
328 static void
329 vfs_reclaim_lowervp_sigdefer(struct mount *mp, struct vnode *vp)
330 {
331 	int prev_stops;
332 
333 	if (*mp->mnt_vfc->vfc_vfsops_sd->vfs_reclaim_lowervp == NULL)
334 		return;
335 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
336 	(*mp->mnt_vfc->vfc_vfsops_sd->vfs_reclaim_lowervp)(mp, vp);
337 	sigallowstop(prev_stops);
338 }
339 
340 static void
341 vfs_unlink_lowervp_sigdefer(struct mount *mp, struct vnode *vp)
342 {
343 	int prev_stops;
344 
345 	if (*mp->mnt_vfc->vfc_vfsops_sd->vfs_unlink_lowervp == NULL)
346 		return;
347 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
348 	(*(mp)->mnt_vfc->vfc_vfsops_sd->vfs_unlink_lowervp)(mp, vp);
349 	sigallowstop(prev_stops);
350 }
351 
352 static void
353 vfs_purge_sigdefer(struct mount *mp)
354 {
355 	int prev_stops;
356 
357 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
358 	(*mp->mnt_vfc->vfc_vfsops_sd->vfs_purge)(mp);
359 	sigallowstop(prev_stops);
360 }
361 
362 static int
363 vfs_report_lockf_sigdefer(struct mount *mp, struct sbuf *sb)
364 {
365 	int prev_stops, rc;
366 
367 	prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
368 	rc = (*mp->mnt_vfc->vfc_vfsops_sd->vfs_report_lockf)(mp, sb);
369 	sigallowstop(prev_stops);
370 	return (rc);
371 }
372 
373 static struct vfsops vfsops_sigdefer = {
374 	.vfs_mount =		vfs_mount_sigdefer,
375 	.vfs_unmount =		vfs_unmount_sigdefer,
376 	.vfs_root =		vfs_root_sigdefer,
377 	.vfs_cachedroot =	vfs_cachedroot_sigdefer,
378 	.vfs_quotactl =		vfs_quotactl_sigdefer,
379 	.vfs_statfs =		vfs_statfs_sigdefer,
380 	.vfs_sync =		vfs_sync_sigdefer,
381 	.vfs_vget =		vfs_vget_sigdefer,
382 	.vfs_fhtovp =		vfs_fhtovp_sigdefer,
383 	.vfs_checkexp =		vfs_checkexp_sigdefer,
384 	.vfs_extattrctl =	vfs_extattrctl_sigdefer,
385 	.vfs_sysctl =		vfs_sysctl_sigdefer,
386 	.vfs_susp_clean =	vfs_susp_clean_sigdefer,
387 	.vfs_reclaim_lowervp =	vfs_reclaim_lowervp_sigdefer,
388 	.vfs_unlink_lowervp =	vfs_unlink_lowervp_sigdefer,
389 	.vfs_purge =		vfs_purge_sigdefer,
390 	.vfs_report_lockf =	vfs_report_lockf_sigdefer,
391 };
392 
393 /* Register a new filesystem type in the global table */
394 static int
395 vfs_register(struct vfsconf *vfc)
396 {
397 	struct sysctl_oid *oidp;
398 	struct vfsops *vfsops;
399 	static int once;
400 	struct vfsconf *tvfc;
401 	uint32_t hashval;
402 	int error, prevmaxconf, secondpass;
403 
404 	if (!once) {
405 		vattr_null(&va_null);
406 		once = 1;
407 	}
408 
409 	if (vfc->vfc_version != VFS_VERSION) {
410 		printf("ERROR: filesystem %s, unsupported ABI version %x\n",
411 		    vfc->vfc_name, vfc->vfc_version);
412 		return (EINVAL);
413 	}
414 	vfsconf_lock();
415 	if (vfs_byname_locked(vfc->vfc_name) != NULL) {
416 		vfsconf_unlock();
417 		return (EEXIST);
418 	}
419 
420 	prevmaxconf = maxvfsconf;
421 	if (vfs_typenumhash != 0) {
422 		/*
423 		 * Calculate a hash on vfc_name to use for vfc_typenum. Unless
424 		 * all of 1<->255 are assigned, it is limited to 8bits since
425 		 * that is what ZFS uses from vfc_typenum and is also the
426 		 * preferred range for vfs_getnewfsid().
427 		 */
428 		hashval = fnv_32_str(vfc->vfc_name, FNV1_32_INIT);
429 		hashval &= 0xff;
430 		secondpass = 0;
431 		do {
432 			/* Look for and fix any collision. */
433 			TAILQ_FOREACH(tvfc, &vfsconf, vfc_list) {
434 				if (hashval == tvfc->vfc_typenum) {
435 					if (hashval == 255 && secondpass == 0) {
436 						hashval = 1;
437 						secondpass = 1;
438 					} else
439 						hashval++;
440 					break;
441 				}
442 			}
443 		} while (tvfc != NULL);
444 		vfc->vfc_typenum = hashval;
445 		if (vfc->vfc_typenum >= maxvfsconf)
446 			maxvfsconf = vfc->vfc_typenum + 1;
447 	} else
448 		vfc->vfc_typenum = maxvfsconf++;
449 	TAILQ_INSERT_TAIL(&vfsconf, vfc, vfc_list);
450 
451 	/*
452 	 * Initialise unused ``struct vfsops'' fields, to use
453 	 * the vfs_std*() functions.  Note, we need the mount
454 	 * and unmount operations, at the least.  The check
455 	 * for vfsops available is just a debugging aid.
456 	 */
457 	KASSERT(vfc->vfc_vfsops != NULL,
458 	    ("Filesystem %s has no vfsops", vfc->vfc_name));
459 	/*
460 	 * Check the mount and unmount operations.
461 	 */
462 	vfsops = vfc->vfc_vfsops;
463 	KASSERT(vfsops->vfs_mount != NULL,
464 	    ("Filesystem %s has no mount op", vfc->vfc_name));
465 	KASSERT(vfsops->vfs_unmount != NULL,
466 	    ("Filesystem %s has no unmount op", vfc->vfc_name));
467 
468 	if (vfsops->vfs_root == NULL)
469 		/* return file system's root vnode */
470 		vfsops->vfs_root =	vfs_stdroot;
471 	if (vfsops->vfs_quotactl == NULL)
472 		/* quota control */
473 		vfsops->vfs_quotactl =	vfs_stdquotactl;
474 	if (vfsops->vfs_statfs == NULL)
475 		/* return file system's status */
476 		vfsops->vfs_statfs =	vfs_stdstatfs;
477 	if (vfsops->vfs_sync == NULL)
478 		/*
479 		 * flush unwritten data (nosync)
480 		 * file systems can use vfs_stdsync
481 		 * explicitly by setting it in the
482 		 * vfsop vector.
483 		 */
484 		vfsops->vfs_sync =	vfs_stdnosync;
485 	if (vfsops->vfs_vget == NULL)
486 		/* convert an inode number to a vnode */
487 		vfsops->vfs_vget =	vfs_stdvget;
488 	if (vfsops->vfs_fhtovp == NULL)
489 		/* turn an NFS file handle into a vnode */
490 		vfsops->vfs_fhtovp =	vfs_stdfhtovp;
491 	if (vfsops->vfs_checkexp == NULL)
492 		/* check if file system is exported */
493 		vfsops->vfs_checkexp =	vfs_stdcheckexp;
494 	if (vfsops->vfs_init == NULL)
495 		/* file system specific initialisation */
496 		vfsops->vfs_init =	vfs_stdinit;
497 	if (vfsops->vfs_uninit == NULL)
498 		/* file system specific uninitialisation */
499 		vfsops->vfs_uninit =	vfs_stduninit;
500 	if (vfsops->vfs_extattrctl == NULL)
501 		/* extended attribute control */
502 		vfsops->vfs_extattrctl = vfs_stdextattrctl;
503 	if (vfsops->vfs_sysctl == NULL)
504 		vfsops->vfs_sysctl = vfs_stdsysctl;
505 	if (vfsops->vfs_report_lockf == NULL)
506 		vfsops->vfs_report_lockf = vfs_report_lockf;
507 
508 	if ((vfc->vfc_flags & VFCF_SBDRY) != 0) {
509 		vfc->vfc_vfsops_sd = vfc->vfc_vfsops;
510 		vfc->vfc_vfsops = &vfsops_sigdefer;
511 	}
512 
513 	/*
514 	 * Call init function for this VFS...
515 	 */
516 	if ((vfc->vfc_flags & VFCF_SBDRY) != 0)
517 		error = vfc->vfc_vfsops_sd->vfs_init(vfc);
518 	else
519 		error = vfc->vfc_vfsops->vfs_init(vfc);
520 
521 	if (error != 0) {
522 		maxvfsconf = prevmaxconf;
523 		TAILQ_REMOVE(&vfsconf, vfc, vfc_list);
524 		vfsconf_unlock();
525 		return (error);
526 	}
527 
528 	if ((vfc->vfc_flags & VFCF_JAIL) != 0)
529 		prison_add_vfs(vfc);
530 
531 	vfsconf_unlock();
532 
533 	/*
534 	 * If this filesystem has a sysctl node under vfs
535 	 * (i.e. vfs.xxfs), then change the oid number of that node to
536 	 * match the filesystem's type number.  This allows user code
537 	 * which uses the type number to read sysctl variables defined
538 	 * by the filesystem to continue working. Since the oids are
539 	 * in a sorted list, we need to make sure the order is
540 	 * preserved by re-registering the oid after modifying its
541 	 * number.
542 	 */
543 	sysctl_wlock();
544 	RB_FOREACH(oidp, sysctl_oid_list, SYSCTL_CHILDREN(&sysctl___vfs)) {
545 		if (strcmp(oidp->oid_name, vfc->vfc_name) == 0) {
546 			sysctl_unregister_oid(oidp);
547 			oidp->oid_number = vfc->vfc_typenum;
548 			sysctl_register_oid(oidp);
549 			break;
550 		}
551 	}
552 	sysctl_wunlock();
553 
554 	return (0);
555 }
556 
557 /* Remove registration of a filesystem type */
558 static int
559 vfs_unregister(struct vfsconf *vfc)
560 {
561 	struct vfsconf *vfsp;
562 	int error, maxtypenum;
563 
564 	vfsconf_lock();
565 	vfsp = vfs_byname_locked(vfc->vfc_name);
566 	if (vfsp == NULL) {
567 		vfsconf_unlock();
568 		return (EINVAL);
569 	}
570 	if (vfsp->vfc_refcount != 0) {
571 		vfsconf_unlock();
572 		return (EBUSY);
573 	}
574 	error = 0;
575 	if ((vfc->vfc_flags & VFCF_SBDRY) != 0) {
576 		if (vfc->vfc_vfsops_sd->vfs_uninit != NULL)
577 			error = vfc->vfc_vfsops_sd->vfs_uninit(vfsp);
578 	} else {
579 		if (vfc->vfc_vfsops->vfs_uninit != NULL)
580 			error = vfc->vfc_vfsops->vfs_uninit(vfsp);
581 	}
582 	if (error != 0) {
583 		vfsconf_unlock();
584 		return (error);
585 	}
586 	TAILQ_REMOVE(&vfsconf, vfsp, vfc_list);
587 	maxtypenum = VFS_GENERIC;
588 	TAILQ_FOREACH(vfsp, &vfsconf, vfc_list)
589 		if (maxtypenum < vfsp->vfc_typenum)
590 			maxtypenum = vfsp->vfc_typenum;
591 	maxvfsconf = maxtypenum + 1;
592 	vfsconf_unlock();
593 	return (0);
594 }
595 
596 /*
597  * Standard kernel module handling code for filesystem modules.
598  * Referenced from VFS_SET().
599  */
600 int
601 vfs_modevent(module_t mod, int type, void *data)
602 {
603 	struct vfsconf *vfc;
604 	int error = 0;
605 
606 	vfc = (struct vfsconf *)data;
607 
608 	switch (type) {
609 	case MOD_LOAD:
610 		if (vfc)
611 			error = vfs_register(vfc);
612 		break;
613 
614 	case MOD_UNLOAD:
615 		if (vfc)
616 			error = vfs_unregister(vfc);
617 		break;
618 	default:
619 		error = EOPNOTSUPP;
620 		break;
621 	}
622 	return (error);
623 }
624