[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/8] plugins: add core API functions for QPP callbacks
From: |
Andrew Fasano |
Subject: |
[PATCH 4/8] plugins: add core API functions for QPP callbacks |
Date: |
Tue, 13 Dec 2022 16:37:53 -0500 |
From: Elysia Witham <elysia.witham@ll.mit.edu>
Plugin callbacks and their registered functions are stored in a
separate struct which is accessible from the plugin's ctx.
In order for plugins to use another plugin's callbacks, we have
internal functions that resolve a plugin's name to its ctx and
find a target plugin.
Signed-off-by: Elysia Witham <elysia.witham@ll.mit.edu>
Signed-off-by: Andrew Fasano <fasano@mit.edu>
---
include/qemu/qemu-plugin.h | 10 ++++++++++
plugins/core.c | 23 +++++++++++++++++++++++
plugins/loader.c | 10 ++++++++++
plugins/plugin.h | 15 +++++++++++++++
4 files changed, 58 insertions(+)
diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index 5326f33ce8..3ec82ce97f 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -14,6 +14,7 @@
#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
+#include <gmodule.h>
/*
* For best performance, build the plugin with -fvisibility=hidden so that
@@ -38,6 +39,15 @@
*/
typedef uint64_t qemu_plugin_id_t;
+/**
+ * typedef cb_func_t - callback function pointer type
+ * @evdata: plugin callback defined event data
+ * @udata: plugin defined user data
+ *
+ * No return value.
+ */
+typedef void (*cb_func_t) (gpointer evdata, gpointer udata);
+
/*
* Versioning plugins:
*
diff --git a/plugins/core.c b/plugins/core.c
index 6a50b4a6e6..0415a55ec5 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -236,6 +236,17 @@ void qemu_plugin_vcpu_exit_hook(CPUState *cpu)
qemu_rec_mutex_unlock(&plugin.lock);
}
+struct qemu_plugin_ctx *plugin_name_to_ctx_locked(const char* name)
+{
+ struct qemu_plugin_ctx *ctx;
+ QTAILQ_FOREACH(ctx, &plugin.ctxs, entry) {
+ if (strcmp(ctx->name, name) == 0) {
+ return plugin_id_to_ctx_locked(ctx->id);
+ }
+ }
+ return NULL;
+}
+
int name_to_plugin_version(const char *name)
{
struct qemu_plugin_ctx *ctx;
@@ -260,6 +271,18 @@ const char *id_to_plugin_name(qemu_plugin_id_t id)
}
}
+struct qemu_plugin_qpp_cb *plugin_find_qpp_cb(struct qemu_plugin_ctx *ctx,
+ const char *name)
+{
+ struct qemu_plugin_qpp_cb *cb;
+ QTAILQ_FOREACH(cb, &ctx->qpp_cbs, entry) {
+ if (strcmp(cb->name, name) == 0) {
+ return cb;
+ }
+ }
+ return NULL;
+}
+
struct plugin_for_each_args {
struct qemu_plugin_ctx *ctx;
qemu_plugin_vcpu_simple_cb_t cb;
diff --git a/plugins/loader.c b/plugins/loader.c
index 12c0680e03..ab01d0753c 100644
--- a/plugins/loader.c
+++ b/plugins/loader.c
@@ -277,6 +277,7 @@ static int plugin_load(struct qemu_plugin_desc *desc, const
qemu_info_t *info, E
break;
}
}
+ QTAILQ_INIT(&ctx->qpp_cbs);
QTAILQ_INSERT_TAIL(&plugin.ctxs, ctx, entry);
ctx->installing = true;
rc = install(ctx->id, info, desc->argc, desc->argv);
@@ -303,6 +304,15 @@ static int plugin_load(struct qemu_plugin_desc *desc,
const qemu_info_t *info, E
return 1;
}
+void plugin_add_qpp_cb(struct qemu_plugin_ctx *ctx, const char *name)
+{
+ struct qemu_plugin_qpp_cb *new_cb;
+ new_cb = qemu_memalign(qemu_dcache_linesize, sizeof(*new_cb));
+ memset(new_cb, 0, sizeof(*new_cb));
+ new_cb->name = name;
+ QTAILQ_INSERT_TAIL(&ctx->qpp_cbs, new_cb, entry);
+}
+
/* call after having removed @desc from the list */
static void plugin_desc_free(struct qemu_plugin_desc *desc)
{
diff --git a/plugins/plugin.h b/plugins/plugin.h
index 9e710c23a7..fee4741bc6 100644
--- a/plugins/plugin.h
+++ b/plugins/plugin.h
@@ -47,6 +47,14 @@ struct qemu_plugin_state {
struct qht dyn_cb_arr_ht;
};
+typedef void (*cb_func_t) (gpointer evdata, gpointer udata);
+
+struct qemu_plugin_qpp_cb {
+ const char *name;
+ cb_func_t registered_cb_funcs[QEMU_PLUGIN_EV_MAX];
+ int counter;
+ QTAILQ_ENTRY(qemu_plugin_qpp_cb) entry;
+};
struct qemu_plugin_ctx {
GModule *handle;
@@ -54,6 +62,7 @@ struct qemu_plugin_ctx {
const char *name;
int version;
struct qemu_plugin_cb *callbacks[QEMU_PLUGIN_EV_MAX];
+ QTAILQ_HEAD(, qemu_plugin_qpp_cb) qpp_cbs;
QTAILQ_ENTRY(qemu_plugin_ctx) entry;
/*
* keep a reference to @desc until uninstall, so that plugins do not have
@@ -106,4 +115,10 @@ int name_to_plugin_version(const char *name);
const char *id_to_plugin_name(qemu_plugin_id_t id);
+struct qemu_plugin_qpp_cb *plugin_find_qpp_cb(struct qemu_plugin_ctx
*plugin_ctx,
+ const char *cb_name);
+
+/* loader.c */
+void plugin_add_qpp_cb(struct qemu_plugin_ctx *ctx, const char *name);
+
#endif /* PLUGIN_H */
--
2.34.1
- [PATCH 0/8] Inter-plugin interactions with QPP, Andrew Fasano, 2022/12/13
- [PATCH 1/8] docs/devel: describe QPP API, Andrew Fasano, 2022/12/13
- [PATCH 2/8] plugins: version 2, require unique plugin names, Andrew Fasano, 2022/12/13
- [PATCH 3/8] plugins: add id_to_plugin_name, Andrew Fasano, 2022/12/13
- [PATCH 6/8] plugins: implement QPP import function, Andrew Fasano, 2022/12/13
- [PATCH 7/8] include/qemu: added macro for QPP import function, Andrew Fasano, 2022/12/13
- [PATCH 8/8] tests: build and run QPP tests, Andrew Fasano, 2022/12/13
- [PATCH 4/8] plugins: add core API functions for QPP callbacks,
Andrew Fasano <=
- [PATCH 5/8] plugins: implement QPP callbacks, Andrew Fasano, 2022/12/13