diff options
author | Lei Li <lilei@linux.vnet.ibm.com> | 2013-01-25 00:03:20 +0800 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2013-01-25 11:23:06 -0200 |
commit | 1f590cf9455c571799d1bfc0777255fa0796d4da (patch) | |
tree | 587b89852266e89772c565474d85d95f34fba37d /qemu-char.c | |
parent | 51767e7cf2c3abc07d30009ab3d6262bdfd89b8b (diff) | |
download | qemu-1f590cf9455c571799d1bfc0777255fa0796d4da.tar.gz qemu-1f590cf9455c571799d1bfc0777255fa0796d4da.tar.bz2 qemu-1f590cf9455c571799d1bfc0777255fa0796d4da.zip |
QAPI: Introduce memchar-write QMP command
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'qemu-char.c')
-rw-r--r-- | qemu-char.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/qemu-char.c b/qemu-char.c index 80458697f2..dbd1a7c066 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2748,6 +2748,48 @@ fail: return NULL; } +static bool qemu_is_chr(const CharDriverState *chr, const char *filename) +{ + return strcmp(chr->filename, filename); +} + +void qmp_memchar_write(const char *device, int64_t size, + const char *data, bool has_format, + enum DataFormat format, + Error **errp) +{ + CharDriverState *chr; + guchar *write_data; + int ret; + gsize write_count; + + chr = qemu_chr_find(device); + if (!chr) { + error_set(errp, QERR_DEVICE_NOT_FOUND, device); + return; + } + + if (qemu_is_chr(chr, "memory")) { + error_setg(errp,"%s is not memory char device", device); + return; + } + + write_count = (gsize)size; + + if (has_format && (format == DATA_FORMAT_BASE64)) { + write_data = g_base64_decode(data, &write_count); + } else { + write_data = (uint8_t *)data; + } + + ret = cirmem_chr_write(chr, write_data, write_count); + + if (ret < 0) { + error_setg(errp, "Failed to write to device %s", device); + return; + } +} + QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) { char host[65], port[33], width[8], height[8]; |