Dobby
3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
|
Class that manages all the plugin hook libraries. More...
#include <DobbyLegacyPluginManager.h>
Public Member Functions | |
DobbyLegacyPluginManager (const std::shared_ptr< IDobbyEnv > &env, const std::shared_ptr< IDobbyUtils > &utils, const std::string &path=std::string(DEFAULT_PLUGIN_PATH)) | |
void | refreshPlugins (const std::string &path=std::string(DEFAULT_PLUGIN_PATH)) |
(re)loads all the plugin libraries found at the given path More... | |
bool | executePostConstructionHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::shared_ptr< IDobbyStartState > &startupState, const std::string &rootfsPath) const |
Calls the postConstruction method for the given plugins. More... | |
bool | executePreStartHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, pid_t pid, const std::string &rootfsPath) const |
Calls the preStart method for the given plugins. More... | |
bool | executePostStartHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, pid_t pid, const std::string &rootfsPath) const |
Calls the postStart method for the given plugins. More... | |
bool | executePostStopHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::string &rootfsPath) const |
Calls the postStop method for the given plugins. More... | |
bool | executePreDestructionHooks (const std::map< std::string, Json::Value > &plugins, const ContainerId &id, const std::string &rootfsPath) const |
Calls the preDestruction method for the given plugins. More... | |
Private Types | |
typedef std::function< bool(IDobbyPlugin *, const Json::Value &)> | HookFn |
Private Member Functions | |
bool | executeHooks (const std::map< std::string, Json::Value > &plugins, const HookFn &hookFn, unsigned asyncFlag, unsigned syncFlag) const |
Calls the supplied hook function for the plugins in the list. More... | |
std::shared_ptr< IDobbyPlugin > | getPlugin (const std::string &name) const |
Get the plugin with the name, or nullptr if no plugin. More... | |
void | loadPlugins (const std::string &path) |
Scans the given path for any shared objects that implement the plugin entry points. More... | |
Private Attributes | |
pthread_rwlock_t | mRwLock |
const std::shared_ptr< IDobbyEnv > | mEnvironment |
const std::shared_ptr< IDobbyUtils > | mUtilities |
std::map< std::string, std::pair< void *, std::shared_ptr< IDobbyPlugin > > > | mPlugins |
Class that manages all the plugin hook libraries.
This class doesn't manage the system hooks, they are setup in the DobbyManager class (we should probably change this ... TBD)
At creation time it loads all the plugin libraries from /opt/libexec.
|
private |
Calls the supplied hook function for the plugins in the list.
Because the process of executing plugin hooks is the same for all hooks, we use this function to do the work, supplying it with (effectively) a function pointer of the hook we want to execute.
This function will iterate over the plugins and call the function pointer on each plugin object.
The plugins themselves provide a bit-field indicating which hooks need to be executed, and if they should be executed whether they run in a separate thread or in the calling thread. These hints are queried before executing the supplied hook function.
[in] | plugins | A map of plugin names and their data to execute |
[in] | hookFn | The hook method to call on the plugin |
[in] | asyncFlag | The bit flag that if the plugin has set indicates the hook method should be called asynchronously |
[in] | syncFlag | The bit flag that if the plugin has set indicates the hook method should be called synchronously |
bool DobbyLegacyPluginManager::executePostConstructionHooks | ( | const std::map< std::string, Json::Value > & | plugins, |
const ContainerId & | id, | ||
const std::shared_ptr< IDobbyStartState > & | startupState, | ||
const std::string & | rootfsPath | ||
) | const |
Calls the postConstruction method for the given plugins.
The function iterates over the list of plugins and their data and calls the plugin's postConstruction method. Each plugin provides hints as to whether the hook method should be executed at all or synchronously or asynchronously.
[in] | plugins | A map of plugin names and their data to execute. |
[in] | id | The id of the container. |
[in] | startupState | The start-up state of the container. |
[in] | rootfsPath | The path of the rootfs of the container. |
bool DobbyLegacyPluginManager::executePostStartHooks | ( | const std::map< std::string, Json::Value > & | plugins, |
const ContainerId & | id, | ||
pid_t | pid, | ||
const std::string & | rootfsPath | ||
) | const |
Calls the postStart method for the given plugins.
The function iterates over the list of plugins and their data and calls the plugin's postStart method. Each plugin provides hints as to whether the hook method should be executed; at all or synchronously or asynchronously.
[in] | plugins | A map of plugin names and their data to execute. |
[in] | id | The id of the container. |
[in] | pid | The pid of the init process inside the container. |
[in] | rootfsPath | The path of the rootfs of the container. |
bool DobbyLegacyPluginManager::executePostStopHooks | ( | const std::map< std::string, Json::Value > & | plugins, |
const ContainerId & | id, | ||
const std::string & | rootfsPath | ||
) | const |
Calls the postStop method for the given plugins.
The function iterates over the list of plugins and their data and calls the plugin's postStop method. Each plugin provides hints as to whether the hook method should be executed; at all or synchronously or asynchronously.
[in] | plugins | A map of plugin names and their data to execute. |
[in] | id | The id of the container. |
[in] | rootfsPath | The path of the rootfs of the container. |
bool DobbyLegacyPluginManager::executePreDestructionHooks | ( | const std::map< std::string, Json::Value > & | plugins, |
const ContainerId & | id, | ||
const std::string & | rootfsPath | ||
) | const |
Calls the preDestruction method for the given plugins.
The function iterates over the list of plugins and their data and calls the plugin's preDestruction method. Each plugin provides hints as to whether the hook method should be executed; at all or synchronously or asynchronously.
[in] | plugins | A map of plugin names and their data to execute. |
[in] | id | The id of the container. |
[in] | rootfsPath | The path of the rootfs of the container. |
bool DobbyLegacyPluginManager::executePreStartHooks | ( | const std::map< std::string, Json::Value > & | plugins, |
const ContainerId & | id, | ||
pid_t | pid, | ||
const std::string & | rootfsPath | ||
) | const |
Calls the preStart method for the given plugins.
The function iterates over the list of plugins and their data and calls the plugin's preStart method. Each plugin provides hints as to whether the hook method should be executed; at all or synchronously or asynchronously.
[in] | plugins | A map of plugin names and their data to execute. |
[in] | id | The id of the container. |
[in] | pid | The pid of the init process inside the container. |
[in] | rootfsPath | The path of the rootfs of the container. |
|
inlineprivate |
Get the plugin with the name, or nullptr if no plugin.
[in] | name | The name of the plugin. |
|
private |
Scans the given path for any shared objects that implement the plugin entry points.
This calls dlopen() on all the executable files in the given path (although it doesn't recurse into subdirs), if the file has symbols createIDobbyPlugin and destroyIDobbyPlugin then it's deemed to be a 'dobby' plugin.
If loaded successfully the plugins are stored in an internal map, keyed off the plugin name.
[in] | path | The path to scan for hook libraries. |
void DobbyLegacyPluginManager::refreshPlugins | ( | const std::string & | path = std::string(DEFAULT_PLUGIN_PATH) | ) |
(re)loads all the plugin libraries found at the given path
Intended for debugging / developing plugins as it allows for reloading libraries.
[in] | path | The path to scan for plugins libraries. |