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.
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.
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]
22 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Delphix (c) 2012 by Delphix. All rights reserved.
28 * Dump driver. Provides ioctls to get/set crash dump configuration.
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/vnode.h>
38 #include <sys/errno.h>
39 #include <sys/modctl.h>
40 #include <sys/dumphdr.h>
41 #include <sys/dumpadm.h>
42 #include <sys/pathname.h>
48 #include <sys/sunddi.h>
50 static dev_info_t
*dump_devi
;
53 dump_attach(dev_info_t
*devi
, ddi_attach_cmd_t cmd
)
55 if (cmd
!= DDI_ATTACH
)
57 if (ddi_create_minor_node(devi
, "dump", S_IFCHR
, 0, DDI_PSEUDO
, 0) ==
59 ddi_remove_minor_node(devi
, NULL
);
67 dump_detach(dev_info_t
*devi
, ddi_detach_cmd_t cmd
)
69 if (cmd
!= DDI_DETACH
)
71 ddi_remove_minor_node(devi
, NULL
);
77 dump_info(dev_info_t
*dip
, ddi_info_cmd_t infocmd
, void *arg
, void **result
)
80 case DDI_INFO_DEVT2DEVINFO
:
83 case DDI_INFO_DEVT2INSTANCE
:
92 dump_ioctl(dev_t dev
, int cmd
, intptr_t arg
, int mode
, cred_t
*cred
, int *rvalp
)
95 uint64_t dumpsize_in_pages
;
97 char *pathbuf
= kmem_zalloc(MAXPATHLEN
, KM_SLEEP
);
103 case DIOCGETDUMPSIZE
:
104 if (dump_conflags
& DUMP_ALL
)
105 size
= ptob((uint64_t)physmem
) / DUMP_COMPRESS_RATIO
;
108 * We can't give a good answer for the DUMP_CURPROC
109 * because we won't know which process to use until it
110 * causes a panic. We'll therefore punt and give the
111 * caller the size for the kernel.
113 * This kernel size equation takes care of the
114 * boot time kernel footprint and also accounts
115 * for availrmem changes due to user explicit locking.
116 * Refer to kernel/vm/vm_page.c for an explanation
119 dumpsize_in_pages
= (physinstalled
- obp_pages
-
121 anon_segkp_pages_locked
-
122 k_anoninfo
.ani_mem_resv
-
128 * Protect against vm vagaries.
130 if (dumpsize_in_pages
> (uint64_t)physmem
)
131 dumpsize_in_pages
= (uint64_t)physmem
;
133 size
= ptob(dumpsize_in_pages
) / DUMP_COMPRESS_RATIO
;
135 if (copyout(&size
, (void *)arg
, sizeof (size
)) < 0)
140 mutex_enter(&dump_lock
);
141 *rvalp
= dump_conflags
;
142 if (dumpvp
&& !(dumpvp
->v_flag
& VISSWAP
))
144 mutex_exit(&dump_lock
);
148 mutex_enter(&dump_lock
);
149 if (arg
== DUMP_KERNEL
|| arg
== DUMP_ALL
||
154 mutex_exit(&dump_lock
);
158 mutex_enter(&dump_lock
);
159 if (dumppath
== NULL
) {
160 mutex_exit(&dump_lock
);
164 (void) strcpy(pathbuf
, dumppath
);
165 mutex_exit(&dump_lock
);
166 error
= copyoutstr(pathbuf
, (void *)arg
, MAXPATHLEN
, NULL
);
171 if ((error
= copyinstr((char *)arg
, pathbuf
, MAXPATHLEN
,
172 NULL
)) != 0 || (error
= lookupname(pathbuf
, UIO_SYSSPACE
,
173 FOLLOW
, NULLVPP
, &vp
)) != 0)
175 mutex_enter(&dump_lock
);
176 if (vp
->v_type
== VBLK
)
177 error
= dumpinit(vp
, pathbuf
, cmd
== DIOCTRYDEV
);
180 mutex_exit(&dump_lock
);
185 mutex_enter(&dump_lock
);
188 else if (dumpvp
->v_flag
& VISSWAP
)
192 mutex_exit(&dump_lock
);
196 if ((error
= copyinstr((char *)arg
, uuidbuf
, sizeof (uuidbuf
),
205 error
= dump_set_uuid(uuidbuf
);
209 error
= copyoutstr(dump_get_uuid(), (void *)arg
, 37, NULL
);
213 mutex_enter(&dump_lock
);
216 mutex_exit(&dump_lock
);
223 kmem_free(pathbuf
, MAXPATHLEN
);
227 struct cb_ops dump_cb_ops
= {
230 nodev
, /* strategy */
235 dump_ioctl
, /* ioctl */
240 ddi_prop_op
, /* prop_op */
242 D_NEW
|D_MP
/* Driver compatibility flag */
245 struct dev_ops dump_ops
= {
246 DEVO_REV
, /* devo_rev, */
248 dump_info
, /* info */
249 nulldev
, /* identify */
251 dump_attach
, /* attach */
252 dump_detach
, /* detach */
254 &dump_cb_ops
, /* driver operations */
255 NULL
, /* bus operations */
257 ddi_quiesce_not_needed
, /* quiesce */
260 static struct modldrv modldrv
= {
261 &mod_driverops
, "crash dump driver", &dump_ops
,
264 static struct modlinkage modlinkage
= {
265 MODREV_1
, (void *)&modldrv
, NULL
271 return (mod_install(&modlinkage
));
277 return (mod_remove(&modlinkage
));
281 _info(struct modinfo
*modinfop
)
283 return (mod_info(&modlinkage
, modinfop
));