From 3fb356cc86461a14450802e14fa79e8436dbbf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Mon, 4 Nov 2019 13:18:36 +0000 Subject: tcg plugins: expose an API version concept MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a very simple versioning API which allows the plugin infrastructure to check the API a plugin was built against. We also expose a min/cur API version to the plugin via the info block in case it wants to avoid using old deprecated APIs in the future. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell Reviewed-by: Robert Foley --- plugins/loader.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'plugins/loader.c') diff --git a/plugins/loader.c b/plugins/loader.c index ce724ed583..15fc7e5515 100644 --- a/plugins/loader.c +++ b/plugins/loader.c @@ -178,6 +178,25 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info) goto err_symbol; } + if (!g_module_symbol(ctx->handle, "qemu_plugin_version", &sym)) { + error_report("TCG plugin %s does not declare API version %s", + desc->path, g_module_error()); + goto err_symbol; + } else { + int version = *(int *)sym; + if (version < QEMU_PLUGIN_MIN_VERSION) { + error_report("TCG plugin %s requires API version %d, but " + "this QEMU supports only a minimum version of %d", + desc->path, version, QEMU_PLUGIN_MIN_VERSION); + goto err_symbol; + } else if (version > QEMU_PLUGIN_VERSION) { + error_report("TCG plugin %s requires API version %d, but " + "this QEMU supports only up to version %d", + desc->path, version, QEMU_PLUGIN_VERSION); + goto err_symbol; + } + } + qemu_rec_mutex_lock(&plugin.lock); /* find an unused random id with &ctx as the seed */ @@ -248,6 +267,8 @@ int qemu_plugin_load_list(QemuPluginList *head) g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1); info->target_name = TARGET_NAME; + info->version.min = QEMU_PLUGIN_MIN_VERSION; + info->version.cur = QEMU_PLUGIN_VERSION; #ifndef CONFIG_USER_ONLY MachineState *ms = MACHINE(qdev_get_machine()); info->system_emulation = true; -- cgit v1.2.3