yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-dump-Turn-some-functions-to-void-to-make-code-cleane.patch

5d360b
From 4a4865cb64b429fc95d4466be707c812c7f3ee06 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:50 +0100
5d360b
Subject: [PATCH 19/41] dump: Turn some functions to void to make code cleaner
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-20-marcandre.lureau@redhat.com>
5d360b
Patchwork-id: 78368
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 19/41] dump: Turn some functions to void to make code cleaner
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
Functions shouldn't return an error code and an Error object at the same time.
5d360b
Turn all these functions that returning Error object to void.
5d360b
We also judge if a function success or fail by reference to the local_err.
5d360b
5d360b
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
5d360b
Reviewed-by: Eric Blake <eblake@redhat.com>
5d360b
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
5d360b
5d360b
(cherry picked from commit 4c7e251ae6d9c328850d62d8aeafa14ca600c858)
5d360b
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 dump.c | 312 ++++++++++++++++++++++++++++++-----------------------------------
5d360b
 1 file changed, 142 insertions(+), 170 deletions(-)
5d360b
5d360b
diff --git a/dump.c b/dump.c
5d360b
index 3718a79..099346a 100644
5d360b
--- a/dump.c
5d360b
+++ b/dump.c
5d360b
@@ -100,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, Error **errp)
5d360b
+static void write_elf64_header(DumpState *s, Error **errp)
5d360b
 {
5d360b
     Elf64_Ehdr elf_header;
5d360b
     int ret;
5d360b
@@ -128,13 +128,10 @@ static int write_elf64_header(DumpState *s, Error **errp)
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", errp);
5d360b
-        return -1;
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
-static int write_elf32_header(DumpState *s, Error **errp)
5d360b
+static void write_elf32_header(DumpState *s, Error **errp)
5d360b
 {
5d360b
     Elf32_Ehdr elf_header;
5d360b
     int ret;
5d360b
@@ -162,15 +159,12 @@ static int write_elf32_header(DumpState *s, Error **errp)
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", errp);
5d360b
-        return -1;
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
-static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
5d360b
-                            int phdr_index, hwaddr offset,
5d360b
-                            hwaddr filesz, Error **errp)
5d360b
+static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
5d360b
+                             int phdr_index, hwaddr offset,
5d360b
+                             hwaddr filesz, Error **errp)
5d360b
 {
5d360b
     Elf64_Phdr phdr;
5d360b
     int ret;
5d360b
@@ -188,15 +182,12 @@ static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
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", errp);
5d360b
-        return -1;
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
-static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
5d360b
-                            int phdr_index, hwaddr offset,
5d360b
-                            hwaddr filesz, Error **errp)
5d360b
+static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
5d360b
+                             int phdr_index, hwaddr offset,
5d360b
+                             hwaddr filesz, Error **errp)
5d360b
 {
5d360b
     Elf32_Phdr phdr;
5d360b
     int ret;
5d360b
@@ -214,13 +205,10 @@ static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
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", errp);
5d360b
-        return -1;
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
-static int write_elf64_note(DumpState *s, Error **errp)
5d360b
+static void write_elf64_note(DumpState *s, Error **errp)
5d360b
 {
5d360b
     Elf64_Phdr phdr;
5d360b
     hwaddr begin = s->memory_offset - s->note_size;
5d360b
@@ -237,10 +225,7 @@ static int write_elf64_note(DumpState *s, Error **errp)
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", errp);
5d360b
-        return -1;
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
 static inline int cpu_index(CPUState *cpu)
5d360b
@@ -248,8 +233,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
-                             Error **errp)
5d360b
+static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
5d360b
+                              Error **errp)
5d360b
 {
5d360b
     CPUArchState *env;
5d360b
     CPUState *cpu;
5d360b
@@ -262,7 +247,7 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
5d360b
         ret = cpu_write_elf64_note(f, cpu, id, s);
5d360b
         if (ret < 0) {
5d360b
             dump_error(s, "dump: failed to write elf notes", errp);
5d360b
-            return -1;
5d360b
+            return;
5d360b
         }
5d360b
     }
5d360b
 
5d360b
@@ -271,14 +256,12 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
5d360b
         ret = cpu_write_elf64_qemunote(f, cpu, s);
5d360b
         if (ret < 0) {
5d360b
             dump_error(s, "dump: failed to write CPU status", errp);
5d360b
-            return -1;
5d360b
+            return;
5d360b
         }
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
-static int write_elf32_note(DumpState *s, Error **errp)
5d360b
+static void write_elf32_note(DumpState *s, Error **errp)
5d360b
 {
5d360b
     hwaddr begin = s->memory_offset - s->note_size;
5d360b
     Elf32_Phdr phdr;
5d360b
@@ -295,14 +278,11 @@ static int write_elf32_note(DumpState *s, Error **errp)
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", errp);
5d360b
-        return -1;
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
-static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
5d360b
-                             Error **errp)
5d360b
+static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
5d360b
+                              Error **errp)
5d360b
 {
5d360b
     CPUArchState *env;
5d360b
     CPUState *cpu;
5d360b
@@ -315,7 +295,7 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
5d360b
         ret = cpu_write_elf32_note(f, cpu, id, s);
5d360b
         if (ret < 0) {
5d360b
             dump_error(s, "dump: failed to write elf notes", errp);
5d360b
-            return -1;
5d360b
+            return;
5d360b
         }
5d360b
     }
5d360b
 
5d360b
@@ -324,14 +304,12 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
5d360b
         ret = cpu_write_elf32_qemunote(f, cpu, s);
5d360b
         if (ret < 0) {
5d360b
             dump_error(s, "dump: failed to write CPU status", errp);
5d360b
-            return -1;
5d360b
+            return;
5d360b
         }
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
-static int write_elf_section(DumpState *s, int type, Error **errp)
5d360b
+static void write_elf_section(DumpState *s, int type, Error **errp)
5d360b
 {
5d360b
     Elf32_Shdr shdr32;
5d360b
     Elf64_Shdr shdr64;
5d360b
@@ -354,49 +332,43 @@ static int write_elf_section(DumpState *s, int type, Error **errp)
5d360b
     ret = fd_write_vmcore(&shdr, shdr_size, s);
5d360b
     if (ret < 0) {
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, Error **errp)
5d360b
+static void 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", errp);
5d360b
-        return -1;
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
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, Error **errp)
5d360b
+/* write the memory to vmcore. 1 page per I/O. */
5d360b
+static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
5d360b
+                         int64_t size, Error **errp)
5d360b
 {
5d360b
     int64_t i;
5d360b
-    int ret;
5d360b
+    Error *local_err = NULL;
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, errp);
5d360b
-        if (ret < 0) {
5d360b
-            return ret;
5d360b
+        write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
5d360b
+                   TARGET_PAGE_SIZE, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
     }
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, errp);
5d360b
-        if (ret < 0) {
5d360b
-            return ret;
5d360b
+        write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
5d360b
+                   size % TARGET_PAGE_SIZE, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
 /* get the memory's offset and size in the vmcore */
5d360b
@@ -461,13 +433,13 @@ static void get_offset_range(hwaddr phys_addr,
5d360b
     }
5d360b
 }
5d360b
 
5d360b
-static int write_elf_loads(DumpState *s, Error **errp)
5d360b
+static void write_elf_loads(DumpState *s, Error **errp)
5d360b
 {
5d360b
     hwaddr offset, filesz;
5d360b
     MemoryMapping *memory_mapping;
5d360b
     uint32_t phdr_index = 1;
5d360b
-    int ret;
5d360b
     uint32_t max_index;
5d360b
+    Error *local_err = NULL;
5d360b
 
5d360b
     if (s->have_section) {
5d360b
         max_index = s->sh_info;
5d360b
@@ -480,29 +452,28 @@ static int write_elf_loads(DumpState *s, Error **errp)
5d360b
                          memory_mapping->length,
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, errp);
5d360b
+            write_elf64_load(s, memory_mapping, phdr_index++, offset,
5d360b
+                             filesz, &local_err);
5d360b
         } else {
5d360b
-            ret = write_elf32_load(s, memory_mapping, phdr_index++, offset,
5d360b
-                                   filesz, errp);
5d360b
+            write_elf32_load(s, memory_mapping, phdr_index++, offset,
5d360b
+                             filesz, &local_err);
5d360b
         }
5d360b
 
5d360b
-        if (ret < 0) {
5d360b
-            return -1;
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
 
5d360b
         if (phdr_index >= max_index) {
5d360b
             break;
5d360b
         }
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
 /* write elf header, PT_NOTE and elf note to vmcore. */
5d360b
-static int dump_begin(DumpState *s, Error **errp)
5d360b
+static void dump_begin(DumpState *s, Error **errp)
5d360b
 {
5d360b
-    int ret;
5d360b
+    Error *local_err = NULL;
5d360b
 
5d360b
     /*
5d360b
      * the vmcore's format is:
5d360b
@@ -530,69 +501,81 @@ static int dump_begin(DumpState *s, Error **errp)
5d360b
 
5d360b
     /* write elf header to vmcore */
5d360b
     if (s->dump_info.d_class == ELFCLASS64) {
5d360b
-        ret = write_elf64_header(s, errp);
5d360b
+        write_elf64_header(s, &local_err);
5d360b
     } else {
5d360b
-        ret = write_elf32_header(s, errp);
5d360b
+        write_elf32_header(s, &local_err);
5d360b
     }
5d360b
-    if (ret < 0) {
5d360b
-        return -1;
5d360b
+    if (local_err) {
5d360b
+        error_propagate(errp, local_err);
5d360b
+        return;
5d360b
     }
5d360b
 
5d360b
     if (s->dump_info.d_class == ELFCLASS64) {
5d360b
         /* write PT_NOTE to vmcore */
5d360b
-        if (write_elf64_note(s, errp) < 0) {
5d360b
-            return -1;
5d360b
+        write_elf64_note(s, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
 
5d360b
         /* write all PT_LOAD to vmcore */
5d360b
-        if (write_elf_loads(s, errp) < 0) {
5d360b
-            return -1;
5d360b
+        write_elf_loads(s, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
 
5d360b
         /* write section to vmcore */
5d360b
         if (s->have_section) {
5d360b
-            if (write_elf_section(s, 1, errp) < 0) {
5d360b
-                return -1;
5d360b
+            write_elf_section(s, 1, &local_err);
5d360b
+            if (local_err) {
5d360b
+                error_propagate(errp, local_err);
5d360b
+                return;
5d360b
             }
5d360b
         }
5d360b
 
5d360b
         /* write notes to vmcore */
5d360b
-        if (write_elf64_notes(fd_write_vmcore, s, errp) < 0) {
5d360b
-            return -1;
5d360b
+        write_elf64_notes(fd_write_vmcore, s, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
-
5d360b
     } else {
5d360b
         /* write PT_NOTE to vmcore */
5d360b
-        if (write_elf32_note(s, errp) < 0) {
5d360b
-            return -1;
5d360b
+        write_elf32_note(s, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
 
5d360b
         /* write all PT_LOAD to vmcore */
5d360b
-        if (write_elf_loads(s, errp) < 0) {
5d360b
-            return -1;
5d360b
+        write_elf_loads(s, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
 
5d360b
         /* write section to vmcore */
5d360b
         if (s->have_section) {
5d360b
-            if (write_elf_section(s, 0, errp) < 0) {
5d360b
-                return -1;
5d360b
+            write_elf_section(s, 0, &local_err);
5d360b
+            if (local_err) {
5d360b
+                error_propagate(errp, local_err);
5d360b
+                return;
5d360b
             }
5d360b
         }
5d360b
 
5d360b
         /* write notes to vmcore */
5d360b
-        if (write_elf32_notes(fd_write_vmcore, s, errp) < 0) {
5d360b
-            return -1;
5d360b
+        write_elf32_notes(fd_write_vmcore, s, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
     }
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
-/* write PT_LOAD to vmcore */
5d360b
-static int dump_completed(DumpState *s)
5d360b
+static void dump_completed(DumpState *s)
5d360b
 {
5d360b
     dump_cleanup(s);
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
 static int get_next_block(DumpState *s, GuestPhysBlock *block)
5d360b
@@ -623,11 +606,12 @@ static int get_next_block(DumpState *s, GuestPhysBlock *block)
5d360b
 }
5d360b
 
5d360b
 /* write all memory to vmcore */
5d360b
-static int dump_iterate(DumpState *s, Error **errp)
5d360b
+static void dump_iterate(DumpState *s, Error **errp)
5d360b
 {
5d360b
     GuestPhysBlock *block;
5d360b
     int64_t size;
5d360b
     int ret;
5d360b
+    Error *local_err = NULL;
5d360b
 
5d360b
     while (1) {
5d360b
         block = s->next_block;
5d360b
@@ -639,34 +623,30 @@ static int dump_iterate(DumpState *s, Error **errp)
5d360b
                 size -= block->target_end - (s->begin + s->length);
5d360b
             }
5d360b
         }
5d360b
-        ret = write_memory(s, block, s->start, size, errp);
5d360b
-        if (ret == -1) {
5d360b
-            return ret;
5d360b
+        write_memory(s, block, s->start, size, &local_err);
5d360b
+        if (local_err) {
5d360b
+            error_propagate(errp, local_err);
5d360b
+            return;
5d360b
         }
5d360b
 
5d360b
         ret = get_next_block(s, block);
5d360b
         if (ret == 1) {
5d360b
             dump_completed(s);
5d360b
-            return 0;
5d360b
         }
5d360b
     }
5d360b
 }
5d360b
 
5d360b
-static int create_vmcore(DumpState *s, Error **errp)
5d360b
+static void create_vmcore(DumpState *s, Error **errp)
5d360b
 {
5d360b
-    int ret;
5d360b
+    Error *local_err = NULL;
5d360b
 
5d360b
-    ret = dump_begin(s, errp);
5d360b
-    if (ret < 0) {
5d360b
-        return -1;
5d360b
-    }
5d360b
-
5d360b
-    ret = dump_iterate(s, errp);
5d360b
-    if (ret < 0) {
5d360b
-        return -1;
5d360b
+    dump_begin(s, &local_err);
5d360b
+    if (local_err) {
5d360b
+        error_propagate(errp, local_err);
5d360b
+        return;
5d360b
     }
5d360b
 
5d360b
-    return 0;
5d360b
+    dump_iterate(s, errp);
5d360b
 }
5d360b
 
5d360b
 static int write_start_flat_header(int fd)
5d360b
@@ -747,9 +727,8 @@ 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, Error **errp)
5d360b
+static void create_header32(DumpState *s, Error **errp)
5d360b
 {
5d360b
-    int ret = 0;
5d360b
     DiskDumpHeader32 *dh = NULL;
5d360b
     KdumpSubHeader32 *kh = NULL;
5d360b
     size_t size;
5d360b
@@ -758,6 +737,7 @@ static int create_header32(DumpState *s, Error **errp)
5d360b
     uint32_t bitmap_blocks;
5d360b
     uint32_t status = 0;
5d360b
     uint64_t offset_note;
5d360b
+    Error *local_err = NULL;
5d360b
 
5d360b
     /* write common header, the version of kdump-compressed format is 6th */
5d360b
     size = sizeof(DiskDumpHeader32);
5d360b
@@ -794,7 +774,6 @@ static int create_header32(DumpState *s, Error **errp)
5d360b
 
5d360b
     if (write_buffer(s->fd, 0, dh, size) < 0) {
5d360b
         dump_error(s, "dump: failed to write disk dump header", errp);
5d360b
-        ret = -1;
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -814,7 +793,6 @@ static int create_header32(DumpState *s, Error **errp)
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", errp);
5d360b
-        ret = -1;
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -823,15 +801,14 @@ static int create_header32(DumpState *s, Error **errp)
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, errp) < 0) {
5d360b
-        ret = -1;
5d360b
+    write_elf32_notes(buf_write_note, s, &local_err);
5d360b
+    if (local_err) {
5d360b
+        error_propagate(errp, local_err);
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", errp);
5d360b
-        ret = -1;
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -847,14 +824,11 @@ out:
5d360b
     g_free(dh);
5d360b
     g_free(kh);
5d360b
     g_free(s->note_buf);
5d360b
-
5d360b
-    return ret;
5d360b
 }
5d360b
 
5d360b
 /* write common header, sub header and elf note to vmcore */
5d360b
-static int create_header64(DumpState *s, Error **errp)
5d360b
+static void create_header64(DumpState *s, Error **errp)
5d360b
 {
5d360b
-    int ret = 0;
5d360b
     DiskDumpHeader64 *dh = NULL;
5d360b
     KdumpSubHeader64 *kh = NULL;
5d360b
     size_t size;
5d360b
@@ -863,6 +837,7 @@ static int create_header64(DumpState *s, Error **errp)
5d360b
     uint32_t bitmap_blocks;
5d360b
     uint32_t status = 0;
5d360b
     uint64_t offset_note;
5d360b
+    Error *local_err = NULL;
5d360b
 
5d360b
     /* write common header, the version of kdump-compressed format is 6th */
5d360b
     size = sizeof(DiskDumpHeader64);
5d360b
@@ -899,7 +874,6 @@ static int create_header64(DumpState *s, Error **errp)
5d360b
 
5d360b
     if (write_buffer(s->fd, 0, dh, size) < 0) {
5d360b
         dump_error(s, "dump: failed to write disk dump header", errp);
5d360b
-        ret = -1;
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -919,7 +893,6 @@ static int create_header64(DumpState *s, Error **errp)
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", errp);
5d360b
-        ret = -1;
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -928,15 +901,15 @@ static int create_header64(DumpState *s, Error **errp)
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, errp) < 0) {
5d360b
-        ret = -1;
5d360b
+    write_elf64_notes(buf_write_note, s, &local_err);
5d360b
+    if (local_err) {
5d360b
+        error_propagate(errp, local_err);
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", errp);
5d360b
-        ret = -1;
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -952,16 +925,19 @@ out:
5d360b
     g_free(dh);
5d360b
     g_free(kh);
5d360b
     g_free(s->note_buf);
5d360b
-
5d360b
-    return ret;
5d360b
 }
5d360b
 
5d360b
-static int write_dump_header(DumpState *s, Error **errp)
5d360b
+static void write_dump_header(DumpState *s, Error **errp)
5d360b
 {
5d360b
+     Error *local_err = NULL;
5d360b
+
5d360b
     if (s->dump_info.d_class == ELFCLASS32) {
5d360b
-        return create_header32(s, errp);
5d360b
+        create_header32(s, &local_err);
5d360b
     } else {
5d360b
-        return create_header64(s, errp);
5d360b
+        create_header64(s, &local_err);
5d360b
+    }
5d360b
+    if (local_err) {
5d360b
+        error_propagate(errp, local_err);
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -1075,7 +1051,7 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
5d360b
     return true;
5d360b
 }
5d360b
 
5d360b
-static int write_dump_bitmap(DumpState *s, Error **errp)
5d360b
+static void write_dump_bitmap(DumpState *s, Error **errp)
5d360b
 {
5d360b
     int ret = 0;
5d360b
     uint64_t last_pfn, pfn;
5d360b
@@ -1097,7 +1073,6 @@ static int write_dump_bitmap(DumpState *s, Error **errp)
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", errp);
5d360b
-            ret = -1;
5d360b
             goto out;
5d360b
         }
5d360b
 
5d360b
@@ -1115,7 +1090,6 @@ static int write_dump_bitmap(DumpState *s, Error **errp)
5d360b
                               dump_bitmap_buf, s);
5d360b
         if (ret < 0) {
5d360b
             dump_error(s, "dump: failed to sync dump_bitmap", errp);
5d360b
-            ret = -1;
5d360b
             goto out;
5d360b
         }
5d360b
     }
5d360b
@@ -1125,8 +1099,6 @@ static int write_dump_bitmap(DumpState *s, Error **errp)
5d360b
 
5d360b
 out:
5d360b
     g_free(dump_bitmap_buf);
5d360b
-
5d360b
-    return ret;
5d360b
 }
5d360b
 
5d360b
 static void prepare_data_cache(DataCache *data_cache, DumpState *s,
5d360b
@@ -1206,7 +1178,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, Error **errp)
5d360b
+static void write_dump_pages(DumpState *s, Error **errp)
5d360b
 {
5d360b
     int ret = 0;
5d360b
     DataCache page_desc, page_data;
5d360b
@@ -1371,13 +1343,12 @@ out:
5d360b
 #endif
5d360b
 
5d360b
     g_free(buf_out);
5d360b
-
5d360b
-    return ret;
5d360b
 }
5d360b
 
5d360b
-static int create_kdump_vmcore(DumpState *s, Error **errp)
5d360b
+static void create_kdump_vmcore(DumpState *s, Error **errp)
5d360b
 {
5d360b
     int ret;
5d360b
+    Error *local_err = NULL;
5d360b
 
5d360b
     /*
5d360b
      * the kdump-compressed format is:
5d360b
@@ -1404,33 +1375,34 @@ static int create_kdump_vmcore(DumpState *s, Error **errp)
5d360b
     ret = write_start_flat_header(s->fd);
5d360b
     if (ret < 0) {
5d360b
         dump_error(s, "dump: failed to write start flat header", errp);
5d360b
-        return -1;
5d360b
+        return;
5d360b
     }
5d360b
 
5d360b
-    ret = write_dump_header(s, errp);
5d360b
-    if (ret < 0) {
5d360b
-        return -1;
5d360b
+    write_dump_header(s, &local_err);
5d360b
+    if (local_err) {
5d360b
+        error_propagate(errp, local_err);
5d360b
+        return;
5d360b
     }
5d360b
 
5d360b
-    ret = write_dump_bitmap(s, errp);
5d360b
-    if (ret < 0) {
5d360b
-        return -1;
5d360b
+    write_dump_bitmap(s, &local_err);
5d360b
+    if (local_err) {
5d360b
+        error_propagate(errp, local_err);
5d360b
+        return;
5d360b
     }
5d360b
 
5d360b
-    ret = write_dump_pages(s, errp);
5d360b
-    if (ret < 0) {
5d360b
-        return -1;
5d360b
+    write_dump_pages(s, &local_err);
5d360b
+    if (local_err) {
5d360b
+        error_propagate(errp, local_err);
5d360b
+        return;
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", errp);
5d360b
-        return -1;
5d360b
+        return;
5d360b
     }
5d360b
 
5d360b
     dump_completed(s);
5d360b
-
5d360b
-    return 0;
5d360b
 }
5d360b
 
5d360b
 static ram_addr_t get_start_block(DumpState *s)
5d360b
@@ -1469,9 +1441,9 @@ static void get_max_mapnr(DumpState *s)
5d360b
     s->max_mapnr = paddr_to_pfn(last_block->target_end);
5d360b
 }
5d360b
 
5d360b
-static int dump_init(DumpState *s, int fd, bool has_format,
5d360b
-                     DumpGuestMemoryFormat format, bool paging, bool has_filter,
5d360b
-                     int64_t begin, int64_t length, Error **errp)
5d360b
+static void dump_init(DumpState *s, int fd, bool has_format,
5d360b
+                      DumpGuestMemoryFormat format, bool paging, bool has_filter,
5d360b
+                      int64_t begin, int64_t length, Error **errp)
5d360b
 {
5d360b
     CPUArchState *env;
5d360b
     int nr_cpus;
5d360b
@@ -1576,7 +1548,7 @@ static int dump_init(DumpState *s, int fd, bool has_format,
5d360b
             s->flag_compress = 0;
5d360b
         }
5d360b
 
5d360b
-        return 0;
5d360b
+        return;
5d360b
     }
5d360b
 
5d360b
     if (s->has_filter) {
5d360b
@@ -1625,11 +1597,10 @@ static int dump_init(DumpState *s, int fd, bool has_format,
5d360b
         }
5d360b
     }
5d360b
 
5d360b
-    return 0;
5d360b
+    return;
5d360b
 
5d360b
 cleanup:
5d360b
     dump_cleanup(s);
5d360b
-    return -1;
5d360b
 }
5d360b
 
5d360b
 void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
5d360b
@@ -1640,7 +1611,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
5d360b
     const char *p;
5d360b
     int fd = -1;
5d360b
     DumpState *s;
5d360b
-    int ret;
5d360b
+    Error *local_err = NULL;
5d360b
 
5d360b
     /*
5d360b
      * kdump-compressed format need the whole memory dumped, so paging or
5d360b
@@ -1700,10 +1671,11 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
5d360b
 
5d360b
     s = g_malloc0(sizeof(DumpState));
5d360b
 
5d360b
-    ret = dump_init(s, fd, has_format, format, paging, has_begin,
5d360b
-                    begin, length, errp);
5d360b
-    if (ret < 0) {
5d360b
+    dump_init(s, fd, has_format, format, paging, has_begin,
5d360b
+              begin, length, &local_err);
5d360b
+    if (local_err) {
5d360b
         g_free(s);
5d360b
+        error_propagate(errp, local_err);
5d360b
         return;
5d360b
     }
5d360b
 
5d360b
-- 
5d360b
1.8.3.1
5d360b