Patchwork [RfC,0/9] chardev hotplug

login
register
mail settings
Submitter Gerd Hoffmann
Date Dec. 21, 2012, 9:01 a.m.
Message ID <50D4257A.7050402@redhat.com>
Download mbox | patch
Permalink /patch/207771/
State New
Headers show

Comments

Gerd Hoffmann - Dec. 21, 2012, 9:01 a.m.
Hi,

>> pty looks like another non-trivial challenge.  How does libvirt gather
>> the pty device today?  IIRC there is some stderr parsing?  Or was it
>> info chardev?  With QMP we probably want switch to a more sane model
>> here ...
> 
> Yes, these days we use info chardev, or query-chardev as appropriate
> for the monitor mode.

So do you want continue using query-chardev, or do you prefer to get the
path returned directly, i.e. something like the attached patch?

cheers,
  Gerd
From a616ae73d545a80b3a545fdc66bf141a9b3ba004 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Thu, 20 Dec 2012 14:39:13 +0100
Subject: [PATCH] chardev: hotplug, qmp, pty

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 qapi-schema.json |    7 ++++++-
 qemu-char.c      |   24 +++++++++++++++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)
Daniel P. Berrange - Dec. 21, 2012, 9:28 a.m.
On Fri, Dec 21, 2012 at 10:01:46AM +0100, Gerd Hoffmann wrote:
>   Hi,
> 
> >> pty looks like another non-trivial challenge.  How does libvirt gather
> >> the pty device today?  IIRC there is some stderr parsing?  Or was it
> >> info chardev?  With QMP we probably want switch to a more sane model
> >> here ...
> > 
> > Yes, these days we use info chardev, or query-chardev as appropriate
> > for the monitor mode.
> 
> So do you want continue using query-chardev, or do you prefer to get the
> path returned directly, i.e. something like the attached patch?

If you return the path directly, that'd certainly make life easier

Daniel

Patch

diff --git a/qapi-schema.json b/qapi-schema.json
index 39e0ab4..63c61c4 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3054,10 +3054,15 @@ 
 { 'union': 'ChardevBackend', 'data': { 'file'   : 'ChardevFile',
                                        'port'   : 'ChardevPort',
                                        'socket' : 'ChardevSocket',
+                                       'pty'    : 'ChardevDummy',
                                        'null'   : 'ChardevDummy' } }
 
+{ 'union': 'ChardevReturn', 'data': { 'pty'    : 'str',
+                                      'nodata' : 'ChardevDummy' } }
+
 { 'command': 'chardev-add', 'data': {'id'      : 'str',
-                                     'backend' : 'ChardevBackend' } }
+                                     'backend' : 'ChardevBackend' },
+  'returns' : 'ChardevReturn' }
 
 ##
 # @chardev-remove:
diff --git a/qemu-char.c b/qemu-char.c
index 911649a..7f65d40 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -3115,9 +3115,13 @@  static CharDriverState *qmp_chardev_open_socket(ChardevSocket *sock,
                                    is_telnet, is_waitconnect, errp);
 }
 
-void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp)
+ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
+                               Error **errp)
 {
-    CharDriverState *chr;
+    ChardevReturn *ret = g_new0(ChardevReturn, 1);
+    CharDriverState *chr = NULL;
+
+    ret->kind = CHARDEV_RETURN_KIND_NODATA;
 
     switch (backend->kind) {
     case CHARDEV_BACKEND_KIND_FILE:
@@ -3129,17 +3133,31 @@  void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp)
     case CHARDEV_BACKEND_KIND_SOCKET:
         chr = qmp_chardev_open_socket(backend->socket, errp);
         break;
+#ifdef HAVE_CHARDEV_TTY
+    case CHARDEV_BACKEND_KIND_PTY:
+    {
+        /* qemu_chr_open_pty sets "path" in opts */
+        QemuOpts *opts;
+        opts = qemu_opts_create_nofail(qemu_find_opts("chardev"));
+        chr = qemu_chr_open_pty(opts);
+        ret->kind = CHARDEV_RETURN_KIND_PTY;
+        ret->pty = g_strdup(qemu_opt_get(opts, "path"));
+        qemu_opts_del(opts);
+        break;
+    }
+#endif
     case CHARDEV_BACKEND_KIND_NULL:
         chr = qemu_chr_open_null(NULL);
         break;
     default:
         error_setg(errp, "unknown chardev backend (%d)", backend->kind);
-        return;
+        break;
     }
 
     if (chr == NULL && !error_is_set(errp)) {
         error_setg(errp, "Failed to create chardev");
     }
+    return ret;
 }
 
 void qmp_chardev_remove(const char *id, Error **errp)