--memory-only option is introduced without compression supported. Therefore,
this is a freature regression of virsh dump. Now qemu has support dumping memory
in kdump-compressed format. This patch is used to add "--compress" and
"[--compression-format] <string>" to "virsh dump --memory-only"
and send
dump-guest-memory command to qemu with dump format specified to one of elf,
kdump-zlib, kdump-lzo and kdump-snappy.
Signed-off-by: Qiao Nuohan <qiaonuohan(a)cn.fujitsu.com>
---
include/libvirt/libvirt.h.in | 19 ++++++++++++++-----
src/qemu/qemu_driver.c | 20 ++++++++++++++++----
src/qemu/qemu_monitor.c | 6 +++---
src/qemu/qemu_monitor.h | 3 ++-
src/qemu/qemu_monitor_json.c | 4 +++-
src/qemu/qemu_monitor_json.h | 3 ++-
tests/qemumonitorjsontest.c | 2 +-
tools/virsh-domain.c | 42 ++++++++++++++++++++++++++++++++++++++++++
8 files changed, 83 insertions(+), 16 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 295d551..df62918 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1173,11 +1173,20 @@ typedef virDomainMemoryStatStruct *virDomainMemoryStatPtr;
/* Domain core dump flags. */
typedef enum {
- VIR_DUMP_CRASH = (1 << 0), /* crash after dump */
- VIR_DUMP_LIVE = (1 << 1), /* live dump */
- VIR_DUMP_BYPASS_CACHE = (1 << 2), /* avoid file system cache pollution */
- VIR_DUMP_RESET = (1 << 3), /* reset domain after dump finishes */
- VIR_DUMP_MEMORY_ONLY = (1 << 4), /* use dump-guest-memory */
+ VIR_DUMP_CRASH = (1 << 0), /* crash after dump */
+ VIR_DUMP_LIVE = (1 << 1), /* live dump */
+ VIR_DUMP_BYPASS_CACHE = (1 << 2), /* avoid file system cache pollution */
+ VIR_DUMP_RESET = (1 << 3), /* reset domain after dump finishes */
+ VIR_DUMP_MEMORY_ONLY = (1 << 4), /* use dump-guest-memory */
+ VIR_DUMP_COMPRESS_ZLIB = (1 << 5), /* dump guest memory in
+ kdump-compressed format, with
+ zlib-compressed */
+ VIR_DUMP_COMPRESS_LZO = (1 << 6), /* dump guest memory in
+ kdump-compressed format, with
+ lzo-compressed */
+ VIR_DUMP_COMPRESS_SNAPPY = (1 << 7), /* dump guest memory in
+ kdump-compressed format, with
+ snappy-compressed */
} virDomainCoreDumpFlags;
/* Domain migration flags. */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 59e018d..19b4dd2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3383,7 +3383,8 @@ cleanup:
}
static int qemuDumpToFd(virQEMUDriverPtr driver, virDomainObjPtr vm,
- int fd, enum qemuDomainAsyncJob asyncJob)
+ int fd, enum qemuDomainAsyncJob asyncJob,
+ const char* dump_format)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
int ret = -1;
@@ -3403,7 +3404,7 @@ static int qemuDumpToFd(virQEMUDriverPtr driver,
virDomainObjPtr vm,
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1;
- ret = qemuMonitorDumpToFd(priv->mon, fd);
+ ret = qemuMonitorDumpToFd(priv->mon, fd, dump_format);
qemuDomainObjExitMonitor(driver, vm);
return ret;
@@ -3421,6 +3422,7 @@ doCoreDump(virQEMUDriverPtr driver,
virFileWrapperFdPtr wrapperFd = NULL;
int directFlag = 0;
unsigned int flags = VIR_FILE_WRAPPER_NON_BLOCKING;
+ const char *dump_format;
/* Create an empty file with appropriate ownership. */
if (dump_flags & VIR_DUMP_BYPASS_CACHE) {
@@ -3444,7 +3446,16 @@ doCoreDump(virQEMUDriverPtr driver,
goto cleanup;
if (dump_flags & VIR_DUMP_MEMORY_ONLY) {
- ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP);
+ if (dump_flags & VIR_DUMP_COMPRESS_ZLIB)
+ dump_format = "kdump-zlib";
+ else if (dump_flags & VIR_DUMP_COMPRESS_LZO)
+ dump_format = "kdump-lzo";
+ else if (dump_flags & VIR_DUMP_COMPRESS_SNAPPY)
+ dump_format = "kdump-snappy";
+ else
+ dump_format = "elf";
+ ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
+ dump_format);
} else {
ret = qemuMigrationToFile(driver, vm, fd, 0, path,
qemuCompressProgramName(compress), false,
@@ -3520,7 +3531,8 @@ static int qemuDomainCoreDump(virDomainPtr dom,
virCheckFlags(VIR_DUMP_LIVE | VIR_DUMP_CRASH |
VIR_DUMP_BYPASS_CACHE | VIR_DUMP_RESET |
- VIR_DUMP_MEMORY_ONLY, -1);
+ VIR_DUMP_MEMORY_ONLY | VIR_DUMP_COMPRESS_ZLIB |
+ VIR_DUMP_COMPRESS_LZO | VIR_DUMP_COMPRESS_SNAPPY, -1);
if (!(vm = qemuDomObjFromDomain(dom)))
return -1;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a2769db..2722781 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2345,10 +2345,10 @@ int qemuMonitorMigrateCancel(qemuMonitorPtr mon)
}
int
-qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd)
+qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd, const char *dump_format)
{
int ret;
- VIR_DEBUG("mon=%p fd=%d", mon, fd);
+ VIR_DEBUG("mon=%p fd=%d dump_format=%s", mon, fd, dump_format);
if (!mon) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -2368,7 +2368,7 @@ qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd)
if (qemuMonitorSendFileHandle(mon, "dump", fd) < 0)
return -1;
- ret = qemuMonitorJSONDump(mon, "fd:dump");
+ ret = qemuMonitorJSONDump(mon, "fd:dump", dump_format);
if (ret < 0) {
if (qemuMonitorCloseFileHandle(mon, "dump") < 0)
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index eabf000..f2e5763 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -495,7 +495,8 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
int qemuMonitorMigrateCancel(qemuMonitorPtr mon);
int qemuMonitorDumpToFd(qemuMonitorPtr mon,
- int fd);
+ int fd,
+ const char *dump_format);
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
int type,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 5e825ac..7c9625f 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2636,7 +2636,8 @@ int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
int
qemuMonitorJSONDump(qemuMonitorPtr mon,
- const char *protocol)
+ const char *protocol,
+ const char *dump_format)
{
int ret;
virJSONValuePtr cmd = NULL;
@@ -2645,6 +2646,7 @@ qemuMonitorJSONDump(qemuMonitorPtr mon,
cmd = qemuMonitorJSONMakeCommand("dump-guest-memory",
"b:paging", false,
"s:protocol", protocol,
+ "s:format", dump_format,
NULL);
if (!cmd)
return -1;
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index a93c51e..7691356 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -148,7 +148,8 @@ int qemuMonitorJSONGetSpiceMigrationStatus(qemuMonitorPtr mon,
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon);
int qemuMonitorJSONDump(qemuMonitorPtr mon,
- const char *protocol);
+ const char *protocol,
+ const char *dump_format);
int qemuMonitorJSONGraphicsRelocate(qemuMonitorPtr mon,
int type,
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index d7da5a8..c02016f 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1154,7 +1154,7 @@ GEN_TEST_FUNC(qemuMonitorJSONSetMigrationDowntime, 1)
GEN_TEST_FUNC(qemuMonitorJSONMigrate, QEMU_MONITOR_MIGRATE_BACKGROUND |
QEMU_MONITOR_MIGRATE_NON_SHARED_DISK |
QEMU_MONITOR_MIGRATE_NON_SHARED_INC, "tcp:localhost:12345")
-GEN_TEST_FUNC(qemuMonitorJSONDump, "dummy_protocol")
+GEN_TEST_FUNC(qemuMonitorJSONDump, "dummy_protocol",
"dummy_dump_format")
GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE,
"localhost", 12345, 12346, NULL)
GEN_TEST_FUNC(qemuMonitorJSONAddNetdev, "some_dummy_netdevstr")
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index c3db94c..68e9d02 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4519,6 +4519,14 @@ static const vshCmdOptDef opts_dump[] = {
.type = VSH_OT_BOOL,
.help = N_("dump domain's memory only")
},
+ {.name = "compress",
+ .type = VSH_OT_BOOL,
+ .help = N_("make qemu dump domain's memory in kdump-compressed
format")
+ },
+ {.name = "compression-format",
+ .type = VSH_OT_DATA,
+ .help = N_("specify the compression format of kdump-compressed format")
+ },
{.name = NULL}
};
@@ -4533,6 +4541,8 @@ doDump(void *opaque)
sigset_t sigmask, oldsigmask;
const char *name = NULL;
const char *to = NULL;
+ bool optCompress;
+ const char *compression_format = NULL;
unsigned int flags = 0;
sigemptyset(&sigmask);
@@ -4557,6 +4567,38 @@ doDump(void *opaque)
if (vshCommandOptBool(cmd, "memory-only"))
flags |= VIR_DUMP_MEMORY_ONLY;
+ optCompress = vshCommandOptBool(cmd, "compress");
+ if (optCompress && !(flags & VIR_DUMP_MEMORY_ONLY)) {
+ vshError(ctl, "%s",
+ _("compress flag cannot be set without memory-only flag"));
+ goto out;
+ }
+
+ if (vshCommandOptString(cmd, "compression-format",
&compression_format)) {
+ if (!optCompress) {
+ vshError(ctl, "%s",
+ _("compression-format cannot be set without compress "
+ "flag"));
+ goto out;
+ }
+
+ if (STREQ(compression_format, "zlib"))
+ flags |= VIR_DUMP_COMPRESS_ZLIB;
+ else if (STREQ(compression_format, "lzo"))
+ flags |= VIR_DUMP_COMPRESS_LZO;
+ else if (STREQ(compression_format, "snappy"))
+ flags |= VIR_DUMP_COMPRESS_SNAPPY;
+ else {
+ vshError(ctl, _("compression format '%s' is not supported,
"
+ "expecting 'zlib', 'lzo' or
'snappy'."),
+ compression_format);
+ goto out;
+ }
+ } else {
+ if (optCompress)
+ flags |= VIR_DUMP_COMPRESS_ZLIB;
+ }
+
if (virDomainCoreDump(dom, to, flags) < 0) {
vshError(ctl, _("Failed to core dump domain %s to %s"), name, to);
goto out;