diff options
| author | Kay Sievers <kay@vrfy.org> | 2012-06-15 08:07:51 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-06-15 17:53:59 -0400 |
| commit | e2ae715d66bf4becfb85eb84b7150e23cf27df30 (patch) | |
| tree | 206f08bc1f5138d1416c040f78c5b527ca07536d | |
| parent | 1bd289d1e8e29c09be0e783a53f16a1dc80684be (diff) | |
kmsg - kmsg_dump() use iterator to receive log buffer content
Provide an iterator to receive the log buffer content, and convert all
kmsg_dump() users to it.
The structured data in the kmsg buffer now contains binary data, which
should no longer be copied verbatim to the kmsg_dump() users.
The iterator should provide reliable access to the buffer data, and also
supports proper log line-aware chunking of data while iterating.
Signed-off-by: Kay Sievers <kay@vrfy.org>
Tested-by: Tony Luck <tony.luck@intel.com>
Reported-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Tested-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | arch/powerpc/platforms/pseries/nvram.c | 61 | ||||
| -rw-r--r-- | arch/x86/platform/mrst/early_printk_mrst.c | 13 | ||||
| -rw-r--r-- | drivers/mtd/mtdoops.c | 22 | ||||
| -rw-r--r-- | fs/pstore/platform.c | 34 | ||||
| -rw-r--r-- | include/linux/kmsg_dump.h | 45 | ||||
| -rw-r--r-- | kernel/printk.c | 220 |
6 files changed, 258 insertions, 137 deletions
diff --git a/arch/powerpc/platforms/pseries/nvram.c b/arch/powerpc/platforms/pseries/nvram.c index 36f957f31842..8733a86ad52e 100644 --- a/arch/powerpc/platforms/pseries/nvram.c +++ b/arch/powerpc/platforms/pseries/nvram.c | |||
| @@ -68,9 +68,7 @@ static const char *pseries_nvram_os_partitions[] = { | |||
| 68 | }; | 68 | }; |
| 69 | 69 | ||
| 70 | static void oops_to_nvram(struct kmsg_dumper *dumper, | 70 | static void oops_to_nvram(struct kmsg_dumper *dumper, |
| 71 | enum kmsg_dump_reason reason, | 71 | enum kmsg_dump_reason reason); |
| 72 | const char *old_msgs, unsigned long old_len, | ||
| 73 | const char *new_msgs, unsigned long new_len); | ||
| 74 | 72 | ||
| 75 | static struct kmsg_dumper nvram_kmsg_dumper = { | 73 | static struct kmsg_dumper nvram_kmsg_dumper = { |
| 76 | .dump = oops_to_nvram | 74 | .dump = oops_to_nvram |
| @@ -504,28 +502,6 @@ int __init pSeries_nvram_init(void) | |||
| 504 | } | 502 | } |
| 505 | 503 | ||
| 506 | /* | 504 | /* |
| 507 | * Try to capture the last capture_len bytes of the printk buffer. Return | ||
| 508 | * the amount actually captured. | ||
| 509 | */ | ||
| 510 | static size_t capture_last_msgs(const char *old_msgs, size_t old_len, | ||
| 511 | const char *new_msgs, size_t new_len, | ||
| 512 | char *captured, size_t capture_len) | ||
| 513 | { | ||
| 514 | if (new_len >= capture_len) { | ||
| 515 | memcpy(captured, new_msgs + (new_len - capture_len), | ||
| 516 | capture_len); | ||
| 517 | return capture_len; | ||
| 518 | } else { | ||
| 519 | /* Grab the end of old_msgs. */ | ||
| 520 | size_t old_tail_len = min(old_len, capture_len - new_len); | ||
| 521 | memcpy(captured, old_msgs + (old_len - old_tail_len), | ||
| 522 | old_tail_len); | ||
| 523 | memcpy(captured + old_tail_len, new_msgs, new_len); | ||
| 524 | return old_tail_len + new_len; | ||
| 525 | } | ||
| 526 | } | ||
| 527 | |||
| 528 | /* | ||
| 529 | * Are we using the ibm,rtas-log for oops/panic reports? And if so, | 505 | * Are we using the ibm,rtas-log for oops/panic reports? And if so, |
| 530 | * would logging this oops/panic overwrite an RTAS event that rtas_errd | 506 | * would logging this oops/panic overwrite an RTAS event that rtas_errd |
| 531 | * hasn't had a chance to read and process? Return 1 if so, else 0. | 507 | * hasn't had a chance to read and process? Return 1 if so, else 0. |
| @@ -541,27 +517,6 @@ static int clobbering_unread_rtas_event(void) | |||
| 541 | NVRAM_RTAS_READ_TIMEOUT); | 517 | NVRAM_RTAS_READ_TIMEOUT); |
| 542 | } | 518 | } |
| 543 | 519 | ||
| 544 | /* Squeeze out each line's <n> severity prefix. */ | ||
| 545 | static size_t elide_severities(char *buf, size_t len) | ||
| 546 | { | ||
| 547 | char *in, *out, *buf_end = buf + len; | ||
| 548 | /* Assume a <n> at the very beginning marks the start of a line. */ | ||
| 549 | int newline = 1; | ||
| 550 | |||
| 551 | in = out = buf; | ||
| 552 | while (in < buf_end) { | ||
| 553 | if (newline && in+3 <= buf_end && | ||
| 554 | *in == '<' && isdigit(in[1]) && in[2] == '>') { | ||
| 555 | in += 3; | ||
| 556 | newline = 0; | ||
| 557 | } else { | ||
| 558 | newline = (*in == '\n'); | ||
| 559 | *out++ = *in++; | ||
| 560 | } | ||
| 561 | } | ||
| 562 | return out - buf; | ||
| 563 | } | ||
| 564 | |||
| 565 | /* Derived from logfs_compress() */ | 520 | /* Derived from logfs_compress() */ |
| 566 | static int nvram_compress(const void *in, void *out, size_t inlen, | 521 | static int nvram_compress(const void *in, void *out, size_t inlen, |
| 567 | size_t outlen) | 522 | size_t outlen) |
| @@ -619,9 +574,7 @@ static int zip_oops(size_t text_len) | |||
| 619 | * partition. If that's too much, go back and capture uncompressed text. | 574 | * partition. If that's too much, go back and capture uncompressed text. |
| 620 | */ | 575 | */ |
| 621 | static void oops_to_nvram(struct kmsg_dumper *dumper, | 576 | static void oops_to_nvram(struct kmsg_dumper *dumper, |
| 622 | enum kmsg_dump_reason reason, | 577 | enum kmsg_dump_reason reason) |
| 623 | const char *old_msgs, unsigned long old_len, | ||
| 624 | const char *new_msgs, unsigned long new_len) | ||
| 625 | { | 578 | { |
| 626 | static unsigned int oops_count = 0; | 579 | static unsigned int oops_count = 0; |
| 627 | static bool panicking = false; | 580 | static bool panicking = false; |
| @@ -660,14 +613,14 @@ static void oops_to_nvram(struct kmsg_dumper *dumper, | |||
| 660 | return; | 613 | return; |
| 661 | 614 | ||
| 662 | if (big_oops_buf) { | 615 | if (big_oops_buf) { |
| 663 | text_len = capture_last_msgs(old_msgs, old_len, | 616 | kmsg_dump_get_buffer(dumper, false, |
| 664 | new_msgs, new_len, big_oops_buf, big_oops_buf_sz); | 617 | big_oops_buf, big_oops_buf_sz, &text_len); |
| 665 | text_len = elide_severities(big_oops_buf, text_len); | ||
| 666 | rc = zip_oops(text_len); | 618 | rc = zip_oops(text_len); |
| 667 | } | 619 | } |
| 668 | if (rc != 0) { | 620 | if (rc != 0) { |
| 669 | text_len = capture_last_msgs(old_msgs, old_len, | 621 | kmsg_dump_rewind(dumper); |
| 670 | new_msgs, new_len, oops_data, oops_data_sz); | 622 | kmsg_dump_get_buffer(dumper, true, |
| 623 | oops_data, oops_data_sz, &text_len); | ||
| 671 | err_type = ERR_TYPE_KERNEL_PANIC; | 624 | err_type = ERR_TYPE_KERNEL_PANIC; |
| 672 | *oops_len = (u16) text_len; | 625 | *oops_len = (u16) text_len; |
| 673 | } | 626 | } |
diff --git a/arch/x86/platform/mrst/early_printk_mrst.c b/arch/x86/platform/mrst/early_printk_mrst.c index 3c6e328483c7..028454f0c3a5 100644 --- a/arch/x86/platform/mrst/early_printk_mrst.c +++ b/arch/x86/platform/mrst/early_printk_mrst.c | |||
| @@ -110,19 +110,16 @@ static struct kmsg_dumper dw_dumper; | |||
| 110 | static int dumper_registered; | 110 | static int dumper_registered; |
| 111 | 111 | ||
| 112 | static void dw_kmsg_dump(struct kmsg_dumper *dumper, | 112 | static void dw_kmsg_dump(struct kmsg_dumper *dumper, |
| 113 | enum kmsg_dump_reason reason, | 113 | enum kmsg_dump_reason reason) |
| 114 | const char *s1, unsigned long l1, | ||
| 115 | const char *s2, unsigned long l2) | ||
| 116 | { | 114 | { |
| 117 | int i; | 115 | static char line[1024]; |
| 116 | size_t len; | ||
| 118 | 117 | ||
| 119 | /* When run to this, we'd better re-init the HW */ | 118 | /* When run to this, we'd better re-init the HW */ |
| 120 | mrst_early_console_init(); | 119 | mrst_early_console_init(); |
| 121 | 120 | ||
| 122 | for (i = 0; i < l1; i++) | 121 | while (kmsg_dump_get_line(dumper, true, line, sizeof(line), &len)) |
| 123 | early_mrst_console.write(&early_mrst_console, s1 + i, 1); | 122 | early_mrst_console.write(&early_mrst_console, line, len); |
| 124 | for (i = 0; i < l2; i++) | ||
| 125 | early_mrst_console.write(&early_mrst_console, s2 + i, 1); | ||
| 126 | } | 123 | } |
| 127 | 124 | ||
| 128 | /* Set the ratio rate to 115200, 8n1, IRQ disabled */ | 125 | /* Set the ratio rate to 115200, 8n1, IRQ disabled */ |
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index ae36d7e1e913..551e316e4454 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c | |||
| @@ -304,32 +304,17 @@ static void find_next_position(struct mtdoops_context *cxt) | |||
| 304 | } | 304 | } |
| 305 | 305 | ||
| 306 | static void mtdoops_do_dump(struct kmsg_dumper *dumper, | 306 | static void mtdoops_do_dump(struct kmsg_dumper *dumper, |
| 307 | enum kmsg_dump_reason reason, const char *s1, unsigned long l1, | 307 | enum kmsg_dump_reason reason) |
| 308 | const char *s2, unsigned long l2) | ||
| 309 | { | 308 | { |
| 310 | struct mtdoops_context *cxt = container_of(dumper, | 309 | struct mtdoops_context *cxt = container_of(dumper, |
| 311 | struct mtdoops_context, dump); | 310 | struct mtdoops_context, dump); |
| 312 | unsigned long s1_start, s2_start; | ||
| 313 | unsigned long l1_cpy, l2_cpy; | ||
| 314 | char *dst; | ||
| 315 | |||
| 316 | if (reason != KMSG_DUMP_OOPS && | ||
| 317 | reason != KMSG_DUMP_PANIC) | ||
| 318 | return; | ||
| 319 | 311 | ||
| 320 | /* Only dump oopses if dump_oops is set */ | 312 | /* Only dump oopses if dump_oops is set */ |
| 321 | if (reason == KMSG_DUMP_OOPS && !dump_oops) | 313 | if (reason == KMSG_DUMP_OOPS && !dump_oops) |
| 322 | return; | 314 | return; |
| 323 | 315 | ||
| 324 | dst = cxt->oops_buf + MTDOOPS_HEADER_SIZE; /* Skip the header */ | 316 | kmsg_dump_get_buffer(dumper, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, |
| 325 | l2_cpy = min(l2, record_size - MTDOOPS_HEADER_SIZE); | 317 | record_size - MTDOOPS_HEADER_SIZE, NULL); |
