qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 15/17] chardev: add memory (ringbuf) support to qapi


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH 15/17] chardev: add memory (ringbuf) support to qapi
Date: Thu, 28 Feb 2013 08:50:07 +0100

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 <address@hidden>
---
 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 edea0f6..a18d88d 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -2654,7 +2654,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;
@@ -2662,14 +2663,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;
     }
 
@@ -3029,6 +3027,20 @@ static void qemu_chr_parse_vc(QemuOpts *opts, 
ChardevBackend *backend,
     }
 }
 
+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;
+    }
+}
+
 static const struct {
     const char *name;
     /* old, pre qapi */
@@ -3043,7 +3055,8 @@ static const struct {
     { .name = "msmouse",   .kind  = CHARDEV_BACKEND_KIND_MSMOUSE },
     { .name = "vc",        .kind  = CHARDEV_BACKEND_KIND_VC,
                            .parse = qemu_chr_parse_vc },
-    { .name = "memory",    .open = qemu_chr_open_ringbuf },
+    { .name = "memory",    .kind  = CHARDEV_BACKEND_KIND_MEMORY,
+                           .parse = qemu_chr_parse_ringbuf },
     { .name = "file",      .kind  = CHARDEV_BACKEND_KIND_FILE,
                            .parse = qemu_chr_parse_file_out },
     { .name = "stdio",     .kind  = CHARDEV_BACKEND_KIND_STDIO,
@@ -3546,6 +3559,9 @@ ChardevReturn *qmp_chardev_add(const char *id, 
ChardevBackend *backend,
         chr = qemu_chr_open_spice_port(backend->spiceport->fqdn);
         break;
 #endif
+    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;
-- 
1.7.9.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]