cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-dump-guest-memory-cleanup-removing-dump_-error-clean.patch

5d360b
From e105226b0203159f15fc932eac668c67686ec923 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:54 +0100
5d360b
Subject: [PATCH 23/41] dump-guest-memory: cleanup: removing
5d360b
 dump_{error|cleanup}().
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-24-marcandre.lureau@redhat.com>
5d360b
Patchwork-id: 78372
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 23/41] dump-guest-memory: cleanup: removing dump_{error|cleanup}().
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: Peter Xu <peterx@redhat.com>
5d360b
5d360b
It might be a little bit confusing and error prone to do
5d360b
dump_cleanup() in these two functions. A better way is to do
5d360b
dump_cleanup() before dump finish, no matter whether dump has
5d360b
succeeded or not.
5d360b
5d360b
Signed-off-by: Peter Xu <peterx@redhat.com>
5d360b
Reviewed-by: Fam Zheng <famz@redhat.com>
5d360b
Message-Id: <1455772616-8668-2-git-send-email-peterx@redhat.com>
5d360b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5d360b
5d360b
(cherry picked from commit e3517a529913a2a48c12ba8eef4975ad561af97c)
5d360b
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 dump.c | 78 +++++++++++++++++++++++++++---------------------------------------
5d360b
 1 file changed, 32 insertions(+), 46 deletions(-)
5d360b
5d360b
diff --git a/dump.c b/dump.c
5d360b
index a359c29..790bfe4 100644
5d360b
--- a/dump.c
5d360b
+++ b/dump.c
5d360b
@@ -81,12 +81,6 @@ static int dump_cleanup(DumpState *s)
5d360b
     return 0;
5d360b
 }
5d360b
 
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
 {
5d360b
     DumpState *s = opaque;
5d360b
@@ -127,7 +121,7 @@ static void write_elf64_header(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write elf header");
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -158,7 +152,7 @@ static void write_elf32_header(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write elf header");
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -181,7 +175,7 @@ static void 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", errp);
5d360b
+        error_setg(errp, "dump: failed to write program header table");
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -204,7 +198,7 @@ static void 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", errp);
5d360b
+        error_setg(errp, "dump: failed to write program header table");
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -224,7 +218,7 @@ static void write_elf64_note(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write program header table");
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -246,7 +240,7 @@ static void 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", errp);
5d360b
+            error_setg(errp, "dump: failed to write elf notes");
5d360b
             return;
5d360b
         }
5d360b
     }
5d360b
@@ -255,7 +249,7 @@ static void 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", errp);
5d360b
+            error_setg(errp, "dump: failed to write CPU status");
5d360b
             return;
5d360b
         }
5d360b
     }
5d360b
@@ -277,7 +271,7 @@ static void write_elf32_note(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write program header table");
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -294,7 +288,7 @@ static void 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", errp);
5d360b
+            error_setg(errp, "dump: failed to write elf notes");
5d360b
             return;
5d360b
         }
5d360b
     }
5d360b
@@ -303,7 +297,7 @@ static void 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", errp);
5d360b
+            error_setg(errp, "dump: failed to write CPU status");
5d360b
             return;
5d360b
         }
5d360b
     }
5d360b
@@ -331,7 +325,7 @@ static void write_elf_section(DumpState *s, int type, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write section header table");
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -341,7 +335,7 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp)
5d360b
 
5d360b
     ret = fd_write_vmcore(buf, length, s);
5d360b
     if (ret < 0) {
5d360b
-        dump_error(s, "dump: failed to save memory", errp);
5d360b
+        error_setg(errp, "dump: failed to save memory");
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -573,11 +567,6 @@ static void dump_begin(DumpState *s, Error **errp)
5d360b
     }
5d360b
 }
5d360b
 
5d360b
-static void dump_completed(DumpState *s)
5d360b
-{
5d360b
-    dump_cleanup(s);
5d360b
-}
5d360b
-
5d360b
 static int get_next_block(DumpState *s, GuestPhysBlock *block)
5d360b
 {
5d360b
     while (1) {
5d360b
@@ -629,8 +618,6 @@ static void dump_iterate(DumpState *s, Error **errp)
5d360b
         }
5d360b
 
5d360b
     } while (!get_next_block(s, block));
5d360b
-
5d360b
-    dump_completed(s);
5d360b
 }
5d360b
 
5d360b
 static void create_vmcore(DumpState *s, Error **errp)
5d360b
@@ -770,7 +757,7 @@ static void create_header32(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write disk dump header");
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -789,7 +776,7 @@ static void create_header32(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write kdump sub header");
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -805,7 +792,7 @@ static void create_header32(DumpState *s, Error **errp)
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
+        error_setg(errp, "dump: failed to write notes");
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -870,7 +857,7 @@ static void create_header64(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write disk dump header");
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -889,7 +876,7 @@ static void create_header64(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to write kdump sub header");
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -906,7 +893,7 @@ static void create_header64(DumpState *s, Error **errp)
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
+        error_setg(errp, "dump: failed to write notes");
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -1092,7 +1079,7 @@ static void write_dump_bitmap(DumpState *s, Error **errp)
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", errp);
5d360b
+            error_setg(errp, "dump: failed to set dump_bitmap");
5d360b
             goto out;
5d360b
         }
5d360b
 
5d360b
@@ -1109,7 +1096,7 @@ static void write_dump_bitmap(DumpState *s, Error **errp)
5d360b
         ret = set_dump_bitmap(last_pfn, last_pfn + bits_per_buf, false,
5d360b
                               dump_bitmap_buf, s);
5d360b
         if (ret < 0) {
5d360b
-            dump_error(s, "dump: failed to sync dump_bitmap", errp);
5d360b
+            error_setg(errp, "dump: failed to sync dump_bitmap");
5d360b
             goto out;
5d360b
         }
5d360b
     }
5d360b
@@ -1242,7 +1229,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
5d360b
     ret = write_cache(&page_data, buf, s->dump_info.page_size, false);
5d360b
     g_free(buf);
5d360b
     if (ret < 0) {
5d360b
-        dump_error(s, "dump: failed to write page data (zero page)", errp);
5d360b
+        error_setg(errp, "dump: failed to write page data (zero page)");
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -1258,7 +1245,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
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", errp);
5d360b
+                error_setg(errp, "dump: failed to write page desc");
5d360b
                 goto out;
5d360b
             }
5d360b
         } else {
5d360b
@@ -1283,7 +1270,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
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", errp);
5d360b
+                    error_setg(errp, "dump: failed to write page data");
5d360b
                     goto out;
5d360b
                 }
5d360b
 #ifdef CONFIG_LZO
5d360b
@@ -1296,7 +1283,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
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", errp);
5d360b
+                    error_setg(errp, "dump: failed to write page data");
5d360b
                     goto out;
5d360b
                 }
5d360b
 #endif
5d360b
@@ -1310,7 +1297,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
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", errp);
5d360b
+                    error_setg(errp, "dump: failed to write page data");
5d360b
                     goto out;
5d360b
                 }
5d360b
 #endif
5d360b
@@ -1326,7 +1313,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
5d360b
                 ret = write_cache(&page_data, buf,
5d360b
                                   s->dump_info.page_size, false);
5d360b
                 if (ret < 0) {
5d360b
-                    dump_error(s, "dump: failed to write page data", errp);
5d360b
+                    error_setg(errp, "dump: failed to write page data");
5d360b
                     goto out;
5d360b
                 }
5d360b
             }
5d360b
@@ -1338,7 +1325,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
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", errp);
5d360b
+                error_setg(errp, "dump: failed to write page desc");
5d360b
                 goto out;
5d360b
             }
5d360b
         }
5d360b
@@ -1346,12 +1333,12 @@ static void write_dump_pages(DumpState *s, Error **errp)
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", errp);
5d360b
+        error_setg(errp, "dump: failed to sync cache for page_desc");
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", errp);
5d360b
+        error_setg(errp, "dump: failed to sync cache for page_data");
5d360b
         goto out;
5d360b
     }
5d360b
 
5d360b
@@ -1395,7 +1382,7 @@ static void create_kdump_vmcore(DumpState *s, Error **errp)
5d360b
 
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
+        error_setg(errp, "dump: failed to write start flat header");
5d360b
         return;
5d360b
     }
5d360b
 
5d360b
@@ -1419,11 +1406,9 @@ static void create_kdump_vmcore(DumpState *s, Error **errp)
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
+        error_setg(errp, "dump: failed to write end flat header");
5d360b
         return;
5d360b
     }
5d360b
-
5d360b
-    dump_completed(s);
5d360b
 }
5d360b
 
5d360b
 static ram_addr_t get_start_block(DumpState *s)
5d360b
@@ -1711,6 +1696,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
5d360b
         create_vmcore(s, errp);
5d360b
     }
5d360b
 
5d360b
+    dump_cleanup(s);
5d360b
     g_free(s);
5d360b
 }
5d360b
 
5d360b
-- 
5d360b
1.8.3.1
5d360b