[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 12/18] modules: add module_load_path_init helper
From: |
Gerd Hoffmann |
Subject: |
[PATCH v2 12/18] modules: add module_load_path_init helper |
Date: |
Thu, 10 Jun 2021 07:57:49 +0200 |
Factor out module search path initialization to the new
module_load_path_init() helper. Also store the search path in
global variables and keep it so we have to do it only once.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
util/module.c | 58 ++++++++++++++++++++++++++++++---------------------
1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/util/module.c b/util/module.c
index eee8ff2de136..3a2d6dde9734 100644
--- a/util/module.c
+++ b/util/module.c
@@ -110,6 +110,36 @@ void module_call_init(module_init_type type)
}
#ifdef CONFIG_MODULES
+
+static char *module_dirs[5];
+static int module_ndirs;
+
+static void module_load_path_init(void)
+{
+ const char *search_dir;
+
+ if (module_ndirs) {
+ return;
+ }
+
+ search_dir = getenv("QEMU_MODULE_DIR");
+ if (search_dir != NULL) {
+ module_dirs[module_ndirs++] = g_strdup_printf("%s", search_dir);
+ }
+ module_dirs[module_ndirs++] = get_relocated_path(CONFIG_QEMU_MODDIR);
+ module_dirs[module_ndirs++] = g_strdup(qemu_get_exec_dir());
+
+#ifdef CONFIG_MODULE_UPGRADES
+ version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
+ G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~",
+ '_');
+ module_dirs[module_ndirs++] = g_strdup_printf("/var/run/qemu/%s",
version_dir);
+#endif
+
+ assert(module_ndirs <= ARRAY_SIZE(module_dirs));
+
+}
+
static int module_load_file(const char *fname, bool mayfail, bool
export_symbols)
{
GModule *g_module;
@@ -204,10 +234,8 @@ bool module_load_one(const char *prefix, const char
*lib_name, bool mayfail)
#ifdef CONFIG_MODULE_UPGRADES
char *version_dir;
#endif
- const char *search_dir;
- char *dirs[5];
char *module_name;
- int i = 0, n_dirs = 0;
+ int i = 0;
int ret, dep;
bool export_symbols = false;
static GHashTable *loaded_modules;
@@ -240,25 +268,11 @@ bool module_load_one(const char *prefix, const char
*lib_name, bool mayfail)
}
g_hash_table_add(loaded_modules, module_name);
- search_dir = getenv("QEMU_MODULE_DIR");
- if (search_dir != NULL) {
- dirs[n_dirs++] = g_strdup_printf("%s", search_dir);
- }
- dirs[n_dirs++] = get_relocated_path(CONFIG_QEMU_MODDIR);
- dirs[n_dirs++] = g_strdup(qemu_get_exec_dir());
+ module_load_path_init();
-#ifdef CONFIG_MODULE_UPGRADES
- version_dir = g_strcanon(g_strdup(QEMU_PKGVERSION),
- G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.~",
- '_');
- dirs[n_dirs++] = g_strdup_printf("/var/run/qemu/%s", version_dir);
-#endif
-
- assert(n_dirs <= ARRAY_SIZE(dirs));
-
- for (i = 0; i < n_dirs; i++) {
+ for (i = 0; i < module_ndirs; i++) {
fname = g_strdup_printf("%s/%s%s",
- dirs[i], module_name, CONFIG_HOST_DSOSUF);
+ module_dirs[i], module_name, CONFIG_HOST_DSOSUF);
ret = module_load_file(fname, mayfail, export_symbols);
g_free(fname);
fname = NULL;
@@ -274,10 +288,6 @@ bool module_load_one(const char *prefix, const char
*lib_name, bool mayfail)
g_free(module_name);
}
- for (i = 0; i < n_dirs; i++) {
- g_free(dirs[i]);
- }
-
#endif
return success;
}
--
2.31.1
- Re: [PATCH v2 02/18] qapi: add ModuleInfo schema, (continued)
[PATCH v2 05/18] modules: add chardev module annotations, Gerd Hoffmann, 2021/06/10
[PATCH v2 04/18] modules: add virtio-gpu module annotations, Gerd Hoffmann, 2021/06/10
[PATCH v2 06/18] modules: add audio module annotations, Gerd Hoffmann, 2021/06/10
[PATCH v2 07/18] modules: add usb-redir module annotations, Gerd Hoffmann, 2021/06/10
[PATCH v2 09/18] modules: add ui module annotations, Gerd Hoffmann, 2021/06/10
[PATCH v2 08/18] modules: add ccid module annotations, Gerd Hoffmann, 2021/06/10
[PATCH v2 10/18] modules: add s390x module annotations, Gerd Hoffmann, 2021/06/10
[PATCH v2 11/18] modules: add block module annotations, Gerd Hoffmann, 2021/06/10
[PATCH v2 12/18] modules: add module_load_path_init helper,
Gerd Hoffmann <=
[PATCH v2 13/18] modules: load modinfo.json, Gerd Hoffmann, 2021/06/10
[PATCH v2 14/18] modules: use modinfo for dependencies, Gerd Hoffmann, 2021/06/10
[PATCH v2 15/18] modules: use modinfo for qom load, Gerd Hoffmann, 2021/06/10
[PATCH v2 17/18] modules: check arch and block load on mismatch, Gerd Hoffmann, 2021/06/10
- Re: [PATCH v2 17/18] modules: check arch and block load on mismatch, Daniel P . Berrangé, 2021/06/10
- Re: [PATCH v2 17/18] modules: check arch and block load on mismatch, Gerd Hoffmann, 2021/06/10
- Re: [PATCH v2 17/18] modules: check arch and block load on mismatch, Daniel P . Berrangé, 2021/06/10
- Re: [PATCH v2 17/18] modules: check arch and block load on mismatch, Gerd Hoffmann, 2021/06/10
- Re: [PATCH v2 17/18] modules: check arch and block load on mismatch, Claudio Fontana, 2021/06/14
- Re: [PATCH v2 17/18] modules: check arch and block load on mismatch, Gerd Hoffmann, 2021/06/14