1 /* 2 * QEMU dump 3 * 4 * Copyright Fujitsu, Corp. 2011, 2012 5 * 6 * Authors: 7 * Wen Congyang <wency@cn.fujitsu.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 * 12 */ 13 14 #ifndef DUMP_H 15 #define DUMP_H 16 17 #define MAKEDUMPFILE_SIGNATURE "makedumpfile" 18 #define MAX_SIZE_MDF_HEADER (4096) /* max size of makedumpfile_header */ 19 #define TYPE_FLAT_HEADER (1) /* type of flattened format */ 20 #define VERSION_FLAT_HEADER (1) /* version of flattened format */ 21 #define END_FLAG_FLAT_HEADER (-1) 22 23 #ifndef ARCH_PFN_OFFSET 24 #define ARCH_PFN_OFFSET (0) 25 #endif 26 27 /* 28 * flag for compressed format 29 */ 30 #define DUMP_DH_COMPRESSED_ZLIB (0x1) 31 #define DUMP_DH_COMPRESSED_LZO (0x2) 32 #define DUMP_DH_COMPRESSED_SNAPPY (0x4) 33 34 #define KDUMP_SIGNATURE "KDUMP " 35 #define SIG_LEN (sizeof(KDUMP_SIGNATURE) - 1) 36 #define DUMP_LEVEL (1) 37 #define DISKDUMP_HEADER_BLOCKS (1) 38 39 #include "sysemu/dump-arch.h" 40 #include "sysemu/memory_mapping.h" 41 #include "qapi-types.h" 42 43 typedef struct QEMU_PACKED MakedumpfileHeader { 44 char signature[16]; /* = "makedumpfile" */ 45 int64_t type; 46 int64_t version; 47 } MakedumpfileHeader; 48 49 typedef struct QEMU_PACKED MakedumpfileDataHeader { 50 int64_t offset; 51 int64_t buf_size; 52 } MakedumpfileDataHeader; 53 54 typedef struct QEMU_PACKED NewUtsname { 55 char sysname[65]; 56 char nodename[65]; 57 char release[65]; 58 char version[65]; 59 char machine[65]; 60 char domainname[65]; 61 } NewUtsname; 62 63 typedef struct QEMU_PACKED DiskDumpHeader32 { 64 char signature[SIG_LEN]; /* = "KDUMP " */ 65 uint32_t header_version; /* Dump header version */ 66 NewUtsname utsname; /* copy of system_utsname */ 67 char timestamp[10]; /* Time stamp */ 68 uint32_t status; /* Above flags */ 69 uint32_t block_size; /* Size of a block in byte */ 70 uint32_t sub_hdr_size; /* Size of arch dependent header in block */ 71 uint32_t bitmap_blocks; /* Size of Memory bitmap in block */ 72 uint32_t max_mapnr; /* = max_mapnr , 73 obsoleted in header_version 6 */ 74 uint32_t total_ram_blocks; /* Number of blocks should be written */ 75 uint32_t device_blocks; /* Number of total blocks in dump device */ 76 uint32_t written_blocks; /* Number of written blocks */ 77 uint32_t current_cpu; /* CPU# which handles dump */ 78 uint32_t nr_cpus; /* Number of CPUs */ 79 } DiskDumpHeader32; 80 81 typedef struct QEMU_PACKED DiskDumpHeader64 { 82 char signature[SIG_LEN]; /* = "KDUMP " */ 83 uint32_t header_version; /* Dump header version */ 84 NewUtsname utsname; /* copy of system_utsname */ 85 char timestamp[22]; /* Time stamp */ 86 uint32_t status; /* Above flags */ 87 uint32_t block_size; /* Size of a block in byte */ 88 uint32_t sub_hdr_size; /* Size of arch dependent header in block */ 89 uint32_t bitmap_blocks; /* Size of Memory bitmap in block */ 90 uint32_t max_mapnr; /* = max_mapnr, 91 obsoleted in header_version 6 */ 92 uint32_t total_ram_blocks; /* Number of blocks should be written */ 93 uint32_t device_blocks; /* Number of total blocks in dump device */ 94 uint32_t written_blocks; /* Number of written blocks */ 95 uint32_t current_cpu; /* CPU# which handles dump */ 96 uint32_t nr_cpus; /* Number of CPUs */ 97 } DiskDumpHeader64; 98 99 typedef struct QEMU_PACKED KdumpSubHeader32 { 100 uint32_t phys_base; 101 uint32_t dump_level; /* header_version 1 and later */ 102 uint32_t split; /* header_version 2 and later */ 103 uint32_t start_pfn; /* header_version 2 and later, 104 obsoleted in header_version 6 */ 105 uint32_t end_pfn; /* header_version 2 and later, 106 obsoleted in header_version 6 */ 107 uint64_t offset_vmcoreinfo; /* header_version 3 and later */ 108 uint32_t size_vmcoreinfo; /* header_version 3 and later */ 109 uint64_t offset_note; /* header_version 4 and later */ 110 uint32_t note_size; /* header_version 4 and later */ 111 uint64_t offset_eraseinfo; /* header_version 5 and later */ 112 uint32_t size_eraseinfo; /* header_version 5 and later */ 113 uint64_t start_pfn_64; /* header_version 6 and later */ 114 uint64_t end_pfn_64; /* header_version 6 and later */ 115 uint64_t max_mapnr_64; /* header_version 6 and later */ 116 } KdumpSubHeader32; 117 118 typedef struct QEMU_PACKED KdumpSubHeader64 { 119 uint64_t phys_base; 120 uint32_t dump_level; /* header_version 1 and later */ 121 uint32_t split; /* header_version 2 and later */ 122 uint64_t start_pfn; /* header_version 2 and later, 123 obsoleted in header_version 6 */ 124 uint64_t end_pfn; /* header_version 2 and later, 125 obsoleted in header_version 6 */ 126 uint64_t offset_vmcoreinfo; /* header_version 3 and later */ 127 uint64_t size_vmcoreinfo; /* header_version 3 and later */ 128 uint64_t offset_note; /* header_version 4 and later */ 129 uint64_t note_size; /* header_version 4 and later */ 130 uint64_t offset_eraseinfo; /* header_version 5 and later */ 131 uint64_t size_eraseinfo; /* header_version 5 and later */ 132 uint64_t start_pfn_64; /* header_version 6 and later */ 133 uint64_t end_pfn_64; /* header_version 6 and later */ 134 uint64_t max_mapnr_64; /* header_version 6 and later */ 135 } KdumpSubHeader64; 136 137 typedef struct DataCache { 138 int fd; /* fd of the file where to write the cached data */ 139 uint8_t *buf; /* buffer for cached data */ 140 size_t buf_size; /* size of the buf */ 141 size_t data_size; /* size of cached data in buf */ 142 off_t offset; /* offset of the file */ 143 } DataCache; 144 145 typedef struct QEMU_PACKED PageDescriptor { 146 uint64_t offset; /* the offset of the page data*/ 147 uint32_t size; /* the size of this dump page */ 148 uint32_t flags; /* flags */ 149 uint64_t page_flags; /* page flags */ 150 } PageDescriptor; 151 152 typedef struct DumpState { 153 GuestPhysBlockList guest_phys_blocks; 154 ArchDumpInfo dump_info; 155 MemoryMappingList list; 156 uint16_t phdr_num; 157 uint32_t sh_info; 158 bool have_section; 159 bool resume; 160 bool detached; 161 ssize_t note_size; 162 hwaddr memory_offset; 163 int fd; 164 165 GuestPhysBlock *next_block; 166 ram_addr_t start; 167 bool has_filter; 168 int64_t begin; 169 int64_t length; 170 171 uint8_t *note_buf; /* buffer for notes */ 172 size_t note_buf_offset; /* the writing place in note_buf */ 173 uint32_t nr_cpus; /* number of guest's cpu */ 174 uint64_t max_mapnr; /* the biggest guest's phys-mem's number */ 175 size_t len_dump_bitmap; /* the size of the place used to store 176 dump_bitmap in vmcore */ 177 off_t offset_dump_bitmap; /* offset of dump_bitmap part in vmcore */ 178 off_t offset_page; /* offset of page part in vmcore */ 179 size_t num_dumpable; /* number of page that can be dumped */ 180 uint32_t flag_compress; /* indicate the compression format */ 181 DumpStatus status; /* current dump status */ 182 183 bool has_format; /* whether format is provided */ 184 DumpGuestMemoryFormat format; /* valid only if has_format == true */ 185 QemuThread dump_thread; /* thread for detached dump */ 186 187 int64_t total_size; /* total memory size (in bytes) to 188 * be dumped. When filter is 189 * enabled, this will only count 190 * those to be written. */ 191 int64_t written_size; /* written memory size (in bytes), 192 * this could be used to calculate 193 * how much work we have 194 * finished. */ 195 uint8_t *guest_note; /* ELF note content */ 196 size_t guest_note_size; 197 } DumpState; 198 199 uint16_t cpu_to_dump16(DumpState *s, uint16_t val); 200 uint32_t cpu_to_dump32(DumpState *s, uint32_t val); 201 uint64_t cpu_to_dump64(DumpState *s, uint64_t val); 202 #endif 203