mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-20 16:51:37 +00:00
files: Factor sending fd to peer via temp unix sk
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
b16293414b
commit
76c2818b95
4 changed files with 19 additions and 36 deletions
26
files.c
26
files.c
|
|
@ -301,7 +301,7 @@ static int restore_exe_early(struct fdinfo_entry *fe, int fd)
|
|||
return reopen_fd_as(self_exe_fd, tmp);
|
||||
}
|
||||
|
||||
void transport_name_gen(struct sockaddr_un *addr, int *len,
|
||||
static void transport_name_gen(struct sockaddr_un *addr, int *len,
|
||||
int pid, long fd)
|
||||
{
|
||||
addr->sun_family = AF_UNIX;
|
||||
|
|
@ -367,12 +367,24 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe, struct file_desc
|
|||
return 0;
|
||||
}
|
||||
|
||||
int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int tsk)
|
||||
{
|
||||
struct sockaddr_un saddr;
|
||||
int len;
|
||||
|
||||
pr_info("Wait fdinfo pid=%d fd=%d\n", fle->pid, fle->fd);
|
||||
futex_wait_while(&fle->real_pid, 0);
|
||||
transport_name_gen(&saddr, &len,
|
||||
futex_get(&fle->real_pid), fle->fd);
|
||||
pr_info("Send fd %d to %s\n", fd, saddr.sun_path + 1);
|
||||
return send_fd(tsk, &saddr, len, fd);
|
||||
}
|
||||
|
||||
static int open_fd(int pid, struct fdinfo_entry *fe,
|
||||
struct file_desc *d, int *fdinfo_fd)
|
||||
{
|
||||
int tmp;
|
||||
int serv, sock;
|
||||
struct sockaddr_un saddr;
|
||||
struct fdinfo_list_entry *fle;
|
||||
|
||||
fle = file_master(d);
|
||||
|
|
@ -395,8 +407,6 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
|
|||
pr_info("\t%d: Create fd for %lx\n", pid, fe->addr);
|
||||
|
||||
list_for_each_entry(fle, &d->fd_info_head, list) {
|
||||
int len;
|
||||
|
||||
if (pid == fle->pid) {
|
||||
pr_info("\t\tGoing to dup %d into %d\n",
|
||||
(int)fe->addr, fle->fd);
|
||||
|
|
@ -417,13 +427,7 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
|
|||
continue;
|
||||
}
|
||||
|
||||
pr_info("Wait fdinfo pid=%d fd=%d\n", fle->pid, fle->fd);
|
||||
futex_wait_while(&fle->real_pid, 0);
|
||||
|
||||
pr_info("Send fd %d to %s\n", (int)fe->addr, saddr.sun_path + 1);
|
||||
transport_name_gen(&saddr, &len, futex_get(&fle->real_pid), fle->fd);
|
||||
|
||||
if (send_fd(sock, &saddr, len, fe->addr) < 0) {
|
||||
if (send_fd_to_peer(fe->addr, fle, sock)) {
|
||||
pr_perror("Can't send file descriptor");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,9 +58,7 @@ extern void file_desc_add(struct file_desc *d, int type, u32 id,
|
|||
struct file_desc_ops *ops);
|
||||
extern struct fdinfo_list_entry *file_master(struct file_desc *d);
|
||||
extern struct file_desc *find_file_desc_raw(int type, u32 id);
|
||||
|
||||
extern void transport_name_gen(struct sockaddr_un *addr,
|
||||
int *len, int pid, long fd);
|
||||
extern int send_fd_to_peer(int fd, struct fdinfo_list_entry *, int transport);
|
||||
|
||||
void show_saved_files(void);
|
||||
extern int collect_reg_files(void);
|
||||
|
|
|
|||
14
pipes.c
14
pipes.c
|
|
@ -296,23 +296,13 @@ static int open_pipe(struct file_desc *d)
|
|||
}
|
||||
|
||||
list_for_each_entry(p, &pi->pipe_list, pipe_list) {
|
||||
int len, fd;
|
||||
struct sockaddr_un saddr;
|
||||
struct fdinfo_list_entry *fle;
|
||||
int fd;
|
||||
|
||||
fle = file_master(&p->d);
|
||||
|
||||
pr_info("\t\tWait fdinfo pid=%d fd=%d\n", fle->pid, fle->fd);
|
||||
futex_wait_while(&fle->real_pid, 0);
|
||||
|
||||
transport_name_gen(&saddr, &len,
|
||||
futex_get(&fle->real_pid), fle->fd);
|
||||
|
||||
fd = pfd[p->pe.flags & O_WRONLY];
|
||||
|
||||
pr_info("\t\tSend fd %d to %s\n", fd, saddr.sun_path + 1);
|
||||
|
||||
if (send_fd(sock, &saddr, len, fd) < 0) {
|
||||
if (send_fd_to_peer(fd, fle, sock)) {
|
||||
pr_perror("Can't send file descriptor");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
11
sockets.c
11
sockets.c
|
|
@ -1256,8 +1256,6 @@ static int open_unixsk_pair_master(struct unix_sk_info *ui)
|
|||
int sk[2], tsk;
|
||||
struct unix_sk_info *peer = ui->peer;
|
||||
struct fdinfo_list_entry *fle;
|
||||
struct sockaddr_un addr;
|
||||
int addr_len;
|
||||
|
||||
pr_info("Opening pair master (id %x peer %x)\n",
|
||||
ui->ue.id, ui->ue.peer);
|
||||
|
|
@ -1282,14 +1280,7 @@ static int open_unixsk_pair_master(struct unix_sk_info *ui)
|
|||
}
|
||||
|
||||
fle = file_master(&peer->d);
|
||||
futex_wait_while(&fle->real_pid, 0);
|
||||
|
||||
pr_info("\tSending pair to %d's %d\n",
|
||||
futex_get(&fle->real_pid), fle->fd);
|
||||
transport_name_gen(&addr, &addr_len,
|
||||
futex_get(&fle->real_pid), fle->fd);
|
||||
|
||||
if (send_fd(tsk, &addr, addr_len, sk[1]) < 0) {
|
||||
if (send_fd_to_peer(sk[1], fle, tsk)) {
|
||||
pr_err("Can't send pair slave\n");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue