[CRIU] [PATCH RFC 06/12] files: Move derefferencing of TRANSPORT_FD_OFF to send_fd_to_peer()

Kirill Tkhai ktkhai at virtuozzo.com
Fri Oct 28 05:53:22 PDT 2016


Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/files.c         |   18 +++++++++---------
 criu/include/files.h |    2 +-
 criu/pipes.c         |    5 +----
 criu/sk-unix.c       |    6 ++----
 criu/tty.c           |    6 ++----
 5 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/criu/files.c b/criu/files.c
index c4da1a7..e4c2ab7 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -975,10 +975,12 @@ int recv_fd_from_peer(struct fdinfo_list_entry *fle)
 	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;
-	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);
 	futex_wait_while(&fle->real_pid, 0);
@@ -989,7 +991,7 @@ int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int sock)
 	return send_fds(sock, &saddr, len, &fd, 1, false, (unsigned long *)&fle);
 }
 
-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;
 
@@ -1000,7 +1002,7 @@ static int send_fd_to_self(int fd, struct fdinfo_list_entry *fle, int sock)
 	if (inherit_fd_resolve_clash(dfd) < 0)
 		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);
 	if (dup2(fd, dfd) != dfd) {
@@ -1035,18 +1037,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)
 {
-	int sock, ret;
+	int ret;
 	struct fdinfo_list_entry *fle;
 
-	sock = get_service_fd(TRANSPORT_FD_OFF);
-
 	pr_info("\t\tCreate fd for %d\n", fd);
 
 	list_for_each_entry(fle, &d->fd_info_head, desc_list) {
 		if (pid == fle->pid)
-			ret = send_fd_to_self(fd, fle, sock);
+			ret = send_fd_to_self(fd, fle);
 		else
-			ret = send_fd_to_peer(fd, fle, sock);
+			ret = send_fd_to_peer(fd, fle);
 
 		if (ret) {
 			pr_err("Can't sent fd %d to %d\n", fd, fle->pid);
diff --git a/criu/include/files.h b/criu/include/files.h
index 457cc46..9388a8a 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -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 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 rst_file_params(int fd, FownEntry *fown, int flags);
 
diff --git a/criu/pipes.c b/criu/pipes.c
index 9a61cff..a4556f8 100644
--- a/criu/pipes.c
+++ b/criu/pipes.c
@@ -276,7 +276,6 @@ static int open_pipe(struct file_desc *d)
 	struct pipe_info *pi, *p;
 	int ret, tmp;
 	int pfd[2];
-	int sock;
 
 	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);
@@ -301,8 +300,6 @@ static int open_pipe(struct file_desc *d)
 	if (ret)
 		return -1;
 
-	sock = get_service_fd(TRANSPORT_FD_OFF);
-
 	list_for_each_entry(p, &pi->pipe_list, pipe_list) {
 		struct fdinfo_list_entry *fle;
 		int fd;
@@ -310,7 +307,7 @@ static int open_pipe(struct file_desc *d)
 		fle = file_master(&p->d);
 		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");
 			return -1;
 		}
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index fbe29c2..965a195 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -1044,7 +1044,7 @@ static int unixsk_should_open_transport(FdinfoEntry *fe,
 
 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 fdinfo_list_entry *fle;
 
@@ -1073,10 +1073,8 @@ static int open_unixsk_pair_master(struct unix_sk_info *ui)
 	if (shutdown_unix_sk(sk[0], ui))
 		return -1;
 
-	tsk = get_service_fd(TRANSPORT_FD_OFF);
-
 	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");
 		return -1;
 	}
diff --git a/criu/tty.c b/criu/tty.c
index 08e5211..2d0e535 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -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)
 {
-	int sock = -1, fd = -1, ret = -1;
+	int fd = -1, ret = -1;
 	struct fdinfo_list_entry *fle;
 	struct tty_info *slave;
 
-	sock = get_service_fd(TRANSPORT_FD_OFF);
-
 	list_for_each_entry(slave, &info->sibling, sibling) {
 		BUG_ON(tty_is_master(slave));
 
@@ -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",
 			 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_perror("Can't send file descriptor");
 			goto err;
 		}



More information about the CRIU mailing list