提交 316e9f90 编写于 作者: D Daniel P. Berrange

Add APIs for issuing 'memsave' and 'pmemsave' monitor commands

* 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
上级 6d9c4758
......@@ -6232,7 +6232,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;
......@@ -6272,21 +6271,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"));
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,
......@@ -6299,7 +6291,6 @@ qemudDomainMemoryPeek (virDomainPtr dom,
cleanup:
VIR_FREE(tmp);
VIR_FREE(info);
if (fd >= 0) close (fd);
unlink (tmp);
if (vm)
......
......@@ -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);
}
......@@ -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 */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册