[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v3 3/4] allow "virsh dump --memory-only" specify dump format



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 virDomainMemoryDump API.

Signed-off-by: Qiao Nuohan <qiaonuohan cn fujitsu com>
---
 tools/virsh-domain.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 2e3f0ed..14ef612 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 = 0;
 
     sigemptyset(&sigmask);
     sigaddset(&sigmask, SIGINT);
@@ -4524,11 +4535,51 @@ doDump(void *opaque)
     if (vshCommandOptBool(cmd, "memory-only"))
         flags |= VIR_DUMP_MEMORY_ONLY;
 
-    if (virDomainCoreDump(dom, to, flags) < 0) {
-        vshError(ctl, _("Failed to core dump domain %s to %s"), name, to);
+    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_MEMORY_DUMP_COMPRESS_ZLIB;
+        else if (STREQ(compression_format, "lzo"))
+            memory_dump_format = VIR_MEMORY_DUMP_COMPRESS_LZO;
+        else if (STREQ(compression_format, "snappy"))
+            memory_dump_format = VIR_MEMORY_DUMP_COMPRESS_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_MEMORY_DUMP_COMPRESS_ZLIB;
+    }
+
+    if (flags & VIR_DUMP_MEMORY_ONLY) {
+        if (virDomainMemoryDump(dom, to, flags, memory_dump_format) < 0) {
+            vshError(ctl, _("Failed to dump the memory of domain %s to %s"),
+                     name, to);
+            goto out;
+        }
+    } else {
+        if (virDomainCoreDump(dom, to, flags) < 0) {
+            vshError(ctl, _("Failed to core dump domain %s to %s"), name, to);
+            goto out;
+        }
+    }
+
     ret = '0';
 out:
     pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
-- 
1.8.5.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]