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
This commit is contained in:
Nguyen Anh Quynh 2009-07-22 16:27:09 +02:00 committed by Daniel Veillard
parent 6ec87af68e
commit e4c48e02b4
4 changed files with 20 additions and 11 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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;
}

View File

@ -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) {