Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/dump.c
+++ new/usr/src/uts/common/io/dump.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) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Delphix (c) 2012 by Delphix. All rights reserved.
24 24 */
25 25
26 26
27 27 /*
28 28 * Dump driver. Provides ioctls to get/set crash dump configuration.
29 29 */
30 30
31 31 #include <sys/types.h>
32 32 #include <sys/param.h>
33 33 #include <sys/systm.h>
34 34 #include <sys/vnode.h>
35 35 #include <sys/uio.h>
36 36 #include <sys/cred.h>
37 37 #include <sys/kmem.h>
38 38 #include <sys/errno.h>
39 39 #include <sys/modctl.h>
40 40 #include <sys/dumphdr.h>
41 41 #include <sys/dumpadm.h>
42 42 #include <sys/pathname.h>
43 43 #include <sys/file.h>
44 44 #include <vm/anon.h>
45 45 #include <sys/stat.h>
46 46 #include <sys/conf.h>
47 47 #include <sys/ddi.h>
48 48 #include <sys/sunddi.h>
49 49
50 50 static dev_info_t *dump_devi;
51 51
52 52 static int
53 53 dump_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
54 54 {
55 55 if (cmd != DDI_ATTACH)
56 56 return (DDI_FAILURE);
57 57 if (ddi_create_minor_node(devi, "dump", S_IFCHR, 0, DDI_PSEUDO, NULL) ==
58 58 DDI_FAILURE) {
59 59 ddi_remove_minor_node(devi, NULL);
60 60 return (DDI_FAILURE);
61 61 }
62 62 dump_devi = devi;
63 63 return (DDI_SUCCESS);
64 64 }
65 65
66 66 static int
67 67 dump_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
68 68 {
69 69 if (cmd != DDI_DETACH)
70 70 return (DDI_FAILURE);
71 71 ddi_remove_minor_node(devi, NULL);
72 72 return (DDI_SUCCESS);
73 73 }
74 74
75 75 /*ARGSUSED*/
76 76 static int
77 77 dump_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
78 78 {
79 79 switch (infocmd) {
80 80 case DDI_INFO_DEVT2DEVINFO:
81 81 *result = dump_devi;
82 82 return (DDI_SUCCESS);
83 83 case DDI_INFO_DEVT2INSTANCE:
84 84 *result = 0;
85 85 return (DDI_SUCCESS);
86 86 }
87 87 return (DDI_FAILURE);
88 88 }
89 89
90 90 /*ARGSUSED*/
91 91 int
92 92 dump_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cred, int *rvalp)
93 93 {
94 94 uint64_t size;
95 95 uint64_t dumpsize_in_pages;
96 96 int error = 0;
97 97 char *pathbuf = kmem_zalloc(MAXPATHLEN, KM_SLEEP);
98 98 char uuidbuf[36 + 1];
99 99 size_t len;
100 100 vnode_t *vp;
101 101
102 102 switch (cmd) {
103 103 case DIOCGETDUMPSIZE:
104 104 if (dump_conflags & DUMP_ALL)
105 105 size = ptob((uint64_t)physmem) / DUMP_COMPRESS_RATIO;
106 106 else {
107 107 /*
108 108 * We can't give a good answer for the DUMP_CURPROC
109 109 * because we won't know which process to use until it
110 110 * causes a panic. We'll therefore punt and give the
111 111 * caller the size for the kernel.
112 112 *
113 113 * This kernel size equation takes care of the
114 114 * boot time kernel footprint and also accounts
115 115 * for availrmem changes due to user explicit locking.
116 116 * Refer to common/vm/vm_page.c for an explanation
117 117 * of these counters.
118 118 */
119 119 dumpsize_in_pages = (physinstalled - obp_pages -
120 120 availrmem -
121 121 anon_segkp_pages_locked -
122 122 k_anoninfo.ani_mem_resv -
123 123 pages_locked -
124 124 pages_claimed -
125 125 pages_useclaim);
126 126
127 127 /*
128 128 * Protect against vm vagaries.
129 129 */
130 130 if (dumpsize_in_pages > (uint64_t)physmem)
131 131 dumpsize_in_pages = (uint64_t)physmem;
132 132
133 133 size = ptob(dumpsize_in_pages) / DUMP_COMPRESS_RATIO;
134 134 }
135 135 if (copyout(&size, (void *)arg, sizeof (size)) < 0)
136 136 error = EFAULT;
137 137 break;
138 138
139 139 case DIOCGETCONF:
140 140 mutex_enter(&dump_lock);
141 141 *rvalp = dump_conflags;
142 142 if (dumpvp && !(dumpvp->v_flag & VISSWAP))
143 143 *rvalp |= DUMP_EXCL;
144 144 mutex_exit(&dump_lock);
145 145 break;
146 146
147 147 case DIOCSETCONF:
148 148 mutex_enter(&dump_lock);
149 149 if (arg == DUMP_KERNEL || arg == DUMP_ALL ||
150 150 arg == DUMP_CURPROC)
151 151 dump_conflags = arg;
152 152 else
153 153 error = EINVAL;
154 154 mutex_exit(&dump_lock);
155 155 break;
156 156
157 157 case DIOCGETDEV:
158 158 mutex_enter(&dump_lock);
159 159 if (dumppath == NULL) {
160 160 mutex_exit(&dump_lock);
161 161 error = ENODEV;
162 162 break;
163 163 }
164 164 (void) strcpy(pathbuf, dumppath);
165 165 mutex_exit(&dump_lock);
166 166 error = copyoutstr(pathbuf, (void *)arg, MAXPATHLEN, NULL);
167 167 break;
168 168
169 169 case DIOCSETDEV:
170 170 case DIOCTRYDEV:
171 171 if ((error = copyinstr((char *)arg, pathbuf, MAXPATHLEN,
172 172 NULL)) != 0 || (error = lookupname(pathbuf, UIO_SYSSPACE,
173 173 FOLLOW, NULLVPP, &vp)) != 0)
174 174 break;
175 175 mutex_enter(&dump_lock);
176 176 if (vp->v_type == VBLK)
177 177 error = dumpinit(vp, pathbuf, cmd == DIOCTRYDEV);
178 178 else
179 179 error = ENOTBLK;
180 180 mutex_exit(&dump_lock);
181 181 VN_RELE(vp);
182 182 break;
183 183
184 184 case DIOCDUMP:
185 185 mutex_enter(&dump_lock);
186 186 if (dumpvp == NULL)
187 187 error = ENODEV;
188 188 else if (dumpvp->v_flag & VISSWAP)
189 189 error = EBUSY;
190 190 else
191 191 dumpsys();
192 192 mutex_exit(&dump_lock);
193 193 break;
194 194
195 195 case DIOCSETUUID:
196 196 if ((error = copyinstr((char *)arg, uuidbuf, sizeof (uuidbuf),
197 197 &len)) != 0)
198 198 break;
199 199
200 200 if (len != 37) {
201 201 error = EINVAL;
202 202 break;
203 203 }
204 204
205 205 error = dump_set_uuid(uuidbuf);
206 206 break;
207 207
208 208 case DIOCGETUUID:
209 209 error = copyoutstr(dump_get_uuid(), (void *)arg, 37, NULL);
210 210 break;
211 211
212 212 case DIOCRMDEV:
213 213 mutex_enter(&dump_lock);
214 214 if (dumpvp != NULL)
215 215 dumpfini();
216 216 mutex_exit(&dump_lock);
217 217 break;
218 218
219 219 default:
220 220 error = ENXIO;
221 221 }
222 222
223 223 kmem_free(pathbuf, MAXPATHLEN);
224 224 return (error);
225 225 }
226 226
227 227 struct cb_ops dump_cb_ops = {
228 228 nulldev, /* open */
229 229 nulldev, /* close */
230 230 nodev, /* strategy */
231 231 nodev, /* print */
232 232 nodev, /* dump */
233 233 nodev, /* read */
234 234 nodev, /* write */
235 235 dump_ioctl, /* ioctl */
236 236 nodev, /* devmap */
237 237 nodev, /* mmap */
238 238 nodev, /* segmap */
239 239 nochpoll, /* poll */
240 240 ddi_prop_op, /* prop_op */
241 241 0, /* streamtab */
242 242 D_NEW|D_MP /* Driver compatibility flag */
243 243 };
244 244
245 245 struct dev_ops dump_ops = {
246 246 DEVO_REV, /* devo_rev, */
247 247 0, /* refcnt */
248 248 dump_info, /* info */
249 249 nulldev, /* identify */
250 250 nulldev, /* probe */
251 251 dump_attach, /* attach */
252 252 dump_detach, /* detach */
253 253 nodev, /* reset */
254 254 &dump_cb_ops, /* driver operations */
↓ open down ↓ |
254 lines elided |
↑ open up ↑ |
255 255 (struct bus_ops *)0, /* bus operations */
256 256 NULL, /* power */
257 257 ddi_quiesce_not_needed, /* quiesce */
258 258 };
259 259
260 260 static struct modldrv modldrv = {
261 261 &mod_driverops, "crash dump driver", &dump_ops,
262 262 };
263 263
264 264 static struct modlinkage modlinkage = {
265 - MODREV_1, (void *)&modldrv, NULL
265 + MODREV_1, { (void *)&modldrv, NULL }
266 266 };
267 267
268 268 int
269 269 _init(void)
270 270 {
271 271 return (mod_install(&modlinkage));
272 272 }
273 273
274 274 int
275 275 _fini(void)
276 276 {
277 277 return (mod_remove(&modlinkage));
278 278 }
279 279
280 280 int
281 281 _info(struct modinfo *modinfop)
282 282 {
283 283 return (mod_info(&modlinkage, modinfop));
284 284 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX