From: Baoquan He <bhe@redhat.com>
To: kexec@lists.infradead.org
Cc: kumagai-atsushi@mxc.nes.nec.co.jp, Baoquan He <bhe@redhat.com>,
vgoyal@redhat.com
Subject: [PATCH v4 3/8] preparation functions for parsing vmcoreinfo
Date: Mon, 25 Aug 2014 11:33:07 +0800 [thread overview]
Message-ID: <1408937592-2609-4-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1408937592-2609-1-git-send-email-bhe@redhat.com>
Add 2 preparation functions get_elf_loads and get_page_offset, later
they will be needed for parsing vmcoreinfo.
Meanwhile since get_kernel_version need be called to get page_offset
before initial() in mem_usage code flow, and surely it will be called
inside initial() again. Add a static variable to avoid this duplicate
calling.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
elf_info.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
elf_info.h | 1 +
makedumpfile.c | 18 ++++++++++++++++++
3 files changed, 69 insertions(+)
diff --git a/elf_info.c b/elf_info.c
index b277f69..69d3fdb 100644
--- a/elf_info.c
+++ b/elf_info.c
@@ -681,6 +681,56 @@ get_elf32_ehdr(int fd, char *filename, Elf32_Ehdr *ehdr)
return TRUE;
}
+int
+get_elf_loads(int fd, char *filename)
+{
+ int i, j, phnum, elf_format;
+ Elf64_Phdr phdr;
+
+ /*
+ * Check ELF64 or ELF32.
+ */
+ elf_format = check_elf_format(fd, filename, &phnum, &num_pt_loads);
+ if (elf_format == ELF64)
+ flags_memory |= MEMORY_ELF64;
+ else if (elf_format != ELF32)
+ return FALSE;
+
+ if (!num_pt_loads) {
+ ERRMSG("Can't get the number of PT_LOAD.\n");
+ return FALSE;
+ }
+
+ /*
+ * The below file information will be used as /proc/vmcore.
+ */
+ fd_memory = fd;
+ name_memory = filename;
+
+ pt_loads = calloc(sizeof(struct pt_load_segment), num_pt_loads);
+ if (pt_loads == NULL) {
+ ERRMSG("Can't allocate memory for the PT_LOAD. %s\n",
+ strerror(errno));
+ return FALSE;
+ }
+ for (i = 0, j = 0; i < phnum; i++) {
+ if (!get_phdr_memory(i, &phdr))
+ return FALSE;
+
+ if (phdr.p_type != PT_LOAD)
+ continue;
+
+ if (j >= num_pt_loads)
+ return FALSE;
+ if(!dump_Elf_load(&phdr, j))
+ return FALSE;
+ j++;
+ }
+
+ return TRUE;
+}
+
+
/*
* Get ELF information about /proc/vmcore.
*/
diff --git a/elf_info.h b/elf_info.h
index 801faff..263d993 100644
--- a/elf_info.h
+++ b/elf_info.h
@@ -44,6 +44,7 @@ int get_elf64_ehdr(int fd, char *filename, Elf64_Ehdr *ehdr);
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 is_elf64_memory(void);
int is_xen_memory(void);
diff --git a/makedumpfile.c b/makedumpfile.c
index 44cf26f..8c8ca91 100644
--- a/makedumpfile.c
+++ b/makedumpfile.c
@@ -682,6 +682,9 @@ get_kernel_version(char *release)
long maj, min, rel;
char *start, *end;
+ if (info->kernel_version)
+ return info->kernel_version;
+
/*
* This method checks that vmlinux and vmcore are same kernel version.
*/
@@ -706,6 +709,7 @@ get_kernel_version(char *release)
MSG("The kernel version is not supported.\n");
MSG("The created dumpfile may be incomplete.\n");
}
+
return version;
}
@@ -9125,6 +9129,20 @@ int is_crashkernel_mem_reserved(void)
return !!crash_reserved_mem_nr;
}
+static int get_page_offset()
+{
+ struct utsname utsname;
+ if (uname(&utsname)) {
+ ERRMSG("Cannot get name and information about current kernel : %s", strerror(errno));
+ return FALSE;
+ }
+
+ info->kernel_version = get_kernel_version(utsname.release);
+ get_versiondep_info();
+
+ return TRUE;
+}
+
static struct option longopts[] = {
{"split", no_argument, NULL, OPT_SPLIT},
{"reassemble", no_argument, NULL, OPT_REASSEMBLE},
--
1.8.5.3
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2014-08-25 3:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-25 3:33 [PATCH v4 0/8] add a new interface to show the memory usage of 1st kernel Baoquan He
2014-08-25 3:33 ` [PATCH v4 1/8] initialize pfn_memhole in get_num_dumpable_cyclic Baoquan He
2014-08-25 3:33 ` [PATCH v4 2/8] functions to get crashkernel memory range Baoquan He
2014-08-25 3:33 ` Baoquan He [this message]
2014-08-25 5:45 ` [PATCH v5 3/8] preparation functions for parsing vmcoreinfo Baoquan He
2014-08-25 6:33 ` [PATCH v4 " Baoquan He
2014-08-25 3:33 ` [PATCH v4 4/8] set vmcoreinfo for kcore Baoquan He
2014-08-25 3:33 ` [PATCH v4 5/8] prepare the dump loads for kcore analysis Baoquan He
2014-08-25 3:33 ` [PATCH v4 6/8] introduce a function exclude_zero_pages_cyclic() Baoquan He
2014-08-25 3:33 ` [PATCH v4 7/8] implement a function to print the memory usage Baoquan He
2014-08-25 3:33 ` [PATCH v4 8/8] add a new interface to show the memory usage of 1st kernel Baoquan He
2014-08-25 6:36 ` [PATCH v5 " Baoquan He
2014-08-25 20:04 ` Vivek Goyal
2014-08-26 6:37 ` Baoquan He
2014-08-26 13:10 ` Vivek Goyal
2014-08-27 0:32 ` Atsushi Kumagai
2014-08-29 9:37 ` bhe
2014-08-25 7:03 ` [PATCH v4 " Baoquan He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1408937592-2609-4-git-send-email-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=kexec@lists.infradead.org \
--cc=kumagai-atsushi@mxc.nes.nec.co.jp \
--cc=vgoyal@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox