Skip to content

Commit 2845774

Browse files
committed
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 <[email protected]> Message-id: [email protected]
1 parent 7623b5b commit 2845774

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

include/qemu/module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,7 @@ void register_dso_module_init(void (*fn)(void), module_init_type type);
7070

7171
void module_call_init(module_init_type type);
7272
bool module_load_one(const char *prefix, const char *lib_name);
73+
void module_load_qom_one(const char *type);
74+
void module_load_qom_all(void);
7375

7476
#endif

util/module.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,58 @@ bool module_load_one(const char *prefix, const char *lib_name)
245245
#endif
246246
return success;
247247
}
248+
249+
/*
250+
* Building devices and other qom objects modular is mostly useful in
251+
* case they have dependencies to external shared libraries, so we can
252+
* cut down the core qemu library dependencies. Which is the case for
253+
* only a very few devices & objects.
254+
*
255+
* So with the expectation that this will be rather the exception than
256+
* to rule and the list will not gain that many entries go with a
257+
* simple manually maintained list for now.
258+
*/
259+
static struct {
260+
const char *type;
261+
const char *prefix;
262+
const char *module;
263+
} const qom_modules[] = {
264+
};
265+
266+
static bool module_loaded_qom_all;
267+
268+
void module_load_qom_one(const char *type)
269+
{
270+
int i;
271+
272+
if (module_loaded_qom_all) {
273+
return;
274+
}
275+
for (i = 0; i < ARRAY_SIZE(qom_modules); i++) {
276+
if (strcmp(qom_modules[i].type, type) == 0) {
277+
module_load_one(qom_modules[i].prefix,
278+
qom_modules[i].module);
279+
return;
280+
}
281+
}
282+
}
283+
284+
void module_load_qom_all(void)
285+
{
286+
int i;
287+
288+
if (module_loaded_qom_all) {
289+
return;
290+
}
291+
for (i = 0; i < ARRAY_SIZE(qom_modules); i++) {
292+
if (i > 0 && (strcmp(qom_modules[i - 1].module,
293+
qom_modules[i].module) == 0 &&
294+
strcmp(qom_modules[i - 1].prefix,
295+
qom_modules[i].prefix) == 0)) {
296+
/* one module implementing multiple types -> load only once */
297+
continue;
298+
}
299+
module_load_one(qom_modules[i].prefix, qom_modules[i].module);
300+
}
301+
module_loaded_qom_all = true;
302+
}

0 commit comments

Comments
 (0)