From: Qiao Nuohan qiaonuo...@cn.fujitsu.com
Make monitor command 'dump-guest-memory' be able to dump in kdump-compressed
format. The command's usage:
dump [-p] protocol [begin] [length] [format]
'format' is used to specified the format of vmcore and can be:
1. 'elf': ELF format, without compression
2. 'zlib': kdump-compressed format, with zlib-compressed
3. 'lzo': kdump-compressed format, with lzo-compressed
4. 'snappy': kdump-compressed format, with snappy-compressed
And without 'format' being set, it is same as 'elf'.
Note:
1. The kdump-compressed format is readable only with the crash utility, and
it can be smaller than the ELF format because of the compression support.
2. The kdump-compressed format is the 5th edition.
Signed-off-by: Qiao Nuohan qiaonuo...@cn.fujitsu.com
Signed-off-by: Zhang Xiaohe zhan...@cn.fujitsu.com
---
configure| 50
dump.c | 102 +-
hmp-commands.hx | 12 +++--
hmp.c| 23 +-
include/sysemu/dump_memory.h |1 +
qapi-schema.json | 22 +-
qmp-commands.hx |6 ++-
7 files changed, 197 insertions(+), 19 deletions(-)
diff --git a/configure b/configure
index eb74510..5f459a5 100755
--- a/configure
+++ b/configure
@@ -230,6 +230,8 @@ libusb=
usb_redir=
glx=
zlib=yes
+lzo=no
+snappy=no
guest_agent=yes
want_tools=yes
libiscsi=
@@ -902,6 +904,10 @@ for opt do
;;
--disable-zlib-test) zlib=no
;;
+ --enable-lzo) lzo=yes
+ ;;
+ --enable-snappy) snappy=yes
+ ;;
--enable-guest-agent) guest_agent=yes
;;
--disable-guest-agent) guest_agent=no
@@ -1499,6 +1505,42 @@ fi
libs_softmmu=$libs_softmmu -lz
##
+# lzo check
+
+if test $lzo != no ; then
+cat $TMPC EOF
+#include lzo/lzo1x.h
+int main(void) { lzo_version(); return 0; }
+EOF
+if compile_prog -llzo2 ; then
+:
+else
+error_exit lzo check failed \
+Make sure to have the lzo libs and headers installed.
+fi
+
+libs_softmmu=$libs_softmmu -llzo2
+fi
+
+##
+# snappy check
+
+if test $snappy != no ; then
+cat $TMPC EOF
+#include snappy-c.h
+int main(void) { snappy_max_compressed_length(4096); return 0; }
+EOF
+if compile_prog -lsnappy ; then
+:
+else
+error_exit snappy check failed \
+Make sure to have the snappy libs and headers installed.
+fi
+
+libs_softmmu=$libs_softmmu -lsnappy
+fi
+
+##
# libseccomp check
if test $seccomp != no ; then
@@ -3901,6 +3943,14 @@ if test $glx = yes ; then
echo GLX_LIBS=$glx_libs $config_host_mak
fi
+if test $lzo = yes ; then
+ echo CONFIG_LZO=y $config_host_mak
+fi
+
+if test $snappy = yes ; then
+ echo CONFIG_SNAPPY=y $config_host_mak
+fi
+
if test $libiscsi = yes ; then
echo CONFIG_LIBISCSI=y $config_host_mak
fi
diff --git a/dump.c b/dump.c
index 17686ad..274249f 100644
--- a/dump.c
+++ b/dump.c
@@ -1036,6 +1036,16 @@ static int create_header64(DumpState *s)
return 0;
}
+static void get_max_mapnr(DumpState *s)
+{
+MemoryMapping *memory_mapping;
+
+QTAILQ_FOREACH(memory_mapping, s-list.head, next) {
+s-max_mapnr = paddr_to_pfn(memory_mapping-phys_addr +
+memory_mapping-length, s-page_shift);
+}
+}
+
/*
* gather data of header and sub header
*/
@@ -1404,12 +1414,14 @@ out:
return ret;
}
-static int dump_init(DumpState *s, int fd, bool paging, bool has_filter,
- int64_t begin, int64_t length, Error **errp)
+static int dump_init(DumpState *s, int fd, bool has_format,
+DumpGuestMemoryFormat format, bool paging, bool has_filter,
+int64_t begin, int64_t length, Error **errp)
{
CPUArchState *env;
int nr_cpus;
int ret;
+unsigned long tmp;
if (runstate_is_running()) {
vm_stop(RUN_STATE_SAVE_VM);
@@ -1464,6 +1476,56 @@ static int dump_init(DumpState *s, int fd, bool paging,
bool has_filter,
qemu_get_guest_simple_memory_mapping(s-list);
}
+/* init for kdump-compressed format */
+if (has_format format != DUMP_GUEST_MEMORY_FORMAT_ELF) {
+switch (format) {
+case DUMP_GUEST_MEMORY_FORMAT_ZLIB:
+s-flag_compress = DUMP_DH_COMPRESSED_ZLIB;
+break;
+case DUMP_GUEST_MEMORY_FORMAT_LZO:
+s-flag_compress = DUMP_DH_COMPRESSED_LZO;
+break;
+case DUMP_GUEST_MEMORY_FORMAT_SNAPPY:
+s-flag_compress = DUMP_DH_COMPRESSED_SNAPPY;
+break;
+default:
+s-flag_compress = 0;
+}
+
+s-nr_cpus = nr_cpus;
+s-page_size = PAGE_SIZE;
+s-page_shift = ffs(s-page_size) - 1;
+
+get_max_mapnr(s);
+
+tmp = divideup(divideup(s-max_mapnr,