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 #define ARCH_PFN_OFFSET (0) 24 25 #define paddr_to_pfn(X) \ 26 (((unsigned long long)(X) >> TARGET_PAGE_BITS) - ARCH_PFN_OFFSET) 27 #define pfn_to_paddr(X) \ 28 (((unsigned long long)(X) + ARCH_PFN_OFFSET) << TARGET_PAGE_BITS) 29 30 /* 31 * flag for compressed format 32 */ 33 #define DUMP_DH_COMPRESSED_ZLIB (0x1) 34 #define DUMP_DH_COMPRESSED_LZO (0x2) 35 #define DUMP_DH_COMPRESSED_SNAPPY (0x4) 36 37 #define KDUMP_SIGNATURE "KDUMP " 38 #define SIG_LEN (sizeof(KDUMP_SIGNATURE) - 1) 39 #define PHYS_BASE (0) 40 #define DUMP_LEVEL (1) 41 #define DISKDUMP_HEADER_BLOCKS (1) 42 #define BUFSIZE_BITMAP (TARGET_PAGE_SIZE) 43 #define PFN_BUFBITMAP (CHAR_BIT * BUFSIZE_BITMAP) 44 #define BUFSIZE_DATA_CACHE (TARGET_PAGE_SIZE * 4) 45 46 #include "sysemu/dump-arch.h" 47 #include "sysemu/memory_mapping.h" 48 49 typedef struct QEMU_PACKED MakedumpfileHeader { 50 char signature[16]; /* = "makedumpfile" */ 51 int64_t type; 52 int64_t version; 53 } MakedumpfileHeader; 54 55 typedef struct QEMU_PACKED MakedumpfileDataHeader { 56 int64_t offset; 57 int64_t buf_size; 58 } MakedumpfileDataHeader; 59 60 typedef struct QEMU_PACKED NewUtsname { 61 char sysname[65]; 62 char nodename[65]; 63 char release[65]; 64 char version[65]; 65 char machine[65]; 66 char domainname[65]; 67 } NewUtsname; 68 69 typedef struct QEMU_PACKED DiskDumpHeader32 { 70 char signature[SIG_LEN]; /* = "KDUMP " */ 71 uint32_t header_version; /* Dump header version */ 72 NewUtsname utsname; /* copy of system_utsname */ 73 char timestamp[10]; /* Time stamp */ 74 uint32_t status; /* Above flags */ 75 uint32_t block_size; /* Size of a block in byte */ 76 uint32_t sub_hdr_size; /* Size of arch dependent header in block */ 77 uint32_t bitmap_blocks; /* Size of Memory bitmap in block */ 78 uint32_t max_mapnr; /* = max_mapnr , 79 obsoleted in header_version 6 */ 80 uint32_t total_ram_blocks; /* Number of blocks should be written */ 81 uint32_t device_blocks; /* Number of total blocks in dump device */ 82 uint32_t written_blocks; /* Number of written blocks */ 83 uint32_t current_cpu; /* CPU# which handles dump */ 84 uint32_t nr_cpus; /* Number of CPUs */ 85 } DiskDumpHeader32; 86 87 typedef struct QEMU_PACKED DiskDumpHeader64 { 88 char signature[SIG_LEN]; /* = "KDUMP " */ 89 uint32_t header_version; /* Dump header version */ 90 NewUtsname utsname; /* copy of system_utsname */ 91 char timestamp[22]; /* Time stamp */ 92 uint32_t status; /* Above flags */ 93 uint32_t block_size; /* Size of a block in byte */ 94 uint32_t sub_hdr_size; /* Size of arch dependent header in block */ 95 uint32_t bitmap_blocks; /* Size of Memory bitmap in block */ 96 uint32_t max_mapnr; /* = max_mapnr, 97 obsoleted in header_version 6 */ 98 uint32_t total_ram_blocks; /* Number of blocks should be written */ 99 uint32_t device_blocks; /* Number of total blocks in dump device */ 100 uint32_t written_blocks; /* Number of written blocks */ 101 uint32_t current_cpu; /* CPU# which handles dump */ 102 uint32_t nr_cpus; /* Number of CPUs */ 103 } DiskDumpHeader64; 104 105 typedef struct QEMU_PACKED KdumpSubHeader32 { 106 uint32_t phys_base; 107 uint32_t dump_level; /* header_version 1 and later */ 108 uint32_t split; /* header_version 2 and later */ 109 uint32_t start_pfn; /* header_version 2 and later, 110 obsoleted in header_version 6 */ 111 uint32_t end_pfn; /* header_version 2 and later, 112 obsoleted in header_version 6 */ 113 uint64_t offset_vmcoreinfo; /* header_version 3 and later */ 114 uint32_t size_vmcoreinfo; /* header_version 3 and later */ 115 uint64_t offset_note; /* header_version 4 and later */ 116 uint32_t note_size; /* header_version 4 and later */ 117 uint64_t offset_eraseinfo; /* header_version 5 and later */ 118 uint32_t size_eraseinfo; /* header_version 5 and later */ 119 uint64_t start_pfn_64; /* header_version 6 and later */ 120 uint64_t end_pfn_64; /* header_version 6 and later */ 121 uint64_t max_mapnr_64; /* header_version 6 and later */ 122 } KdumpSubHeader32; 123 124 typedef struct QEMU_PACKED KdumpSubHeader64 { 125 uint64_t phys_base; 126 uint32_t dump_level; /* header_version 1 and later */ 127 uint32_t split; /* header_version 2 and later */ 128 uint64_t start_pfn; /* header_version 2 and later, 129 obsoleted in header_version 6 */ 130 uint64_t end_pfn; /* header_version 2 and later, 131 obsoleted in header_version 6 */ 132 uint64_t offset_vmcoreinfo; /* header_version 3 and later */ 133 uint64_t size_vmcoreinfo; /* header_version 3 and later */ 134 uint64_t offset_note; /* header_version 4 and later */ 135 uint64_t note_size; /* header_version 4 and later */ 136 uint64_t offset_eraseinfo; /* header_version 5 and later */ 137 uint64_t size_eraseinfo; /* header_version 5 and later */ 138 uint64_t start_pfn_64; /* header_version 6 and later */ 139 uint64_t end_pfn_64; /* header_version 6 and later */ 140 uint64_t max_mapnr_64; /* header_version 6 and later */ 141 } KdumpSubHeader64; 142 143 typedef struct DataCache { 144 int fd; /* fd of the file where to write the cached data */ 145 uint8_t *buf; /* buffer for cached data */ 146 size_t buf_size; /* size of the buf */ 147 size_t data_size; /* size of cached data in buf */ 148 off_t offset; /* offset of the file */ 149 } DataCache; 150 151 typedef struct QEMU_PACKED PageDescriptor { 152 uint64_t offset; /* the offset of the page data*/ 153 uint32_t size; /* the size of this dump page */ 154 uint32_t flags; /* flags */ 155 uint64_t page_flags; /* page flags */ 156 } PageDescriptor; 157 158 typedef struct DumpState { 159 GuestPhysBlockList guest_phys_blocks; 160 ArchDumpInfo dump_info; 161 MemoryMappingList list; 162 uint16_t phdr_num; 163 uint32_t sh_info; 164 bool have_section; 165 bool resume; 166 ssize_t note_size; 167 hwaddr memory_offset; 168 int fd; 169 170 GuestPhysBlock *next_block; 171 ram_addr_t start; 172 bool has_filter; 173 int64_t begin; 174 int64_t length; 175 176 uint8_t *note_buf; /* buffer for notes */ 177 size_t note_buf_offset; /* the writing place in note_buf */ 178 uint32_t nr_cpus; /* number of guest's cpu */ 179 uint64_t max_mapnr; /* the biggest guest's phys-mem's number */ 180 size_t len_dump_bitmap; /* the size of the place used to store 181 dump_bitmap in vmcore */ 182 off_t offset_dump_bitmap; /* offset of dump_bitmap part in vmcore */ 183 off_t offset_page; /* offset of page part in vmcore */ 184 size_t num_dumpable; /* number of page that can be dumped */ 185 uint32_t flag_compress; /* indicate the compression format */ 186 } DumpState; 187 188 uint16_t cpu_to_dump16(DumpState *s, uint16_t val); 189 uint32_t cpu_to_dump32(DumpState *s, uint32_t val); 190 uint64_t cpu_to_dump64(DumpState *s, uint64_t val); 191 #endif 192