Skip to content

Commit

Permalink
qemu-config: load modules when instantiating option groups
Browse files Browse the repository at this point in the history
Right now the SPICE module is special cased to be loaded when processing
of the -spice command line option.  However, the spice option group
can also be brought in via -readconfig, in which case the module is
not loaded.

Add a generic hook to load modules that provide a QemuOpts group,
and use it for the "spice" and "iscsi" groups.

Fixes: #194
Fixes: https://bugs.launchpad.net/qemu/+bug/1910696
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed May 26, 2021
1 parent d349f92 commit 632a887
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/qemu/config-file.h
@@ -1,7 +1,7 @@
#ifndef QEMU_CONFIG_FILE_H
#define QEMU_CONFIG_FILE_H


void qemu_load_module_for_opts(const char *group);
QemuOptsList *qemu_find_opts(const char *group);
QemuOptsList *qemu_find_opts_err(const char *group, Error **errp);
QemuOpts *qemu_find_opts_singleton(const char *group);
Expand Down
21 changes: 17 additions & 4 deletions softmmu/vl.c
Expand Up @@ -2627,6 +2627,23 @@ void qmp_x_exit_preconfig(Error **errp)
}
}

#ifdef CONFIG_MODULES
void qemu_load_module_for_opts(const char *group)
{
static bool spice_tried;
if (g_str_equal(group, "spice") && !spice_tried) {
ui_module_load_one("spice-core");
spice_tried = true;
}

static bool iscsi_tried;
if (g_str_equal(group, "iscsi") && !iscsi_tried) {
block_module_load_one("iscsi");
iscsi_tried = true;
}
}
#endif

void qemu_init(int argc, char **argv, char **envp)
{
QemuOpts *opts;
Expand Down Expand Up @@ -3386,10 +3403,6 @@ void qemu_init(int argc, char **argv, char **envp)
break;
case QEMU_OPTION_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);
Expand Down
1 change: 1 addition & 0 deletions stubs/meson.build
Expand Up @@ -22,6 +22,7 @@ stub_ss.add(files('isa-bus.c'))
stub_ss.add(files('is-daemonized.c'))
stub_ss.add(when: 'CONFIG_LINUX_AIO', if_true: files('linux-aio.c'))
stub_ss.add(files('migr-blocker.c'))
stub_ss.add(files('module-opts.c'))
stub_ss.add(files('monitor.c'))
stub_ss.add(files('monitor-core.c'))
stub_ss.add(files('pci-bus.c'))
Expand Down
6 changes: 6 additions & 0 deletions stubs/module-opts.c
@@ -0,0 +1,6 @@
#include "qemu/osdep.h"
#include "qemu/config-file.h"

void qemu_load_module_for_opts(const char *group)
{
}
1 change: 1 addition & 0 deletions util/qemu-config.c
Expand Up @@ -16,6 +16,7 @@ static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
{
int i;

qemu_load_module_for_opts(group);
for (i = 0; lists[i] != NULL; i++) {
if (strcmp(lists[i]->name, group) == 0)
break;
Expand Down

0 comments on commit 632a887

Please sign in to comment.