cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
9ae3a8
From 36cd1b1bdc56da8e18d69df82731fb79a2ed01dd Mon Sep 17 00:00:00 2001
9ae3a8
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
9ae3a8
Date: Wed, 13 Dec 2017 13:38:47 +0100
9ae3a8
Subject: [PATCH 16/41] dump: Make DumpState and endian conversion routines
9ae3a8
 available for arch-specific dump code
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
Message-id: <20171213133912.26176-17-marcandre.lureau@redhat.com>
9ae3a8
Patchwork-id: 78366
9ae3a8
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 16/41] dump: Make DumpState and endian conversion routines available for arch-specific dump code
9ae3a8
Bugzilla: 1411490
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
From: Bharata B Rao <bharata@linux.vnet.ibm.com>
9ae3a8
9ae3a8
Make DumpState and endian conversion routines available for arch-specific dump
9ae3a8
code by moving into dump.h. DumpState will be needed by arch-specific dump
9ae3a8
code to access target endian information from DumpState->ArchDumpInfo. Also
9ae3a8
break the dependency of dump.h from stubs/dump.c by creating a separate
9ae3a8
dump-arch.h.
9ae3a8
9ae3a8
This patch doesn't change any functionality.
9ae3a8
9ae3a8
Signed-off-by: Bharata B Rao <bharata@linux.ibm.com>
9ae3a8
[ rebased on top of current master branch,
9ae3a8
  renamed endian helpers to cpu_to_dump{16,32,64},
9ae3a8
  pass a DumpState * argument to endian helpers,
9ae3a8
  Greg Kurz <gkurz@linux.vnet.ibm.com> ]
9ae3a8
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
9ae3a8
[agraf: fix to apply]
9ae3a8
Signed-off-by: Alexander Graf <agraf@suse.de>
9ae3a8
9ae3a8
(cherry picked from commit acb0ef5801fc0caafdcfd34ae62e48d276866a1b)
9ae3a8
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 dump.c                     | 231 ++++++++++++++++++---------------------------
9ae3a8
 include/sysemu/dump-arch.h |  28 ++++++
9ae3a8
 include/sysemu/dump.h      |  45 +++++++--
9ae3a8
 stubs/dump.c               |   2 +-
9ae3a8
 4 files changed, 154 insertions(+), 152 deletions(-)
9ae3a8
 create mode 100644 include/sysemu/dump-arch.h
9ae3a8
9ae3a8
diff --git a/dump.c b/dump.c
9ae3a8
index e9bd237..c902944 100644
9ae3a8
--- a/dump.c
9ae3a8
+++ b/dump.c
9ae3a8
@@ -36,9 +36,9 @@
9ae3a8
 #define ELF_MACHINE_UNAME "Unknown"
9ae3a8
 #endif
9ae3a8
 
9ae3a8
-static uint16_t cpu_convert_to_target16(uint16_t val, int endian)
9ae3a8
+uint16_t cpu_to_dump16(DumpState *s, uint16_t val)
9ae3a8
 {
9ae3a8
-    if (endian == ELFDATA2LSB) {
9ae3a8
+    if (s->dump_info.d_endian == ELFDATA2LSB) {
9ae3a8
         val = cpu_to_le16(val);
9ae3a8
     } else {
9ae3a8
         val = cpu_to_be16(val);
9ae3a8
@@ -47,9 +47,9 @@ static uint16_t cpu_convert_to_target16(uint16_t val, int endian)
9ae3a8
     return val;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static uint32_t cpu_convert_to_target32(uint32_t val, int endian)
9ae3a8
+uint32_t cpu_to_dump32(DumpState *s, uint32_t val)
9ae3a8
 {
9ae3a8
-    if (endian == ELFDATA2LSB) {
9ae3a8
+    if (s->dump_info.d_endian == ELFDATA2LSB) {
9ae3a8
         val = cpu_to_le32(val);
9ae3a8
     } else {
9ae3a8
         val = cpu_to_be32(val);
9ae3a8
@@ -58,9 +58,9 @@ static uint32_t cpu_convert_to_target32(uint32_t val, int endian)
9ae3a8
     return val;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static uint64_t cpu_convert_to_target64(uint64_t val, int endian)
9ae3a8
+uint64_t cpu_to_dump64(DumpState *s, uint64_t val)
9ae3a8
 {
9ae3a8
-    if (endian == ELFDATA2LSB) {
9ae3a8
+    if (s->dump_info.d_endian == ELFDATA2LSB) {
9ae3a8
         val = cpu_to_le64(val);
9ae3a8
     } else {
9ae3a8
         val = cpu_to_be64(val);
9ae3a8
@@ -69,36 +69,6 @@ static uint64_t cpu_convert_to_target64(uint64_t val, int endian)
9ae3a8
     return val;
9ae3a8
 }
9ae3a8
 
9ae3a8
-typedef struct DumpState {
9ae3a8
-    GuestPhysBlockList guest_phys_blocks;
9ae3a8
-    ArchDumpInfo dump_info;
9ae3a8
-    MemoryMappingList list;
9ae3a8
-    uint16_t phdr_num;
9ae3a8
-    uint32_t sh_info;
9ae3a8
-    bool have_section;
9ae3a8
-    bool resume;
9ae3a8
-    ssize_t note_size;
9ae3a8
-    hwaddr memory_offset;
9ae3a8
-    int fd;
9ae3a8
-
9ae3a8
-    GuestPhysBlock *next_block;
9ae3a8
-    ram_addr_t start;
9ae3a8
-    bool has_filter;
9ae3a8
-    int64_t begin;
9ae3a8
-    int64_t length;
9ae3a8
-
9ae3a8
-    uint8_t *note_buf;          /* buffer for notes */
9ae3a8
-    size_t note_buf_offset;     /* the writing place in note_buf */
9ae3a8
-    uint32_t nr_cpus;           /* number of guest's cpu */
9ae3a8
-    uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
9ae3a8
-    size_t len_dump_bitmap;     /* the size of the place used to store
9ae3a8
-                                   dump_bitmap in vmcore */
9ae3a8
-    off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
9ae3a8
-    off_t offset_page;          /* offset of page part in vmcore */
9ae3a8
-    size_t num_dumpable;        /* number of page that can be dumped */
9ae3a8
-    uint32_t flag_compress;     /* indicate the compression format */
9ae3a8
-} DumpState;
9ae3a8
-
9ae3a8
 static int dump_cleanup(DumpState *s)
9ae3a8
 {
9ae3a8
     int ret = 0;
9ae3a8
@@ -137,29 +107,25 @@ static int write_elf64_header(DumpState *s)
9ae3a8
 {
9ae3a8
     Elf64_Ehdr elf_header;
9ae3a8
     int ret;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
 
9ae3a8
     memset(&elf_header, 0, sizeof(Elf64_Ehdr));
9ae3a8
     memcpy(&elf_header, ELFMAG, SELFMAG);
9ae3a8
     elf_header.e_ident[EI_CLASS] = ELFCLASS64;
9ae3a8
     elf_header.e_ident[EI_DATA] = s->dump_info.d_endian;
9ae3a8
     elf_header.e_ident[EI_VERSION] = EV_CURRENT;
9ae3a8
-    elf_header.e_type = cpu_convert_to_target16(ET_CORE, endian);
9ae3a8
-    elf_header.e_machine = cpu_convert_to_target16(s->dump_info.d_machine,
9ae3a8
-                                                   endian);
9ae3a8
-    elf_header.e_version = cpu_convert_to_target32(EV_CURRENT, endian);
9ae3a8
-    elf_header.e_ehsize = cpu_convert_to_target16(sizeof(elf_header), endian);
9ae3a8
-    elf_header.e_phoff = cpu_convert_to_target64(sizeof(Elf64_Ehdr), endian);
9ae3a8
-    elf_header.e_phentsize = cpu_convert_to_target16(sizeof(Elf64_Phdr),
9ae3a8
-                                                     endian);
9ae3a8
-    elf_header.e_phnum = cpu_convert_to_target16(s->phdr_num, endian);
9ae3a8
+    elf_header.e_type = cpu_to_dump16(s, ET_CORE);
9ae3a8
+    elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
9ae3a8
+    elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
9ae3a8
+    elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
9ae3a8
+    elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
9ae3a8
+    elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
9ae3a8
+    elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num);
9ae3a8
     if (s->have_section) {
9ae3a8
         uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->sh_info;
9ae3a8
 
9ae3a8
-        elf_header.e_shoff = cpu_convert_to_target64(shoff, endian);
9ae3a8
-        elf_header.e_shentsize = cpu_convert_to_target16(sizeof(Elf64_Shdr),
9ae3a8
-                                                         endian);
9ae3a8
-        elf_header.e_shnum = cpu_convert_to_target16(1, endian);
9ae3a8
+        elf_header.e_shoff = cpu_to_dump64(s, shoff);
9ae3a8
+        elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
9ae3a8
+        elf_header.e_shnum = cpu_to_dump16(s, 1);
9ae3a8
     }
9ae3a8
 
9ae3a8
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
9ae3a8
@@ -175,29 +141,25 @@ static int write_elf32_header(DumpState *s)
9ae3a8
 {
9ae3a8
     Elf32_Ehdr elf_header;
9ae3a8
     int ret;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
 
9ae3a8
     memset(&elf_header, 0, sizeof(Elf32_Ehdr));
9ae3a8
     memcpy(&elf_header, ELFMAG, SELFMAG);
9ae3a8
     elf_header.e_ident[EI_CLASS] = ELFCLASS32;
9ae3a8
-    elf_header.e_ident[EI_DATA] = endian;
9ae3a8
+    elf_header.e_ident[EI_DATA] = s->dump_info.d_endian;
9ae3a8
     elf_header.e_ident[EI_VERSION] = EV_CURRENT;
9ae3a8
-    elf_header.e_type = cpu_convert_to_target16(ET_CORE, endian);
9ae3a8
-    elf_header.e_machine = cpu_convert_to_target16(s->dump_info.d_machine,
9ae3a8
-                                                   endian);
9ae3a8
-    elf_header.e_version = cpu_convert_to_target32(EV_CURRENT, endian);
9ae3a8
-    elf_header.e_ehsize = cpu_convert_to_target16(sizeof(elf_header), endian);
9ae3a8
-    elf_header.e_phoff = cpu_convert_to_target32(sizeof(Elf32_Ehdr), endian);
9ae3a8
-    elf_header.e_phentsize = cpu_convert_to_target16(sizeof(Elf32_Phdr),
9ae3a8
-                                                     endian);
9ae3a8
-    elf_header.e_phnum = cpu_convert_to_target16(s->phdr_num, endian);
9ae3a8
+    elf_header.e_type = cpu_to_dump16(s, ET_CORE);
9ae3a8
+    elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
9ae3a8
+    elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
9ae3a8
+    elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
9ae3a8
+    elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
9ae3a8
+    elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
9ae3a8
+    elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num);
9ae3a8
     if (s->have_section) {
9ae3a8
         uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->sh_info;
9ae3a8
 
9ae3a8
-        elf_header.e_shoff = cpu_convert_to_target32(shoff, endian);
9ae3a8
-        elf_header.e_shentsize = cpu_convert_to_target16(sizeof(Elf32_Shdr),
9ae3a8
-                                                         endian);
9ae3a8
-        elf_header.e_shnum = cpu_convert_to_target16(1, endian);
9ae3a8
+        elf_header.e_shoff = cpu_to_dump32(s, shoff);
9ae3a8
+        elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
9ae3a8
+        elf_header.e_shnum = cpu_to_dump16(s, 1);
9ae3a8
     }
9ae3a8
 
9ae3a8
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
9ae3a8
@@ -215,15 +177,14 @@ static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
9ae3a8
 {
9ae3a8
     Elf64_Phdr phdr;
9ae3a8
     int ret;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
 
9ae3a8
     memset(&phdr, 0, sizeof(Elf64_Phdr));
9ae3a8
-    phdr.p_type = cpu_convert_to_target32(PT_LOAD, endian);
9ae3a8
-    phdr.p_offset = cpu_convert_to_target64(offset, endian);
9ae3a8
-    phdr.p_paddr = cpu_convert_to_target64(memory_mapping->phys_addr, endian);
9ae3a8
-    phdr.p_filesz = cpu_convert_to_target64(filesz, endian);
9ae3a8
-    phdr.p_memsz = cpu_convert_to_target64(memory_mapping->length, endian);
9ae3a8
-    phdr.p_vaddr = cpu_convert_to_target64(memory_mapping->virt_addr, endian);
9ae3a8
+    phdr.p_type = cpu_to_dump32(s, PT_LOAD);
9ae3a8
+    phdr.p_offset = cpu_to_dump64(s, offset);
9ae3a8
+    phdr.p_paddr = cpu_to_dump64(s, memory_mapping->phys_addr);
9ae3a8
+    phdr.p_filesz = cpu_to_dump64(s, filesz);
9ae3a8
+    phdr.p_memsz = cpu_to_dump64(s, memory_mapping->length);
9ae3a8
+    phdr.p_vaddr = cpu_to_dump64(s, memory_mapping->virt_addr);
9ae3a8
 
9ae3a8
     assert(memory_mapping->length >= filesz);
9ae3a8
 
9ae3a8
@@ -242,15 +203,14 @@ static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
9ae3a8
 {
9ae3a8
     Elf32_Phdr phdr;
9ae3a8
     int ret;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
 
9ae3a8
     memset(&phdr, 0, sizeof(Elf32_Phdr));
9ae3a8
-    phdr.p_type = cpu_convert_to_target32(PT_LOAD, endian);
9ae3a8
-    phdr.p_offset = cpu_convert_to_target32(offset, endian);
9ae3a8
-    phdr.p_paddr = cpu_convert_to_target32(memory_mapping->phys_addr, endian);
9ae3a8
-    phdr.p_filesz = cpu_convert_to_target32(filesz, endian);
9ae3a8
-    phdr.p_memsz = cpu_convert_to_target32(memory_mapping->length, endian);
9ae3a8
-    phdr.p_vaddr = cpu_convert_to_target32(memory_mapping->virt_addr, endian);
9ae3a8
+    phdr.p_type = cpu_to_dump32(s, PT_LOAD);
9ae3a8
+    phdr.p_offset = cpu_to_dump32(s, offset);
9ae3a8
+    phdr.p_paddr = cpu_to_dump32(s, memory_mapping->phys_addr);
9ae3a8
+    phdr.p_filesz = cpu_to_dump32(s, filesz);
9ae3a8
+    phdr.p_memsz = cpu_to_dump32(s, memory_mapping->length);
9ae3a8
+    phdr.p_vaddr = cpu_to_dump32(s, memory_mapping->virt_addr);
9ae3a8
 
9ae3a8
     assert(memory_mapping->length >= filesz);
9ae3a8
 
9ae3a8
@@ -266,16 +226,15 @@ static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
9ae3a8
 static int write_elf64_note(DumpState *s)
9ae3a8
 {
9ae3a8
     Elf64_Phdr phdr;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
     hwaddr begin = s->memory_offset - s->note_size;
9ae3a8
     int ret;
9ae3a8
 
9ae3a8
     memset(&phdr, 0, sizeof(Elf64_Phdr));
9ae3a8
-    phdr.p_type = cpu_convert_to_target32(PT_NOTE, endian);
9ae3a8
-    phdr.p_offset = cpu_convert_to_target64(begin, endian);
9ae3a8
+    phdr.p_type = cpu_to_dump32(s, PT_NOTE);
9ae3a8
+    phdr.p_offset = cpu_to_dump64(s, begin);
9ae3a8
     phdr.p_paddr = 0;
9ae3a8
-    phdr.p_filesz = cpu_convert_to_target64(s->note_size, endian);
9ae3a8
-    phdr.p_memsz = cpu_convert_to_target64(s->note_size, endian);
9ae3a8
+    phdr.p_filesz = cpu_to_dump64(s, s->note_size);
9ae3a8
+    phdr.p_memsz = cpu_to_dump64(s, s->note_size);
9ae3a8
     phdr.p_vaddr = 0;
9ae3a8
 
9ae3a8
     ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
9ae3a8
@@ -325,15 +284,14 @@ static int write_elf32_note(DumpState *s)
9ae3a8
 {
9ae3a8
     hwaddr begin = s->memory_offset - s->note_size;
9ae3a8
     Elf32_Phdr phdr;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
     int ret;
9ae3a8
 
9ae3a8
     memset(&phdr, 0, sizeof(Elf32_Phdr));
9ae3a8
-    phdr.p_type = cpu_convert_to_target32(PT_NOTE, endian);
9ae3a8
-    phdr.p_offset = cpu_convert_to_target32(begin, endian);
9ae3a8
+    phdr.p_type = cpu_to_dump32(s, PT_NOTE);
9ae3a8
+    phdr.p_offset = cpu_to_dump32(s, begin);
9ae3a8
     phdr.p_paddr = 0;
9ae3a8
-    phdr.p_filesz = cpu_convert_to_target32(s->note_size, endian);
9ae3a8
-    phdr.p_memsz = cpu_convert_to_target32(s->note_size, endian);
9ae3a8
+    phdr.p_filesz = cpu_to_dump32(s, s->note_size);
9ae3a8
+    phdr.p_memsz = cpu_to_dump32(s, s->note_size);
9ae3a8
     phdr.p_vaddr = 0;
9ae3a8
 
9ae3a8
     ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
9ae3a8
@@ -378,7 +336,6 @@ static int write_elf_section(DumpState *s, int type)
9ae3a8
 {
9ae3a8
     Elf32_Shdr shdr32;
9ae3a8
     Elf64_Shdr shdr64;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
     int shdr_size;
9ae3a8
     void *shdr;
9ae3a8
     int ret;
9ae3a8
@@ -386,12 +343,12 @@ static int write_elf_section(DumpState *s, int type)
9ae3a8
     if (type == 0) {
9ae3a8
         shdr_size = sizeof(Elf32_Shdr);
9ae3a8
         memset(&shdr32, 0, shdr_size);
9ae3a8
-        shdr32.sh_info = cpu_convert_to_target32(s->sh_info, endian);
9ae3a8
+        shdr32.sh_info = cpu_to_dump32(s, s->sh_info);
9ae3a8
         shdr = &shdr32;
9ae3a8
     } else {
9ae3a8
         shdr_size = sizeof(Elf64_Shdr);
9ae3a8
         memset(&shdr64, 0, shdr_size);
9ae3a8
-        shdr64.sh_info = cpu_convert_to_target32(s->sh_info, endian);
9ae3a8
+        shdr64.sh_info = cpu_to_dump32(s, s->sh_info);
9ae3a8
         shdr = &shdr64;
9ae3a8
     }
9ae3a8
 
9ae3a8
@@ -797,7 +754,6 @@ static int create_header32(DumpState *s)
9ae3a8
     DiskDumpHeader32 *dh = NULL;
9ae3a8
     KdumpSubHeader32 *kh = NULL;
9ae3a8
     size_t size;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
     uint32_t block_size;
9ae3a8
     uint32_t sub_hdr_size;
9ae3a8
     uint32_t bitmap_blocks;
9ae3a8
@@ -809,18 +765,17 @@ static int create_header32(DumpState *s)
9ae3a8
     dh = g_malloc0(size);
9ae3a8
 
9ae3a8
     strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
9ae3a8
-    dh->header_version = cpu_convert_to_target32(6, endian);
9ae3a8
+    dh->header_version = cpu_to_dump32(s, 6);
9ae3a8
     block_size = TARGET_PAGE_SIZE;
9ae3a8
-    dh->block_size = cpu_convert_to_target32(block_size, endian);
9ae3a8
+    dh->block_size = cpu_to_dump32(s, block_size);
9ae3a8
     sub_hdr_size = sizeof(struct KdumpSubHeader32) + s->note_size;
9ae3a8
     sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);
9ae3a8
-    dh->sub_hdr_size = cpu_convert_to_target32(sub_hdr_size, endian);
9ae3a8
+    dh->sub_hdr_size = cpu_to_dump32(s, sub_hdr_size);
9ae3a8
     /* dh->max_mapnr may be truncated, full 64bit is in kh.max_mapnr_64 */
9ae3a8
-    dh->max_mapnr = cpu_convert_to_target32(MIN(s->max_mapnr, UINT_MAX),
9ae3a8
-                                            endian);
9ae3a8
-    dh->nr_cpus = cpu_convert_to_target32(s->nr_cpus, endian);
9ae3a8
+    dh->max_mapnr = cpu_to_dump32(s, MIN(s->max_mapnr, UINT_MAX));
9ae3a8
+    dh->nr_cpus = cpu_to_dump32(s, s->nr_cpus);
9ae3a8
     bitmap_blocks = DIV_ROUND_UP(s->len_dump_bitmap, block_size) * 2;
9ae3a8
-    dh->bitmap_blocks = cpu_convert_to_target32(bitmap_blocks, endian);
9ae3a8
+    dh->bitmap_blocks = cpu_to_dump32(s, bitmap_blocks);
9ae3a8
     strncpy(dh->utsname.machine, ELF_MACHINE_UNAME, sizeof(dh->utsname.machine));
9ae3a8
 
9ae3a8
     if (s->flag_compress & DUMP_DH_COMPRESSED_ZLIB) {
9ae3a8
@@ -836,7 +791,7 @@ static int create_header32(DumpState *s)
9ae3a8
         status |= DUMP_DH_COMPRESSED_SNAPPY;
9ae3a8
     }
9ae3a8
 #endif
9ae3a8
-    dh->status = cpu_convert_to_target32(status, endian);
9ae3a8
+    dh->status = cpu_to_dump32(s, status);
9ae3a8
 
9ae3a8
     if (write_buffer(s->fd, 0, dh, size) < 0) {
9ae3a8
         dump_error(s, "dump: failed to write disk dump header.\n");
9ae3a8
@@ -849,13 +804,13 @@ static int create_header32(DumpState *s)
9ae3a8
     kh = g_malloc0(size);
9ae3a8
 
9ae3a8
     /* 64bit max_mapnr_64 */
9ae3a8
-    kh->max_mapnr_64 = cpu_convert_to_target64(s->max_mapnr, endian);
9ae3a8
-    kh->phys_base = cpu_convert_to_target32(PHYS_BASE, endian);
9ae3a8
-    kh->dump_level = cpu_convert_to_target32(DUMP_LEVEL, endian);
9ae3a8
+    kh->max_mapnr_64 = cpu_to_dump64(s, s->max_mapnr);
9ae3a8
+    kh->phys_base = cpu_to_dump32(s, PHYS_BASE);
9ae3a8
+    kh->dump_level = cpu_to_dump32(s, DUMP_LEVEL);
9ae3a8
 
9ae3a8
     offset_note = DISKDUMP_HEADER_BLOCKS * block_size + size;
9ae3a8
-    kh->offset_note = cpu_convert_to_target64(offset_note, endian);
9ae3a8
-    kh->note_size = cpu_convert_to_target32(s->note_size, endian);
9ae3a8
+    kh->offset_note = cpu_to_dump64(s, offset_note);
9ae3a8
+    kh->note_size = cpu_to_dump32(s, s->note_size);
9ae3a8
 
9ae3a8
     if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
9ae3a8
                      block_size, kh, size) < 0) {
9ae3a8
@@ -904,7 +859,6 @@ static int create_header64(DumpState *s)
9ae3a8
     DiskDumpHeader64 *dh = NULL;
9ae3a8
     KdumpSubHeader64 *kh = NULL;
9ae3a8
     size_t size;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
     uint32_t block_size;
9ae3a8
     uint32_t sub_hdr_size;
9ae3a8
     uint32_t bitmap_blocks;
9ae3a8
@@ -916,18 +870,17 @@ static int create_header64(DumpState *s)
9ae3a8
     dh = g_malloc0(size);
9ae3a8
 
9ae3a8
     strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
9ae3a8
-    dh->header_version = cpu_convert_to_target32(6, endian);
9ae3a8
+    dh->header_version = cpu_to_dump32(s, 6);
9ae3a8
     block_size = TARGET_PAGE_SIZE;
9ae3a8
-    dh->block_size = cpu_convert_to_target32(block_size, endian);
9ae3a8
+    dh->block_size = cpu_to_dump32(s, block_size);
9ae3a8
     sub_hdr_size = sizeof(struct KdumpSubHeader64) + s->note_size;
9ae3a8
     sub_hdr_size = DIV_ROUND_UP(sub_hdr_size, block_size);
9ae3a8
-    dh->sub_hdr_size = cpu_convert_to_target32(sub_hdr_size, endian);
9ae3a8
+    dh->sub_hdr_size = cpu_to_dump32(s, sub_hdr_size);
9ae3a8
     /* dh->max_mapnr may be truncated, full 64bit is in kh.max_mapnr_64 */
9ae3a8
-    dh->max_mapnr = cpu_convert_to_target32(MIN(s->max_mapnr, UINT_MAX),
9ae3a8
-                                            endian);
9ae3a8
-    dh->nr_cpus = cpu_convert_to_target32(s->nr_cpus, endian);
9ae3a8
+    dh->max_mapnr = cpu_to_dump32(s, MIN(s->max_mapnr, UINT_MAX));
9ae3a8
+    dh->nr_cpus = cpu_to_dump32(s, s->nr_cpus);
9ae3a8
     bitmap_blocks = DIV_ROUND_UP(s->len_dump_bitmap, block_size) * 2;
9ae3a8
-    dh->bitmap_blocks = cpu_convert_to_target32(bitmap_blocks, endian);
9ae3a8
+    dh->bitmap_blocks = cpu_to_dump32(s, bitmap_blocks);
9ae3a8
     strncpy(dh->utsname.machine, ELF_MACHINE_UNAME, sizeof(dh->utsname.machine));
9ae3a8
 
9ae3a8
     if (s->flag_compress & DUMP_DH_COMPRESSED_ZLIB) {
9ae3a8
@@ -943,7 +896,7 @@ static int create_header64(DumpState *s)
9ae3a8
         status |= DUMP_DH_COMPRESSED_SNAPPY;
9ae3a8
     }
9ae3a8
 #endif
9ae3a8
-    dh->status = cpu_convert_to_target32(status, endian);
9ae3a8
+    dh->status = cpu_to_dump32(s, status);
9ae3a8
 
9ae3a8
     if (write_buffer(s->fd, 0, dh, size) < 0) {
9ae3a8
         dump_error(s, "dump: failed to write disk dump header.\n");
9ae3a8
@@ -956,13 +909,13 @@ static int create_header64(DumpState *s)
9ae3a8
     kh = g_malloc0(size);
9ae3a8
 
9ae3a8
     /* 64bit max_mapnr_64 */
9ae3a8
-    kh->max_mapnr_64 = cpu_convert_to_target64(s->max_mapnr, endian);
9ae3a8
-    kh->phys_base = cpu_convert_to_target64(PHYS_BASE, endian);
9ae3a8
-    kh->dump_level = cpu_convert_to_target32(DUMP_LEVEL, endian);
9ae3a8
+    kh->max_mapnr_64 = cpu_to_dump64(s, s->max_mapnr);
9ae3a8
+    kh->phys_base = cpu_to_dump64(s, PHYS_BASE);
9ae3a8
+    kh->dump_level = cpu_to_dump32(s, DUMP_LEVEL);
9ae3a8
 
9ae3a8
     offset_note = DISKDUMP_HEADER_BLOCKS * block_size + size;
9ae3a8
-    kh->offset_note = cpu_convert_to_target64(offset_note, endian);
9ae3a8
-    kh->note_size = cpu_convert_to_target64(s->note_size, endian);
9ae3a8
+    kh->offset_note = cpu_to_dump64(s, offset_note);
9ae3a8
+    kh->note_size = cpu_to_dump64(s, s->note_size);
9ae3a8
 
9ae3a8
     if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
9ae3a8
                      block_size, kh, size) < 0) {
9ae3a8
@@ -1266,7 +1219,6 @@ static int write_dump_pages(DumpState *s)
9ae3a8
     off_t offset_desc, offset_data;
9ae3a8
     PageDescriptor pd, pd_zero;
9ae3a8
     uint8_t *buf;
9ae3a8
-    int endian = s->dump_info.d_endian;
9ae3a8
     GuestPhysBlock *block_iter = NULL;
9ae3a8
     uint64_t pfn_iter;
9ae3a8
 
9ae3a8
@@ -1291,10 +1243,10 @@ static int write_dump_pages(DumpState *s)
9ae3a8
      * init zero page's page_desc and page_data, because every zero page
9ae3a8
      * uses the same page_data
9ae3a8
      */
9ae3a8
-    pd_zero.size = cpu_convert_to_target32(TARGET_PAGE_SIZE, endian);
9ae3a8
-    pd_zero.flags = cpu_convert_to_target32(0, endian);
9ae3a8
-    pd_zero.offset = cpu_convert_to_target64(offset_data, endian);
9ae3a8
-    pd_zero.page_flags = cpu_convert_to_target64(0, endian);
9ae3a8
+    pd_zero.size = cpu_to_dump32(s, TARGET_PAGE_SIZE);
9ae3a8
+    pd_zero.flags = cpu_to_dump32(s, 0);
9ae3a8
+    pd_zero.offset = cpu_to_dump64(s, offset_data);
9ae3a8
+    pd_zero.page_flags = cpu_to_dump64(s, 0);
9ae3a8
     buf = g_malloc0(TARGET_PAGE_SIZE);
9ae3a8
     ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
9ae3a8
     g_free(buf);
9ae3a8
@@ -1332,12 +1284,11 @@ static int write_dump_pages(DumpState *s)
9ae3a8
              */
9ae3a8
              size_out = len_buf_out;
9ae3a8
              if ((s->flag_compress & DUMP_DH_COMPRESSED_ZLIB) &&
9ae3a8
-                 (compress2(buf_out, (uLongf *)&size_out, buf,
9ae3a8
-                            TARGET_PAGE_SIZE, Z_BEST_SPEED) == Z_OK) &&
9ae3a8
-                 (size_out < TARGET_PAGE_SIZE)) {
9ae3a8
-                pd.flags = cpu_convert_to_target32(DUMP_DH_COMPRESSED_ZLIB,
9ae3a8
-                                                   endian);
9ae3a8
-                pd.size  = cpu_convert_to_target32(size_out, endian);
9ae3a8
+                    (compress2(buf_out, (uLongf *)&size_out, buf,
9ae3a8
+                               TARGET_PAGE_SIZE, Z_BEST_SPEED) == Z_OK) &&
9ae3a8
+                    (size_out < TARGET_PAGE_SIZE)) {
9ae3a8
+                pd.flags = cpu_to_dump32(s, DUMP_DH_COMPRESSED_ZLIB);
9ae3a8
+                pd.size  = cpu_to_dump32(s, size_out);
9ae3a8
 
9ae3a8
                 ret = write_cache(&page_data, buf_out, size_out, false);
9ae3a8
                 if (ret < 0) {
9ae3a8
@@ -1349,9 +1300,8 @@ static int write_dump_pages(DumpState *s)
9ae3a8
                     (lzo1x_1_compress(buf, TARGET_PAGE_SIZE, buf_out,
9ae3a8
                     (lzo_uint *)&size_out, wrkmem) == LZO_E_OK) &&
9ae3a8
                     (size_out < TARGET_PAGE_SIZE)) {
9ae3a8
-                pd.flags = cpu_convert_to_target32(DUMP_DH_COMPRESSED_LZO,
9ae3a8
-                                                   endian);
9ae3a8
-                pd.size  = cpu_convert_to_target32(size_out, endian);
9ae3a8
+                pd.flags = cpu_to_dump32(s, DUMP_DH_COMPRESSED_LZO);
9ae3a8
+                pd.size  = cpu_to_dump32(s, size_out);
9ae3a8
 
9ae3a8
                 ret = write_cache(&page_data, buf_out, size_out, false);
9ae3a8
                 if (ret < 0) {
9ae3a8
@@ -1364,9 +1314,8 @@ static int write_dump_pages(DumpState *s)
9ae3a8
                     (snappy_compress((char *)buf, TARGET_PAGE_SIZE,
9ae3a8
                     (char *)buf_out, &size_out) == SNAPPY_OK) &&
9ae3a8
                     (size_out < TARGET_PAGE_SIZE)) {
9ae3a8
-                pd.flags = cpu_convert_to_target32(
9ae3a8
-                                        DUMP_DH_COMPRESSED_SNAPPY, endian);
9ae3a8
-                pd.size  = cpu_convert_to_target32(size_out, endian);
9ae3a8
+                pd.flags = cpu_to_dump32(s, DUMP_DH_COMPRESSED_SNAPPY);
9ae3a8
+                pd.size  = cpu_to_dump32(s, size_out);
9ae3a8
 
9ae3a8
                 ret = write_cache(&page_data, buf_out, size_out, false);
9ae3a8
                 if (ret < 0) {
9ae3a8
@@ -1379,9 +1328,9 @@ static int write_dump_pages(DumpState *s)
9ae3a8
                  * fall back to save in plaintext, size_out should be
9ae3a8
                  * assigned TARGET_PAGE_SIZE
9ae3a8
                  */
9ae3a8
-                pd.flags = cpu_convert_to_target32(0, endian);
9ae3a8
+                pd.flags = cpu_to_dump32(s, 0);
9ae3a8
                 size_out = TARGET_PAGE_SIZE;
9ae3a8
-                pd.size = cpu_convert_to_target32(size_out, endian);
9ae3a8
+                pd.size = cpu_to_dump32(s, size_out);
9ae3a8
 
9ae3a8
                 ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
9ae3a8
                 if (ret < 0) {
9ae3a8
@@ -1391,8 +1340,8 @@ static int write_dump_pages(DumpState *s)
9ae3a8
             }
9ae3a8
 
9ae3a8
             /* get and write page desc here */
9ae3a8
-            pd.page_flags = cpu_convert_to_target64(0, endian);
9ae3a8
-            pd.offset = cpu_convert_to_target64(offset_data, endian);
9ae3a8
+            pd.page_flags = cpu_to_dump64(s, 0);
9ae3a8
+            pd.offset = cpu_to_dump64(s, offset_data);
9ae3a8
             offset_data += size_out;
9ae3a8
 
9ae3a8
             ret = write_cache(&page_desc, &pd, sizeof(PageDescriptor), false);
9ae3a8
diff --git a/include/sysemu/dump-arch.h b/include/sysemu/dump-arch.h
9ae3a8
new file mode 100644
9ae3a8
index 0000000..9c95ced
9ae3a8
--- /dev/null
9ae3a8
+++ b/include/sysemu/dump-arch.h
9ae3a8
@@ -0,0 +1,28 @@
9ae3a8
+/*
9ae3a8
+ * QEMU dump
9ae3a8
+ *
9ae3a8
+ * Copyright Fujitsu, Corp. 2011, 2012
9ae3a8
+ *
9ae3a8
+ * Authors:
9ae3a8
+ *     Wen Congyang <wency@cn.fujitsu.com>
9ae3a8
+ *
9ae3a8
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
9ae3a8
+ * See the COPYING file in the top-level directory.
9ae3a8
+ *
9ae3a8
+ */
9ae3a8
+
9ae3a8
+#ifndef DUMP_ARCH_H
9ae3a8
+#define DUMP_ARCH_H
9ae3a8
+
9ae3a8
+typedef struct ArchDumpInfo {
9ae3a8
+    int d_machine;  /* Architecture */
9ae3a8
+    int d_endian;   /* ELFDATA2LSB or ELFDATA2MSB */
9ae3a8
+    int d_class;    /* ELFCLASS32 or ELFCLASS64 */
9ae3a8
+} ArchDumpInfo;
9ae3a8
+
9ae3a8
+struct GuestPhysBlockList; /* memory_mapping.h */
9ae3a8
+int cpu_get_dump_info(ArchDumpInfo *info,
9ae3a8
+                      const struct GuestPhysBlockList *guest_phys_blocks);
9ae3a8
+ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
9ae3a8
+
9ae3a8
+#endif
9ae3a8
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
9ae3a8
index 12af557..7e4ec5c 100644
9ae3a8
--- a/include/sysemu/dump.h
9ae3a8
+++ b/include/sysemu/dump.h
9ae3a8
@@ -43,11 +43,8 @@
9ae3a8
 #define PFN_BUFBITMAP               (CHAR_BIT * BUFSIZE_BITMAP)
9ae3a8
 #define BUFSIZE_DATA_CACHE          (TARGET_PAGE_SIZE * 4)
9ae3a8
 
9ae3a8
-typedef struct ArchDumpInfo {
9ae3a8
-    int d_machine;  /* Architecture */
9ae3a8
-    int d_endian;   /* ELFDATA2LSB or ELFDATA2MSB */
9ae3a8
-    int d_class;    /* ELFCLASS32 or ELFCLASS64 */
9ae3a8
-} ArchDumpInfo;
9ae3a8
+#include "sysemu/dump-arch.h"
9ae3a8
+#include "sysemu/memory_mapping.h"
9ae3a8
 
9ae3a8
 typedef struct QEMU_PACKED MakedumpfileHeader {
9ae3a8
     char signature[16];     /* = "makedumpfile" */
9ae3a8
@@ -158,9 +155,37 @@ typedef struct QEMU_PACKED PageDescriptor {
9ae3a8
     uint64_t page_flags;            /* page flags */
9ae3a8
 } PageDescriptor;
9ae3a8
 
9ae3a8
-struct GuestPhysBlockList; /* memory_mapping.h */
9ae3a8
-int cpu_get_dump_info(ArchDumpInfo *info,
9ae3a8
-                      const struct GuestPhysBlockList *guest_phys_blocks);
9ae3a8
-ssize_t cpu_get_note_size(int class, int machine, int nr_cpus);
9ae3a8
-
9ae3a8
+typedef struct DumpState {
9ae3a8
+    GuestPhysBlockList guest_phys_blocks;
9ae3a8
+    ArchDumpInfo dump_info;
9ae3a8
+    MemoryMappingList list;
9ae3a8
+    uint16_t phdr_num;
9ae3a8
+    uint32_t sh_info;
9ae3a8
+    bool have_section;
9ae3a8
+    bool resume;
9ae3a8
+    ssize_t note_size;
9ae3a8
+    hwaddr memory_offset;
9ae3a8
+    int fd;
9ae3a8
+
9ae3a8
+    GuestPhysBlock *next_block;
9ae3a8
+    ram_addr_t start;
9ae3a8
+    bool has_filter;
9ae3a8
+    int64_t begin;
9ae3a8
+    int64_t length;
9ae3a8
+
9ae3a8
+    uint8_t *note_buf;          /* buffer for notes */
9ae3a8
+    size_t note_buf_offset;     /* the writing place in note_buf */
9ae3a8
+    uint32_t nr_cpus;           /* number of guest's cpu */
9ae3a8
+    uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
9ae3a8
+    size_t len_dump_bitmap;     /* the size of the place used to store
9ae3a8
+                                   dump_bitmap in vmcore */
9ae3a8
+    off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
9ae3a8
+    off_t offset_page;          /* offset of page part in vmcore */
9ae3a8
+    size_t num_dumpable;        /* number of page that can be dumped */
9ae3a8
+    uint32_t flag_compress;     /* indicate the compression format */
9ae3a8
+} DumpState;
9ae3a8
+
9ae3a8
+uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
9ae3a8
+uint32_t cpu_to_dump32(DumpState *s, uint32_t val);
9ae3a8
+uint64_t cpu_to_dump64(DumpState *s, uint64_t val);
9ae3a8
 #endif
9ae3a8
diff --git a/stubs/dump.c b/stubs/dump.c
9ae3a8
index 370cd96..fac7019 100644
9ae3a8
--- a/stubs/dump.c
9ae3a8
+++ b/stubs/dump.c
9ae3a8
@@ -12,7 +12,7 @@
9ae3a8
  */
9ae3a8
 
9ae3a8
 #include "qemu-common.h"
9ae3a8
-#include "sysemu/dump.h"
9ae3a8
+#include "sysemu/dump-arch.h"
9ae3a8
 #include "qapi/qmp/qerror.h"
9ae3a8
 #include "qmp-commands.h"
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8