summaryrefslogtreecommitdiffstats
path: root/include/sysemu/dump.h
blob: 2672a15f8ba4056085a8e8a54213ebfd7689b44c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
 * QEMU dump
 *
 * Copyright Fujitsu, Corp. 2011, 2012
 *
 * Authors:
 *     Wen Congyang <wency@cn.fujitsu.com>
 *
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 * See the COPYING file in the top-level directory.
 *
 */

#ifndef DUMP_H
#define DUMP_H

#define MAKEDUMPFILE_SIGNATURE      "makedumpfile"
#define MAX_SIZE_MDF_HEADER         (4096) /* max size of makedumpfile_header */
#define TYPE_FLAT_HEADER            (1)    /* type of flattened format */
#define VERSION_FLAT_HEADER         (1)    /* version of flattened format */
#define END_FLAG_FLAT_HEADER        (-1)

#ifndef ARCH_PFN_OFFSET
#define ARCH_PFN_OFFSET             (0)
#endif

/*
 * flag for compressed format
 */
#define DUMP_DH_COMPRESSED_ZLIB     (0x1)
#define DUMP_DH_COMPRESSED_LZO      (0x2)
#define DUMP_DH_COMPRESSED_SNAPPY   (0x4)

#define KDUMP_SIGNATURE             "KDUMP   "
#define SIG_LEN                     (sizeof(KDUMP_SIGNATURE) - 1)
#define DUMP_LEVEL                  (1)
#define DISKDUMP_HEADER_BLOCKS      (1)

#include "sysemu/dump-arch.h"
#include "sysemu/memory_mapping.h"
#include "qapi-types.h"

typedef struct QEMU_PACKED MakedumpfileHeader {
    char signature[16];     /* = "makedumpfile" */
    int64_t type;
    int64_t version;
} MakedumpfileHeader;

typedef struct QEMU_PACKED MakedumpfileDataHeader {
    int64_t offset;
    int64_t buf_size;
} MakedumpfileDataHeader;

typedef struct QEMU_PACKED NewUtsname {
    char sysname[65];
    char nodename[65];
    char release[65];
    char version[65];
    char machine[65];
    char domainname[65];
} NewUtsname;

typedef struct QEMU_PACKED DiskDumpHeader32 {
    char signature[SIG_LEN];        /* = "KDUMP   " */
    uint32_t header_version;        /* Dump header version */
    NewUtsname utsname;             /* copy of system_utsname */
    char timestamp[10];             /* Time stamp */
    uint32_t status;                /* Above flags */
    uint32_t block_size;            /* Size of a block in byte */
    uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
    uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
    uint32_t max_mapnr;             /* = max_mapnr ,
                                       obsoleted in header_version 6 */
    uint32_t total_ram_blocks;      /* Number of blocks should be written */
    uint32_t device_blocks;         /* Number of total blocks in dump device */
    uint32_t written_blocks;        /* Number of written blocks */
    uint32_t current_cpu;           /* CPU# which handles dump */
    uint32_t nr_cpus;               /* Number of CPUs */
} DiskDumpHeader32;

typedef struct QEMU_PACKED DiskDumpHeader64 {
    char signature[SIG_LEN];        /* = "KDUMP   " */
    uint32_t header_version;        /* Dump header version */
    NewUtsname utsname;             /* copy of system_utsname */
    char timestamp[22];             /* Time stamp */
    uint32_t status;                /* Above flags */
    uint32_t block_size;            /* Size of a block in byte */
    uint32_t sub_hdr_size;          /* Size of arch dependent header in block */
    uint32_t bitmap_blocks;         /* Size of Memory bitmap in block */
    uint32_t max_mapnr;             /* = max_mapnr,
                                       obsoleted in header_version 6 */
    uint32_t total_ram_blocks;      /* Number of blocks should be written */
    uint32_t device_blocks;         /* Number of total blocks in dump device */
    uint32_t written_blocks;        /* Number of written blocks */
    uint32_t current_cpu;           /* CPU# which handles dump */
    uint32_t nr_cpus;               /* Number of CPUs */
} DiskDumpHeader64;

typedef struct QEMU_PACKED KdumpSubHeader32 {
    uint32_t phys_base;
    uint32_t dump_level;            /* header_version 1 and later */
    uint32_t split;                 /* header_version 2 and later */
    uint32_t start_pfn;             /* header_version 2 and later,
                                       obsoleted in header_version 6 */
    uint32_t end_pfn;               /* header_version 2 and later,
                                       obsoleted in header_version 6 */
    uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
    uint32_t size_vmcoreinfo;       /* header_version 3 and later */
    uint64_t offset_note;           /* header_version 4 and later */
    uint32_t note_size;             /* header_version 4 and later */
    uint64_t offset_eraseinfo;      /* header_version 5 and later */
    uint32_t size_eraseinfo;        /* header_version 5 and later */
    uint64_t start_pfn_64;          /* header_version 6 and later */
    uint64_t end_pfn_64;            /* header_version 6 and later */
    uint64_t max_mapnr_64;          /* header_version 6 and later */
} KdumpSubHeader32;

typedef struct QEMU_PACKED KdumpSubHeader64 {
    uint64_t phys_base;
    uint32_t dump_level;            /* header_version 1 and later */
    uint32_t split;                 /* header_version 2 and later */
    uint64_t start_pfn;             /* header_version 2 and later,
                                       obsoleted in header_version 6 */
    uint64_t end_pfn;               /* header_version 2 and later,
                                       obsoleted in header_version 6 */
    uint64_t offset_vmcoreinfo;     /* header_version 3 and later */
    uint64_t size_vmcoreinfo;       /* header_version 3 and later */
    uint64_t offset_note;           /* header_version 4 and later */
    uint64_t note_size;             /* header_version 4 and later */
    uint64_t offset_eraseinfo;      /* header_version 5 and later */
    uint64_t size_eraseinfo;        /* header_version 5 and later */
    uint64_t start_pfn_64;          /* header_version 6 and later */
    uint64_t end_pfn_64;            /* header_version 6 and later */
    uint64_t max_mapnr_64;          /* header_version 6 and later */
} KdumpSubHeader64;

typedef struct DataCache {
    int fd;             /* fd of the file where to write the cached data */
    uint8_t *buf;       /* buffer for cached data */
    size_t buf_size;    /* size of the buf */
    size_t data_size;   /* size of cached data in buf */
    off_t offset;       /* offset of the file */
} DataCache;

typedef struct QEMU_PACKED PageDescriptor {
    uint64_t offset;                /* the offset of the page data*/
    uint32_t size;                  /* the size of this dump page */
    uint32_t flags;                 /* flags */
    uint64_t page_flags;            /* page flags */
} PageDescriptor;

typedef struct DumpState {
    GuestPhysBlockList guest_phys_blocks;
    ArchDumpInfo dump_info;
    MemoryMappingList list;
    uint16_t phdr_num;
    uint32_t sh_info;
    bool have_section;
    bool resume;
    bool detached;
    ssize_t note_size;
    hwaddr memory_offset;
    int fd;

    GuestPhysBlock *next_block;
    ram_addr_t start;
    bool has_filter;
    int64_t begin;
    int64_t length;

    uint8_t *note_buf;          /* buffer for notes */
    size_t note_buf_offset;     /* the writing place in note_buf */
    uint32_t nr_cpus;           /* number of guest's cpu */
    uint64_t max_mapnr;         /* the biggest guest's phys-mem's number */
    size_t len_dump_bitmap;     /* the size of the place used to store
                                   dump_bitmap in vmcore */
    off_t offset_dump_bitmap;   /* offset of dump_bitmap part in vmcore */
    off_t offset_page;          /* offset of page part in vmcore */
    size_t num_dumpable;        /* number of page that can be dumped */
    uint32_t flag_compress;     /* indicate the compression format */
    DumpStatus status;          /* current dump status */

    bool has_format;              /* whether format is provided */
    DumpGuestMemoryFormat format; /* valid only if has_format == true */
    QemuThread dump_thread;       /* thread for detached dump */

    int64_t total_size;          /* total memory size (in bytes) to
                                  * be dumped. When filter is
                                  * enabled, this will only count
                                  * those to be written. */
    int64_t written_size;        /* written memory size (in bytes),
                                  * this could be used to calculate
                                  * how much work we have
                                  * finished. */
} DumpState;

uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
uint32_t cpu_to_dump32(DumpState *s, uint32_t val);
uint64_t cpu_to_dump64(DumpState *s, uint64_t val);
#endif