mirror of
https://github.com/containers/fuse-overlayfs.git
synced 2025-08-04 02:15:58 -04:00
plugins: allow to manage multiple layers with a ds
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
7095cc29ef
commit
1c490d91d8
9
direct.c
9
direct.c
@ -160,7 +160,7 @@ direct_readlinkat (struct ovl_layer *l, const char *path, char *buf, size_t bufs
|
||||
}
|
||||
|
||||
static int
|
||||
direct_load_data_source (struct ovl_layer *l, const char *opaque, const char *path)
|
||||
direct_load_data_source (struct ovl_layer *l, const char *opaque, const char *path, int n_layer)
|
||||
{
|
||||
l->path = realpath (path, NULL);
|
||||
if (l->path == NULL)
|
||||
@ -186,8 +186,15 @@ direct_cleanup (struct ovl_layer *l)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
direct_num_of_layers (const char *opaque, const char *path)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct data_source direct_access_ds =
|
||||
{
|
||||
.num_of_layers = direct_num_of_layers,
|
||||
.load_data_source = direct_load_data_source,
|
||||
.cleanup = direct_cleanup,
|
||||
.file_exists = direct_file_exists,
|
||||
|
@ -119,7 +119,8 @@ struct ovl_layer
|
||||
/* a data_source defines the methods for accessing a lower layer. */
|
||||
struct data_source
|
||||
{
|
||||
int (*load_data_source)(struct ovl_layer *l, const char *opaque, const char *path);
|
||||
int (*num_of_layers) (const char *opaque, const char *path);
|
||||
int (*load_data_source)(struct ovl_layer *l, const char *opaque, const char *path, int n_layer);
|
||||
int (*cleanup)(struct ovl_layer *l);
|
||||
int (*file_exists)(struct ovl_layer *l, const char *pathname);
|
||||
int (*statat)(struct ovl_layer *l, const char *path, struct stat *st, int flags, unsigned int mask);
|
||||
|
30
main.c
30
main.c
@ -1549,16 +1549,14 @@ read_dirs (struct ovl_data *lo, char *path, bool low, struct ovl_layer *layers)
|
||||
{
|
||||
char *name, *data;
|
||||
char *it_path = it;
|
||||
int i, n_layers;
|
||||
cleanup_layer struct ovl_layer *l = NULL;
|
||||
|
||||
l = calloc (1, sizeof (*l));
|
||||
if (l == NULL)
|
||||
return NULL;
|
||||
struct data_source *ds;
|
||||
|
||||
if (it[0] != '/' || it[1] != '/')
|
||||
{
|
||||
/* By default use the direct access data store. */
|
||||
l->ds = &direct_access_ds;
|
||||
ds = &direct_access_ds;
|
||||
|
||||
data = NULL;
|
||||
path = it_path;
|
||||
@ -1603,20 +1601,35 @@ read_dirs (struct ovl_data *lo, char *path, bool low, struct ovl_layer *layers)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
l->ds = p->load (l, data, path);
|
||||
if (l->ds == NULL)
|
||||
ds = p->load (data, path);
|
||||
if (ds == NULL)
|
||||
{
|
||||
fprintf (stderr, "cannot load plugin %s\n", name);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
n_layers = ds->num_of_layers (data, path);
|
||||
if (n_layers < 0)
|
||||
{
|
||||
fprintf (stderr, "cannot retrieve number of layers for %s\n", path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < n_layers; i++)
|
||||
{
|
||||
l = calloc (1, sizeof (*l));
|
||||
if (l == NULL)
|
||||
return NULL;
|
||||
|
||||
l->ds = ds;
|
||||
|
||||
l->ovl_data = lo;
|
||||
|
||||
l->path = NULL;
|
||||
l->fd = -1;
|
||||
|
||||
if (l->ds->load_data_source (l, data, path) < 0)
|
||||
if (l->ds->load_data_source (l, data, path, i) < 0)
|
||||
{
|
||||
fprintf (stderr, "cannot load store %s at %s\n", data, path);
|
||||
return NULL;
|
||||
@ -1641,6 +1654,7 @@ read_dirs (struct ovl_data *lo, char *path, bool low, struct ovl_layer *layers)
|
||||
}
|
||||
l = NULL;
|
||||
}
|
||||
}
|
||||
return layers;
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,10 @@ plugin_free_all (struct ovl_plugin_context *context)
|
||||
{
|
||||
next = it->next;
|
||||
|
||||
dlclose (it->handle);
|
||||
it->release ();
|
||||
|
||||
/* Skip dlclose (it->handle) as it causes plugins written in Go to crash. */
|
||||
|
||||
free (it);
|
||||
|
||||
it = next;
|
||||
|
4
plugin.h
4
plugin.h
@ -23,8 +23,8 @@
|
||||
# include <utils.h>
|
||||
# include <fuse-overlayfs.h>
|
||||
|
||||
typedef struct data_source *(*plugin_load_data_source)(struct ovl_layer *layer, const char *opaque, const char *path);
|
||||
typedef int (*plugin_release)(struct ovl_layer *layer);
|
||||
typedef struct data_source *(*plugin_load_data_source)(const char *opaque, const char *path);
|
||||
typedef int (*plugin_release)();
|
||||
typedef const char *(*plugin_name)();
|
||||
typedef int (*plugin_version)();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user