[CRIU] [PATCH 16/28] rst: migrate cwd update
Kinsbursky Stanislav
skinsbursky at openvz.org
Thu Mar 22 13:59:18 EDT 2012
From: Stanislav Kinsbursky <skinsbursky at openvz.org>
Migrate cwd using reg files engine.
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
cr-dump.c | 10 ++++++++--
files.c | 33 +++++++++++++++++++++------------
include/image.h | 1 -
3 files changed, 29 insertions(+), 15 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index 6e6a5ec..179f49a 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -97,6 +97,12 @@ static int dump_one_reg_file(struct file_entry *p, pid_t pid,
int len;
int ret = -1;
struct fd_entry *fde = &e.fde;
+ struct stat fd_stat;
+
+ if (fstat(lfd, &fd_stat) < 0) {
+ pr_perror("Can't get stat on %d", lfd);
+ return -1;
+ }
snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", lfd);
len = readlink(fd_str, big_buffer, sizeof(big_buffer) - 1);
@@ -120,6 +126,7 @@ static int dump_one_reg_file(struct file_entry *p, pid_t pid,
u8 new;
long id;
+ p->id = MAKE_FD_GENID(fd_stat.st_dev, fd_stat.st_ino, p->pos);
id = file_collect(pid, target_fd, p, &new);
if (id < 0)
return id;
@@ -174,7 +181,7 @@ static int dump_task_special_files(pid_t pid, const struct cr_fdset *cr_fdset)
fd = open_proc(pid, "cwd");
if (fd < 0)
return -1;
- ret = dump_one_reg_file(&fe, FD_PID_INVALID, fd, 0, cr_fdset, 1);
+ ret = dump_one_reg_file(&fe, pid, fd, 0, cr_fdset, 1);
if (ret)
return ret;
@@ -357,7 +364,6 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, const char *d_name,
S_ISDIR(fd_stat.st_mode) ||
(S_ISCHR(fd_stat.st_mode) && major(fd_stat.st_rdev) == MEM_MAJOR)) {
- p.id = MAKE_FD_GENID(fd_stat.st_dev, fd_stat.st_ino, p.pos);
p.type = FDINFO_REG;
return dump_one_reg_file(&p, pid, lfd, target_fd, cr_fdset, 1);
diff --git a/files.c b/files.c
index 6bdc518..b4cc0c3 100644
--- a/files.c
+++ b/files.c
@@ -196,21 +196,26 @@ static int open_fe_fd(struct fdinfo_entry *fe, int fd)
return tmp;
}
-static int restore_cwd(struct fdinfo_entry *fe, int fd)
+static int restore_cwd(int id)
{
- char path[PATH_MAX];
+ struct file_info *fi;
+ char *path;
int ret;
- if (get_file_path(path, fe, fd))
+ fi = file_search(FDINFO_CWD, id);
+ if (fi == NULL) {
+ pr_err("Failed to find cwd with id %d\n", id);
return -1;
+ }
+
+ path = (char *)fi->rfe->name;
- pr_info("Restore CWD %s\n", path);
+ pr_info("\t%d: Restore CWD %s\n", fi->pid, path);
ret = chdir(path);
if (ret < 0) {
pr_perror("Can't change dir %s", path);
return -1;
}
-
return 0;
}
@@ -368,9 +373,6 @@ static int open_fd_transport(int pid, struct file_info *fi, struct fd_entry *fde
if (fi->pid == pid)
return 0;
- if (fde->type != FDINFO_REG)
- return 0;
-
pr_info("\t%d: Create transport for fd %d type %d id %ld\n", pid,
fde->fd, fde->type, fde->id);
@@ -412,6 +414,9 @@ static int open_fdinfo(int pid, struct fd_entry *fde, int *fdinfo_fd, int state)
if (move_img_fd(fdinfo_fd, fde->fd))
return -1;
+ pr_info("\t%d: Got fd for %d type %d id %ld\n", pid,
+ fde->fd, fde->type, fde->id);
+
BUG_ON(fde->type != FDINFO_REG);
fi = file_search(fde->type, fde->id);
@@ -446,8 +451,6 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe,
if (fe->fde.type == FDINFO_MAP)
return open_fmap(pid, fe, fdinfo_fd);
- if (fe->fde.type == FDINFO_CWD)
- return restore_cwd(fe, fdinfo_fd);
if (fe->fde.type == FDINFO_EXE)
return restore_exe_early(fe, fdinfo_fd);
@@ -458,7 +461,7 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe,
int prepare_fds(int pid)
{
- int ret, err = -1, fdinfo_fd, state;
+ int ret, err = -1, fdinfo_fd, state, cwd_id = 0;
off_t offset, magic_offset;
struct fdinfo_entry fe;
@@ -485,6 +488,11 @@ int prepare_fds(int pid)
goto err;
}
+ if (fe.fde.type == FDINFO_CWD) {
+ cwd_id = fe.fde.id;
+ continue;
+ }
+
if (fd_is_special(&fe.fde)) {
if (open_special_fdinfo(pid, &fe, fdinfo_fd, state))
goto err;
@@ -499,7 +507,8 @@ int prepare_fds(int pid)
lseek(fdinfo_fd, offset + fe.len, SEEK_SET);
}
}
- err = 0;
+ BUG_ON(cwd_id == 0);
+ err = restore_cwd(cwd_id);
err:
close(fdinfo_fd);
return err;
diff --git a/include/image.h b/include/image.h
index 62cf603..685fe06 100644
--- a/include/image.h
+++ b/include/image.h
@@ -71,7 +71,6 @@ struct fdinfo_entry {
#define fd_is_special(fde) \
(((fde)->type == FDINFO_MAP) || \
- ((fde)->type == FDINFO_CWD) || \
((fde)->type == FDINFO_EXE))
struct pstree_entry {
More information about the CRIU
mailing list