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