diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2013-02-26 16:21:11 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2013-03-13 10:27:46 +0100 |
commit | 1da48c658a26d0c1444d05d8d3a545d311e01026 (patch) | |
tree | cba4ff0e2a4e5531b4714c980efa14a32d586edc /qemu-char.c | |
parent | 702ec69cc1aa87a1e53d1b066a38a9eb0fa7845b (diff) | |
download | qemu-1da48c658a26d0c1444d05d8d3a545d311e01026.tar.gz qemu-1da48c658a26d0c1444d05d8d3a545d311e01026.tar.bz2 qemu-1da48c658a26d0c1444d05d8d3a545d311e01026.zip |
chardev: add memory (ringbuf) support to qapi
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 <kraxel@redhat.com>
Diffstat (limited to 'qemu-char.c')
-rw-r--r-- | qemu-char.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/qemu-char.c b/qemu-char.c index 2d62ee9e26..eb2045a5da 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2884,7 +2884,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; @@ -2892,14 +2893,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; } @@ -3201,6 +3199,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 */ @@ -3740,6 +3752,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; @@ -3782,7 +3797,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, |