* [Qemu-devel] [RFC][PATCH 01/15] monitor: introduce qemu_suspend_monitor()/qemu_resume_monitor()
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
@ 2012-01-19 3:06 ` Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 02/15] Add API to create memory mapping list Wen Congyang
` (14 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:06 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Sync command needs these two APIs to suspend/resume monitor.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
monitor.c | 27 +++++++++++++++++++++++++++
monitor.h | 2 ++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/monitor.c b/monitor.c
index 56f3778..ce2bc13 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4594,6 +4594,26 @@ static void monitor_command_cb(Monitor *mon, const char *cmdline, void *opaque)
monitor_resume(mon);
}
+int qemu_suspend_monitor(const char *fmt, ...)
+{
+ int ret;
+
+ if (cur_mon) {
+ ret = monitor_suspend(cur_mon);
+ } else {
+ ret = -ENOTTY;
+ }
+
+ if (ret < 0 && fmt) {
+ va_list ap;
+ va_start(ap, fmt);
+ monitor_vprintf(cur_mon, fmt, ap);
+ va_end(ap);
+ }
+
+ return ret;
+}
+
int monitor_suspend(Monitor *mon)
{
if (!mon->rs)
@@ -4602,6 +4622,13 @@ int monitor_suspend(Monitor *mon)
return 0;
}
+void qemu_resume_monitor(void)
+{
+ if (cur_mon) {
+ monitor_resume(cur_mon);
+ }
+}
+
void monitor_resume(Monitor *mon)
{
if (!mon->rs)
diff --git a/monitor.h b/monitor.h
index 274cd39..cc94bab 100644
--- a/monitor.h
+++ b/monitor.h
@@ -43,7 +43,9 @@ int monitor_cur_is_qmp(void);
void monitor_protocol_event(MonitorEvent event, QObject *data);
void monitor_init(CharDriverState *chr, int flags);
+int qemu_suspend_monitor(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
int monitor_suspend(Monitor *mon);
+void qemu_resume_monitor(void);
void monitor_resume(Monitor *mon);
int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs,
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 02/15] Add API to create memory mapping list
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 01/15] monitor: introduce qemu_suspend_monitor()/qemu_resume_monitor() Wen Congyang
@ 2012-01-19 3:06 ` Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 03/15] Add API to check whether a physical address is I/O address Wen Congyang
` (13 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:06 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
The memory mapping list stores virtual address and physical address mapping.
The folloing patch will use this information to create PT_LOAD in the vmcore.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
Makefile.target | 1 +
memory_mapping.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
memory_mapping.h | 38 ++++++++++++++++
3 files changed, 169 insertions(+), 0 deletions(-)
create mode 100644 memory_mapping.c
create mode 100644 memory_mapping.h
diff --git a/Makefile.target b/Makefile.target
index 06d79b8..fed5531 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -197,6 +197,7 @@ obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o
obj-$(CONFIG_KVM) += kvm.o kvm-all.o
obj-$(CONFIG_NO_KVM) += kvm-stub.o
obj-y += memory.o savevm.o
+obj-y += memory_mapping.o
LIBS+=-lz
QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
diff --git a/memory_mapping.c b/memory_mapping.c
new file mode 100644
index 0000000..d83b7d7
--- /dev/null
+++ b/memory_mapping.c
@@ -0,0 +1,130 @@
+/*
+ * QEMU memory mapping
+ *
+ * Copyright Fujitsu, Corp. 2011
+ *
+ * Authors:
+ * Wen Congyang <wency@cn.fujitsu.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "cpu.h"
+#include "cpu-all.h"
+#include "memory_mapping.h"
+
+static MemoryMapping *last_mapping;
+
+static void create_new_memory_mapping(MemoryMappingList *list,
+ target_phys_addr_t phys_addr,
+ target_phys_addr_t virt_addr,
+ ram_addr_t length)
+{
+ MemoryMapping *memory_mapping, *p;
+
+ memory_mapping = g_malloc(sizeof(MemoryMapping));
+ memory_mapping->phys_addr = phys_addr;
+ memory_mapping->virt_addr = virt_addr;
+ memory_mapping->length = length;
+ last_mapping = memory_mapping;
+ list->num++;
+ QTAILQ_FOREACH(p, &list->head, next) {
+ if (p->phys_addr >= memory_mapping->phys_addr) {
+ QTAILQ_INSERT_BEFORE(p, memory_mapping, next);
+ return;
+ }
+ }
+ QTAILQ_INSERT_TAIL(&list->head, memory_mapping, next);
+ return;
+}
+
+void create_new_memory_mapping_head(MemoryMappingList *list,
+ target_phys_addr_t phys_addr,
+ target_phys_addr_t virt_addr,
+ ram_addr_t length)
+{
+ MemoryMapping *memory_mapping;
+
+ memory_mapping = g_malloc(sizeof(MemoryMapping));
+ memory_mapping->phys_addr = phys_addr;
+ memory_mapping->virt_addr = virt_addr;
+ memory_mapping->length = length;
+ last_mapping = memory_mapping;
+ list->num++;
+ QTAILQ_INSERT_HEAD(&list->head, memory_mapping, next);
+ return;
+}
+
+void add_to_memory_mapping(MemoryMappingList *list,
+ target_phys_addr_t phys_addr,
+ target_phys_addr_t virt_addr,
+ ram_addr_t length)
+{
+ MemoryMapping *memory_mapping;
+
+ if (QTAILQ_EMPTY(&list->head)) {
+ create_new_memory_mapping(list, phys_addr, virt_addr, length);
+ return;
+ }
+
+ if (last_mapping) {
+ if ((phys_addr == (last_mapping->phys_addr + last_mapping->length)) &&
+ (virt_addr == (last_mapping->virt_addr + last_mapping->length))) {
+ last_mapping->length += length;
+ return;
+ }
+ }
+
+ QTAILQ_FOREACH(memory_mapping, &list->head, next) {
+ last_mapping = memory_mapping;
+ if ((phys_addr == (last_mapping->phys_addr + last_mapping->length)) &&
+ (virt_addr == (last_mapping->virt_addr + last_mapping->length))) {
+ last_mapping->length += length;
+ return;
+ }
+
+ if (!(phys_addr >= (last_mapping->phys_addr)) ||
+ !(phys_addr < (last_mapping->phys_addr + last_mapping->length))) {
+ /* last_mapping does not contain this region */
+ continue;
+ }
+ if (!(virt_addr >= (last_mapping->virt_addr)) ||
+ !(virt_addr < (last_mapping->virt_addr + last_mapping->length))) {
+ /* last_mapping does not contain this region */
+ continue;
+ }
+ if ((virt_addr - last_mapping->virt_addr) !=
+ (phys_addr - last_mapping->phys_addr)) {
+ /*
+ * last_mapping contains this region, but we should create another
+ * mapping region.
+ */
+ break;
+ }
+
+ /* merge this region into last_mapping */
+ if ((virt_addr + length) >
+ (last_mapping->virt_addr + last_mapping->length)) {
+ last_mapping->length = virt_addr + length - last_mapping->virt_addr;
+ }
+ return;
+ }
+
+ /* this region can not be merged into any existed memory mapping. */
+ create_new_memory_mapping(list, phys_addr, virt_addr, length);
+ return;
+}
+
+void free_memory_mapping_list(MemoryMappingList *list)
+{
+ MemoryMapping *p, *q;
+
+ QTAILQ_FOREACH_SAFE(p, &list->head, next, q) {
+ QTAILQ_REMOVE(&list->head, p, next);
+ g_free(p);
+ }
+
+ list->num = 0;
+}
diff --git a/memory_mapping.h b/memory_mapping.h
new file mode 100644
index 0000000..a4b1532
--- /dev/null
+++ b/memory_mapping.h
@@ -0,0 +1,38 @@
+#ifndef MEMORY_MAPPING_H
+#define MEMORY_MAPPING_H
+
+#include "qemu-queue.h"
+
+typedef struct MemoryMapping {
+ target_phys_addr_t phys_addr;
+ target_ulong virt_addr;
+ ram_addr_t length;
+ QTAILQ_ENTRY(MemoryMapping) next;
+} MemoryMapping;
+
+typedef struct MemoryMappingList {
+ unsigned int num;
+ QTAILQ_HEAD(, MemoryMapping) head;
+} MemoryMappingList;
+
+/*
+ * crash needs some memory mapping should be at the head of the list. It will
+ * cause the list is not sorted. So the caller must add the special memory
+ * mapping after adding all the normal memory mapping into list.
+ */
+void create_new_memory_mapping_head(MemoryMappingList *list,
+ target_phys_addr_t phys_addr,
+ target_phys_addr_t virt_addr,
+ ram_addr_t length);
+/*
+ * add or merge the memory region into the memory mapping's list. The list is
+ * sorted by phys_addr.
+ */
+void add_to_memory_mapping(MemoryMappingList *list,
+ target_phys_addr_t phys_addr,
+ target_phys_addr_t virt_addr,
+ ram_addr_t length);
+
+void free_memory_mapping_list(MemoryMappingList *list);
+
+#endif
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 03/15] Add API to check whether a physical address is I/O address
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 01/15] monitor: introduce qemu_suspend_monitor()/qemu_resume_monitor() Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 02/15] Add API to create memory mapping list Wen Congyang
@ 2012-01-19 3:06 ` Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 04/15] target-i386: implement cpu_get_memory_mapping() Wen Congyang
` (12 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:06 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
This API will be used in the following patch.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
cpu-common.h | 2 ++
exec.c | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/cpu-common.h b/cpu-common.h
index a40c57d..d047137 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -71,6 +71,8 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
void *cpu_register_map_client(void *opaque, void (*callback)(void *opaque));
void cpu_unregister_map_client(void *cookie);
+bool is_io_addr(target_phys_addr_t phys_addr);
+
/* Coalesced MMIO regions are areas where write operations can be reordered.
* This usually implies that write operations are side-effect free. This allows
* batching which can make a major impact on performance when using
diff --git a/exec.c b/exec.c
index 7f9f730..adc4e74 100644
--- a/exec.c
+++ b/exec.c
@@ -4411,3 +4411,19 @@ tb_page_addr_t get_page_addr_code(CPUState *env1, target_ulong addr)
#undef env
#endif
+
+bool is_io_addr(target_phys_addr_t phys_addr)
+{
+ ram_addr_t pd;
+ PhysPageDesc p;
+
+ p = phys_page_find(phys_addr >> TARGET_PAGE_BITS);
+ pd = p.phys_offset;
+
+ if (!is_ram_rom_romd(pd)) {
+ /* I/O region */
+ return true;
+ }
+
+ return false;
+}
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 04/15] target-i386: implement cpu_get_memory_mapping()
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (2 preceding siblings ...)
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 03/15] Add API to check whether a physical address is I/O address Wen Congyang
@ 2012-01-19 3:06 ` Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 05/15] Add API to get memory mapping Wen Congyang
` (11 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:06 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Walk cpu's page table and collect all virtual address and physical address mapping.
Then, add these mapping into memory mapping list.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
Makefile.target | 2 +-
cpu-all.h | 7 ++
target-i386/arch-dump.c | 254 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 262 insertions(+), 1 deletions(-)
create mode 100644 target-i386/arch-dump.c
diff --git a/Makefile.target b/Makefile.target
index fed5531..d869550 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -73,7 +73,7 @@ libobj-$(CONFIG_TCG_INTERPRETER) += tci.o
libobj-y += fpu/softfloat.o
libobj-y += op_helper.o helper.o
ifeq ($(TARGET_BASE_ARCH), i386)
-libobj-y += cpuid.o
+libobj-y += cpuid.o arch-dump.o
endif
libobj-$(TARGET_SPARC64) += vis_helper.o
libobj-$(CONFIG_NEED_MMU) += mmu.o
diff --git a/cpu-all.h b/cpu-all.h
index e2c3c49..4cd7fbb 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -22,6 +22,7 @@
#include "qemu-common.h"
#include "qemu-tls.h"
#include "cpu-common.h"
+#include "memory_mapping.h"
/* some important defines:
*
@@ -523,4 +524,10 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf);
int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
uint8_t *buf, int len, int is_write);
+#if defined(TARGET_I386)
+void cpu_get_memory_mapping(MemoryMappingList *list, CPUState *env);
+#else
+#define cpu_get_memory_mapping(list, env)
+#endif
+
#endif /* CPU_ALL_H */
diff --git a/target-i386/arch-dump.c b/target-i386/arch-dump.c
new file mode 100644
index 0000000..2e921c7
--- /dev/null
+++ b/target-i386/arch-dump.c
@@ -0,0 +1,254 @@
+/*
+ * i386 dump
+ *
+ * Copyright Fujitsu, Corp. 2011
+ *
+ * Authors:
+ * Wen Congyang <wency@cn.fujitsu.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "cpu.h"
+#include "cpu-all.h"
+
+/* PAE Paging or IA-32e Paging */
+static void walk_pte(MemoryMappingList *list, target_phys_addr_t pte_start_addr,
+ int32_t a20_mask, target_ulong start_line_addr)
+{
+ target_phys_addr_t pte_addr, start_paddr;
+ uint64_t pte;
+ target_ulong start_vaddr;
+ int i;
+
+ for (i = 0; i < 512; i++) {
+ pte_addr = (pte_start_addr + i * 8) & a20_mask;
+ pte = ldq_phys(pte_addr);
+ if (!(pte & PG_PRESENT_MASK)) {
+ /* not present */
+ continue;
+ }
+
+ start_paddr = (pte & ~0xfff) & ~(0x1ULL << 63);
+ if (is_io_addr(start_paddr)) {
+ /* I/O region */
+ continue;
+ }
+
+ start_vaddr = start_line_addr | ((i & 0x1fff) << 12);
+ add_to_memory_mapping(list, start_paddr, start_vaddr, 1 << 12);
+ }
+}
+
+/* 32-bit Paging */
+static void walk_pte2(MemoryMappingList *list,
+ target_phys_addr_t pte_start_addr, int32_t a20_mask,
+ target_ulong start_line_addr)
+{
+ target_phys_addr_t pte_addr, start_paddr;
+ uint32_t pte;
+ target_ulong start_vaddr;
+ int i;
+
+ for (i = 0; i < 1024; i++) {
+ pte_addr = (pte_start_addr + i * 4) & a20_mask;
+ pte = ldl_phys(pte_addr);
+ if (!(pte & PG_PRESENT_MASK)) {
+ /* not present */
+ continue;
+ }
+
+ start_paddr = pte & ~0xfff;
+ if (is_io_addr(start_paddr)) {
+ /* I/O region */
+ continue;
+ }
+
+ start_vaddr = start_line_addr | ((i & 0x3ff) << 12);
+ add_to_memory_mapping(list, start_paddr, start_vaddr, 1 << 12);
+ }
+}
+
+/* PAE Paging or IA-32e Paging */
+static void walk_pde(MemoryMappingList *list, target_phys_addr_t pde_start_addr,
+ int32_t a20_mask, target_ulong start_line_addr)
+{
+ target_phys_addr_t pde_addr, pte_start_addr, start_paddr;
+ uint64_t pde;
+ target_ulong line_addr, start_vaddr;
+ int i;
+
+ for (i = 0; i < 512; i++) {
+ pde_addr = (pde_start_addr + i * 8) & a20_mask;
+ pde = ldq_phys(pde_addr);
+ if (!(pde & PG_PRESENT_MASK)) {
+ /* not present */
+ continue;
+ }
+
+ line_addr = start_line_addr | ((i & 0x1ff) << 21);
+ if (pde & PG_PSE_MASK) {
+ /* 2 MB page */
+ start_paddr = (pde & ~0x1fffff) & ~(0x1ULL << 63);
+ if (is_io_addr(start_paddr)) {
+ /* I/O region */
+ continue;
+ }
+ start_vaddr = line_addr;
+ add_to_memory_mapping(list, start_paddr, start_vaddr, 1 << 21);
+ continue;
+ }
+
+ pte_start_addr = (pde & ~0xfff) & a20_mask;
+ walk_pte(list, pte_start_addr, a20_mask, line_addr);
+ }
+}
+
+/* 32-bit Paging */
+static void walk_pde2(MemoryMappingList *list,
+ target_phys_addr_t pde_start_addr, int32_t a20_mask,
+ bool pse)
+{
+ target_phys_addr_t pde_addr, pte_start_addr, start_paddr;
+ uint32_t pde;
+ target_ulong line_addr, start_vaddr;
+ int i;
+
+ for (i = 0; i < 1024; i++) {
+ pde_addr = (pde_start_addr + i * 4) & a20_mask;
+ pde = ldl_phys(pde_addr);
+ if (!(pde & PG_PRESENT_MASK)) {
+ /* not present */
+ continue;
+ }
+
+ line_addr = (((unsigned int)i & 0x3ff) << 22);
+ if ((pde & PG_PSE_MASK) && pse) {
+ /* 4 MB page */
+ start_paddr = (pde & ~0x3fffff) | ((pde & 0x1fe000) << 19);
+ if (is_io_addr(start_paddr)) {
+ /* I/O region */
+ continue;
+ }
+ start_vaddr = line_addr;
+ add_to_memory_mapping(list, start_paddr, start_vaddr, 1 << 22);
+ continue;
+ }
+
+ pte_start_addr = (pde & ~0xfff) & a20_mask;
+ walk_pte2(list, pte_start_addr, a20_mask, line_addr);
+ }
+}
+
+/* PAE Paging */
+static void walk_pdpe2(MemoryMappingList *list,
+ target_phys_addr_t pdpe_start_addr, int32_t a20_mask)
+{
+ target_phys_addr_t pdpe_addr, pde_start_addr;
+ uint64_t pdpe;
+ target_ulong line_addr;
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ pdpe_addr = (pdpe_start_addr + i * 8) & a20_mask;
+ pdpe = ldq_phys(pdpe_addr);
+ if (!(pdpe & PG_PRESENT_MASK)) {
+ /* not present */
+ continue;
+ }
+
+ line_addr = (((unsigned int)i & 0x3) << 30);
+ pde_start_addr = (pdpe & ~0xfff) & a20_mask;
+ walk_pde(list, pde_start_addr, a20_mask, line_addr);
+ }
+}
+
+#ifdef TARGET_X86_64
+/* IA-32e Paging */
+static void walk_pdpe(MemoryMappingList *list,
+ target_phys_addr_t pdpe_start_addr, int32_t a20_mask,
+ target_ulong start_line_addr)
+{
+ target_phys_addr_t pdpe_addr, pde_start_addr, start_paddr;
+ uint64_t pdpe;
+ target_ulong line_addr, start_vaddr;
+ int i;
+
+ for (i = 0; i < 512; i++) {
+ pdpe_addr = (pdpe_start_addr + i * 8) & a20_mask;
+ pdpe = ldq_phys(pdpe_addr);
+ if (!(pdpe & PG_PRESENT_MASK)) {
+ /* not present */
+ continue;
+ }
+
+ line_addr = start_line_addr | ((i & 0x1ffULL) << 30);
+ if (pdpe & PG_PSE_MASK) {
+ /* 1 GB page */
+ start_paddr = (pdpe & ~0x3fffffff) & ~(0x1ULL << 63);
+ if (is_io_addr(start_paddr)) {
+ /* I/O region */
+ continue;
+ }
+ start_vaddr = line_addr;
+ add_to_memory_mapping(list, start_paddr, start_vaddr, 1 << 30);
+ continue;
+ }
+
+ pde_start_addr = (pdpe & ~0xfff) & a20_mask;
+ walk_pde(list, pde_start_addr, a20_mask, line_addr);
+ }
+}
+
+/* IA-32e Paging */
+static void walk_pml4e(MemoryMappingList *list,
+ target_phys_addr_t pml4e_start_addr, int32_t a20_mask)
+{
+ target_phys_addr_t pml4e_addr, pdpe_start_addr;
+ uint64_t pml4e;
+ target_ulong line_addr;
+ int i;
+
+ for (i = 0; i < 512; i++) {
+ pml4e_addr = (pml4e_start_addr + i * 8) & a20_mask;
+ pml4e = ldq_phys(pml4e_addr);
+ if (!(pml4e & PG_PRESENT_MASK)) {
+ /* not present */
+ continue;
+ }
+
+ line_addr = ((i & 0x1ffULL) << 39) | (0xffffULL << 48);
+ pdpe_start_addr = (pml4e & ~0xfff) & a20_mask;
+ walk_pdpe(list, pdpe_start_addr, a20_mask, line_addr);
+ }
+}
+#endif
+
+void cpu_get_memory_mapping(MemoryMappingList *list, CPUState *env)
+{
+ if (env->cr[4] & CR4_PAE_MASK) {
+#ifdef TARGET_X86_64
+ if (env->hflags & HF_LMA_MASK) {
+ target_phys_addr_t pml4e_addr;
+
+ pml4e_addr = (env->cr[3] & ~0xfff) & env->a20_mask;
+ walk_pml4e(list, pml4e_addr, env->a20_mask);
+ } else
+#endif
+ {
+ target_phys_addr_t pdpe_addr;
+
+ pdpe_addr = (env->cr[3] & ~0x1f) & env->a20_mask;
+ walk_pdpe2(list, pdpe_addr, env->a20_mask);
+ }
+ } else {
+ target_phys_addr_t pde_addr;
+ bool pse;
+
+ pde_addr = (env->cr[3] & ~0xfff) & env->a20_mask;
+ pse = !!(env->cr[4] & CR4_PSE_MASK);
+ walk_pde2(list, pde_addr, env->a20_mask, pse);
+ }
+}
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 05/15] Add API to get memory mapping
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (3 preceding siblings ...)
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 04/15] target-i386: implement cpu_get_memory_mapping() Wen Congyang
@ 2012-01-19 3:06 ` Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 06/15] target-i386: Add API to write elf notes to core file Wen Congyang
` (10 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:06 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Add API to get all virtual address and physical address mapping.
If there is no virtual address for some physical address, the virtual
address is 0.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
memory_mapping.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
memory_mapping.h | 1 +
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/memory_mapping.c b/memory_mapping.c
index d83b7d7..55c9266 100644
--- a/memory_mapping.c
+++ b/memory_mapping.c
@@ -128,3 +128,58 @@ void free_memory_mapping_list(MemoryMappingList *list)
list->num = 0;
}
+
+void get_memory_mapping(MemoryMappingList *list)
+{
+ CPUState *env;
+ MemoryMapping *memory_mapping;
+ RAMBlock *block;
+ ram_addr_t offset, length;
+
+ last_mapping = NULL;
+
+ for (env = first_cpu; env != NULL; env = env->next_cpu) {
+ cpu_get_memory_mapping(list, env);
+ }
+
+ /* some memory may be not mapped, add them into memory mapping's list */
+ QLIST_FOREACH(block, &ram_list.blocks, next) {
+ offset = block->offset;
+ length = block->length;
+
+ QTAILQ_FOREACH(memory_mapping, &list->head, next) {
+ if (memory_mapping->phys_addr >= (offset + length)) {
+ /*
+ * memory_mapping'list does not conatin the region
+ * [offset, offset+length)
+ */
+ create_new_memory_mapping(list, offset, 0, length);
+ break;
+ }
+
+ if ((memory_mapping->phys_addr + memory_mapping->length) <=
+ offset) {
+ continue;
+ }
+
+ if (memory_mapping->phys_addr > offset) {
+ /*
+ * memory_mapping'list does not conatin the region
+ * [offset, memory_mapping->phys_addr)
+ */
+ create_new_memory_mapping(list, offset, 0,
+ memory_mapping->phys_addr - offset);
+ }
+
+ if ((offset + length) <=
+ (memory_mapping->phys_addr + memory_mapping->length)) {
+ break;
+ }
+ length -= memory_mapping->phys_addr + memory_mapping->length -
+ offset;
+ offset = memory_mapping->phys_addr + memory_mapping->length;
+ }
+ }
+
+ return;
+}
diff --git a/memory_mapping.h b/memory_mapping.h
index a4b1532..679f9ef 100644
--- a/memory_mapping.h
+++ b/memory_mapping.h
@@ -34,5 +34,6 @@ void add_to_memory_mapping(MemoryMappingList *list,
ram_addr_t length);
void free_memory_mapping_list(MemoryMappingList *list);
+void get_memory_mapping(MemoryMappingList *list);
#endif
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 06/15] target-i386: Add API to write elf notes to core file
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (4 preceding siblings ...)
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 05/15] Add API to get memory mapping Wen Congyang
@ 2012-01-19 3:06 ` Wen Congyang
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 07/15] target-i386: Add API to add extra memory mapping Wen Congyang
` (9 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:06 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
The core file contains register's value. These APIs write registers to
core file, and them will be called in the following patch.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
cpu-all.h | 6 +
target-i386/arch-dump.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 249 insertions(+), 0 deletions(-)
diff --git a/cpu-all.h b/cpu-all.h
index 4cd7fbb..efb5ba3 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -526,8 +526,14 @@ int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
#if defined(TARGET_I386)
void cpu_get_memory_mapping(MemoryMappingList *list, CPUState *env);
+int cpu_write_elf64_note(int fd, CPUState *env, int cpuid,
+ target_phys_addr_t *offset);
+int cpu_write_elf32_note(int fd, CPUState *env, int cpuid,
+ target_phys_addr_t *offset);
#else
#define cpu_get_memory_mapping(list, env)
+#define cpu_write_elf64_note(fd, env, cpuid, offset) ({ -1; })
+#define cpu_write_elf32_note(fd, env, cpuid, offset) ({ -1; })
#endif
#endif /* CPU_ALL_H */
diff --git a/target-i386/arch-dump.c b/target-i386/arch-dump.c
index 2e921c7..4c0ff77 100644
--- a/target-i386/arch-dump.c
+++ b/target-i386/arch-dump.c
@@ -11,8 +11,11 @@
*
*/
+#include <elf.h>
+
#include "cpu.h"
#include "cpu-all.h"
+#include "monitor.h"
/* PAE Paging or IA-32e Paging */
static void walk_pte(MemoryMappingList *list, target_phys_addr_t pte_start_addr,
@@ -252,3 +255,243 @@ void cpu_get_memory_mapping(MemoryMappingList *list, CPUState *env)
walk_pde2(list, pde_addr, env->a20_mask, pse);
}
}
+
+#ifdef TARGET_X86_64
+typedef struct {
+ target_ulong r15, r14, r13, r12, rbp, rbx, r11, r10;
+ target_ulong r9, r8, rax, rcx, rdx, rsi, rdi, orig_rax;
+ target_ulong rip, cs, eflags;
+ target_ulong rsp, ss;
+ target_ulong fs_base, gs_base;
+ target_ulong ds, es, fs, gs;
+} x86_64_user_regs_struct;
+
+static int x86_64_write_elf64_note(int fd, CPUState *env, int id,
+ target_phys_addr_t *offset)
+{
+ x86_64_user_regs_struct regs;
+ Elf64_Nhdr *note;
+ char *buf;
+ int descsz, note_size, name_size = 5;
+ const char *name = "CORE";
+ int ret;
+
+ regs.r15 = env->regs[15];
+ regs.r14 = env->regs[14];
+ regs.r13 = env->regs[13];
+ regs.r12 = env->regs[12];
+ regs.r11 = env->regs[11];
+ regs.r10 = env->regs[10];
+ regs.r9 = env->regs[9];
+ regs.r8 = env->regs[8];
+ regs.rbp = env->regs[R_EBP];
+ regs.rsp = env->regs[R_ESP];
+ regs.rdi = env->regs[R_EDI];
+ regs.rsi = env->regs[R_ESI];
+ regs.rdx = env->regs[R_EDX];
+ regs.rcx = env->regs[R_ECX];
+ regs.rbx = env->regs[R_EBX];
+ regs.rax = env->regs[R_EAX];
+ regs.rip = env->eip;
+ regs.eflags = env->eflags;
+
+ regs.orig_rax = 0; /* FIXME */
+ regs.cs = env->segs[R_CS].selector;
+ regs.ss = env->segs[R_SS].selector;
+ regs.fs_base = env->segs[R_FS].base;
+ regs.gs_base = env->segs[R_GS].base;
+ regs.ds = env->segs[R_DS].selector;
+ regs.es = env->segs[R_ES].selector;
+ regs.fs = env->segs[R_FS].selector;
+ regs.gs = env->segs[R_GS].selector;
+
+ descsz = 336; /* sizeof(prstatus_t) is 336 on x86_64 box */
+ note_size = ((sizeof(Elf64_Nhdr) + 3) / 4 + (name_size + 3) / 4 +
+ (descsz + 3) / 4) * 4;
+ note = g_malloc(note_size);
+
+ memset(note, 0, note_size);
+ note->n_namesz = cpu_to_le32(name_size);
+ note->n_descsz = cpu_to_le32(descsz);
+ note->n_type = cpu_to_le32(NT_PRSTATUS);
+ buf = (char *)note;
+ buf += ((sizeof(Elf64_Nhdr) + 3) / 4) * 4;
+ memcpy(buf, name, name_size);
+ buf += ((name_size + 3) / 4) * 4;
+ memcpy(buf + 32, &id, 4); /* pr_pid */
+ buf += descsz - sizeof(x86_64_user_regs_struct)-sizeof(target_ulong);
+ memcpy(buf, ®s, sizeof(x86_64_user_regs_struct));
+
+ lseek(fd, *offset, SEEK_SET);
+ ret = write(fd, note, note_size);
+ g_free(note);
+ if (ret < 0) {
+ return -1;
+ }
+
+ *offset += note_size;
+
+ return 0;
+}
+#endif
+
+typedef struct {
+ uint32_t ebx, ecx, edx, esi, edi, ebp, eax;
+ unsigned short ds, __ds, es, __es;
+ unsigned short fs, __fs, gs, __gs;
+ uint32_t orig_eax, eip;
+ unsigned short cs, __cs;
+ uint32_t eflags, esp;
+ unsigned short ss, __ss;
+} x86_user_regs_struct;
+
+static int x86_write_elf64_note(int fd, CPUState *env, int id,
+ target_phys_addr_t *offset)
+{
+ x86_user_regs_struct regs;
+ Elf64_Nhdr *note;
+ char *buf;
+ int descsz, note_size, name_size = 5;
+ const char *name = "CORE";
+ int ret;
+
+ regs.ebp = env->regs[R_EBP] & 0xffffffff;
+ regs.esp = env->regs[R_ESP] & 0xffffffff;
+ regs.edi = env->regs[R_EDI] & 0xffffffff;
+ regs.esi = env->regs[R_ESI] & 0xffffffff;
+ regs.edx = env->regs[R_EDX] & 0xffffffff;
+ regs.ecx = env->regs[R_ECX] & 0xffffffff;
+ regs.ebx = env->regs[R_EBX] & 0xffffffff;
+ regs.eax = env->regs[R_EAX] & 0xffffffff;
+ regs.eip = env->eip & 0xffffffff;
+ regs.eflags = env->eflags & 0xffffffff;
+
+ regs.cs = env->segs[R_CS].selector;
+ regs.__cs = 0;
+ regs.ss = env->segs[R_SS].selector;
+ regs.__ss = 0;
+ regs.ds = env->segs[R_DS].selector;
+ regs.__ds = 0;
+ regs.es = env->segs[R_ES].selector;
+ regs.__es = 0;
+ regs.fs = env->segs[R_FS].selector;
+ regs.__fs = 0;
+ regs.gs = env->segs[R_GS].selector;
+ regs.__gs = 0;
+
+ descsz = 144; /* sizeof(prstatus_t) is 144 on x86 box */
+ note_size = ((sizeof(Elf64_Nhdr) + 3) / 4 + (name_size + 3) / 4 +
+ (descsz + 3) / 4) * 4;
+ note = g_malloc(note_size);
+
+ memset(note, 0, note_size);
+ note->n_namesz = cpu_to_le32(name_size);
+ note->n_descsz = cpu_to_le32(descsz);
+ note->n_type = cpu_to_le32(NT_PRSTATUS);
+ buf = (char *)note;
+ buf += ((sizeof(Elf64_Nhdr) + 3) / 4) * 4;
+ memcpy(buf, name, name_size);
+ buf += ((name_size + 3) / 4) * 4;
+ memcpy(buf + 24, &id, 4); /* pr_pid */
+ buf += descsz - sizeof(x86_user_regs_struct)-4;
+ memcpy(buf, ®s, sizeof(x86_user_regs_struct));
+
+ lseek(fd, *offset, SEEK_SET);
+ ret = write(fd, note, note_size);
+ g_free(note);
+ if (ret < 0) {
+ return -1;
+ }
+
+ *offset += note_size;
+
+ return 0;
+}
+
+static int x86_write_elf32_note(int fd, CPUState *env, int id,
+ target_phys_addr_t *offset)
+{
+ x86_user_regs_struct regs;
+ Elf32_Nhdr *note;
+ char *buf;
+ int descsz, note_size, name_size = 5;
+ const char *name = "CORE";
+ int ret;
+
+ regs.ebp = env->regs[R_EBP] & 0xffffffff;
+ regs.esp = env->regs[R_ESP] & 0xffffffff;
+ regs.edi = env->regs[R_EDI] & 0xffffffff;
+ regs.esi = env->regs[R_ESI] & 0xffffffff;
+ regs.edx = env->regs[R_EDX] & 0xffffffff;
+ regs.ecx = env->regs[R_ECX] & 0xffffffff;
+ regs.ebx = env->regs[R_EBX] & 0xffffffff;
+ regs.eax = env->regs[R_EAX] & 0xffffffff;
+ regs.eip = env->eip & 0xffffffff;
+ regs.eflags = env->eflags & 0xffffffff;
+
+ regs.cs = env->segs[R_CS].selector;
+ regs.__cs = 0;
+ regs.ss = env->segs[R_SS].selector;
+ regs.__ss = 0;
+ regs.ds = env->segs[R_DS].selector;
+ regs.__ds = 0;
+ regs.es = env->segs[R_ES].selector;
+ regs.__es = 0;
+ regs.fs = env->segs[R_FS].selector;
+ regs.__fs = 0;
+ regs.gs = env->segs[R_GS].selector;
+ regs.__gs = 0;
+
+ descsz = 144; /* sizeof(prstatus_t) is 144 on x86 box */
+ note_size = ((sizeof(Elf32_Nhdr) + 3) / 4 + (name_size + 3) / 4 +
+ (descsz + 3) / 4) * 4;
+ note = g_malloc(note_size);
+
+ memset(note, 0, note_size);
+ note->n_namesz = cpu_to_le32(name_size);
+ note->n_descsz = cpu_to_le32(descsz);
+ note->n_type = cpu_to_le32(NT_PRSTATUS);
+ buf = (char *)note;
+ buf += ((sizeof(Elf32_Nhdr) + 3) / 4) * 4;
+ memcpy(buf, name, name_size);
+ buf += ((name_size + 3) / 4) * 4;
+ memcpy(buf + 24, &id, 4); /* pr_pid */
+ buf += descsz - sizeof(x86_user_regs_struct)-4;
+ memcpy(buf, ®s, sizeof(x86_user_regs_struct));
+
+ lseek(fd, *offset, SEEK_SET);
+ ret = write(fd, note, note_size);
+ g_free(note);
+ if (ret < 0) {
+ return -1;
+ }
+
+ *offset += note_size;
+
+ return 0;
+}
+
+int cpu_write_elf64_note(int fd, CPUState *env, int cpuid,
+ target_phys_addr_t *offset)
+{
+ int ret;
+#ifdef TARGET_X86_64
+ bool lma = !!(first_cpu->hflags & HF_LMA_MASK);
+
+ if (lma) {
+ ret = x86_64_write_elf64_note(fd, env, cpuid, offset);
+ } else {
+#endif
+ ret = x86_write_elf64_note(fd, env, cpuid, offset);
+#ifdef TARGET_X86_64
+ }
+#endif
+
+ return ret;
+}
+
+int cpu_write_elf32_note(int fd, CPUState *env, int cpuid,
+ target_phys_addr_t *offset)
+{
+ return x86_write_elf32_note(fd, env, cpuid, offset);
+}
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 07/15] target-i386: Add API to add extra memory mapping
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (5 preceding siblings ...)
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 06/15] target-i386: Add API to write elf notes to core file Wen Congyang
@ 2012-01-19 3:06 ` Wen Congyang
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 08/15] target-i386: add API to get dump info Wen Congyang
` (8 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:06 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Crash needs extra memory mapping to determine phys_base.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
cpu-all.h | 2 ++
target-i386/arch-dump.c | 43 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/cpu-all.h b/cpu-all.h
index efb5ba3..290c43a 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -530,10 +530,12 @@ int cpu_write_elf64_note(int fd, CPUState *env, int cpuid,
target_phys_addr_t *offset);
int cpu_write_elf32_note(int fd, CPUState *env, int cpuid,
target_phys_addr_t *offset);
+int cpu_add_extra_memory_mapping(MemoryMappingList *list);
#else
#define cpu_get_memory_mapping(list, env)
#define cpu_write_elf64_note(fd, env, cpuid, offset) ({ -1; })
#define cpu_write_elf32_note(fd, env, cpuid, offset) ({ -1; })
+#define cpu_add_extra_memory_mapping(list) ({ 0; })
#endif
#endif /* CPU_ALL_H */
diff --git a/target-i386/arch-dump.c b/target-i386/arch-dump.c
index 4c0ff77..d96f6ae 100644
--- a/target-i386/arch-dump.c
+++ b/target-i386/arch-dump.c
@@ -495,3 +495,46 @@ int cpu_write_elf32_note(int fd, CPUState *env, int cpuid,
{
return x86_write_elf32_note(fd, env, cpuid, offset);
}
+
+/* This function is copied from crash */
+static target_ulong get_phys_base_addr(CPUState *env, target_ulong *base_vaddr)
+{
+ int i;
+ target_ulong kernel_base = -1;
+ target_ulong last, mask;
+
+ for (i = 30, last = -1; (kernel_base == -1) && (i >= 20); i--) {
+ mask = ~((1LL << i) - 1);
+ *base_vaddr = env->idt.base & mask;
+ if (*base_vaddr == last) {
+ continue;
+ }
+
+ kernel_base = cpu_get_phys_page_debug(env, *base_vaddr);
+ last = *base_vaddr;
+ }
+
+ return kernel_base;
+}
+
+int cpu_add_extra_memory_mapping(MemoryMappingList *list)
+{
+#ifdef TARGET_X86_64
+ target_phys_addr_t kernel_base = -1;
+ target_ulong base_vaddr;
+ bool lma = !!(first_cpu->hflags & HF_LMA_MASK);
+
+ if (!lma) {
+ return 0;
+ }
+
+ kernel_base = get_phys_base_addr(first_cpu, &base_vaddr);
+ if (kernel_base == -1) {
+ return -1;
+ }
+
+ create_new_memory_mapping_head(list, kernel_base, base_vaddr,
+ TARGET_PAGE_SIZE);
+#endif
+ return 0;
+}
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 08/15] target-i386: add API to get dump info
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (6 preceding siblings ...)
2012-01-19 3:06 ` [Qemu-devel] [RFC][PATCH 07/15] target-i386: Add API to add extra memory mapping Wen Congyang
@ 2012-01-19 3:07 ` Wen Congyang
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 09/15] introduce a new monitor command 'dump' to dump guest's memory Wen Congyang
` (7 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:07 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Dump info contains: endian, class and architecture. The next
patch will use these information to create vmcore.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
cpu-all.h | 3 +++
dump.h | 10 ++++++++++
target-i386/arch-dump.c | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 0 deletions(-)
create mode 100644 dump.h
diff --git a/cpu-all.h b/cpu-all.h
index 290c43a..268d1f6 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -23,6 +23,7 @@
#include "qemu-tls.h"
#include "cpu-common.h"
#include "memory_mapping.h"
+#include "dump.h"
/* some important defines:
*
@@ -531,11 +532,13 @@ int cpu_write_elf64_note(int fd, CPUState *env, int cpuid,
int cpu_write_elf32_note(int fd, CPUState *env, int cpuid,
target_phys_addr_t *offset);
int cpu_add_extra_memory_mapping(MemoryMappingList *list);
+int cpu_get_dump_info(ArchDumpInfo *info);
#else
#define cpu_get_memory_mapping(list, env)
#define cpu_write_elf64_note(fd, env, cpuid, offset) ({ -1; })
#define cpu_write_elf32_note(fd, env, cpuid, offset) ({ -1; })
#define cpu_add_extra_memory_mapping(list) ({ 0; })
+#define cpu_get_dump_info(info) ({ -1; })
#endif
#endif /* CPU_ALL_H */
diff --git a/dump.h b/dump.h
new file mode 100644
index 0000000..a36468b
--- /dev/null
+++ b/dump.h
@@ -0,0 +1,10 @@
+#ifndef DUMP_H
+#define DUMP_H
+
+typedef struct ArchDumpInfo {
+ int d_machine; /* Architecture */
+ int d_endian; /* ELFDATA2LSB or ELFDATA2MSB */
+ int d_class; /* ELFCLASS32 or ELFCLASS64 */
+} ArchDumpInfo;
+
+#endif
diff --git a/target-i386/arch-dump.c b/target-i386/arch-dump.c
index d96f6ae..92a53bc 100644
--- a/target-i386/arch-dump.c
+++ b/target-i386/arch-dump.c
@@ -15,6 +15,7 @@
#include "cpu.h"
#include "cpu-all.h"
+#include "dump.h"
#include "monitor.h"
/* PAE Paging or IA-32e Paging */
@@ -538,3 +539,36 @@ int cpu_add_extra_memory_mapping(MemoryMappingList *list)
#endif
return 0;
}
+
+int cpu_get_dump_info(ArchDumpInfo *info)
+{
+ bool lma = false;
+ RAMBlock *block;
+
+#ifdef TARGET_X86_64
+ lma = !!(first_cpu->hflags & HF_LMA_MASK);
+#endif
+
+ if (lma) {
+ info->d_machine = EM_X86_64;
+ } else {
+ info->d_machine = EM_386;
+ }
+ info->d_endian = ELFDATA2LSB;
+
+ if (lma) {
+ info->d_class = ELFCLASS64;
+ } else {
+ info->d_class = ELFCLASS32;
+ }
+
+ QLIST_FOREACH(block, &ram_list.blocks, next) {
+ if (!lma && (block->offset + block->length > UINT_MAX)) {
+ /* The memory size is greater than 4G */
+ info->d_class = ELFCLASS32;
+ break;
+ }
+ }
+
+ return 0;
+}
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 09/15] introduce a new monitor command 'dump' to dump guest's memory
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (7 preceding siblings ...)
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 08/15] target-i386: add API to get dump info Wen Congyang
@ 2012-01-19 3:07 ` Wen Congyang
2012-01-19 16:32 ` Eric Blake
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 10/15] run dump at the background Wen Congyang
` (6 subsequent siblings)
15 siblings, 1 reply; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:07 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
Makefile.target | 8 +-
dump.c | 590 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
dump.h | 3 +
hmp-commands.hx | 16 ++
hmp.c | 9 +
hmp.h | 1 +
monitor.c | 3 +
qapi-schema.json | 13 ++
qmp-commands.hx | 26 +++
9 files changed, 665 insertions(+), 4 deletions(-)
create mode 100644 dump.c
diff --git a/Makefile.target b/Makefile.target
index d869550..abfb057 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -110,7 +110,7 @@ $(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) -I$(SRC_PATH)/linux-user
obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \
- user-exec.o $(oslib-obj-y)
+ user-exec.o $(oslib-obj-y) dump.o
obj-$(TARGET_HAS_BFLT) += flatload.o
@@ -148,7 +148,7 @@ LDFLAGS+=-Wl,-segaddr,__STD_PROG_ZONE,0x1000 -image_base 0x0e000000
LIBS+=-lmx
obj-y = main.o commpage.o machload.o mmap.o signal.o syscall.o thunk.o \
- gdbstub.o user-exec.o
+ gdbstub.o user-exec.o dump.o
obj-i386-y += ioport-user.o
@@ -170,7 +170,7 @@ $(call set-vpath, $(SRC_PATH)/bsd-user)
QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH)
obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
- gdbstub.o uaccess.o user-exec.o
+ gdbstub.o uaccess.o user-exec.o dump.o
obj-i386-y += ioport-user.o
@@ -186,7 +186,7 @@ endif #CONFIG_BSD_USER
# System emulator target
ifdef CONFIG_SOFTMMU
-obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o
+obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o dump.o
# virtio has to be here due to weird dependency between PCI and virtio-net.
# need to fix this properly
obj-$(CONFIG_NO_PCI) += pci-stub.o
diff --git a/dump.c b/dump.c
new file mode 100644
index 0000000..2951b8b
--- /dev/null
+++ b/dump.c
@@ -0,0 +1,590 @@
+/*
+ * QEMU dump
+ *
+ * Copyright Fujitsu, Corp. 2011
+ *
+ * Authors:
+ * Wen Congyang <wency@cn.fujitsu.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu-common.h"
+#include <unistd.h>
+#include <elf.h>
+#include <sys/procfs.h>
+#include <glib.h>
+#include "cpu.h"
+#include "cpu-all.h"
+#include "targphys.h"
+#include "monitor.h"
+#include "kvm.h"
+#include "dump.h"
+#include "sysemu.h"
+#include "bswap.h"
+#include "memory_mapping.h"
+#include "error.h"
+#include "qmp-commands.h"
+
+#define CPU_CONVERT_TO_TARGET16(val) \
+({ \
+ uint16_t _val = (val); \
+ if (endian == ELFDATA2LSB) { \
+ _val = cpu_to_le16(_val); \
+ } else {\
+ _val = cpu_to_be16(_val); \
+ } \
+ _val; \
+})
+
+#define CPU_CONVERT_TO_TARGET32(val) \
+({ \
+ uint32_t _val = (val); \
+ if (endian == ELFDATA2LSB) { \
+ _val = cpu_to_le32(_val); \
+ } else {\
+ _val = cpu_to_be32(_val); \
+ } \
+ _val; \
+})
+
+#define CPU_CONVERT_TO_TARGET64(val) \
+({ \
+ uint64_t _val = (val); \
+ if (endian == ELFDATA2LSB) { \
+ _val = cpu_to_le64(_val); \
+ } else {\
+ _val = cpu_to_be64(_val); \
+ } \
+ _val; \
+})
+
+enum {
+ DUMP_STATE_ERROR,
+ DUMP_STATE_SETUP,
+ DUMP_STATE_CANCELLED,
+ DUMP_STATE_ACTIVE,
+ DUMP_STATE_COMPLETED,
+};
+
+typedef struct DumpState {
+ ArchDumpInfo dump_info;
+ MemoryMappingList list;
+ int phdr_num;
+ int state;
+ char *error;
+ int fd;
+ target_phys_addr_t memory_offset;
+} DumpState;
+
+static DumpState *dump_get_current(void)
+{
+ static DumpState current_dump = {
+ .state = DUMP_STATE_SETUP,
+ };
+
+ return ¤t_dump;
+}
+
+static int dump_cleanup(DumpState *s)
+{
+ int ret = 0;
+
+ free_memory_mapping_list(&s->list);
+ if (s->fd != -1) {
+ close(s->fd);
+ s->fd = -1;
+ }
+
+ return ret;
+}
+
+static void dump_error(DumpState *s, const char *reason)
+{
+ s->state = DUMP_STATE_ERROR;
+ s->error = g_strdup(reason);
+ dump_cleanup(s);
+}
+
+static inline int cpuid(CPUState *env)
+{
+#if defined(CONFIG_USER_ONLY) && defined(CONFIG_USE_NPTL)
+ return env->host_tid;
+#else
+ return env->cpu_index + 1;
+#endif
+}
+
+static int write_elf64_header(DumpState *s)
+{
+ Elf64_Ehdr elf_header;
+ int ret;
+ int endian = s->dump_info.d_endian;
+
+ memset(&elf_header, 0, sizeof(Elf64_Ehdr));
+ memcpy(&elf_header, ELFMAG, 4);
+ elf_header.e_ident[EI_CLASS] = ELFCLASS64;
+ elf_header.e_ident[EI_DATA] = s->dump_info.d_endian;
+ elf_header.e_ident[EI_VERSION] = EV_CURRENT;
+ elf_header.e_type = CPU_CONVERT_TO_TARGET16(ET_CORE);
+ elf_header.e_machine = CPU_CONVERT_TO_TARGET16(s->dump_info.d_machine);
+ elf_header.e_version = CPU_CONVERT_TO_TARGET32(EV_CURRENT);
+ elf_header.e_ehsize = CPU_CONVERT_TO_TARGET16(sizeof(elf_header));
+ elf_header.e_phoff = CPU_CONVERT_TO_TARGET64(sizeof(Elf64_Ehdr));
+ elf_header.e_phentsize = CPU_CONVERT_TO_TARGET16(sizeof(Elf64_Phdr));
+ elf_header.e_phnum = CPU_CONVERT_TO_TARGET16(s->phdr_num);
+
+ lseek(s->fd, 0, SEEK_SET);
+ ret = write(s->fd, &elf_header, sizeof(elf_header));
+ if (ret < 0) {
+ dump_error(s, "dump: failed to write elf header.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int write_elf32_header(DumpState *s)
+{
+ Elf32_Ehdr elf_header;
+ int ret;
+ int endian = s->dump_info.d_endian;
+
+ memset(&elf_header, 0, sizeof(Elf32_Ehdr));
+ memcpy(&elf_header, ELFMAG, 4);
+ elf_header.e_ident[EI_CLASS] = ELFCLASS32;
+ elf_header.e_ident[EI_DATA] = endian;
+ elf_header.e_ident[EI_VERSION] = EV_CURRENT;
+ elf_header.e_type = CPU_CONVERT_TO_TARGET16(ET_CORE);
+ elf_header.e_machine = CPU_CONVERT_TO_TARGET16(s->dump_info.d_machine);
+ elf_header.e_version = CPU_CONVERT_TO_TARGET32(EV_CURRENT);
+ elf_header.e_ehsize = CPU_CONVERT_TO_TARGET16(sizeof(elf_header));
+ elf_header.e_phoff = CPU_CONVERT_TO_TARGET32(sizeof(Elf32_Ehdr));
+ elf_header.e_phentsize = CPU_CONVERT_TO_TARGET16(sizeof(Elf32_Phdr));
+ elf_header.e_phnum = CPU_CONVERT_TO_TARGET16(s->phdr_num);
+
+ lseek(s->fd, 0, SEEK_SET);
+ ret = write(s->fd, &elf_header, sizeof(elf_header));
+ if (ret < 0) {
+ dump_error(s, "dump: failed to write elf header.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
+ int phdr_index, target_phys_addr_t offset)
+{
+ Elf64_Phdr phdr;
+ off_t phdr_offset;
+ int ret;
+ int endian = s->dump_info.d_endian;
+
+ memset(&phdr, 0, sizeof(Elf64_Phdr));
+ phdr.p_type = CPU_CONVERT_TO_TARGET32(PT_LOAD);
+ phdr.p_offset = CPU_CONVERT_TO_TARGET64(offset);
+ phdr.p_paddr = CPU_CONVERT_TO_TARGET64(memory_mapping->phys_addr);
+ if (offset == -1) {
+ phdr.p_filesz = 0;
+ } else {
+ phdr.p_filesz = CPU_CONVERT_TO_TARGET64(memory_mapping->length);
+ }
+ phdr.p_memsz = CPU_CONVERT_TO_TARGET64(memory_mapping->length);
+ phdr.p_vaddr = CPU_CONVERT_TO_TARGET64(memory_mapping->virt_addr);
+
+ phdr_offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr)*phdr_index;
+ lseek(s->fd, phdr_offset, SEEK_SET);
+ ret = write(s->fd, &phdr, sizeof(Elf64_Phdr));
+ if (ret < 0) {
+ dump_error(s, "dump: failed to write program header table.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
+ int phdr_index, target_phys_addr_t offset)
+{
+ Elf32_Phdr phdr;
+ off_t phdr_offset;
+ int ret;
+ int endian = s->dump_info.d_endian;
+
+ memset(&phdr, 0, sizeof(Elf32_Phdr));
+ phdr.p_type = CPU_CONVERT_TO_TARGET32(PT_LOAD);
+ phdr.p_offset = CPU_CONVERT_TO_TARGET32(offset);
+ phdr.p_paddr = CPU_CONVERT_TO_TARGET32(memory_mapping->phys_addr);
+ if (offset == -1) {
+ phdr.p_filesz = 0;
+ } else {
+ phdr.p_filesz = CPU_CONVERT_TO_TARGET32(memory_mapping->length);
+ }
+ phdr.p_memsz = CPU_CONVERT_TO_TARGET32(memory_mapping->length);
+ phdr.p_vaddr = CPU_CONVERT_TO_TARGET32(memory_mapping->virt_addr);
+
+ phdr_offset = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr)*phdr_index;
+ lseek(s->fd, phdr_offset, SEEK_SET);
+ ret = write(s->fd, &phdr, sizeof(Elf32_Phdr));
+ if (ret < 0) {
+ dump_error(s, "dump: failed to write program header table.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int write_elf64_notes(DumpState *s, int phdr_index,
+ target_phys_addr_t *offset)
+{
+ CPUState *env;
+ int ret;
+ target_phys_addr_t begin = *offset;
+ Elf64_Phdr phdr;
+ off_t phdr_offset;
+ int id;
+ int endian = s->dump_info.d_endian;
+
+ for (env = first_cpu; env != NULL; env = env->next_cpu) {
+ id = cpuid(env);
+ ret = cpu_write_elf64_note(s->fd, env, id, offset);
+ if (ret < 0) {
+ dump_error(s, "dump: failed to write elf notes.\n");
+ return -1;
+ }
+ }
+
+ memset(&phdr, 0, sizeof(Elf64_Phdr));
+ phdr.p_type = CPU_CONVERT_TO_TARGET32(PT_NOTE);
+ phdr.p_offset = CPU_CONVERT_TO_TARGET64(begin);
+ phdr.p_paddr = 0;
+ phdr.p_filesz = CPU_CONVERT_TO_TARGET64(*offset - begin);
+ phdr.p_memsz = CPU_CONVERT_TO_TARGET64(*offset - begin);
+ phdr.p_vaddr = 0;
+
+ phdr_offset = sizeof(Elf64_Ehdr);
+ lseek(s->fd, phdr_offset, SEEK_SET);
+ ret = write(s->fd, &phdr, sizeof(Elf64_Phdr));
+ if (ret < 0) {
+ dump_error(s, "dump: failed to write program header table.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int write_elf32_notes(DumpState *s, int phdr_index,
+ target_phys_addr_t *offset)
+{
+ CPUState *env;
+ int ret;
+ target_phys_addr_t begin = *offset;
+ Elf32_Phdr phdr;
+ off_t phdr_offset;
+ int id;
+ int endian = s->dump_info.d_endian;
+
+ for (env = first_cpu; env != NULL; env = env->next_cpu) {
+ id = cpuid(env);
+ ret = cpu_write_elf32_note(s->fd, env, id, offset);
+ if (ret < 0) {
+ dump_error(s, "dump: failed to write elf notes.\n");
+ return -1;
+ }
+ }
+
+ memset(&phdr, 0, sizeof(Elf32_Phdr));
+ phdr.p_type = CPU_CONVERT_TO_TARGET32(PT_NOTE);
+ phdr.p_offset = CPU_CONVERT_TO_TARGET32(begin);
+ phdr.p_paddr = 0;
+ phdr.p_filesz = CPU_CONVERT_TO_TARGET32(*offset - begin);
+ phdr.p_memsz = CPU_CONVERT_TO_TARGET32(*offset - begin);
+ phdr.p_vaddr = 0;
+
+ phdr_offset = sizeof(Elf32_Ehdr);
+ lseek(s->fd, phdr_offset, SEEK_SET);
+ ret = write(s->fd, &phdr, sizeof(Elf32_Phdr));
+ if (ret < 0) {
+ dump_error(s, "dump: failed to write program header table.\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+static int write_data(DumpState *s, void *buf, int length,
+ target_phys_addr_t *offset)
+{
+ int ret;
+
+ lseek(s->fd, *offset, SEEK_SET);
+ ret = write(s->fd, buf, length);
+ if (ret < 0) {
+ dump_error(s, "dump: failed to save memory.\n");
+ return -1;
+ }
+
+ *offset += length;
+ return 0;
+}
+
+/* write the memroy to vmcore. 1 page per I/O. */
+static int write_memory(DumpState *s, RAMBlock *block,
+ target_phys_addr_t *offset)
+{
+ int i, ret;
+
+ for (i = 0; i < block->length / TARGET_PAGE_SIZE; i++) {
+ ret = write_data(s, block->host + i * TARGET_PAGE_SIZE,
+ TARGET_PAGE_SIZE, offset);
+ if (ret < 0) {
+ return -1;
+ }
+ }
+
+ if ((block->length % TARGET_PAGE_SIZE) != 0) {
+ ret = write_data(s, block->host + i * TARGET_PAGE_SIZE,
+ block->length % TARGET_PAGE_SIZE, offset);
+ if (ret < 0) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+/* get the memory's offset in the vmcore */
+static target_phys_addr_t get_offset(target_phys_addr_t phys_addr,
+ target_phys_addr_t memory_offset)
+{
+ RAMBlock *block;
+ target_phys_addr_t offset = memory_offset;
+
+ QLIST_FOREACH(block, &ram_list.blocks, next) {
+ if (phys_addr >= block->offset &&
+ phys_addr < block->offset + block->length) {
+ return phys_addr - block->offset + offset;
+ }
+ offset += block->length;
+ }
+
+ return -1;
+}
+
+static DumpState *dump_init(int fd, Error **errp)
+{
+ CPUState *env;
+ DumpState *s = dump_get_current();
+ int ret;
+
+ vm_stop(RUN_STATE_PAUSED);
+ s->state = DUMP_STATE_SETUP;
+ if (s->error) {
+ g_free(s->error);
+ s->error = NULL;
+ }
+ s->fd = fd;
+
+ /*
+ * get dump info: endian, class and architecture.
+ * If the target architecture is not supported, cpu_get_dump_info() will
+ * return -1.
+ *
+ * if we use kvm, we should synchronize the register before we get dump
+ * info.
+ */
+ for (env = first_cpu; env != NULL; env = env->next_cpu) {
+ cpu_synchronize_state(env);
+ }
+ ret = cpu_get_dump_info(&s->dump_info);
+ if (ret < 0) {
+ error_set(errp, QERR_UNSUPPORTED);
+ return NULL;
+ }
+
+ /* get memory mapping */
+ s->list.num = 0;
+ QTAILQ_INIT(&s->list.head);
+ get_memory_mapping(&s->list);
+
+ /* crash needs extra memory mapping to determine phys_base. */
+ ret = cpu_add_extra_memory_mapping(&s->list);
+ if (ret < 0) {
+ error_set(errp, QERR_UNDEFINED_ERROR);
+ return NULL;
+ }
+
+ /*
+ * calculate phdr_num
+ *
+ * the type of phdr->num is uint16_t, so we should avoid overflow
+ */
+ s->phdr_num = 1; /* PT_NOTE */
+ if (s->list.num > (1 << 16) - 2) {
+ s->phdr_num = (1 << 16) - 1;
+ } else {
+ s->phdr_num += s->list.num;
+ }
+
+ return s;
+}
+
+/* write elf header, PT_NOTE and elf note to vmcore. */
+static int dump_begin(DumpState *s)
+{
+ target_phys_addr_t offset;
+ int ret;
+
+ s->state = DUMP_STATE_ACTIVE;
+
+ /*
+ * the vmcore's format is:
+ * --------------
+ * | elf header |
+ * --------------
+ * | PT_NOTE |
+ * --------------
+ * | PT_LOAD |
+ * --------------
+ * | ...... |
+ * --------------
+ * | PT_LOAD |
+ * --------------
+ * | elf note |
+ * --------------
+ * | memory |
+ * --------------
+ *
+ * we only know where the memory is saved after we write elf note into
+ * vmcore.
+ */
+
+ /* write elf header to vmcore */
+ if (s->dump_info.d_class == ELFCLASS64) {
+ ret = write_elf64_header(s);
+ } else {
+ ret = write_elf32_header(s);
+ }
+ if (ret < 0) {
+ return -1;
+ }
+
+ /* write elf notes to vmcore */
+ if (s->dump_info.d_class == ELFCLASS64) {
+ offset = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr)*s->phdr_num;
+ ret = write_elf64_notes(s, 0, &offset);
+ } else {
+ offset = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr)*s->phdr_num;
+ ret = write_elf32_notes(s, 0, &offset);
+ }
+
+ if (ret < 0) {
+ return -1;
+ }
+
+ s->memory_offset = offset;
+ return 0;
+}
+
+/* write PT_LOAD to vmcore */
+static int dump_completed(DumpState *s)
+{
+ target_phys_addr_t offset;
+ MemoryMapping *memory_mapping;
+ int phdr_index = 1, ret;
+
+ QTAILQ_FOREACH(memory_mapping, &s->list.head, next) {
+ offset = get_offset(memory_mapping->phys_addr, s->memory_offset);
+ if (s->dump_info.d_class == ELFCLASS64) {
+ ret = write_elf64_load(s, memory_mapping, phdr_index++, offset);
+ } else {
+ ret = write_elf32_load(s, memory_mapping, phdr_index++, offset);
+ }
+ if (ret < 0) {
+ return -1;
+ }
+ }
+
+ s->state = DUMP_STATE_COMPLETED;
+ dump_cleanup(s);
+ return 0;
+}
+
+/* write all memory to vmcore */
+static int dump_iterate(DumpState *s)
+{
+ RAMBlock *block;
+ target_phys_addr_t offset = s->memory_offset;
+ int ret;
+
+ /* write all memory to vmcore */
+ QLIST_FOREACH(block, &ram_list.blocks, next) {
+ ret = write_memory(s, block, &offset);
+ if (ret < 0) {
+ return -1;
+ }
+ }
+
+ return dump_completed(s);
+}
+
+static int create_vmcore(DumpState *s)
+{
+ int ret;
+
+ ret = dump_begin(s);
+ if (ret < 0) {
+ return -1;
+ }
+
+ ret = dump_iterate(s);
+ if (ret < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+void qmp_dump(const char *file, Error **errp)
+{
+ const char *p;
+ int fd = -1;
+ DumpState *s;
+
+#if !defined(WIN32)
+ if (strstart(file, "fd:", &p)) {
+ fd = qemu_get_fd(p);
+ if (fd == -1) {
+ error_set(errp, QERR_FD_NOT_FOUND, p);
+ return;
+ }
+ }
+#endif
+
+ if (strstart(file, "file:", &p)) {
+ fd = open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
+ if (fd < 0) {
+ error_set(errp, QERR_OPEN_FILE_FAILED, p);
+ return;
+ }
+ }
+
+ if (fd == -1) {
+ error_set(errp, QERR_INVALID_PARAMETER, "file");
+ return;
+ }
+
+ s = dump_init(fd, errp);
+ if (!s) {
+ return;
+ }
+
+ if (create_vmcore(s) < 0) {
+ error_set(errp, QERR_IO_ERROR);
+ }
+
+ return;
+}
diff --git a/dump.h b/dump.h
index a36468b..b413d18 100644
--- a/dump.h
+++ b/dump.h
@@ -1,6 +1,9 @@
#ifndef DUMP_H
#define DUMP_H
+#include "qdict.h"
+#include "error.h"
+
typedef struct ArchDumpInfo {
int d_machine; /* Architecture */
int d_endian; /* ELFDATA2LSB or ELFDATA2MSB */
diff --git a/hmp-commands.hx b/hmp-commands.hx
index a586498..c3615e3 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -828,6 +828,22 @@ new parameters (if specified) once the vm migration finished successfully.
ETEXI
{
+ .name = "dump",
+ .args_type = "file:s",
+ .params = "file",
+ .help = "dump to file",
+ .user_print = monitor_user_noop,
+ .mhandler.cmd = hmp_dump,
+ },
+
+
+STEXI
+@item dump @var{file}
+@findex dump
+Dump to @var{file}.
+ETEXI
+
+ {
.name = "snapshot_blkdev",
.args_type = "device:B,snapshot-file:s?,format:s?",
.params = "device [new-image-file] [format]",
diff --git a/hmp.c b/hmp.c
index 8a77780..11b4ce6 100644
--- a/hmp.c
+++ b/hmp.c
@@ -681,3 +681,12 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
int64_t value = qdict_get_int(qdict, "value");
qmp_migrate_set_speed(value, NULL);
}
+
+void hmp_dump(Monitor *mon, const QDict *qdict)
+{
+ Error *errp = NULL;
+ const char *file = qdict_get_str(qdict, "file");
+
+ qmp_dump(file, &errp);
+ hmp_handle_error(mon, &errp);
+}
diff --git a/hmp.h b/hmp.h
index 093242d..8d6a5d2 100644
--- a/hmp.h
+++ b/hmp.h
@@ -49,5 +49,6 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict);
void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_dump(Monitor *mon, const QDict *qdict);
#endif
diff --git a/monitor.c b/monitor.c
index ce2bc13..24d4371 100644
--- a/monitor.c
+++ b/monitor.c
@@ -73,6 +73,9 @@
#endif
#include "hw/lm32_pic.h"
+/* for dump */
+#include "dump.h"
+
//#define DEBUG
//#define DEBUG_COMPLETION
diff --git a/qapi-schema.json b/qapi-schema.json
index 44cf764..84c2c9a 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1275,3 +1275,16 @@
{ 'command': 'qom-set',
'data': { 'path': 'str', 'property': 'str', 'value': 'visitor' },
'gen': 'no' }
+
+##
+# @dump
+#
+# Dump guest's memory to vmcore.
+#
+# @file: the filename or file descriptor of the vmcore.
+#
+# Returns: nothing on success
+#
+# Since: 1.1
+##
+{ 'command': 'dump', 'data': {'file': 'str'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 7e3f4b9..fefdae2 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -572,6 +572,32 @@ Example:
EQMP
{
+ .name = "dump",
+ .args_type = "file:s",
+ .params = "file",
+ .help = "dump to file",
+ .user_print = monitor_user_noop,
+ .mhandler.cmd_new = qmp_marshal_input_dump,
+ },
+
+SQMP
+dump
+
+
+Dump to file.
+
+Arguments:
+
+- "file": Destination file (json-string)
+
+Example:
+
+-> { "execute": "dump", "arguments": { "file": "fd:dump" } }
+<- { "return": {} }
+
+EQMP
+
+ {
.name = "netdev_add",
.args_type = "netdev:O",
.params = "[user|tap|socket],id=str[,prop=value][,...]",
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 09/15] introduce a new monitor command 'dump' to dump guest's memory
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 09/15] introduce a new monitor command 'dump' to dump guest's memory Wen Congyang
@ 2012-01-19 16:32 ` Eric Blake
2012-01-30 5:36 ` Wen Congyang
0 siblings, 1 reply; 26+ messages in thread
From: Eric Blake @ 2012-01-19 16:32 UTC (permalink / raw)
To: Wen Congyang
Cc: Jan Kiszka, HATAYAMA Daisuke, Dave Anderson, qemu-devel,
Luiz Capitulino
[-- Attachment #1: Type: text/plain, Size: 1867 bytes --]
On 01/18/2012 08:07 PM, Wen Congyang wrote:
> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
> ---
> Makefile.target | 8 +-
> dump.c | 590 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> dump.h | 3 +
> hmp-commands.hx | 16 ++
> hmp.c | 9 +
> hmp.h | 1 +
> monitor.c | 3 +
> qapi-schema.json | 13 ++
> qmp-commands.hx | 26 +++
> 9 files changed, 665 insertions(+), 4 deletions(-)
> create mode 100644 dump.c
>
> +void qmp_dump(const char *file, Error **errp)
> +{
> + const char *p;
> + int fd = -1;
> + DumpState *s;
> +
> +#if !defined(WIN32)
> + if (strstart(file, "fd:", &p)) {
> + fd = qemu_get_fd(p);
> + if (fd == -1) {
> + error_set(errp, QERR_FD_NOT_FOUND, p);
> + return;
> + }
> + }
> +#endif
Thanks for implementing fd support off the bat.
> +
> + if (strstart(file, "file:", &p)) {
> + fd = open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
Use of O_CREAT requires that you pass a third argument to open()
specifying the mode_t to use.
> +++ b/hmp-commands.hx
> @@ -828,6 +828,22 @@ new parameters (if specified) once the vm migration finished successfully.
> ETEXI
>
> {
> + .name = "dump",
> + .args_type = "file:s",
> + .params = "file",
> + .help = "dump to file",
> + .user_print = monitor_user_noop,
> + .mhandler.cmd = hmp_dump,
> + },
What if I want to dump only a fraction of the memory? I think you need
optional start and length parameters, to limit how much memory to be
dumped, rather than forcing me to dump all memory at once.
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 09/15] introduce a new monitor command 'dump' to dump guest's memory
2012-01-19 16:32 ` Eric Blake
@ 2012-01-30 5:36 ` Wen Congyang
2012-01-30 17:19 ` Eric Blake
0 siblings, 1 reply; 26+ messages in thread
From: Wen Congyang @ 2012-01-30 5:36 UTC (permalink / raw)
To: Eric Blake
Cc: Jan Kiszka, HATAYAMA Daisuke, Dave Anderson, qemu-devel,
Luiz Capitulino
At 01/20/2012 12:32 AM, Eric Blake Wrote:
> On 01/18/2012 08:07 PM, Wen Congyang wrote:
>> Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
>> ---
>> Makefile.target | 8 +-
>> dump.c | 590 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> dump.h | 3 +
>> hmp-commands.hx | 16 ++
>> hmp.c | 9 +
>> hmp.h | 1 +
>> monitor.c | 3 +
>> qapi-schema.json | 13 ++
>> qmp-commands.hx | 26 +++
>> 9 files changed, 665 insertions(+), 4 deletions(-)
>> create mode 100644 dump.c
>>
>
>> +void qmp_dump(const char *file, Error **errp)
>> +{
>> + const char *p;
>> + int fd = -1;
>> + DumpState *s;
>> +
>> +#if !defined(WIN32)
>> + if (strstart(file, "fd:", &p)) {
>> + fd = qemu_get_fd(p);
>> + if (fd == -1) {
>> + error_set(errp, QERR_FD_NOT_FOUND, p);
>> + return;
>> + }
>> + }
>> +#endif
>
> Thanks for implementing fd support off the bat.
>
>> +
>> + if (strstart(file, "file:", &p)) {
>> + fd = open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
>
> Use of O_CREAT requires that you pass a third argument to open()
> specifying the mode_t to use.
Yes, I forgot it, and will fix it.
>
>> +++ b/hmp-commands.hx
>> @@ -828,6 +828,22 @@ new parameters (if specified) once the vm migration finished successfully.
>> ETEXI
>>
>> {
>> + .name = "dump",
>> + .args_type = "file:s",
>> + .params = "file",
>> + .help = "dump to file",
>> + .user_print = monitor_user_noop,
>> + .mhandler.cmd = hmp_dump,
>> + },
>
> What if I want to dump only a fraction of the memory? I think you need
> optional start and length parameters, to limit how much memory to be
> dumped, rather than forcing me to dump all memory at once.
>
It is OK to support it, but I do not know why do you want it?
The purpose of this command is dumping the memory when the guest is paniced.
And then we can use crash/gdb(or other application) to investigate why the guest
is paniced. So we should dump the whole memory.
Thanks
Wen Congyang
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 09/15] introduce a new monitor command 'dump' to dump guest's memory
2012-01-30 5:36 ` Wen Congyang
@ 2012-01-30 17:19 ` Eric Blake
2012-01-31 1:39 ` Wen Congyang
0 siblings, 1 reply; 26+ messages in thread
From: Eric Blake @ 2012-01-30 17:19 UTC (permalink / raw)
To: Wen Congyang
Cc: Jan Kiszka, HATAYAMA Daisuke, Dave Anderson, qemu-devel,
Luiz Capitulino
[-- Attachment #1: Type: text/plain, Size: 2427 bytes --]
On 01/29/2012 10:36 PM, Wen Congyang wrote:
>>> +++ b/hmp-commands.hx
>>> @@ -828,6 +828,22 @@ new parameters (if specified) once the vm migration finished successfully.
>>> ETEXI
>>>
>>> {
>>> + .name = "dump",
>>> + .args_type = "file:s",
>>> + .params = "file",
>>> + .help = "dump to file",
>>> + .user_print = monitor_user_noop,
>>> + .mhandler.cmd = hmp_dump,
>>> + },
>>
>> What if I want to dump only a fraction of the memory? I think you need
>> optional start and length parameters, to limit how much memory to be
>> dumped, rather than forcing me to dump all memory at once.
>>
>
> It is OK to support it, but I do not know why do you want it?
>
> The purpose of this command is dumping the memory when the guest is paniced.
> And then we can use crash/gdb(or other application) to investigate why the guest
> is paniced. So we should dump the whole memory.
That's one purpose, but not the only purpose. We shouldn't be
artificially constraining things into requiring the entire memory region
in order to use this command.
Libvirt provides virDomainMemoryPeek which currently wraps the 'memsave'
and 'pmemsave' monitor commands, but these commands output raw memory.
Your command is introducing a new memory format into ELF images, and if
'memsave' can already do a subset of memory, it also makes sense for
'dump' to do a subset when creating the ELF image. That is, if a
management app every has a reason to access a subset of memory, then
this reason exists whether the subset is raw or ELF formatted when
presented to the management app.
Meanwhile, on the libvirt side, the virDomainMemoryPeek API to
management apps is constrained - it sends the data inline with the
command, rather than on a side channel. Someday, I'd like to enhance
libvirt to have a dump-to-stream command, and reuse the existing libvirt
ability to stream large amounts of data on side channels, in order to
let management apps directly and atomically query a subset of memory
into a file with the desired formatting, rather than the current
approach of constraining the management app to only query 64k at a time
and to have to manually pause the guest if they need to atomically
inspect more memory.
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 09/15] introduce a new monitor command 'dump' to dump guest's memory
2012-01-30 17:19 ` Eric Blake
@ 2012-01-31 1:39 ` Wen Congyang
0 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-31 1:39 UTC (permalink / raw)
To: Eric Blake
Cc: Jan Kiszka, HATAYAMA Daisuke, Dave Anderson, qemu-devel,
Luiz Capitulino
At 01/31/2012 01:19 AM, Eric Blake Wrote:
> On 01/29/2012 10:36 PM, Wen Congyang wrote:
>>>> +++ b/hmp-commands.hx
>>>> @@ -828,6 +828,22 @@ new parameters (if specified) once the vm migration finished successfully.
>>>> ETEXI
>>>>
>>>> {
>>>> + .name = "dump",
>>>> + .args_type = "file:s",
>>>> + .params = "file",
>>>> + .help = "dump to file",
>>>> + .user_print = monitor_user_noop,
>>>> + .mhandler.cmd = hmp_dump,
>>>> + },
>>>
>>> What if I want to dump only a fraction of the memory? I think you need
>>> optional start and length parameters, to limit how much memory to be
>>> dumped, rather than forcing me to dump all memory at once.
>>>
>>
>> It is OK to support it, but I do not know why do you want it?
>>
>> The purpose of this command is dumping the memory when the guest is paniced.
>> And then we can use crash/gdb(or other application) to investigate why the guest
>> is paniced. So we should dump the whole memory.
>
> That's one purpose, but not the only purpose. We shouldn't be
> artificially constraining things into requiring the entire memory region
> in order to use this command.
>
> Libvirt provides virDomainMemoryPeek which currently wraps the 'memsave'
> and 'pmemsave' monitor commands, but these commands output raw memory.
> Your command is introducing a new memory format into ELF images, and if
> 'memsave' can already do a subset of memory, it also makes sense for
> 'dump' to do a subset when creating the ELF image. That is, if a
> management app every has a reason to access a subset of memory, then
> this reason exists whether the subset is raw or ELF formatted when
> presented to the management app.
OK. I know why you want it, and will support it. Please wait for some
days.
Thanks
Wen Congyang
>
> Meanwhile, on the libvirt side, the virDomainMemoryPeek API to
> management apps is constrained - it sends the data inline with the
> command, rather than on a side channel. Someday, I'd like to enhance
> libvirt to have a dump-to-stream command, and reuse the existing libvirt
> ability to stream large amounts of data on side channels, in order to
> let management apps directly and atomically query a subset of memory
> into a file with the desired formatting, rather than the current
> approach of constraining the management app to only query 64k at a time
> and to have to manually pause the guest if they need to atomically
> inspect more memory.
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 10/15] run dump at the background
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (8 preceding siblings ...)
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 09/15] introduce a new monitor command 'dump' to dump guest's memory Wen Congyang
@ 2012-01-19 3:07 ` Wen Congyang
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 11/15 v5] support detached dump Wen Congyang
` (5 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:07 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
The new monitor command dump may take long time to finish. So we need run it
at the background.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
dump.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 136 insertions(+), 19 deletions(-)
diff --git a/dump.c b/dump.c
index 2951b8b..b2cccd8 100644
--- a/dump.c
+++ b/dump.c
@@ -77,12 +77,20 @@ typedef struct DumpState {
char *error;
int fd;
target_phys_addr_t memory_offset;
+ int64_t bandwidth;
+ RAMBlock *block;
+ ram_addr_t start;
+ target_phys_addr_t offset;
+ QEMUTimer *timer;
} DumpState;
+#define DEFAULT_THROTTLE (32 << 20) /* Default dump speed throttling */
+
static DumpState *dump_get_current(void)
{
static DumpState current_dump = {
.state = DUMP_STATE_SETUP,
+ .bandwidth = DEFAULT_THROTTLE,
};
return ¤t_dump;
@@ -93,11 +101,19 @@ static int dump_cleanup(DumpState *s)
int ret = 0;
free_memory_mapping_list(&s->list);
+
if (s->fd != -1) {
close(s->fd);
s->fd = -1;
}
+ if (s->timer) {
+ qemu_del_timer(s->timer);
+ qemu_free_timer(s->timer);
+ }
+
+ qemu_resume_monitor();
+
return ret;
}
@@ -332,25 +348,40 @@ static int write_data(DumpState *s, void *buf, int length,
}
/* write the memroy to vmcore. 1 page per I/O. */
-static int write_memory(DumpState *s, RAMBlock *block,
- target_phys_addr_t *offset)
+static int write_memory(DumpState *s, RAMBlock *block, ram_addr_t start,
+ target_phys_addr_t *offset, int64_t *size,
+ int64_t deadline)
{
int i, ret;
+ int64_t writen_size = 0;
+ int64_t time;
- for (i = 0; i < block->length / TARGET_PAGE_SIZE; i++) {
- ret = write_data(s, block->host + i * TARGET_PAGE_SIZE,
+ for (i = 0; i < *size / TARGET_PAGE_SIZE; i++) {
+ ret = write_data(s, block->host + start + i * TARGET_PAGE_SIZE,
TARGET_PAGE_SIZE, offset);
if (ret < 0) {
return -1;
}
+ writen_size += TARGET_PAGE_SIZE;
+ time = qemu_get_clock_ms(rt_clock);
+ if (time >= deadline) {
+ /* time out */
+ *size = writen_size;
+ return 1;
+ }
}
- if ((block->length % TARGET_PAGE_SIZE) != 0) {
- ret = write_data(s, block->host + i * TARGET_PAGE_SIZE,
- block->length % TARGET_PAGE_SIZE, offset);
+ if ((*size % TARGET_PAGE_SIZE) != 0) {
+ ret = write_data(s, block->host + start + i * TARGET_PAGE_SIZE,
+ *size % TARGET_PAGE_SIZE, offset);
if (ret < 0) {
return -1;
}
+ time = qemu_get_clock_ms(rt_clock);
+ if (time >= deadline) {
+ /* time out */
+ return 1;
+ }
}
return 0;
@@ -379,6 +410,7 @@ static DumpState *dump_init(int fd, Error **errp)
CPUState *env;
DumpState *s = dump_get_current();
int ret;
+ const char *msg = NULL;
vm_stop(RUN_STATE_PAUSED);
s->state = DUMP_STATE_SETUP;
@@ -387,6 +419,9 @@ static DumpState *dump_init(int fd, Error **errp)
s->error = NULL;
}
s->fd = fd;
+ s->block = QLIST_FIRST(&ram_list.blocks);
+ s->start = 0;
+ s->timer = NULL;
/*
* get dump info: endian, class and architecture.
@@ -429,6 +464,9 @@ static DumpState *dump_init(int fd, Error **errp)
s->phdr_num += s->list.num;
}
+ msg = "terminal does not allow synchronous dumping, continuing detached\n";
+ qemu_suspend_monitor("%s", msg);
+
return s;
}
@@ -486,6 +524,7 @@ static int dump_begin(DumpState *s)
}
s->memory_offset = offset;
+ s->offset = offset;
return 0;
}
@@ -513,38 +552,116 @@ static int dump_completed(DumpState *s)
return 0;
}
-/* write all memory to vmcore */
-static int dump_iterate(DumpState *s)
+/*
+ * write memory to vmcore.
+ *
+ * this function has three return values:
+ * -1 : there was one error
+ * 0 : We haven't finished, caller have to go again
+ * 1 : We have finished, we can go to complete phase
+ */
+static int dump_iterate(DumpState *s, int64_t deadline)
{
- RAMBlock *block;
- target_phys_addr_t offset = s->memory_offset;
+ RAMBlock *block = s->block;
+ target_phys_addr_t offset = s->offset;
+ int64_t size, remain, writen_size;
+ int64_t total = s->bandwidth / 10;
int ret;
- /* write all memory to vmcore */
- QLIST_FOREACH(block, &ram_list.blocks, next) {
- ret = write_memory(s, block, &offset);
+ if ((block->length - s->start) >= total) {
+ size = total;
+ } else {
+ size = block->length - s->start;
+ }
+
+ ret = write_memory(s, block, s->start, &offset, &size, deadline);
+ if (ret < 0) {
+ return -1;
+ }
+
+ if (size == total || ret == 1) {
+ if ((size + s->start) == block->length) {
+ s->block = QLIST_NEXT(block, next);
+ s->start = 0;
+ } else {
+ s->start += size;
+ }
+ goto end;
+ }
+
+ while (size < total) {
+ block = QLIST_NEXT(block, next);
+ if (!block) {
+ /* we have finished */
+ return 1;
+ }
+
+ remain = total - size;
+ if (remain >= block->length) {
+ writen_size = block->length;
+ } else {
+ writen_size = remain;
+ }
+ ret = write_memory(s, block, 0, &offset, &writen_size, deadline);
if (ret < 0) {
return -1;
+ } else if (ret == 1) {
+ break;
}
+ size += writen_size;
+ }
+ if (writen_size == block->length) {
+ s->block = QLIST_NEXT(block, next);
+ s->start = 0;
+ } else {
+ s->block = block;
+ s->start = writen_size;
+ }
+
+end:
+ s->offset = offset;
+ if (!s->block) {
+ /* we have finished */
+ return 1;
}
- return dump_completed(s);
+ return 0;
}
-static int create_vmcore(DumpState *s)
+static void dump_rate_tick(void *opaque)
{
+ DumpState *s = opaque;
+ int64_t begin, end;
int ret;
- ret = dump_begin(s);
+ begin = qemu_get_clock_ms(rt_clock);
+ ret = dump_iterate(s, begin + 100);
if (ret < 0) {
- return -1;
+ return;
+ } else if (ret == 1) {
+ dump_completed(s);
+ return;
}
+ end = qemu_get_clock_ms(rt_clock);
+ if (end - begin >= 100) {
+ qemu_mod_timer(s->timer, end + 10);
+ } else {
+ qemu_mod_timer(s->timer, begin + 100);
+ }
+}
- ret = dump_iterate(s);
+static int create_vmcore(DumpState *s)
+{
+ int ret;
+
+ ret = dump_begin(s);
if (ret < 0) {
return -1;
}
+ s->timer = qemu_new_timer_ms(rt_clock, dump_rate_tick, s);
+ qemu_mod_timer(s->timer, qemu_get_clock_ms(rt_clock) + 100);
+
return 0;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 11/15 v5] support detached dump
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (9 preceding siblings ...)
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 10/15] run dump at the background Wen Congyang
@ 2012-01-19 3:07 ` Wen Congyang
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 12/15 v5] support to cancel the current dumping Wen Congyang
` (4 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:07 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Let the user to choose whether to block other monitor command while dumping.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
dump.c | 12 ++++++++----
hmp-commands.hx | 8 ++++----
hmp.c | 3 ++-
qapi-schema.json | 2 +-
qmp-commands.hx | 7 ++++---
5 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/dump.c b/dump.c
index b2cccd8..14c2642 100644
--- a/dump.c
+++ b/dump.c
@@ -76,6 +76,7 @@ typedef struct DumpState {
int state;
char *error;
int fd;
+ bool detach;
target_phys_addr_t memory_offset;
int64_t bandwidth;
RAMBlock *block;
@@ -405,7 +406,7 @@ static target_phys_addr_t get_offset(target_phys_addr_t phys_addr,
return -1;
}
-static DumpState *dump_init(int fd, Error **errp)
+static DumpState *dump_init(int fd, bool detach, Error **errp)
{
CPUState *env;
DumpState *s = dump_get_current();
@@ -422,6 +423,7 @@ static DumpState *dump_init(int fd, Error **errp)
s->block = QLIST_FIRST(&ram_list.blocks);
s->start = 0;
s->timer = NULL;
+ s->detach = detach;
/*
* get dump info: endian, class and architecture.
@@ -465,7 +467,9 @@ static DumpState *dump_init(int fd, Error **errp)
}
msg = "terminal does not allow synchronous dumping, continuing detached\n";
- qemu_suspend_monitor("%s", msg);
+ if (!detach && qemu_suspend_monitor("%s", msg) != 0) {
+ s->detach = true;
+ }
return s;
}
@@ -665,7 +669,7 @@ static int create_vmcore(DumpState *s)
return 0;
}
-void qmp_dump(const char *file, Error **errp)
+void qmp_dump(bool detach, const char *file, Error **errp)
{
const char *p;
int fd = -1;
@@ -694,7 +698,7 @@ void qmp_dump(const char *file, Error **errp)
return;
}
- s = dump_init(fd, errp);
+ s = dump_init(fd, detach, errp);
if (!s) {
return;
}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index c3615e3..4582875 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -829,18 +829,18 @@ ETEXI
{
.name = "dump",
- .args_type = "file:s",
+ .args_type = "detach:-d,file:s",
.params = "file",
- .help = "dump to file",
+ .help = "dump to file (using -d to not wait for completion)",
.user_print = monitor_user_noop,
.mhandler.cmd = hmp_dump,
},
STEXI
-@item dump @var{file}
+@item dump [-d] @var{file}
@findex dump
-Dump to @var{file}.
+Dump to @var{file} (using -d to not wait for completion).
ETEXI
{
diff --git a/hmp.c b/hmp.c
index 11b4ce6..1ae8926 100644
--- a/hmp.c
+++ b/hmp.c
@@ -685,8 +685,9 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict)
void hmp_dump(Monitor *mon, const QDict *qdict)
{
Error *errp = NULL;
+ bool detach = qdict_get_try_bool(qdict, "detach", 0);
const char *file = qdict_get_str(qdict, "file");
- qmp_dump(file, &errp);
+ qmp_dump(detach, file, &errp);
hmp_handle_error(mon, &errp);
}
diff --git a/qapi-schema.json b/qapi-schema.json
index 84c2c9a..f96268a 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1287,4 +1287,4 @@
#
# Since: 1.1
##
-{ 'command': 'dump', 'data': {'file': 'str'} }
+{ 'command': 'dump', 'data': {'detach' : 'bool', 'file': 'str'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index fefdae2..59ddd98 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -573,9 +573,9 @@ EQMP
{
.name = "dump",
- .args_type = "file:s",
+ .args_type = "detach:-d,file:s",
.params = "file",
- .help = "dump to file",
+ .help = "dump to file (using -d to not wait for completion)",
.user_print = monitor_user_noop,
.mhandler.cmd_new = qmp_marshal_input_dump,
},
@@ -588,7 +588,8 @@ Dump to file.
Arguments:
-- "file": Destination file (json-string)
+- "detach": detached dumping (json-bool, optional)
+- "file": Destination file (json-string)
Example:
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 12/15 v5] support to cancel the current dumping
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (10 preceding siblings ...)
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 11/15 v5] support detached dump Wen Congyang
@ 2012-01-19 3:07 ` Wen Congyang
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 13/15 v5] support to set dumping speed Wen Congyang
` (3 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:07 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Add API to allow the user to cancel the current dumping.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
dump.c | 13 +++++++++++++
hmp-commands.hx | 14 ++++++++++++++
hmp.c | 5 +++++
hmp.h | 1 +
qapi-schema.json | 13 +++++++++++++
qmp-commands.hx | 21 +++++++++++++++++++++
6 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/dump.c b/dump.c
index 14c2642..485e3f3 100644
--- a/dump.c
+++ b/dump.c
@@ -709,3 +709,16 @@ void qmp_dump(bool detach, const char *file, Error **errp)
return;
}
+
+void qmp_dump_cancel(Error **errp)
+{
+ DumpState *s = dump_get_current();
+
+ if (s->state != DUMP_STATE_ACTIVE) {
+ return;
+ }
+
+ s->state = DUMP_STATE_CANCELLED;
+ dump_cleanup(s);
+ return;
+}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 4582875..57f5a20 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -844,6 +844,20 @@ Dump to @var{file} (using -d to not wait for completion).
ETEXI
{
+ .name = "dump_cancel",
+ .args_type = "",
+ .params = "",
+ .help = "cancel the current VM dumping",
+ .mhandler.cmd = hmp_dump_cancel,
+ },
+
+STEXI
+@item dump_cancel
+@findex dump_cancel
+Cancel the current VM dumping.
+ETEXI
+
+ {
.name = "snapshot_blkdev",
.args_type = "device:B,snapshot-file:s?,format:s?",
.params = "device [new-image-file] [format]",
diff --git a/hmp.c b/hmp.c
index 1ae8926..bca411b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -691,3 +691,8 @@ void hmp_dump(Monitor *mon, const QDict *qdict)
qmp_dump(detach, file, &errp);
hmp_handle_error(mon, &errp);
}
+
+void hmp_dump_cancel(Monitor *mon, const QDict *qdict)
+{
+ qmp_dump_cancel(NULL);
+}
diff --git a/hmp.h b/hmp.h
index 8d6a5d2..c0037b6 100644
--- a/hmp.h
+++ b/hmp.h
@@ -50,5 +50,6 @@ void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
void hmp_dump(Monitor *mon, const QDict *qdict);
+void hmp_dump_cancel(Monitor *mon, const QDict *qdict);
#endif
diff --git a/qapi-schema.json b/qapi-schema.json
index f96268a..bbd2011 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1288,3 +1288,16 @@
# Since: 1.1
##
{ 'command': 'dump', 'data': {'detach' : 'bool', 'file': 'str'} }
+
+##
+# @dump_cancel
+#
+# Cancel the current executing dumping process.
+#
+# Returns: nothing on success
+#
+# Notes: This command succeeds even if there is no dumping process running.
+#
+# Since: 1.1
+##
+{ 'command': 'dump_cancel' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 59ddd98..055072d 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -599,6 +599,27 @@ Example:
EQMP
{
+ .name = "dump_cancel",
+ .args_type = "",
+ .mhandler.cmd_new = qmp_marshal_input_dump_cancel,
+ },
+
+SQMP
+dump_cancel
+
+
+Cancel the current dumping.
+
+Arguments: None.
+
+Example:
+
+-> { "execute": "dump_cancel" }
+<- { "return": {} }
+
+EQMP
+
+ {
.name = "netdev_add",
.args_type = "netdev:O",
.params = "[user|tap|socket],id=str[,prop=value][,...]",
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 13/15 v5] support to set dumping speed
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (11 preceding siblings ...)
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 12/15 v5] support to cancel the current dumping Wen Congyang
@ 2012-01-19 3:07 ` Wen Congyang
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 14/15 v5] support to query dumping status Wen Congyang
` (2 subsequent siblings)
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:07 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Add API to allow the user to control dumping speed
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
dump.c | 12 ++++++++++++
hmp-commands.hx | 15 +++++++++++++++
hmp.c | 6 ++++++
hmp.h | 1 +
qapi-schema.json | 15 +++++++++++++++
qmp-commands.hx | 22 ++++++++++++++++++++++
6 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/dump.c b/dump.c
index 485e3f3..39dc892 100644
--- a/dump.c
+++ b/dump.c
@@ -86,6 +86,7 @@ typedef struct DumpState {
} DumpState;
#define DEFAULT_THROTTLE (32 << 20) /* Default dump speed throttling */
+#define MIN_THROTTLE (1 << 10) /* Miniumum dump speed */
static DumpState *dump_get_current(void)
{
@@ -722,3 +723,14 @@ void qmp_dump_cancel(Error **errp)
dump_cleanup(s);
return;
}
+
+void qmp_dump_set_speed(int64_t value, Error **errp)
+{
+ DumpState *s = dump_get_current();
+
+ if (value < MIN_THROTTLE) {
+ value = MIN_THROTTLE;
+ }
+ s->bandwidth = value;
+ return;
+}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 57f5a20..e71a174 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -858,6 +858,21 @@ Cancel the current VM dumping.
ETEXI
{
+ .name = "dump_set_speed",
+ .args_type = "value:o",
+ .params = "value",
+ .help = "set maximum speed (in bytes) for dumping. "
+ "Defaults to MB if no size suffix is specified, ie. B/K/M/G/T",
+ .mhandler.cmd = hmp_dump_set_speed,
+ },
+
+STEXI
+@item dump_set_speed @var{value}
+@findex dump_set_speed
+Set maximum speed to @var{value} (in bytes) for dumping.
+ETEXI
+
+ {
.name = "snapshot_blkdev",
.args_type = "device:B,snapshot-file:s?,format:s?",
.params = "device [new-image-file] [format]",
diff --git a/hmp.c b/hmp.c
index bca411b..4c015f9 100644
--- a/hmp.c
+++ b/hmp.c
@@ -696,3 +696,9 @@ void hmp_dump_cancel(Monitor *mon, const QDict *qdict)
{
qmp_dump_cancel(NULL);
}
+
+void hmp_dump_set_speed(Monitor *mon, const QDict *qdict)
+{
+ int64_t value = qdict_get_int(qdict, "value");
+ qmp_dump_set_speed(value, NULL);
+}
diff --git a/hmp.h b/hmp.h
index c0037b6..2d71343 100644
--- a/hmp.h
+++ b/hmp.h
@@ -51,5 +51,6 @@ void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
void hmp_dump(Monitor *mon, const QDict *qdict);
void hmp_dump_cancel(Monitor *mon, const QDict *qdict);
+void hmp_dump_set_speed(Monitor *mon, const QDict *qdict);
#endif
diff --git a/qapi-schema.json b/qapi-schema.json
index bbd2011..ec19631 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1301,3 +1301,18 @@
# Since: 1.1
##
{ 'command': 'dump_cancel' }
+
+##
+# @dump_set_speed
+#
+# Set maximum speed for dumping.
+#
+# @value: maximum speed in bytes.
+#
+# Returns: nothing on success
+#
+# Notes: A value lesser than 1024 will be automatically round up to 1024.
+#
+# Since: 1.1
+##
+{ 'command': 'dump_set_speed', 'data': {'value': 'int'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 055072d..509273e 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -620,6 +620,28 @@ Example:
EQMP
{
+ .name = "dump_set_speed",
+ .args_type = "value:o",
+ .mhandler.cmd_new = qmp_marshal_input_dump_set_speed,
+ },
+
+SQMP
+dump_set_speed
+
+Set maximum speed for dumping.
+
+Arguments:
+
+- "value": maximum speed, in bytes per second (json-int)
+
+Example:
+
+-> { "execute": "dump_set_speed", "arguments": { "value": 1024 } }
+<- { "return": {} }
+
+EQMP
+
+ {
.name = "netdev_add",
.args_type = "netdev:O",
.params = "[user|tap|socket],id=str[,prop=value][,...]",
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 14/15 v5] support to query dumping status
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (12 preceding siblings ...)
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 13/15 v5] support to set dumping speed Wen Congyang
@ 2012-01-19 3:07 ` Wen Congyang
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 15/15 v5] auto cancel dumping after vm state is changed to run Wen Congyang
2012-01-19 3:32 ` [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Jun Koi
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:07 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
Add API to allow the user to query dumping status.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
dump.c | 32 ++++++++++++++++++++++++++++++++
hmp-commands.hx | 2 ++
hmp.c | 17 +++++++++++++++++
hmp.h | 1 +
monitor.c | 7 +++++++
qapi-schema.json | 26 ++++++++++++++++++++++++++
qmp-commands.hx | 47 +++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 132 insertions(+), 0 deletions(-)
diff --git a/dump.c b/dump.c
index 39dc892..b681a2e 100644
--- a/dump.c
+++ b/dump.c
@@ -734,3 +734,35 @@ void qmp_dump_set_speed(int64_t value, Error **errp)
s->bandwidth = value;
return;
}
+
+DumpInfo *qmp_query_dump(Error **errp)
+{
+ DumpInfo *info = g_malloc0(sizeof(*info));
+ DumpState *s = dump_get_current();
+
+ switch (s->state) {
+ case DUMP_STATE_SETUP:
+ /* no migration has happened ever */
+ break;
+ case DUMP_STATE_ACTIVE:
+ info->has_status = true;
+ info->status = g_strdup("active");
+ break;
+ case DUMP_STATE_COMPLETED:
+ info->has_status = true;
+ info->status = g_strdup("completed");
+ break;
+ case DUMP_STATE_ERROR:
+ info->has_status = true;
+ info->status = g_strdup("failed");
+ info->has_error = true;
+ info->error = g_strdup(s->error);
+ break;
+ case DUMP_STATE_CANCELLED:
+ info->has_status = true;
+ info->status = g_strdup("cancelled");
+ break;
+ }
+
+ return info;
+}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index e71a174..5796786 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1395,6 +1395,8 @@ show device tree
show qdev device model list
@item info roms
show roms
+@item info dump
+show dumping status
@end table
ETEXI
diff --git a/hmp.c b/hmp.c
index 4c015f9..087dae4 100644
--- a/hmp.c
+++ b/hmp.c
@@ -702,3 +702,20 @@ void hmp_dump_set_speed(Monitor *mon, const QDict *qdict)
int64_t value = qdict_get_int(qdict, "value");
qmp_dump_set_speed(value, NULL);
}
+
+void hmp_info_dump(Monitor *mon)
+{
+ DumpInfo *info;
+
+ info = qmp_query_dump(NULL);
+
+ if (info->has_status) {
+ monitor_printf(mon, "Dumping status: %s\n", info->status);
+ }
+
+ if (info->has_error) {
+ monitor_printf(mon, "Dumping failed reason: %s\n", info->error);
+ }
+
+ qapi_free_DumpInfo(info);
+}
diff --git a/hmp.h b/hmp.h
index 2d71343..b91deb8 100644
--- a/hmp.h
+++ b/hmp.h
@@ -52,5 +52,6 @@ void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
void hmp_dump(Monitor *mon, const QDict *qdict);
void hmp_dump_cancel(Monitor *mon, const QDict *qdict);
void hmp_dump_set_speed(Monitor *mon, const QDict *qdict);
+void hmp_info_dump(Monitor *mon);
#endif
diff --git a/monitor.c b/monitor.c
index 24d4371..47e64b6 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2744,6 +2744,13 @@ static mon_cmd_t info_cmds[] = {
.mhandler.info = do_trace_print_events,
},
{
+ .name = "dump",
+ .args_type = "",
+ .params = "",
+ .help = "show dumping status",
+ .mhandler.info = hmp_info_dump,
+ },
+ {
.name = NULL,
},
};
diff --git a/qapi-schema.json b/qapi-schema.json
index ec19631..5edf3d1 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1316,3 +1316,29 @@
# Since: 1.1
##
{ 'command': 'dump_set_speed', 'data': {'value': 'int'} }
+
+##
+# @DumpInfo
+#
+# Information about current migration process.
+#
+# @status: #optional string describing the current dumping status.
+# As of 1,1 this can be 'active', 'completed', 'failed' or
+# 'cancelled'. If this field is not returned, no migration process
+# has been initiated
+#
+# Since: 1.1
+##
+{ 'type': 'DumpInfo',
+ 'data': {'*status': 'str', '*error': 'str'} }
+
+##
+# @query-dump
+#
+# Returns information about current dumping process.
+#
+# Returns: @DumpInfo
+#
+# Since: 1.1
+##
+{ 'command': 'query-dump', 'returns': 'DumpInfo' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 509273e..cb68ab8 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2040,6 +2040,53 @@ EQMP
},
SQMP
+query-dump
+-------------
+
+Dumping status.
+
+Return a json-object.
+
+The main json-object contains the following:
+
+- "status": migration status (json-string)
+ - Possible values: "active", "completed", "failed", "cancelled"
+
+Examples:
+
+1. Before the first migration
+
+-> { "execute": "query-dump" }
+<- { "return": {} }
+
+2. Migration is done and has succeeded
+
+-> { "execute": "query-dump" }
+<- { "return": { "status": "completed" } }
+
+3. Migration is done and has failed
+
+-> { "execute": "query-dump" }
+<- { "return": { "status": "failed" } }
+
+4. Migration is being performed:
+
+-> { "execute": "query-dump" }
+<- {
+ "return":{
+ "status":"active",
+ }
+ }
+
+EQMP
+
+ {
+ .name = "query-dump",
+ .args_type = "",
+ .mhandler.cmd_new = qmp_marshal_input_query_dump,
+ },
+
+SQMP
query-balloon
-------------
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* [Qemu-devel] [RFC][PATCH 15/15 v5] auto cancel dumping after vm state is changed to run
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (13 preceding siblings ...)
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 14/15 v5] support to query dumping status Wen Congyang
@ 2012-01-19 3:07 ` Wen Congyang
2012-01-19 3:32 ` [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Jun Koi
15 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:07 UTC (permalink / raw)
To: qemu-devel, Jan Kiszka, Dave Anderson, HATAYAMA Daisuke,
Luiz Capitulino
The command dump does not support to dump while vm is running. If the user resume
the vm, we should auto cancel dumping and set the status to failed.
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
---
dump.c | 19 +++++++++++++++++++
vl.c | 5 +++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/dump.c b/dump.c
index b681a2e..b3847a0 100644
--- a/dump.c
+++ b/dump.c
@@ -83,6 +83,7 @@ typedef struct DumpState {
ram_addr_t start;
target_phys_addr_t offset;
QEMUTimer *timer;
+ VMChangeStateEntry *handler;
} DumpState;
#define DEFAULT_THROTTLE (32 << 20) /* Default dump speed throttling */
@@ -114,6 +115,11 @@ static int dump_cleanup(DumpState *s)
qemu_free_timer(s->timer);
}
+ if (s->handler) {
+ qemu_del_vm_change_state_handler(s->handler);
+ s->handler = NULL;
+ }
+
qemu_resume_monitor();
return ret;
@@ -670,6 +676,17 @@ static int create_vmcore(DumpState *s)
return 0;
}
+static void dump_vm_state_change(void *opaque, int running, RunState state)
+{
+ DumpState *s = opaque;
+
+ if (running) {
+ qmp_dump_cancel(NULL);
+ s->state = DUMP_STATE_ERROR;
+ s->error = g_strdup("vm state is changed to run\n");
+ }
+}
+
void qmp_dump(bool detach, const char *file, Error **errp)
{
const char *p;
@@ -704,6 +721,8 @@ void qmp_dump(bool detach, const char *file, Error **errp)
return;
}
+ s->handler = qemu_add_vm_change_state_handler(dump_vm_state_change, s);
+
if (create_vmcore(s) < 0) {
error_set(errp, QERR_IO_ERROR);
}
diff --git a/vl.c b/vl.c
index ba55b35..2d9df0f 100644
--- a/vl.c
+++ b/vl.c
@@ -1247,11 +1247,12 @@ void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
void vm_state_notify(int running, RunState state)
{
- VMChangeStateEntry *e;
+ VMChangeStateEntry *e, *next;
trace_vm_state_notify(running, state);
- for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
+ /* e->cb() may remove itself */
+ QLIST_FOREACH_SAFE(e, &vm_change_state_head, entries, next) {
e->cb(e->opaque, running, state);
}
}
--
1.7.1
^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism
2012-01-19 2:50 [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Wen Congyang
` (14 preceding siblings ...)
2012-01-19 3:07 ` [Qemu-devel] [RFC][PATCH 15/15 v5] auto cancel dumping after vm state is changed to run Wen Congyang
@ 2012-01-19 3:32 ` Jun Koi
2012-01-19 3:39 ` Wen Congyang
15 siblings, 1 reply; 26+ messages in thread
From: Jun Koi @ 2012-01-19 3:32 UTC (permalink / raw)
To: Wen Congyang
Cc: Jan Kiszka, HATAYAMA Daisuke, Dave Anderson, qemu-devel,
Luiz Capitulino
On Thu, Jan 19, 2012 at 10:50 AM, Wen Congyang <wency@cn.fujitsu.com> wrote:
> Hi, all
>
> 'virsh dump' can not work when host pci device is used by guest. We have
> discussed this issue here:
> http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg00736.html
>
> We have determined to introduce a new command dump to dump memory. The core
> file's format can be elf.
do you pause the guest when the dump happen, or you can somehow let it
continue to run?
would be wonderful if you can do the latter, since dumping a guest
memory can take a lot of time.
thanks,
Jun
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism
2012-01-19 3:32 ` [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism Jun Koi
@ 2012-01-19 3:39 ` Wen Congyang
2012-01-19 16:34 ` Eric Blake
0 siblings, 1 reply; 26+ messages in thread
From: Wen Congyang @ 2012-01-19 3:39 UTC (permalink / raw)
To: Jun Koi
Cc: Jan Kiszka, HATAYAMA Daisuke, Dave Anderson, qemu-devel,
Luiz Capitulino
At 01/19/2012 11:32 AM, Jun Koi Wrote:
> On Thu, Jan 19, 2012 at 10:50 AM, Wen Congyang <wency@cn.fujitsu.com> wrote:
>> Hi, all
>>
>> 'virsh dump' can not work when host pci device is used by guest. We have
>> discussed this issue here:
>> http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg00736.html
>>
>> We have determined to introduce a new command dump to dump memory. The core
>> file's format can be elf.
>
> do you pause the guest when the dump happen, or you can somehow let it
> continue to run?
I pause the guest when the dump happens.
>
> would be wonderful if you can do the latter, since dumping a guest
> memory can take a lot of time.
Yes, it may tak a lot of time. But we dump a guest memory when the guest
panics, and there is no need to continue to run the guest.
Thanks
Wen Congyang
>
> thanks,
> Jun
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism
2012-01-19 3:39 ` Wen Congyang
@ 2012-01-19 16:34 ` Eric Blake
2012-01-30 5:40 ` Wen Congyang
0 siblings, 1 reply; 26+ messages in thread
From: Eric Blake @ 2012-01-19 16:34 UTC (permalink / raw)
To: Wen Congyang
Cc: Jan Kiszka, qemu-devel, Luiz Capitulino, HATAYAMA Daisuke,
Dave Anderson, Jun Koi
[-- Attachment #1: Type: text/plain, Size: 1899 bytes --]
On 01/18/2012 08:39 PM, Wen Congyang wrote:
> At 01/19/2012 11:32 AM, Jun Koi Wrote:
>> On Thu, Jan 19, 2012 at 10:50 AM, Wen Congyang <wency@cn.fujitsu.com> wrote:
>>> Hi, all
>>>
>>> 'virsh dump' can not work when host pci device is used by guest. We have
>>> discussed this issue here:
>>> http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg00736.html
>>>
>>> We have determined to introduce a new command dump to dump memory. The core
>>> file's format can be elf.
>>
>> do you pause the guest when the dump happen, or you can somehow let it
>> continue to run?
>
> I pause the guest when the dump happens.
>
>>
>> would be wonderful if you can do the latter, since dumping a guest
>> memory can take a lot of time.
>
> Yes, it may tak a lot of time. But we dump a guest memory when the guest
> panics, and there is no need to continue to run the guest.
Would it be possible to have both a dump from a certain point in time
and still allow the guest to run unpaused?
I'm thinking something along the lines of pausing the guest, setting up
control structures, then calling fork(). The parent can then unpause,
and use the control structures to communicate the memory state from the
child back out the monitor. Meanwhile, the guest has a copy-on-write
clone of the entire memory state, so as long as the control structures
guarantee that the child will not accept any monitor commands and not
resume the guest, then the child process can be used to stream the
memory contents as they were at the time of the dump command back over
the control structure back to the parent process. I will admit,
however, that following the fork(), you would be limited to
async-signal-safe functions, so it may be a rather difficult task to design.
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism
2012-01-19 16:34 ` Eric Blake
@ 2012-01-30 5:40 ` Wen Congyang
2012-01-30 17:38 ` Eric Blake
0 siblings, 1 reply; 26+ messages in thread
From: Wen Congyang @ 2012-01-30 5:40 UTC (permalink / raw)
To: Eric Blake
Cc: Jan Kiszka, qemu-devel, Luiz Capitulino, HATAYAMA Daisuke,
Dave Anderson, Jun Koi
At 01/20/2012 12:34 AM, Eric Blake Wrote:
> On 01/18/2012 08:39 PM, Wen Congyang wrote:
>> At 01/19/2012 11:32 AM, Jun Koi Wrote:
>>> On Thu, Jan 19, 2012 at 10:50 AM, Wen Congyang <wency@cn.fujitsu.com> wrote:
>>>> Hi, all
>>>>
>>>> 'virsh dump' can not work when host pci device is used by guest. We have
>>>> discussed this issue here:
>>>> http://lists.nongnu.org/archive/html/qemu-devel/2011-10/msg00736.html
>>>>
>>>> We have determined to introduce a new command dump to dump memory. The core
>>>> file's format can be elf.
>>>
>>> do you pause the guest when the dump happen, or you can somehow let it
>>> continue to run?
>>
>> I pause the guest when the dump happens.
>>
>>>
>>> would be wonderful if you can do the latter, since dumping a guest
>>> memory can take a lot of time.
>>
>> Yes, it may tak a lot of time. But we dump a guest memory when the guest
>> panics, and there is no need to continue to run the guest.
>
> Would it be possible to have both a dump from a certain point in time
> and still allow the guest to run unpaused?
>
> I'm thinking something along the lines of pausing the guest, setting up
> control structures, then calling fork(). The parent can then unpause,
> and use the control structures to communicate the memory state from the
> child back out the monitor. Meanwhile, the guest has a copy-on-write
> clone of the entire memory state, so as long as the control structures
> guarantee that the child will not accept any monitor commands and not
> resume the guest, then the child process can be used to stream the
> memory contents as they were at the time of the dump command back over
> the control structure back to the parent process. I will admit,
> however, that following the fork(), you would be limited to
> async-signal-safe functions, so it may be a rather difficult task to design.
>
I do not understand this section. Do you say the reason of allowing the guest
to run unpaused? Or do you say the way to do it?
Thanks
Wen Congyang
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism
2012-01-30 5:40 ` Wen Congyang
@ 2012-01-30 17:38 ` Eric Blake
2012-01-31 1:35 ` Wen Congyang
0 siblings, 1 reply; 26+ messages in thread
From: Eric Blake @ 2012-01-30 17:38 UTC (permalink / raw)
To: Wen Congyang
Cc: Jan Kiszka, qemu-devel, Luiz Capitulino, HATAYAMA Daisuke,
Dave Anderson, Jun Koi
[-- Attachment #1: Type: text/plain, Size: 3013 bytes --]
On 01/29/2012 10:40 PM, Wen Congyang wrote:
>>> Yes, it may tak a lot of time. But we dump a guest memory when the guest
>>> panics, and there is no need to continue to run the guest.
>>
>> Would it be possible to have both a dump from a certain point in time
>> and still allow the guest to run unpaused?
>>
>> I'm thinking something along the lines of pausing the guest, setting up
>> control structures, then calling fork(). The parent can then unpause,
>> and use the control structures to communicate the memory state from the
>> child back out the monitor. Meanwhile, the guest has a copy-on-write
>> clone of the entire memory state, so as long as the control structures
>> guarantee that the child will not accept any monitor commands and not
>> resume the guest, then the child process can be used to stream the
>> memory contents as they were at the time of the dump command back over
>> the control structure back to the parent process. I will admit,
>> however, that following the fork(), you would be limited to
>> async-signal-safe functions, so it may be a rather difficult task to design.
>>
>
> I do not understand this section. Do you say the reason of allowing the guest
> to run unpaused? Or do you say the way to do it?
Among other reasons for supporting a guest that runs in parallel with a
memory dump, I'm envisioning a thin-provisioning setup. Right now, you
have to get a common off-line base disk image state, then each cloned
guest has to boot from scratch as a delta from that base state. But it
would be a lot faster if you could get a common on-line VM state, and
start cloned guests from the same memory state as the baseline. Taking
it further, I can envision a forensic-style application, that runs
what-if scenarios, by running two similar guests side by side and seeing
what happens when only one of the two guests has a particular tweak
made. Or suppose you have a production server, and want to apply a
patch, but want to make sure the patch will work before committing to it
- the obvious way is to apply the patch to a temporary cloned VM. But
because it is a production server, you can't afford to wait for a long
downtime with the guest paused just to capture the machine state for
cloning a temporary VM for testing out the patch.
Basically, in all of these scenarios, my idea is that it should be easy
(well, at least easier than it currently is), to create a new guest
based on the memory state of an existing guest, all without impacting
the existing guest. And to do that, it would be nice to be able to
reliably dump the state of memory of a guest at a given point of time,
all while continuing to let the original guest run past that point in time.
But whether this has to be done right away, or whether it even fits in
with your 'dump' command vs. needing a command of its own, I don't know.
--
Eric Blake eblake@redhat.com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [Qemu-devel] [RFC][PATCH 00/15 v5] introducing a new, dedicated memory dump mechanism
2012-01-30 17:38 ` Eric Blake
@ 2012-01-31 1:35 ` Wen Congyang
0 siblings, 0 replies; 26+ messages in thread
From: Wen Congyang @ 2012-01-31 1:35 UTC (permalink / raw)
To: Eric Blake
Cc: Jan Kiszka, qemu-devel, Luiz Capitulino, HATAYAMA Daisuke,
Dave Anderson, Jun Koi
At 01/31/2012 01:38 AM, Eric Blake Wrote:
> On 01/29/2012 10:40 PM, Wen Congyang wrote:
>>>> Yes, it may tak a lot of time. But we dump a guest memory when the guest
>>>> panics, and there is no need to continue to run the guest.
>>>
>>> Would it be possible to have both a dump from a certain point in time
>>> and still allow the guest to run unpaused?
>>>
>>> I'm thinking something along the lines of pausing the guest, setting up
>>> control structures, then calling fork(). The parent can then unpause,
>>> and use the control structures to communicate the memory state from the
>>> child back out the monitor. Meanwhile, the guest has a copy-on-write
>>> clone of the entire memory state, so as long as the control structures
>>> guarantee that the child will not accept any monitor commands and not
>>> resume the guest, then the child process can be used to stream the
>>> memory contents as they were at the time of the dump command back over
>>> the control structure back to the parent process. I will admit,
>>> however, that following the fork(), you would be limited to
>>> async-signal-safe functions, so it may be a rather difficult task to design.
>>>
>>
>> I do not understand this section. Do you say the reason of allowing the guest
>> to run unpaused? Or do you say the way to do it?
>
> Among other reasons for supporting a guest that runs in parallel with a
> memory dump, I'm envisioning a thin-provisioning setup. Right now, you
> have to get a common off-line base disk image state, then each cloned
> guest has to boot from scratch as a delta from that base state. But it
> would be a lot faster if you could get a common on-line VM state, and
> start cloned guests from the same memory state as the baseline. Taking
> it further, I can envision a forensic-style application, that runs
> what-if scenarios, by running two similar guests side by side and seeing
> what happens when only one of the two guests has a particular tweak
> made. Or suppose you have a production server, and want to apply a
> patch, but want to make sure the patch will work before committing to it
> - the obvious way is to apply the patch to a temporary cloned VM. But
> because it is a production server, you can't afford to wait for a long
> downtime with the guest paused just to capture the machine state for
> cloning a temporary VM for testing out the patch.
>
> Basically, in all of these scenarios, my idea is that it should be easy
> (well, at least easier than it currently is), to create a new guest
> based on the memory state of an existing guest, all without impacting
> the existing guest. And to do that, it would be nice to be able to
> reliably dump the state of memory of a guest at a given point of time,
> all while continuing to let the original guest run past that point in time.
>
> But whether this has to be done right away, or whether it even fits in
> with your 'dump' command vs. needing a command of its own, I don't know.
>
Thanks for your explantion. I know what you want, and I think it needs a command
of its own. Because the 'dump' command only provides memory, and it does
not include device's state, CPU's state, and so on. If the guest uses host
devices, and i think it should not be cloned. If you want to get all the state
of the guest, you may need a command like 'mirgate' command.
Thanks
Wen Congyang
^ permalink raw reply [flat|nested] 26+ messages in thread