-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple plugin mechanism that will help to expand fuse-overlayfs functionalities, in particular it allows to load data from a layer on demand. A plugin is loaded into fuse-overlayfs using the option: -o plugins=path/to/plugin.so:path/to/another/plugin.so A layer can use a plugin with the syntax: -o lowerdir=//plugin-name/DATA-FOR-THE-PLUGIN/path Each time a file/directory is looked up, if a plugin is registered for a layer, the plugin is first notified about the request. After the callback is invoked, fuse-overlayfs still expects the data to be accessible at the specified directory. Signed-off-by: Giuseppe Scrivano <[email protected]>
- Loading branch information
Showing
8 changed files
with
289 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* fuse-overlayfs: Overlay Filesystem in Userspace | ||
Copyright (C) 2019 Red Hat Inc. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <config.h> | ||
#include <plugin.h> | ||
#include <stdlib.h> | ||
#include <error.h> | ||
#include <errno.h> | ||
#include <string.h> | ||
|
||
struct ovl_plugin_context * | ||
load_plugins (const char *plugins) | ||
{ | ||
char *saveptr = NULL, *it; | ||
cleanup_free char *buf = NULL; | ||
struct ovl_plugin_context *ctx; | ||
|
||
ctx = calloc (1, sizeof (*ctx)); | ||
if (ctx == NULL) | ||
error (EXIT_FAILURE, errno, "cannot allocate context"); | ||
|
||
buf = strdup (plugins); | ||
if (buf == NULL) | ||
error (EXIT_FAILURE, errno, "cannot allocate memory"); | ||
|
||
for (it = strtok_r (buf, ":", &saveptr); it; it = strtok_r (NULL, ":", &saveptr)) | ||
plugin_load_one (ctx, it); | ||
|
||
return ctx; | ||
} | ||
|
||
void | ||
plugin_load_one (struct ovl_plugin_context *context, const char *path) | ||
{ | ||
plugin_name name; | ||
struct ovl_plugin *p; | ||
plugin_version version; | ||
void *handle = dlopen (path, RTLD_NOW|RTLD_LOCAL); | ||
if (! handle) | ||
error (EXIT_FAILURE, 0, "cannot load plugin %s: %s", path, dlerror()); | ||
|
||
p = calloc (1, sizeof (*p)); | ||
if (p == NULL) | ||
error (EXIT_FAILURE, errno, "cannot load plugin %s", path); | ||
p->next = context->plugins; | ||
|
||
version = dlsym (handle, "plugin_version"); | ||
if (version == NULL) | ||
error (EXIT_FAILURE, 0, "cannot find symbol `plugin_version` in plugin %s", path); | ||
|
||
if (version () != 1) | ||
error (EXIT_FAILURE, 0, "invalid plugin version for %s", path); | ||
|
||
p->handle = handle; | ||
name = dlsym (handle, "plugin_name"); | ||
if (name == NULL) | ||
error (EXIT_FAILURE, 0, "cannot find symbol `plugin_name` in plugin %s", path); | ||
|
||
p->name = name (); | ||
|
||
if (plugin_find (context, p->name)) | ||
error (EXIT_FAILURE, 0, "plugin %s added twice", p->name); | ||
|
||
p->load = dlsym (handle, "plugin_load"); | ||
if (p->load == NULL) | ||
error (EXIT_FAILURE, 0, "cannot find symbol `plugin_load` in plugin %s", path); | ||
|
||
p->release = dlsym (handle, "plugin_release"); | ||
if (p->release == NULL) | ||
error (EXIT_FAILURE, 0, "cannot find symbol `plugin_release` in plugin %s", path); | ||
|
||
context->plugins = p; | ||
} | ||
|
||
struct ovl_plugin * | ||
plugin_find (struct ovl_plugin_context *context, const char *name) | ||
{ | ||
struct ovl_plugin *it; | ||
|
||
for (it = context->plugins; it; it = it->next) | ||
{ | ||
if (strcmp (name, it->name) == 0) | ||
return it; | ||
} | ||
return NULL; | ||
} | ||
|
||
int | ||
plugin_free_all (struct ovl_plugin_context *context) | ||
{ | ||
struct ovl_plugin *it, *next; | ||
|
||
it = context->plugins; | ||
while (it) | ||
{ | ||
next = it->next; | ||
|
||
dlclose (it->handle); | ||
free (it); | ||
|
||
it = next; | ||
} | ||
|
||
free (context); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* fuse-overlayfs: Overlay Filesystem in Userspace | ||
Copyright (C) 2019 Red Hat Inc. | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef PLUGIN_MANAGER_H | ||
# define PLUGIN_MANAGER_H | ||
# include <config.h> | ||
|
||
# include <dlfcn.h> | ||
|
||
struct ovl_plugin_context | ||
{ | ||
struct ovl_plugin *plugins; | ||
}; | ||
|
||
void plugin_load_one (struct ovl_plugin_context *context, const char *path); | ||
int plugin_free_all (struct ovl_plugin_context *context); | ||
struct ovl_plugin *plugin_find (struct ovl_plugin_context *context, const char *name); | ||
struct ovl_plugin_context *load_plugins (const char *plugins); | ||
|
||
#endif |
Oops, something went wrong.