summary refs log tree commit diff stats
path: root/util/module.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2020-06-24 15:10:36 +0200
committerGerd Hoffmann <kraxel@redhat.com>2020-07-07 14:54:29 +0200
commit28457744c345ca4ccb58c984c9552e9c5955a9de (patch)
treeead752b46d257cdf4ff53fcb3d4200c2b22caca5 /util/module.c
parent7623b5ba017f61de5d7c2bba12c6feb3d55091b1 (diff)
downloadfocaccia-qemu-28457744c345ca4ccb58c984c9552e9c5955a9de.tar.gz
focaccia-qemu-28457744c345ca4ccb58c984c9552e9c5955a9de.zip
module: qom module support
Add support for qom types provided by modules.  For starters use a
manually maintained list which maps qom type to module and prefix.

Two load functions are added:  One to load the module for a specific
type, and one to load all modules (needed for object/device lists as
printed by -- for example -- qemu -device help).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Message-id: 20200624131045.14512-2-kraxel@redhat.com
Diffstat (limited to 'util/module.c')
-rw-r--r--util/module.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/util/module.c b/util/module.c
index e48d9aacc0..ee560a4b42 100644
--- a/util/module.c
+++ b/util/module.c
@@ -245,3 +245,58 @@ bool module_load_one(const char *prefix, const char *lib_name)
 #endif
     return success;
 }
+
+/*
+ * Building devices and other qom objects modular is mostly useful in
+ * case they have dependencies to external shared libraries, so we can
+ * cut down the core qemu library dependencies.  Which is the case for
+ * only a very few devices & objects.
+ *
+ * So with the expectation that this will be rather the exception than
+ * to rule and the list will not gain that many entries go with a
+ * simple manually maintained list for now.
+ */
+static struct {
+    const char *type;
+    const char *prefix;
+    const char *module;
+} const qom_modules[] = {
+};
+
+static bool module_loaded_qom_all;
+
+void module_load_qom_one(const char *type)
+{
+    int i;
+
+    if (module_loaded_qom_all) {
+        return;
+    }
+    for (i = 0; i < ARRAY_SIZE(qom_modules); i++) {
+        if (strcmp(qom_modules[i].type, type) == 0) {
+            module_load_one(qom_modules[i].prefix,
+                            qom_modules[i].module);
+            return;
+        }
+    }
+}
+
+void module_load_qom_all(void)
+{
+    int i;
+
+    if (module_loaded_qom_all) {
+        return;
+    }
+    for (i = 0; i < ARRAY_SIZE(qom_modules); i++) {
+        if (i > 0 && (strcmp(qom_modules[i - 1].module,
+                             qom_modules[i].module) == 0 &&
+                      strcmp(qom_modules[i - 1].prefix,
+                             qom_modules[i].prefix) == 0)) {
+            /* one module implementing multiple types -> load only once */
+            continue;
+        }
+        module_load_one(qom_modules[i].prefix, qom_modules[i].module);
+    }
+    module_loaded_qom_all = true;
+}