[PATCH v4 2/3] add qemu support to virDomainCoreDumpWithFormat API

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

 



This patch makes qemu driver supprot virDomainCoreDumpWithFormat API.
---
 src/qemu/qemu_driver.c       | 45 +++++++++++++++++++++++++++++++++++---------
 src/qemu/qemu_monitor.c      |  7 ++++---
 src/qemu/qemu_monitor.h      |  3 ++-
 src/qemu/qemu_monitor_json.c |  4 +++-
 src/qemu/qemu_monitor_json.h |  3 ++-
 tests/qemumonitorjsontest.c  |  2 +-
 6 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c9a865e..f373f7c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3391,7 +3391,8 @@ cleanup:
 }
 
 static int qemuDumpToFd(virQEMUDriverPtr driver, virDomainObjPtr vm,
-                        int fd, enum qemuDomainAsyncJob asyncJob)
+                        int fd, enum qemuDomainAsyncJob asyncJob,
+                        const char* memory_dump_format)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     int ret = -1;
@@ -3411,7 +3412,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, memory_dump_format);
     qemuDomainObjExitMonitor(driver, vm);
 
     return ret;
@@ -3422,13 +3423,15 @@ doCoreDump(virQEMUDriverPtr driver,
            virDomainObjPtr vm,
            const char *path,
            virQEMUSaveFormat compress,
-           unsigned int dump_flags)
+           unsigned int dump_flags,
+           unsigned int dumpformat)
 {
     int fd = -1;
     int ret = -1;
     virFileWrapperFdPtr wrapperFd = NULL;
     int directFlag = 0;
     unsigned int flags = VIR_FILE_WRAPPER_NON_BLOCKING;
+    const char *memory_dump_format = NULL;
 
     /* Create an empty file with appropriate ownership.  */
     if (dump_flags & VIR_DUMP_BYPASS_CACHE) {
@@ -3452,7 +3455,20 @@ doCoreDump(virQEMUDriverPtr driver,
         goto cleanup;
 
     if (dump_flags & VIR_DUMP_MEMORY_ONLY) {
-        ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP);
+        if (dumpformat == VIR_DUMP_FORMAT_RAW)
+            memory_dump_format = "elf";
+        else if (dumpformat == VIR_DUMP_FORMAT_KDUMP_ZLIB)
+            memory_dump_format = "kdump-zlib";
+        else if (dumpformat == VIR_DUMP_FORMAT_KDUMP_LZO)
+            memory_dump_format = "kdump-lzo";
+        else if (dumpformat == VIR_DUMP_FORMAT_KDUMP_SNAPPY)
+            memory_dump_format = "kdump-snappy";
+        else {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("unknown dumpformat '%d'"), dumpformat);
+        }
+        ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
+                           memory_dump_format);
     } else {
         ret = qemuMigrationToFile(driver, vm, fd, 0, path,
                                   qemuCompressProgramName(compress), false,
@@ -3515,8 +3531,9 @@ cleanup:
     return ret;
 }
 
-static int qemuDomainCoreDump(virDomainPtr dom,
+static int qemuDomainCoreDumpWithFormat(virDomainPtr dom,
                               const char *path,
+                              unsigned int dumpformat,
                               unsigned int flags)
 {
     virQEMUDriverPtr driver = dom->conn->privateData;
@@ -3533,7 +3550,7 @@ static int qemuDomainCoreDump(virDomainPtr dom,
     if (!(vm = qemuDomObjFromDomain(dom)))
         return -1;
 
-    if (virDomainCoreDumpEnsureACL(dom->conn, vm->def) < 0)
+    if (virDomainCoreDumpWithFormatEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
     if (qemuDomainObjBeginAsyncJob(driver, vm,
@@ -3565,7 +3582,8 @@ static int qemuDomainCoreDump(virDomainPtr dom,
         }
     }
 
-    ret = doCoreDump(driver, vm, path, getCompressionType(driver), flags);
+    ret = doCoreDump(driver, vm, path, getCompressionType(driver), flags,
+                     dumpformat);
     if (ret < 0)
         goto endjob;
 
@@ -3619,6 +3637,13 @@ cleanup:
     return ret;
 }
 
+static int qemuDomainCoreDump(virDomainPtr dom,
+                              const char *path,
+                              unsigned int flags)
+{
+    return qemuDomainCoreDumpWithFormat(dom, path, VIR_DUMP_FORMAT_RAW, flags);
+}
+
 static char *
 qemuDomainScreenshot(virDomainPtr dom,
                      virStreamPtr st,
@@ -3742,7 +3767,8 @@ static void processWatchdogEvent(virQEMUDriverPtr driver, virDomainObjPtr vm, in
 
             flags |= cfg->autoDumpBypassCache ? VIR_DUMP_BYPASS_CACHE: 0;
             ret = doCoreDump(driver, vm, dumpfile,
-                             getCompressionType(driver), flags);
+                             getCompressionType(driver), flags,
+                             VIR_DUMP_FORMAT_RAW);
             if (ret < 0)
                 virReportError(VIR_ERR_OPERATION_FAILED,
                                "%s", _("Dump failed"));
@@ -3806,7 +3832,7 @@ doCoreDumpToAutoDumpPath(virQEMUDriverPtr driver,
 
     flags |= cfg->autoDumpBypassCache ? VIR_DUMP_BYPASS_CACHE: 0;
     ret = doCoreDump(driver, vm, dumpfile,
-                     getCompressionType(driver), flags);
+                     getCompressionType(driver), flags, VIR_DUMP_FORMAT_RAW);
     if (ret < 0)
         virReportError(VIR_ERR_OPERATION_FAILED,
                        "%s", _("Dump failed"));
@@ -16610,6 +16636,7 @@ static virDriver qemuDriver = {
     .domainSaveImageGetXMLDesc = qemuDomainSaveImageGetXMLDesc, /* 0.9.4 */
     .domainSaveImageDefineXML = qemuDomainSaveImageDefineXML, /* 0.9.4 */
     .domainCoreDump = qemuDomainCoreDump, /* 0.7.0 */
+    .domainCoreDumpWithFormat = qemuDomainCoreDumpWithFormat, /* 1.2.3 */
     .domainScreenshot = qemuDomainScreenshot, /* 0.9.2 */
     .domainSetVcpus = qemuDomainSetVcpus, /* 0.4.4 */
     .domainSetVcpusFlags = qemuDomainSetVcpusFlags, /* 0.8.5 */
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a2769db..bcb457f 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2345,10 +2345,11 @@ int qemuMonitorMigrateCancel(qemuMonitorPtr mon)
 }
 
 int
-qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd)
+qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd, const char* memory_dump_format)
 {
     int ret;
-    VIR_DEBUG("mon=%p fd=%d", mon, fd);
+    VIR_DEBUG("mon=%p fd=%d memory_dump_format=%s", mon, fd,
+              memory_dump_format);
 
     if (!mon) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -2368,7 +2369,7 @@ qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd)
     if (qemuMonitorSendFileHandle(mon, "dump", fd) < 0)
         return -1;
 
-    ret = qemuMonitorJSONDump(mon, "fd:dump");
+    ret = qemuMonitorJSONDump(mon, "fd:dump", memory_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..a6fc8ee 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* memory_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..f77b35a 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 *memory_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", memory_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..af6f666 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 *memory_dump_format);
 
 int qemuMonitorJSONGraphicsRelocate(qemuMonitorPtr mon,
                                     int type,
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index d7da5a8..f21de84 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_memory_dump_format")
 GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE,
               "localhost", 12345, 12346, NULL)
 GEN_TEST_FUNC(qemuMonitorJSONAddNetdev, "some_dummy_netdevstr")
-- 
1.8.5.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]