[CRIU] [RFC PATCH 03/20] criu/files-reg: Add offset and file path plugin
Felix Kuehling
Felix.Kuehling at amd.com
Sat May 1 04:58:28 MSK 2021
From: Rajneesh Bhardwaj <rajneesh.bhardwaj at amd.com>
This applies to Checkpoint-Restore operations for a device file. When
restoring VMAs for the device files, criu runs sys_mmap in the pie
restore context but the offsets and file path within a device file may
change during restore operation so it needs to be adjusted properly. A
future patch will add a consumer for this plugin.
Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj at amd.com>
Signed-off-by: David Yat Sin <david.yatsin at amd.com>
---
criu/files-reg.c | 18 ++++++++++++++++++
criu/include/criu-plugin.h | 8 ++++++++
criu/plugin.c | 1 +
3 files changed, 27 insertions(+)
diff --git a/criu/files-reg.c b/criu/files-reg.c
index d0a6fae60..531454af3 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -2314,6 +2314,23 @@ static int open_filemap(int pid, struct vma_area *vma)
BUG_ON((vma->vmfd == NULL) || !vma->e->has_fdflags);
flags = vma->e->fdflags;
+ /* update the new device file page offsets and file paths set during restore */
+ if (vma->e->status & VMA_UNSUPP) {
+ uint64_t new_pgoff;
+ char new_path[PATH_MAX];
+ int ret;
+
+ struct reg_file_info *rfi = container_of(vma->vmfd, struct reg_file_info, d);
+ ret = run_plugins(UPDATE_VMA_MAP, rfi->rfe->name, new_path, vma->e->start,
+ vma->e->pgoff, &new_pgoff);
+ if (ret == 1) {
+ pr_info("New mmap %#016"PRIx64"->%#016"PRIx64" path %s\n", vma->e->pgoff,
+ new_pgoff, new_path);
+ vma->e->pgoff = new_pgoff;
+ strcpy(rfi->path, new_path);
+ }
+ }
+
if (ctx.flags != flags || ctx.desc != vma->vmfd) {
if (vma->e->status & VMA_AREA_MEMFD)
ret = memfd_open(vma->vmfd, &flags);
@@ -2331,6 +2348,7 @@ static int open_filemap(int pid, struct vma_area *vma)
ctx.vma = vma;
vma->e->fd = ctx.fd;
+
return 0;
}
diff --git a/criu/include/criu-plugin.h b/criu/include/criu-plugin.h
index b76f5f839..850594ebf 100644
--- a/criu/include/criu-plugin.h
+++ b/criu/include/criu-plugin.h
@@ -22,6 +22,7 @@
#include <limits.h>
#include <stdbool.h>
+#include <stdint.h>
#define CRIU_PLUGIN_GEN_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#define CRIU_PLUGIN_VERSION_MAJOR 0
@@ -50,6 +51,8 @@ enum {
CR_PLUGIN_HOOK__DUMP_EXT_LINK = 6,
+ CR_PLUGIN_HOOK__UPDATE_VMA_MAP = 7,
+
CR_PLUGIN_HOOK__MAX
};
@@ -63,6 +66,8 @@ DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__RESTORE_EXT_FILE, int id);
DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__DUMP_EXT_MOUNT, char *mountpoint, int id);
DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__RESTORE_EXT_MOUNT, int id, char *mountpoint, char *old_root, int *is_file);
DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__DUMP_EXT_LINK, int index, int type, char *kind);
+DECLARE_PLUGIN_HOOK_ARGS(CR_PLUGIN_HOOK__UPDATE_VMA_MAP, const char* old_path, char *new_path,
+ const uint64_t addr, const uint64_t old_pgoff, uint64_t *new_pgoff);
enum {
CR_PLUGIN_STAGE__DUMP,
@@ -128,5 +133,8 @@ typedef int (cr_plugin_restore_file_t)(int id);
typedef int (cr_plugin_dump_ext_mount_t)(char *mountpoint, int id);
typedef int (cr_plugin_restore_ext_mount_t)(int id, char *mountpoint, char *old_root, int *is_file);
typedef int (cr_plugin_dump_ext_link_t)(int index, int type, char *kind);
+typedef int (cr_plugin_update_vma_offset_t)(const char* old_path, char *new_path,
+ const uint64_t addr, const uint64_t old_pgoff,
+ uint64_t *new_pgoff);
#endif /* __CRIU_PLUGIN_H__ */
diff --git a/criu/plugin.c b/criu/plugin.c
index f35a04fc9..35d171820 100644
--- a/criu/plugin.c
+++ b/criu/plugin.c
@@ -53,6 +53,7 @@ static cr_plugin_desc_t *cr_gen_plugin_desc(void *h, char *path)
__assign_hook(DUMP_EXT_MOUNT, "cr_plugin_dump_ext_mount");
__assign_hook(RESTORE_EXT_MOUNT, "cr_plugin_restore_ext_mount");
__assign_hook(DUMP_EXT_LINK, "cr_plugin_dump_ext_link");
+ __assign_hook(UPDATE_VMA_MAP, "cr_plugin_update_vma_map");
#undef __assign_hook
--
2.17.1
More information about the CRIU
mailing list