qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 05/16] qapi: Convert pmemsave


From: Luiz Capitulino
Subject: [Qemu-devel] [PATCH 05/16] qapi: Convert pmemsave
Date: Mon, 5 Dec 2011 18:00:15 -0200

Signed-off-by: Anthony Liguori <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
 cpus.c           |   30 ++++++++++++++++++++++++++++++
 hmp-commands.hx  |    3 +--
 hmp.c            |   11 +++++++++++
 hmp.h            |    1 +
 monitor.c        |   37 -------------------------------------
 qapi-schema.json |   22 ++++++++++++++++++++++
 qmp-commands.hx  |    5 +----
 7 files changed, 66 insertions(+), 43 deletions(-)

diff --git a/cpus.c b/cpus.c
index 0f2ce60..e916137 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1183,3 +1183,33 @@ void qmp_memsave(int64_t addr, int64_t size, const char 
*filename,
 exit:
     fclose(f);
 }
+
+void qmp_pmemsave(int64_t addr, int64_t size, const char *filename,
+                  Error **errp)
+{
+    FILE *f;
+    uint32_t l;
+    uint8_t buf[1024];
+
+    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_physical_memory_rw(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);
+}
diff --git a/hmp-commands.hx b/hmp-commands.hx
index dac0b47..0a721cc 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -703,8 +703,7 @@ ETEXI
         .args_type  = "val:l,size:i,filename:s",
         .params     = "addr size file",
         .help       = "save to disk physical memory dump starting at 'addr' of 
size 'size'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_physical_memory_save,
+        .mhandler.cmd = hmp_pmemsave,
     },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index 67b3eb3..96e3ce1 100644
--- a/hmp.c
+++ b/hmp.c
@@ -550,3 +550,14 @@ void hmp_memsave(Monitor *mon, const QDict *qdict)
     qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &errp);
     hmp_handle_error(mon, &errp);
 }
+
+void hmp_pmemsave(Monitor *mon, const QDict *qdict)
+{
+    uint32_t size = qdict_get_int(qdict, "size");
+    const char *filename = qdict_get_str(qdict, "filename");
+    uint64_t addr = qdict_get_int(qdict, "val");
+    Error *errp = NULL;
+
+    qmp_pmemsave(addr, size, filename, &errp);
+    hmp_handle_error(mon, &errp);
+}
diff --git a/hmp.h b/hmp.h
index dd8ad0c..4882bea 100644
--- a/hmp.h
+++ b/hmp.h
@@ -38,5 +38,6 @@ void hmp_system_reset(Monitor *mon, const QDict *qdict);
 void hmp_system_powerdown(Monitor *mon, const QDict *qdict);
 void hmp_cpu(Monitor *mon, const QDict *qdict);
 void hmp_memsave(Monitor *mon, const QDict *qdict);
+void hmp_pmemsave(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 7272014..a1b46b3 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1370,43 +1370,6 @@ static void do_print(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "\n");
 }
 
-static int do_physical_memory_save(Monitor *mon, const QDict *qdict,
-                                    QObject **ret_data)
-{
-    FILE *f;
-    uint32_t l;
-    uint8_t buf[1024];
-    uint32_t size = qdict_get_int(qdict, "size");
-    const char *filename = qdict_get_str(qdict, "filename");
-    target_phys_addr_t addr = qdict_get_int(qdict, "val");
-    int ret = -1;
-
-    f = fopen(filename, "wb");
-    if (!f) {
-        qerror_report(QERR_OPEN_FILE_FAILED, filename);
-        return -1;
-    }
-    while (size != 0) {
-        l = sizeof(buf);
-        if (l > size)
-            l = size;
-        cpu_physical_memory_read(addr, buf, l);
-        if (fwrite(buf, 1, l, f) != l) {
-            monitor_printf(mon, "fwrite() error in do_physical_memory_save\n");
-            goto exit;
-        }
-        fflush(f);
-        addr += l;
-        size -= l;
-    }
-
-    ret = 0;
-
-exit:
-    fclose(f);
-    return ret;
-}
-
 static void do_sum(Monitor *mon, const QDict *qdict)
 {
     uint32_t addr;
diff --git a/qapi-schema.json b/qapi-schema.json
index dbf6170..7f9aa94 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -927,3 +927,25 @@
 ##
 { 'command': 'memsave',
   'data': {'val': 'int', 'size': 'int', 'filename': 'str', '*cpu-index': 
'int'} }
+
+##
+# @pmemsave:
+#
+# Save a portion of guest physical memory to a file.
+#
+# @val: the physical address of the guest to start from
+#
+# @size: the size of memory region to save
+#
+# @filename: the file to save the memory to as binary data
+#
+# Returns: Nothing on success
+#          If @filename cannot be opened, OpenFileFailed
+#          If an I/O error occurs while writing the file, IOError
+#
+# Since: 0.14.0
+#
+# Notes: Errors were not reliably returned until 1.1
+##
+{ 'command': 'pmemsave',
+  'data': {'val': 'int', 'size': 'int', 'filename': 'str'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 0e2f392..5093ac9 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -382,10 +382,7 @@ EQMP
     {
         .name       = "pmemsave",
         .args_type  = "val:l,size:i,filename:s",
-        .params     = "addr size file",
-        .help       = "save to disk physical memory dump starting at 'addr' of 
size 'size'",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = do_physical_memory_save,
+        .mhandler.cmd_new = qmp_marshal_input_pmemsave,
     },
 
 SQMP
-- 
1.7.8.dirty




reply via email to

[Prev in Thread] Current Thread [Next in Thread]