2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 18:07:57 +00:00
criu/files-ext.c

94 lines
1.9 KiB
C
Raw Normal View History

/* An external file is a file, which is dumped with help a plugin */
#include <unistd.h>
#include "imgset.h"
#include "files.h"
#include "plugin.h"
#include "protobuf.h"
#include "protobuf/ext-file.pb-c.h"
static int dump_one_ext_file(int lfd, u32 id, const struct fd_parms *p)
{
int ret;
struct cr_img *rimg;
ExtFileEntry xfe = EXT_FILE_ENTRY__INIT;
plugin: Rework plugins API, v2 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>
2014-02-27 20:58:23 +04:00
ret = run_plugins(DUMP_EXT_FILE, lfd, id);
if (ret < 0)
return ret;
xfe.id = id;
xfe.fown = (FownEntry *)&p->fown;
rimg = img_from_set(glob_imgset, CR_FD_EXT_FILES);
return pb_write_one(rimg, &xfe, PB_EXT_FILE);
}
const struct fdtype_ops ext_dump_ops = {
.type = FD_TYPES__EXT,
.dump = dump_one_ext_file,
};
struct ext_file_info {
struct file_desc d;
ExtFileEntry *xfe;
};
static int open_fd(struct file_desc *d)
{
struct ext_file_info *xfi;
int fd;
xfi = container_of(d, struct ext_file_info, d);
plugin: Rework plugins API, v2 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>
2014-02-27 20:58:23 +04:00
fd = run_plugins(RESTORE_EXT_FILE, xfi->xfe->id);
if (fd < 0) {
pr_err("Unable to restore %#x\n", xfi->xfe->id);
return -1;
}
if (restore_fown(fd, xfi->xfe->fown))
return -1;
return fd;
}
static struct file_desc_ops ext_desc_ops = {
.type = FD_TYPES__EXT,
.open = open_fd,
};
static int collect_one_ext(void *o, ProtobufCMessage *base)
{
struct ext_file_info *xfi = o;
xfi->xfe = pb_msg(base, ExtFileEntry);
pr_info("Collected external file with ID %#x\n", xfi->xfe->id);
return file_desc_add(&xfi->d, xfi->xfe->id, &ext_desc_ops);
}
struct collect_image_info ext_file_cinfo = {
.fd_type = CR_FD_EXT_FILES,
.pb_type = PB_EXT_FILE,
.priv_size = sizeof(struct ext_file_info),
.collect = collect_one_ext,
};
int dump_unsupp_fd(struct fd_parms *p, int lfd,
struct cr_img *img, char *more, char *info)
{
int ret;
ret = do_dump_gen_file(p, lfd, &ext_dump_ops, img);
if (ret == 0)
return 0;
if (ret == -ENOTSUP)
pr_err("Can't dump file %d of that type [%o] (%s %s)\n",
p->fd, p->stat.st_mode, more, info);
return -1;
}