]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: implement qemu's dump-guest-memory
authorWen Congyang <wency@cn.fujitsu.com>
Tue, 12 Jun 2012 03:04:51 +0000 (11:04 +0800)
committerWen Congyang <wency@cn.fujitsu.com>
Fri, 15 Jun 2012 12:36:14 +0000 (20:36 +0800)
dump-guest-memory is a new dump mechanism, and it can work when the
guest uses host devices. This patch adds a API to use this new
monitor command.
We will always use json mode if qemu's version is >= 0.15, so I
don't implement the API for text mode.

src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index 007e7b9613124a8ae841adefef5573594d28af6c..b8a2f2fbcd6465bd93f3c1d73dd3e204a0109be4 100644 (file)
@@ -2017,6 +2017,43 @@ int qemuMonitorMigrateCancel(qemuMonitorPtr mon)
     return ret;
 }
 
+int qemuMonitorDumpToFd(qemuMonitorPtr mon,
+                        unsigned int flags,
+                        int fd,
+                        unsigned long long begin,
+                        unsigned long long length)
+{
+    int ret;
+    VIR_DEBUG("mon=%p fd=%d flags=%x begin=%llx length=%llx",
+              mon, fd, flags, begin, length);
+
+    if (!mon) {
+        qemuReportError(VIR_ERR_INVALID_ARG, "%s",
+                        _("monitor must not be NULL"));
+        return -1;
+    }
+
+    if (!mon->json) {
+        /* We don't have qemuMonitorTextDump(), so we should check mon->json
+         * here.
+         */
+        qemuReportError(VIR_ERR_NO_SUPPORT, "%s",
+                        _("dump-guest-memory is not supported in text mode"));
+        return -1;
+    }
+
+    if (qemuMonitorSendFileHandle(mon, "dump", fd) < 0)
+        return -1;
+
+    ret = qemuMonitorJSONDump(mon, flags, "fd:dump", begin, length);
+
+    if (ret < 0) {
+        if (qemuMonitorCloseFileHandle(mon, "dump") < 0)
+            VIR_WARN("failed to close dumping handle");
+    }
+
+    return ret;
+}
 
 int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
                                 int type,
index ffe8fe7ff99ac49dd35d8d6cf245c21a5f6a97f1..66bec38982bcac2afb931f52a6d2d3c3eee03ff4 100644 (file)
@@ -379,6 +379,18 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
 
 int qemuMonitorMigrateCancel(qemuMonitorPtr mon);
 
+typedef enum {
+  QEMU_MONITOR_DUMP_HAVE_FILTER  = 1 << 0,
+  QEMU_MONITOR_DUMP_PAGING       = 1 << 1,
+  QEMU_MONITOR_DUMP_FLAGS_LAST
+} QEMU_MONITOR_DUMP;
+
+int qemuMonitorDumpToFd(qemuMonitorPtr mon,
+                        unsigned int flags,
+                        int fd,
+                        unsigned long long begin,
+                        unsigned long long length);
+
 int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
                                 int type,
                                 const char *hostname,
index 90303479f596afbb2b9b8108b39ec1341fcfd362..6ca01c5a188612af788d69cef26401628370979e 100644 (file)
@@ -2465,6 +2465,40 @@ int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
     return ret;
 }
 
+int qemuMonitorJSONDump(qemuMonitorPtr mon,
+                        unsigned int flags,
+                        const char *protocol,
+                        unsigned long long begin,
+                        unsigned long long length)
+{
+    int ret;
+    virJSONValuePtr cmd = NULL;
+    virJSONValuePtr reply = NULL;
+
+    if (flags & QEMU_MONITOR_DUMP_HAVE_FILTER)
+        cmd = qemuMonitorJSONMakeCommand("dump-guest-memory",
+                                         "b:paging", flags & QEMU_MONITOR_DUMP_PAGING ? 1 : 0,
+                                         "s:protocol", protocol,
+                                         "U:begin", begin,
+                                         "U:length", length,
+                                         NULL);
+    else
+        cmd = qemuMonitorJSONMakeCommand("dump-guest-memory",
+                                         "b:paging", flags & QEMU_MONITOR_DUMP_PAGING ? 1 : 0,
+                                         "s:protocol", protocol,
+                                         NULL);
+    if (!cmd)
+        return -1;
+
+    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
+
+    if (ret == 0)
+        ret = qemuMonitorJSONCheckError(cmd, reply);
+
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    return ret;
+}
 
 int qemuMonitorJSONGraphicsRelocate(qemuMonitorPtr mon,
                                     int type,
index 22a3adff5bb4502e01225c704183795392cb8592..e8bd9b8841c6ee846f2693022c2566e0305f180e 100644 (file)
@@ -136,6 +136,12 @@ int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
 
 int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon);
 
+int qemuMonitorJSONDump(qemuMonitorPtr mon,
+                        unsigned int flags,
+                        const char *protocol,
+                        unsigned long long begin,
+                        unsigned long long length);
+
 int qemuMonitorJSONGraphicsRelocate(qemuMonitorPtr mon,
                                     int type,
                                     const char *hostname,