From e4c48e02b4a7b4e49ee55ed62c65794d419a0b64 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Wed, 22 Jul 2009 16:27:09 +0200 Subject: [PATCH] Add support for physical memory access for QEmu * include/libvirt/libvirt.h include/libvirt/libvirt.h.in: adds the new flag VIR_MEMORY_PHYSICAL for virDomainMemoryPeek * src/libvirt.c: update the front-end checking * src/qemu_driver.c: extend the QEmu driver --- include/libvirt/libvirt.h | 1 + include/libvirt/libvirt.h.in | 1 + src/libvirt.c | 14 ++++++++------ src/qemu_driver.c | 15 ++++++++++----- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index 90007a1808..86f56e59ad 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -619,6 +619,7 @@ int virDomainBlockPeek (virDomainPtr dom, /* Memory peeking flags. */ typedef enum { VIR_MEMORY_VIRTUAL = 1, /* addresses are virtual addresses */ + VIR_MEMORY_PHYSICAL = 2, /* addresses are physical addresses */ } virDomainMemoryFlags; int virDomainMemoryPeek (virDomainPtr dom, diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index ba2b6f043e..e6536c78d0 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -619,6 +619,7 @@ int virDomainBlockPeek (virDomainPtr dom, /* Memory peeking flags. */ typedef enum { VIR_MEMORY_VIRTUAL = 1, /* addresses are virtual addresses */ + VIR_MEMORY_PHYSICAL = 2, /* addresses are physical addresses */ } virDomainMemoryFlags; int virDomainMemoryPeek (virDomainPtr dom, diff --git a/src/libvirt.c b/src/libvirt.c index 7463c06f5c..0e6d88f552 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -3813,19 +3813,20 @@ virDomainMemoryPeek (virDomainPtr dom, goto error; } - /* Flags must be VIR_MEMORY_VIRTUAL at the moment. - * - * Note on access to physical memory: A VIR_MEMORY_PHYSICAL flag is + /* Note on access to physical memory: A VIR_MEMORY_PHYSICAL flag is * a possibility. However it isn't really useful unless the caller * can also access registers, particularly CR3 on x86 in order to * get the Page Table Directory. Since registers are different on * every architecture, that would imply another call to get the * machine registers. * - * The QEMU driver handles only VIR_MEMORY_VIRTUAL, mapping it + * The QEMU driver handles VIR_MEMORY_VIRTUAL, mapping it * to the qemu 'memsave' command which does the virtual to physical * mapping inside qemu. * + * The QEMU driver also handles VIR_MEMORY_PHYSICAL, mapping it + * to the qemu 'pmemsave' command. + * * At time of writing there is no Xen driver. However the Xen * hypervisor only lets you map physical pages from other domains, * and so the Xen driver would have to do the virtual to physical @@ -3834,9 +3835,10 @@ virDomainMemoryPeek (virDomainPtr dom, * which does this, although we cannot copy this code directly * because of incompatible licensing. */ - if (flags != VIR_MEMORY_VIRTUAL) { + + if (flags != VIR_MEMORY_VIRTUAL && flags != VIR_MEMORY_PHYSICAL) { virLibDomainError (dom, VIR_ERR_INVALID_ARG, - _("flags parameter must be VIR_MEMORY_VIRTUAL")); + _("flags parameter must be VIR_MEMORY_VIRTUAL or VIR_MEMORY_PHYSICAL")); goto error; } diff --git a/src/qemu_driver.c b/src/qemu_driver.c index 3de2ee0fc6..c4683ae2d2 100644 --- a/src/qemu_driver.c +++ b/src/qemu_driver.c @@ -5463,9 +5463,9 @@ qemudDomainMemoryPeek (virDomainPtr dom, goto cleanup; } - if (flags != VIR_MEMORY_VIRTUAL) { + if (flags != VIR_MEMORY_VIRTUAL && flags != VIR_MEMORY_PHYSICAL) { qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_ARG, - "%s", _("QEMU driver only supports virtual memory addrs")); + "%s", _("flags parameter must be VIR_MEMORY_VIRTUAL or VIR_MEMORY_PHYSICAL")); goto cleanup; } @@ -5482,15 +5482,20 @@ qemudDomainMemoryPeek (virDomainPtr dom, goto cleanup; } - /* Issue the memsave command. */ - snprintf (cmd, sizeof cmd, "memsave %llu %zi \"%s\"", offset, size, tmp); + 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; } - DEBUG ("%s: memsave reply: %s", vm->def->name, info); + DEBUG ("%s: (p)memsave reply: %s", vm->def->name, info); /* Read the memory file into buffer. */ if (saferead (fd, buffer, size) == (ssize_t) -1) {