This patch is used to add "--compress" and "[--compression-format]
<string>" to
"virsh dump --memory-only". And "virsh dump --memory-only" is going
be
implemented by new virDomainCoreDumpWithFormat API.
Signed-off-by: Qiao Nuohan <qiaonuohan(a)cn.fujitsu.com>
---
tools/virsh-domain.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 2e3f0ed..70613e5 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4486,6 +4486,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}
};
@@ -4501,6 +4509,9 @@ doDump(void *opaque)
const char *name = NULL;
const char *to = NULL;
unsigned int flags = 0;
+ bool optCompress;
+ const char *compression_format = NULL;
+ unsigned int memory_dump_format = VIR_DUMP_FORMAT_RAW;
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT);
@@ -4524,7 +4535,39 @@ doDump(void *opaque)
if (vshCommandOptBool(cmd, "memory-only"))
flags |= VIR_DUMP_MEMORY_ONLY;
- if (virDomainCoreDump(dom, to, flags) < 0) {
+ 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"))
+ memory_dump_format = VIR_DUMP_FORMAT_KDUMP_ZLIB;
+ else if (STREQ(compression_format, "lzo"))
+ memory_dump_format = VIR_DUMP_FORMAT_KDUMP_LZO;
+ else if (STREQ(compression_format, "snappy"))
+ memory_dump_format = VIR_DUMP_FORMAT_KDUMP_SNAPPY;
+ else {
+ vshError(ctl, _("compression format '%s' is not supported,
"
+ "expecting 'zlib', 'lzo' or
'snappy'."),
+ compression_format);
+ goto out;
+ }
+ } else {
+ if (optCompress)
+ memory_dump_format = VIR_DUMP_FORMAT_KDUMP_ZLIB;
+ }
+
+ if (virDomainCoreDumpWithFormat(dom, to, memory_dump_format, flags) < 0) {
vshError(ctl, _("Failed to core dump domain %s to %s"), name, to);
goto out;
}
--
1.8.5.3