return 0;
}
-static int write_elf64_header(DumpState *s, Error **errp)
+static void write_elf64_header(DumpState *s, Error **errp)
{
Elf64_Ehdr elf_header;
int ret;
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
if (ret < 0) {
dump_error(s, "dump: failed to write elf header", errp);
- return -1;
}
-
- return 0;
}
-static int write_elf32_header(DumpState *s, Error **errp)
+static void write_elf32_header(DumpState *s, Error **errp)
{
Elf32_Ehdr elf_header;
int ret;
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
if (ret < 0) {
dump_error(s, "dump: failed to write elf header", errp);
- return -1;
}
-
- return 0;
}
-static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
- int phdr_index, hwaddr offset,
- hwaddr filesz, Error **errp)
+static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
+ int phdr_index, hwaddr offset,
+ hwaddr filesz, Error **errp)
{
Elf64_Phdr phdr;
int ret;
ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
if (ret < 0) {
dump_error(s, "dump: failed to write program header table", errp);
- return -1;
}
-
- return 0;
}
-static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
- int phdr_index, hwaddr offset,
- hwaddr filesz, Error **errp)
+static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
+ int phdr_index, hwaddr offset,
+ hwaddr filesz, Error **errp)
{
Elf32_Phdr phdr;
int ret;
ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
if (ret < 0) {
dump_error(s, "dump: failed to write program header table", errp);
- return -1;
}
-
- return 0;
}
-static int write_elf64_note(DumpState *s, Error **errp)
+static void write_elf64_note(DumpState *s, Error **errp)
{
Elf64_Phdr phdr;
hwaddr begin = s->memory_offset - s->note_size;
ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
if (ret < 0) {
dump_error(s, "dump: failed to write program header table", errp);
- return -1;
}
-
- return 0;
}
static inline int cpu_index(CPUState *cpu)
return cpu->cpu_index + 1;
}
-static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
- Error **errp)
+static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
+ Error **errp)
{
CPUState *cpu;
int ret;
ret = cpu_write_elf64_note(f, cpu, id, s);
if (ret < 0) {
dump_error(s, "dump: failed to write elf notes", errp);
- return -1;
+ return;
}
}
ret = cpu_write_elf64_qemunote(f, cpu, s);
if (ret < 0) {
dump_error(s, "dump: failed to write CPU status", errp);
- return -1;
+ return;
}
}
-
- return 0;
}
-static int write_elf32_note(DumpState *s, Error **errp)
+static void write_elf32_note(DumpState *s, Error **errp)
{
hwaddr begin = s->memory_offset - s->note_size;
Elf32_Phdr phdr;
ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
if (ret < 0) {
dump_error(s, "dump: failed to write program header table", errp);
- return -1;
}
-
- return 0;
}
-static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
- Error **errp)
+static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
+ Error **errp)
{
CPUState *cpu;
int ret;
ret = cpu_write_elf32_note(f, cpu, id, s);
if (ret < 0) {
dump_error(s, "dump: failed to write elf notes", errp);
- return -1;
+ return;
}
}
ret = cpu_write_elf32_qemunote(f, cpu, s);
if (ret < 0) {
dump_error(s, "dump: failed to write CPU status", errp);
- return -1;
+ return;
}
}
-
- return 0;
}
-static int write_elf_section(DumpState *s, int type, Error **errp)
+static void write_elf_section(DumpState *s, int type, Error **errp)
{
Elf32_Shdr shdr32;
Elf64_Shdr shdr64;
ret = fd_write_vmcore(&shdr, shdr_size, s);
if (ret < 0) {
dump_error(s, "dump: failed to write section header table", errp);
- return -1;
}
-
- return 0;
}
-static int write_data(DumpState *s, void *buf, int length, Error **errp)
+static void write_data(DumpState *s, void *buf, int length, Error **errp)
{
int ret;
ret = fd_write_vmcore(buf, length, s);
if (ret < 0) {
dump_error(s, "dump: failed to save memory", errp);
- return -1;
}
-
- return 0;
}
-/* write the memroy to vmcore. 1 page per I/O. */
-static int write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
- int64_t size, Error **errp)
+/* write the memory to vmcore. 1 page per I/O. */
+static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
+ int64_t size, Error **errp)
{
int64_t i;
- int ret;
+ Error *local_err = NULL;
for (i = 0; i < size / TARGET_PAGE_SIZE; i++) {
- ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
- TARGET_PAGE_SIZE, errp);
- if (ret < 0) {
- return ret;
+ write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
+ TARGET_PAGE_SIZE, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
}
if ((size % TARGET_PAGE_SIZE) != 0) {
- ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
- size % TARGET_PAGE_SIZE, errp);
- if (ret < 0) {
- return ret;
+ write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
+ size % TARGET_PAGE_SIZE, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
}
-
- return 0;
}
/* get the memory's offset and size in the vmcore */
}
}
-static int write_elf_loads(DumpState *s, Error **errp)
+static void write_elf_loads(DumpState *s, Error **errp)
{
hwaddr offset, filesz;
MemoryMapping *memory_mapping;
uint32_t phdr_index = 1;
- int ret;
uint32_t max_index;
+ Error *local_err = NULL;
if (s->have_section) {
max_index = s->sh_info;
memory_mapping->length,
s, &offset, &filesz);
if (s->dump_info.d_class == ELFCLASS64) {
- ret = write_elf64_load(s, memory_mapping, phdr_index++, offset,
- filesz, errp);
+ write_elf64_load(s, memory_mapping, phdr_index++, offset,
+ filesz, &local_err);
} else {
- ret = write_elf32_load(s, memory_mapping, phdr_index++, offset,
- filesz, errp);
+ write_elf32_load(s, memory_mapping, phdr_index++, offset,
+ filesz, &local_err);
}
- if (ret < 0) {
- return -1;
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
if (phdr_index >= max_index) {
break;
}
}
-
- return 0;
}
/* write elf header, PT_NOTE and elf note to vmcore. */
-static int dump_begin(DumpState *s, Error **errp)
+static void dump_begin(DumpState *s, Error **errp)
{
- int ret;
+ Error *local_err = NULL;
/*
* the vmcore's format is:
/* write elf header to vmcore */
if (s->dump_info.d_class == ELFCLASS64) {
- ret = write_elf64_header(s, errp);
+ write_elf64_header(s, &local_err);
} else {
- ret = write_elf32_header(s, errp);
+ write_elf32_header(s, &local_err);
}
- if (ret < 0) {
- return -1;
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
if (s->dump_info.d_class == ELFCLASS64) {
/* write PT_NOTE to vmcore */
- if (write_elf64_note(s, errp) < 0) {
- return -1;
+ write_elf64_note(s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
/* write all PT_LOAD to vmcore */
- if (write_elf_loads(s, errp) < 0) {
- return -1;
+ write_elf_loads(s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
/* write section to vmcore */
if (s->have_section) {
- if (write_elf_section(s, 1, errp) < 0) {
- return -1;
+ write_elf_section(s, 1, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
}
/* write notes to vmcore */
- if (write_elf64_notes(fd_write_vmcore, s, errp) < 0) {
- return -1;
+ write_elf64_notes(fd_write_vmcore, s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
-
} else {
/* write PT_NOTE to vmcore */
- if (write_elf32_note(s, errp) < 0) {
- return -1;
+ write_elf32_note(s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
/* write all PT_LOAD to vmcore */
- if (write_elf_loads(s, errp) < 0) {
- return -1;
+ write_elf_loads(s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
/* write section to vmcore */
if (s->have_section) {
- if (write_elf_section(s, 0, errp) < 0) {
- return -1;
+ write_elf_section(s, 0, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
}
/* write notes to vmcore */
- if (write_elf32_notes(fd_write_vmcore, s, errp) < 0) {
- return -1;
+ write_elf32_notes(fd_write_vmcore, s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
}
-
- return 0;
}
-/* write PT_LOAD to vmcore */
-static int dump_completed(DumpState *s)
+static void dump_completed(DumpState *s)
{
dump_cleanup(s);
- return 0;
}
static int get_next_block(DumpState *s, GuestPhysBlock *block)
}
/* write all memory to vmcore */
-static int dump_iterate(DumpState *s, Error **errp)
+static void dump_iterate(DumpState *s, Error **errp)
{
GuestPhysBlock *block;
int64_t size;
int ret;
+ Error *local_err = NULL;
while (1) {
block = s->next_block;
size -= block->target_end - (s->begin + s->length);
}
}
- ret = write_memory(s, block, s->start, size, errp);
- if (ret == -1) {
- return ret;
+ write_memory(s, block, s->start, size, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
ret = get_next_block(s, block);
if (ret == 1) {
dump_completed(s);
- return 0;
}
}
}
-static int create_vmcore(DumpState *s, Error **errp)
+static void create_vmcore(DumpState *s, Error **errp)
{
- int ret;
+ Error *local_err = NULL;
- ret = dump_begin(s, errp);
- if (ret < 0) {
- return -1;
- }
-
- ret = dump_iterate(s, errp);
- if (ret < 0) {
- return -1;
+ dump_begin(s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
- return 0;
+ dump_iterate(s, errp);
}
static int write_start_flat_header(int fd)
}
/* write common header, sub header and elf note to vmcore */
-static int create_header32(DumpState *s, Error **errp)
+static void create_header32(DumpState *s, Error **errp)
{
- int ret = 0;
DiskDumpHeader32 *dh = NULL;
KdumpSubHeader32 *kh = NULL;
size_t size;
uint32_t bitmap_blocks;
uint32_t status = 0;
uint64_t offset_note;
+ Error *local_err = NULL;
/* write common header, the version of kdump-compressed format is 6th */
size = sizeof(DiskDumpHeader32);
if (write_buffer(s->fd, 0, dh, size) < 0) {
dump_error(s, "dump: failed to write disk dump header", errp);
- ret = -1;
goto out;
}
if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
block_size, kh, size) < 0) {
dump_error(s, "dump: failed to write kdump sub header", errp);
- ret = -1;
goto out;
}
s->note_buf_offset = 0;
/* use s->note_buf to store notes temporarily */
- if (write_elf32_notes(buf_write_note, s, errp) < 0) {
- ret = -1;
+ write_elf32_notes(buf_write_note, s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
goto out;
}
-
if (write_buffer(s->fd, offset_note, s->note_buf,
s->note_size) < 0) {
dump_error(s, "dump: failed to write notes", errp);
- ret = -1;
goto out;
}
g_free(dh);
g_free(kh);
g_free(s->note_buf);
-
- return ret;
}
/* write common header, sub header and elf note to vmcore */
-static int create_header64(DumpState *s, Error **errp)
+static void create_header64(DumpState *s, Error **errp)
{
- int ret = 0;
DiskDumpHeader64 *dh = NULL;
KdumpSubHeader64 *kh = NULL;
size_t size;
uint32_t bitmap_blocks;
uint32_t status = 0;
uint64_t offset_note;
+ Error *local_err = NULL;
/* write common header, the version of kdump-compressed format is 6th */
size = sizeof(DiskDumpHeader64);
if (write_buffer(s->fd, 0, dh, size) < 0) {
dump_error(s, "dump: failed to write disk dump header", errp);
- ret = -1;
goto out;
}
if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
block_size, kh, size) < 0) {
dump_error(s, "dump: failed to write kdump sub header", errp);
- ret = -1;
goto out;
}
s->note_buf_offset = 0;
/* use s->note_buf to store notes temporarily */
- if (write_elf64_notes(buf_write_note, s, errp) < 0) {
- ret = -1;
+ write_elf64_notes(buf_write_note, s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
goto out;
}
if (write_buffer(s->fd, offset_note, s->note_buf,
s->note_size) < 0) {
dump_error(s, "dump: failed to write notes", errp);
- ret = -1;
goto out;
}
g_free(dh);
g_free(kh);
g_free(s->note_buf);
-
- return ret;
}
-static int write_dump_header(DumpState *s, Error **errp)
+static void write_dump_header(DumpState *s, Error **errp)
{
+ Error *local_err = NULL;
+
if (s->dump_info.d_class == ELFCLASS32) {
- return create_header32(s, errp);
+ create_header32(s, &local_err);
} else {
- return create_header64(s, errp);
+ create_header64(s, &local_err);
+ }
+ if (local_err) {
+ error_propagate(errp, local_err);
}
}
return true;
}
-static int write_dump_bitmap(DumpState *s, Error **errp)
+static void write_dump_bitmap(DumpState *s, Error **errp)
{
int ret = 0;
uint64_t last_pfn, pfn;
ret = set_dump_bitmap(last_pfn, pfn, true, dump_bitmap_buf, s);
if (ret < 0) {
dump_error(s, "dump: failed to set dump_bitmap", errp);
- ret = -1;
goto out;
}
dump_bitmap_buf, s);
if (ret < 0) {
dump_error(s, "dump: failed to sync dump_bitmap", errp);
- ret = -1;
goto out;
}
}
out:
g_free(dump_bitmap_buf);
-
- return ret;
}
static void prepare_data_cache(DataCache *data_cache, DumpState *s,
return buffer_is_zero(buf, page_size);
}
-static int write_dump_pages(DumpState *s, Error **errp)
+static void write_dump_pages(DumpState *s, Error **errp)
{
int ret = 0;
DataCache page_desc, page_data;
#endif
g_free(buf_out);
-
- return ret;
}
-static int create_kdump_vmcore(DumpState *s, Error **errp)
+static void create_kdump_vmcore(DumpState *s, Error **errp)
{
int ret;
+ Error *local_err = NULL;
/*
* the kdump-compressed format is:
ret = write_start_flat_header(s->fd);
if (ret < 0) {
dump_error(s, "dump: failed to write start flat header", errp);
- return -1;
+ return;
}
- ret = write_dump_header(s, errp);
- if (ret < 0) {
- return -1;
+ write_dump_header(s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
- ret = write_dump_bitmap(s, errp);
- if (ret < 0) {
- return -1;
+ write_dump_bitmap(s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
- ret = write_dump_pages(s, errp);
- if (ret < 0) {
- return -1;
+ write_dump_pages(s, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
}
ret = write_end_flat_header(s->fd);
if (ret < 0) {
dump_error(s, "dump: failed to write end flat header", errp);
- return -1;
+ return;
}
dump_completed(s);
-
- return 0;
}
static ram_addr_t get_start_block(DumpState *s)
s->max_mapnr = paddr_to_pfn(last_block->target_end);
}
-static int dump_init(DumpState *s, int fd, bool has_format,
- DumpGuestMemoryFormat format, bool paging, bool has_filter,
- int64_t begin, int64_t length, Error **errp)
+static void dump_init(DumpState *s, int fd, bool has_format,
+ DumpGuestMemoryFormat format, bool paging, bool has_filter,
+ int64_t begin, int64_t length, Error **errp)
{
CPUState *cpu;
int nr_cpus;
s->flag_compress = 0;
}
- return 0;
+ return;
}
if (s->has_filter) {
}
}
- return 0;
+ return;
cleanup:
dump_cleanup(s);
- return -1;
}
void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
const char *p;
int fd = -1;
DumpState *s;
- int ret;
+ Error *local_err = NULL;
/*
* kdump-compressed format need the whole memory dumped, so paging or
s = g_malloc0(sizeof(DumpState));
- ret = dump_init(s, fd, has_format, format, paging, has_begin,
- begin, length, errp);
- if (ret < 0) {
+ dump_init(s, fd, has_format, format, paging, has_begin,
+ begin, length, &local_err);
+ if (local_err) {
g_free(s);
+ error_propagate(errp, local_err);
return;
}