* src/qemu/qemu_monitor.h, src/qemu/qemu_monitor.c: Add new APIs
qemuMonitorSaveVirtualMemory() and qemuMonitorSavePhysicalMemory()
* src/qemu/qemu_driver.c: Use the new qemuMonitorSaveVirtualMemory()
and qemuMonitorSavePhysicalMemory() APIs
---
src/qemu/qemu_driver.c | 21 ++++-----------
src/qemu/qemu_monitor_text.c | 54 ++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_text.h | 10 +++++++
3 files changed, 70 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b15dc03..9c09024 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6233,7 +6233,6 @@ qemudDomainMemoryPeek (virDomainPtr dom,
{
struct qemud_driver *driver = dom->conn->privateData;
virDomainObjPtr vm;
- char cmd[256], *info = NULL;
char *tmp = NULL;
int fd = -1, ret = -1;
@@ -6273,21 +6272,14 @@ qemudDomainMemoryPeek (virDomainPtr dom,
goto cleanup;
}
- if (flags == VIR_MEMORY_VIRTUAL)
- /* Issue the memsave command. */
- snprintf (cmd, sizeof cmd, "memsave %llu %zi \"%s\"", offset,
size, tmp);
- else
- /* Issue the pmemsave command. */
- snprintf (cmd, sizeof cmd, "pmemsave %llu %zi \"%s\"",
offset, size, tmp);
-
- if (qemudMonitorCommand (vm, cmd, &info) < 0) {
- qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
- "%s", _("'memsave' command
failed"));
- goto cleanup;
+ if (flags == VIR_MEMORY_VIRTUAL) {
+ if (qemuMonitorSaveVirtualMemory(vm, offset, size, tmp) < 0)
+ goto cleanup;
+ } else {
+ if (qemuMonitorSavePhysicalMemory(vm, offset, size, tmp) < 0)
+ goto cleanup;
}
- DEBUG ("%s: (p)memsave reply: %s", vm->def->name, info);
-
/* Read the memory file into buffer. */
if (saferead (fd, buffer, size) == (ssize_t) -1) {
virReportSystemError (dom->conn, errno,
@@ -6300,7 +6292,6 @@ qemudDomainMemoryPeek (virDomainPtr dom,
cleanup:
VIR_FREE(tmp);
- VIR_FREE(info);
if (fd >= 0) close (fd);
unlink (tmp);
if (vm)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 8be8047..a5f43c5 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -810,3 +810,57 @@ cleanup:
return ret;
}
+static int qemuMonitorSaveMemory(const virDomainObjPtr vm,
+ const char *cmdtype,
+ unsigned long long offset,
+ size_t length,
+ const char *path)
+{
+ char *cmd = NULL;
+ char *reply = NULL;
+ char *safepath = NULL;
+ int ret = -1;
+
+ if (!(safepath = qemudEscapeMonitorArg(path))) {
+ virReportOOMError(NULL);
+ goto cleanup;
+ }
+
+ if (virAsprintf(&cmd, "%s %llu %zi \"%s\"", cmdtype, offset,
length, safepath) < 0) {
+ virReportOOMError(NULL);
+ goto cleanup;
+ }
+
+ if (qemudMonitorCommand(vm, cmd, &reply) < 0) {
+ qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+ _("could save memory region to '%s'"), path);
+ goto cleanup;
+ }
+
+ /* XXX what is printed on failure ? */
+
+ ret = 0;
+
+cleanup:
+ VIR_FREE(cmd);
+ VIR_FREE(reply);
+ VIR_FREE(safepath);
+ return ret;
+}
+
+
+int qemuMonitorSaveVirtualMemory(const virDomainObjPtr vm,
+ unsigned long long offset,
+ size_t length,
+ const char *path)
+{
+ return qemuMonitorSaveMemory(vm, "memsave", offset, length, path);
+}
+
+int qemuMonitorSavePhysicalMemory(const virDomainObjPtr vm,
+ unsigned long long offset,
+ size_t length,
+ const char *path)
+{
+ return qemuMonitorSaveMemory(vm, "pmemsave", offset, length, path);
+}
diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h
index d05dea1..dfe3445 100644
--- a/src/qemu/qemu_monitor_text.h
+++ b/src/qemu/qemu_monitor_text.h
@@ -91,4 +91,14 @@ int qemuMonitorChangeMedia(const virDomainObjPtr vm,
const char *devname,
const char *newmedia);
+
+int qemuMonitorSaveVirtualMemory(const virDomainObjPtr vm,
+ unsigned long long offset,
+ size_t length,
+ const char *path);
+int qemuMonitorSavePhysicalMemory(const virDomainObjPtr vm,
+ unsigned long long offset,
+ size_t length,
+ const char *path);
+
#endif /* QEMU_MONITOR_TEXT_H */
--
1.6.2.5