[Patch v3 4/7] set vmcoreinfo for kcore
Atsushi Kumagai
kumagai-atsushi at mxc.nes.nec.co.jp
Fri Aug 1 00:12:12 PDT 2014
>In vmcore dumping, note program of vmcoreinfo is set in elf header
>of /proc/vmcore. In 1st kernel, the vmcoreinfo is also needed for
>kcore analyzing. So in this patch information of vmcoreinfo is
>parsed and set in offset_vmcoreinfo and size_vmcoreinfo.
>
>Signed-off-by: Baoquan He <bhe at redhat.com>
>---
> elf_info.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
> elf_info.h | 1 +
> makedumpfile.c | 29 +++++++++++++++++++++++++++++
> 3 files changed, 77 insertions(+)
>
>diff --git a/elf_info.c b/elf_info.c
>index 69d3fdb..edbfc97 100644
>--- a/elf_info.c
>+++ b/elf_info.c
>@@ -395,6 +395,53 @@ get_pt_note_info(void)
> return TRUE;
> }
>
>+#define UNINITIALIZED ((ulong)(-1))
>+int set_kcore_vmcoreinfo(uint64_t vmcoreinfo_addr, uint64_t vmcoreinfo_len)
>+{
>+ int i;
>+ ulong kvaddr;
>+ off_t offset;
>+ char note[MAX_SIZE_NHDR];
>+ int size_desc;
>+ off_t offset_desc;
>+
>+ offset = UNINITIALIZED;
>+ kvaddr = (ulong)vmcoreinfo_addr | PAGE_OFFSET;
>+
>+ for (i = 0; i < num_pt_loads; ++i) {
>+ struct pt_load_segment *p = &pt_loads[i];
>+ if ((kvaddr >= p->virt_start) && (kvaddr < p->virt_end)) {
>+ offset = (off_t)(kvaddr - p->virt_start) +
>+ (off_t)p->file_offset;
>+ break;
>+ }
>+ }
>+
>+ if (offset == UNINITIALIZED){
>+ ERRMSG("Can't seek the dump memory(%s). %s\n",
>+ name_memory, strerror(errno));
>+ return FALSE;
>+ }
>+
>+ if (lseek(fd_memory, offset, SEEK_SET) != offset){
>+ ERRMSG("Can't seek the dump memory(%s). %s\n",
>+ name_memory, strerror(errno));
>+ return FALSE;
>+ }
These two error messages are the same, they aren't helpful for debugging.
I think the former should be like "Can't get the offset of VMCOREINFO".
>+
>+ if (read(fd_memory, note, MAX_SIZE_NHDR) != MAX_SIZE_NHDR){
>+ ERRMSG("Can't read the dump memory(%s). %s\n",
>+ name_memory, strerror(errno));
>+ return FALSE;
>+ }
>+
>+ size_desc = note_descsz(note);
>+ offset_desc = offset + offset_note_desc(note);
>+
>+ set_vmcoreinfo(offset_desc, size_desc);
>+
>+ return TRUE;
>+}
>
> /*
> * External functions.
>diff --git a/elf_info.h b/elf_info.h
>index 263d993..3ce0138 100644
>--- a/elf_info.h
>+++ b/elf_info.h
>@@ -45,6 +45,7 @@ int get_elf32_ehdr(int fd, char *filename, Elf32_Ehdr *ehdr);
> int get_elf_info(int fd, char *filename);
> void free_elf_info(void);
> int get_elf_loads(int fd, char *filename);
>+int set_kcore_vmcoreinfo(uint64_t vmcoreinfo_addr, uint64_t vmcoreinfo_len);
>
> int is_elf64_memory(void);
> int is_xen_memory(void);
>diff --git a/makedumpfile.c b/makedumpfile.c
>index 78aa7a5..84857e0 100644
>--- a/makedumpfile.c
>+++ b/makedumpfile.c
>@@ -9085,6 +9085,35 @@ static int get_page_offset()
> return TRUE;
> }
>
>+
>+/* Returns the physical address of start of crash notes buffer for a kernel. */
>+static int get_sys_kernel_vmcoreinfo(uint64_t *addr, uint64_t *len)
>+{
This function just return the result status, so please use TRUE or FALSE
as the return value instead of 0 or -1.
>+ char line[BUFSIZE_FGETS];
>+ int count;
>+ FILE *fp;
>+ unsigned long long temp, temp2;
>+
>+ *addr = 0;
>+ *len = 0;
>+
>+ if (!(fp = fopen("/sys/kernel/vmcoreinfo", "r")))
>+ return -1;
>+
>+ if (!fgets(line, sizeof(line), fp))
>+ ERRMSG("Cannot parse %s: %s\n", "/sys/kernel/vmcoreinfo", strerror(errno));
>+ count = sscanf(line, "%Lx %Lx", &temp, &temp2);
>+ if (count != 2)
>+ ERRMSG("Cannot parse %s: %s\n", "/sys/kernel/vmcoreinfo", strerror(errno));
The messages are the same, too.
Thanks
Atsushi Kumagai
>+
>+ *addr = (uint64_t) temp;
>+ *len = (uint64_t) temp2;
>+
>+ fclose(fp);
>+ return 0;
>+}
>+
>+
> static struct option longopts[] = {
> {"split", no_argument, NULL, OPT_SPLIT},
> {"reassemble", no_argument, NULL, OPT_REASSEMBLE},
>--
>1.8.5.3
More information about the kexec
mailing list