thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-DumpState-adding-total_size-and-written_size-fields.patch

5d360b
From 60e8f031af3ca219ac6344c6028fe009eddf8c19 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:59 +0100
5d360b
Subject: [PATCH 28/41] DumpState: adding total_size and written_size fields
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-29-marcandre.lureau@redhat.com>
5d360b
Patchwork-id: 78382
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH v3 28/41] DumpState: adding total_size and written_size fields
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
Here, total_size is the size in bytes to be dumped (raw data, which
5d360b
means before compression), while written_size are bytes handled (raw
5d360b
size too).
5d360b
5d360b
Signed-off-by: Peter Xu <peterx@redhat.com>
5d360b
Message-Id: <1455772616-8668-9-git-send-email-peterx@redhat.com>
5d360b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
5d360b
5d360b
(cherry picked from commit 2264c2c96e0a1f0913412da73e9bcaf9f8fa4427)
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                | 32 ++++++++++++++++++++++++++++++++
5d360b
 include/sysemu/dump.h |  8 ++++++++
5d360b
 2 files changed, 40 insertions(+)
5d360b
5d360b
diff --git a/dump.c b/dump.c
5d360b
index 8618230..008a722 100644
5d360b
--- a/dump.c
5d360b
+++ b/dump.c
5d360b
@@ -336,6 +336,8 @@ static void write_data(DumpState *s, void *buf, int length, Error **errp)
5d360b
     ret = fd_write_vmcore(buf, length, s);
5d360b
     if (ret < 0) {
5d360b
         error_setg(errp, "dump: failed to save memory");
5d360b
+    } else {
5d360b
+        s->written_size += length;
5d360b
     }
5d360b
 }
5d360b
 
5d360b
@@ -1329,6 +1331,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
5d360b
                 goto out;
5d360b
             }
5d360b
         }
5d360b
+        s->written_size += s->dump_info.page_size;
5d360b
     }
5d360b
 
5d360b
     ret = write_cache(&page_desc, NULL, 0, true);
5d360b
@@ -1461,6 +1464,30 @@ bool dump_in_progress(void)
5d360b
     return (state->status == DUMP_STATUS_ACTIVE);
5d360b
 }
5d360b
 
5d360b
+/* calculate total size of memory to be dumped (taking filter into
5d360b
+ * acoount.) */
5d360b
+static int64_t dump_calculate_size(DumpState *s)
5d360b
+{
5d360b
+    GuestPhysBlock *block;
5d360b
+    int64_t size = 0, total = 0, left = 0, right = 0;
5d360b
+
5d360b
+    QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) {
5d360b
+        if (s->has_filter) {
5d360b
+            /* calculate the overlapped region. */
5d360b
+            left = MAX(s->begin, block->target_start);
5d360b
+            right = MIN(s->begin + s->length, block->target_end);
5d360b
+            size = right - left;
5d360b
+            size = size > 0 ? size : 0;
5d360b
+        } else {
5d360b
+            /* count the whole region in */
5d360b
+            size = (block->target_end - block->target_start);
5d360b
+        }
5d360b
+        total += size;
5d360b
+    }
5d360b
+
5d360b
+    return total;
5d360b
+}
5d360b
+
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
@@ -1472,6 +1499,7 @@ static void dump_init(DumpState *s, int fd, bool has_format,
5d360b
 
5d360b
     s->has_format = has_format;
5d360b
     s->format = format;
5d360b
+    s->written_size = 0;
5d360b
 
5d360b
     /* kdump-compressed is conflict with paging and filter */
5d360b
     if (has_format && format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
5d360b
@@ -1503,6 +1531,10 @@ static void dump_init(DumpState *s, int fd, bool has_format,
5d360b
 
5d360b
     guest_phys_blocks_init(&s->guest_phys_blocks);
5d360b
     guest_phys_blocks_append(&s->guest_phys_blocks);
5d360b
+    s->total_size = dump_calculate_size(s);
5d360b
+#ifdef DEBUG_DUMP_GUEST_MEMORY
5d360b
+    fprintf(stderr, "DUMP: total memory to dump: %lu\n", s->total_size);
5d360b
+#endif
5d360b
 
5d360b
     s->start = get_start_block(s);
5d360b
     if (s->start == -1) {
5d360b
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
5d360b
index 1da3ddb..b5ebb0a 100644
5d360b
--- a/include/sysemu/dump.h
5d360b
+++ b/include/sysemu/dump.h
5d360b
@@ -181,6 +181,14 @@ typedef struct DumpState {
5d360b
 
5d360b
     bool has_format;              /* whether format is provided */
5d360b
     DumpGuestMemoryFormat format; /* valid only if has_format == true */
5d360b
+    int64_t total_size;          /* total memory size (in bytes) to
5d360b
+                                  * be dumped. When filter is
5d360b
+                                  * enabled, this will only count
5d360b
+                                  * those to be written. */
5d360b
+    int64_t written_size;        /* written memory size (in bytes),
5d360b
+                                  * this could be used to calculate
5d360b
+                                  * how much work we have
5d360b
+                                  * finished. */
5d360b
 } DumpState;
5d360b
 
5d360b
 uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
5d360b
-- 
5d360b
1.8.3.1
5d360b