qapi: Convert pmemsave

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
Luiz Capitulino 2011-11-22 17:26:46 -02:00
parent 0cfd6a9ab4
commit 6d3962bf84
7 changed files with 66 additions and 43 deletions

30
cpus.c
View File

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

View File

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

11
hmp.c
View File

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

1
hmp.h
View File

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

View File

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

View File

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

View File

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