aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorHATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>2013-07-03 18:02:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 19:07:30 -0400
commit591ff71664e764a3806e341370f3c758cb2e7e3c (patch)
tree7c6b1c4df35242c9cc395e506206ae76e608f166 /fs/proc
parentef9e78fd2753213ea01d77f7a76a9cb6ad0f50a7 (diff)
vmcore: calculate vmcore file size from buffer size and total size of vmcore objects
The previous patches newly added holes before each chunk of memory and the holes need to be count in vmcore file size. There are two ways to count file size in such a way: 1) suppose m is a poitner to the last vmcore object in vmcore_list. Then file size is (m->offset + m->size), or 2) calculate sum of size of buffers for ELF header, program headers, ELF note segments and objects in vmcore_list. Although 1) is more direct and simpler than 2), 2) seems better in that it reflects internal object structure of /proc/vmcore. Thus, this patch changes get_vmcore_size_elf{64, 32} so that it calculates size in the way of 2). As a result, both get_vmcore_size_elf{64, 32} have the same definition. Merge them as get_vmcore_size. Signed-off-by: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com> Acked-by: Vivek Goyal <vgoyal@redhat.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp> Cc: Lisa Mitchell <lisa.mitchell@hp.com> Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/vmcore.c44
1 files changed, 11 insertions, 33 deletions
diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
index 1082492e02fc..8ec648368985 100644
--- a/fs/proc/vmcore.c
+++ b/fs/proc/vmcore.c
@@ -204,36 +204,15 @@ static struct vmcore* __init get_new_element(void)
204 return kzalloc(sizeof(struct vmcore), GFP_KERNEL); 204 return kzalloc(sizeof(struct vmcore), GFP_KERNEL);
205} 205}
206 206
207static u64 __init get_vmcore_size_elf64(char *elfptr, size_t elfsz) 207static u64 __init get_vmcore_size(size_t elfsz, size_t elfnotesegsz,
208 struct list_head *vc_list)
208{ 209{
209 int i;
210 u64 size; 210 u64 size;
211 Elf64_Ehdr *ehdr_ptr; 211 struct vmcore *m;
212 Elf64_Phdr *phdr_ptr;
213
214 ehdr_ptr = (Elf64_Ehdr *)elfptr;
215 phdr_ptr = (Elf64_Phdr*)(elfptr + sizeof(Elf64_Ehdr));
216 size = elfsz;
217 for (i = 0; i < ehdr_ptr->e_phnum; i++) {
218 size += phdr_ptr->p_memsz;
219 phdr_ptr++;
220 }
221 return size;
222}
223
224static u64 __init get_vmcore_size_elf32(char *elfptr, size_t elfsz)
225{
226 int i;
227 u64 size;
228 Elf32_Ehdr *ehdr_ptr;
229 Elf32_Phdr *phdr_ptr;
230 212
231 ehdr_ptr = (Elf32_Ehdr *)elfptr; 213 size = elfsz + elfnotesegsz;
232 phdr_ptr = (Elf32_Phdr*)(elfptr + sizeof(Elf32_Ehdr)); 214 list_for_each_entry(m, vc_list, list) {
233 size = elfsz; 215 size += m->size;
234 for (i = 0; i < ehdr_ptr->e_phnum; i++) {
235 size += phdr_ptr->p_memsz;
236 phdr_ptr++;
237 } 216 }
238 return size; 217 return size;
239} 218}
@@ -856,20 +835,19 @@ static int __init parse_crash_elf_headers(void)
856 rc = parse_crash_elf64_headers(); 835 rc = parse_crash_elf64_headers();
857 if (rc) 836 if (rc)
858 return rc; 837 return rc;
859
860 /* Determine vmcore size. */
861 vmcore_size = get_vmcore_size_elf64(elfcorebuf, elfcorebuf_sz);
862 } else if (e_ident[EI_CLASS] == ELFCLASS32) { 838 } else if (e_ident[EI_CLASS] == ELFCLASS32) {
863 rc = parse_crash_elf32_headers(); 839 rc = parse_crash_elf32_headers();
864 if (rc) 840 if (rc)
865 return rc; 841 return rc;
866
867 /* Determine vmcore size. */
868 vmcore_size = get_vmcore_size_elf32(elfcorebuf, elfcorebuf_sz);
869 } else { 842 } else {
870 pr_warn("Warning: Core image elf header is not sane\n"); 843 pr_warn("Warning: Core image elf header is not sane\n");
871 return -EINVAL; 844 return -EINVAL;
872 } 845 }
846
847 /* Determine vmcore size. */
848 vmcore_size = get_vmcore_size(elfcorebuf_sz, elfnotes_sz,
849 &vmcore_list);
850
873 return 0; 851 return 0;
874} 852}
875 853