5d360b
From b67ef65a1f5d8ceb02ca11c0af92d2c06fd006cb 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:57 +0100
5d360b
Subject: [PATCH 26/41] dump-guest-memory: introduce dump_process() helper
5d360b
 function.
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-27-marcandre.lureau@redhat.com>
5d360b
Patchwork-id: 78375
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 26/41] dump-guest-memory: introduce dump_process() helper function.
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
No functional change. Cleanup only.
5d360b
5d360b
Signed-off-by: Peter Xu <peterx@redhat.com>
5d360b
Reviewed-by: Fam Zheng <famz@redhat.com>
5d360b
Message-Id: <1455772616-8668-6-git-send-email-peterx@redhat.com>
5d360b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5d360b
5d360b
(cherry picked from commit ca1fc8c97e9f26690b1ddbbbced5bafb3d65f6b5)
5d360b
5d360b
RHEL: minor conflict due to "detach" mode not being backported.
5d360b
5d360b
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 dump.c                | 35 +++++++++++++++++++++++------------
5d360b
 include/sysemu/dump.h |  3 +++
5d360b
 2 files changed, 26 insertions(+), 12 deletions(-)
5d360b
5d360b
diff --git a/dump.c b/dump.c
5d360b
index 639d52a..4bce6cf 100644
5d360b
--- a/dump.c
5d360b
+++ b/dump.c
5d360b
@@ -1470,6 +1470,9 @@ static void dump_init(DumpState *s, int fd, bool has_format,
5d360b
     Error *err = NULL;
5d360b
     int ret;
5d360b
 
5d360b
+    s->has_format = has_format;
5d360b
+    s->format = format;
5d360b
+
5d360b
     /* kdump-compressed is conflict with paging and filter */
5d360b
     if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
5d360b
         assert(!paging && !has_filter);
5d360b
@@ -1628,8 +1631,25 @@ cleanup:
5d360b
     dump_cleanup(s);
5d360b
 }
5d360b
 
5d360b
-void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
5d360b
-                           int64_t begin, bool has_length,
5d360b
+/* this operation might be time consuming. */
5d360b
+static void dump_process(DumpState *s, Error **errp)
5d360b
+{
5d360b
+    Error *local_err = NULL;
5d360b
+
5d360b
+    if (s->has_format && s->format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
5d360b
+        create_kdump_vmcore(s, &local_err);
5d360b
+    } else {
5d360b
+        create_vmcore(s, &local_err);
5d360b
+    }
5d360b
+
5d360b
+    s->status = (local_err ? DUMP_STATUS_FAILED : DUMP_STATUS_COMPLETED);
5d360b
+    error_propagate(errp, local_err);
5d360b
+
5d360b
+    dump_cleanup(s);
5d360b
+}
5d360b
+
5d360b
+void qmp_dump_guest_memory(bool paging, const char *file,
5d360b
+                           bool has_begin, int64_t begin, bool has_length,
5d360b
                            int64_t length, bool has_format,
5d360b
                            DumpGuestMemoryFormat format, Error **errp)
5d360b
 {
5d360b
@@ -1712,16 +1732,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
5d360b
         return;
5d360b
     }
5d360b
 
5d360b
-    if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
5d360b
-        create_kdump_vmcore(s, &local_err);
5d360b
-    } else {
5d360b
-        create_vmcore(s, &local_err);
5d360b
-    }
5d360b
-
5d360b
-    s->status = (local_err ? DUMP_STATUS_FAILED : DUMP_STATUS_COMPLETED);
5d360b
-    error_propagate(errp, local_err);
5d360b
-
5d360b
-    dump_cleanup(s);
5d360b
+    dump_process(s, errp);
5d360b
 }
5d360b
 
5d360b
 DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
5d360b
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
5d360b
index 21fc02d..1da3ddb 100644
5d360b
--- a/include/sysemu/dump.h
5d360b
+++ b/include/sysemu/dump.h
5d360b
@@ -178,6 +178,9 @@ typedef struct DumpState {
5d360b
     size_t num_dumpable;        /* number of page that can be dumped */
5d360b
     uint32_t flag_compress;     /* indicate the compression format */
5d360b
     DumpStatus status;          /* current dump status */
5d360b
+
5d360b
+    bool has_format;              /* whether format is provided */
5d360b
+    DumpGuestMemoryFormat format; /* valid only if has_format == true */
5d360b
 } DumpState;
5d360b
 
5d360b
 uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
5d360b
-- 
5d360b
1.8.3.1
5d360b