Index: sys/ddb/db_command.c =================================================================== --- sys/ddb/db_command.c +++ sys/ddb/db_command.c @@ -35,16 +35,17 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include +#include #include #include #include #include #include #include -#include #include #include Index: sys/dev/null/null.c =================================================================== --- sys/dev/null/null.c +++ sys/dev/null/null.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include Index: sys/geom/geom_dev.c =================================================================== --- sys/geom/geom_dev.c +++ sys/geom/geom_dev.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include Index: sys/geom/raid/g_raid.c =================================================================== --- sys/geom/raid/g_raid.c +++ sys/geom/raid/g_raid.c @@ -29,7 +29,9 @@ #include #include +#include #include +#include #include #include #include Index: sys/kern/kern_dump.c =================================================================== --- sys/kern/kern_dump.c +++ sys/kern/kern_dump.c @@ -27,18 +27,23 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_ddb.h" #include "opt_watchdog.h" #include #include #include #include +#include #include -#include #include +#include +#include +#include #ifdef SW_WATCHDOG #include #endif +#include #include #include #include @@ -58,13 +63,117 @@ #define MD_ALIGN(x) (((off_t)(x) + PAGE_MASK) & ~PAGE_MASK) #define DEV_ALIGN(x) (((off_t)(x) + (DEV_BSIZE-1)) & ~(DEV_BSIZE-1)) +struct dump_pa dump_map[DUMPSYS_MD_PA_NPAIRS]; off_t dumplo; +/* Our selected dumper. */ +static struct dumperinfo dumper; + +/* Context information for dump-debuggers. */ +static struct pcb dumppcb; /* Registers. */ +lwpid_t dumptid; /* Thread ID. */ + /* Handle buffered writes. */ static char buffer[DEV_BSIZE]; static size_t fragsz; -struct dump_pa dump_map[DUMPSYS_MD_PA_NPAIRS]; +char dumpdevname[sizeof(((struct cdev *)NULL)->si_name)]; +SYSCTL_DECL(_kern_shutdown); +SYSCTL_STRING(_kern_shutdown, OID_AUTO, dumpdevname, CTLFLAG_RD, dumpdevname, 0, + "Device for kernel dumps"); + +int +doadump(boolean_t textdump) +{ + boolean_t coredump; + int error; + + error = 0; + if (dumping) + return (EBUSY); + if (dumper.dumper == NULL) + return (ENXIO); + + savectx(&dumppcb); + dumptid = curthread->td_tid; + dumping++; + + coredump = TRUE; +#ifdef DDB + if (textdump && textdump_pending) { + coredump = FALSE; + textdump_dumpsys(&dumper); + } +#endif + if (coredump) + error = dumpsys(&dumper); + + dumping--; + return (error); +} + +/* Call dumper with bounds checking. */ +int +dump_write(struct dumperinfo *di, void *virtual, vm_offset_t physical, + off_t offset, size_t length) +{ + + if (length != 0 && (offset < di->mediaoffset || + offset - di->mediaoffset + length > di->mediasize)) { + printf("Attempt to write outside dump device boundaries.\n" + "offset(%jd), mediaoffset(%jd), length(%ju), mediasize(%jd).\n", + (intmax_t)offset, (intmax_t)di->mediaoffset, + (uintmax_t)length, (intmax_t)di->mediasize); + return (ENOSPC); + } + return (di->dumper(di->priv, virtual, physical, offset, length)); +} + +/* Register a dumper. */ +int +set_dumper(struct dumperinfo *di, const char *devname, struct thread *td) +{ + size_t wantcopy; + int error; + + error = priv_check(td, PRIV_SETDUMPER); + if (error != 0) + return (error); + + if (di == NULL) { + bzero(&dumper, sizeof dumper); + dumpdevname[0] = '\0'; + return (0); + } + if (dumper.dumper != NULL) + return (EBUSY); + dumper = *di; + wantcopy = strlcpy(dumpdevname, devname, sizeof(dumpdevname)); + if (wantcopy >= sizeof(dumpdevname)) + printf("set_dumper: device name truncated from '%s' -> '%s'\n", + devname, dumpdevname); + return (0); +} + +void +mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver, + uint64_t dumplen, uint32_t blksz) +{ + + bzero(kdh, sizeof(*kdh)); + strlcpy(kdh->magic, magic, sizeof(kdh->magic)); + strlcpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture)); + kdh->version = htod32(KERNELDUMPVERSION); + kdh->architectureversion = htod32(archver); + kdh->dumplength = htod64(dumplen); + kdh->dumptime = htod64(time_second); + kdh->blocksize = htod32(blksz); + strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname)); + strlcpy(kdh->versionstring, version, sizeof(kdh->versionstring)); + if (panicstr != NULL) + strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); + kdh->parity = kerneldump_parity(kdh); +} void dumpsys_gen_pa_init(void) Index: sys/kern/kern_shutdown.c =================================================================== --- sys/kern/kern_shutdown.c +++ sys/kern/kern_shutdown.c @@ -37,7 +37,6 @@ #include __FBSDID("$FreeBSD$"); -#include "opt_ddb.h" #include "opt_kdb.h" #include "opt_panic.h" #include "opt_sched.h" @@ -50,7 +49,6 @@ #include #include #include -#include #include #include #include @@ -70,10 +68,7 @@ #include #include -#include - #include -#include #include #include @@ -101,6 +96,9 @@ */ #include +SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0, + "Shutdown environment"); + #ifdef KDB #ifdef KDB_UNATTENDED int debugger_on_panic = 0; @@ -122,11 +120,8 @@ #endif /* KDB */ static int sync_on_panic = 0; -SYSCTL_INT(_kern, OID_AUTO, sync_on_panic, CTLFLAG_RWTUN, - &sync_on_panic, 0, "Do a sync before rebooting from a panic"); - -static SYSCTL_NODE(_kern, OID_AUTO, shutdown, CTLFLAG_RW, 0, - "Shutdown environment"); +SYSCTL_INT(_kern, OID_AUTO, sync_on_panic, CTLFLAG_RWTUN, &sync_on_panic, 0, + "Do a sync before rebooting from a panic"); #ifndef DIAGNOSTIC static int show_busybufs; @@ -144,11 +139,6 @@ int dumping; /* system is dumping */ int rebooting; /* system is rebooting */ -static struct dumperinfo dumper; /* our selected dumper */ - -/* Context information for dump-debuggers. */ -static struct pcb dumppcb; /* Registers. */ -lwpid_t dumptid; /* Thread ID. */ static void poweroff_wait(void *, int); static void shutdown_halt(void *junk, int howto); @@ -245,36 +235,6 @@ printf("%lds\n", (long)ts.tv_sec); } -int -doadump(boolean_t textdump) -{ - boolean_t coredump; - int error; - - error = 0; - if (dumping) - return (EBUSY); - if (dumper.dumper == NULL) - return (ENXIO); - - savectx(&dumppcb); - dumptid = curthread->td_tid; - dumping++; - - coredump = TRUE; -#ifdef DDB - if (textdump && textdump_pending) { - coredump = FALSE; - textdump_dumpsys(&dumper); - } -#endif - if (coredump) - error = dumpsys(&dumper); - - dumping--; - return (error); -} - static int isbufbusy(struct buf *bp) { @@ -818,71 +778,3 @@ else printf("done\n"); } - -static char dumpdevname[sizeof(((struct cdev*)NULL)->si_name)]; -SYSCTL_STRING(_kern_shutdown, OID_AUTO, dumpdevname, CTLFLAG_RD, - dumpdevname, 0, "Device for kernel dumps"); - -/* Registration of dumpers */ -int -set_dumper(struct dumperinfo *di, const char *devname, struct thread *td) -{ - size_t wantcopy; - int error; - - error = priv_check(td, PRIV_SETDUMPER); - if (error != 0) - return (error); - - if (di == NULL) { - bzero(&dumper, sizeof dumper); - dumpdevname[0] = '\0'; - return (0); - } - if (dumper.dumper != NULL) - return (EBUSY); - dumper = *di; - wantcopy = strlcpy(dumpdevname, devname, sizeof(dumpdevname)); - if (wantcopy >= sizeof(dumpdevname)) { - printf("set_dumper: device name truncated from '%s' -> '%s'\n", - devname, dumpdevname); - } - return (0); -} - -/* Call dumper with bounds checking. */ -int -dump_write(struct dumperinfo *di, void *virtual, vm_offset_t physical, - off_t offset, size_t length) -{ - - if (length != 0 && (offset < di->mediaoffset || - offset - di->mediaoffset + length > di->mediasize)) { - printf("Attempt to write outside dump device boundaries.\n" - "offset(%jd), mediaoffset(%jd), length(%ju), mediasize(%jd).\n", - (intmax_t)offset, (intmax_t)di->mediaoffset, - (uintmax_t)length, (intmax_t)di->mediasize); - return (ENOSPC); - } - return (di->dumper(di->priv, virtual, physical, offset, length)); -} - -void -mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver, - uint64_t dumplen, uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strlcpy(kdh->magic, magic, sizeof(kdh->magic)); - strlcpy(kdh->architecture, MACHINE_ARCH, sizeof(kdh->architecture)); - kdh->version = htod32(KERNELDUMPVERSION); - kdh->architectureversion = htod32(archver); - kdh->dumplength = htod64(dumplen); - kdh->dumptime = htod64(time_second); - kdh->blocksize = htod32(blksz); - strlcpy(kdh->hostname, prison0.pr_hostname, sizeof(kdh->hostname)); - strlcpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strlcpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} Index: sys/sys/conf.h =================================================================== --- sys/sys/conf.h +++ sys/sys/conf.h @@ -319,9 +319,6 @@ off_t mediasize; /* Space available in bytes. */ }; -int set_dumper(struct dumperinfo *, const char *_devname, struct thread *td); -int dump_write(struct dumperinfo *, void *, vm_offset_t, off_t, size_t); -int doadump(boolean_t); extern int dumping; /* system is dumping */ #endif /* _KERNEL */ Index: sys/sys/kerneldump.h =================================================================== --- sys/sys/kerneldump.h +++ sys/sys/kerneldump.h @@ -123,6 +123,10 @@ void dumpsys_gen_unmap_chunk(vm_paddr_t, size_t, void *); int dumpsys_gen_write_aux_headers(struct dumperinfo *); +int set_dumper(struct dumperinfo *, const char *, struct thread *); +int dump_write(struct dumperinfo *, void *, vm_offset_t, off_t, size_t); +int doadump(boolean_t); + extern int do_minidump; #endif