All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Xu <peterx@redhat.com>
Subject: [Qemu-devel] [PULL 09/19] dump-guest-memory: add "detach" support
Date: Wed, 24 Feb 2016 14:27:31 +0100	[thread overview]
Message-ID: <1456320461-26756-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1456320461-26756-1-git-send-email-pbonzini@redhat.com>

From: Peter Xu <peterx@redhat.com>

If "detach" is provided, one thread is created to do the dump work,
while main thread will return immediately. For each GuestPhysBlock,
adding one more field "mr" to points to MemoryRegion that it
belongs, also ref the mr before use.

Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Message-Id: <1455772616-8668-8-git-send-email-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 dump.c                          | 27 ++++++++++++++++++++++++++-
 include/sysemu/dump.h           |  1 +
 include/sysemu/memory_mapping.h |  4 ++++
 memory_mapping.c                |  3 +++
 4 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/dump.c b/dump.c
index 923e3a5..9210a72 100644
--- a/dump.c
+++ b/dump.c
@@ -1643,6 +1643,20 @@ static void dump_process(DumpState *s, Error **errp)
     dump_cleanup(s);
 }
 
+static void *dump_thread(void *data)
+{
+    Error *err = NULL;
+    DumpState *s = (DumpState *)data;
+
+    dump_process(s, &err);
+
+    if (err) {
+        /* TODO: notify user the error */
+        error_free(err);
+    }
+    return NULL;
+}
+
 void qmp_dump_guest_memory(bool paging, const char *file,
                            bool has_detach, bool detach,
                            bool has_begin, int64_t begin, bool has_length,
@@ -1653,6 +1667,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,
     int fd = -1;
     DumpState *s;
     Error *local_err = NULL;
+    bool detach_p = false;
 
     if (runstate_check(RUN_STATE_INMIGRATE)) {
         error_setg(errp, "Dump not allowed during incoming migration.");
@@ -1684,6 +1699,9 @@ void qmp_dump_guest_memory(bool paging, const char *file,
         error_setg(errp, QERR_MISSING_PARAMETER, "begin");
         return;
     }
+    if (has_detach) {
+        detach_p = detach;
+    }
 
     /* check whether lzo/snappy is supported */
 #ifndef CONFIG_LZO
@@ -1733,7 +1751,14 @@ void qmp_dump_guest_memory(bool paging, const char *file,
         return;
     }
 
-    dump_process(s, errp);
+    if (detach_p) {
+        /* detached dump */
+        qemu_thread_create(&s->dump_thread, "dump_thread", dump_thread,
+                           s, QEMU_THREAD_DETACHED);
+    } else {
+        /* sync dump */
+        dump_process(s, errp);
+    }
 }
 
 DumpGuestMemoryCapability *qmp_query_dump_guest_memory_capability(Error **errp)
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index 1da3ddb..06393c3 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -181,6 +181,7 @@ typedef struct DumpState {
 
     bool has_format;              /* whether format is provided */
     DumpGuestMemoryFormat format; /* valid only if has_format == true */
+    QemuThread dump_thread;       /* thread for detached dump */
 } DumpState;
 
 uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
diff --git a/include/sysemu/memory_mapping.h b/include/sysemu/memory_mapping.h
index a75d59a..d46d879 100644
--- a/include/sysemu/memory_mapping.h
+++ b/include/sysemu/memory_mapping.h
@@ -16,6 +16,7 @@
 
 #include "qemu/queue.h"
 #include "qemu/typedefs.h"
+#include "exec/memory.h"
 
 typedef struct GuestPhysBlock {
     /* visible to guest, reflects PCI hole, etc */
@@ -27,6 +28,9 @@ typedef struct GuestPhysBlock {
     /* points into host memory */
     uint8_t *host_addr;
 
+    /* points to the MemoryRegion that this block belongs to */
+    MemoryRegion *mr;
+
     QTAILQ_ENTRY(GuestPhysBlock) next;
 } GuestPhysBlock;
 
diff --git a/memory_mapping.c b/memory_mapping.c
index 04db3ac..c8855de 100644
--- a/memory_mapping.c
+++ b/memory_mapping.c
@@ -178,6 +178,7 @@ void guest_phys_blocks_free(GuestPhysBlockList *list)
 
     QTAILQ_FOREACH_SAFE(p, &list->head, next, q) {
         QTAILQ_REMOVE(&list->head, p, next);
+        memory_region_unref(p->mr);
         g_free(p);
     }
     list->num = 0;
@@ -241,6 +242,8 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,
         block->target_start = target_start;
         block->target_end   = target_end;
         block->host_addr    = host_addr;
+        block->mr           = section->mr;
+        memory_region_ref(section->mr);
 
         QTAILQ_INSERT_TAIL(&g->list->head, block, next);
         ++g->list->num;
-- 
2.5.0

  parent reply	other threads:[~2016-02-24 13:28 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-24 13:27 [Qemu-devel] [PULL 00/19] Misc changes for 2016-02-24 Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 01/19] qemu-options.hx: Improve documentation of chardev multiplexing mode Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 02/19] scripts/kvm/kvm_stat: Fix missing right parantheses and ".format(...)" Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 03/19] dump-guest-memory: cleanup: removing dump_{error|cleanup}() Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 04/19] dump-guest-memory: add "detach" flag for QMP/HMP interfaces Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 05/19] dump-guest-memory: using static DumpState, add DumpStatus Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 06/19] dump-guest-memory: add dump_in_progress() helper function Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 07/19] dump-guest-memory: introduce dump_process() " Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 08/19] dump-guest-memory: disable dump when in INMIGRATE state Paolo Bonzini
2016-02-24 13:27 ` Paolo Bonzini [this message]
2016-02-24 13:27 ` [Qemu-devel] [PULL 10/19] DumpState: adding total_size and written_size fields Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 11/19] Dump: add qmp command "query-dump" Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 12/19] Dump: add hmp command "info dump" Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 13/19] dump-guest-memory: add qmp event DUMP_COMPLETED Paolo Bonzini
2016-02-24 15:54   ` Eric Blake
2016-02-24 13:27 ` [Qemu-devel] [PULL 14/19] log: Redirect stderr to logfile if deamonized Paolo Bonzini
2016-02-29  8:57   ` Ján Tomko
2016-02-29  9:07     ` Paolo Bonzini
2016-02-29 10:04       ` Ján Tomko
2016-02-29 10:17         ` Paolo Bonzini
2016-02-29 11:05           ` Ján Tomko
2016-02-29 11:17             ` Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 15/19] exec: store RAMBlock pointer into memory region Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 16/19] memory: optimize qemu_get_ram_ptr and qemu_ram_ptr_length Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 17/19] memory: Remove unreachable return statement Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 18/19] chardev: Properly initialize ChardevCommon components Paolo Bonzini
2016-02-24 13:27 ` [Qemu-devel] [PULL 19/19] target-i386: fix confusion in xcr0 bit position vs. mask Paolo Bonzini
2016-02-25 10:45 ` [Qemu-devel] [PULL 00/19] Misc changes for 2016-02-24 Peter Maydell
2016-02-25 11:10   ` Gonglei (Arei)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456320461-26756-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.