ui: build spice and opengl as module.
cover ui: build spice and opengl as module.
- Add QemuSpiceOps, reorganize spice stubs.
- Add support for module dependencies.
- Build spice-core modular, and make the existing spice modules (audio, chardev, qxl) depend on spice-core.
- Build egl-headless display and opengl helpers modular (pretty easy thanks to module dependencies).
Gerd Hoffmann (14):
spice: add module helpers
spice: add QemuSpiceOps, move migrate_info
spice: move qemu_spice_init() to QemuSpiceOps.
spice: move display_init() to QemuSpiceOps.
spice: move add_interface() to QemuSpiceOps.
spice: move auth functions to QemuSpiceOps.
spice: move display_add_client() to QemuSpiceOps.
spice: wire up monitor in QemuSpiceOps.
spice: load module when enabled on the cmdline
modules: dependencies infrastructure
modules: add spice dependencies
spice: flip modules switch
opengl: build egl-headless display modular
opengl: build opengl helper code modular
include/ui/qemu-spice-module.h | 44 ++++++++++++++++++ include/ui/qemu-spice.h | 42 +---------------- audio/spiceaudio.c | 4 +- chardev/spice.c | 2 +- monitor/misc.c | 2 +- monitor/qmp-cmds.c | 6 +-- softmmu/vl.c | 10 ++-- ui/spice-core.c | 31 +++++++++---- ui/spice-input.c | 6 +-- ui/spice-module.c | 85 ++++++++++++++++++++++++++++++++++ util/module.c | 44 ++++++++++++++++-- ui/meson.build | 28 +++++++++-- 12 files changed, 232 insertions(+), 72 deletions(-) create mode 100644 include/ui/qemu-spice-module.h create mode 100644 ui/spice-module.c
Signature · 1 line
2.27.0
PATCH 1/14 spice: add module helpers
Add new spice-module.c + qemu-spice-module.h files. The code needed to support modular spice will be there. For starters this will be only the using_spice variable, more will follow ...
--- include/ui/qemu-spice-module.h | 23 +++++++++++++++++++++++ include/ui/qemu-spice.h | 4 +--- ui/spice-core.c | 1 - ui/spice-module.c | 23 +++++++++++++++++++++++ ui/meson.build | 1 + 5 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 include/ui/qemu-spice-module.h create mode 100644 ui/spice-module.c
include/ui/qemu-spice-module.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (C) 2010 Red Hat, Inc. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 or +* (at your option) version 3 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef QEMU_SPICE_MODULE_H +#define QEMU_SPICE_MODULE_H + +extern int using_spice; + +#endif
include/ui/qemu-spice.h +1 -3
@@ -19,14 +19,13 @@#define QEMU_SPICE_H #include "qapi/error.h" +#include "ui/qemu-spice-module.h" #ifdef CONFIG_SPICE #include <spice.h> #include "qemu/config-file.h" -extern int using_spice; -void qemu_spice_init (void );void qemu_spice_input_init (void );void qemu_spice_display_init (void );
@@ -50,7 +49,6 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,#include "qemu/error-report.h" -#define using_spice 0#define spice_displays 0 static inline int qemu_spice_set_passwd(const char *passwd, bool fail_if_connected,
ui/spice-core.c +0 -1
@@ -48,7 +48,6 @@ static time_t auth_expires = TIME_MAX;static int spice_migration_completed;static int spice_display_is_running;static int spice_have_target_host; -int using_spice =0 ;static QemuThread me;
ui/spice-module.c new file +23 -0
@@ -0,0 +1,23 @@ +/* +* spice module support, also spice stubs. +* +* Copyright (C) 2010 Red Hat, Inc. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 or +* (at your option) version 3 of the License. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "qemu/osdep.h" +#include "ui/qemu-spice-module.h" + +int using_spice;
ui/meson.build +1 -0
@@ -12,6 +12,7 @@ softmmu_ss.add(files( 'keymaps.c', 'qemu-pixman.c', )) +softmmu_ss.add([spice_headers, files('spice-module.c')]) softmmu_ss.add(when: 'CONFIG_LINUX', if_true: files('input-linux.c')) softmmu_ss.add(when: [spice, 'CONFIG_SPICE'], if_true: files('spice-core.c', 'spice-input.c', 'spice-display.c'))
Signature · 1 line
2.27.0
PATCH 2/14 spice: add QemuSpiceOps, move migrate_info
In reply to Gerd HoffmannAdd QemuSpiceOps struct. This struct holds function pointers to the spice functions. It will be initialized with pointers to the stub functions. When spice gets initialized the function pointers will be re-written to the real functions.
The spice stubs will move from qemu-spice.h to spice-module.c for that, because they will be needed for both "CONFIG_SPICE=n" and "CONFIG_SPICE=y but spice module not loaded" cases.
This patch adds the infrastructure and starts with moving qemu_spice_migrate_info() to QemuSpiceOps.
--- include/ui/qemu-spice-module.h | 5 +++++ include/ui/qemu-spice.h | 5 ----- monitor/misc.c | 2 +- ui/spice-core.c | 5 +++++ ui/spice-module.c | 10 ++++++++++ 5 files changed, 21 insertions(+), 6 deletions(-)
include/ui/qemu-spice-module.h +5 -0
@@ -18,6 +18,11 @@#ifndef QEMU_SPICE_MODULE_H #define QEMU_SPICE_MODULE_H +struct QemuSpiceOps { +int (*migrate_info)(const char *h,int p,int t,const char *s); +}; +extern int using_spice; +extern struct QemuSpiceOps qemu_spice;#endif
include/ui/qemu-spice.h +0 -5
@@ -60,11 +60,6 @@ static inline int qemu_spice_set_pw_expire(time_t expires) {return -1 ; } -static inline int qemu_spice_migrate_info (const char *h,int p,int t, -const char *s) -{ -return -1 ; -}static inline int qemu_spice_display_add_client (int csock,int skipauth,int tls)
monitor/misc.c +1 -1
@@ -437,7 +437,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,return ; } -if (qemu_spice_migrate_info (hostname, +if (qemu_spice.migrate_info (hostname, has_port ? port :-1 , has_tls_port ? tls_port :-1 , cert_subject)) {
ui/spice-core.c +5 -0
@@ -993,8 +993,13 @@ int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd)return spice_display_is_running; } +static struct QemuSpiceOps real_spice_ops = { + .migrate_info = qemu_spice_migrate_info, +}; +static void spice_register_config (void ) { + qemu_spice = real_spice_ops;qemu_add_opts (&qemu_spice_opts); }opts_init (spice_register_config);
ui/spice-module.c +10 -0
@@ -21,3 +21,13 @@#include "ui/qemu-spice-module.h" int using_spice; + +static int qemu_spice_migrate_info_stub (const char *h,int p,int t, +const char *s) +{ +return -1 ; +} + +struct QemuSpiceOps qemu_spice = { + .migrate_info = qemu_spice_migrate_info_stub, +};
Signature · 1 line
2.27.0
Re: [PATCH 02/14] spice: add QemuSpiceOps, move migrate_info
Quoted 26 lines · * Gerd Hoffmann ([email protected]) wrote:
Add QemuSpiceOps struct. This struct holds function pointers to the spice functions. It will be initialized with pointers to the stub functions. When spice gets initialized the function pointers will be re-written to the real functions.
The spice stubs will move from
qemu-spice.htospice-module.cfor that, because they will be needed for both "CONFIG_SPICE=n" and "CONFIG_SPICE=ybut spice module not loaded" cases.This patch adds the infrastructure and starts with moving
qemu_spice_migrate_info()to QemuSpiceOps.Signed-off-by Gerd Hoffmann <[email protected]>--- include/ui/qemu-spice-module.h | 5 +++++ include/ui/qemu-spice.h | 5 ----- monitor/misc.c | 2 +- ui/spice-core.c | 5 +++++ ui/spice-module.c | 10 ++++++++++ 5 files changed, 21 insertions(+), 6 deletions(-)include/ui/qemu-spice-module.h +0
-0
include/ui/qemu-spice-module.h line 24
Quoted 7 lines
include/ui/qemu-spice-module.h +4
-0@@ -18,6 +18,11 @@#ifndef QEMU_SPICE_MODULE_H #define QEMU_SPICE_MODULE_H +struct QemuSpiceOps { +int (*migrate_info)(const char *h,int p,int t,const char *s); +}; +
I realise that's mostly a move, but if you need to repost, can you expand those 4 single character parameter names?
Dave
Quoted 72 lines
include/ui/qemu-spice-module.h +1
-0extern int using_spice; +extern struct QemuSpiceOps qemu_spice;#endif include/ui/qemu-spice.h +0
-5@@ -60,11 +60,6 @@ static inline int qemu_spice_set_pw_expire(time_t expires) {return -1 ; } -static inline int qemu_spice_migrate_info (const char *h,int p,int t, -const char *s) -{ -return -1 ; -}static inline int qemu_spice_display_add_client (int csock,int skipauth,int tls)monitor/misc.c +1
-1@@ -437,7 +437,7 @@ void qmp_client_migrate_info(const char *protocol, const char *hostname,return ; } -if (qemu_spice_migrate_info (hostname, +if (qemu_spice.migrate_info (hostname, has_port ? port :-1 , has_tls_port ? tls_port :-1 , cert_subject)) {ui/spice-core.c +5
-0@@ -993,8 +993,13 @@ int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd)return spice_display_is_running; } +static struct QemuSpiceOps real_spice_ops = { + .migrate_info = qemu_spice_migrate_info, +}; +static void spice_register_config (void ) { + qemu_spice = real_spice_ops;qemu_add_opts (&qemu_spice_opts); }opts_init (spice_register_config);ui/spice-module.c +10
-0@@ -21,3 +21,13 @@#include "ui/qemu-spice-module.h" int using_spice; + +static int qemu_spice_migrate_info_stub (const char *h,int p,int t, +const char *s) +{ +return -1 ; +} + +struct QemuSpiceOps qemu_spice = { + .migrate_info = qemu_spice_migrate_info_stub, +};Signature · 1 line
2.27.0
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 3/14 spice: move qemu_spice_init() to QemuSpiceOps.
In reply to Gerd Hoffmann--- include/ui/qemu-spice-module.h | 1 + include/ui/qemu-spice.h | 5 ----- softmmu/vl.c | 2 +- ui/spice-core.c | 3 ++- ui/spice-module.c | 5 +++++ 5 files changed, 9 insertions(+), 7 deletions(-)
include/ui/qemu-spice-module.h +1 -0
@@ -19,6 +19,7 @@#define QEMU_SPICE_MODULE_H struct QemuSpiceOps { +void (*init)(void );int (*migrate_info)(const char *h,int p,int t,const char *s); };
include/ui/qemu-spice.h +0 -5
@@ -26,7 +26,6 @@#include <spice.h> #include "qemu/config-file.h" -void qemu_spice_init (void );void qemu_spice_input_init (void );void qemu_spice_display_init (void );int qemu_spice_display_add_client (int csock,int skipauth,int tls);
@@ -74,10 +73,6 @@ static inline void qemu_spice_display_init(void) abort(); } -static inline void qemu_spice_init (void ) -{ -} -#endif /* CONFIG_SPICE */ static inline bool qemu_using_spice (Error **errp)
softmmu/vl.c +1 -1
@@ -4151,7 +4151,7 @@ void qemu_init(int argc, char **argv, char **envp)/* spice needs the timers to be initialized by this point */ /* spice must initialize before audio as it changes the default auiodev */ /* spice must initialize before chardevs (for spicevmc and spiceport) */ -qemu_spice_init (); + qemu_spice.init ();qemu_opts_foreach (qemu_find_opts ("chardev" ), chardev_init_func,NULL , &error_fatal);
ui/spice-core.c +2 -1
@@ -633,7 +633,7 @@ static void vm_change_state_handler(void *opaque, int running, } } -void qemu_spice_init (void ) +static void qemu_spice_init (void ) {QemuOpts *opts =QTAILQ_FIRST (&qemu_spice_opts.head); const char *password, *str, *x509_dir, *addr,
@@ -994,6 +994,7 @@ int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd) }static struct QemuSpiceOps real_spice_ops = { + .init = qemu_spice_init, .migrate_info = qemu_spice_migrate_info, };
ui/spice-module.c +5 -0
@@ -22,6 +22,10 @@int using_spice; +static void qemu_spice_init_stub (void ) +{ +} +static int qemu_spice_migrate_info_stub (const char *h,int p,int t,const char *s) {
@@ -29,5 +33,6 @@ static int qemu_spice_migrate_info_stub(const char *h, int p, int t, }struct QemuSpiceOps qemu_spice = { + .init = qemu_spice_init_stub, .migrate_info = qemu_spice_migrate_info_stub, };
Signature · 1 line
2.27.0
PATCH 4/14 spice: move display_init() to QemuSpiceOps.
In reply to Gerd Hoffmann--- include/ui/qemu-spice-module.h | 1 + include/ui/qemu-spice.h | 7 ------- softmmu/vl.c | 2 +- ui/spice-core.c | 1 + ui/spice-module.c | 9 +++++++++ 5 files changed, 12 insertions(+), 8 deletions(-)
include/ui/qemu-spice-module.h +1 -0
@@ -20,6 +20,7 @@struct QemuSpiceOps {void (*init)(void ); +void (*display_init)(void );int (*migrate_info)(const char *h,int p,int t,const char *s); };
include/ui/qemu-spice.h +0 -7
@@ -66,13 +66,6 @@ static inline int qemu_spice_display_add_client(int csock, int skipauth, return -1; } -static inline void qemu_spice_display_init (void ) -{ -/* This must never be called if CONFIG_SPICE is disabled */ -error_report ("spice support is disabled" ); -abort (); -} -#endif /* CONFIG_SPICE */ static inline bool qemu_using_spice (Error **errp)
softmmu/vl.c +1 -1
@@ -4447,7 +4447,7 @@ void qemu_init(int argc, char **argv, char **envp)#endif if (using_spice) { -qemu_spice_display_init (); + qemu_spice.display_init (); }if (foreach_device_config (DEV_GDB , gdbserver_start) <0 ) {
ui/spice-core.c +1 -0
@@ -995,6 +995,7 @@ int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd)static struct QemuSpiceOps real_spice_ops = { .init = qemu_spice_init, + .display_init = qemu_spice_display_init, .migrate_info = qemu_spice_migrate_info, };
ui/spice-module.c +9 -0
@@ -18,6 +18,7 @@*/ #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "ui/qemu-spice-module.h" int using_spice;
@@ -26,6 +27,13 @@ static void qemu_spice_init_stub(void) { } +static void qemu_spice_display_init_stub (void ) +{ +/* This must never be called if CONFIG_SPICE is disabled */ +error_report ("spice support is disabled" ); +abort (); +} +static int qemu_spice_migrate_info_stub (const char *h,int p,int t,const char *s) {
@@ -34,5 +42,6 @@ static int qemu_spice_migrate_info_stub(const char *h, int p, int t,struct QemuSpiceOps qemu_spice = { .init = qemu_spice_init_stub, + .display_init = qemu_spice_display_init_stub, .migrate_info = qemu_spice_migrate_info_stub, };
Signature · 1 line
2.27.0
PATCH 5/14 spice: move add_interface() to QemuSpiceOps.
In reply to Gerd Hoffmann--- include/ui/qemu-spice-module.h | 7 +++++++ include/ui/qemu-spice.h | 1 - audio/spiceaudio.c | 4 ++-- chardev/spice.c | 2 +- ui/spice-core.c | 5 +++-- ui/spice-input.c | 6 +++--- 6 files changed, 16 insertions(+), 9 deletions(-)
include/ui/qemu-spice-module.h +7 -0
@@ -18,10 +18,17 @@#ifndef QEMU_SPICE_MODULE_H #define QEMU_SPICE_MODULE_H +#ifdef CONFIG_SPICE +#include <spice.h> +#endif +struct QemuSpiceOps {void (*init)(void );void (*display_init)(void );int (*migrate_info)(const char *h,int p,int t,const char *s); +#ifdef CONFIG_SPICE +int (*add_interface)(SpiceBaseInstance *sin); +#endif };extern int using_spice;
include/ui/qemu-spice.h +0 -1
@@ -29,7 +29,6 @@void qemu_spice_input_init (void );void qemu_spice_display_init (void );int qemu_spice_display_add_client (int csock,int skipauth,int tls); -int qemu_spice_add_interface (SpiceBaseInstance *sin);bool qemu_spice_have_display_interface (QemuConsole *con);int qemu_spice_add_display_interface (QXLInstance *qxlin,QemuConsole *con); int qemu_spice_set_passwd(const char *passwd,
audio/spiceaudio.c +2 -2
@@ -106,7 +106,7 @@ static int line_out_init(HWVoiceOut *hw, struct audsettings *as, out->active =0 ; out->sin.base.sif = &playback_sif.base; -qemu_spice_add_interface (&out->sin.base); + qemu_spice.add_interface (&out->sin.base);#if SPICE_INTERFACE_PLAYBACK_MAJOR >1 ||SPICE_INTERFACE_PLAYBACK_MINOR >=3 spice_server_set_playback_rate (&out->sin, settings.freq);#endif
@@ -215,7 +215,7 @@ static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque) in->active =0 ; in->sin.base.sif = &record_sif.base; -qemu_spice_add_interface (&in->sin.base); + qemu_spice.add_interface (&in->sin.base);#if SPICE_INTERFACE_RECORD_MAJOR >2 ||SPICE_INTERFACE_RECORD_MINOR >=3 spice_server_set_record_rate (&in->sin, settings.freq);#endif
chardev/spice.c +1 -1
@@ -110,7 +110,7 @@ static void vmc_register_interface(SpiceChardev *scd)return ; } scd->sin.base.sif = &vmc_interface.base; -qemu_spice_add_interface (&scd->sin.base); + qemu_spice.add_interface (&scd->sin.base); scd->active = true;trace_spice_vmc_register_interface (scd); }
ui/spice-core.c +3 -2
@@ -800,7 +800,7 @@ static void qemu_spice_init(void) migration_state.notify = migration_state_notifier;add_migration_state_change_notifier (&migration_state); spice_migrate.base.sif = &migrate_interface.base; -qemu_spice_add_interface (&spice_migrate.base); + qemu_spice.add_interface (&spice_migrate.base);qemu_spice_input_init ();
@@ -829,7 +829,7 @@ static void qemu_spice_init(void)#endif } -int qemu_spice_add_interface (SpiceBaseInstance *sin) +static int qemu_spice_add_interface (SpiceBaseInstance *sin) {if (!spice_server) {if (QTAILQ_FIRST (&qemu_spice_opts.head) !=NULL ) {
@@ -997,6 +997,7 @@ static struct QemuSpiceOps real_spice_ops = { .init = qemu_spice_init, .display_init = qemu_spice_display_init, .migrate_info = qemu_spice_migrate_info, + .add_interface = qemu_spice_add_interface, };static void spice_register_config (void )
ui/spice-input.c +3 -3
@@ -231,7 +231,7 @@ static void mouse_mode_notifier(Notifier *notifier, void *data) }if (is_absolute) { -qemu_spice_add_interface (&pointer->tablet.base); + qemu_spice.add_interface (&pointer->tablet.base); }else {spice_server_remove_interface (&pointer->tablet.base); }
@@ -245,13 +245,13 @@ void qemu_spice_input_init(void) kbd =g_malloc0 (sizeof (*kbd)); kbd->sin.base.sif = &kbd_interface.base; -qemu_spice_add_interface (&kbd->sin.base); + qemu_spice.add_interface (&kbd->sin.base);qemu_add_led_event_handler (kbd_leds, kbd); pointer =g_malloc0 (sizeof (*pointer)); pointer->mouse.base.sif = &mouse_interface.base; pointer->tablet.base.sif = &tablet_interface.base; -qemu_spice_add_interface (&pointer->mouse.base); + qemu_spice.add_interface (&pointer->mouse.base); pointer->absolute = false; pointer->mouse_mode.notify = mouse_mode_notifier;
Signature · 1 line
2.27.0
PATCH 6/14 spice: move auth functions to QemuSpiceOps.
In reply to Gerd HoffmannMove qemu_spice_set_passwd() and qemu_spice_set_pw_expire() functions to QemuSpiceOps.
--- include/ui/qemu-spice-module.h | 3 +++ include/ui/qemu-spice.h | 14 -------------- monitor/qmp-cmds.c | 4 ++-- ui/spice-core.c | 10 ++++++---- ui/spice-module.c | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 20 deletions(-)
include/ui/qemu-spice-module.h +3 -0
@@ -26,6 +26,9 @@ struct QemuSpiceOps {void (*init)(void );void (*display_init)(void );int (*migrate_info)(const char *h,int p,int t,const char *s); +int (*set_passwd)(const char *passwd, +bool fail_if_connected,bool disconnect_if_connected); +int (*set_pw_expire)(time_t expires);#ifdef CONFIG_SPICE int (*add_interface)(SpiceBaseInstance *sin);#endif
include/ui/qemu-spice.h +0 -14
@@ -31,9 +31,6 @@ void qemu_spice_display_init(void);int qemu_spice_display_add_client (int csock,int skipauth,int tls);bool qemu_spice_have_display_interface (QemuConsole *con);int qemu_spice_add_display_interface (QXLInstance *qxlin,QemuConsole *con); -int qemu_spice_set_passwd (const char *passwd, -bool fail_if_connected,bool disconnect_if_connected); -int qemu_spice_set_pw_expire (time_t expires);int qemu_spice_migrate_info (const char *hostname,int port,int tls_port,const char *subject);
@@ -48,17 +45,6 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,#include "qemu/error-report.h" #define spice_displays 0 -static inline int qemu_spice_set_passwd (const char *passwd, -bool fail_if_connected, -bool disconnect_if_connected) -{ -return -1 ; -} -static inline int qemu_spice_set_pw_expire (time_t expires) -{ -return -1 ; -} -static inline int qemu_spice_display_add_client (int csock,int skipauth,int tls) {
monitor/qmp-cmds.c +2 -2
@@ -197,7 +197,7 @@ void qmp_set_password(const char *protocol, const char *password,if (!qemu_using_spice (errp)) {return ; } - rc =qemu_spice_set_passwd (password, fail_if_connected, + rc = qemu_spice.set_passwd (password, fail_if_connected, disconnect_if_connected);if (rc !=0 ) {error_setg (errp,QERR_SET_PASSWD_FAILED );
@@ -243,7 +243,7 @@ void qmp_expire_password(const char *protocol, const char *whenstr,if (!qemu_using_spice (errp)) {return ; } - rc =qemu_spice_set_pw_expire (when); + rc = qemu_spice.set_pw_expire (when);if (rc !=0 ) {error_setg (errp,QERR_SET_PASSWD_FAILED ); }
ui/spice-core.c +6 -4
@@ -727,7 +727,7 @@ static void qemu_spice_init(void) tls_ciphers); }if (password) { -qemu_spice_set_passwd (password, false, false); + qemu_spice.set_passwd (password, false, false); }if (qemu_opt_get_bool (opts,"sasl" ,0 )) {if (spice_server_set_sasl (spice_server,1 ) ==-1 ) {
@@ -941,8 +941,8 @@ static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_conn) fail_if_conn, disconnect_if_conn); } -int qemu_spice_set_passwd (const char *passwd, -bool fail_if_conn,bool disconnect_if_conn) +static int qemu_spice_set_passwd (const char *passwd, +bool fail_if_conn,bool disconnect_if_conn) {if (strcmp (auth,"spice" ) !=0 ) {return -1 ;
@@ -953,7 +953,7 @@ int qemu_spice_set_passwd(const char *passwd,return qemu_spice_set_ticket (fail_if_conn, disconnect_if_conn); } -int qemu_spice_set_pw_expire (time_t expires) +static int qemu_spice_set_pw_expire (time_t expires) { auth_expires = expires;return qemu_spice_set_ticket (false, false);
@@ -997,6 +997,8 @@ static struct QemuSpiceOps real_spice_ops = { .init = qemu_spice_init, .display_init = qemu_spice_display_init, .migrate_info = qemu_spice_migrate_info, + .set_passwd = qemu_spice_set_passwd, + .set_pw_expire = qemu_spice_set_pw_expire, .add_interface = qemu_spice_add_interface, };
ui/spice-module.c +14 -0
@@ -40,8 +40,22 @@ static int qemu_spice_migrate_info_stub(const char *h, int p, int t,return -1 ; } +static int qemu_spice_set_passwd_stub (const char *passwd, +bool fail_if_connected, +bool disconnect_if_connected) +{ +return -1 ; +} + +static int qemu_spice_set_pw_expire_stub (time_t expires) +{ +return -1 ; +} +struct QemuSpiceOps qemu_spice = { .init = qemu_spice_init_stub, .display_init = qemu_spice_display_init_stub, .migrate_info = qemu_spice_migrate_info_stub, + .set_passwd = qemu_spice_set_passwd_stub, + .set_pw_expire = qemu_spice_set_pw_expire_stub, };
Signature · 1 line
2.27.0
PATCH 7/14 spice: move display_add_client() to QemuSpiceOps.
In reply to Gerd Hoffmann--- include/ui/qemu-spice-module.h | 1 + include/ui/qemu-spice.h | 6 ------ monitor/qmp-cmds.c | 2 +- ui/spice-core.c | 3 ++- ui/spice-module.c | 7 +++++++ 5 files changed, 11 insertions(+), 8 deletions(-)
include/ui/qemu-spice-module.h +1 -0
@@ -29,6 +29,7 @@ struct QemuSpiceOps {int (*set_passwd)(const char *passwd,bool fail_if_connected,bool disconnect_if_connected);int (*set_pw_expire)(time_t expires); +int (*display_add_client)(int csock,int skipauth,int tls);#ifdef CONFIG_SPICE int (*add_interface)(SpiceBaseInstance *sin);#endif
include/ui/qemu-spice.h +0 -6
@@ -28,7 +28,6 @@void qemu_spice_input_init (void );void qemu_spice_display_init (void ); -int qemu_spice_display_add_client (int csock,int skipauth,int tls);bool qemu_spice_have_display_interface (QemuConsole *con);int qemu_spice_add_display_interface (QXLInstance *qxlin,QemuConsole *con); int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,
@@ -45,11 +44,6 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port,#include "qemu/error-report.h" #define spice_displays 0 -static inline int qemu_spice_display_add_client (int csock,int skipauth, -int tls) -{ -return -1 ; -}#endif /* CONFIG_SPICE */
monitor/qmp-cmds.c +1 -1
@@ -340,7 +340,7 @@ void qmp_add_client(const char *protocol, const char *fdname, } skipauth = has_skipauth ? skipauth : false; tls = has_tls ? tls : false; -if (qemu_spice_display_add_client (fd, skipauth, tls) <0 ) { +if (qemu_spice.display_add_client (fd, skipauth, tls) <0 ) {error_setg (errp,"spice failed to add client" );close (fd); }
ui/spice-core.c +2 -1
@@ -959,7 +959,7 @@ static int qemu_spice_set_pw_expire(time_t expires)return qemu_spice_set_ticket (false, false); } -int qemu_spice_display_add_client (int csock,int skipauth,int tls) +static int qemu_spice_display_add_client (int csock,int skipauth,int tls) {if (tls) {return spice_server_add_ssl_client (spice_server, csock, skipauth);
@@ -999,6 +999,7 @@ static struct QemuSpiceOps real_spice_ops = { .migrate_info = qemu_spice_migrate_info, .set_passwd = qemu_spice_set_passwd, .set_pw_expire = qemu_spice_set_pw_expire, + .display_add_client = qemu_spice_display_add_client, .add_interface = qemu_spice_add_interface, };
ui/spice-module.c +7 -0
@@ -52,10 +52,17 @@ static int qemu_spice_set_pw_expire_stub(time_t expires)return -1 ; } +static int qemu_spice_display_add_client_stub (int csock,int skipauth, +int tls) +{ +return -1 ; +} +struct QemuSpiceOps qemu_spice = { .init = qemu_spice_init_stub, .display_init = qemu_spice_display_init_stub, .migrate_info = qemu_spice_migrate_info_stub, .set_passwd = qemu_spice_set_passwd_stub, .set_pw_expire = qemu_spice_set_pw_expire_stub, + .display_add_client = qemu_spice_display_add_client_stub, };
Signature · 1 line
2.27.0
PATCH 8/14 spice: wire up monitor in QemuSpiceOps.
In reply to Gerd HoffmannRename qmp_query_spice() to qmp_query_spice_real(), add to QemuSpiceOps.
Add new qmp_query_spice() function which calls the real function via QemuSpiceOps if available, otherwise return SpiceInfo.enabled = false.
--- include/ui/qemu-spice-module.h | 3 +++ ui/spice-core.c | 3 ++- ui/spice-module.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-)
include/ui/qemu-spice-module.h +3 -0
@@ -22,6 +22,8 @@#include <spice.h> #endif +typedef struct SpiceInfo SpiceInfo ; +struct QemuSpiceOps {void (*init)(void );void (*display_init)(void );
@@ -32,6 +34,7 @@ struct QemuSpiceOps {int (*display_add_client)(int csock,int skipauth,int tls);#ifdef CONFIG_SPICE int (*add_interface)(SpiceBaseInstance *sin); + SpiceInfo* (*qmp_query)(Error **errp);#endif };
ui/spice-core.c +2 -1
@@ -502,7 +502,7 @@ static QemuOptsList qemu_spice_opts = { }, }; -SpiceInfo *qmp_query_spice (Error **errp) +static SpiceInfo *qmp_query_spice_real (Error **errp) {QemuOpts *opts =QTAILQ_FIRST (&qemu_spice_opts.head);int port, tls_port;
@@ -1001,6 +1001,7 @@ static struct QemuSpiceOps real_spice_ops = { .set_pw_expire = qemu_spice_set_pw_expire, .display_add_client = qemu_spice_display_add_client, .add_interface = qemu_spice_add_interface, + .qmp_query = qmp_query_spice_real, };static void spice_register_config (void )
ui/spice-module.c +17 -0
@@ -19,6 +19,9 @@#include "qemu/osdep.h" #include "qemu/error-report.h" +#include "qapi/error.h" +#include "qapi/qapi-types-ui.h" +#include "qapi/qapi-commands-ui.h" #include "ui/qemu-spice-module.h" int using_spice;
@@ -66,3 +69,17 @@ struct QemuSpiceOps qemu_spice = { .set_pw_expire = qemu_spice_set_pw_expire_stub, .display_add_client = qemu_spice_display_add_client_stub, }; + +#ifdef CONFIG_SPICE + +SpiceInfo *qmp_query_spice (Error **errp) +{ +if (!qemu_spice.qmp_query) { +SpiceInfo *info =g_new0 (SpiceInfo,1 ); + info->enabled = false; +return info; + } +return qemu_spice.qmp_query (errp); +} + +#endif
Signature · 1 line
2.27.0
PATCH 9/14 spice: load module when enabled on the cmdline
In reply to Gerd HoffmannIn case the spice opts are not registered, try loading the spice module.
--- softmmu/vl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
softmmu/vl.c +5 -1
@@ -3705,7 +3705,11 @@ void qemu_init(int argc, char **argv, char **envp)break ; }case QEMU_OPTION_spice: - olist =qemu_find_opts ("spice" ); + olist =qemu_find_opts_err ("spice" ,NULL ); +if (!olist) { +ui_module_load_one ("spice-core" ); + olist =qemu_find_opts ("spice" ); + }if (!olist) {error_report ("spice support is disabled" );exit (1 );
Signature · 1 line
2.27.0
PATCH 10/14 modules: dependencies infrastructure
In reply to Gerd HoffmannAllow modules depending on other modules.
module_load_file() gets the option to export symbols (by not adding the G_MODULE_BIND_LOCAL flag).
module_load_one() will check the module dependency list to figure (a) whenever are other modules must be loaded first, or (b) the module should export the symbols.
The dependencies are specificed as static list in the source code for now as I expect the list will stay small.
--- util/module.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
util/module.c +27 -5
@@ -110,7 +110,7 @@ void module_call_init(module_init_type type) }#ifdef CONFIG_MODULES -static int module_load_file (const char *fname,bool mayfail) +static int module_load_file (const char *fname,bool mayfail,bool export_symbols) {GModule *g_module;void (*sym)(void );
@@ -118,7 +118,7 @@ static int module_load_file(const char *fname, bool mayfail)int len =strlen (fname);int suf_len =strlen (dsosuf);ModuleEntry *e, *next; -int ret; +int ret, flags;if (len <= suf_len ||strcmp (&fname[len - suf_len], dsosuf)) {/* wrong suffix */
@@ -132,7 +132,11 @@ static int module_load_file(const char *fname, bool mayfail)assert (QTAILQ_EMPTY (&dso_init_list)); - g_module =g_module_open (fname,G_MODULE_BIND_LAZY |G_MODULE_BIND_LOCAL ); + flags =G_MODULE_BIND_LAZY ; +if (!export_symbols) { + flags |=G_MODULE_BIND_LOCAL ; + } + g_module =g_module_open (fname, flags);if (!g_module) {if (!mayfail) { fprintf(stderr, "Failed to open module: %s\n",
@@ -167,6 +171,12 @@ static int module_load_file(const char *fname, bool mayfail) out: return ret; } + +static const struct { +const char *name; +const char *dep; +} module_deps[] = { +};#endif bool module_load_one (const char *prefix,const char *lib_name,bool mayfail)
@@ -182,7 +192,8 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)char *dirs[5 ];char *module_name;int i =0 , n_dirs =0 ; -int ret; +int ret, dep; +bool export_symbols = false;static GHashTable *loaded_modules;if (!g_module_supported ()) {
@@ -196,6 +207,17 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail) module_name =g_strdup_printf ("%s%s" , prefix, lib_name); +for (dep =0 ; dep <ARRAY_SIZE (module_deps); dep++) { +if (strcmp (module_name, module_deps[dep].name) ==0 ) { +/* we depend on another module */ +module_load_one ("" , module_deps[dep].dep, false); + } +if (strcmp (module_name, module_deps[dep].dep) ==0 ) { +/* another module depends on us */ + export_symbols = true; + } + } +if (!g_hash_table_add (loaded_modules, module_name)) {g_free (module_name);return true;
@@ -220,7 +242,7 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail)for (i =0 ; i < n_dirs; i++) { fname =g_strdup_printf ("%s/%s%s" , dirs[i], module_name,CONFIG_HOST_DSOSUF ); - ret =module_load_file (fname, mayfail); + ret =module_load_file (fname, mayfail, export_symbols);g_free (fname); fname =NULL ;/* Try loading until loaded a module file */
Signature · 1 line
2.27.0
PATCH 11/14 modules: add spice dependencies
In reply to Gerd Hoffmann--- util/module.c | 5 +++++ 1 file changed, 5 insertions(+)
util/module.c +5 -0
@@ -176,6 +176,11 @@ static const struct { const char *name; const char *dep; } module_deps[] = { + { "audio-spice", "ui-spice-core" }, + { "chardev-spice", "ui-spice-core" }, + { "hw-display-qxl", "ui-spice-core" }, + { "ui-spice-app", "ui-spice-core" }, + { "ui-spice-app", "chardev-spice" }, }; #endif
Signature · 1 line
2.27.0
PATCH 12/14 spice: flip modules switch
In reply to Gerd HoffmannBuild spice core code as module. This removes libspice-server and a handful of indirect dependencies from core qemu. The number of shared libraries for qemu-system-x86_64 goes down from 73 to 66 on my system.
--- ui/meson.build | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
ui/meson.build +10 -1
@@ -15,7 +15,6 @@ softmmu_ss.add(files( softmmu_ss.add([spice_headers, files('spice-module.c')]) softmmu_ss.add(when: 'CONFIG_LINUX', if_true: files('input-linux.c')) -softmmu_ss.add(when: [spice, 'CONFIG_SPICE'], if_true: files('spice-core.c', 'spice-input.c', 'spice-display.c')) softmmu_ss.add(when: cocoa, if_true: files('cocoa.m')) vnc_ss = ss.source_set()
@@ -71,6 +70,16 @@ if sdl.found() ui_modules += {'sdl' : sdl_ss} endif +if config_host.has_key('CONFIG_SPICE') + spice_core_ss = ss.source_set() + spice_core_ss.add(spice, pixman, files( + 'spice-core.c', + 'spice-input.c', + 'spice-display.c' + )) + ui_modules += {'spice-core' : spice_core_ss} +endif + if config_host.has_key('CONFIG_SPICE') and config_host.has_key('CONFIG_GIO') spice_ss = ss.source_set() spice_ss.add(spice, gio, pixman, files('spice-app.c'))
Signature · 1 line
2.27.0
PATCH 13/14 opengl: build egl-headless display modular
In reply to Gerd Hoffmann--- ui/meson.build | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
ui/meson.build +7 -1
@@ -34,7 +34,6 @@ vnc_ss.add(when: sasl, if_true: files('vnc-auth-sasl.c')) softmmu_ss.add_all(when: vnc, if_true: vnc_ss) softmmu_ss.add(when: vnc, if_false: files('vnc-stubs.c')) softmmu_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('shader.c', 'console-gl.c', 'egl-helpers.c', 'egl-context.c')) -softmmu_ss.add(when: [opengl, 'CONFIG_OPENGL_DMABUF'], if_true: files('egl-headless.c')) specific_ss.add(when: ['CONFIG_SOFTMMU'], if_true: opengl) ui_modules = {}
@@ -45,6 +44,13 @@ if curses.found() ui_modules += {'curses' : curses_ss} endif +if config_host.has_key('CONFIG_OPENGL_DMABUF') + egl_headless_ss = ss.source_set() + egl_headless_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL_DMABUF'], + if_true: files('egl-headless.c')) + ui_modules += {'egl-headless' : egl_headless_ss} +endif + if config_host.has_key('CONFIG_GTK') softmmu_ss.add(when: 'CONFIG_WIN32', if_true: files('win32-kbd-hook.c'))
Signature · 1 line
2.27.0
PATCH 14/14 opengl: build opengl helper code modular
In reply to Gerd HoffmannRemoves opengl dependency from core qemu. The number of shared libraries for qemu-system-x86_64 goes down from 66 to 60 on my system.
--- util/module.c | 7 +++++++ ui/meson.build | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-)
util/module.c +7 -0
@@ -181,6 +181,13 @@ static const struct { { "hw-display-qxl", "ui-spice-core" }, { "ui-spice-app", "ui-spice-core" }, { "ui-spice-app", "chardev-spice" }, + +#ifdef CONFIG_OPENGL + { "ui-egl-headless", "ui-opengl" }, + { "ui-gtk", "ui-opengl" }, + { "ui-sdl", "ui-opengl" }, + { "ui-spice-core", "ui-opengl" }, +#endif }; #endif
ui/meson.build +7 -1
@@ -33,7 +33,6 @@ vnc_ss.add(zlib, png, jpeg) vnc_ss.add(when: sasl, if_true: files('vnc-auth-sasl.c')) softmmu_ss.add_all(when: vnc, if_true: vnc_ss) softmmu_ss.add(when: vnc, if_false: files('vnc-stubs.c')) -softmmu_ss.add(when: [opengl, 'CONFIG_OPENGL'], if_true: files('shader.c', 'console-gl.c', 'egl-helpers.c', 'egl-context.c')) specific_ss.add(when: ['CONFIG_SOFTMMU'], if_true: opengl) ui_modules = {}
@@ -44,6 +43,13 @@ if curses.found() ui_modules += {'curses' : curses_ss} endif +if config_host.has_key('CONFIG_OPENGL') + opengl_ss = ss.source_set() + opengl_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL'], + if_true: files('shader.c', 'console-gl.c', 'egl-helpers.c', 'egl-context.c')) + ui_modules += {'opengl' : opengl_ss} +endif + if config_host.has_key('CONFIG_OPENGL_DMABUF') egl_headless_ss = ss.source_set() egl_headless_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL_DMABUF'],
Signature · 1 line
2.27.0
Hi
Quoted 7 lines · Gerd Hoffmann
- Add QemuSpiceOps, reorganize spice stubs.
- Add support for module dependencies.
- Build spice-core modular, and make the existing spice modules (audio, chardev, qxl) depend on spice-core.
- Build egl-headless display and opengl helpers modular (pretty easy thanks to module dependencies).
Quoted 16 lines
Gerd Hoffmann (14):
spice: add module helpers
spice: add QemuSpiceOps, movemigrate_info
spice: moveqemu_spice_init()to QemuSpiceOps.
spice: movedisplay_init()to QemuSpiceOps.
spice: moveadd_interface()to QemuSpiceOps.
spice: move auth functions to QemuSpiceOps.
spice: movedisplay_add_client()to QemuSpiceOps.
spice: wire up monitor in QemuSpiceOps.
spice: load module when enabled on the cmdline
modules: dependencies infrastructure
modules: add spice dependencies
spice: flip modules switch
opengl: build egl-headless display modular
opengl: build opengl helper code modular
thanks!
Quoted 22 lines
include/ui/qemu-spice-module.h | 44 ++++++++++++++++++ include/ui/qemu-spice.h | 42 +---------------- audio/spiceaudio.c | 4 +- chardev/spice.c | 2 +- monitor/misc.c | 2 +- monitor/qmp-cmds.c | 6 +-- softmmu/vl.c | 10 ++-- ui/spice-core.c | 31 +++++++++---- ui/spice-input.c | 6 +-- ui/spice-module.c | 85 ++++++++++++++++++++++++++++++++++ util/module.c | 44 ++++++++++++++++-- ui/meson.build | 28 +++++++++-- 12 files changed, 232 insertions(+), 72 deletions(-) create mode 100644 include/ui/qemu-spice-module.h create mode 100644 ui/spice-module.c--
2.27.0
Signature · 1 line
Marc-André Lureau
Quoted 7 lines · Gerd Hoffmann
- Add QemuSpiceOps, reorganize spice stubs.
- Add support for module dependencies.
- Build spice-core modular, and make the existing spice modules (audio, chardev, qxl) depend on spice-core.
- Build egl-headless display and opengl helpers modular (pretty easy thanks to module dependencies).
Hi Gerd, others,
I am happy to see the work you are doing with modularizing qemu, but I think there also needs to be corresponding work with libvirt's ability to properly detect qemu functionality in light of this modularization.
Right now the QMP interface for probing "spice support" is quite a big hammer, and doesn't allow for any nuance.
As I've looked into other aspects of how libvirt detects qemu functionality, it seems there is a lot of room for improvement in how qemu advertises it's functionality - which goes well beyond the issues of modularization.
If you have any pointers to and discussion or plans in this regard, I'd appreciate it. Otherwise I'll look into doing something in this space myself.
Thanks,
Bruce
Quoted 9 lines · Bruce Rogers
Quoted 6 lines · Gerd Hoffmann
- Add QemuSpiceOps, reorganize spice stubs.
- Add support for module dependencies.
- Build spice-core modular, and make the existing spice modules (audio, chardev, qxl) depend on spice-core.
- Build egl-headless display and opengl helpers modular (pretty easy thanks to module dependencies).Hi Gerd, others,
Cc'ing John Snow who looks at qmp/qapi too right now.
Quoted 4 lines
I am happy to see the work you are doing with modularizing qemu, but I think there also needs to be corresponding work with libvirt's ability to properly detect qemu functionality in light of this modularization.
I've tried to not change qemu behavior, but there are limits to this as modularization brings some new constellations.
Quoted 2 lines
Right now the QMP interface for probing "spice support" is quite a big hammer, and doesn't allow for any nuance.
Yep. Specifically the CONFIG_SPICE=y and spice modules not installed at runtime is problematic I think.
Quoted 4 lines
As I've looked into other aspects of how libvirt detects qemu functionality, it seems there is a lot of room for improvement in how qemu advertises it's functionality - which goes well beyond the issues of modularization.
Well, everything which involves qom objects should work just fine, even with modules. You can see objects supported by qemu via qapi introspection, and that should work just fine with objects being implemented in modules.
Quoted 3 lines
If you have any pointers to and discussion or plans in this regard, I'd appreciate it. Otherwise I'll look into doing something in this space myself.
For -audiodev and -display we could turn stuff into objects (simliar to -chardev) and just use the object class registry instead of having a private registry. That would make things also visible in qom introspection.
The spice problem has been discussed in the past, but IIRC we didn't end up with a plan. We could have spice register a dummy qom object (say 'feature-spice'). Not sure this is a good idea though.
take care,
Gerd