qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC PATCH qemu] qapi: Add query-memory-checksum
@ 2019-08-22  1:16 Alexey Kardashevskiy
  2019-08-22  1:33 ` Eric Blake
  2019-08-22 14:16 ` Markus Armbruster
  0 siblings, 2 replies; 9+ messages in thread
From: Alexey Kardashevskiy @ 2019-08-22  1:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexey Kardashevskiy, Paolo Bonzini

This returns MD5 checksum of all RAM blocks for migration debugging
as this is way faster than saving the entire RAM to a file and checking
that.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---


I am actually wondering if there is an easier way of getting these
checksums and I just do not see it, it cannot be that we fixed all
memory migration bugs :)


---
 qapi/misc.json            | 27 +++++++++++++++++++++++++++
 include/exec/cpu-common.h |  1 +
 exec.c                    | 16 ++++++++++++++++
 monitor/qmp-cmds.c        |  9 +++++++++
 4 files changed, 53 insertions(+)

diff --git a/qapi/misc.json b/qapi/misc.json
index a7fba7230cfa..e7475f30a844 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -1194,6 +1194,33 @@
 ##
 { 'command': 'query-memory-size-summary', 'returns': 'MemoryInfo' }
 
+##
+# @MemoryChecksum:
+#
+# A string with MD5 checksum of all RAMBlocks.
+#
+# @checksum: the checksum.
+#
+# Since: 3.2.0
+##
+{ 'struct': 'MemoryChecksum',
+  'data'  : { 'checksum': 'str' } }
+
+##
+# @query-memory-checksum:
+#
+# Return the MD5 checksum of all RAMBlocks.
+#
+# Example:
+#
+# -> { "execute": "query-memory-checksum" }
+# <- { "return": { "checksum": "a0880304994f64cb2edad77b9a1cd58f" } }
+#
+# Since: 3.2.0
+##
+{ 'command': 'query-memory-checksum',
+  'returns': 'MemoryChecksum' }
+
 
 ##
 # @AddfdInfo:
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index f7dbe75fbc38..15dbf18c2d5d 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -57,6 +57,7 @@ void qemu_ram_set_idstr(RAMBlock *block, const char *name, DeviceState *dev);
 void qemu_ram_unset_idstr(RAMBlock *block);
 const char *qemu_ram_get_idstr(RAMBlock *rb);
 void *qemu_ram_get_host_addr(RAMBlock *rb);
+gchar *qemu_ram_chksum(void);
 ram_addr_t qemu_ram_get_offset(RAMBlock *rb);
 ram_addr_t qemu_ram_get_used_length(RAMBlock *rb);
 bool qemu_ram_is_shared(RAMBlock *rb);
diff --git a/exec.c b/exec.c
index 3e78de3b8f8b..76f7f63cf71b 100644
--- a/exec.c
+++ b/exec.c
@@ -2050,6 +2050,22 @@ void *qemu_ram_get_host_addr(RAMBlock *rb)
     return rb->host;
 }
 
+gchar *qemu_ram_chksum(void)
+{
+    struct RAMBlock *rb;
+    GChecksum *chksum = g_checksum_new(G_CHECKSUM_MD5);
+    gchar *ret;
+
+    RAMBLOCK_FOREACH(rb) {
+        g_checksum_update(chksum, qemu_ram_get_host_addr(rb),
+                          qemu_ram_get_used_length(rb));
+    }
+    ret = g_strdup(g_checksum_get_string(chksum));
+    g_checksum_free(chksum);
+
+    return ret;
+}
+
 ram_addr_t qemu_ram_get_offset(RAMBlock *rb)
 {
     return rb->offset;
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index b9ae40eec751..ec52bd82588e 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -413,3 +413,12 @@ MemoryInfo *qmp_query_memory_size_summary(Error **errp)
 
     return mem_info;
 }
+
+MemoryChecksum *qmp_query_memory_checksum(Error **errp)
+{
+    MemoryChecksum *chk = g_malloc0(sizeof(MemoryChecksum));
+
+    chk->checksum = qemu_ram_chksum();
+
+    return chk;
+}
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-08-26  4:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22  1:16 [Qemu-devel] [RFC PATCH qemu] qapi: Add query-memory-checksum Alexey Kardashevskiy
2019-08-22  1:33 ` Eric Blake
2019-08-22  3:20   ` Alexey Kardashevskiy
2019-08-22 14:16 ` Markus Armbruster
2019-08-22 14:49   ` Daniel P. Berrangé
2019-08-23  5:49     ` Markus Armbruster
2019-08-23  9:23       ` Daniel P. Berrangé
2019-08-23 11:41         ` Markus Armbruster
2019-08-26  4:28           ` Alexey Kardashevskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).