qmp: Clean up design of memchar-read
The data returned has a well-defined size, which makes the size returned along with it redundant at best. Drop it. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
82e59a676c
commit
3ab651fc81
11
hmp.c
11
hmp.c
@ -677,21 +677,18 @@ void hmp_memchar_read(Monitor *mon, const QDict *qdict)
|
|||||||
{
|
{
|
||||||
uint32_t size = qdict_get_int(qdict, "size");
|
uint32_t size = qdict_get_int(qdict, "size");
|
||||||
const char *chardev = qdict_get_str(qdict, "device");
|
const char *chardev = qdict_get_str(qdict, "device");
|
||||||
MemCharRead *meminfo;
|
char *data;
|
||||||
Error *errp = NULL;
|
Error *errp = NULL;
|
||||||
|
|
||||||
meminfo = qmp_memchar_read(chardev, size, false, 0, &errp);
|
data = qmp_memchar_read(chardev, size, false, 0, &errp);
|
||||||
if (errp) {
|
if (errp) {
|
||||||
monitor_printf(mon, "%s\n", error_get_pretty(errp));
|
monitor_printf(mon, "%s\n", error_get_pretty(errp));
|
||||||
error_free(errp);
|
error_free(errp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meminfo->count > 0) {
|
monitor_printf(mon, "%s\n", data);
|
||||||
monitor_printf(mon, "%s\n", meminfo->data);
|
g_free(data);
|
||||||
}
|
|
||||||
|
|
||||||
qapi_free_MemCharRead(meminfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hmp_cont_cb(void *opaque, int err)
|
static void hmp_cont_cb(void *opaque, int err)
|
||||||
|
@ -360,20 +360,6 @@
|
|||||||
'data': {'device': 'str', 'data': 'str',
|
'data': {'device': 'str', 'data': 'str',
|
||||||
'*format': 'DataFormat'} }
|
'*format': 'DataFormat'} }
|
||||||
|
|
||||||
##
|
|
||||||
# @MemCharRead
|
|
||||||
#
|
|
||||||
# Result of QMP command memchar-read.
|
|
||||||
#
|
|
||||||
# @data: The data read from memchar as string.
|
|
||||||
#
|
|
||||||
# @count: The numbers of bytes read from.
|
|
||||||
#
|
|
||||||
# Since: 1.4
|
|
||||||
##
|
|
||||||
{ 'type': 'MemCharRead',
|
|
||||||
'data': { 'data': 'str', 'count': 'int' } }
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# @memchar-read:
|
# @memchar-read:
|
||||||
#
|
#
|
||||||
@ -387,14 +373,14 @@
|
|||||||
# @format: #optional the format of the data want to read from
|
# @format: #optional the format of the data want to read from
|
||||||
# memchardev, by default is 'utf8'.
|
# memchardev, by default is 'utf8'.
|
||||||
#
|
#
|
||||||
# Returns: @MemCharRead
|
# Returns: data read from the device
|
||||||
# If @device is not a valid memchr device, DeviceNotFound
|
# If @device is not a valid memchr device, DeviceNotFound
|
||||||
#
|
#
|
||||||
# Since: 1.4
|
# Since: 1.4
|
||||||
##
|
##
|
||||||
{ 'command': 'memchar-read',
|
{ 'command': 'memchar-read',
|
||||||
'data': {'device': 'str', 'size': 'int', '*format': 'DataFormat'},
|
'data': {'device': 'str', 'size': 'int', '*format': 'DataFormat'},
|
||||||
'returns': 'MemCharRead' }
|
'returns': 'str' }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @CommandInfo:
|
# @CommandInfo:
|
||||||
|
17
qemu-char.c
17
qemu-char.c
@ -2788,14 +2788,14 @@ void qmp_memchar_write(const char *device, const char *data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MemCharRead *qmp_memchar_read(const char *device, int64_t size,
|
char *qmp_memchar_read(const char *device, int64_t size,
|
||||||
bool has_format, enum DataFormat format,
|
bool has_format, enum DataFormat format,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
CharDriverState *chr;
|
CharDriverState *chr;
|
||||||
guchar *read_data;
|
guchar *read_data;
|
||||||
MemCharRead *meminfo;
|
|
||||||
size_t count;
|
size_t count;
|
||||||
|
char *data;
|
||||||
|
|
||||||
chr = qemu_chr_find(device);
|
chr = qemu_chr_find(device);
|
||||||
if (!chr) {
|
if (!chr) {
|
||||||
@ -2813,26 +2813,23 @@ MemCharRead *qmp_memchar_read(const char *device, int64_t size,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
meminfo = g_malloc0(sizeof(MemCharRead));
|
|
||||||
|
|
||||||
count = qemu_chr_cirmem_count(chr);
|
count = qemu_chr_cirmem_count(chr);
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
meminfo->data = g_strdup("");
|
return g_strdup("");
|
||||||
return meminfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size = size > count ? count : size;
|
size = size > count ? count : size;
|
||||||
read_data = g_malloc0(size + 1);
|
read_data = g_malloc0(size + 1);
|
||||||
|
|
||||||
meminfo->count = cirmem_chr_read(chr, read_data, size);
|
cirmem_chr_read(chr, read_data, size);
|
||||||
|
|
||||||
if (has_format && (format == DATA_FORMAT_BASE64)) {
|
if (has_format && (format == DATA_FORMAT_BASE64)) {
|
||||||
meminfo->data = g_base64_encode(read_data, (size_t)meminfo->count);
|
data = g_base64_encode(read_data, size);
|
||||||
} else {
|
} else {
|
||||||
meminfo->data = (char *)read_data;
|
data = (char *)read_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return meminfo;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
|
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
|
||||||
|
@ -525,7 +525,7 @@ Example:
|
|||||||
"arguments": { "device": foo,
|
"arguments": { "device": foo,
|
||||||
"size": 1000,
|
"size": 1000,
|
||||||
"format": "utf8" } }
|
"format": "utf8" } }
|
||||||
<- { "return": { "data": "data string...", "count": 1000 } }
|
<- {"return": "abcdefgh"}
|
||||||
|
|
||||||
EQMP
|
EQMP
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user