Commit e2f745b9 authored by Pavel Emelyanov's avatar Pavel Emelyanov

files: Simplify fd-s restore

Don't re-read fdinfo image 4 times on restore, just use those collected
on me pstree_entry instance.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a72d8586
...@@ -504,7 +504,7 @@ static int restore_one_alive_task(int pid) ...@@ -504,7 +504,7 @@ static int restore_one_alive_task(int pid)
{ {
pr_info("%d: Restoring resources\n", pid); pr_info("%d: Restoring resources\n", pid);
if (prepare_fds(pid)) if (prepare_fds(me))
return -1; return -1;
if (prepare_fs(pid)) if (prepare_fs(pid))
......
...@@ -528,8 +528,7 @@ int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int tsk) ...@@ -528,8 +528,7 @@ int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int tsk)
return send_fd(tsk, &saddr, len, fd); return send_fd(tsk, &saddr, len, fd);
} }
static int open_fd(int pid, struct fdinfo_entry *fe, static int open_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
struct file_desc *d, int *fdinfo_fd)
{ {
int tmp; int tmp;
int serv, sock; int serv, sock;
...@@ -564,8 +563,6 @@ static int open_fd(int pid, struct fdinfo_entry *fe, ...@@ -564,8 +563,6 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
if (move_img_fd(&sock, fle->fe.fd)) if (move_img_fd(&sock, fle->fe.fd))
return -1; return -1;
if (move_img_fd(fdinfo_fd, fle->fe.fd))
return -1;
if (dup2(fe->fd, fle->fe.fd) != fle->fe.fd) { if (dup2(fe->fd, fle->fe.fd) != fle->fe.fd) {
pr_perror("Can't dup local fd %d -> %d", pr_perror("Can't dup local fd %d -> %d",
...@@ -615,16 +612,13 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d) ...@@ -615,16 +612,13 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
return 0; return 0;
} }
static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int state) static int open_fdinfo(int pid, struct fdinfo_entry *fe, int state)
{ {
u32 mag; u32 mag;
int ret = 0; int ret = 0;
struct file_desc *fdesc; struct file_desc *fdesc;
fdesc = find_file_desc(fe); fdesc = find_file_desc(fe);
if (move_img_fd(fdinfo_fd, fe->fd))
return -1;
pr_info("\t%d: Restoring fd %d (state -> %d)\n", pid, fe->fd, state); pr_info("\t%d: Restoring fd %d (state -> %d)\n", pid, fe->fd, state);
switch (state) { switch (state) {
...@@ -632,7 +626,7 @@ static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int sta ...@@ -632,7 +626,7 @@ static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int sta
ret = open_transport_fd(pid, fe, fdesc); ret = open_transport_fd(pid, fe, fdesc);
break; break;
case FD_STATE_CREATE: case FD_STATE_CREATE:
ret = open_fd(pid, fe, fdesc, fdinfo_fd); ret = open_fd(pid, fe, fdesc);
break; break;
case FD_STATE_RECV: case FD_STATE_RECV:
ret = receive_fd(pid, fe, fdesc); ret = receive_fd(pid, fe, fdesc);
...@@ -642,45 +636,24 @@ static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int sta ...@@ -642,45 +636,24 @@ static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int sta
return ret; return ret;
} }
int prepare_fds(int pid) int prepare_fds(struct pstree_item *me)
{ {
u32 type = 0, ret; u32 type = 0, ret;
int fdinfo_fd;
int state; int state;
struct fdinfo_list_entry *fle;
struct fdinfo_entry fe;
int nr = 0; int nr = 0;
pr_info("%d: Opening fdinfo-s\n", pid); pr_info("%d: Opening fdinfo-s\n", me->pid);
fdinfo_fd = open_image_ro(CR_FD_FDINFO, pid);
if (fdinfo_fd < 0) {
pr_perror("%d: Can't open pipes img", pid);
return -1;
}
for (state = 0; state < FD_STATE_MAX; state++) {
lseek(fdinfo_fd, MAGIC_OFFSET, SEEK_SET);
while (1) { for (state = 0; state < FD_STATE_MAX; state++)
ret = read_img_eof(fdinfo_fd, &fe); list_for_each_entry(fle, &me->rst->fds, ps_list) {
if (ret <= 0) ret = open_fdinfo(me->pid, &fle->fe, state);
break;
ret = open_fdinfo(pid, &fe, &fdinfo_fd, state);
if (ret) if (ret)
break; goto done;
} }
if (ret)
break;
}
close(fdinfo_fd);
if (!ret)
ret = run_unix_connections(); ret = run_unix_connections();
done:
return ret; return ret;
} }
......
...@@ -59,7 +59,8 @@ extern int restore_fown(int fd, fown_t *fown); ...@@ -59,7 +59,8 @@ extern int restore_fown(int fd, fown_t *fown);
void show_saved_files(void); void show_saved_files(void);
extern int collect_reg_files(void); extern int collect_reg_files(void);
extern int prepare_fds(int pid); struct pstree_item;
extern int prepare_fds(struct pstree_item *);
struct rst_info; struct rst_info;
extern int prepare_fd_pid(int pid, struct rst_info *); extern int prepare_fd_pid(int pid, struct rst_info *);
extern int prepare_shared_fdinfo(void); extern int prepare_shared_fdinfo(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment