summaryrefslogtreecommitdiffstats
path: root/discover/device-handler.c
diff options
context:
space:
mode:
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>2017-02-01 16:11:43 +1100
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2017-08-15 13:03:28 +1000
commitff7293bba1fd4cdf54bb90bd1b7a38dd393fee69 (patch)
tree39c5d79e99c48d577ed9f8a26114b2d8407cfe9e /discover/device-handler.c
parent9f191cc3c194ed51534c22e2dae15b2c08c8abc2 (diff)
downloadtalos-petitboot-ff7293bba1fd4cdf54bb90bd1b7a38dd393fee69.tar.gz
talos-petitboot-ff7293bba1fd4cdf54bb90bd1b7a38dd393fee69.zip
discover: Handle and track plugin_options
Track plugin_options in the device_handler. Plugins can be added with device_handler_add_plugin_option() and accessed via device_handler_get_plugin(). Extend discover_server to support the new 'add' and 'remove' pb-protocol actions and advertise new plugins to connecting clients. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/device-handler.c')
-rw-r--r--discover/device-handler.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index ec4a6f6..3ef48ad 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -84,6 +84,9 @@ struct device_handler {
struct list progress;
unsigned int n_progress;
+
+ struct plugin_option **plugins;
+ unsigned int n_plugins;
};
static int mount_device(struct discover_device *dev);
@@ -126,6 +129,28 @@ const struct discover_device *device_handler_get_device(
return handler->devices[index];
}
+/**
+ * device_handler_get_plugin_count - Get the count of current handler plugins.
+ */
+int device_handler_get_plugin_count(const struct device_handler *handler)
+{
+ return handler->n_plugins;
+}
+
+/**
+ * discover_handler_get_plugin - Get a handler plugin by index.
+ */
+const struct plugin_option *device_handler_get_plugin(
+ const struct device_handler *handler, unsigned int index)
+{
+ if (index >= handler->n_plugins) {
+ assert(0 && "bad index");
+ return NULL;
+ }
+
+ return handler->plugins[index];
+}
+
struct network *device_handler_get_network(
const struct device_handler *handler)
{
@@ -385,6 +410,15 @@ void device_handler_reinit(struct device_handler *handler)
handler->ramdisks = NULL;
handler->n_ramdisks = 0;
+ /* drop any known plugins */
+ for (i = 0; i < handler->n_plugins; i++)
+ talloc_free(handler->plugins[i]);
+ talloc_free(handler->plugins);
+ handler->plugins = NULL;
+ handler->n_plugins = 0;
+
+ discover_server_notify_plugins_remove(handler->server);
+
device_handler_reinit_sources(handler);
}
@@ -1408,6 +1442,36 @@ void device_handler_discover_context_commit(struct device_handler *handler,
}
}
+void device_handler_add_plugin_option(struct device_handler *handler,
+ struct plugin_option *opt)
+{
+ struct plugin_option *tmp;
+ unsigned int i;
+
+ for (i = 0; i < handler->n_plugins; i++) {
+ tmp = handler->plugins[i];
+ /* If both id and version match, ignore */
+ if (strncmp(opt->id, tmp->id, strlen(opt->id)) == 0 &&
+ strncmp(opt->version, tmp->version,
+ strlen(opt->version) == 0)) {
+ pb_log("discover: Plugin '%s' already exists, ignoring\n",
+ opt->id);
+ return;
+ }
+ }
+
+ handler->plugins = talloc_realloc(handler, handler->plugins,
+ struct plugin_option *, handler->n_plugins + 1);
+ if (!handler->plugins) {
+ pb_log("Failed to allocate memory for new plugin\n");
+ handler->n_plugins = 0;
+ return;
+ }
+
+ handler->plugins[handler->n_plugins++] = opt;
+ discover_server_notify_plugin_option_add(handler->server, opt);
+}
+
static void device_handler_update_lang(const char *lang)
{
const char *cur_lang;
OpenPOWER on IntegriCloud