Date: Thu, 3 Jan 2008 22:25:17 GMT From: Peter Wemm <peter@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 132434 for review Message-ID: <200801032225.m03MPHAE060675@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=132434 Change 132434 by peter@peter_daintree on 2008/01/03 22:24:56 Export the build uuid to the dump header. Nothing interesting is done with it at this point. While here, move all the mkdumpheader() copies into a MI place, as the (duplicated) comment suggested. Allow magic numbers to be passed through so textdumps can share the code too. Affected files ... .. //depot/projects/hammer/sbin/savecore/savecore.c#17 edit .. //depot/projects/hammer/sys/amd64/amd64/dump_machdep.c#27 edit .. //depot/projects/hammer/sys/amd64/amd64/minidump_machdep.c#4 edit .. //depot/projects/hammer/sys/arm/arm/dump_machdep.c#3 edit .. //depot/projects/hammer/sys/ddb/db_textdump.c#2 edit .. //depot/projects/hammer/sys/i386/i386/dump_machdep.c#12 edit .. //depot/projects/hammer/sys/i386/i386/minidump_machdep.c#4 edit .. //depot/projects/hammer/sys/ia64/ia64/dump_machdep.c#9 edit .. //depot/projects/hammer/sys/kern/kern_shutdown.c#49 edit .. //depot/projects/hammer/sys/sparc64/sparc64/dump_machdep.c#9 edit .. //depot/projects/hammer/sys/sun4v/sun4v/dump_machdep.c#2 edit .. //depot/projects/hammer/sys/sys/kerneldump.h#9 edit Differences ... ==== //depot/projects/hammer/sbin/savecore/savecore.c#17 (text+ko) ==== @@ -84,6 +84,7 @@ #include <syslog.h> #include <time.h> #include <unistd.h> +#include <uuid.h> /* The size of the buffer used for I/O. */ #define BUFFERSIZE (1024*1024) @@ -104,6 +105,10 @@ uint64_t dumplen; time_t t; const char *stat_str; + const struct kerneldumpheader_v1 *h_v1 = (const struct kerneldumpheader_v1 *)h; + char *uuid_string; + uint32_t uuid_ret; + uuid_t u; fprintf(f, "Dump header from device %s\n", device); fprintf(f, " Architecture: %s\n", h->architecture); @@ -118,7 +123,18 @@ fprintf(f, " Hostname: %s\n", h->hostname); fprintf(f, " Magic: %s\n", h->magic); fprintf(f, " Version String: %s", h->versionstring); - fprintf(f, " Panic String: %s\n", h->panicstring); + if (dtoh32(h->version) == KERNELDUMPVERSION_V1) { + fprintf(f, " Panic String: %s\n", h_v1->panicstring); + } else { + fprintf(f, " Panic String: %s\n", h->panicstring); + uuid_string = NULL; + memcpy(&u, h->uuid, sizeof(u)); + uuid_to_string(&u, &uuid_string, &uuid_ret); + if (uuid_ret == uuid_s_ok) + fprintf(f, " Build uuid: %s\n", uuid_string); + if (uuid_string) + free(uuid_string); + } fprintf(f, " Dump Parity: %u\n", h->parity); fprintf(f, " Bounds: %d\n", bounds); @@ -435,7 +451,8 @@ } } else if (memcmp(kdhl.magic, KERNELDUMPMAGIC, sizeof kdhl.magic) == 0) { - if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { + if (dtoh32(kdhl.version) != KERNELDUMPVERSION && + dtoh32(kdhl.version) != KERNELDUMPVERSION_V1) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); @@ -463,7 +480,8 @@ syslog(LOG_ERR, "unable to force dump - bad magic"); goto closefd; } - if (dtoh32(kdhl.version) != KERNELDUMPVERSION) { + if (dtoh32(kdhl.version) != KERNELDUMPVERSION && + dtoh32(kdhl.version) != KERNELDUMPVERSION_V1) { syslog(LOG_ERR, "unknown version (%d) in last dump header on %s", dtoh32(kdhl.version), device); ==== //depot/projects/hammer/sys/amd64/amd64/dump_machdep.c#27 (text+ko) ==== @@ -104,27 +104,6 @@ return (mdp); } -/* XXX should be MI */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen, - uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - static int buf_write(struct dumperinfo *di, char *ptr, size_t sz) { @@ -321,7 +300,7 @@ dumplo = di->mediaoffset + di->mediasize - dumpsize; dumplo -= sizeof(kdh) * 2; - mkdumpheader(&kdh, KERNELDUMP_AMD64_VERSION, dumpsize, di->blocksize); + mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AMD64_VERSION, dumpsize, di->blocksize); printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20, ehdr.e_phnum); ==== //depot/projects/hammer/sys/amd64/amd64/minidump_machdep.c#4 (text) ==== @@ -81,27 +81,6 @@ return (0); } -/* XXX should be MI */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen, - uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - #define PG2MB(pgs) (((pgs) + (1 << 8) - 1) >> 8) static int @@ -280,7 +259,7 @@ mdhdr.dmapend = DMAP_MAX_ADDRESS; strncpy(mdhdr.build_uuid, build_uuid, sizeof(mdhdr.build_uuid) - 1); - mkdumpheader(&kdh, KERNELDUMP_AMD64_VERSION, dumpsize, di->blocksize); + mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_AMD64_VERSION, dumpsize, di->blocksize); printf("Physical memory: %ju MB\n", ptoa((uintmax_t)physmem) / 1048576); printf("Dumping %llu MB:", (long long)dumpsize >> 20); ==== //depot/projects/hammer/sys/arm/arm/dump_machdep.c#3 (text+ko) ==== @@ -102,27 +102,6 @@ return (mdp); } -/* XXX should be MI */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen, - uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - static int buf_write(struct dumperinfo *di, char *ptr, size_t sz) { @@ -324,7 +303,7 @@ dumplo = di->mediaoffset + di->mediasize - dumpsize; dumplo -= sizeof(kdh) * 2; - mkdumpheader(&kdh, KERNELDUMP_ARM_VERSION, dumpsize, di->blocksize); + mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_ARM_VERSION, dumpsize, di->blocksize); printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20, ehdr.e_phnum); ==== //depot/projects/hammer/sys/ddb/db_textdump.c#2 (text+ko) ==== @@ -177,30 +177,6 @@ static struct kerneldumpheader kdh; /* - * Text dumps are prefixed with a normal kernel dump header but with a - * different magic number to allow them to be uniquely identified. - */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, - uint64_t dumplen, uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, TEXTDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - -/* * Calculate and fill in the checksum for a tar header. */ static void @@ -465,7 +441,7 @@ */ textdump_offset = di->mediasize - sizeof(kdh); textdump_saveoff(&trailer_offset); - mkdumpheader(&kdh, KERNELDUMP_TEXT_VERSION, 0, TEXTDUMP_BLOCKSIZE); + mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, 0, TEXTDUMP_BLOCKSIZE); (void)textdump_writenextblock(di, (char *)&kdh); /* @@ -490,7 +466,7 @@ * size. */ dumplen = trailer_offset - (textdump_offset + TEXTDUMP_BLOCKSIZE); - mkdumpheader(&kdh, KERNELDUMP_TEXT_VERSION, dumplen, + mkdumpheader(&kdh, TEXTDUMPMAGIC, KERNELDUMP_TEXT_VERSION, dumplen, TEXTDUMP_BLOCKSIZE); (void)textdump_writenextblock(di, (char *)&kdh); textdump_restoreoff(trailer_offset); ==== //depot/projects/hammer/sys/i386/i386/dump_machdep.c#12 (text+ko) ==== @@ -104,27 +104,6 @@ return (mdp); } -/* XXX should be MI */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen, - uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - static int buf_write(struct dumperinfo *di, char *ptr, size_t sz) { @@ -321,7 +300,7 @@ dumplo = di->mediaoffset + di->mediasize - dumpsize; dumplo -= sizeof(kdh) * 2; - mkdumpheader(&kdh, KERNELDUMP_I386_VERSION, dumpsize, di->blocksize); + mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, dumpsize, di->blocksize); printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20, ehdr.e_phnum); ==== //depot/projects/hammer/sys/i386/i386/minidump_machdep.c#4 (text) ==== @@ -78,27 +78,6 @@ return (0); } -/* XXX should be MI */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen, - uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - #define PG2MB(pgs) (((pgs) + (1 << 8) - 1) >> 8) static int @@ -275,7 +254,7 @@ mdhdr.paemode = 1; #endif - mkdumpheader(&kdh, KERNELDUMP_I386_VERSION, dumpsize, di->blocksize); + mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_I386_VERSION, dumpsize, di->blocksize); printf("Physical memory: %ju MB\n", ptoa((uintmax_t)physmem) / 1048576); printf("Dumping %llu MB:", (long long)dumpsize >> 20); ==== //depot/projects/hammer/sys/ia64/ia64/dump_machdep.c#9 (text+ko) ==== @@ -59,27 +59,6 @@ static char buffer[DEV_BSIZE]; static size_t fragsz; -/* XXX should be MI */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen, - uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - static int buf_write(struct dumperinfo *di, char *ptr, size_t sz) { @@ -260,7 +239,7 @@ dumplo = di->mediaoffset + di->mediasize - dumpsize; dumplo -= sizeof(kdh) * 2; - mkdumpheader(&kdh, KERNELDUMP_IA64_VERSION, dumpsize, di->blocksize); + mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_IA64_VERSION, dumpsize, di->blocksize); printf("Dumping %llu MB (%d chunks)\n", (long long)dumpsize >> 20, ehdr.e_phnum); ==== //depot/projects/hammer/sys/kern/kern_shutdown.c#49 (text+ko) ==== @@ -53,6 +53,7 @@ #include <sys/eventhandler.h> #include <sys/kdb.h> #include <sys/kernel.h> +#include <sys/kerneldump.h> #include <sys/kthread.h> #include <sys/malloc.h> #include <sys/mount.h> @@ -64,6 +65,7 @@ #include <sys/smp.h> /* smp_active */ #include <sys/sysctl.h> #include <sys/sysproto.h> +#include <sys/uuid.h> #include <ddb/ddb.h> @@ -388,7 +390,7 @@ * unmount filesystems (thus forcing an fsck on reboot). */ printf("Giving up on %d buffers\n", nbusy); -#ifdef DDB +#ifdef DDB_x Debugger("busy buffers"); #endif DELAY(5000000); /* 5 seconds */ @@ -677,3 +679,26 @@ printf("Kernel dumps not implemented on this architecture\n"); } #endif + +void +mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver, + uint64_t dumplen, uint32_t blksz) +{ + struct uuid u; + + parse_uuid(build_uuid, &u); + bzero(kdh, sizeof(*kdh)); + strncpy(kdh->magic, magic, sizeof(kdh->magic)); + strncpy(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); + strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); + strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); + if (panicstr != NULL) + strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); + bcopy(&u, kdh->uuid, sizeof(kdh->uuid)); + kdh->parity = kerneldump_parity(kdh); +} ==== //depot/projects/hammer/sys/sparc64/sparc64/dump_machdep.c#9 (text+ko) ==== @@ -55,27 +55,6 @@ #define MAXDUMPSZ (MAXDUMPPGS << PAGE_SHIFT) -/* XXX should be MI */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen, - uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - static int buf_write(struct dumperinfo *di, char *ptr, size_t sz) { @@ -190,7 +169,7 @@ /* Determine dump offset on device. */ dumplo = di->mediaoffset + di->mediasize - totsize; - mkdumpheader(&kdh, KERNELDUMP_SPARC64_VERSION, size, di->blocksize); + mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size, di->blocksize); printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg); ==== //depot/projects/hammer/sys/sun4v/sun4v/dump_machdep.c#2 (text+ko) ==== @@ -56,27 +56,6 @@ #define MAXDUMPSZ (MAXDUMPPGS << PAGE_SHIFT) -/* XXX should be MI */ -static void -mkdumpheader(struct kerneldumpheader *kdh, uint32_t archver, uint64_t dumplen, - uint32_t blksz) -{ - - bzero(kdh, sizeof(*kdh)); - strncpy(kdh->magic, KERNELDUMPMAGIC, sizeof(kdh->magic)); - strncpy(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); - strncpy(kdh->hostname, hostname, sizeof(kdh->hostname)); - strncpy(kdh->versionstring, version, sizeof(kdh->versionstring)); - if (panicstr != NULL) - strncpy(kdh->panicstring, panicstr, sizeof(kdh->panicstring)); - kdh->parity = kerneldump_parity(kdh); -} - static int buf_write(struct dumperinfo *di, char *ptr, size_t sz) { @@ -193,7 +172,7 @@ /* Determine dump offset on device. */ dumplo = di->mediaoffset + di->mediasize - totsize; - mkdumpheader(&kdh, KERNELDUMP_SPARC64_VERSION, size, di->blocksize); + mkdumpheader(&kdh, KERNELDUMPMAGIC, KERNELDUMP_SPARC64_VERSION, size, di->blocksize); printf("Dumping %lu MB (%d chunks)\n", (u_long)(size >> 20), nreg); ==== //depot/projects/hammer/sys/sys/kerneldump.h#9 (text+ko) ==== @@ -64,7 +64,7 @@ #define KERNELDUMPMAGIC_CLEARED "Cleared Kernel Dump" char architecture[12]; uint32_t version; -#define KERNELDUMPVERSION 1 +#define KERNELDUMPVERSION 2 uint32_t architectureversion; #define KERNELDUMP_ALPHA_VERSION 1 #define KERNELDUMP_I386_VERSION 2 @@ -78,6 +78,22 @@ uint32_t blocksize; char hostname[64]; char versionstring[192]; + char panicstring[176]; + u_char uuid[16]; + uint32_t parity; +}; + +struct kerneldumpheader_v1 { + char magic[20]; + char architecture[12]; +#define KERNELDUMPVERSION_V1 1 + uint32_t version; + uint32_t architectureversion; + uint64_t dumplength; /* excl headers */ + uint64_t dumptime; + uint32_t blocksize; + char hostname[64]; + char versionstring[192]; char panicstring[192]; uint32_t parity; }; @@ -98,4 +114,9 @@ return (parity); } +#ifdef _KERNEL +void mkdumpheader(struct kerneldumpheader *kdh, char *magic, uint32_t archver, + uint64_t dumplen, uint32_t blksz); +#endif + #endif /* _SYS_KERNELDUMP_H */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801032225.m03MPHAE060675>