xref: /illumos-gate/usr/src/uts/common/fs/sockfs/sockvfsops.c (revision ea7b7d8ad0ddfa6a32fb675e11cc106f686a5bb5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2024 Oxide Computer Company
25  */
26 
27 #include <sys/types.h>
28 #include <sys/t_lock.h>
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/buf.h>
32 #include <sys/cmn_err.h>
33 #include <sys/debug.h>
34 #include <sys/errno.h>
35 #include <sys/vfs.h>
36 #include <sys/swap.h>
37 #include <sys/vnode.h>
38 #include <sys/cred.h>
39 #include <sys/thread.h>
40 #include <sys/zone.h>
41 
42 #include <fs/fs_subr.h>
43 
44 #include <sys/stream.h>
45 #include <sys/socket.h>
46 #include <sys/stropts.h>
47 #include <sys/socketvar.h>
48 
49 /*
50  * This is the loadable module wrapper.
51  */
52 #include <sys/modctl.h>
53 
54 static zone_key_t sockfs_zone_key;
55 
56 static vfsdef_t vfw = {
57 	VFSDEF_VERSION,
58 	"sockfs",
59 	sockinit,
60 	VSW_ZMOUNT,
61 	NULL
62 };
63 
64 /*
65  * Module linkage information for the kernel.
66  */
67 static struct modlfs modlfs = {
68 	&mod_fsops, "filesystem for sockfs", &vfw
69 };
70 
71 static struct modlinkage modlinkage = {
72 	MODREV_1, (void *)&modlfs, NULL
73 };
74 
75 int
_init(void)76 _init(void)
77 {
78 	int ret;
79 
80 	/*
81 	 * We want to be informed each time a zone is created or
82 	 * destroyed in the kernel, so we can maintain per-zone
83 	 * kstat. sock_kstat_init() will also be called for the
84 	 * global zone, without us having to special case it here.
85 	 */
86 	zone_key_create(&sockfs_zone_key,
87 	    sock_kstat_init, NULL, sock_kstat_fini);
88 
89 	if ((ret = mod_install(&modlinkage)) != 0) {
90 		(void) zone_key_delete(sockfs_zone_key);
91 	}
92 
93 	return (ret);
94 }
95 
96 int
_info(struct modinfo * modinfop)97 _info(struct modinfo *modinfop)
98 {
99 	return (mod_info(&modlinkage, modinfop));
100 }
101 
102 int
_fini(void)103 _fini(void)
104 {
105 	/* zone_key_delete(sockfs_zone_key); - if we were ever to be unloaded */
106 
107 	return (EBUSY);
108 }
109 
110 /*
111  * N.B.
112  * No _fini routine. This module cannot be unloaded once loaded.
113  * The NO_UNLOAD_STUB in modstub.s must change if this module ever
114  * is modified to become unloadable.
115  */
116 
117 /*
118  * In the past, there was no dedicated vfs_t for sockfs ala fifofs and instead
119  * every vnode actually had the root filesystem's vfs_t. While there really
120  * isn't anything that makes that much sense to put in here, we fill out a token
121  * statvfs here. We're not the only system that provides a token, not super
122  * useful vfs_t here.
123  */
124 int
sockfs_statvfs(vfs_t * vfsp,struct statvfs64 * stat)125 sockfs_statvfs(vfs_t *vfsp, struct statvfs64 *stat)
126 {
127 	dev32_t d32;
128 
129 	/*
130 	 * We explicitly don't set any kind of fundamental block size and leave
131 	 * this at zero.
132 	 *
133 	 * Similarly we don't even try to lie bout the number of blocks and
134 	 * files, especially as our kmem cache stats aren't zone aware.
135 	 */
136 	bzero(stat, sizeof (struct statvfs64));
137 	stat->f_bsize = PAGESIZE;
138 
139 	(void) cmpldev(&d32, vfsp->vfs_dev);
140 	stat->f_fsid = d32;
141 
142 	(void) strlcpy(stat->f_basetype, "sockfs", sizeof (stat->f_basetype));
143 
144 	return (0);
145 }
146