This patch adds 'memory' support to qapi and also switches over the memory chardev initialization to the new qapi code path.
Signed-off-by: Gerd Hoffmann <kra...@redhat.com> --- qapi-schema.json | 14 +++++++++++++- qemu-char.c | 30 +++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 3c12122..59c025f 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3248,6 +3248,17 @@ '*rows' : 'int' } } ## +# @ChardevRingbuf: +# +# Configuration info for memory chardevs +# +# @size: #optional Ringbuffer size, must be power of two, default is 65536 +# +# Since: 1.5 +## +{ 'type': 'ChardevRingbuf', 'data': { '*size' : 'int' } } + +## # @ChardevBackend: # # Configuration info for the new chardev backend. @@ -3270,7 +3281,8 @@ 'console': 'ChardevDummy', 'spicevmc' : 'ChardevSpiceChannel', 'spiceport' : 'ChardevSpicePort', - 'vc' : 'ChardevVC' } } + 'vc' : 'ChardevVC', + 'memory' : 'ChardevRingbuf' } } ## # @ChardevReturn: diff --git a/qemu-char.c b/qemu-char.c index a1c668f..0e7d46c 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2860,7 +2860,8 @@ static void ringbuf_chr_close(struct CharDriverState *chr) chr->opaque = NULL; } -static CharDriverState *qemu_chr_open_ringbuf(QemuOpts *opts) +static CharDriverState *qemu_chr_open_ringbuf(ChardevRingbuf *opts, + Error **errp) { CharDriverState *chr; RingBufCharDriver *d; @@ -2868,14 +2869,11 @@ static CharDriverState *qemu_chr_open_ringbuf(QemuOpts *opts) chr = g_malloc0(sizeof(CharDriverState)); d = g_malloc(sizeof(*d)); - d->size = qemu_opt_get_size(opts, "size", 0); - if (d->size == 0) { - d->size = 65536; - } + d->size = opts->has_size ? opts->size : 65536; /* The size must be power of 2 */ if (d->size & (d->size - 1)) { - error_report("size of ringbuf device must be power of two"); + error_setg(errp, "size of ringbuf chardev must be power of two"); goto fail; } @@ -3177,6 +3175,20 @@ static void qemu_chr_parse_pipe(QemuOpts *opts, ChardevBackend *backend, backend->pipe->device = g_strdup(device); } +static void qemu_chr_parse_ringbuf(QemuOpts *opts, ChardevBackend *backend, + Error **errp) +{ + int val; + + backend->memory = g_new0(ChardevRingbuf, 1); + + val = qemu_opt_get_number(opts, "size", 0); + if (val != 0) { + backend->memory->has_size = true; + backend->memory->size = val; + } +} + typedef struct CharDriver { const char *name; /* old, pre qapi */ @@ -3716,6 +3728,9 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, case CHARDEV_BACKEND_KIND_VC: chr = vc_init(backend->vc); break; + case CHARDEV_BACKEND_KIND_MEMORY: + chr = qemu_chr_open_ringbuf(backend->memory, errp); + break; default: error_setg(errp, "unknown chardev backend (%d)", backend->kind); break; @@ -3758,7 +3773,8 @@ static void register_types(void) register_char_driver_qapi("null", CHARDEV_BACKEND_KIND_NULL, NULL); register_char_driver("socket", qemu_chr_open_socket); register_char_driver("udp", qemu_chr_open_udp); - register_char_driver("memory", qemu_chr_open_ringbuf); + register_char_driver_qapi("memory", CHARDEV_BACKEND_KIND_MEMORY, + qemu_chr_parse_ringbuf); register_char_driver_qapi("file", CHARDEV_BACKEND_KIND_FILE, qemu_chr_parse_file_out); register_char_driver_qapi("stdio", CHARDEV_BACKEND_KIND_STDIO, -- 1.7.9.7