[CRIU] [PATCH 10/28] rst: undump add collect of regular files added
Kinsbursky Stanislav
skinsbursky at openvz.org
Thu Mar 22 13:58:38 EDT 2012
From: Stanislav Kinsbursky <skinsbursky at openvz.org>
Note, file is collected with it's name - i.e no additional read prior to open
will be required.
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
cr-restore.c | 4 ++++
files.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
include/files.h | 1 +
3 files changed, 64 insertions(+), 1 deletions(-)
-------------- next part --------------
diff --git a/cr-restore.c b/cr-restore.c
index e95b0f6..7d0fa04 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -456,6 +456,10 @@ static int prepare_shared(int ps_fd)
return -1;
}
+ ret = prepare_files();
+ if (ret < 0)
+ return ret;
+
if (prepare_shared_fdinfo())
return -1;
diff --git a/files.c b/files.c
index 6a18bd6..6c14781 100644
--- a/files.c
+++ b/files.c
@@ -128,6 +128,65 @@ static int collect_fd(int pid, struct fdinfo_entry *e)
return 0;
}
+static int prepare_reg_files(void)
+{
+ int reg_file_fd, ret = 0;
+
+ reg_file_fd = open_glob_image_ro(CR_FD_REG_FILES);
+ if (reg_file_fd < 0) {
+ if (errno == ENOENT)
+ return 0;
+ return -1;
+ }
+
+ pr_info("Undumping regular files:\n");
+
+ while (1) {
+ struct file_entry *fe;
+
+ fe = xmalloc_shm(sizeof(*fe));
+ if (!fe)
+ return -ENOMEM;
+
+ ret = read_img_eof(reg_file_fd, fe);
+ if (ret <= 0)
+ break;
+
+ pr_info("\ttype: %4d id %20ld", fe->type, fe->id);
+
+ if (fe->len) {
+ fe = xrealloc_shm(fe, sizeof(*fe) + fe->len + 1);
+ if (!fe)
+ return -ENOMEM;
+
+ ret = read_img_buf_eof(reg_file_fd, fe->name, fe->len);
+ if (ret <= 0)
+ break;
+ fe->name[fe->len] = '\0';
+ }
+
+ if (fe->len)
+ pr_info(" --> %s", fe->name);
+ pr_info("\n");
+
+ ret = file_add(fe);
+ BUG_ON(ret);
+ }
+
+ close(reg_file_fd);
+ return ret;
+}
+
+int prepare_files(void)
+{
+ int ret;
+
+ pr_info("Undumping files objects:\n");
+
+ ret = prepare_reg_files();
+ return ret;
+}
+
int prepare_fd_pid(int pid)
{
int fdinfo_fd, ret = 0;
@@ -347,7 +406,6 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct fdinfo_desc *fi)
return -1;
}
}
-
return 0;
}
diff --git a/include/files.h b/include/files.h
index 098cf58..1d560ad 100644
--- a/include/files.h
+++ b/include/files.h
@@ -39,6 +39,7 @@ struct fdinfo_list_entry {
extern int prepare_fds(int pid);
extern int prepare_fd_pid(int pid);
+extern int prepare_files(void);
extern int prepare_shared_fdinfo(void);
extern int get_filemap_fd(int pid, struct vma_entry *vma_entry);
More information about the CRIU
mailing list