Use module database for module dependencies. Drop hard-coded dependency list.
Signed-off-by: Gerd Hoffmann <kra...@redhat.com> --- util/module.c | 55 ++++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/util/module.c b/util/module.c index b0ea8c57d438..fd5fc059e14a 100644 --- a/util/module.c +++ b/util/module.c @@ -254,28 +254,6 @@ static int module_load_file(const char *fname, bool mayfail, bool export_symbols out: return ret; } - -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" }, - - { "hw-display-virtio-gpu-gl", "hw-display-virtio-gpu" }, - { "hw-display-virtio-gpu-pci-gl", "hw-display-virtio-gpu-pci" }, - { "hw-display-virtio-vga-gl", "hw-display-virtio-vga" }, - -#ifdef CONFIG_OPENGL - { "ui-egl-headless", "ui-opengl" }, - { "ui-gtk", "ui-opengl" }, - { "ui-sdl", "ui-opengl" }, - { "ui-spice-core", "ui-opengl" }, -#endif -}; #endif bool module_load_one(const char *prefix, const char *lib_name, bool mayfail) @@ -289,9 +267,11 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail) #endif char *module_name; int i = 0; - int ret, dep; + int ret; bool export_symbols = false; static GHashTable *loaded_modules; + ModuleInfoList *modlist; + strList *sl; if (!g_module_supported()) { fprintf(stderr, "Module is not supported by system.\n"); @@ -304,17 +284,6 @@ 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_contains(loaded_modules, module_name)) { g_free(module_name); return true; @@ -324,6 +293,24 @@ bool module_load_one(const char *prefix, const char *lib_name, bool mayfail) module_load_path_init(); module_load_modinfo(); + for (modlist = modinfo->list; modlist != NULL; modlist = modlist->next) { + if (modlist->value->has_deps) { + if (strcmp(modlist->value->name, module_name) == 0) { + /* we depend on other module(s) */ + for (sl = modlist->value->deps; sl != NULL; sl = sl->next) { + module_load_one("", sl->value, false); + } + } else { + for (sl = modlist->value->deps; sl != NULL; sl = sl->next) { + if (strcmp(module_name, sl->value) == 0) { + /* another module depends on us */ + export_symbols = true; + } + } + } + } + } + for (i = 0; i < module_ndirs; i++) { fname = g_strdup_printf("%s/%s%s", module_dirs[i], module_name, CONFIG_HOST_DSOSUF); -- 2.31.1