Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/proc/prvfsops.c
+++ new/usr/src/uts/common/fs/proc/prvfsops.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
26 26 /* All Rights Reserved */
27 27
28 28
29 29 #include <sys/types.h>
30 30 #include <sys/param.h>
31 31 #include <sys/cmn_err.h>
32 32 #include <sys/cred.h>
33 33 #include <sys/debug.h>
34 34 #include <sys/errno.h>
35 35 #include <sys/proc.h>
36 36 #include <sys/procfs.h>
37 37 #include <sys/stat.h>
38 38 #include <sys/statvfs.h>
39 39 #include <sys/sysmacros.h>
40 40 #include <sys/systm.h>
41 41 #include <sys/zone.h>
42 42 #include <sys/var.h>
43 43 #include <sys/vfs.h>
44 44 #include <sys/vfs_opreg.h>
45 45 #include <sys/vnode.h>
46 46 #include <sys/mode.h>
47 47 #include <sys/signal.h>
48 48 #include <sys/user.h>
49 49 #include <sys/mount.h>
50 50 #include <sys/bitmap.h>
51 51 #include <sys/kmem.h>
52 52 #include <sys/policy.h>
53 53 #include <fs/fs_subr.h>
54 54 #include <fs/proc/prdata.h>
55 55
56 56 /*
57 57 * This is the loadable module wrapper.
58 58 */
59 59 #include <sys/modctl.h>
60 60
61 61 static int prinit();
62 62
63 63 static mntopts_t proc_mntopts = {
64 64 NULL,
65 65 0
66 66 };
67 67
68 68 static vfsdef_t vfw = {
69 69 VFSDEF_VERSION,
70 70 "proc",
71 71 prinit,
72 72 VSW_HASPROTO|VSW_STATS|VSW_XID|VSW_ZMOUNT,
73 73 &proc_mntopts
74 74 };
75 75
↓ open down ↓ |
75 lines elided |
↑ open up ↑ |
76 76 /*
77 77 * Module linkage information for the kernel.
78 78 */
79 79 extern struct mod_ops mod_fsops;
80 80
81 81 static struct modlfs modlfs = {
82 82 &mod_fsops, "filesystem for proc", &vfw
83 83 };
84 84
85 85 static struct modlinkage modlinkage = {
86 - MODREV_1, (void *)&modlfs, NULL
86 + MODREV_1, { (void *)&modlfs, NULL }
87 87 };
88 88
89 89 int
90 90 _init(void)
91 91 {
92 92 return (mod_install(&modlinkage));
93 93 }
94 94
95 95 int
96 96 _info(struct modinfo *modinfop)
97 97 {
98 98 return (mod_info(&modlinkage, modinfop));
99 99 }
100 100
101 101 /*
102 102 * N.B.
103 103 * No _fini routine. The module cannot be unloaded once loaded.
104 104 * The NO_UNLOAD_STUB in modstubs.s must change if this module
105 105 * is ever modified to become unloadable.
106 106 */
107 107
108 108 int nproc_highbit; /* highbit(v.v_nproc) */
109 109
110 110 static int procfstype;
111 111 static major_t procfs_major;
112 112 static minor_t procfs_minor;
113 113 static kmutex_t procfs_minor_lock;
114 114
115 115 static kmutex_t pr_mount_lock;
116 116
117 117 /*
118 118 * /proc VFS operations vector.
119 119 */
120 120 static int prmount(), prunmount(), prroot(), prstatvfs();
121 121
122 122 static void
123 123 prinitrootnode(prnode_t *pnp, vfs_t *vfsp)
124 124 {
125 125 struct vnode *vp;
126 126
127 127 bzero((caddr_t)pnp, sizeof (*pnp));
128 128 pnp->pr_vnode = vp = vn_alloc(KM_SLEEP);
129 129
130 130 mutex_init(&pnp->pr_mutex, NULL, MUTEX_DEFAULT, NULL);
131 131 vp->v_flag = VROOT|VNOCACHE|VNOMAP|VNOSWAP|VNOMOUNT;
132 132 VN_SET_VFS_TYPE_DEV(vp, vfsp, VDIR, 0);
133 133 vn_setops(vp, prvnodeops);
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
134 134 vp->v_data = (caddr_t)pnp;
135 135 pnp->pr_type = PR_PROCDIR;
136 136 pnp->pr_mode = 0555; /* read-search by everyone */
137 137 vn_exists(vp);
138 138 }
139 139
140 140 static int
141 141 prinit(int fstype, char *name)
142 142 {
143 143 static const fs_operation_def_t pr_vfsops_template[] = {
144 - VFSNAME_MOUNT, { .vfs_mount = prmount },
145 - VFSNAME_UNMOUNT, { .vfs_unmount = prunmount },
146 - VFSNAME_ROOT, { .vfs_root = prroot },
147 - VFSNAME_STATVFS, { .vfs_statvfs = prstatvfs },
148 - NULL, NULL
144 + { VFSNAME_MOUNT, { .vfs_mount = prmount } },
145 + { VFSNAME_UNMOUNT, { .vfs_unmount = prunmount } },
146 + { VFSNAME_ROOT, { .vfs_root = prroot } },
147 + { VFSNAME_STATVFS, { .vfs_statvfs = prstatvfs } },
148 + { NULL, { NULL } }
149 149 };
150 150 extern const fs_operation_def_t pr_vnodeops_template[];
151 151 int error;
152 152
153 153 nproc_highbit = highbit(v.v_proc);
154 154 procfstype = fstype;
155 155 ASSERT(procfstype != 0);
156 156 /*
157 157 * Associate VFS ops vector with this fstype.
158 158 */
159 159 error = vfs_setfsops(fstype, pr_vfsops_template, NULL);
160 160 if (error != 0) {
161 161 cmn_err(CE_WARN, "prinit: bad vfs ops template");
162 162 return (error);
163 163 }
164 164
165 165 /*
166 166 * Set up vnode ops vector too.
167 167 */
168 168
169 169 error = vn_make_ops(name, pr_vnodeops_template, &prvnodeops);
170 170 if (error != 0) {
171 171 (void) vfs_freevfsops_by_type(fstype);
172 172 cmn_err(CE_WARN, "prinit: bad vnode ops template");
173 173 return (error);
174 174 }
175 175
176 176 /*
177 177 * Assign a unique "device" number (used by stat(2)).
178 178 */
179 179 if ((procfs_major = getudev()) == (major_t)-1) {
180 180 cmn_err(CE_WARN, "prinit: can't get unique device number");
181 181 procfs_major = 0;
182 182 }
183 183 mutex_init(&pr_mount_lock, NULL, MUTEX_DEFAULT, NULL);
184 184 mutex_init(&procfs_minor_lock, NULL, MUTEX_DEFAULT, NULL);
185 185
186 186 return (0);
187 187 }
188 188
189 189 /* ARGSUSED */
190 190 static int
191 191 prmount(struct vfs *vfsp, struct vnode *mvp,
192 192 struct mounta *uap, struct cred *cr)
193 193 {
194 194 prnode_t *pnp;
195 195 zone_t *zone = curproc->p_zone;
196 196
197 197 if (secpolicy_fs_mount(cr, mvp, vfsp) != 0)
198 198 return (EPERM);
199 199
200 200 if (mvp->v_type != VDIR)
201 201 return (ENOTDIR);
202 202
203 203 if (zone == global_zone) {
204 204 zone_t *mntzone;
205 205
206 206 mntzone = zone_find_by_path(refstr_value(vfsp->vfs_mntpt));
207 207 zone_rele(mntzone);
208 208 if (zone != mntzone)
209 209 return (EBUSY);
210 210 }
211 211 /*
212 212 * Having the resource be anything but "proc" doesn't make sense
213 213 */
214 214 vfs_setresource(vfsp, "proc", 0);
215 215
216 216 pnp = kmem_alloc(sizeof (*pnp), KM_SLEEP);
217 217 mutex_enter(&pr_mount_lock);
218 218
219 219 mutex_enter(&mvp->v_lock);
220 220 if ((uap->flags & MS_OVERLAY) == 0 &&
221 221 (mvp->v_count > 1 || (mvp->v_flag & VROOT))) {
222 222 mutex_exit(&mvp->v_lock);
223 223 mutex_exit(&pr_mount_lock);
224 224 kmem_free(pnp, sizeof (*pnp));
225 225 return (EBUSY);
226 226 }
227 227 mutex_exit(&mvp->v_lock);
228 228
229 229 prinitrootnode(pnp, vfsp);
230 230 vfsp->vfs_fstype = procfstype;
231 231 vfsp->vfs_data = (caddr_t)pnp;
232 232 vfsp->vfs_bsize = DEV_BSIZE;
233 233 /*
234 234 * find an available minor device number for this mount
235 235 */
236 236 mutex_enter(&procfs_minor_lock);
237 237 do {
238 238 vfsp->vfs_dev = makedevice(procfs_major, procfs_minor);
239 239 procfs_minor = (procfs_minor + 1) & L_MAXMIN32;
240 240 } while (vfs_devismounted(vfsp->vfs_dev));
241 241 mutex_exit(&procfs_minor_lock);
242 242 vfs_make_fsid(&vfsp->vfs_fsid, vfsp->vfs_dev, procfstype);
243 243
244 244 mutex_exit(&pr_mount_lock);
245 245 return (0);
246 246 }
247 247
248 248 /* ARGSUSED */
249 249 static int
250 250 prunmount(struct vfs *vfsp, int flag, struct cred *cr)
251 251 {
252 252 prnode_t *pnp = (prnode_t *)vfsp->vfs_data;
253 253 vnode_t *vp = PTOV(pnp);
254 254
255 255 mutex_enter(&pr_mount_lock);
256 256 if (secpolicy_fs_unmount(cr, vfsp) != 0) {
257 257 mutex_exit(&pr_mount_lock);
258 258 return (EPERM);
259 259 }
260 260
261 261 /*
262 262 * forced unmount is not supported by this file system
263 263 * and thus, ENOTSUP, is being returned.
264 264 */
265 265 if (flag & MS_FORCE) {
266 266 mutex_exit(&pr_mount_lock);
267 267 return (ENOTSUP);
268 268 }
269 269
270 270 /*
271 271 * Ensure that no /proc vnodes are in use on this mount point.
272 272 */
273 273 mutex_enter(&vp->v_lock);
274 274 if (vp->v_count > 1) {
275 275 mutex_exit(&vp->v_lock);
276 276 mutex_exit(&pr_mount_lock);
277 277 return (EBUSY);
278 278 }
279 279
280 280 mutex_exit(&vp->v_lock);
281 281 mutex_exit(&pr_mount_lock);
282 282 vn_invalid(vp);
283 283 vn_free(vp);
284 284 kmem_free(pnp, sizeof (*pnp));
285 285 return (0);
286 286 }
287 287
288 288 /* ARGSUSED */
289 289 static int
290 290 prroot(struct vfs *vfsp, struct vnode **vpp)
291 291 {
292 292 vnode_t *vp = PTOV((prnode_t *)vfsp->vfs_data);
293 293
294 294 VN_HOLD(vp);
295 295 *vpp = vp;
296 296 return (0);
297 297 }
298 298
299 299 static int
300 300 prstatvfs(struct vfs *vfsp, struct statvfs64 *sp)
301 301 {
302 302 int n;
303 303 dev32_t d32;
304 304 extern uint_t nproc;
305 305
306 306 n = v.v_proc - nproc;
307 307
308 308 bzero((caddr_t)sp, sizeof (*sp));
309 309 sp->f_bsize = DEV_BSIZE;
310 310 sp->f_frsize = DEV_BSIZE;
311 311 sp->f_blocks = (fsblkcnt64_t)0;
312 312 sp->f_bfree = (fsblkcnt64_t)0;
313 313 sp->f_bavail = (fsblkcnt64_t)0;
314 314 sp->f_files = (fsfilcnt64_t)v.v_proc + 2;
315 315 sp->f_ffree = (fsfilcnt64_t)n;
316 316 sp->f_favail = (fsfilcnt64_t)n;
317 317 (void) cmpldev(&d32, vfsp->vfs_dev);
318 318 sp->f_fsid = d32;
319 319 (void) strcpy(sp->f_basetype, vfssw[procfstype].vsw_name);
320 320 sp->f_flag = vf_to_stf(vfsp->vfs_flag);
321 321 sp->f_namemax = 64; /* quite arbitrary */
322 322 bzero(sp->f_fstr, sizeof (sp->f_fstr));
323 323 (void) strcpy(sp->f_fstr, "/proc");
324 324 (void) strcpy(&sp->f_fstr[6], "/proc");
325 325 return (0);
326 326 }
↓ open down ↓ |
168 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX