diff mbox series

[v3,11/11] display: add -display spice-app launching a Spice client

Message ID 20190221110703.5775-12-marcandre.lureau@redhat.com
State New
Headers show
Series spice: add -display spice-app, setup and launch a Spice client | expand

Commit Message

Marc-André Lureau Feb. 21, 2019, 11:07 a.m. UTC
Add a new display backend that will configure Spice to allow a remote
client to control QEMU in a similar fashion as other QEMU display
backend/UI like GTK.

For this to work, it will set up Spice server with a unix socket, and
register a VC chardev that will be exposed as Spice ports. A QMP
monitor is also exposed as a Spice port, this allows the remote client
fuller qemu control and state handling.

- doesn't handle VC set_echo() - this doesn't seem a strong
  requirement, very few front-end use it
- spice options can be tweaked with other -spice arguments
- Windows support shouldn't be hard to do, but will probably use a TCP
  port instead
- we may want to watch the child process to quit automatically if it
  crashed

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Victor Toso <victortoso@redhat.com>
---
 qapi/ui.json     |   7 +-
 ui/spice-app.c   | 200 +++++++++++++++++++++++++++++++++++++++++++++++
 qemu-options.hx  |   5 ++
 ui/Makefile.objs |   5 ++
 4 files changed, 216 insertions(+), 1 deletion(-)
 create mode 100644 ui/spice-app.c

Comments

Gerd Hoffmann Feb. 21, 2019, 1:23 p.m. UTC | #1
On Thu, Feb 21, 2019 at 12:07:03PM +0100, Marc-André Lureau wrote:
> Add a new display backend that will configure Spice to allow a remote
> client to control QEMU in a similar fashion as other QEMU display
> backend/UI like GTK.
> 
> For this to work, it will set up Spice server with a unix socket, and
> register a VC chardev that will be exposed as Spice ports. A QMP
> monitor is also exposed as a Spice port, this allows the remote client
> fuller qemu control and state handling.
> 
> - doesn't handle VC set_echo() - this doesn't seem a strong
>   requirement, very few front-end use it
> - spice options can be tweaked with other -spice arguments
> - Windows support shouldn't be hard to do, but will probably use a TCP
>   port instead
> - we may want to watch the child process to quit automatically if it
>   crashed

Hmm, not working on RHEL-7:

  qemu-system-x86_64: Failed to launch spice+unix:///tmp/.QON7WZ/spice.sock URI: The specified location is not supported

virt-viewer + remote-viewer are installed.

any clue?

thanks,
  Gerd
Marc-André Lureau Feb. 21, 2019, 1:32 p.m. UTC | #2
Hi

On Thu, Feb 21, 2019 at 2:24 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On Thu, Feb 21, 2019 at 12:07:03PM +0100, Marc-André Lureau wrote:
> > Add a new display backend that will configure Spice to allow a remote
> > client to control QEMU in a similar fashion as other QEMU display
> > backend/UI like GTK.
> >
> > For this to work, it will set up Spice server with a unix socket, and
> > register a VC chardev that will be exposed as Spice ports. A QMP
> > monitor is also exposed as a Spice port, this allows the remote client
> > fuller qemu control and state handling.
> >
> > - doesn't handle VC set_echo() - this doesn't seem a strong
> >   requirement, very few front-end use it
> > - spice options can be tweaked with other -spice arguments
> > - Windows support shouldn't be hard to do, but will probably use a TCP
> >   port instead
> > - we may want to watch the child process to quit automatically if it
> >   crashed
>
> Hmm, not working on RHEL-7:
>
>   qemu-system-x86_64: Failed to launch spice+unix:///tmp/.QON7WZ/spice.sock URI: The specified location is not supported
>
> virt-viewer + remote-viewer are installed.
>
> any clue?

5 months old patch, not event released yet :( but virt-viewer should
have a release very soon hopefully

https://pagure.io/virt-viewer/c/c4f6142f15c4e51cbf427f5f1bf1fc6ac0e10d88?branch=master

thanks
Gerd Hoffmann Feb. 21, 2019, 2:39 p.m. UTC | #3
Hi,

> > Hmm, not working on RHEL-7:
> >
> >   qemu-system-x86_64: Failed to launch spice+unix:///tmp/.QON7WZ/spice.sock URI: The specified location is not supported
> >
> > virt-viewer + remote-viewer are installed.
> >
> > any clue?
> 
> 5 months old patch, not event released yet :( but virt-viewer should
> have a release very soon hopefully
> 
> https://pagure.io/virt-viewer/c/c4f6142f15c4e51cbf427f5f1bf1fc6ac0e10d88?branch=master
> 
> thanks

Too bad.  So broken for pretty much everyone I guess?

I think we should have a fallback which exec's remote-viewer then, for
the next 2-3 years, until a fixed virt-viewer is in widespread use ...

cheers,
  Gerd
Marc-André Lureau Feb. 21, 2019, 2:54 p.m. UTC | #4
Hi

On Thu, Feb 21, 2019 at 3:39 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
>
>   Hi,
>
> > > Hmm, not working on RHEL-7:
> > >
> > >   qemu-system-x86_64: Failed to launch spice+unix:///tmp/.QON7WZ/spice.sock URI: The specified location is not supported
> > >
> > > virt-viewer + remote-viewer are installed.
> > >
> > > any clue?
> >
> > 5 months old patch, not event released yet :( but virt-viewer should
> > have a release very soon hopefully
> >
> > https://pagure.io/virt-viewer/c/c4f6142f15c4e51cbf427f5f1bf1fc6ac0e10d88?branch=master
> >
> > thanks
>
> Too bad.  So broken for pretty much everyone I guess?

It should be easy to backport the patch for older virt-viewer.

But to get the "complete" experience, I would recommend you use the
upcoming virt-viewer. Without it, you won't have the QMP monitor
handling, VTE serial console, etc..

> I think we should have a fallback which exec's remote-viewer then, for
> the next 2-3 years, until a fixed virt-viewer is in widespread use ...

I am not sure, I think it make sense to require the upcoming
virt-viewer instead.

After all, if you use a bleeding edge qemu, you can use bleeding edge
virt-viewer, no?
Gerd Hoffmann Feb. 21, 2019, 3:18 p.m. UTC | #5
Hi,

> > Too bad.  So broken for pretty much everyone I guess?
> 
> It should be easy to backport the patch for older virt-viewer.
> 
> But to get the "complete" experience, I would recommend you use the
> upcoming virt-viewer. Without it, you won't have the QMP monitor
> handling, VTE serial console, etc..
> 
> > I think we should have a fallback which exec's remote-viewer then, for
> > the next 2-3 years, until a fixed virt-viewer is in widespread use ...
> 
> I am not sure, I think it make sense to require the upcoming
> virt-viewer instead.
> 
> After all, if you use a bleeding edge qemu, you can use bleeding edge
> virt-viewer, no?

Fair enough, but please add a hint to the error message then so users
have a clue how to deal with it.

thanks,
  Gerd
Marc-André Lureau Feb. 21, 2019, 3:59 p.m. UTC | #6
Hi

On Thu, Feb 21, 2019 at 4:19 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
>
>   Hi,
>
> > > Too bad.  So broken for pretty much everyone I guess?
> >
> > It should be easy to backport the patch for older virt-viewer.
> >
> > But to get the "complete" experience, I would recommend you use the
> > upcoming virt-viewer. Without it, you won't have the QMP monitor
> > handling, VTE serial console, etc..
> >
> > > I think we should have a fallback which exec's remote-viewer then, for
> > > the next 2-3 years, until a fixed virt-viewer is in widespread use ...
> >
> > I am not sure, I think it make sense to require the upcoming
> > virt-viewer instead.
> >
> > After all, if you use a bleeding edge qemu, you can use bleeding edge
> > virt-viewer, no?
>
> Fair enough, but please add a hint to the error message then so users
> have a clue how to deal with it.
>

Would something like that be helpful?

diff --git a/ui/spice-app.c b/ui/spice-app.c
index 4f5229f3ee..69f92e440c 100644
--- a/ui/spice-app.c
+++ b/ui/spice-app.c
@@ -181,6 +181,7 @@ static void spice_app_display_init(DisplayState
*ds, DisplayOptions *opts)
     g_app_info_launch_default_for_uri(uri, NULL, &err);
     if (err) {
         error_report("Failed to launch %s URI: %s", uri, err->message);
+        error_report("You need a capable Spice client, such as
virt-viewer 8.0");
         exit(1);
     }
     g_free(uri);
Gerd Hoffmann Feb. 22, 2019, 5:51 a.m. UTC | #7
Hi,

> Would something like that be helpful?
> 
> diff --git a/ui/spice-app.c b/ui/spice-app.c
> index 4f5229f3ee..69f92e440c 100644
> --- a/ui/spice-app.c
> +++ b/ui/spice-app.c
> @@ -181,6 +181,7 @@ static void spice_app_display_init(DisplayState
> *ds, DisplayOptions *opts)
>      g_app_info_launch_default_for_uri(uri, NULL, &err);
>      if (err) {
>          error_report("Failed to launch %s URI: %s", uri, err->message);
> +        error_report("You need a capable Spice client, such as
> virt-viewer 8.0");

Yep, looks good to me.  Can you send that as incremental patch?

thanks,
  Gerd
diff mbox series

Patch

diff --git a/qapi/ui.json b/qapi/ui.json
index 7702ddf583..c5d1d7f099 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1110,12 +1110,17 @@ 
 #
 # @cocoa: The Cocoa user interface.
 #
+# @spice-app: Set up a Spice server and run the default associated
+#             application to connect to it. The server will redirect
+#             the serial console and QEMU monitors. (Since 4.0)
+#
 # Since: 2.12
 #
 ##
 { 'enum'    : 'DisplayType',
   'data'    : [ 'default', 'none', 'gtk', 'sdl',
-                'egl-headless', 'curses', 'cocoa' ] }
+                'egl-headless', 'curses', 'cocoa',
+                'spice-app'] }
 
 ##
 # @DisplayOptions:
diff --git a/ui/spice-app.c b/ui/spice-app.c
new file mode 100644
index 0000000000..4f5229f3ee
--- /dev/null
+++ b/ui/spice-app.c
@@ -0,0 +1,200 @@ 
+/*
+ * QEMU external Spice client display driver
+ *
+ * Copyright (c) 2018 Marc-André Lureau <marcandre.lureau@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu/osdep.h"
+
+#include <gio/gio.h>
+
+#include "qemu-common.h"
+#include "ui/console.h"
+#include "qemu/config-file.h"
+#include "qemu/option.h"
+#include "qemu/cutils.h"
+#include "qapi/error.h"
+#include "io/channel-command.h"
+#include "chardev/spice.h"
+#include "sysemu/sysemu.h"
+
+static const char *tmp_dir;
+static char *app_dir;
+static char *sock_path;
+
+typedef struct VCChardev {
+    SpiceChardev parent;
+} VCChardev;
+
+#define TYPE_CHARDEV_VC "chardev-vc"
+#define VC_CHARDEV(obj) OBJECT_CHECK(VCChardev, (obj), TYPE_CHARDEV_VC)
+
+static ChardevBackend *
+chr_spice_backend_new(void)
+{
+    ChardevBackend *be = g_new0(ChardevBackend, 1);
+
+    be->type = CHARDEV_BACKEND_KIND_SPICEPORT;
+    be->u.spiceport.data = g_new0(ChardevSpicePort, 1);
+
+    return be;
+}
+
+static void vc_chr_open(Chardev *chr,
+                        ChardevBackend *backend,
+                        bool *be_opened,
+                        Error **errp)
+{
+    ChardevBackend *be;
+    const char *fqdn = NULL;
+
+    if (strstart(chr->label, "serial", NULL)) {
+        fqdn = "org.qemu.console.serial.0";
+    } else if (strstart(chr->label, "parallel", NULL)) {
+        fqdn = "org.qemu.console.parallel.0";
+    } else if (strstart(chr->label, "compat_monitor", NULL)) {
+        fqdn = "org.qemu.monitor.hmp.0";
+    }
+
+    be = chr_spice_backend_new();
+    be->u.spiceport.data->fqdn = fqdn ?
+        g_strdup(fqdn) : g_strdup_printf("org.qemu.console.%s", chr->label);
+    qemu_chr_open_spice_port(chr, be, be_opened, errp);
+    qapi_free_ChardevBackend(be);
+}
+
+static void vc_chr_set_echo(Chardev *chr, bool echo)
+{
+    /* TODO: set echo for frontends QMP and qtest */
+}
+
+static void char_vc_class_init(ObjectClass *oc, void *data)
+{
+    ChardevClass *cc = CHARDEV_CLASS(oc);
+
+    cc->parse = qemu_chr_parse_vc;
+    cc->open = vc_chr_open;
+    cc->chr_set_echo = vc_chr_set_echo;
+}
+
+static const TypeInfo char_vc_type_info = {
+    .name = TYPE_CHARDEV_VC,
+    .parent = TYPE_CHARDEV_SPICEPORT,
+    .instance_size = sizeof(VCChardev),
+    .class_init = char_vc_class_init,
+};
+
+static void spice_app_atexit(void)
+{
+    if (sock_path) {
+        unlink(sock_path);
+    }
+    if (tmp_dir) {
+        rmdir(tmp_dir);
+    }
+    g_free(sock_path);
+    g_free(app_dir);
+}
+
+static void spice_app_display_early_init(DisplayOptions *opts)
+{
+    QemuOpts *qopts;
+    ChardevBackend *be = chr_spice_backend_new();
+    GError *err = NULL;
+
+    if (opts->has_full_screen) {
+        error_report("spice-app full-screen isn't supported yet.");
+        exit(1);
+    }
+    if (opts->has_window_close) {
+        error_report("spice-app window-close isn't supported yet.");
+        exit(1);
+    }
+
+    atexit(spice_app_atexit);
+
+    if (qemu_name) {
+        app_dir = g_build_filename(g_get_user_runtime_dir(),
+                                   "qemu", qemu_name, NULL);
+        if (g_mkdir_with_parents(app_dir, S_IRWXU) < -1) {
+            error_report("Failed to create directory %s: %s",
+                         app_dir, strerror(errno));
+            exit(1);
+        }
+    } else {
+        app_dir = g_dir_make_tmp(NULL, &err);
+        tmp_dir = app_dir;
+        if (err) {
+            error_report("Failed to create temporary directory: %s",
+                         err->message);
+            exit(1);
+        }
+    }
+
+    type_register(&char_vc_type_info);
+
+    sock_path = g_strjoin("", app_dir, "/", "spice.sock", NULL);
+    qopts = qemu_opts_create(qemu_find_opts("spice"), NULL, 0, &error_abort);
+    qemu_opt_set(qopts, "disable-ticketing", "on", &error_abort);
+    qemu_opt_set(qopts, "unix", "on", &error_abort);
+    qemu_opt_set(qopts, "addr", sock_path, &error_abort);
+    qemu_opt_set(qopts, "image-compression", "off", &error_abort);
+    qemu_opt_set(qopts, "streaming-video", "off", &error_abort);
+    qemu_opt_set(qopts, "gl", opts->has_gl ? "on" : "off", &error_abort);
+    display_opengl = opts->has_gl;
+
+    be->u.spiceport.data->fqdn = g_strdup("org.qemu.monitor.qmp.0");
+    qemu_chardev_new("org.qemu.monitor.qmp", TYPE_CHARDEV_SPICEPORT,
+                     be, NULL, &error_abort);
+    qopts = qemu_opts_create(qemu_find_opts("mon"),
+                             NULL, 0, &error_fatal);
+    qemu_opt_set(qopts, "chardev", "org.qemu.monitor.qmp", &error_abort);
+    qemu_opt_set(qopts, "mode", "control", &error_abort);
+
+    qapi_free_ChardevBackend(be);
+}
+
+static void spice_app_display_init(DisplayState *ds, DisplayOptions *opts)
+{
+    GError *err = NULL;
+    gchar *uri;
+
+    uri = g_strjoin("", "spice+unix://", app_dir, "/", "spice.sock", NULL);
+    info_report("Launching display with URI: %s", uri);
+    g_app_info_launch_default_for_uri(uri, NULL, &err);
+    if (err) {
+        error_report("Failed to launch %s URI: %s", uri, err->message);
+        exit(1);
+    }
+    g_free(uri);
+}
+
+static QemuDisplay qemu_display_spice_app = {
+    .type       = DISPLAY_TYPE_SPICE_APP,
+    .early_init = spice_app_display_early_init,
+    .init       = spice_app_display_init,
+};
+
+static void register_spice_app(void)
+{
+    qemu_display_register(&qemu_display_spice_app);
+}
+
+type_init(register_spice_app);
diff --git a/qemu-options.hx b/qemu-options.hx
index 77bd98e20b..c843126ebd 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1211,6 +1211,7 @@  STEXI
 ETEXI
 
 DEF("display", HAS_ARG, QEMU_OPTION_display,
+    "-display spice-app[,gl=on|off]\n"
     "-display sdl[,frame=on|off][,alt_grab=on|off][,ctrl_grab=on|off]\n"
     "            [,window_close=on|off][,gl=on|core|es|off]\n"
     "-display gtk[,grab_on_hover=on|off][,gl=on|off]|\n"
@@ -1262,6 +1263,10 @@  Start a VNC server on display <arg>
 @item egl-headless
 Offload all OpenGL operations to a local DRI device. For any graphical display,
 this display needs to be paired with either VNC or SPICE displays.
+@item spice-app
+Start QEMU as a Spice server and launch the default Spice client
+application. The Spice server will redirect the serial consoles and
+QEMU monitors. (Since 4.0)
 @end table
 ETEXI
 
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 7f8b3da791..fe1a7aed97 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -49,6 +49,11 @@  curses.mo-objs := curses.o
 curses.mo-cflags := $(CURSES_CFLAGS)
 curses.mo-libs := $(CURSES_LIBS)
 
+common-obj-$(call land,$(CONFIG_SPICE),$(CONFIG_GIO)) += spice-app.mo
+spice-app.mo-objs := spice-app.o
+spice-app.mo-cflags := $(GIO_CFLAGS)
+spice-app.mo-libs := $(GIO_LIBS)
+
 common-obj-$(CONFIG_OPENGL) += shader.o
 common-obj-$(CONFIG_OPENGL) += console-gl.o
 common-obj-$(CONFIG_OPENGL) += egl-helpers.o