summaryrefslogtreecommitdiff
path: root/cpus.c
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2011-11-22 16:32:37 -0200
committerLuiz Capitulino <lcapitulino@redhat.com>2011-12-06 11:40:00 -0200
commit0cfd6a9ab4356cd2c69bb29b1d70e1fd037bc1f2 (patch)
tree70d50b3eb62d4ad3bdd4ce128d40015299754694 /cpus.c
parent588988736634ad2aa356dafac78f88d1ea68b1a4 (diff)
downloadqemu-0cfd6a9ab4356cd2c69bb29b1d70e1fd037bc1f2.tar.gz
qemu-0cfd6a9ab4356cd2c69bb29b1d70e1fd037bc1f2.tar.bz2
qemu-0cfd6a9ab4356cd2c69bb29b1d70e1fd037bc1f2.zip
qapi: Convert memsave
Please, note that the QMP command has a new 'cpu-index' parameter. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'cpus.c')
-rw-r--r--cpus.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/cpus.c b/cpus.c
index ca46ec6523..0f2ce60a36 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1136,3 +1136,50 @@ CpuInfoList *qmp_query_cpus(Error **errp)
return head;
}
+
+void qmp_memsave(int64_t addr, int64_t size, const char *filename,
+ bool has_cpu, int64_t cpu_index, Error **errp)
+{
+ FILE *f;
+ uint32_t l;
+ CPUState *env;
+ uint8_t buf[1024];
+
+ if (!has_cpu) {
+ cpu_index = 0;
+ }
+
+ for (env = first_cpu; env; env = env->next_cpu) {
+ if (cpu_index == env->cpu_index) {
+ break;
+ }
+ }
+
+ if (env == NULL) {
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
+ "a CPU number");
+ return;
+ }
+
+ f = fopen(filename, "wb");
+ if (!f) {
+ error_set(errp, QERR_OPEN_FILE_FAILED, filename);
+ return;
+ }
+
+ while (size != 0) {
+ l = sizeof(buf);
+ if (l > size)
+ l = size;
+ cpu_memory_rw_debug(env, addr, buf, l, 0);
+ if (fwrite(buf, 1, l, f) != l) {
+ error_set(errp, QERR_IO_ERROR);
+ goto exit;
+ }
+ addr += l;
+ size -= l;
+ }
+
+exit:
+ fclose(f);
+}