|
|
5d360b |
From 888eb5bb28377bc392629e34133bf5bc50b0554f 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:49 +0100
|
|
|
5d360b |
Subject: [PATCH 18/41] dump: Propagate errors into qmp_dump_guest_memory()
|
|
|
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-19-marcandre.lureau@redhat.com>
|
|
|
5d360b |
Patchwork-id: 78367
|
|
|
5d360b |
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 18/41] dump: Propagate errors into qmp_dump_guest_memory()
|
|
|
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: zhanghailiang <zhang.zhanghailiang@huawei.com>
|
|
|
5d360b |
|
|
|
5d360b |
The code calls dump_error() on error, and even passes it a suitable
|
|
|
5d360b |
message. However, the message is thrown away, and its callers pass
|
|
|
5d360b |
up only success/failure. All qmp_dump_guest_memory() can do is set
|
|
|
5d360b |
a generic error.
|
|
|
5d360b |
|
|
|
5d360b |
Propagate the errors properly, so qmp_dump_guest_memory() can return
|
|
|
5d360b |
a more useful error.
|
|
|
5d360b |
|
|
|
5d360b |
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
|
|
|
5d360b |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
5d360b |
Reviewed-by: Markus Armbruster <armbru@redhat.com>
|
|
|
5d360b |
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
|
|
|
5d360b |
|
|
|
5d360b |
(cherry picked from commit 37917da2d071ab5273703f5169b0b2fefd40cbb5)
|
|
|
5d360b |
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
5d360b |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
5d360b |
---
|
|
|
5d360b |
dump.c | 165 ++++++++++++++++++++++++++++++++---------------------------------
|
|
|
5d360b |
1 file changed, 82 insertions(+), 83 deletions(-)
|
|
|
5d360b |
|
|
|
5d360b |
diff --git a/dump.c b/dump.c
|
|
|
5d360b |
index c709fc2..3718a79 100644
|
|
|
5d360b |
--- a/dump.c
|
|
|
5d360b |
+++ b/dump.c
|
|
|
5d360b |
@@ -81,9 +81,10 @@ static int dump_cleanup(DumpState *s)
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static void dump_error(DumpState *s, const char *reason)
|
|
|
5d360b |
+static void dump_error(DumpState *s, const char *reason, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
dump_cleanup(s);
|
|
|
5d360b |
+ error_setg(errp, "%s", reason);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
|
|
|
5d360b |
@@ -99,7 +100,7 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_elf64_header(DumpState *s)
|
|
|
5d360b |
+static int write_elf64_header(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
Elf64_Ehdr elf_header;
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
@@ -126,14 +127,14 @@ static int write_elf64_header(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write elf header.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write elf header", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_elf32_header(DumpState *s)
|
|
|
5d360b |
+static int write_elf32_header(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
Elf32_Ehdr elf_header;
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
@@ -160,7 +161,7 @@ static int write_elf32_header(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write elf header.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write elf header", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -169,7 +170,7 @@ static int write_elf32_header(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
|
|
|
5d360b |
int phdr_index, hwaddr offset,
|
|
|
5d360b |
- hwaddr filesz)
|
|
|
5d360b |
+ hwaddr filesz, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
Elf64_Phdr phdr;
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
@@ -186,7 +187,7 @@ static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
|
|
|
5d360b |
|
|
|
5d360b |
ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write program header table.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write program header table", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -195,7 +196,7 @@ static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
|
|
|
5d360b |
|
|
|
5d360b |
static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
|
|
|
5d360b |
int phdr_index, hwaddr offset,
|
|
|
5d360b |
- hwaddr filesz)
|
|
|
5d360b |
+ hwaddr filesz, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
Elf32_Phdr phdr;
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
@@ -212,14 +213,14 @@ static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
|
|
|
5d360b |
|
|
|
5d360b |
ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write program header table.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write program header table", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_elf64_note(DumpState *s)
|
|
|
5d360b |
+static int write_elf64_note(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
Elf64_Phdr phdr;
|
|
|
5d360b |
hwaddr begin = s->memory_offset - s->note_size;
|
|
|
5d360b |
@@ -235,7 +236,7 @@ static int write_elf64_note(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write program header table.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write program header table", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -247,7 +248,8 @@ static inline int cpu_index(CPUState *cpu)
|
|
|
5d360b |
return cpu->cpu_index + 1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s)
|
|
|
5d360b |
+static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
|
|
|
5d360b |
+ Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
CPUArchState *env;
|
|
|
5d360b |
CPUState *cpu;
|
|
|
5d360b |
@@ -259,7 +261,7 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s)
|
|
|
5d360b |
id = cpu_index(cpu);
|
|
|
5d360b |
ret = cpu_write_elf64_note(f, cpu, id, s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write elf notes.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write elf notes", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -268,7 +270,7 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s)
|
|
|
5d360b |
cpu = ENV_GET_CPU(env);
|
|
|
5d360b |
ret = cpu_write_elf64_qemunote(f, cpu, s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write CPU status.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write CPU status", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -276,7 +278,7 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s)
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_elf32_note(DumpState *s)
|
|
|
5d360b |
+static int write_elf32_note(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
hwaddr begin = s->memory_offset - s->note_size;
|
|
|
5d360b |
Elf32_Phdr phdr;
|
|
|
5d360b |
@@ -292,14 +294,15 @@ static int write_elf32_note(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write program header table.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write program header table", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s)
|
|
|
5d360b |
+static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
|
|
|
5d360b |
+ Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
CPUArchState *env;
|
|
|
5d360b |
CPUState *cpu;
|
|
|
5d360b |
@@ -311,7 +314,7 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s)
|
|
|
5d360b |
id = cpu_index(cpu);
|
|
|
5d360b |
ret = cpu_write_elf32_note(f, cpu, id, s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write elf notes.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write elf notes", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -320,7 +323,7 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s)
|
|
|
5d360b |
cpu = ENV_GET_CPU(env);
|
|
|
5d360b |
ret = cpu_write_elf32_qemunote(f, cpu, s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write CPU status.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write CPU status", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -328,7 +331,7 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s)
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_elf_section(DumpState *s, int type)
|
|
|
5d360b |
+static int write_elf_section(DumpState *s, int type, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
Elf32_Shdr shdr32;
|
|
|
5d360b |
Elf64_Shdr shdr64;
|
|
|
5d360b |
@@ -350,20 +353,20 @@ static int write_elf_section(DumpState *s, int type)
|
|
|
5d360b |
|
|
|
5d360b |
ret = fd_write_vmcore(&shdr, shdr_size, s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write section header table.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write section header table", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_data(DumpState *s, void *buf, int length)
|
|
|
5d360b |
+static int write_data(DumpState *s, void *buf, int length, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
|
|
|
5d360b |
ret = fd_write_vmcore(buf, length, s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to save memory.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to save memory", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -372,14 +375,14 @@ static int write_data(DumpState *s, void *buf, int length)
|
|
|
5d360b |
|
|
|
5d360b |
/* write the memroy to vmcore. 1 page per I/O. */
|
|
|
5d360b |
static int write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
|
|
|
5d360b |
- int64_t size)
|
|
|
5d360b |
+ int64_t size, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int64_t i;
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
|
|
|
5d360b |
for (i = 0; i < size / TARGET_PAGE_SIZE; i++) {
|
|
|
5d360b |
ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
|
|
|
5d360b |
- TARGET_PAGE_SIZE);
|
|
|
5d360b |
+ TARGET_PAGE_SIZE, errp);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
return ret;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -387,7 +390,7 @@ static int write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
|
|
|
5d360b |
|
|
|
5d360b |
if ((size % TARGET_PAGE_SIZE) != 0) {
|
|
|
5d360b |
ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
|
|
|
5d360b |
- size % TARGET_PAGE_SIZE);
|
|
|
5d360b |
+ size % TARGET_PAGE_SIZE, errp);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
return ret;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -458,7 +461,7 @@ static void get_offset_range(hwaddr phys_addr,
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_elf_loads(DumpState *s)
|
|
|
5d360b |
+static int write_elf_loads(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
hwaddr offset, filesz;
|
|
|
5d360b |
MemoryMapping *memory_mapping;
|
|
|
5d360b |
@@ -478,10 +481,10 @@ static int write_elf_loads(DumpState *s)
|
|
|
5d360b |
s, &offset, &filesz);
|
|
|
5d360b |
if (s->dump_info.d_class == ELFCLASS64) {
|
|
|
5d360b |
ret = write_elf64_load(s, memory_mapping, phdr_index++, offset,
|
|
|
5d360b |
- filesz);
|
|
|
5d360b |
+ filesz, errp);
|
|
|
5d360b |
} else {
|
|
|
5d360b |
ret = write_elf32_load(s, memory_mapping, phdr_index++, offset,
|
|
|
5d360b |
- filesz);
|
|
|
5d360b |
+ filesz, errp);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
@@ -497,7 +500,7 @@ static int write_elf_loads(DumpState *s)
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write elf header, PT_NOTE and elf note to vmcore. */
|
|
|
5d360b |
-static int dump_begin(DumpState *s)
|
|
|
5d360b |
+static int dump_begin(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
|
|
|
5d360b |
@@ -527,9 +530,9 @@ static int dump_begin(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
/* write elf header to vmcore */
|
|
|
5d360b |
if (s->dump_info.d_class == ELFCLASS64) {
|
|
|
5d360b |
- ret = write_elf64_header(s);
|
|
|
5d360b |
+ ret = write_elf64_header(s, errp);
|
|
|
5d360b |
} else {
|
|
|
5d360b |
- ret = write_elf32_header(s);
|
|
|
5d360b |
+ ret = write_elf32_header(s, errp);
|
|
|
5d360b |
}
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
@@ -537,47 +540,47 @@ static int dump_begin(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
if (s->dump_info.d_class == ELFCLASS64) {
|
|
|
5d360b |
/* write PT_NOTE to vmcore */
|
|
|
5d360b |
- if (write_elf64_note(s) < 0) {
|
|
|
5d360b |
+ if (write_elf64_note(s, errp) < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write all PT_LOAD to vmcore */
|
|
|
5d360b |
- if (write_elf_loads(s) < 0) {
|
|
|
5d360b |
+ if (write_elf_loads(s, errp) < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write section to vmcore */
|
|
|
5d360b |
if (s->have_section) {
|
|
|
5d360b |
- if (write_elf_section(s, 1) < 0) {
|
|
|
5d360b |
+ if (write_elf_section(s, 1, errp) < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write notes to vmcore */
|
|
|
5d360b |
- if (write_elf64_notes(fd_write_vmcore, s) < 0) {
|
|
|
5d360b |
+ if (write_elf64_notes(fd_write_vmcore, s, errp) < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
} else {
|
|
|
5d360b |
/* write PT_NOTE to vmcore */
|
|
|
5d360b |
- if (write_elf32_note(s) < 0) {
|
|
|
5d360b |
+ if (write_elf32_note(s, errp) < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write all PT_LOAD to vmcore */
|
|
|
5d360b |
- if (write_elf_loads(s) < 0) {
|
|
|
5d360b |
+ if (write_elf_loads(s, errp) < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write section to vmcore */
|
|
|
5d360b |
if (s->have_section) {
|
|
|
5d360b |
- if (write_elf_section(s, 0) < 0) {
|
|
|
5d360b |
+ if (write_elf_section(s, 0, errp) < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write notes to vmcore */
|
|
|
5d360b |
- if (write_elf32_notes(fd_write_vmcore, s) < 0) {
|
|
|
5d360b |
+ if (write_elf32_notes(fd_write_vmcore, s, errp) < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -620,7 +623,7 @@ static int get_next_block(DumpState *s, GuestPhysBlock *block)
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write all memory to vmcore */
|
|
|
5d360b |
-static int dump_iterate(DumpState *s)
|
|
|
5d360b |
+static int dump_iterate(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
GuestPhysBlock *block;
|
|
|
5d360b |
int64_t size;
|
|
|
5d360b |
@@ -636,7 +639,7 @@ static int dump_iterate(DumpState *s)
|
|
|
5d360b |
size -= block->target_end - (s->begin + s->length);
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
- ret = write_memory(s, block, s->start, size);
|
|
|
5d360b |
+ ret = write_memory(s, block, s->start, size, errp);
|
|
|
5d360b |
if (ret == -1) {
|
|
|
5d360b |
return ret;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -649,16 +652,16 @@ static int dump_iterate(DumpState *s)
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int create_vmcore(DumpState *s)
|
|
|
5d360b |
+static int create_vmcore(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
|
|
|
5d360b |
- ret = dump_begin(s);
|
|
|
5d360b |
+ ret = dump_begin(s, errp);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- ret = dump_iterate(s);
|
|
|
5d360b |
+ ret = dump_iterate(s, errp);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -744,7 +747,7 @@ static int buf_write_note(const void *buf, size_t size, void *opaque)
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write common header, sub header and elf note to vmcore */
|
|
|
5d360b |
-static int create_header32(DumpState *s)
|
|
|
5d360b |
+static int create_header32(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int ret = 0;
|
|
|
5d360b |
DiskDumpHeader32 *dh = NULL;
|
|
|
5d360b |
@@ -790,7 +793,7 @@ static int create_header32(DumpState *s)
|
|
|
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 |
+ dump_error(s, "dump: failed to write disk dump header", errp);
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -810,7 +813,7 @@ static int create_header32(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
|
|
|
5d360b |
block_size, kh, size) < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write kdump sub header.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write kdump sub header", errp);
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -820,14 +823,14 @@ static int create_header32(DumpState *s)
|
|
|
5d360b |
s->note_buf_offset = 0;
|
|
|
5d360b |
|
|
|
5d360b |
/* use s->note_buf to store notes temporarily */
|
|
|
5d360b |
- if (write_elf32_notes(buf_write_note, s) < 0) {
|
|
|
5d360b |
+ if (write_elf32_notes(buf_write_note, s, errp) < 0) {
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
if (write_buffer(s->fd, offset_note, s->note_buf,
|
|
|
5d360b |
s->note_size) < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write notes");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write notes", errp);
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -849,7 +852,7 @@ out:
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* write common header, sub header and elf note to vmcore */
|
|
|
5d360b |
-static int create_header64(DumpState *s)
|
|
|
5d360b |
+static int create_header64(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int ret = 0;
|
|
|
5d360b |
DiskDumpHeader64 *dh = NULL;
|
|
|
5d360b |
@@ -895,7 +898,7 @@ static int create_header64(DumpState *s)
|
|
|
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 |
+ dump_error(s, "dump: failed to write disk dump header", errp);
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -915,7 +918,7 @@ static int create_header64(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
|
|
|
5d360b |
block_size, kh, size) < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write kdump sub header.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write kdump sub header", errp);
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -925,14 +928,14 @@ static int create_header64(DumpState *s)
|
|
|
5d360b |
s->note_buf_offset = 0;
|
|
|
5d360b |
|
|
|
5d360b |
/* use s->note_buf to store notes temporarily */
|
|
|
5d360b |
- if (write_elf64_notes(buf_write_note, s) < 0) {
|
|
|
5d360b |
+ if (write_elf64_notes(buf_write_note, s, errp) < 0) {
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
if (write_buffer(s->fd, offset_note, s->note_buf,
|
|
|
5d360b |
s->note_size) < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write notes");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write notes", errp);
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -953,12 +956,12 @@ out:
|
|
|
5d360b |
return ret;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_dump_header(DumpState *s)
|
|
|
5d360b |
+static int write_dump_header(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
if (s->dump_info.d_class == ELFCLASS32) {
|
|
|
5d360b |
- return create_header32(s);
|
|
|
5d360b |
+ return create_header32(s, errp);
|
|
|
5d360b |
} else {
|
|
|
5d360b |
- return create_header64(s);
|
|
|
5d360b |
+ return create_header64(s, errp);
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -1072,7 +1075,7 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
|
|
|
5d360b |
return true;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_dump_bitmap(DumpState *s)
|
|
|
5d360b |
+static int write_dump_bitmap(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int ret = 0;
|
|
|
5d360b |
uint64_t last_pfn, pfn;
|
|
|
5d360b |
@@ -1093,7 +1096,7 @@ static int write_dump_bitmap(DumpState *s)
|
|
|
5d360b |
while (get_next_page(&block_iter, &pfn, NULL, s)) {
|
|
|
5d360b |
ret = set_dump_bitmap(last_pfn, pfn, true, dump_bitmap_buf, s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to set dump_bitmap.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to set dump_bitmap", errp);
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -1111,7 +1114,7 @@ static int write_dump_bitmap(DumpState *s)
|
|
|
5d360b |
ret = set_dump_bitmap(last_pfn, last_pfn + PFN_BUFBITMAP, false,
|
|
|
5d360b |
dump_bitmap_buf, s);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to sync dump_bitmap.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to sync dump_bitmap", errp);
|
|
|
5d360b |
ret = -1;
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -1203,7 +1206,7 @@ static inline bool is_zero_page(const uint8_t *buf, size_t page_size)
|
|
|
5d360b |
return buffer_is_zero(buf, page_size);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
+static int write_dump_pages(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int ret = 0;
|
|
|
5d360b |
DataCache page_desc, page_data;
|
|
|
5d360b |
@@ -1247,7 +1250,7 @@ static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
|
|
|
5d360b |
g_free(buf);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write page data(zero page).\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write page data (zero page)", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -1263,7 +1266,7 @@ static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
ret = write_cache(&page_desc, &pd_zero, sizeof(PageDescriptor),
|
|
|
5d360b |
false);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write page desc.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write page desc", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
} else {
|
|
|
5d360b |
@@ -1288,7 +1291,7 @@ static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = write_cache(&page_data, buf_out, size_out, false);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write page data.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write page data", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
#ifdef CONFIG_LZO
|
|
|
5d360b |
@@ -1301,7 +1304,7 @@ static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = write_cache(&page_data, buf_out, size_out, false);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write page data.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write page data", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
#endif
|
|
|
5d360b |
@@ -1315,7 +1318,7 @@ static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = write_cache(&page_data, buf_out, size_out, false);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write page data.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write page data", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
#endif
|
|
|
5d360b |
@@ -1330,7 +1333,7 @@ static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write page data.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write page data", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -1342,7 +1345,7 @@ static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = write_cache(&page_desc, &pd, sizeof(PageDescriptor), false);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write page desc.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write page desc", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -1350,12 +1353,12 @@ static int write_dump_pages(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = write_cache(&page_desc, NULL, 0, true);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to sync cache for page_desc.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to sync cache for page_desc", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
ret = write_cache(&page_data, NULL, 0, true);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to sync cache for page_data.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to sync cache for page_data", errp);
|
|
|
5d360b |
goto out;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -1372,7 +1375,7 @@ out:
|
|
|
5d360b |
return ret;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
-static int create_kdump_vmcore(DumpState *s)
|
|
|
5d360b |
+static int create_kdump_vmcore(DumpState *s, Error **errp)
|
|
|
5d360b |
{
|
|
|
5d360b |
int ret;
|
|
|
5d360b |
|
|
|
5d360b |
@@ -1400,28 +1403,28 @@ static int create_kdump_vmcore(DumpState *s)
|
|
|
5d360b |
|
|
|
5d360b |
ret = write_start_flat_header(s->fd);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write start flat header.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write start flat header", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- ret = write_dump_header(s);
|
|
|
5d360b |
+ ret = write_dump_header(s, errp);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- ret = write_dump_bitmap(s);
|
|
|
5d360b |
+ ret = write_dump_bitmap(s, errp);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- ret = write_dump_pages(s);
|
|
|
5d360b |
+ ret = write_dump_pages(s, errp);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
ret = write_end_flat_header(s->fd);
|
|
|
5d360b |
if (ret < 0) {
|
|
|
5d360b |
- dump_error(s, "dump: failed to write end flat header.\n");
|
|
|
5d360b |
+ dump_error(s, "dump: failed to write end flat header", errp);
|
|
|
5d360b |
return -1;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -1705,13 +1708,9 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
|
|
|
5d360b |
- if (create_kdump_vmcore(s) < 0) {
|
|
|
5d360b |
- error_set(errp, QERR_IO_ERROR);
|
|
|
5d360b |
- }
|
|
|
5d360b |
+ create_kdump_vmcore(s, errp);
|
|
|
5d360b |
} else {
|
|
|
5d360b |
- if (create_vmcore(s) < 0) {
|
|
|
5d360b |
- error_set(errp, QERR_IO_ERROR);
|
|
|
5d360b |
- }
|
|
|
5d360b |
+ create_vmcore(s, errp);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
g_free(s);
|
|
|
5d360b |
--
|
|
|
5d360b |
1.8.3.1
|
|
|
5d360b |
|