mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 18:25:14 +00:00
Here we define new api to be used in plugins.
- Plugin should provide a descriptor with help of
CR_PLUGIN_REGISTER macro, or in case if plugin require
no init/exit functions -- with CR_PLUGIN_REGISTER_DUMMY.
- Plugin should define a plugin hook with help of
CR_PLUGIN_REGISTER_HOOK macro.
- Now init/exit functions of plugins takes @stage
argument which tells plugin which stage of criu
it's been called on dump/restore. For exit it
also takes @ret which allows plugin to know if
something went wrong and it needs to cleanup
own resources.
The idea behind is to not limit plugins authors with names
of functions they might need to use for particular hook.
Such new API deprecates olds plugins structure but to keep
backward compatibility we will provide a tiny layer of
additional code to support old plugins for at least a couple
of release cycles.
For example a trivial plugin might look like
| #include <sys/types.h>
| #include <sys/stat.h>
| #include <fcntl.h>
| #include <libgen.h>
| #include <errno.h>
|
| #include <sys/socket.h>
| #include <linux/un.h>
|
| #include <stdio.h>
| #include <stdlib.h>
| #include <string.h>
| #include <unistd.h>
|
| #include "criu-plugin.h"
| #include "criu-log.h"
|
| static int dump_ext_file(int fd, int id)
| {
| pr_info("dump_ext_file: fd %d id %d\n", fd, id);
| return 0;
| }
|
| CR_PLUGIN_REGISTER_DUMMY("trivial")
| CR_PLUGIN_REGISTER_HOOK(CR_PLUGIN_HOOK__DUMP_EXT_FILE, dump_ext_file)
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
46 lines
1.2 KiB
C
46 lines
1.2 KiB
C
#ifndef __CR_PLUGIN_H__
|
|
#define __CR_PLUGIN_H__
|
|
|
|
#include "criu-plugin.h"
|
|
#include "compiler.h"
|
|
#include "list.h"
|
|
|
|
#define CR_PLUGIN_DEFAULT "/var/lib/criu/"
|
|
|
|
void cr_plugin_fini(int stage, int err);
|
|
int cr_plugin_init(int stage);
|
|
|
|
typedef struct {
|
|
struct list_head head;
|
|
struct list_head hook_chain[CR_PLUGIN_HOOK__MAX];
|
|
} cr_plugin_ctl_t;
|
|
|
|
extern cr_plugin_ctl_t cr_plugin_ctl;
|
|
|
|
typedef struct {
|
|
cr_plugin_desc_t *d;
|
|
struct list_head list;
|
|
void *dlhandle;
|
|
struct list_head link[CR_PLUGIN_HOOK__MAX];
|
|
} plugin_desc_t;
|
|
|
|
#define run_plugins(__hook, ...) \
|
|
({ \
|
|
plugin_desc_t *this; \
|
|
int __ret = -ENOTSUP; \
|
|
\
|
|
list_for_each_entry(this, &cr_plugin_ctl.hook_chain[CR_PLUGIN_HOOK__ ##__hook], \
|
|
link[CR_PLUGIN_HOOK__ ##__hook]) { \
|
|
pr_debug("plugin: `%s' hook %u -> %p\n", \
|
|
this->d->name, CR_PLUGIN_HOOK__ ##__hook, \
|
|
this->d->hooks[CR_PLUGIN_HOOK__ ##__hook]); \
|
|
__ret = ((CR_PLUGIN_HOOK__ ##__hook ##_t *) \
|
|
this->d->hooks[CR_PLUGIN_HOOK__ ##__hook])(__VA_ARGS__); \
|
|
if (__ret == -ENOTSUP) \
|
|
continue; \
|
|
break; \
|
|
} \
|
|
__ret; \
|
|
})
|
|
|
|
#endif
|