Commit fa6eb98a authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Pavel Emelyanov

files: Move derefferencing of TRANSPORT_FD_OFF to send_fd_to_peer()

No functional changes

travis-ci: success for Rework file opening scheme to make it asynchronous (rev5)
Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent dd195109
...@@ -975,10 +975,12 @@ int recv_fd_from_peer(struct fdinfo_list_entry *fle) ...@@ -975,10 +975,12 @@ int recv_fd_from_peer(struct fdinfo_list_entry *fle)
return fd; return fd;
} }
int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int sock) int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle)
{ {
struct sockaddr_un saddr; struct sockaddr_un saddr;
int len; int len, sock;
sock = get_service_fd(TRANSPORT_FD_OFF);
pr_info("\t\tWait fdinfo pid=%d fd=%d\n", fle->pid, fle->fe->fd); pr_info("\t\tWait fdinfo pid=%d fd=%d\n", fle->pid, fle->fe->fd);
futex_wait_while(&fle->real_pid, 0); futex_wait_while(&fle->real_pid, 0);
...@@ -988,7 +990,7 @@ int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int sock) ...@@ -988,7 +990,7 @@ int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int sock)
return send_fds(sock, &saddr, len, &fd, 1, (void *)&fle, sizeof(struct fdinfo_list_entry *)); return send_fds(sock, &saddr, len, &fd, 1, (void *)&fle, sizeof(struct fdinfo_list_entry *));
} }
static int send_fd_to_self(int fd, struct fdinfo_list_entry *fle, int sock) static int send_fd_to_self(int fd, struct fdinfo_list_entry *fle)
{ {
int dfd = fle->fe->fd; int dfd = fle->fe->fd;
...@@ -999,7 +1001,7 @@ static int send_fd_to_self(int fd, struct fdinfo_list_entry *fle, int sock) ...@@ -999,7 +1001,7 @@ static int send_fd_to_self(int fd, struct fdinfo_list_entry *fle, int sock)
if (inherit_fd_resolve_clash(dfd) < 0) if (inherit_fd_resolve_clash(dfd) < 0)
return -1; return -1;
BUG_ON(dfd == sock); BUG_ON(dfd == get_service_fd(TRANSPORT_FD_OFF));
pr_info("\t\t\tGoing to dup %d into %d\n", fd, dfd); pr_info("\t\t\tGoing to dup %d into %d\n", fd, dfd);
if (dup2(fd, dfd) != dfd) { if (dup2(fd, dfd) != dfd) {
...@@ -1034,18 +1036,16 @@ static int post_open_fd(int pid, struct fdinfo_list_entry *fle) ...@@ -1034,18 +1036,16 @@ static int post_open_fd(int pid, struct fdinfo_list_entry *fle)
static int serve_out_fd(int pid, int fd, struct file_desc *d) static int serve_out_fd(int pid, int fd, struct file_desc *d)
{ {
int sock, ret; int ret;
struct fdinfo_list_entry *fle; struct fdinfo_list_entry *fle;
sock = get_service_fd(TRANSPORT_FD_OFF);
pr_info("\t\tCreate fd for %d\n", fd); pr_info("\t\tCreate fd for %d\n", fd);
list_for_each_entry(fle, &d->fd_info_head, desc_list) { list_for_each_entry(fle, &d->fd_info_head, desc_list) {
if (pid == fle->pid) if (pid == fle->pid)
ret = send_fd_to_self(fd, fle, sock); ret = send_fd_to_self(fd, fle);
else else
ret = send_fd_to_peer(fd, fle, sock); ret = send_fd_to_peer(fd, fle);
if (ret) { if (ret) {
pr_err("Can't sent fd %d to %d\n", fd, fle->pid); pr_err("Can't sent fd %d to %d\n", fd, fle->pid);
......
...@@ -149,7 +149,7 @@ extern struct fdinfo_list_entry *file_master(struct file_desc *d); ...@@ -149,7 +149,7 @@ extern struct fdinfo_list_entry *file_master(struct file_desc *d);
extern struct file_desc *find_file_desc_raw(int type, u32 id); extern struct file_desc *find_file_desc_raw(int type, u32 id);
extern int recv_fd_from_peer(struct fdinfo_list_entry *fle); extern int recv_fd_from_peer(struct fdinfo_list_entry *fle);
extern int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int sock); extern int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle);
extern int restore_fown(int fd, FownEntry *fown); extern int restore_fown(int fd, FownEntry *fown);
extern int rst_file_params(int fd, FownEntry *fown, int flags); extern int rst_file_params(int fd, FownEntry *fown, int flags);
......
...@@ -276,7 +276,6 @@ static int open_pipe(struct file_desc *d) ...@@ -276,7 +276,6 @@ static int open_pipe(struct file_desc *d)
struct pipe_info *pi, *p; struct pipe_info *pi, *p;
int ret, tmp; int ret, tmp;
int pfd[2]; int pfd[2];
int sock;
pi = container_of(d, struct pipe_info, d); pi = container_of(d, struct pipe_info, d);
pr_info("\t\tCreating pipe pipe_id=%#x id=%#x\n", pi->pe->pipe_id, pi->pe->id); pr_info("\t\tCreating pipe pipe_id=%#x id=%#x\n", pi->pe->pipe_id, pi->pe->id);
...@@ -301,8 +300,6 @@ static int open_pipe(struct file_desc *d) ...@@ -301,8 +300,6 @@ static int open_pipe(struct file_desc *d)
if (ret) if (ret)
return -1; return -1;
sock = get_service_fd(TRANSPORT_FD_OFF);
list_for_each_entry(p, &pi->pipe_list, pipe_list) { list_for_each_entry(p, &pi->pipe_list, pipe_list) {
struct fdinfo_list_entry *fle; struct fdinfo_list_entry *fle;
int fd; int fd;
...@@ -310,7 +307,7 @@ static int open_pipe(struct file_desc *d) ...@@ -310,7 +307,7 @@ static int open_pipe(struct file_desc *d)
fle = file_master(&p->d); fle = file_master(&p->d);
fd = pfd[p->pe->flags & O_WRONLY]; fd = pfd[p->pe->flags & O_WRONLY];
if (send_fd_to_peer(fd, fle, sock)) { if (send_fd_to_peer(fd, fle)) {
pr_perror("Can't send file descriptor"); pr_perror("Can't send file descriptor");
return -1; return -1;
} }
......
...@@ -1045,7 +1045,7 @@ static int unixsk_should_open_transport(FdinfoEntry *fe, ...@@ -1045,7 +1045,7 @@ static int unixsk_should_open_transport(FdinfoEntry *fe,
static int open_unixsk_pair_master(struct unix_sk_info *ui) static int open_unixsk_pair_master(struct unix_sk_info *ui)
{ {
int sk[2], tsk; int sk[2];
struct unix_sk_info *peer = ui->peer; struct unix_sk_info *peer = ui->peer;
struct fdinfo_list_entry *fle; struct fdinfo_list_entry *fle;
...@@ -1074,10 +1074,8 @@ static int open_unixsk_pair_master(struct unix_sk_info *ui) ...@@ -1074,10 +1074,8 @@ static int open_unixsk_pair_master(struct unix_sk_info *ui)
if (shutdown_unix_sk(sk[0], ui)) if (shutdown_unix_sk(sk[0], ui))
return -1; return -1;
tsk = get_service_fd(TRANSPORT_FD_OFF);
fle = file_master(&peer->d); fle = file_master(&peer->d);
if (send_fd_to_peer(sk[1], fle, tsk)) { if (send_fd_to_peer(sk[1], fle)) {
pr_err("Can't send pair slave\n"); pr_err("Can't send pair slave\n");
return -1; return -1;
} }
......
...@@ -876,12 +876,10 @@ static void pty_restore_queued_data(struct tty_info *info, int fd) ...@@ -876,12 +876,10 @@ static void pty_restore_queued_data(struct tty_info *info, int fd)
static int pty_open_slaves(struct tty_info *info) static int pty_open_slaves(struct tty_info *info)
{ {
int sock = -1, fd = -1, ret = -1; int fd = -1, ret = -1;
struct fdinfo_list_entry *fle; struct fdinfo_list_entry *fle;
struct tty_info *slave; struct tty_info *slave;
sock = get_service_fd(TRANSPORT_FD_OFF);
list_for_each_entry(slave, &info->sibling, sibling) { list_for_each_entry(slave, &info->sibling, sibling) {
BUG_ON(tty_is_master(slave)); BUG_ON(tty_is_master(slave));
...@@ -899,7 +897,7 @@ static int pty_open_slaves(struct tty_info *info) ...@@ -899,7 +897,7 @@ static int pty_open_slaves(struct tty_info *info)
pr_debug("send slave %#x fd %d connected on %s (pid %d)\n", pr_debug("send slave %#x fd %d connected on %s (pid %d)\n",
slave->tfe->id, fd, path_from_reg(slave->reg_d), fle->pid); slave->tfe->id, fd, path_from_reg(slave->reg_d), fle->pid);
if (send_fd_to_peer(fd, fle, sock)) { if (send_fd_to_peer(fd, fle)) {
pr_err("Can't send file descriptor\n"); pr_err("Can't send file descriptor\n");
goto err; goto err;
} }
......
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