yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-dump-Make-DumpState-and-endian-conversion-routines-a.patch

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