aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarc Mari <markmb@redhat.com>2016-08-12 09:27:03 -0400
committerMax Reitz <mreitz@redhat.com>2016-09-20 22:12:03 +0200
commit88d88798b7efeb0be15b1a60e58b1f8ba4c2f700 (patch)
tree13c971d74f4ee7ffe1829d038955c813b5f1fce0 /util
parent0c0c1fd973013671ea63680fcd9802766c1d04fe (diff)
downloadqemu-arm-88d88798b7efeb0be15b1a60e58b1f8ba4c2f700.tar.gz
blockdev: Add dynamic module loading for block drivers
Extend the current module interface to allow for block drivers to be loaded dynamically on request. The only block drivers that can be converted into modules are the drivers that don't perform any init operation except for registering themselves. In addition, only the protocol drivers are being modularized, as they are the only ones which see significant performance benefits. The format drivers do not generally link to external libraries, so modularizing them is of no benefit from a performance perspective. All the necessary module information is located in a new structure found in module_block.h This spoils the purpose of 5505e8b76f (block/dmg: make it modular). Before this patch, if module build is enabled, block-dmg.so is linked to libbz2, whereas the main binary is not. In downstream, theoretically, it means only the qemu-block-extra package depends on libbz2, while the main QEMU package needn't to. With this patch, we (temporarily) change the case so that the main QEMU depends on libbz2 again. Signed-off-by: Marc MarĂ­ <markmb@redhat.com> Signed-off-by: Colin Lord <clord@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 1471008424-16465-4-git-send-email-clord@redhat.com Reviewed-by: Max Reitz <mreitz@redhat.com> [mreitz: Do a signed comparison against the length of block_driver_modules[], so it will not cause a compile error when empty] Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/module.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/util/module.c b/util/module.c
index 86e3f7aba0..a5f7fbd941 100644
--- a/util/module.c
+++ b/util/module.c
@@ -87,14 +87,11 @@ void register_dso_module_init(void (*fn)(void), module_init_type type)
QTAILQ_INSERT_TAIL(&dso_init_list, e, node);
}
-static void module_load(module_init_type type);
-
void module_call_init(module_init_type type)
{
ModuleTypeList *l;
ModuleEntry *e;
- module_load(type);
l = find_type(type);
QTAILQ_FOREACH(e, l, node) {
@@ -145,6 +142,7 @@ static int module_load_file(const char *fname)
ret = -EINVAL;
} else {
QTAILQ_FOREACH(e, &dso_init_list, node) {
+ e->init();
register_module_init(e->init, e->type);
}
ret = 0;
@@ -159,14 +157,10 @@ out:
}
#endif
-static void module_load(module_init_type type)
+void module_load_one(const char *prefix, const char *lib_name)
{
#ifdef CONFIG_MODULES
char *fname = NULL;
- const char **mp;
- static const char *block_modules[] = {
- CONFIG_BLOCK_MODULES
- };
char *exec_dir;
char *dirs[3];
int i = 0;
@@ -177,15 +171,6 @@ static void module_load(module_init_type type)
return;
}
- switch (type) {
- case MODULE_INIT_BLOCK:
- mp = block_modules;
- break;
- default:
- /* no other types have dynamic modules for now*/
- return;
- }
-
exec_dir = qemu_get_exec_dir();
dirs[i++] = g_strdup_printf("%s", CONFIG_QEMU_MODDIR);
dirs[i++] = g_strdup_printf("%s/..", exec_dir ? : "");
@@ -194,16 +179,15 @@ static void module_load(module_init_type type)
g_free(exec_dir);
exec_dir = NULL;
- for ( ; *mp; mp++) {
- for (i = 0; i < ARRAY_SIZE(dirs); i++) {
- fname = g_strdup_printf("%s/%s%s", dirs[i], *mp, HOST_DSOSUF);
- ret = module_load_file(fname);
- g_free(fname);
- fname = NULL;
- /* Try loading until loaded a module file */
- if (!ret) {
- break;
- }
+ for (i = 0; i < ARRAY_SIZE(dirs); i++) {
+ fname = g_strdup_printf("%s/%s%s%s",
+ dirs[i], prefix, lib_name, HOST_DSOSUF);
+ ret = module_load_file(fname);
+ g_free(fname);
+ fname = NULL;
+ /* Try loading until loaded a module file */
+ if (!ret) {
+ break;
}
}